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%2FBuildGlobalContext.java;h=dfed4282952829a51b0caa8743782e7d6d6133fd;hb=07a461a735316f15f9a78455e1c1c3caf91b2a3e;hp=14d450d56714d76082c7735d372e65e64200954d;hpb=e27979870db1358da1477c6d13b05c510c2045d8;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java index 14d450d567..dfed428295 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java @@ -42,6 +42,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace; import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType; import org.opendaylight.yangtools.yang.parser.stmt.reactor.SourceSpecificContext.PhaseCompletionProgress; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.RecursiveObjectLeaker; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +60,6 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh private final Map> definitions = new HashMap<>(); private final Map,NamespaceBehaviourWithListeners> supportedNamespaces = new HashMap<>(); - private final Map supports; private final Set sources = new HashSet<>(); @@ -71,12 +71,11 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null"); } - public BuildGlobalContext(final Map supports, final Map> supportedValidation) { + public BuildGlobalContext(final Map supports, final Map> supportedValidation) { super(); this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null"); - Set>> validationBundles = supportedValidation.entrySet(); - for (Entry> validationBundle : validationBundles) { + for (Entry> validationBundle : supportedValidation.entrySet()) { addToNs(ValidationBundlesNamespace.class, validationBundle.getKey(), validationBundle.getValue()); } } @@ -109,7 +108,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh NamespaceBehaviourWithListeners potential = supportedNamespaces.get(type); if (potential == null) { NamespaceBehaviour potentialRaw = supports.get(currentPhase).getNamespaceBehaviour(type); - if(potentialRaw != null) { + if (potentialRaw != null) { potential = createNamespaceContext(potentialRaw); supportedNamespaces.put(type, potential); } else { @@ -119,7 +118,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh } Verify.verify(type.equals(potential.getIdentifier())); - /* + /* * Safe cast, previous checkState checks equivalence of key from which type argument are * derived */ @@ -141,9 +140,9 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh public StatementDefinitionContext getStatementDefinition(final QName name) { StatementDefinitionContext potential = definitions.get(name); - if(potential == null) { + if (potential == null) { StatementSupport potentialRaw = supports.get(currentPhase).getStatementDefinition(name); - if(potentialRaw != null) { + if (potentialRaw != null) { potential = new StatementDefinitionContext<>(potentialRaw); definitions.put(name, potential); } @@ -152,7 +151,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh } public EffectiveModelContext build() throws SourceException, ReactorException { - for(ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) { + for (ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) { startPhase(phase); loadPhaseStatements(); completePhaseActions(); @@ -163,16 +162,15 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh private EffectiveModelContext transform() { Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL); - List> rootStatements = new ArrayList<>(); - for(SourceSpecificContext source : sources) { - DeclaredStatement root = source.getRoot().buildDeclared(); - rootStatements.add(root); + List> rootStatements = new ArrayList<>(sources.size()); + for (SourceSpecificContext source : sources) { + rootStatements.add(source.getRoot().buildDeclared()); } return new EffectiveModelContext(rootStatements); } public EffectiveSchemaContext buildEffective() throws SourceException, ReactorException { - for(ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) { + for (ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) { startPhase(phase); loadPhaseStatements(); completePhaseActions(); @@ -183,23 +181,25 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh private EffectiveSchemaContext transformEffective() { Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL); - List> rootStatements = new ArrayList<>(); - List> rootEffectiveStatements = new ArrayList<>(); - - for(SourceSpecificContext source : sources) { - DeclaredStatement root = source.getRoot().buildDeclared(); - rootStatements.add(root); + List> rootStatements = new ArrayList<>(sources.size()); + List> rootEffectiveStatements = new ArrayList<>(sources.size()); - EffectiveStatement rootEffective = source.getRoot().buildEffective(); - rootEffectiveStatements.add(rootEffective); + try { + for (SourceSpecificContext source : sources) { + final RootStatementContext root = source.getRoot(); + rootStatements.add(root.buildDeclared()); + rootEffectiveStatements.add(root.buildEffective()); + } + } finally { + RecursiveObjectLeaker.cleanup(); } - return new EffectiveSchemaContext(rootStatements,rootEffectiveStatements); + return new EffectiveSchemaContext(rootStatements, rootEffectiveStatements); } private void startPhase(final ModelProcessingPhase phase) { Preconditions.checkState(Objects.equals(finishedPhase, phase.getPreviousPhase())); - for(SourceSpecificContext source : sources) { + for (SourceSpecificContext source : sources) { source.startPhase(phase); } currentPhase = phase; @@ -207,7 +207,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh private void loadPhaseStatements() throws SourceException { Preconditions.checkState(currentPhase != null); - for(SourceSpecificContext source : sources) { + for (SourceSpecificContext source : sources) { source.loadStatements(); } } @@ -243,7 +243,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh } } - if(!addedCause) { + if (!addedCause) { addedCause = true; buildFailure.initCause(sourceEx); } else { @@ -258,7 +258,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh List sourcesToProgress = Lists.newArrayList(sources); try { boolean progressing = true; - while(progressing) { + while (progressing) { // We reset progressing to false. progressing = false; Iterator currentSource = sourcesToProgress.iterator(); @@ -283,7 +283,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh } catch (SourceException e) { throw Throwables.propagate(e); } - if(!sourcesToProgress.isEmpty()) { + if (!sourcesToProgress.isEmpty()) { SomeModifiersUnresolvedException buildFailure = new SomeModifiersUnresolvedException(currentPhase); buildFailure = addSourceExceptions(buildFailure, sourcesToProgress); throw buildFailure; @@ -298,5 +298,4 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh public Set getSources() { return sources; } - }