X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=yang%2Fyang-parser-reactor%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Freactor%2FSourceSpecificContext.java;h=19bb1d5faa34c2644f2cab80d8da03ea785dde95;hb=refs%2Fchanges%2F12%2F93612%2F1;hp=f11a094ed7dea2af79d7e99c80d2bab6367c71a7;hpb=7ba42476ebbe233c6118dd6e7a35ac02fa8fed97;p=yangtools.git diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java index f11a094ed7..19bb1d5faa 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java @@ -29,10 +29,7 @@ import org.opendaylight.yangtools.concepts.Mutable; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.YangVersion; -import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; -import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; -import org.opendaylight.yangtools.yang.model.api.meta.StatementSource; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder; @@ -76,7 +73,9 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh private final QNameToStatementDefinitionMap qnameToStmtDefMap = new QNameToStatementDefinitionMap(); private final PrefixToModuleMap prefixToModuleMap = new PrefixToModuleMap(); private final BuildGlobalContext currentContext; - private final StatementStreamSource source; + + // Freed as soon as we complete ModelProcessingPhase.EFFECTIVE_MODEL + private StatementStreamSource source; /* * "imported" namespaces in this source -- this points to RootStatementContexts of @@ -101,23 +100,8 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh return inProgressPhase; } - Optional> lookupDeclaredChild(final StatementContextBase current, - final int childId) { - if (current == null) { - return Optional.empty(); - } - - // Fast path: we are entering a statement which was emitted in previous phase - StatementContextBase existing = current.lookupSubstatement(childId); - while (existing != null && StatementSource.CONTEXT == existing.getStatementSource()) { - existing = existing.lookupSubstatement(childId); - } - - return Optional.ofNullable(existing); - } - - StatementContextBase createDeclaredChild(final StatementContextBase current, final int childId, - final QName name, final String argument, final StatementSourceReference ref) { + AbstractResumedStatement createDeclaredChild(final AbstractResumedStatement current, + final int childId, final QName name, final String argument, final StatementSourceReference ref) { StatementDefinitionContext def = currentContext.getStatementDefinition(getRootVersion(), name); if (def == null) { def = currentContext.getModelDefinedStatementDefinition(name); @@ -192,14 +176,6 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh return root != null ? root.getRootVersion() : RootStatementContext.DEFAULT_VERSION; } - DeclaredStatement buildDeclared() { - return root.buildDeclared(); - } - - EffectiveStatement buildEffective() { - return root.buildEffective(); - } - void startPhase(final ModelProcessingPhase phase) { final ModelProcessingPhase previousPhase = phase.getPreviousPhase(); verify(Objects.equals(previousPhase, finishedPhase), @@ -291,7 +267,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh } @Override - public NamespaceStorageNode getParentNamespaceStorage() { + public BuildGlobalContext getParentNamespaceStorage() { return currentContext; } @@ -299,17 +275,20 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh final Collection currentPhaseModifiers = modifiers.get(phase); boolean hasProgressed = tryToProgress(currentPhaseModifiers); - - checkNotNull(this.root, "Malformed source. Valid root element is missing."); - final boolean phaseCompleted = root.tryToCompletePhase(phase); + final boolean phaseCompleted = requireNonNull(root, "Malformed source. Valid root element is missing.") + .tryToCompletePhase(phase); hasProgressed |= tryToProgress(currentPhaseModifiers); if (phaseCompleted && currentPhaseModifiers.isEmpty()) { finishedPhase = phase; LOG.debug("Source {} finished phase {}", source, phase); + if (phase == ModelProcessingPhase.EFFECTIVE_MODEL) { + // We have the effective model acquired, which is the final phase of source interaction. + LOG.trace("Releasing source {}", source); + source = null; + } return PhaseCompletionProgress.FINISHED; - } return hasProgressed ? PhaseCompletionProgress.PROGRESS : PhaseCompletionProgress.NO_PROGRESS; @@ -389,7 +368,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh } private PrefixToModule preLinkagePrefixes() { - final PrefixToModuleMap preLinkagePrefixes = new PrefixToModuleMap(true); + final PrefixToModuleMap preLinkagePrefixes = new PrefixToModuleMap(); final Map prefixToNamespaceMap = getAllFromLocalStorage(ImpPrefixToNamespace.class); if (prefixToNamespaceMap == null) { //:FIXME if it is a submodule without any import, the map is null. Handle also submodules and includes... @@ -430,7 +409,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh } // We need to any and all extension statements which have been declared in the context - final Map> extensions = currentContext.getAllFromNamespace( + final Map> extensions = currentContext.getNamespace( StatementDefinitionNamespace.class); if (extensions != null) { extensions.forEach((qname, support) -> {