import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Mutable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
-import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleIdentifier;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.IdentityRefSpecificationImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.InstanceIdentifierSpecificationImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.LeafrefSpecificationImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.ModelDefinedStatementDefinition;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnionSpecificationImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBehaviour.Registry, Mutable {
FINISHED
}
+ private static final Logger LOG = LoggerFactory.getLogger(SourceSpecificContext.class);
+
private final StatementStreamSource source;
private final BuildGlobalContext currentContext;
private final Collection<NamespaceStorageNode> importedNamespaces = new ArrayList<>();
private final Multimap<ModelProcessingPhase, ModifierImpl> modifiers = HashMultimap.create();
- private RootStatementContext<?, ?, ?> root;
- private ModelProcessingPhase inProgressPhase;
- private ModelProcessingPhase finishedPhase = ModelProcessingPhase.INIT;
private final QNameToStatementDefinitionMap qNameToStmtDefMap = new QNameToStatementDefinitionMap();
private final PrefixToModuleMap prefixToModuleMap = new PrefixToModuleMap();
+ private ModelProcessingPhase finishedPhase = ModelProcessingPhase.INIT;
+ private ModelProcessingPhase inProgressPhase;
+ private RootStatementContext<?, ?, ?> root;
SourceSpecificContext(final BuildGlobalContext currentContext, final StatementStreamSource source) {
- this.source = source;
this.currentContext = currentContext;
+ this.source = source;
}
public boolean isEnabledSemanticVersioning(){
if (def == null) {
// unknown-stmts (from import, include or local-scope)
if (qNameToStmtDefMap.get(name) != null) {
- final StatementContextBase<?, ?, ?> extension =
- (StatementContextBase<?, ?, ?>) currentContext.getAllFromNamespace(ExtensionNamespace.class).get(name);
-
+ final StatementDefinition extension = currentContext.getFromNamespace(
+ StatementDefinitionNamespace.class, name);
SourceException.throwIfNull(extension, current.getStatementSourceReference(), "Extension %s not found",
name);
- final QName arg = (QName) extension.getStatementArgument();
- final QName qName = current.getFromNamespace(QNameCacheNamespace.class,
- QName.create(arg, extension.getIdentifier().getArgument()));
-
- def = new StatementDefinitionContext<>(new UnknownStatementImpl.Definition(
- getNewStatementDefinition(qName)));
+ def = new StatementDefinitionContext<>(new UnknownStatementImpl.Definition(extension));
} else {
// type-body-stmts
def = resolveTypeBodyStmts(name.getLocalName());
}
} else if (current != null && current.definition().getRepresentingClass().equals(UnknownStatementImpl.class)) {
+ // FIXME: What's going on here?
final QName qName = Utils.qNameFromArgument(current, name.getLocalName());
def = new StatementDefinitionContext<>(new UnknownStatementImpl.Definition(
- getNewStatementDefinition(qName)));
+ new ModelDefinedStatementDefinition(qName)));
}
Preconditions.checkArgument(def != null, "Statement %s does not have type mapping defined.", name);
return current.substatementBuilder(def, ref);
}
- // FIXME: This should be populated differently
- StatementDefinition getNewStatementDefinition(final QName qName) {
- return new ModelDefinedStatementDefinition(qName);
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
private ContextBuilder<?, ?, ?> createDeclaredRoot(final StatementDefinitionContext<?, ?, ?> def,
final StatementSourceReference ref) {
}
void startPhase(final ModelProcessingPhase phase) {
- @Nullable
- final ModelProcessingPhase previousPhase = phase.getPreviousPhase();
+ @Nullable final ModelProcessingPhase previousPhase = phase.getPreviousPhase();
Preconditions.checkState(Objects.equals(previousPhase, finishedPhase));
Preconditions.checkState(modifiers.get(previousPhase).isEmpty());
inProgressPhase = phase;
+ LOG.debug("Source {} started phase {}", source, phase);
}
@Override
Preconditions.checkNotNull(this.root, "Malformed source. Valid root element is missing.");
final boolean phaseCompleted = root.tryToCompletePhase(phase);
- hasProgressed = (tryToProgress(currentPhaseModifiers) | hasProgressed);
+ hasProgressed |= tryToProgress(currentPhaseModifiers);
- if (phaseCompleted && (currentPhaseModifiers.isEmpty())) {
+ if (phaseCompleted && currentPhaseModifiers.isEmpty()) {
finishedPhase = phase;
+ LOG.debug("Source {} finished phase {}", source, phase);
return PhaseCompletionProgress.FINISHED;
}
- if (hasProgressed) {
- return PhaseCompletionProgress.PROGRESS;
- }
- return PhaseCompletionProgress.NO_PROGRESS;
+
+ return hasProgressed ? PhaseCompletionProgress.PROGRESS : PhaseCompletionProgress.NO_PROGRESS;
}
+ finishedPhase + "]";
}
- SourceException failModifiers(final ModelProcessingPhase identifier) {
+ Optional<SourceException> failModifiers(final ModelProcessingPhase identifier) {
final List<SourceException> exceptions = new ArrayList<>();
for (final ModifierImpl mod : modifiers.get(identifier)) {
try {
}
}
- final String message = String.format("Yang model processing phase %s failed", identifier);
if (exceptions.isEmpty()) {
- return new InferenceException(message, root.getStatementSourceReference());
+ return Optional.empty();
}
+ final String message = String.format("Yang model processing phase %s failed", identifier);
final InferenceException e = new InferenceException(message, root.getStatementSourceReference(),
exceptions.get(0));
final Iterator<SourceException> it = exceptions.listIterator(1);
e.addSuppressed(it.next());
}
- return e;
+ return Optional.of(e);
}
void loadStatements() throws SourceException {
+ LOG.trace("Source {} loading statements for phase {}", source, inProgressPhase);
+
switch (inProgressPhase) {
case SOURCE_PRE_LINKAGE:
source.writePreLinkage(new StatementContextWriter(this, inProgressPhase), stmtDef());