import static org.opendaylight.mdsal.binding.model.util.BindingTypes.identifiable;
import static org.opendaylight.mdsal.binding.model.util.BindingTypes.identifier;
import static org.opendaylight.mdsal.binding.model.util.BindingTypes.keyedListAction;
+import static org.opendaylight.mdsal.binding.model.util.BindingTypes.opaqueObject;
import static org.opendaylight.mdsal.binding.model.util.BindingTypes.rpcResult;
import static org.opendaylight.mdsal.binding.model.util.Types.BOOLEAN;
import static org.opendaylight.mdsal.binding.model.util.Types.STRING;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
}
final GeneratedTypeBuilder genType = addDefaultInterfaceDefinition(context, node, baseInterface);
defaultImplementedInterace(genType);
- annotateDeprecatedIfNecessary(node.getStatus(), genType);
+ annotateDeprecatedIfNecessary(node, genType);
final Module module = context.module();
genType.setModuleName(module.getName());
private <T extends DataNodeContainer & ActionNodeContainer> void actionsToGenType(final ModuleContext context,
final Type parent, final T parentSchema, final Type keyType, final boolean inGrouping) {
for (final ActionDefinition action : parentSchema.getActions()) {
+ if (action.isAugmenting()) {
+ continue;
+ }
+
final GeneratedType input;
final GeneratedType output;
if (action.isAddedByUses()) {
qnameConstant(builder, JavaTypeName.create(context.modulePackageName(),
BindingMapping.MODULE_INFO_CLASS_NAME), qname.getLocalName());
- annotateDeprecatedIfNecessary(action.getStatus(), builder);
+ annotateDeprecatedIfNecessary(action, builder);
builder.addImplementsType(keyType != null ? keyedListAction(parent, keyType, input, output)
: action(parent, input, output));
private Optional<ActionDefinition> findOrigAction(final DataNodeContainer parent, final ActionDefinition action) {
for (UsesNode uses : parent.getUses()) {
final GroupingDefinition grp = findUsedGrouping(uses);
- final Optional<ActionDefinition> found = grp.getActions().stream()
- .filter(act -> action.getQName().equals(act.getQName())).findFirst();
+ final Optional<ActionDefinition> found = grp.findAction(action.getQName());
if (found.isPresent()) {
final ActionDefinition result = found.get();
return result.isAddedByUses() ? findOrigAction(grp, result) : found;
outType.addImplementsType(type);
outType.addImplementsType(augmentable(outType));
defaultImplementedInterace(outType);
- annotateDeprecatedIfNecessary(rpc.getStatus(), outType);
+ annotateDeprecatedIfNecessary(rpc, outType);
resolveDataSchemaNodes(context, outType, outType, schema.getChildNodes(), false);
context.addChildNodeType(schema, outType);
return outType.build();
final GeneratedTypeBuilder notificationInterface = addDefaultInterfaceDefinition(
context.modulePackageName(), notification, DATA_OBJECT, context);
defaultImplementedInterace(notificationInterface);
- annotateDeprecatedIfNecessary(notification.getStatus(), notificationInterface);
+ annotateDeprecatedIfNecessary(notification, notificationInterface);
notificationInterface.addImplementsType(NOTIFICATION);
context.addChildNodeType(notification, notificationInterface);
// node of grouping is resolved to the method.
final GeneratedTypeBuilder genType = addDefaultInterfaceDefinition(context, grouping);
narrowImplementedInterface(genType);
- annotateDeprecatedIfNecessary(grouping.getStatus(), genType);
+ annotateDeprecatedIfNecessary(grouping, genType);
context.addGroupingType(grouping, genType);
resolveDataSchemaNodes(context, genType, genType, grouping.getChildNodes(), true);
groupingsToGenTypes(context, grouping.getGroupings());
defaultImplementedInterace(augTypeBuilder);
augTypeBuilder.addImplementsType(augmentationTypeFor(targetTypeRef));
- annotateDeprecatedIfNecessary(augSchema.getStatus(), augTypeBuilder);
+ annotateDeprecatedIfNecessary(augSchema, augTypeBuilder);
addImplementedInterfaceFromUses(augSchema, augTypeBuilder);
augSchemaNodeToMethods(context, augTypeBuilder, augSchema.getChildNodes(), inGrouping);
+ actionsToGenType(context, augTypeBuilder, augSchema, null, inGrouping);
augmentBuilders.put(augTypeName, augTypeBuilder);
if (!augSchema.getChildNodes().isEmpty()) {
context.addTypeToAugmentation(augTypeBuilder, augSchema);
-
}
+
context.addAugmentType(augTypeBuilder);
return augTypeBuilder;
}
listToGenType(context, typeBuilder, baseInterface, (ListSchemaNode) node, inGrouping);
} else if (node instanceof ChoiceSchemaNode) {
choiceToGeneratedType(context, typeBuilder, (ChoiceSchemaNode) node, inGrouping);
+ } else if (node instanceof AnyxmlSchemaNode || node instanceof AnydataSchemaNode) {
+ opaqueToGeneratedType(context, typeBuilder, node);
} else {
- // TODO: anyxml not yet supported
LOG.debug("Unable to add schema node {} as method in {}: unsupported type of node.", node.getClass(),
typeBuilder.getFullyQualifiedName());
}
*/
private void choiceToGeneratedType(final ModuleContext context, final GeneratedTypeBuilder parent,
final ChoiceSchemaNode choiceNode, final boolean inGrouping) {
- checkArgument(choiceNode != null, "Choice Schema Node cannot be NULL.");
-
if (!choiceNode.isAddedByUses()) {
final GeneratedTypeBuilder choiceTypeBuilder = addRawInterfaceDefinition(
JavaTypeName.create(packageNameForGeneratedType(context.modulePackageName(), choiceNode.getPath()),
BindingMapping.getClassName(choiceNode.getQName())), choiceNode);
choiceTypeBuilder.addImplementsType(choiceIn(parent));
- annotateDeprecatedIfNecessary(choiceNode.getStatus(), choiceTypeBuilder);
+ annotateDeprecatedIfNecessary(choiceNode, choiceTypeBuilder);
context.addChildNodeType(choiceNode, choiceTypeBuilder);
final GeneratedType choiceType = choiceTypeBuilder.build();
}
}
+ private void opaqueToGeneratedType(final ModuleContext context, final GeneratedTypeBuilder parent,
+ final DataSchemaNode anyNode) {
+ if (!anyNode.isAddedByUses()) {
+ final GeneratedTypeBuilder anyxmlTypeBuilder = addRawInterfaceDefinition(
+ JavaTypeName.create(packageNameForGeneratedType(context.modulePackageName(), anyNode.getPath()),
+ BindingMapping.getClassName(anyNode.getQName())), anyNode);
+ anyxmlTypeBuilder.addImplementsType(opaqueObject(anyxmlTypeBuilder)).addImplementsType(childOf(parent));
+ defaultImplementedInterace(anyxmlTypeBuilder);
+ annotateDeprecatedIfNecessary(anyNode, anyxmlTypeBuilder);
+ context.addChildNodeType(anyNode, anyxmlTypeBuilder);
+
+ constructGetter(parent, anyxmlTypeBuilder.build(), anyNode);
+ }
+ }
+
/**
* Converts <code>caseNodes</code> set to list of corresponding generated types. For every <i>case</i> which is not
* added through augment or <i>uses</i> is created generated type builder. The package names for the builder is
final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(context, caseNode);
caseTypeBuilder.addImplementsType(refChoiceType);
defaultImplementedInterace(caseTypeBuilder);
- annotateDeprecatedIfNecessary(caseNode.getStatus(), caseTypeBuilder);
+ annotateDeprecatedIfNecessary(caseNode, caseTypeBuilder);
context.addCaseType(caseNode.getPath(), caseTypeBuilder);
context.addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
getterMethodName(node.getQName().getLocalName(), returnType));
getMethod.setReturnType(returnType);
- annotateDeprecatedIfNecessary(node.getStatus(), getMethod);
+ annotateDeprecatedIfNecessary(node, getMethod);
addComment(getMethod, node);
return getMethod;
final MethodSignatureBuilder getMethod = interfaceBuilder.addMethod(
BindingMapping.getNonnullMethodName(node.getQName().getLocalName()));
getMethod.setReturnType(returnType).setDefault(true);
- annotateDeprecatedIfNecessary(node.getStatus(), getMethod);
+ annotateDeprecatedIfNecessary(node, getMethod);
}
/**
private Type addTOToTypeBuilder(final UnionTypeDefinition typeDef,
final GeneratedTypeBuilder typeBuilder, final DataSchemaNode leaf, final Module parentModule) {
final List<GeneratedTOBuilder> types = typeProvider.provideGeneratedTOBuildersForUnionTypeDef(
- typeBuilder.getIdentifier().createEnclosed(BindingMapping.getClassName(leaf.getQName())),
- typeDef, leaf);
+ allocateNestedType(typeBuilder.getIdentifier(), leaf.getQName()), typeDef, leaf);
checkState(!types.isEmpty(), "No GeneratedTOBuilder objects generated from union %s", typeDef);
final List<GeneratedTOBuilder> genTOBuilders = new ArrayList<>(types);
private GeneratedTOBuilder addTOToTypeBuilder(final BitsTypeDefinition typeDef,
final GeneratedTypeBuilder typeBuilder, final DataSchemaNode leaf, final Module parentModule) {
final GeneratedTOBuilder genTOBuilder = typeProvider.provideGeneratedTOBuilderForBitsTypeDefinition(
- typeBuilder.getIdentifier().createEnclosed(BindingMapping.getClassName(leaf.getQName())),
- typeDef, parentModule.getName());
+ allocateNestedType(typeBuilder.getIdentifier(), leaf.getQName()), typeDef, parentModule.getName());
typeBuilder.addEnclosingTransferObject(genTOBuilder);
return genTOBuilder;
-
}
/**
private GeneratedTypeBuilder addImplementedInterfaceFromUses(final DataNodeContainer dataNodeContainer,
final GeneratedTypeBuilder builder) {
for (final UsesNode usesNode : dataNodeContainer.getUses()) {
- final GeneratedType genType = findGroupingByPath(usesNode.getGroupingPath()).build();
+ final GeneratedTypeBuilder genType = findGroupingByPath(usesNode.getGroupingPath());
if (genType == null) {
throw new IllegalStateException("Grouping " + usesNode.getGroupingPath() + "is not resolved for "
+ builder.getName());
}
- builder.addImplementsType(genType);
+ builder.addImplementsType(genType.build());
}
return builder;
}
return null;
}
- private static void annotateDeprecatedIfNecessary(final Status status, final AnnotableTypeBuilder builder) {
- if (status == Status.DEPRECATED) {
- builder.addAnnotation(DEPRECATED_ANNOTATION);
+ private static JavaTypeName allocateNestedType(final JavaTypeName parent, final QName child) {
+ // Single '$' suffix cannot come from user, this mirrors AbstractGeneratedTypeBuilder.addEnumeration()
+ return parent.createEnclosed(BindingMapping.getClassName(child), "$");
+ }
+
+ private static void annotateDeprecatedIfNecessary(final WithStatus node, final AnnotableTypeBuilder builder) {
+ switch (node.getStatus()) {
+ case DEPRECATED:
+ // FIXME: we really want to use a pre-made annotation
+ builder.addAnnotation(DEPRECATED_ANNOTATION);
+ break;
+ case OBSOLETE:
+ builder.addAnnotation(DEPRECATED_ANNOTATION).addParameter("forRemoval", "true");
+ break;
+ case CURRENT:
+ // No-op
+ break;
+ default:
+ throw new IllegalStateException("Unhandled status in " + node);
}
}