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;
import org.opendaylight.mdsal.binding.generator.impl.tree.StatementRepresentation;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.MethodSignature.ValueMechanics;
import org.opendaylight.mdsal.binding.model.api.Type;
import org.opendaylight.mdsal.binding.model.api.TypeMemberComment;
import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder;
import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
-import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
+import org.opendaylight.yangtools.yang.binding.contract.Naming;
import org.opendaylight.yangtools.yang.common.AbstractQName;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AddedByUsesAware;
/**
* An explicit {@link Generator}, associated with a particular {@link EffectiveStatement}.
*/
+// FIXME: unify this with Generator
public abstract class AbstractExplicitGenerator<S extends EffectiveStatement<?, ?>, R extends RuntimeType>
extends Generator implements CopyableNode, StatementRepresentation<S> {
private static final Logger LOG = LoggerFactory.getLogger(AbstractExplicitGenerator.class);
}
/**
- * 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);
}
MethodSignatureBuilder constructGetter(final GeneratedTypeBuilderBase<?> builder, final Type returnType) {
- return constructGetter(builder, returnType, BindingMapping.getGetterMethodName(localName().getLocalName()));
+ return constructGetter(builder, returnType, Naming.getGetterMethodName(localName().getLocalName()));
}
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);
}
final void constructRequireImpl(final GeneratedTypeBuilderBase<?> builder, final Type returnType) {
- constructGetter(builder, returnType, BindingMapping.getRequireMethodName(localName().getLocalName()))
+ constructGetter(builder, returnType, Naming.getRequireMethodName(localName().getLocalName()))
.setDefault(true)
.setMechanics(ValueMechanics.NONNULL);
}
}
return helper;
}
+
+ static final @NonNull GeneratedType verifyGeneratedType(final Type type) {
+ if (type instanceof GeneratedType ret) {
+ return ret;
+ }
+ throw new VerifyException("Unexpected type " + type);
+ }
}