static @NonNull BindingRuntimeTypes createTypes(final @NonNull EffectiveModelContext context) {
final var moduleGens = new GeneratorReactor(context).execute(TypeBuilderFactory.runtime());
- final Stopwatch sw = Stopwatch.createStarted();
- final BindingRuntimeTypesFactory factory = new BindingRuntimeTypesFactory();
+ final var sw = Stopwatch.createStarted();
+ final var factory = new BindingRuntimeTypesFactory();
factory.indexModules(moduleGens);
LOG.debug("Indexed {} generators in {}", moduleGens.size(), sw);
final var modGen = entry.getValue();
// index the module's runtime type
- safePut(modules, "modules", entry.getKey(), modGen.runtimeType().orElseThrow());
+ safePut(modules, "modules", entry.getKey(), modGen.getRuntimeType());
// index module's identities and RPC input/outputs
for (var gen : modGen) {
if (gen instanceof IdentityGenerator idGen) {
- idGen.runtimeType().ifPresent(identity -> {
- safePut(identities, "identities", identity.statement().argument(), identity);
- });
+ safePut(identities, "identities", idGen.statement().argument(), idGen.getRuntimeType());
}
}
}
}
private void indexRuntimeTypes(final Iterable<? extends Generator> generators) {
- for (Generator gen : generators) {
- if (gen instanceof AbstractExplicitGenerator<?, ?> explicitGen && gen.generatedType().isPresent()) {
- final var type = explicitGen.runtimeType().orElseThrow();
- if (type.javaType() instanceof GeneratedType genType) {
+ for (var gen : generators) {
+ if (gen instanceof AbstractExplicitGenerator<?, ?> explicit) {
+ final var type = explicit.generatedRuntimeType();
+ if (type != null && type.javaType() instanceof GeneratedType genType) {
final var name = genType.getIdentifier();
final var prev = allTypes.put(name, type);
verify(prev == null || prev == type, "Conflict on runtime type mapping of %s between %s and %s",
name, prev, type);
// Global indexing of cases generated for a particular choice. We look at the Generated type
- // and make assumptions about its shape -- which works just fine without touching the
- // ChoiceRuntimeType for cases.
+ // and make assumptions about its shape -- which works just fine without touching
+ // the ChoiceRuntimeType for cases.
if (type instanceof CaseRuntimeType caseType) {
final var ifaces = genType.getImplements();
// The appropriate choice and DataObject at the very least. The choice interface is the first
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
import org.kohsuke.MetaInfServices;
import org.opendaylight.mdsal.binding.generator.BindingGenerator;
import org.opendaylight.mdsal.binding.generator.impl.reactor.Generator;
import org.opendaylight.mdsal.binding.generator.impl.reactor.GeneratorReactor;
-import org.opendaylight.mdsal.binding.generator.impl.reactor.ModuleGenerator;
import org.opendaylight.mdsal.binding.generator.impl.reactor.TypeBuilderFactory;
import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
/**
* Default implementation of {@link BindingGenerator}.
@VisibleForTesting
static @NonNull List<GeneratedType> generateFor(final EffectiveModelContext context,
final Collection<? extends Module> modules) {
- final Set<ModuleEffectiveStatement> filter = modules.stream().map(Module::asEffectiveStatement)
+ final var filter = modules.stream().map(Module::asEffectiveStatement)
.collect(Collectors.toUnmodifiableSet());
- final List<GeneratedType> result = new ArrayList<>();
- for (ModuleGenerator gen : new GeneratorReactor(context).execute(TypeBuilderFactory.codegen()).values()) {
+ final var result = new ArrayList<GeneratedType>();
+ for (var gen : new GeneratorReactor(context).execute(TypeBuilderFactory.codegen()).values()) {
if (filter.contains(gen.statement())) {
addTypes(result, gen);
}
}
private static void addTypes(final List<GeneratedType> result, final Generator gen) {
- gen.generatedType()
- .filter(type -> type.getIdentifier().immediatelyEnclosingClass().isEmpty())
- .ifPresent(result::add);
+ final var type = gen.generatedType();
+ if (type != null) {
+ if (type.getIdentifier().immediatelyEnclosingClass().isEmpty()) {
+ result.add(type);
+ }
+ }
+
result.addAll(gen.auxiliaryGeneratedTypes());
- for (Generator child : gen) {
+ for (var child : gen) {
addTypes(result, child);
}
}
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.VerifyException;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.generator.impl.reactor.CollisionDomain.Member;
}
/**
- * Return the {@link RuntimeType} associated with this object, if applicable. This represents the
- * externally-accessible view of this object when considered outside the schema tree or binding tree hierarchy.
+ * Return the {@link RuntimeType} associated with this objec, if applicablet. This represents
+ * the externally-accessible view of this object when considered outside the schema tree or binding tree hierarchy.
*
- * @return Associated run-time type, or empty
+ * @return Associated run-time type, or {@code null}
*/
- public final Optional<R> runtimeType() {
+ public final @Nullable R generatedRuntimeType() {
+ final var type = generatedType();
+ return type == null ? null : runtimeType();
+ }
+
+ private @Nullable R runtimeType() {
if (!runtimeTypeInitialized) {
final var type = runtimeJavaType();
if (type != null) {
}
runtimeTypeInitialized = true;
}
- return Optional.ofNullable(runtimeType);
+ return runtimeType;
+ }
+
+ /**
+ * Return the {@link RuntimeType} associated with this object. This represents the externally-accessible view of
+ * this object when considered outside the schema tree or binding tree hierarchy.
+ *
+ * @return Associated run-time type
+ */
+ public final @NonNull R getRuntimeType() {
+ final var local = runtimeType();
+ if (local == null) {
+ throw new VerifyException(this + " does not have a run-time type");
+ }
+ return local;
}
/**
// FIXME: this should be a generic class argument
// FIXME: this needs a better name, but 'runtimeType' is already taken.
@Nullable Type runtimeJavaType() {
- return generatedType().orElse(null);
+ return generatedType();
}
/**
}
final @NonNull QName getQName() {
- final Object arg = statement.argument();
+ final var arg = statement.argument();
if (arg instanceof QName qname) {
return qname;
}
@NonNull AbstractQName localName() {
// FIXME: this should be done in a nicer way
- final Object arg = statement.argument();
+ final var arg = statement.argument();
if (arg instanceof AbstractQName aqn) {
return aqn;
}
return;
}
- final Type returnType = methodReturnType(builderFactory);
+ final var returnType = methodReturnType(builderFactory);
constructGetter(builder, returnType);
constructRequire(builder, returnType);
}
final MethodSignatureBuilder constructGetter(final GeneratedTypeBuilderBase<?> builder,
final Type returnType, final String methodName) {
- final MethodSignatureBuilder getMethod = builder.addMethod(methodName).setReturnType(returnType);
+ final var getMethod = builder.addMethod(methodName).setReturnType(returnType);
annotateDeprecatedIfNecessary(getMethod);
return methodReturnTypeElement;
}
final var genType = generatedType();
- if (genType.isPresent()) {
- return genType.orElseThrow();
+ if (genType != null) {
+ return genType;
}
final var prev = verifyNotNull(previous(), "No previous generator for %s", this);
return prev.runtimeJavaType();
this.parent = requireNonNull(parent);
}
- public final @NonNull Optional<GeneratedType> generatedType() {
- return Optional.ofNullable(result.generatedType());
+ public final @Nullable GeneratedType generatedType() {
+ return result.generatedType();
}
public @NonNull List<GeneratedType> auxiliaryGeneratedTypes() {
private @Nullable KeyRuntimeType keyRuntimeType() {
final var local = keyGen;
- return local != null ? local.runtimeType().orElseThrow() : null;
+ return local != null ? local.getRuntimeType() : null;
}
@Override
import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultModuleRuntimeType;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
-import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
@Override
GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
- final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
+ final var builder = builderFactory.newGeneratedTypeBuilder(typeName());
builder.setModuleName(statement().argument().getLocalName());
builder.addImplementsType(BindingTypes.DATA_ROOT);
final var yangDataChildren = new ArrayList<YangDataRuntimeType>();
for (var child : ModuleGenerator.this) {
if (child instanceof YangDataGenerator yangDataGen) {
- yangDataGen.runtimeType().ifPresent(yangDataChildren::add);
+ yangDataChildren.add(yangDataGen.getRuntimeType());
}
}