X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Freactor%2FStatementContextBase.java;h=59a22343e13743e8d9531faf92dea4059bc94adb;hb=32438a2739795793f393c872a76a43444db7b46a;hp=d28dc9a458c472d70c13b7645c7e282779168e6d;hpb=f6e95705ab22346ccdc6e5b84e5c0b14cd45511f;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java index d28dc9a458..59a22343e1 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java @@ -7,9 +7,6 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.reactor; -import java.util.LinkedList; - -import java.util.List; import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import com.google.common.collect.HashMultimap; @@ -20,6 +17,7 @@ import java.util.Collections; import java.util.EventListener; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Identifiable; @@ -76,30 +74,32 @@ public abstract class StatementContextBase, E private final StatementSourceReference statementDeclSource; private int order = 0; - private Map> substatements = new LinkedHashMap<>(); + private final Map> substatements = new LinkedHashMap<>(); - private Collection> declared = new ArrayList<>(); - private Collection> effective = new ArrayList<>(); - private Collection> effectOfStatement = new ArrayList<>(); + private final Collection> declared = new ArrayList<>(); + private final Collection> effective = new ArrayList<>(); + private final Collection> effectOfStatement = new ArrayList<>(); + @Override public Collection> getEffectOfStatement() { return effectOfStatement; } - public void addAsEffectOfStatement(StatementContextBase ctx) { + @Override + public void addAsEffectOfStatement(final StatementContextBase ctx) { effectOfStatement.add(ctx); } private ModelProcessingPhase completedPhase; - private Multimap phaseListeners = HashMultimap.create(); - private Multimap phaseMutation = HashMultimap.create(); + private final Multimap phaseListeners = HashMultimap.create(); + private final Multimap phaseMutation = HashMultimap.create(); private D declaredInstance; private E effectiveInstance; private StatementContextBase originalCtx; - private List copyHistory; + private final List copyHistory = new ArrayList<>(1); private boolean isSupportedToBuildEffective = true; @@ -109,7 +109,7 @@ public abstract class StatementContextBase, E } @Override - public void setIsSupportedToBuildEffective(boolean isSupportedToBuildEffective) { + public void setIsSupportedToBuildEffective(final boolean isSupportedToBuildEffective) { this.isSupportedToBuildEffective = isSupportedToBuildEffective; } @@ -119,12 +119,12 @@ public abstract class StatementContextBase, E } @Override - public void addToCopyHistory(TypeOfCopy typeOfCopy) { + public void addToCopyHistory(final TypeOfCopy typeOfCopy) { this.copyHistory.add(typeOfCopy); } @Override - public void addAllToCopyHistory(List typeOfCopyList) { + public void addAllToCopyHistory(final List typeOfCopyList) { this.copyHistory.addAll(typeOfCopyList); } @@ -134,12 +134,12 @@ public abstract class StatementContextBase, E } @Override - public void setOriginalCtx(StatementContextBase originalCtx) { + public void setOriginalCtx(final StatementContextBase originalCtx) { this.originalCtx = originalCtx; } @Override - public void setOrder(int order) { + public void setOrder(final int order) { this.order = order; } @@ -154,19 +154,19 @@ public abstract class StatementContextBase, E } @Override - public void setCompletedPhase(ModelProcessingPhase completedPhase) { + public void setCompletedPhase(final ModelProcessingPhase completedPhase) { this.completedPhase = completedPhase; } - StatementContextBase(@Nonnull ContextBuilder builder) throws SourceException { + StatementContextBase(@Nonnull final ContextBuilder builder) throws SourceException { this.definition = builder.getDefinition(); this.identifier = builder.createIdentifier(); this.statementDeclSource = builder.getStamementSource(); this.completedPhase = null; - initCopyHistory(); + this.copyHistory.add(TypeOfCopy.ORIGINAL); } - StatementContextBase(StatementContextBase original) { + StatementContextBase(final StatementContextBase original) { this.definition = Preconditions .checkNotNull(original.definition, "Statement context definition cannot be null"); this.identifier = Preconditions @@ -174,11 +174,6 @@ public abstract class StatementContextBase, E this.statementDeclSource = Preconditions.checkNotNull(original.statementDeclSource, "Statement context statementDeclSource cannot be null"); this.completedPhase = null; - initCopyHistory(); - } - - private void initCopyHistory() { - this.copyHistory = new LinkedList<>(); this.copyHistory.add(TypeOfCopy.ORIGINAL); } @@ -250,11 +245,11 @@ public abstract class StatementContextBase, E return Collections.unmodifiableCollection(effective); } - public void removeStatementsFromEffectiveSubstatements(Collection> substatements) { + public void removeStatementsFromEffectiveSubstatements(final Collection> substatements) { effective.removeAll(substatements); } - public void removeStatementFromEffectiveSubstatements(StatementDefinition refineSubstatementDef) { + public void removeStatementFromEffectiveSubstatements(final StatementDefinition refineSubstatementDef) { Iterator> iterator = effective.iterator(); while (iterator.hasNext()) { StatementContextBase next = iterator.next(); @@ -274,7 +269,7 @@ public abstract class StatementContextBase, E * * @param substatement substatement */ - public void addEffectiveSubstatement(StatementContextBase substatement) { + public void addEffectiveSubstatement(final StatementContextBase substatement) { final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase(); Preconditions.checkState(inProgressPhase == ModelProcessingPhase.FULL_DECLARATION @@ -295,7 +290,7 @@ public abstract class StatementContextBase, E * * @param substatement substatement */ - public void addDeclaredSubstatement(StatementContextBase substatement) { + public void addDeclaredSubstatement(final StatementContextBase substatement) { final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase(); Preconditions.checkState(inProgressPhase != ModelProcessingPhase.EFFECTIVE_MODEL, @@ -314,15 +309,16 @@ public abstract class StatementContextBase, E * @return instance of ContextBuilder */ @SuppressWarnings({ "rawtypes", "unchecked" }) - public ContextBuilder substatementBuilder(StatementDefinitionContext def, - StatementSourceReference ref) { + public ContextBuilder substatementBuilder(final StatementDefinitionContext def, + final StatementSourceReference ref) { return new ContextBuilder(def, ref) { @Override public StatementContextBase build() throws SourceException { StatementContextBase potential = null; - if (getDefinition().getPublicView() != Rfc6020Mapping.AUGMENT) { + StatementDefinition stmtDef = getDefinition().getPublicView(); + if (stmtDef != Rfc6020Mapping.AUGMENT && stmtDef != Rfc6020Mapping.DEVIATION) { potential = substatements.get(createIdentifier()); } if (potential == null) { @@ -400,7 +396,7 @@ public abstract class StatementContextBase, E * @throws SourceException * when an error occured in source parsing */ - boolean tryToCompletePhase(ModelProcessingPhase phase) throws SourceException { + boolean tryToCompletePhase(final ModelProcessingPhase phase) throws SourceException { Iterator openMutations = phaseMutation.get(phase).iterator(); boolean finished = true; while (openMutations.hasNext()) { @@ -433,7 +429,7 @@ public abstract class StatementContextBase, E * @throws SourceException * when an error occured in source parsing */ - private void onPhaseCompleted(ModelProcessingPhase phase) throws SourceException { + private void onPhaseCompleted(final ModelProcessingPhase phase) throws SourceException { completedPhase = phase; Iterator listener = phaseListeners.get(completedPhase).iterator(); while (listener.hasNext()) { @@ -450,7 +446,7 @@ public abstract class StatementContextBase, E * @param ref * @throws SourceException */ - void endDeclared(StatementSourceReference ref, ModelProcessingPhase phase) throws SourceException { + void endDeclared(final StatementSourceReference ref, final ModelProcessingPhase phase) throws SourceException { definition().onDeclarationFinished(this, phase); } @@ -462,7 +458,7 @@ public abstract class StatementContextBase, E } @Override - protected void checkLocalNamespaceAllowed(Class> type) { + protected void checkLocalNamespaceAllowed(final Class> type) { definition().checkNamespaceAllowed(type); } @@ -472,11 +468,11 @@ public abstract class StatementContextBase, E * @throws SourceException instance of SourceException */ @Override - protected > void onNamespaceElementAdded(Class type, K key, V value) { + protected > void onNamespaceElementAdded(final Class type, final K key, final V value) { // definition().onNamespaceElementAdded(this, type, key, value); } - > void onNamespaceItemAddedAction(final Class type, K key, + > void onNamespaceItemAddedAction(final Class type, final K key, final OnNamespaceItemAdded listener) throws SourceException { Object potential = getFromNamespace(type, key); if (potential != null) { @@ -486,9 +482,9 @@ public abstract class StatementContextBase, E NamespaceBehaviour behaviour = getBehaviourRegistry().getNamespaceBehaviour(type); if (behaviour instanceof NamespaceBehaviourWithListeners) { NamespaceBehaviourWithListeners casted = (NamespaceBehaviourWithListeners) behaviour; - casted.addValueListener(key, new ValueAddedListener(this) { + casted.addValueListener(new ValueAddedListener(this, key) { @Override - void onValueAdded(Object key, Object value) { + void onValueAdded(final Object key, final Object value) { try { listener.namespaceItemAdded(StatementContextBase.this, type, key, value); } catch (SourceException e) { @@ -511,7 +507,7 @@ public abstract class StatementContextBase, E * @return new {@link ModelActionBuilder} for the phase */ @Override - public ModelActionBuilder newInferenceAction(ModelProcessingPhase phase) { + public ModelActionBuilder newInferenceAction(final ModelProcessingPhase phase) { return getRoot().getSourceContext().newInferenceAction(phase); } @@ -520,7 +516,7 @@ public abstract class StatementContextBase, E * * @throws SourceException */ - void addPhaseCompletedListener(ModelProcessingPhase phase, OnPhaseFinished listener) throws SourceException { + void addPhaseCompletedListener(final ModelProcessingPhase phase, final OnPhaseFinished listener) throws SourceException { Preconditions.checkNotNull(phase, "Statement context processing phase cannot be null"); Preconditions.checkNotNull(listener, "Statement context phase listener cannot be null"); @@ -542,7 +538,7 @@ public abstract class StatementContextBase, E * @throws IllegalStateException * when the mutation was registered after phase was completed */ - void addMutation(ModelProcessingPhase phase, ContextMutation mutation) { + void addMutation(final ModelProcessingPhase phase, final ContextMutation mutation) { ModelProcessingPhase finishedPhase = completedPhase; while (finishedPhase != null) { if (phase.equals(finishedPhase)) { @@ -564,8 +560,8 @@ public abstract class StatementContextBase, E * to be added to namespace map */ @Override - public > void addContext(Class namespace, KT key, - StmtContext stmt) { + public > void addContext(final Class namespace, final KT key, + final StmtContext stmt) { addContextToNamespace(namespace, (K) key, stmt); } }