package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviate;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
import com.google.common.collect.SetMultimap;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.Arrays;
import java.util.Collection;
-import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.SchemaNodeIdentifierBuildNamespace;
+import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ChildSchemaNodeNamespace;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.YangValidationBundles;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
.addOptional(YangStmtMapping.UNITS)
.build();
- private static final Map<String, DeviateKind> KEYWORD_TO_DEVIATE_MAP;
+ private static final ImmutableMap<String, DeviateKind> KEYWORD_TO_DEVIATE_MAP =
+ Maps.uniqueIndex(Arrays.asList(DeviateKind.values()), DeviateKind::getKeyword);
- static {
- final Builder<String, DeviateKind> keywordToDeviateMapBuilder = ImmutableMap.builder();
- for (final DeviateKind deviate : DeviateKind.values()) {
- keywordToDeviateMapBuilder.put(deviate.getKeyword(), deviate);
- }
- KEYWORD_TO_DEVIATE_MAP = keywordToDeviateMapBuilder.build();
- }
-
- private static final Set<YangStmtMapping> SINGLETON_STATEMENTS = ImmutableSet.of(
+ private static final ImmutableSet<YangStmtMapping> SINGLETON_STATEMENTS = ImmutableSet.of(
YangStmtMapping.UNITS, YangStmtMapping.CONFIG, YangStmtMapping.MANDATORY,
YangStmtMapping.MIN_ELEMENTS, YangStmtMapping.MAX_ELEMENTS);
- private static final Set<YangStmtMapping> IMPLICIT_STATEMENTS = ImmutableSet.of(YangStmtMapping.CONFIG,
+ private static final ImmutableSet<YangStmtMapping> IMPLICIT_STATEMENTS = ImmutableSet.of(YangStmtMapping.CONFIG,
YangStmtMapping.MANDATORY, YangStmtMapping.MAX_ELEMENTS, YangStmtMapping.MIN_ELEMENTS);
AbstractDeviateStatementSupport() {
getSubstatementValidatorForDeviate(deviateKind).validate(deviateStmtCtx);
final SchemaNodeIdentifier deviationTarget =
- (SchemaNodeIdentifier) deviateStmtCtx.getParentContext().getStatementArgument();
+ (SchemaNodeIdentifier) deviateStmtCtx.coerceParentContext().getStatementArgument();
if (!isDeviationSupported(deviateStmtCtx, deviationTarget)) {
return;
deviateAction.requiresCtx(deviateStmtCtx, ModelProcessingPhase.EFFECTIVE_MODEL);
final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> targetCtxPrerequisite =
- deviateAction.mutatesEffectiveCtx(deviateStmtCtx.getRoot(),
- SchemaNodeIdentifierBuildNamespace.class, deviationTarget);
+ deviateAction.mutatesEffectiveCtxPath(deviateStmtCtx.getRoot(),
+ ChildSchemaNodeNamespace.class, deviationTarget.getPathFromRoot());
deviateAction.apply(new InferenceAction() {
@Override
- public void apply(final InferenceContext ctx) throws InferenceException {
+ public void apply(final InferenceContext ctx) {
// FIXME once BUG-7760 gets fixed, there will be no need for these dirty casts
final StatementContextBase<?, ?, ?> sourceNodeStmtCtx =
(StatementContextBase<?, ?, ?>) sourceCtxPrerequisite.resolve(ctx);
@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
- throw new InferenceException(deviateStmtCtx.getParentContext().getStatementSourceReference(),
+ throw new InferenceException(deviateStmtCtx.coerceParentContext().getStatementSourceReference(),
"Deviation target '%s' not found.", deviationTarget);
}
});
return false;
}
+ @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static void performDeviateAdd(final StatementContextBase<?, ?, ?> deviateStmtCtx,
final StatementContextBase<?, ?, ?> targetCtx) {
for (Mutable<?, ?, ?> originalStmtCtx : deviateStmtCtx.mutableDeclaredSubstatements()) {
copyStatement(stmtCtxToBeAdded, targetCtx);
}
+ @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static void performDeviateReplace(final StatementContextBase<?, ?, ?> deviateStmtCtx,
final StatementContextBase<?, ?, ?> targetCtx) {
for (Mutable<?, ?, ?> originalStmtCtx : deviateStmtCtx.mutableDeclaredSubstatements()) {
stmtToBeReplaced.getStatementName(), targetCtx.getStatementArgument());
}
+ @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static void performDeviateDelete(final StatementContextBase<?, ?, ?> deviateStmtCtx,
final StatementContextBase<?, ?, ?> targetCtx) {
for (Mutable<?, ?, ?> originalStmtCtx : deviateStmtCtx.mutableDeclaredSubstatements()) {