import java.io.IOException;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
/**
* Build the declared view of a combined view of declared statements.
*
* @return Ordered collection of declared statements from requested sources.
+ * @throws YangSyntaxErrorException When a syntactic error is encountered.
*/
List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException;
+ /**
+ * Build the effective view of a combined view of effective statements. Note that this representation, unlike
+ * {@link #buildDeclaredModel()} does not expose submodules as top-level contracts. These are available from their
+ * respective parent modules.
+ *
+ * @return Effective module statements indexed by their QNameModule.
+ * @throws YangSyntaxErrorException When a syntactic error is encountered.
+ */
+ // FIXME: 3.0.0: Make this method non-default
+ default Map<QNameModule, ModuleEffectiveStatement> buildEffectiveModel() throws YangParserException {
+ throw new UnsupportedOperationException(getClass() + " does not implement buildEffectiveModel()");
+ }
+
/**
* Build effective {@link SchemaContext}
*
*/
package org.opendaylight.yangtools.yang.parser.impl;
+import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static java.util.Objects.requireNonNull;
+import static java.util.function.Function.identity;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.SetMultimap;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.xml.transform.TransformerException;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
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.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.parser.api.YangParser;
import org.opendaylight.yangtools.yang.model.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
}
}
+ @Override
+ public Map<QNameModule, ModuleEffectiveStatement> buildEffectiveModel() throws YangParserException {
+ final List<EffectiveStatement<?, ?>> effectiveStatements;
+ try {
+ effectiveStatements = buildAction.buildEffective().getRootEffectiveStatements();
+ } catch (ReactorException e) {
+ throw decodeReactorException(e);
+ }
+
+ return effectiveStatements.stream()
+ .filter(ModuleEffectiveStatement.class::isInstance).map(ModuleEffectiveStatement.class::cast)
+ .collect(toImmutableMap(ModuleEffectiveStatement::localQNameModule, identity()));
+ }
+
@Override
public SchemaContext buildSchemaContext() throws YangParserException {
try {
*/
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
+import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Verify;
import com.google.common.collect.ImmutableList;
return rootDeclaredStatements;
}
- @VisibleForTesting
+ @Beta
public List<EffectiveStatement<?, ?>> getRootEffectiveStatements() {
return rootEffectiveStatements;
}