import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.PathExpression;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
private State state = State.INITIALIZED;
public GeneratorReactor(final EffectiveModelContext context) {
+ super(context);
inferenceStack = SchemaInferenceStack.of(context);
// Construct modules and their subtrees. Dependency sort is very much needed here, as it establishes order of
// AugmentGenerators without having forward references.
// FIXME: migrate to new ModuleDependencySort when it is available, which streamline things here
children = ModuleDependencySort.sort(context.getModules()).stream()
- .map(module -> {
- verify(module instanceof ModuleEffectiveStatement, "Unexpected module %s", module);
- return new ModuleGenerator((ModuleEffectiveStatement) module);
- })
+ .map(Module::asEffectiveStatement)
+ .map(ModuleGenerator::new)
.collect(Collectors.toUnmodifiableList());
generators = Maps.uniqueIndex(children, gen -> gen.statement().localQNameModule());
}
final var augments = new ArrayList<AugmentRequirement>();
for (ModuleGenerator module : children) {
for (Generator gen : module) {
- if (gen instanceof ModuleAugmentGenerator) {
- augments.add(((ModuleAugmentGenerator) gen).startLinkage(this));
+ if (gen instanceof ModuleAugmentGenerator moduleGen) {
+ augments.add(moduleGen.startLinkage(this));
}
}
}
}
LOG.trace("Processing linkage of {} augment generators", augments.size());
- // Step 1c: ... finally establish linkage along the reverse uses/augment axis. This is needed to route generated
- // type manifestations (isAddedByUses/isAugmenting) to their type generation sites. Since generator
- // tree iteration order does not match dependencies, we may need to perform multiple passes.
+ // Step 1c: Establish linkage along the reverse uses/augment axis. This is needed to route generated type
+ // manifestations (isAddedByUses/isAugmenting) to their type generation sites. Since generator tree
+ // iteration order does not match dependencies, we may need to perform multiple passes.
for (ModuleGenerator module : children) {
verify(module.linkOriginalGenerator(), "Module %s failed to link", module);
}
for (Generator gen : parent) {
gen.ensureMember();
collectCollisionDomains(result, gen);
- if (gen instanceof AbstractCompositeGenerator) {
- result.add(((AbstractCompositeGenerator<?>) gen).domain());
+ if (gen instanceof AbstractCompositeGenerator<?, ?> compositeGen) {
+ result.add(compositeGen.domain());
}
}
}
@Override
- <E extends EffectiveStatement<QName, ?>, G extends AbstractExplicitGenerator<E>> G resolveTreeScoped(
+ <E extends EffectiveStatement<QName, ?>, G extends AbstractExplicitGenerator<E, ?>> G resolveTreeScoped(
final Class<G> type, final QName argument) {
LOG.trace("Searching for tree-scoped argument {} at {}", argument, stack);
}
@Override
- AbstractTypeObjectGenerator<?> resolveLeafref(final PathExpression path) {
+ AbstractTypeObjectGenerator<?, ?> resolveLeafref(final PathExpression path) {
LOG.trace("Resolving path {}", path);
verify(inferenceStack.isEmpty(), "Unexpected data tree state %s", inferenceStack);
try {
}
}
- private @NonNull AbstractTypeAwareGenerator<?> strictResolvePath(final @NonNull PathExpression path) {
+ private @NonNull AbstractTypeAwareGenerator<?, ?, ?> strictResolvePath(final @NonNull PathExpression path) {
try {
inferenceStack.resolvePathExpression(path);
} catch (IllegalArgumentException e) {
return mapToGenerator();
}
- private @Nullable AbstractTypeAwareGenerator<?> lenientResolveLeafref(final @NonNull PathExpression path) {
+ private @Nullable AbstractTypeAwareGenerator<?, ?, ?> lenientResolveLeafref(final @NonNull PathExpression path) {
try {
inferenceStack.resolvePathExpression(path);
} catch (IllegalArgumentException e) {
}
// Map a statement to the corresponding generator
- private @NonNull AbstractTypeAwareGenerator<?> mapToGenerator() {
+ private @NonNull AbstractTypeAwareGenerator<?, ?, ?> mapToGenerator() {
// Some preliminaries first: we need to be in the correct module to walk the path
final ModuleEffectiveStatement module = inferenceStack.currentModule();
final ModuleGenerator gen = verifyNotNull(generators.get(module.localQNameModule()),
// Now kick of the search
final List<EffectiveStatement<?, ?>> stmtPath = inferenceStack.toInference().statementPath();
- final AbstractExplicitGenerator<?> found = gen.findGenerator(stmtPath);
- if (found instanceof AbstractTypeAwareGenerator) {
- return (AbstractTypeAwareGenerator<?>) found;
+ final AbstractExplicitGenerator<?, ?> found = gen.findGenerator(stmtPath);
+ if (found instanceof AbstractTypeAwareGenerator<?, ?, ?> typeAware) {
+ return typeAware;
}
throw new VerifyException("Statements " + stmtPath + " resulted in unexpected " + found);
}
// Note: unlike other methods, this method pushes matching child to the stack
private void linkUsesDependencies(final Iterable<? extends Generator> parent) {
for (Generator child : parent) {
- if (child instanceof AbstractCompositeGenerator) {
- LOG.trace("Visiting composite {}", child);
- final AbstractCompositeGenerator<?> composite = (AbstractCompositeGenerator<?>) child;
+ if (child instanceof AbstractCompositeGenerator<?, ?> composite) {
+ LOG.trace("Visiting composite {}", composite);
stack.push(composite);
composite.linkUsesDependencies(this);
linkUsesDependencies(composite);
private void linkDependencies(final Iterable<? extends Generator> parent) {
for (Generator child : parent) {
- if (child instanceof AbstractDependentGenerator) {
- ((AbstractDependentGenerator<?>) child).linkDependencies(this);
+ if (child instanceof AbstractDependentGenerator<?, ?> dependent) {
+ dependent.linkDependencies(this);
} else if (child instanceof AbstractCompositeGenerator) {
stack.push(child);
linkDependencies(child);
private void bindTypeDefinition(final Iterable<? extends Generator> parent) {
for (Generator child : parent) {
stack.push(child);
- if (child instanceof AbstractTypeObjectGenerator) {
- ((AbstractTypeObjectGenerator<?>) child).bindTypeDefinition(this);
+ if (child instanceof AbstractTypeObjectGenerator<?, ?> typeObject) {
+ typeObject.bindTypeDefinition(this);
} else if (child instanceof AbstractCompositeGenerator) {
bindTypeDefinition(child);
}