*/
void setModuleName(String moduleName);
- /**
- * Set the base package name of the module, used to generate package name for
- * builders by reusing the original package name.
- *
- * @param basePackageName
- * the base package name of the module
- */
- void setBasePackageName(String basePackageName);
-
/**
* Set a list of QNames which represent schema path in schema tree from
* actual concrete type to the root.
for (final AugmentationSchema augmentationSchema : schemaPathAugmentListEntry) {
for (final DataSchemaNode caseNode : augmentationSchema.getChildNodes()) {
if (caseNode != null) {
- final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName,
- caseNode.getPath(), BindingNamespaceType.Data);
- final GeneratedTypeBuilder caseTypeBuilder = GenHelperUtil.addDefaultInterfaceDefinition(packageName,
+ final GeneratedTypeBuilder caseTypeBuilder = GenHelperUtil.addDefaultInterfaceDefinition(basePackageName,
caseNode, module, genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider,
namespaceType);
caseTypeBuilder.addImplementsType(targetType);
import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.encodeAngleBrackets;
+import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.replacePackageTopNamespace;
import static org.opendaylight.mdsal.binding.javav2.generator.util.Types.BOOLEAN;
import com.google.common.annotations.Beta;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
+import org.opendaylight.mdsal.binding.javav2.generator.api.BindingGenerator;
import org.opendaylight.mdsal.binding.javav2.generator.impl.txt.yangTemplateForModule;
import org.opendaylight.mdsal.binding.javav2.generator.impl.txt.yangTemplateForNode;
import org.opendaylight.mdsal.binding.javav2.generator.impl.txt.yangTemplateForNodes;
import org.opendaylight.mdsal.binding.javav2.generator.impl.util.YangTextTemplate;
import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
+import org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil;
import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier;
import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer;
import org.opendaylight.mdsal.binding.javav2.generator.util.Types;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilderBase;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.MethodSignatureBuilder;
import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingNamespaceType;
+import org.opendaylight.mdsal.binding.javav2.util.BindingMapping;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@Beta
final class AuxiliaryGenUtils {
- private static final Splitter BSDOT_SPLITTER = Splitter.on("\\.");
+ private static final Splitter BSDOT_SPLITTER = Splitter.on(".");
private static final char NEW_LINE = '\n';
private static final Pattern UNICODE_CHAR_PATTERN = Pattern.compile("\\\\+u");
}
}
- private static boolean hasBuilderClass(final SchemaNode schemaNode) {
- if (schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode ||
- schemaNode instanceof RpcDefinition || schemaNode instanceof NotificationDefinition) {
+ public static boolean hasBuilderClass(final SchemaNode schemaNode, final BindingNamespaceType namespaceType) {
+ if ((namespaceType.equals(BindingNamespaceType.Data)
+ && (schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode ||
+ schemaNode instanceof RpcDefinition || schemaNode instanceof NotificationDefinition))) {
return true;
}
return false;
}
static String createDescription(final SchemaNode schemaNode, final String fullyQualifiedName,
- final SchemaContext schemaContext, final boolean verboseClassComments) {
+ final SchemaContext schemaContext, final boolean verboseClassComments,
+ final BindingNamespaceType namespaceType) {
final StringBuilder sb = new StringBuilder();
final String nodeDescription = encodeAngleBrackets(schemaNode.getDescription());
final String formattedDescription = YangTextTemplate.formatToParagraph(nodeDescription, 0);
sb.append(NEW_LINE);
}
+ final Module module = SchemaContextUtil.findParentModule(schemaContext, schemaNode);
if (verboseClassComments) {
- final Module module = SchemaContextUtil.findParentModule(schemaContext, schemaNode);
- final StringBuilder linkToBuilderClass = new StringBuilder();
- final String[] namespace = Iterables.toArray(BSDOT_SPLITTER.split(fullyQualifiedName), String.class);
- final String className = namespace[namespace.length - 1];
-
- if (hasBuilderClass(schemaNode)) {
- linkToBuilderClass.append(className);
- linkToBuilderClass.append("Builder");
- }
-
sb.append("<p>");
sb.append("This class represents the following YANG schema fragment defined in module <b>");
sb.append(module.getName());
sb.append("</i>");
sb.append(NEW_LINE);
- if (hasBuilderClass(schemaNode) && !(schemaNode instanceof OperationDefinition)) {
+ if (hasBuilderClass(schemaNode, namespaceType) && !(schemaNode instanceof OperationDefinition)) {
+ final StringBuilder linkToBuilderClass = new StringBuilder();
+ final String basePackageName = BindingMapping.getRootPackageName(module);
+
+ linkToBuilderClass
+ .append(replacePackageTopNamespace(basePackageName, fullyQualifiedName,
+ namespaceType, BindingNamespaceType.Builder))
+ .append("Builder");
sb.append(NEW_LINE);
sb.append("<p>To create instances of this class use " + "{@link " + linkToBuilderClass + "}.");
sb.append(NEW_LINE);
sb.append(linkToBuilderClass);
sb.append(NEW_LINE);
if (schemaNode instanceof ListSchemaNode) {
+ final StringBuilder linkToKeyClass = new StringBuilder();
+
+ final String[] namespace = Iterables.toArray(BSDOT_SPLITTER.split(fullyQualifiedName), String.class);
+ final String className = namespace[namespace.length - 1];
+
+ linkToKeyClass.append(BindingGeneratorUtil.packageNameForSubGeneratedType(basePackageName, schemaNode,
+ BindingNamespaceType.Key))
+ .append('.')
+ .append(className)
+ .append("Key");
+
final List<QName> keyDef = ((ListSchemaNode)schemaNode).getKeyDefinition();
if (keyDef != null && !keyDef.isEmpty()) {
sb.append("@see ");
- sb.append(className);
- sb.append("Key");
+ sb.append(linkToKeyClass).append(className).append("Key");
}
sb.append(NEW_LINE);
}
moduleBuilder.setDescription(createDescription(module, verboseClassComments));
moduleBuilder.setReference(module.getReference());
moduleBuilder.setModuleName(moduleName);
- moduleBuilder.setBasePackageName(packageName);
return moduleBuilder;
}
return parent;
}
- static GeneratedTypeBuilder addDefaultInterfaceDefinition(final String packageName, final SchemaNode
+ static GeneratedTypeBuilder addDefaultInterfaceDefinition(final String basePackageName, final SchemaNode
schemaNode, final Module module, final Map<Module, ModuleContext> genCtx, final SchemaContext schemaContext,
final boolean verboseClassComments, final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders,
final TypeProvider typeProvider, final BindingNamespaceType namespaceType) {
- return addDefaultInterfaceDefinition(packageName, schemaNode, null, module, genCtx, schemaContext,
+ return addDefaultInterfaceDefinition(basePackageName, schemaNode, null, module, genCtx, schemaContext,
verboseClassComments, genTypeBuilders, typeProvider , namespaceType);
}
isTypeNormalized = true;
}
- GeneratedTypeBuilder augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augIdentifier,
+ GeneratedTypeBuilderImpl augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augIdentifier,
false, isTypeNormalized);
augTypeBuilder.addImplementsType(BindingTypes.TREE_NODE);
augTypeBuilder.addImplementsType(parameterizedTypeFor(BindingTypes.INSTANTIABLE, augTypeBuilder));
augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef));
augTypeBuilder.setBasePackageName(BindingMapping.getRootPackageName(module));
+ if (namespaceType.equals(BindingNamespaceType.Data)) {
+ augTypeBuilder.setWithBuilder(true);
+ }
annotateDeprecatedIfNecessary(augSchema.getStatus(), augTypeBuilder);
//produces getters for augTypeBuilder eventually
* DataNodeContainer} it can also implement nodes which are specified in
* <i>uses</i>.
*
- * @param packageName
- * string with the name of the package to which
- * <code>schemaNode</code> belongs.
+ * @param basePackageName
+ * string contains the module package name
* @param schemaNode
* schema node for which is created generated type builder
* @param parent
* @param schemaContext schema context
* @return generated type builder <code>schemaNode</code>
*/
- private static GeneratedTypeBuilder addDefaultInterfaceDefinition(final String packageName, final SchemaNode
+ private static GeneratedTypeBuilder addDefaultInterfaceDefinition(final String basePackageName, final SchemaNode
schemaNode, final Type parent, final Module module, final Map<Module, ModuleContext> genCtx,
final SchemaContext schemaContext, final boolean verboseClassComments, final Map<String, Map<String,
GeneratedTypeBuilder>> genTypeBuilders, final TypeProvider typeProvider, final BindingNamespaceType namespaceType) {
String suffix = "";
if (schemaNode instanceof GroupingDefinition) {
suffix = "grouping";
- } else if (namespaceType.equals(BindingNamespaceType.Grouping)){
+ } else if (namespaceType.equals(BindingNamespaceType.Grouping)) {
suffix = "data";
}
- GeneratedTypeBuilder it = addRawInterfaceDefinition(packageName, schemaNode, schemaContext, "", suffix,
- verboseClassComments, genTypeBuilders);
- if (parent == null) {
- it.addImplementsType(BindingTypes.TREE_NODE);
- } else {
- if (parent instanceof ListSchemaNode) {
- it.addImplementsType(parameterizedTypeFor(BindingTypes.TREE_CHILD_NODE, parent, parameterizedTypeFor
- (BindingTypes.IDENTIFIABLE_ITEM, parent)));
+ GeneratedTypeBuilder it = addRawInterfaceDefinition(basePackageName, schemaNode, schemaContext, "", suffix,
+ verboseClassComments, genTypeBuilders, namespaceType);
+ if (namespaceType.equals(BindingNamespaceType.Data)) {
+ if (parent == null) {
+ it.addImplementsType(BindingTypes.TREE_NODE);
} else {
- it.addImplementsType(parameterizedTypeFor(BindingTypes.TREE_CHILD_NODE, parent, parameterizedTypeFor
- (BindingTypes.ITEM, parent)));
- it.addImplementsType(parameterizedTypeFor(BindingTypes.INSTANTIABLE, it));
+ if (parent instanceof ListSchemaNode) {
+ it.addImplementsType(parameterizedTypeFor(BindingTypes.TREE_CHILD_NODE, parent, parameterizedTypeFor
+ (BindingTypes.IDENTIFIABLE_ITEM, parent)));
+ } else {
+ it.addImplementsType(parameterizedTypeFor(BindingTypes.TREE_CHILD_NODE, parent, parameterizedTypeFor
+ (BindingTypes.ITEM, parent)));
+ it.addImplementsType(parameterizedTypeFor(BindingTypes.INSTANTIABLE, it));
+ }
+ }
+
+ if (!(schemaNode instanceof GroupingDefinition)) {
+ it.addImplementsType(BindingTypes.augmentable(it));
}
- }
- //TODO: it's not correct for some special cases
- if (namespaceType.equals(BindingNamespaceType.Data) && !(schemaNode instanceof GroupingDefinition)) {
- it.addImplementsType(BindingTypes.augmentable(it));
+ if (schemaNode instanceof DerivableSchemaNode
+ && ((DerivableSchemaNode) schemaNode).isAddedByUses()) {
+ //TODO: The schema path of child node is not unique for YANG 1.1
+ final GeneratedTypeBuilder originalType =
+ findChildNodeByPath(((DerivableSchemaNode) schemaNode).getOriginal().get().getPath(), genCtx);
+ Preconditions.checkState(originalType != null, "Original type can not be null!");
+ it.addImplementsType(originalType.toInstance());
+ }
+
+ } else {
+ it.addImplementsType(BindingTypes.TREE_NODE);
}
if (schemaNode instanceof DataNodeContainer) {
processUsesAugments(schemaContext, notification, module, genCtx, genTypeBuilders,
verboseClassComments, typeProvider, BindingNamespaceType.Data);
- final String packageName = packageNameForGeneratedType(basePackageName, notification.getPath(), BindingNamespaceType.Data);
final GeneratedTypeBuilder notificationInterface = addDefaultInterfaceDefinition
- (packageName, notification, null, module, genCtx, schemaContext,
+ (basePackageName, notification, null, module, genCtx, schemaContext,
verboseClassComments, genTypeBuilders, typeProvider, BindingNamespaceType.Data);
annotateDeprecatedIfNecessary(notification.getStatus(), notificationInterface);
notificationInterface.addImplementsType(NOTIFICATION);
* {@link BindingGeneratorImpl#genTypeBuilders genTypeBuilders}. If it isn't
* found it is created and added to <code>genTypeBuilders</code>.
*
- * @param packageName
- * string with the package name to which returning generated type
- * builder belongs
+ * @param basePackageName
+ * string contains the module package name
* @param schemaNode
* schema node which provide data about the schema node name
* @param schemaContext schema context
* </ul>
*
*/
- static GeneratedTypeBuilder addRawInterfaceDefinition(final String packageName, final SchemaNode schemaNode,
+ static GeneratedTypeBuilder addRawInterfaceDefinition(final String basePackageName, final SchemaNode schemaNode,
final SchemaContext schemaContext, final String prefix, final String suffix,
- final boolean verboseClassComments, final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders) {
+ final boolean verboseClassComments, final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders,
+ final BindingNamespaceType namespaceType) {
Preconditions.checkArgument(schemaNode != null, "Data Schema Node cannot be NULL.");
- Preconditions.checkArgument(packageName != null, "Package Name for Generated Type cannot be NULL.");
+ Preconditions.checkArgument(basePackageName != null, "Base package Name for Generated Type cannot be NULL.");
String schemaNodeName = schemaNode.getQName().getLocalName();
Preconditions.checkArgument(schemaNodeName != null, "Local Name of QName for Data Schema Node cannot be NULL.");
schemaNodeName = new StringBuilder(schemaNodeName).append('_').append(suffix).toString();
}
+ final String packageName = packageNameForGeneratedType(basePackageName, schemaNode.getPath(), namespaceType);
final GeneratedTypeBuilderImpl newType = new GeneratedTypeBuilderImpl(packageName, schemaNodeName);
final Module module = SchemaContextUtil.findParentModule(schemaContext, schemaNode);
qNameConstant(newType, BindingMapping.QNAME_STATIC_FIELD_NAME, schemaNode.getQName());
newType.addComment(schemaNode.getDescription());
- newType.setDescription(createDescription(schemaNode, newType.getFullyQualifiedName(), schemaContext, verboseClassComments));
+ newType.setDescription(createDescription(schemaNode, newType.getFullyQualifiedName(), schemaContext,
+ verboseClassComments, namespaceType));
newType.setReference(schemaNode.getReference());
newType.setSchemaPath((List<QName>) schemaNode.getPath().getPathFromRoot());
newType.setModuleName(module.getName());
newType.setBasePackageName(BindingMapping.getRootPackageName(module));
+ newType.setWithBuilder(AuxiliaryGenUtils.hasBuilderClass(schemaNode, namespaceType));
if (!genTypeBuilders.containsKey(packageName)) {
final Map<String, GeneratedTypeBuilder> builders = new HashMap<>();
checkArgument(choiceNode != null, "Choice Schema Node cannot be NULL.");
if (!choiceNode.isAddedByUses()) {
- final String packageName = packageNameForGeneratedType(basePackageName, choiceNode.getPath(),
- BindingNamespaceType.Data);
- final GeneratedTypeBuilder choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode,
- schemaContext, "", "", verboseClasssComments, genTypeBuilders);
+ final GeneratedTypeBuilder choiceTypeBuilder = addRawInterfaceDefinition(basePackageName, choiceNode,
+ schemaContext, "", "", verboseClasssComments, genTypeBuilders, namespaceType);
constructGetter(parent, choiceNode.getQName().getLocalName(),
choiceNode.getDescription(), choiceTypeBuilder, choiceNode.getStatus());
choiceTypeBuilder.addImplementsType(parameterizedTypeFor(BindingTypes.INSTANTIABLE, choiceTypeBuilder));
for (final ChoiceCaseNode caseNode : caseNodes) {
if (caseNode != null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) {
- final String packageName = packageNameForGeneratedType(basePackageName, caseNode.getPath(),
- BindingNamespaceType.Data);
- final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode,
+ final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(basePackageName, caseNode,
module, genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider, namespaceType);
caseTypeBuilder.addImplementsType(refChoiceType);
caseTypeBuilder.setParentTypeForBuilder(refChoiceType);
if (node.isAugmenting()) {
return null;
}
- final String packageName = packageNameForGeneratedType(basePackageName, node.getPath(), namespaceType);
- final GeneratedTypeBuilder genType = addDefaultInterfaceDefinition(packageName, node, childOf, module,
+
+ final GeneratedTypeBuilder genType = addDefaultInterfaceDefinition(basePackageName, node, childOf, module,
genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider, namespaceType);
genType.addComment(node.getDescription());
annotateDeprecatedIfNecessary(node.getStatus(), genType);
- genType.setDescription(createDescription(node, genType.getFullyQualifiedName(), schemaContext, verboseClassComments));
+ genType.setDescription(createDescription(node, genType.getFullyQualifiedName(), schemaContext,
+ verboseClassComments, namespaceType));
genType.setModuleName(module.getName());
genType.setReference(node.getReference());
genType.setSchemaPath((List) node.getPath().getPathFromRoot());
private static Map<Module, ModuleContext> groupingToGenType(final String basePackageName, final GroupingDefinition grouping, final Module
module, Map<Module, ModuleContext> genCtx, final SchemaContext schemaContext, final boolean
verboseClassComments, Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders, final TypeProvider typeProvider) {
- final String packageName = packageNameForGeneratedType(basePackageName, grouping.getPath(), BindingNamespaceType.Grouping);
- final GeneratedTypeBuilder genType = addDefaultInterfaceDefinition(packageName, grouping, module, genCtx,
+ final GeneratedTypeBuilder genType = addDefaultInterfaceDefinition(basePackageName, grouping, module, genCtx,
schemaContext, verboseClassComments, genTypeBuilders, typeProvider, BindingNamespaceType.Grouping);
annotateDeprecatedIfNecessary(grouping.getStatus(), genType);
genCtx.get(module).addGroupingType(grouping, genType);
newType.setAbstract(true);
newType.addComment(identity.getDescription());
newType.setDescription(createDescription(identity, newType.getFullyQualifiedName(), schemaContext,
- verboseClassComments));
+ verboseClassComments, BindingNamespaceType.Identity));
newType.setReference(identity.getReference());
newType.setModuleName(module.getName());
newType.setSchemaPath((List) identity.getPath().getPathFromRoot());
import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.addRawInterfaceDefinition;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.moduleTypeBuilder;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.encodeAngleBrackets;
+import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.packageNameForGeneratedType;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.ACTION;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.INPUT;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.INSTANCE_IDENTIFIER;
final Set<ActionDefinition> actions = ((ActionNodeContainer) potential).getActions();
for (ActionDefinition action: actions) {
genCtx.get(module).addTopLevelNodeType(resolveOperation(potential, action, module,
- schemaContext, verboseClassComments, genTypeBuilders, genCtx, typeProvider, true));
+ schemaContext, verboseClassComments, genTypeBuilders, genCtx, typeProvider, true,
+ BindingNamespaceType.Data));
}
}
}
//routedRPC?
if (isAction) {
genCtx.get(module).addTopLevelNodeType(resolveOperation(parent, rpc, module, schemaContext,
- verboseClassComments, genTypeBuilders, genCtx, typeProvider, true));
+ verboseClassComments, genTypeBuilders, genCtx, typeProvider, true,
+ BindingNamespaceType.Data));
} else {
//global RPC only
genCtx.get(module).addTopLevelNodeType(resolveOperation(parent, rpc, module, schemaContext,
- verboseClassComments, genTypeBuilders, genCtx, typeProvider, false));
+ verboseClassComments, genTypeBuilders, genCtx, typeProvider, false,
+ BindingNamespaceType.Data));
}
}
return genCtx;
}
+ //TODO: This method should be reusable for convertion of action that is in grouping.
/**
* Converts RPC, Action or routed RPC into generated type
* @return generated type
private static GeneratedTypeBuilder resolveOperation(final DataSchemaNode parent, final OperationDefinition operation,
final Module module, final SchemaContext schemaContext, final boolean verboseClassComments,
Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders, final Map<Module, ModuleContext> genCtx,
- TypeProvider typeProvider, final boolean isAction) {
+ TypeProvider typeProvider, final boolean isAction, final BindingNamespaceType namespaceType) {
//operation name
final String operationName = operation.getQName().getLocalName();
final String basePackageName = interfaceBuilder.getPackageName();
interfaceBuilder.setDescription(createDescription(operation, interfaceBuilder.getFullyQualifiedName(),
- schemaContext, verboseClassComments));
+ schemaContext, verboseClassComments, namespaceType));
final String operationComment = encodeAngleBrackets(operation.getDescription());
final MethodSignatureBuilder operationMethod = interfaceBuilder.addMethod("invoke");
//input
final ContainerSchemaNode input = operation.getInput();
final GeneratedTypeBuilder inType = resolveOperationNode(interfaceBuilder, module, operation.getInput(),
- basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders, genCtx, true);
+ basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders,
+ genCtx, true, namespaceType);
annotateDeprecatedIfNecessary(operation.getStatus(), inType);
inType.setParentTypeForBuilder(interfaceBuilder);
genCtx.get(module).addChildNodeType(input, inType);
//output
final ContainerSchemaNode output = operation.getOutput();
final GeneratedTypeBuilder outType = resolveOperationNode(interfaceBuilder, module, operation.getOutput(),
- basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders, genCtx, false);
+ basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders,
+ genCtx, false, namespaceType);
annotateDeprecatedIfNecessary(operation.getStatus(), outType);
outType.setParentTypeForBuilder(interfaceBuilder);
genCtx.get(module).addChildNodeType(output, outType);
//Action
GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, parentType, parentType,
((ContainerSchemaNode) parent).getChildNodes(), genCtx, schemaContext, verboseClassComments,
- genTypeBuilders, typeProvider, BindingNamespaceType.Data);
+ genTypeBuilders, typeProvider, namespaceType);
operationMethod.addParameter(parameterizedTypeFor(INSTANCE_IDENTIFIER, parentType), "ii");
interfaceBuilder.addImplementsType(parameterizedTypeFor(ACTION, parentType, inType, outType));
}
private static GeneratedTypeBuilder resolveOperationNode(GeneratedTypeBuilder parent, final Module module, final
ContainerSchemaNode operationNode, final String basePackageName, final SchemaContext schemaContext, final String
operationName, final boolean verboseClassComments, TypeProvider typeProvider, Map<String, Map<String,
- GeneratedTypeBuilder>> genTypeBuilders, final Map<Module, ModuleContext> genCtx, final boolean isInput) {
-
+ GeneratedTypeBuilder>> genTypeBuilders, final Map<Module, ModuleContext> genCtx, final boolean isInput,
+ final BindingNamespaceType namespaceType) {
final GeneratedTypeBuilder nodeType = addRawInterfaceDefinition(basePackageName, operationNode, schemaContext,
- operationName, "", verboseClassComments, genTypeBuilders);
+ operationName, "", verboseClassComments, genTypeBuilders, namespaceType);
addImplementedInterfaceFromUses(operationNode, nodeType, genCtx);
nodeType.addImplementsType(parameterizedTypeFor(BindingTypes.TREE_CHILD_NODE, parent, parameterizedTypeFor
(BindingTypes.ITEM, parent)));
nodeType.addImplementsType(parameterizedTypeFor(INSTANTIABLE, nodeType));
nodeType.addImplementsType(augmentable(nodeType));
GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, nodeType, nodeType, operationNode.getChildNodes(), genCtx,
- schemaContext, verboseClassComments, genTypeBuilders, typeProvider, BindingNamespaceType.Data);
+ schemaContext, verboseClassComments, genTypeBuilders, typeProvider, namespaceType);
final MethodSignatureBuilder nodeMethod = nodeType.addMethod("implementedInterface");
nodeMethod.setReturnType(parameterizedTypeFor(CLASS, nodeType));
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilderBase;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.MethodSignatureBuilder;
+import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingNamespaceType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@SuppressWarnings("rawtypes")
@Test
public void createDescriptionWithSchemaNodeTest() throws Exception {
- final Class[] parameterTypes = { SchemaNode.class, String.class, SchemaContext.class, boolean.class };
+ final Class[] parameterTypes = { SchemaNode.class, String.class, SchemaContext.class, boolean.class,
+ BindingNamespaceType.class};
final Method generate = AuxiliaryGenUtils.class.getDeclaredMethod("createDescription", parameterTypes);
assertNotNull(generate);
generate.setAccessible(true);
final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/generator/test-list.yang");
final ListSchemaNode containerSchemaNode =
(ListSchemaNode) schemaContext.getModules().iterator().next().getChildNodes().iterator().next();
- final String fullyQualifiedName = "test.base.cont.with.leaf.MyList";
+ final String fullyQualifiedName =
+ "org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.data.MyList";
- final Object[] args = { containerSchemaNode, fullyQualifiedName, schemaContext, true };
+ final Object[] args = { containerSchemaNode, fullyQualifiedName, schemaContext, true, BindingNamespaceType.Data };
final String result = (String) generate.invoke(AuxiliaryGenUtils.class, args);
assertNotNull(result);
assertTrue(result.contains("list my-list"));
assertTrue(result.contains("leaf key1"));
assertTrue(result.contains("leaf key2"));
assertTrue(result.contains("leaf foo"));
- assertTrue(result.contains("@see test.base.cont.with.leaf.MyListBuilder"));
- assertTrue(result.contains("@see test.base.cont.with.leaf.MyListKey"));
+ assertTrue(result.contains("@see org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.dto.MyListBuilder"));
+ assertTrue(result.contains("@see org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.key.my_list.MyListKey"));
}
@SuppressWarnings("rawtypes")
@Test
public void createDescriptionWithSchemaNodeWithDescriptionTest() throws Exception {
- final Class[] parameterTypes = { SchemaNode.class, String.class, SchemaContext.class, boolean.class };
+ final Class[] parameterTypes = { SchemaNode.class, String.class, SchemaContext.class, boolean.class,
+ BindingNamespaceType.class};
final Method generate = AuxiliaryGenUtils.class.getDeclaredMethod("createDescription", parameterTypes);
assertNotNull(generate);
generate.setAccessible(true);
(LeafSchemaNode) schemaContext.getModules().iterator().next().getChildNodes().iterator().next();
final String fullyQualifiedName = "test.base.cont.with.leaf.MyList";
- final Object[] args = { containerSchemaNode, fullyQualifiedName, schemaContext, true };
+ final Object[] args = { containerSchemaNode, fullyQualifiedName, schemaContext, true, BindingNamespaceType.Data};
final String result = (String) generate.invoke(AuxiliaryGenUtils.class, args);
assertNotNull(result);
assertTrue(result.contains("I am leaf."));
@SuppressWarnings("rawtypes")
private <T extends SchemaNode> boolean hasBuilderClass(final Class<T> clazz) throws Exception {
- final Class[] parameterTypes = { SchemaNode.class };
+ final Class[] parameterTypes = { SchemaNode.class, BindingNamespaceType.class };
final Method generate = AuxiliaryGenUtils.class.getDeclaredMethod("hasBuilderClass", parameterTypes);
assertNotNull(generate);
generate.setAccessible(true);
final T schemaNode = mock(clazz);
- final Object[] args = { schemaNode };
+ final Object[] args = { schemaNode, BindingNamespaceType.Data };
return (boolean) generate.invoke(AuxiliaryGenUtils.class, args);
}
}
return generateNormalizedPackageName(parentAugmentPackageName, last);
}
- public static String packageNameForSubGeneratedType(final String parentPackageName,
- final SchemaNode node) {
+ public static String packageNameForSubGeneratedType(final String basePackageName, final SchemaNode node,
+ final BindingNamespaceType namespaceType) {
+ final String parent = packageNameForGeneratedType(basePackageName, node.getPath(), namespaceType);
final QName last = node.getPath().getLastComponent();
- return generateNormalizedPackageName(parentPackageName, last);
+ return generateNormalizedPackageName(parent, last);
}
public static String replacePackageTopNamespace(final String basePackageName,
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilderBase;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.MethodSignatureBuilder;
-import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentable;
-import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
import org.opendaylight.yangtools.util.LazyCollections;
@Beta
private String comment = "";
private boolean isAbstract;
private Type parentTypeForBuilder;
- private boolean isDataObjectType = false;
- private String basePackageName = null;
protected AbstractGeneratedTypeBuilder(final String packageName, final String name) {
super(packageName, name);
return enclosedTransferObjects;
}
- protected boolean isDataObjectType() {
- return isDataObjectType;
- }
-
- protected String getBasePackageName() {
- return basePackageName;
- }
-
protected abstract T thisInstance();
@Override
return thisInstance();
}
- @Override
- public void setBasePackageName(String basePackageName) {
- this.basePackageName = basePackageName;
- }
-
@Override
public T addImplementsType(final Type genType) {
Preconditions.checkArgument(genType != null, "Type cannot be null");
Preconditions.checkArgument(!implementsTypes.contains(genType), "This generated type already contains equal implements type.");
implementsTypes = LazyCollections.lazyAdd(implementsTypes, genType);
-
- if (genType.getFullyQualifiedName().equals(Augmentable.class.getName())
- || genType.getFullyQualifiedName().equals(Augmentation.class.getName())) {
- this.isDataObjectType = true;
- }
return thisInstance();
}
import java.util.Optional;
import com.google.common.base.Preconditions;
import org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil;
-import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer;
import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedTypeForBuilder;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
private String reference;
private String moduleName;
private List<QName> schemaPath;
+ private boolean isWithBuilder = false;
+ private String basePackageName = null;
public GeneratedTypeBuilderImpl(final String packageName, final String name) {
super(packageName, name);
@Override
public GeneratedType toInstance() {
- if (this.isDataObjectType()) {
+ if (this.isWithBuilder()) {
return new GeneratedTypeWithBuilderImpl(this);
} else {
return new GeneratedTypeImpl(this);
return this;
}
+ public boolean isWithBuilder() {
+ return isWithBuilder;
+ }
+
+ public void setWithBuilder(boolean withBuilder) {
+ isWithBuilder = withBuilder;
+ }
+
+ public String getBasePackageName() {
+ return basePackageName;
+ }
+
+ public void setBasePackageName(String basePackageName) {
+ this.basePackageName = basePackageName;
+ }
+
private static class GeneratedTypeImpl extends AbstractGeneratedType {
private final String description;
public GeneratedTypeWithBuilderImpl(GeneratedTypeBuilderImpl builder) {
super(builder);
+ Preconditions.checkState(builder.getBasePackageName() != null,
+ "Base package name can not be null for type with builder!");
this.basePackageName = builder.getBasePackageName();
this.builderPackageName = generatePackageNameForBuilder();
}