import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.model.api.AccessModifier;
import org.opendaylight.mdsal.binding.model.api.Constant;
+import org.opendaylight.mdsal.binding.model.api.Enumeration;
import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
genCtx.put(module.getQNameModule(), context);
allTypeDefinitionsToGenTypes(context);
groupingsToGenTypes(context, module.getGroupings());
- rpcMethodsToGenType(context);
allIdentitiesToGenTypes(context);
- notificationsToGenType(context);
if (!module.getChildNodes().isEmpty()) {
final GeneratedTypeBuilder moduleType = moduleToDataType(context);
context.addModuleNode(moduleType);
resolveDataSchemaNodes(context, moduleType, moduleType, module.getChildNodes(), false);
}
+
+ // Resolve RPCs and notifications only after we have created instantiated tree
+ rpcMethodsToGenType(context);
+ notificationsToGenType(context);
return context;
}
final GeneratedTypeBuilder builder = typeProvider.newGeneratedTypeBuilder(JavaTypeName.create(
packageNameForGeneratedType(context.modulePackageName(), action.getPath()),
BindingMapping.getClassName(qname)));
- qnameConstant(builder, JavaTypeName.create(context.modulePackageName(),
- BindingMapping.MODULE_INFO_CLASS_NAME), qname.getLocalName());
+ qnameConstant(builder, context.moduleInfoType(), qname.getLocalName());
annotateDeprecatedIfNecessary(action, builder);
builder.addImplementsType(keyType != null ? keyedListAction(parent, keyType, input, output)
private Type createRpcContainer(final ModuleContext context, final String rpcName, final RpcDefinition rpc,
final ContainerSchemaNode schema, final Type type) {
processUsesAugments(schema, context, false);
- final GeneratedTypeBuilder outType = addRawInterfaceDefinition(
+ final GeneratedTypeBuilder outType = addRawInterfaceDefinition(context,
JavaTypeName.create(context.modulePackageName(), rpcName + BindingMapping.getClassName(schema.getQName())),
schema);
addImplementedInterfaceFromUses(schema, outType);
newType.setModuleName(module.getName());
newType.setSchemaPath(identity.getPath());
- qnameConstant(newType, JavaTypeName.create(context.modulePackageName(), BindingMapping.MODULE_INFO_CLASS_NAME),
- identity.getQName().getLocalName());
+ qnameConstant(newType, context.moduleInfoType(), identity.getQName().getLocalName());
context.addIdentityType(identity, newType);
}
* @param module Module in which type should be generated
* @return enumeration builder which contains data from <code>enumTypeDef</code>
*/
- private EnumBuilder resolveInnerEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final QName enumName,
+ private Enumeration resolveInnerEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final QName enumName,
final GeneratedTypeBuilder typeBuilder, final ModuleContext context) {
- if (enumTypeDef != null && typeBuilder != null && enumTypeDef.getQName().getLocalName() != null) {
- final EnumBuilder enumBuilder = typeBuilder.addEnumeration(BindingMapping.getClassName(enumName));
- typeProvider.addEnumDescription(enumBuilder, enumTypeDef);
- enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
- context.addInnerTypedefType(enumTypeDef.getPath(), enumBuilder);
- return enumBuilder;
- }
- return null;
+ final EnumBuilder enumBuilder = typeBuilder.addEnumeration(BindingMapping.getClassName(enumName));
+ typeProvider.addEnumDescription(enumBuilder, enumTypeDef);
+ enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
+ final Enumeration ret = enumBuilder.toInstance(typeBuilder);
+ context.addTypeToSchema(ret, enumTypeDef);
+ context.addInnerTypedefType(enumTypeDef.getPath(), ret);
+ return ret;
}
/**
private void choiceToGeneratedType(final ModuleContext context, final GeneratedTypeBuilder parent,
final ChoiceSchemaNode choiceNode, final boolean inGrouping) {
if (!choiceNode.isAddedByUses()) {
- final GeneratedTypeBuilder choiceTypeBuilder = addRawInterfaceDefinition(
+ final GeneratedTypeBuilder choiceTypeBuilder = addRawInterfaceDefinition(context,
JavaTypeName.create(packageNameForGeneratedType(context.modulePackageName(), choiceNode.getPath()),
BindingMapping.getClassName(choiceNode.getQName())), choiceNode);
choiceTypeBuilder.addImplementsType(choiceIn(parent));
private void opaqueToGeneratedType(final ModuleContext context, final GeneratedTypeBuilder parent,
final DataSchemaNode anyNode) {
if (!anyNode.isAddedByUses()) {
- final GeneratedTypeBuilder anyxmlTypeBuilder = addRawInterfaceDefinition(
+ final GeneratedTypeBuilder anyxmlTypeBuilder = addRawInterfaceDefinition(context,
JavaTypeName.create(packageNameForGeneratedType(context.modulePackageName(), anyNode.getPath()),
BindingMapping.getClassName(anyNode.getQName())), anyNode);
anyxmlTypeBuilder.addImplementsType(opaqueObject(anyxmlTypeBuilder)).addImplementsType(childOf(parent));
final TypeDefinition<?> typeDef = CompatUtils.compatType(leaf);
if (isInnerType(leaf, typeDef)) {
if (typeDef instanceof EnumTypeDefinition) {
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, inGrouping);
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
- final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.getQName(),
- typeBuilder, context);
- if (enumBuilder != null) {
- returnType = enumBuilder.toInstance(typeBuilder);
- }
+ returnType = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.getQName(), typeBuilder, context);
typeProvider.putReferencedType(leaf.getPath(), returnType);
} else if (typeDef instanceof UnionTypeDefinition) {
final UnionTypeDefinition unionDef = (UnionTypeDefinition)typeDef;
Type returnType = null;
if (typeDef.getBaseType() == null) {
if (typeDef instanceof EnumTypeDefinition) {
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, inGrouping);
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
- final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, nodeName,
- typeBuilder, context);
- returnType = new ReferencedTypeImpl(enumBuilder.getIdentifier());
+ returnType = resolveInnerEnumFromTypeDefinition(enumTypeDef, nodeName, typeBuilder, context);
typeProvider.putReferencedType(node.getPath(), returnType);
} else if (typeDef instanceof UnionTypeDefinition) {
final UnionTypeDefinition unionDef = (UnionTypeDefinition)typeDef;
name = JavaTypeName.create(packageName, BindingMapping.getClassName(schemaNode.getQName()));
}
- final GeneratedTypeBuilder it = addRawInterfaceDefinition(name, schemaNode);
+ final GeneratedTypeBuilder it = addRawInterfaceDefinition(context, name, schemaNode);
it.addImplementsType(baseInterface);
if (!(schemaNode instanceof GroupingDefinition)) {
it.addImplementsType(augmentable(it));
* <li>if schemaNode name is null</li>
* </ul>
*/
- private GeneratedTypeBuilder addRawInterfaceDefinition(final JavaTypeName identifier, final SchemaNode schemaNode) {
+ private GeneratedTypeBuilder addRawInterfaceDefinition(final ModuleContext context, final JavaTypeName identifier,
+ final SchemaNode schemaNode) {
checkArgument(schemaNode != null, "Data Schema Node cannot be NULL.");
checkArgument(schemaNode.getQName() != null, "QName for Data Schema Node cannot be NULL.");
final String schemaNodeName = schemaNode.getQName().getLocalName();
// FIXME: Validation of name conflict
final GeneratedTypeBuilder newType = typeProvider.newGeneratedTypeBuilder(identifier);
- final Module module = findParentModule(schemaContext, schemaNode);
- qnameConstant(newType, JavaTypeName.create(BindingMapping.getRootPackageName(module.getQNameModule()),
- BindingMapping.MODULE_INFO_CLASS_NAME), schemaNode.getQName().getLocalName());
+ qnameConstant(newType, context.moduleInfoType(), schemaNode.getQName().getLocalName());
+ final Module module = context.module();
addCodegenInformation(newType, module, schemaNode);
newType.setSchemaPath(schemaNode.getPath());
newType.setModuleName(module.getName());
for (final UsesNode usesNode : dataNodeContainer.getUses()) {
final GeneratedTypeBuilder genType = findGroupingByPath(usesNode.getGroupingPath());
if (genType == null) {
- throw new IllegalStateException("Grouping " + usesNode.getGroupingPath() + "is not resolved for "
- + builder.getName());
+ throw new IllegalStateException("Grouping " + usesNode.getGroupingPath() + " is not resolved for "
+ + builder.getFullyQualifiedName());
}
builder.addImplementsType(genType.build());