.DS_Store
META-INF
.fbExcludeFilterFile
+.cache-main
+.cache-tests
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.util.BindingMapping;
+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;
} else {
method.append("get");
}
- final String name = BindingMapping.toFirstUpper(NonJavaCharsConverter.convertIdentifier(BindingMapping.getPropertyName
- (localName), JavaIdentifier.METHOD));
- method.append(name);
- return method.toString();
+ // underscore used as separator for distinction of method parts in convertIdentifier()
+ method.append('_').append(localName);
+ return NonJavaCharsConverter.convertIdentifier(method.toString(), JavaIdentifier.METHOD);
}
static String createDescription(final SchemaNode schemaNode, final String fullyQualifiedName,
static EnumBuilder resolveInnerEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final QName enumName,
final Map<Module, ModuleContext> genCtx, final GeneratedTypeBuilder typeBuilder, final Module module) {
if (enumTypeDef != null && typeBuilder != null && enumTypeDef.getQName().getLocalName() != null) {
- final String enumerationName = BindingMapping.getClassName(enumName);
- final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumerationName);
+ final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumName.getLocalName());
final String enumTypedefDescription = encodeAngleBrackets(enumTypeDef.getDescription());
enumBuilder.setDescription(enumTypedefDescription);
enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
- ModuleContext ctx = genCtx.get(module);
+ final ModuleContext ctx = genCtx.get(module);
ctx.addInnerTypedefType(enumTypeDef.getPath(), enumBuilder);
return enumBuilder;
}
static GeneratedTOBuilder addTOToTypeBuilder(final TypeDefinition<?> typeDef, final GeneratedTypeBuilder
typeBuilder, final DataSchemaNode leaf, final Module parentModule, final TypeProvider typeProvider,
final SchemaContext schemaContext) {
- final String classNameFromLeaf = BindingMapping.getClassName(leaf.getQName());
+ final String classNameFromLeaf = leaf.getQName().getLocalName();
final List<GeneratedTOBuilder> genTOBuilders = new ArrayList<>();
final String packageName = typeBuilder.getFullyQualifiedName();
if (typeDef instanceof UnionTypeDefinition) {
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
static Type createReturnTypeForUnion(final GeneratedTOBuilder genTOBuilder, final TypeDefinition<?> typeDef,
final GeneratedTypeBuilder typeBuilder, final Module parentModule, final TypeProvider typeProvider) {
final GeneratedTOBuilderImpl returnType = new GeneratedTOBuilderImpl(genTOBuilder.getPackageName(),
return false;
}
+ /**
+ * Generates for the <code>list</code> which contains any list keys special
+ * generated TO builder.
+ *
+ * @param packageName
+ * string with package name to which the list belongs
+ * @param list
+ * schema node of list
+ * @return generated TO builder which represents the keys of the
+ * <code>list</code> or empty TO builder if <code>list</code> is null or list of
+ * key definitions is null or empty.
+ */
+ static GeneratedTOBuilder resolveListKeyTOBuilder(final String packageName, final ListSchemaNode list) {
+ GeneratedTOBuilder genTOBuilder = null;
+ if ((list.getKeyDefinition() != null) && (!list.getKeyDefinition().isEmpty())) {
+ // underscore used as separator for distinction of class name parts
+ final String genTOName =
+ new StringBuilder(list.getQName().getLocalName()).append('_').append(BindingNamespaceType.Key)
+ .toString();
+ genTOBuilder =
+ new GeneratedTOBuilderImpl(new StringBuilder(packageName).append(".wrapper").toString(), genTOName);
+ }
+ return genTOBuilder;
+ }
+
+ /**
+ * Converts <code>leaf</code> schema node to property of generated TO
+ * builder.
+ *
+ * @param toBuilder
+ * generated TO builder to which is <code>leaf</code> added as
+ * property
+ * @param leaf
+ * leaf schema node which is added to <code>toBuilder</code> as
+ * property
+ * @param returnType
+ * property type
+ * @param isReadOnly
+ * boolean value which says if leaf property is|isn't read only
+ * @return boolean value
+ * <ul>
+ * <li>false - if <code>leaf</code>, <code>toBuilder</code> or leaf
+ * name equals null or if leaf is added by <i>uses</i>.</li>
+ * <li>true - other cases</li>
+ * </ul>
+ */
+ static boolean resolveLeafSchemaNodeAsProperty(final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf,
+ final Type returnType, final boolean isReadOnly) {
+
+ if (returnType == null) {
+ return false;
+ }
+ final String leafName = leaf.getQName().getLocalName();
+ final String leafDesc = encodeAngleBrackets(leaf.getDescription());
+ final GeneratedPropertyBuilder propBuilder =
+ toBuilder.addProperty(NonJavaCharsConverter.convertIdentifier(leafName, JavaIdentifier.METHOD));
+ propBuilder.setReadOnly(isReadOnly);
+ propBuilder.setReturnType(returnType);
+ propBuilder.setComment(leafDesc);
+ toBuilder.addEqualsIdentity(propBuilder);
+ toBuilder.addHashIdentity(propBuilder);
+ toBuilder.addToStringProperty(propBuilder);
+ return true;
+ }
+
@VisibleForTesting
public static String replaceAllIllegalChars(final StringBuilder stringBuilder){
final String ret = UNICODE_CHAR_PATTERN.matcher(stringBuilder).replaceAll("\\\\\\\\u");
package org.opendaylight.mdsal.binding.javav2.generator.impl;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.addTOToTypeBuilder;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.annotateDeprecatedIfNecessary;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.augGenTypeName;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.isInnerType;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.qNameConstant;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.resolveInnerEnumFromTypeDefinition;
+import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.resolveListKeyTOBuilder;
+import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.computeDefaultSUID;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.packageNameForGeneratedType;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
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.BindingTypes;
-import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier;
-import org.opendaylight.mdsal.binding.javav2.generator.util.NonJavaCharsConverter;
import org.opendaylight.mdsal.binding.javav2.generator.util.Types;
+import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedPropertyBuilderImpl;
import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
import org.opendaylight.mdsal.binding.javav2.generator.yang.types.TypeProviderImpl;
+import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedTransferObject;
import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.javav2.model.api.Restrictions;
import org.opendaylight.mdsal.binding.javav2.model.api.Type;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.EnumBuilder;
+import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedPropertyBuilder;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTOBuilder;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
-import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.MethodSignatureBuilder;
import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingNamespaceType;
import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentable;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
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.UsesNode;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
verboseClassComments) {
Preconditions.checkArgument(module != null, "Module reference cannot be NULL.");
final String packageName = BindingMapping.getRootPackageName(module);
- final String moduleName = BindingMapping.getClassName(NonJavaCharsConverter.convertIdentifier(module.getName
- (), JavaIdentifier.CLASS)) + postfix;
+ // underscore used as separator for distinction of module name parts
+ final String moduleName = new StringBuilder(module.getName()).append('_').append(postfix).toString();
final GeneratedTypeBuilderImpl moduleBuilder = new GeneratedTypeBuilderImpl(packageName, moduleName);
moduleBuilder.setDescription(createDescription(module, verboseClassComments));
augmentBuilders = new HashMap<>();
genTypeBuilders.put(augmentPackageName, augmentBuilders);
}
- final String augIdentifier = getAugmentIdentifier(augSchema.getUnknownSchemaNodes());
+ String augIdentifier = getAugmentIdentifier(augSchema.getUnknownSchemaNodes());
- String augTypeName;
- if (augIdentifier != null) {
- augTypeName = BindingMapping.getClassName(augIdentifier);
- } else {
- augTypeName = augGenTypeName(augmentBuilders, targetTypeRef.getName());
+ if (augIdentifier == null) {
+ augIdentifier = augGenTypeName(augmentBuilders, targetTypeRef.getName());
}
- GeneratedTypeBuilder augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augTypeName);
+ GeneratedTypeBuilder augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augIdentifier);
augTypeBuilder.addImplementsType(BindingTypes.TREE_NODE);
augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef));
augTypeBuilder = augSchemaNodeToMethods(module, basePackageName, augTypeBuilder, augTypeBuilder, augSchema
.getChildNodes());
- augmentBuilders.put(augTypeName, augTypeBuilder);
+ augmentBuilders.put(augTypeBuilder.getName(), augTypeBuilder);
if(!augSchema.getChildNodes().isEmpty()) {
genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema);
* added to it.
*/
private static GeneratedTypeBuilder augSchemaNodeToMethods(final Module module, final String basePackageName,
- final GeneratedTypeBuilder typeBuilder, final GeneratedTypeBuilder childOf,
- final Iterable<DataSchemaNode> schemaNodes) {
+ final GeneratedTypeBuilder typeBuilder, final GeneratedTypeBuilder childOf,
+ final Iterable<DataSchemaNode> schemaNodes) {
if (schemaNodes != null && typeBuilder != null) {
for (final DataSchemaNode schemaNode : schemaNodes) {
if (!schemaNode.isAugmenting()) {
Preconditions.checkArgument(schemaNode != null, "Data Schema Node cannot be NULL.");
Preconditions.checkArgument(packageName != null, "Package Name for Generated Type cannot be NULL.");
- final String schemaNodeName = schemaNode.getQName().getLocalName();
+ String schemaNodeName = schemaNode.getQName().getLocalName();
Preconditions.checkArgument(schemaNodeName != null, "Local Name of QName for Data Schema Node cannot be NULL.");
- String genTypeName;
- if (prefix == null) {
- genTypeName = BindingMapping
- .getClassName(NonJavaCharsConverter.normalizeClassIdentifier(packageName, schemaNodeName));
- } else {
- genTypeName = prefix + BindingMapping
- .getClassName(NonJavaCharsConverter.normalizeClassIdentifier(packageName, schemaNodeName));
+ if (prefix != null && !prefix.isEmpty()) {
+ // underscore used as separator for distinction of class name parts
+ schemaNodeName = new StringBuilder(prefix).append('_').append(schemaNodeName).toString();
}
- final GeneratedTypeBuilderImpl newType = new GeneratedTypeBuilderImpl(packageName, genTypeName);
+ 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());
if (!genTypeBuilders.containsKey(packageName)) {
final Map<String, GeneratedTypeBuilder> builders = new HashMap<>();
- builders.put(genTypeName, newType);
+ builders.put(newType.getName(), newType);
genTypeBuilders.put(packageName, builders);
} else {
final Map<String, GeneratedTypeBuilder> builders = genTypeBuilders.get(packageName);
- if (!builders.containsKey(genTypeName)) {
- builders.put(genTypeName, newType);
+ if (!builders.containsKey(newType.getName())) {
+ builders.put(newType.getName(), newType);
}
}
return newType;
} else if (node instanceof LeafSchemaNode) {
resolveLeafSchemaNodeAsMethod(schemaContext, typeBuilder, genCtx, (LeafSchemaNode) node, module,
typeProvider);
+ } else if (node instanceof ListSchemaNode) {
+ listToGenType(module, basePackageName, typeBuilder, childOf, (ListSchemaNode) node, schemaContext,
+ verboseClassComments, genCtx, genTypeBuilders, typeProvider);
}
}
}
}
+ private static void listToGenType(final Module module, final String basePackageName, final GeneratedTypeBuilder
+ parent, final GeneratedTypeBuilder childOf, final ListSchemaNode node, final SchemaContext schemaContext,
+ final boolean verboseClassComments, final Map<Module, ModuleContext> genCtx,
+ final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders, final TypeProvider typeProvider) {
+ final GeneratedTypeBuilder genType = processDataSchemaNode(module, basePackageName, childOf, node,
+ schemaContext, verboseClassComments, genCtx, genTypeBuilders, typeProvider);
+ if (genType != null) {
+ final String nodeName = node.getQName().getLocalName();
+ constructGetter(parent, nodeName, node.getDescription(),
+ Types.listTypeFor(genType), node.getStatus());
+ final List<QName> listKeys = node.getKeyDefinition();
+ final String packageName = new StringBuilder(packageNameForGeneratedType(basePackageName, node.getPath(),
+ BindingNamespaceType.Key)).append('.').append(nodeName).toString();
+
+ final GeneratedTOBuilder genTOBuilder = resolveListKeyTOBuilder(packageName, node);
+
+ for (final DataSchemaNode schemaNode : node.getChildNodes()) {
+ if (!schemaNode.isAugmenting()) {
+ addSchemaNodeToListBuilders(nodeName, basePackageName, schemaNode, genType, genTOBuilder, listKeys,
+ module, typeProvider, schemaContext, genCtx, genTypeBuilders, verboseClassComments);
+ }
+ }
+
+ // serialVersionUID
+ if (genTOBuilder != null) {
+ final GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("serialVersionUID");
+ prop.setValue(Long.toString(computeDefaultSUID(genTOBuilder)));
+ genTOBuilder.setSUID(prop);
+ }
+
+ typeBuildersToGenTypes(module, genType, genTOBuilder, genCtx);
+ }
+ }
+
+ private static void typeBuildersToGenTypes(final Module module, final GeneratedTypeBuilder typeBuilder,
+ final GeneratedTOBuilder genTOBuilder, final Map<Module, ModuleContext> genCtx) {
+ checkArgument(typeBuilder != null, "Generated Type Builder cannot be NULL.");
+ if (genTOBuilder != null) {
+ final GeneratedTransferObject genTO = genTOBuilder.toInstance();
+ constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO, Status.CURRENT);
+ genCtx.get(module).addGeneratedTOBuilder(genTOBuilder);
+ }
+ }
+
/**
* Converts <code>leaf</code> to the getter method which is added to
* <code>typeBuilder</code>.
}
((TypeProviderImpl) typeProvider).putReferencedType(leaf.getPath(), returnType);
} else if (typeDef instanceof UnionTypeDefinition) {
- GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule,
+ final GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule,
typeProvider, schemaContext);
if (genTOBuilder != null) {
//TODO: https://bugs.opendaylight.org/show_bug.cgi?id=2289
returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule, typeProvider);
}
} else if (typeDef instanceof BitsTypeDefinition) {
- GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule,
+ final GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule,
typeProvider, schemaContext);
if (genTOBuilder != null) {
returnType = genTOBuilder.toInstance();
leafDesc = "";
}
- final MethodSignatureBuilder getter = constructGetter(typeBuilder, leafName, leafDesc, returnType, leaf.getStatus());
-
- //FIXME: deal with context-ref
+ constructGetter(typeBuilder, leafName, leafDesc, returnType, leaf.getStatus());
+ genCtx.get(module).addChildNodeType(leaf, typeBuilder);
return returnType;
}
+ /**
+ * Adds <code>schemaNode</code> to <code>typeBuilder</code> as getter method
+ * or to <code>genTOBuilder</code> as property.
+ *
+ * @param nodeName
+ * string contains the name of list
+ * @param basePackageName
+ * string contains the module package name
+ * @param schemaNode
+ * data schema node which should be added as getter method to
+ * <code>typeBuilder</code> or as a property to
+ * <code>genTOBuilder</code> if is part of the list key
+ * @param typeBuilder
+ * generated type builder for the list schema node
+ * @param genTOBuilder
+ * generated TO builder for the list keys
+ * @param listKeys
+ * list of string which contains QNames of the list keys
+ * @param module
+ * current module
+ * @param typeProvider
+ * provider that defines contract for generated types
+ * @param schemaContext
+ * schema context
+ * @param genCtx
+ * map of generated entities in context of YANG modules
+ * @param genTypeBuilders
+ * map of generated type builders
+ * @param verboseClassComments
+ * generate verbose comments
+ * @throws IllegalArgumentException
+ * <ul>
+ * <li>if <code>schemaNode</code> equals null</li>
+ * <li>if <code>typeBuilder</code> equals null</li>
+ * </ul>
+ */
+ private static void addSchemaNodeToListBuilders(final String nodeName, final String basePackageName,
+ final DataSchemaNode schemaNode, final GeneratedTypeBuilder typeBuilder,
+ final GeneratedTOBuilder genTOBuilder, final List<QName> listKeys, final Module module,
+ final TypeProvider typeProvider, final SchemaContext schemaContext, final Map<Module, ModuleContext> genCtx,
+ final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders, final boolean verboseClassComments) {
+ checkArgument(schemaNode != null, "Data Schema Node cannot be NULL.");
+ checkArgument(typeBuilder != null, "Generated Type Builder cannot be NULL.");
+
+ if (schemaNode instanceof LeafSchemaNode) {
+ final LeafSchemaNode leaf = (LeafSchemaNode) schemaNode;
+ final QName leafQName = leaf.getQName();
+ final String leafName = leafQName.getLocalName();
+ String leafPckgName = basePackageName;
+ boolean isKeyPart = false;
+ if (listKeys.contains(leafQName)) {
+ leafPckgName = new StringBuilder(leafPckgName).append('.').append(BindingNamespaceType.Key).append('.')
+ .append(nodeName).toString();
+ isKeyPart = true;
+ } else {
+ leafPckgName = new StringBuilder(leafPckgName).append('.').append(BindingNamespaceType.Data).append('.')
+ .append(nodeName).toString();
+ }
+
+ final String leafGTOName = new StringBuilder(nodeName).append('_').append(leafName).toString();
+ final GeneratedTypeBuilder leafGTp = new GeneratedTypeBuilderImpl(leafPckgName, leafGTOName);
+ resolveLeafSchemaNodeAsMethod(schemaContext, leafGTp, genCtx, leaf, module,
+ typeProvider);
+
+ constructGetter(typeBuilder, leafGTOName, schemaNode.getDescription(), leafGTp, Status.CURRENT);
+
+ if (isKeyPart) {
+ AuxiliaryGenUtils.resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, leafGTp, true);
+ }
+ } else if (!schemaNode.isAddedByUses()) {
+ //TODO: implement leaf list to generated type
+ //TODO: implement choice to generated type
+ if (schemaNode instanceof ContainerSchemaNode) {
+ containerToGenType(module, basePackageName, typeBuilder, typeBuilder, (ContainerSchemaNode) schemaNode,
+ schemaContext, verboseClassComments, genCtx, genTypeBuilders, typeProvider);
+ } else if (schemaNode instanceof ListSchemaNode) {
+ listToGenType(module, basePackageName, typeBuilder, typeBuilder, (ListSchemaNode) schemaNode,
+ schemaContext, verboseClassComments, genCtx, genTypeBuilders, typeProvider);
+ }
+ }
+ }
+
private static TypeDefinition<?> getBaseOrDeclaredType(final TypeDefinition<?> typeDef) {
final TypeDefinition<?> baseType = typeDef.getBaseType();
return (baseType != null && baseType.getBaseType() != null) ? baseType : typeDef;
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
private static GeneratedTypeBuilder processDataSchemaNode(final Module module, final String basePackageName,
final GeneratedTypeBuilder childOf, final DataSchemaNode node, final SchemaContext schemaContext,
final boolean verboseClassComments, final Map<Module, ModuleContext> genCtx, final Map<String, Map<String,
public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
final Restrictions restrictions) {
- String typeName = type.getQName().getLocalName();
+ final String typeName = type.getQName().getLocalName();
switch (typeName) {
case "binary":
return restrictions == null ? Types.BYTE_ARRAY : Types.primitiveType("byte[]", restrictions);
@Override
public String getParamNameFromType(final TypeDefinition<?> type) {
- return NonJavaCharsConverter.convertIdentifier(BindingMapping.getPropertyName(type.getQName()
- .getLocalName()), JavaIdentifier.METHOD);
+ return NonJavaCharsConverter.convertIdentifier(type.getQName().getLocalName(), JavaIdentifier.METHOD);
}
};
* <li>if <code>typedefName</code> equals null</li>
* </ul>
*/
+ @SuppressWarnings({ "rawtypes", "unchecked" })
static GeneratedTransferObject provideGeneratedTOFromExtendedType(final TypeDefinition<?> typedef, final
TypeDefinition<?> innerExtendedType, final String basePackageName, final String moduleName, final SchemaContext
schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
Preconditions.checkArgument(basePackageName != null, "String with base package name cannot be NULL!");
final String typedefName = typedef.getQName().getLocalName();
- final String classTypedefName = BindingMapping.getClassName(typedefName);
final String innerTypeDef = innerExtendedType.getQName().getLocalName();
- final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, classTypedefName);
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typedefName);
final String typedefDescription = encodeAngleBrackets(typedef.getDescription());
genTOBuilder.setDescription(typedefDescription);
genTOBuilder.setSchemaPath((List) typedef.getPath().getPathFromRoot());
genTOBuilder.setModuleName(moduleName);
genTOBuilder.setTypedef(true);
- Restrictions r = BindingGeneratorUtil.getRestrictions(typedef);
+ final Restrictions r = BindingGeneratorUtil.getRestrictions(typedef);
genTOBuilder.setRestrictions(r);
if (typedef.getStatus() == Status.DEPRECATED) {
genTOBuilder.addAnnotation("", "Deprecated");
}
if (typeMap != null) {
- Type type = typeMap.get(innerTypeDef);
+ final Type type = typeMap.get(innerTypeDef);
if (type instanceof GeneratedTransferObject) {
genTOBuilder.setExtendsType((GeneratedTransferObject) type);
}
}
final List<String> regExps = new ArrayList<>(patternConstraints.size());
- for (PatternConstraint patternConstraint : patternConstraints) {
+ for (final PatternConstraint patternConstraint : patternConstraints) {
final String regEx = patternConstraint.getRegularExpression();
final String modifiedRegEx = StringEscapeUtils.escapeJava(regEx);
regExps.add(modifiedRegEx);
*/
static List<TypeDefinition<?>> sortTypeDefinitionAccordingDepth(
final Collection<TypeDefinition<?>> unsortedTypeDefinitions) {
- List<TypeDefinition<?>> sortedTypeDefinition = new ArrayList<>();
+ final List<TypeDefinition<?>> sortedTypeDefinition = new ArrayList<>();
- Map<Integer, List<TypeDefinition<?>>> typeDefinitionsDepths = new TreeMap<>();
- for (TypeDefinition<?> unsortedTypeDefinition : unsortedTypeDefinitions) {
+ final Map<Integer, List<TypeDefinition<?>>> typeDefinitionsDepths = new TreeMap<>();
+ for (final TypeDefinition<?> unsortedTypeDefinition : unsortedTypeDefinitions) {
final int depth = getTypeDefinitionDepth(unsortedTypeDefinition);
- List<TypeDefinition<?>> typeDefinitionsConcreteDepth = typeDefinitionsDepths.computeIfAbsent(depth, k -> new ArrayList<>());
+ final List<TypeDefinition<?>> typeDefinitionsConcreteDepth = typeDefinitionsDepths.computeIfAbsent(depth, k -> new ArrayList<>());
typeDefinitionsConcreteDepth.add(unsortedTypeDefinition);
}
if (typeDefinition == null) {
return 1;
}
- TypeDefinition<?> baseType = typeDefinition.getBaseType();
+ final TypeDefinition<?> baseType = typeDefinition.getBaseType();
if (baseType == null) {
return 1;
}
if (baseType.getBaseType() != null) {
depth = depth + getTypeDefinitionDepth(baseType);
} else if (baseType instanceof UnionTypeDefinition) {
- List<TypeDefinition<?>> childTypeDefinitions = ((UnionTypeDefinition) baseType).getTypes();
+ final List<TypeDefinition<?>> childTypeDefinitions = ((UnionTypeDefinition) baseType).getTypes();
int maxChildDepth = 0;
int childDepth = 1;
- for (TypeDefinition<?> childTypeDefinition : childTypeDefinitions) {
+ for (final TypeDefinition<?> childTypeDefinition : childTypeDefinitions) {
childDepth = childDepth + getTypeDefinitionDepth(childTypeDefinition);
if (childDepth > maxChildDepth) {
maxChildDepth = childDepth;
fillRecursively(ret, module);
final Set<NotificationDefinition> notifications = module.getNotifications();
- for (NotificationDefinition notificationDefinition : notifications) {
+ for (final NotificationDefinition notificationDefinition : notifications) {
fillRecursively(ret, notificationDefinition);
}
final Set<RpcDefinition> rpcs = module.getRpcs();
- for (RpcDefinition rpcDefinition : rpcs) {
+ for (final RpcDefinition rpcDefinition : rpcs) {
ret.addAll(rpcDefinition.getTypeDefinitions());
- ContainerSchemaNode input = rpcDefinition.getInput();
+ final ContainerSchemaNode input = rpcDefinition.getInput();
if (input != null) {
fillRecursively(ret, input);
}
- ContainerSchemaNode output = rpcDefinition.getOutput();
+ final ContainerSchemaNode output = rpcDefinition.getOutput();
if (output != null) {
fillRecursively(ret, output);
}
final Collection<DataSchemaNode> potentials = module.getChildNodes();
- for (DataSchemaNode potential : potentials) {
+ for (final DataSchemaNode potential : potentials) {
if (potential instanceof ActionNodeContainer) {
final Set<ActionDefinition> actions = ((ActionNodeContainer) potential).getActions();
- for (ActionDefinition action: actions) {
- ContainerSchemaNode input = action.getInput();
+ for (final ActionDefinition action: actions) {
+ final ContainerSchemaNode input = action.getInput();
if (input != null) {
fillRecursively(ret, input);
}
- ContainerSchemaNode output = action.getOutput();
+ final ContainerSchemaNode output = action.getOutput();
if (output != null) {
fillRecursively(ret, output);
}
final Set<GroupingDefinition> groupings = container.getGroupings();
if (groupings != null) {
- for (GroupingDefinition grouping : groupings) {
+ for (final GroupingDefinition grouping : groupings) {
fillRecursively(list, grouping);
}
}
*/
static void makeSerializable(final GeneratedTOBuilderImpl gto) {
gto.addImplementsType(Types.typeForClass(Serializable.class));
- GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("serialVersionUID");
+ final GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("serialVersionUID");
prop.setValue(Long.toString(BindingGeneratorUtil.computeDefaultSUID(gto)));
gto.setSUID(prop);
}
* <li>if name of <code>enumTypeDef</code> equal null</li>
* </ul>
*/
+ @SuppressWarnings({ "rawtypes", "unchecked" })
static Enumeration provideTypeForEnum(final EnumTypeDefinition enumTypeDef, final String enumName, final
SchemaNode parentNode, final SchemaContext schemaContext) {
Preconditions.checkArgument(enumTypeDef != null, "EnumTypeDefinition reference cannot be NULL!");
Preconditions.checkArgument(enumTypeDef.getQName().getLocalName() != null,
"Local Name in EnumTypeDefinition QName cannot be NULL!");
-
- final String enumerationName = BindingMapping.getClassName(enumName);
-
- Module module = findParentModule(schemaContext, parentNode);
+ final Module module = findParentModule(schemaContext, parentNode);
final String basePackageName = BindingMapping.getRootPackageName(module);
- final EnumerationBuilderImpl enumBuilder = new EnumerationBuilderImpl(basePackageName, enumerationName);
+ final EnumerationBuilderImpl enumBuilder = new EnumerationBuilderImpl(basePackageName, enumName);
final String enumTypedefDescription = encodeAngleBrackets(enumTypeDef.getDescription());
enumBuilder.setDescription(enumTypedefDescription);
enumBuilder.setReference(enumTypeDef.getReference());
* @return generated TO builder which contains data from
* <code>typedef</code> and <code>basePackageName</code>
*/
+ @SuppressWarnings({ "unchecked", "rawtypes" })
private static GeneratedTOBuilderImpl typedefToTransferObject(final String basePackageName, final TypeDefinition<?> typedef, final String moduleName) {
final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typedef.getPath
final String typeDefTOName = typedef.getQName().getLocalName();
if ((packageName != null) && (typeDefTOName != null)) {
- final String genTOName = BindingMapping.getClassName(typeDefTOName);
- final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(packageName, genTOName);
+ final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(packageName, typeDefTOName);
final String typedefDescription = encodeAngleBrackets(typedef.getDescription());
newType.setDescription(typedefDescription);
}
static Module getParentModule(final SchemaNode node, final SchemaContext schemaContext) {
- QName qname = node.getPath().getPathFromRoot().iterator().next();
- URI namespace = qname.getNamespace();
- Date revision = qname.getRevision();
+ final QName qname = node.getPath().getPathFromRoot().iterator().next();
+ final URI namespace = qname.getNamespace();
+ final Date revision = qname.getRevision();
return schemaContext.findModuleByNamespaceAndRevision(namespace, revision);
}
}
import java.util.regex.Pattern;
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.NonJavaCharsConverter;
import org.opendaylight.mdsal.binding.javav2.generator.util.Types;
import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedPropertyBuilderImpl;
import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
this.genTypeDefsContextMap = new HashMap<>();
this.referencedTypes = new HashMap<>();
this.additionalTypes = new HashMap<>();
- resolveTypeDefsFromContext(schemaContext, genTypeDefsContextMap, additionalTypes);
+ resolveTypeDefsFromContext(schemaContext, this.genTypeDefsContextMap, this.additionalTypes);
}
@Override
- public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, SchemaNode parentNode) {
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode) {
return javaTypeForSchemaDefinitionType(type, parentNode, null);
}
* </ul>
*/
@Override
- public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode, Restrictions restrictions) {
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode, final Restrictions restrictions) {
return javaTypeForSchemaDefType(type, parentNode, restrictions, this.schemaContext, this.genTypeDefsContextMap);
}
@Override
- public String getTypeDefaultConstruction(LeafSchemaNode node) {
+ public String getTypeDefaultConstruction(final LeafSchemaNode node) {
return null;
}
@Override
- public String getConstructorPropertyName(SchemaNode node) {
+ public String getConstructorPropertyName(final SchemaNode node) {
return null;
}
@Override
- public String getParamNameFromType(TypeDefinition<?> type) {
+ public String getParamNameFromType(final TypeDefinition<?> type) {
return null;
}
public Map<String, Map<Date, Map<String, Type>>> getGenTypeDefsContextMap() {
- return genTypeDefsContextMap;
+ return this.genTypeDefsContextMap;
}
/**
* returned types (generated types).
*
*/
- private void resolveTypeDefsFromContext(final SchemaContext schemaContext, Map<String, Map<Date, Map<String,
- Type>>> genTypeDefsContextMap, Map<Module, Set<Type>> additionalTypes) {
+ private void resolveTypeDefsFromContext(final SchemaContext schemaContext, final Map<String, Map<Date, Map<String,
+ Type>>> genTypeDefsContextMap, final Map<Module, Set<Type>> additionalTypes) {
final Set<Module> modules = schemaContext.getModules();
Preconditions.checkArgument(modules != null, "Set of Modules cannot be NULL!");
final Module[] modulesArray = new Module[modules.size()];
int i = 0;
- for (Module modul : modules) {
+ for (final Module modul : modules) {
modulesArray[i++] = modul;
}
final List<Module> modulesSortedByDependency = org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort
final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
if (!(baseTypeDef instanceof LeafrefTypeDefinition) && !(baseTypeDef instanceof IdentityrefTypeDefinition)) {
- final Module module = findParentModule(schemaContext, parentNode);
+ final Module module = findParentModule(this.schemaContext, parentNode);
if (module != null) {
- final Map<Date, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(module.getName());
+ final Map<Date, Map<String, Type>> modulesByDate = this.genTypeDefsContextMap.get(module.getName());
final Map<String, Type> genTOs = modulesByDate.get(module.getRevision());
if (genTOs != null) {
return genTOs.get(typeDefinition.getQName().getLocalName());
Preconditions.checkArgument(refTypePath != null,
"Path reference of Enumeration Type Definition cannot be NULL!");
Preconditions.checkArgument(refType != null, "Reference to Enumeration Type cannot be NULL!");
- referencedTypes.put(refTypePath, refType);
+ this.referencedTypes.put(refTypePath, refType);
}
/**
* <li>if <code>basePackageName</code> equals null</li>
* </ul>
*/
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public GeneratedTOBuilder provideGeneratedTOBuilderForBitsTypeDefinition(final String basePackageName, final
TypeDefinition<?> typeDef, final String typeDefName, final String moduleName) {
Preconditions.checkArgument(basePackageName != null, "Base Package Name cannot be NULL!");
if (typeDef instanceof BitsTypeDefinition) {
- BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) typeDef;
+ final BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) typeDef;
- final String typeName = BindingMapping.getClassName(typeDefName);
- final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeName);
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeDefName);
final String typedefDescription = encodeAngleBrackets(typeDef.getDescription());
genTOBuilder.setDescription(typedefDescription);
final List<Bit> bitList = bitsTypeDefinition.getBits();
GeneratedPropertyBuilder genPropertyBuilder;
for (final Bit bit : bitList) {
- String name = bit.getName();
- genPropertyBuilder = genTOBuilder.addProperty(BindingMapping.getPropertyName(name));
+ final String name = bit.getName();
+ genPropertyBuilder =
+ genTOBuilder.addProperty(NonJavaCharsConverter.convertIdentifier(name, JavaIdentifier.METHOD));
genPropertyBuilder.setReadOnly(true);
genPropertyBuilder.setReturnType(BaseYangTypes.BOOLEAN_TYPE);
* <li>if Qname of <code>typedef</code> is null</li>
* </ul>
*/
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public List<GeneratedTOBuilder> provideGeneratedTOBuildersForUnionTypeDef(final String basePackageName,
final UnionTypeDefinition typedef, final String typeDefName, final SchemaNode parentNode, final SchemaContext
- schemaContext, Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
Preconditions.checkNotNull(basePackageName, "Base Package Name cannot be NULL!");
Preconditions.checkNotNull(typedef, "Type Definition cannot be NULL!");
Preconditions.checkNotNull(typedef.getQName(), "Type definition QName cannot be NULL!");
final GeneratedTOBuilderImpl unionGenTOBuilder;
if (typeDefName != null && !typeDefName.isEmpty()) {
- final String typeName = BindingMapping.getClassName(typeDefName);
- unionGenTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeName);
+ unionGenTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeDefName);
final String typedefDescription = encodeAngleBrackets(typedef.getDescription());
unionGenTOBuilder.setDescription(typedefDescription);
unionGenTOBuilder.setReference(typedef.getReference());
}
public Map<Module, Set<Type>> getAdditionalTypes() {
- return additionalTypes;
+ return this.additionalTypes;
}
public static void addUnitsToGenTO(final GeneratedTOBuilder to, final String units) {
if (!Strings.isNullOrEmpty(units)) {
to.addConstant(Types.STRING, "Units", "\"" + units + "\"");
- GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("UNITS");
+ final GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("UNITS");
prop.setReturnType(Types.STRING);
to.addToStringProperty(prop);
}
}
private Type javaTypeForSchemaDefType(final TypeDefinition<?> typeDefinition, final SchemaNode
- parentNode, final Restrictions r, final SchemaContext schemaContext, Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ parentNode, final Restrictions r, final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!");
- String typedefName = typeDefinition.getQName().getLocalName();
+ final String typedefName = typeDefinition.getQName().getLocalName();
Preconditions.checkArgument(typedefName != null, "Type Definitions Local Name cannot be NULL!");
// Deal with base types
Type returnType = javaTypeForExtendedType(typeDefinition, schemaContext, genTypeDefsContextMap);
if (r != null && returnType instanceof GeneratedTransferObject) {
- GeneratedTransferObject gto = (GeneratedTransferObject) returnType;
- Module module = findParentModule(schemaContext, parentNode);
- String basePackageName = BindingMapping.getRootPackageName(module);
- String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typeDefinition
+ final GeneratedTransferObject gto = (GeneratedTransferObject) returnType;
+ final Module module = findParentModule(schemaContext, parentNode);
+ final String basePackageName = BindingMapping.getRootPackageName(module);
+ final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typeDefinition
.getPath(), BindingNamespaceType.Typedef);
- String genTOName = BindingMapping.getClassName(typedefName);
- String name = packageName + "." + genTOName;
+ final String genTOName = NonJavaCharsConverter.normalizeClassIdentifier(packageName, typedefName);
+ final String name = packageName + "." + genTOName;
if (!(returnType.getFullyQualifiedName().equals(name))) {
returnType = shadedTOWithRestrictions(gto, r);
}
* <code>typedef</code> equals <code>null</code>
*/
private Type typedefToGeneratedType(final String basePackageName, final Module module, final
- TypeDefinition<?> typedef, Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap, Map<Module,
+ TypeDefinition<?> typedef, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap, final Map<Module,
Set<Type>> additionalTypes, final SchemaContext schemaContext) {
final String moduleName = module.getName();
final Date moduleRevision = module.getRevision();
makeSerializable((GeneratedTOBuilderImpl) genTOBuilder);
returnType = genTOBuilder.toInstance();
// union builder
- GeneratedTOBuilder unionBuilder = new GeneratedTOBuilderImpl(genTOBuilder.getPackageName(),
+ final GeneratedTOBuilder unionBuilder = new GeneratedTOBuilderImpl(genTOBuilder.getPackageName(),
genTOBuilder.getName() + "Builder");
unionBuilder.setIsUnionBuilder(true);
- MethodSignatureBuilder method = unionBuilder.addMethod("getDefaultInstance");
+ final MethodSignatureBuilder method = unionBuilder.addMethod("getDefaultInstance");
method.setReturnType(returnType);
method.addParameter(Types.STRING, "defaultValue");
method.setAccessModifier(AccessModifier.PUBLIC);
* @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
*/
private Type javaTypeForExtendedType(final TypeDefinition<?> typeDefinition, final SchemaContext
- schemaContext, Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
final String typedefName = typeDefinition.getQName().getLocalName();
final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
returnType = provideTypeForEnum(enumTypeDef, typedefName, typeDefinition, schemaContext);
} else {
final Module module = findParentModule(schemaContext, typeDefinition);
- Restrictions r = BindingGeneratorUtil.getRestrictions(typeDefinition);
+ final Restrictions r = BindingGeneratorUtil.getRestrictions(typeDefinition);
if (module != null) {
final Map<Date, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(module.getName());
final Map<String, Type> genTOs = modulesByDate.get(module.getRevision());
* @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
*/
private Type javaTypeForLeafrefOrIdentityRef(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode,
- final SchemaContext schemaContext, Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
if (typeDefinition instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
if (isLeafRefSelfReference(leafref, parentNode, schemaContext)) {
*
*/
public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType, final SchemaNode parentNode,
- final SchemaContext schemaContext, Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
Type returnType = null;
Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!");
strXPath, getParentModule(parentNode, schemaContext).getName(), parentNode.getQName().getModule());
if (leafContainsEnumDefinition(dataNode)) {
- returnType = referencedTypes.get(dataNode.getPath());
+ returnType = this.referencedTypes.get(dataNode.getPath());
} else if (leafListContainsEnumDefinition(dataNode)) {
- returnType = Types.listTypeFor(referencedTypes.get(dataNode.getPath()));
+ returnType = Types.listTypeFor(this.referencedTypes.get(dataNode.getPath()));
} else {
returnType = resolveTypeFromDataSchemaNode(dataNode, schemaContext, genTypeDefsContextMap);
}
* @return JAVA <code>Type</code> representation of <code>dataNode</code>
*/
private Type resolveTypeFromDataSchemaNode(final SchemaNode dataNode, final SchemaContext schemaContext,
- Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
Type returnType = null;
if (dataNode != null) {
if (dataNode instanceof LeafSchemaNode) {
*/
private static Type provideTypeForIdentityref(final IdentityrefTypeDefinition idref, final SchemaContext schemaContext) {
//TODO: incompatibility with Binding spec v2, get first or only one
- QName baseIdQName = idref.getIdentities().iterator().next().getQName();
- Module module = schemaContext.findModuleByNamespaceAndRevision(baseIdQName.getNamespace(),
+ final QName baseIdQName = idref.getIdentities().iterator().next().getQName();
+ final Module module = schemaContext.findModuleByNamespaceAndRevision(baseIdQName.getNamespace(),
baseIdQName.getRevision());
IdentitySchemaNode identity = null;
- for (IdentitySchemaNode id : module.getIdentities()) {
+ for (final IdentitySchemaNode id : module.getIdentities()) {
if (id.getQName().equals(baseIdQName)) {
identity = id;
}
final String basePackageName = BindingMapping.getRootPackageName(module);
final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, identity.getPath
(), BindingNamespaceType.Typedef);
- final String genTypeName = BindingMapping.getClassName(identity.getQName());
+ final String genTypeName =
+ NonJavaCharsConverter.normalizeClassIdentifier(packageName, identity.getQName().getLocalName());
- Type baseType = Types.typeForClass(Class.class);
- Type paramType = Types.wildcardTypeFor(packageName, genTypeName);
+ final Type baseType = Types.typeForClass(Class.class);
+ final Type paramType = Types.wildcardTypeFor(packageName, genTypeName);
return Types.parameterizedTypeFor(baseType, paramType);
}
* @return generated TO builder which contains data from
* <code>typedef</code> and <code>basePackageName</code>
*/
+ @SuppressWarnings({ "rawtypes", "unchecked" })
private static GeneratedTOBuilderImpl typedefToTransferObject(final String basePackageName, final TypeDefinition<?> typedef, final String moduleName) {
final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typedef.getPath
final String typeDefTOName = typedef.getQName().getLocalName();
if ((packageName != null) && (typeDefTOName != null)) {
- final String genTOName = BindingMapping.getClassName(typeDefTOName);
- final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(packageName, genTOName);
+ final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(packageName, typeDefTOName);
final String typedefDescription = encodeAngleBrackets(typedef.getDescription());
newType.setDescription(typedefDescription);
}
private static GeneratedTransferObject shadedTOWithRestrictions(final GeneratedTransferObject gto, final Restrictions r) {
- GeneratedTOBuilder gtob = new GeneratedTOBuilderImpl(gto.getPackageName(), gto.getName());
- GeneratedTransferObject parent = gto.getSuperType();
+ final GeneratedTOBuilder gtob = new GeneratedTOBuilderImpl(gto.getPackageName(), gto.getName());
+ final GeneratedTransferObject parent = gto.getSuperType();
if (parent != null) {
gtob.setExtendsType(parent);
}
gtob.setRestrictions(r);
- for (GeneratedProperty gp : gto.getProperties()) {
- GeneratedPropertyBuilder gpb = gtob.addProperty(gp.getName());
+ for (final GeneratedProperty gp : gto.getProperties()) {
+ final GeneratedPropertyBuilder gpb = gtob.addProperty(gp.getName());
gpb.setValue(gp.getValue());
gpb.setReadOnly(gp.isReadOnly());
gpb.setAccessModifier(gp.getAccessModifier());
private static void updateUnionTypeAsProperty(final GeneratedTOBuilder unionGenTransObject, final Type type, final String propertyName) {
if (unionGenTransObject != null && type != null && !unionGenTransObject.containsProperty(propertyName)) {
final GeneratedPropertyBuilder propBuilder = unionGenTransObject
- .addProperty(BindingMapping.getPropertyName(propertyName));
+ .addProperty(NonJavaCharsConverter.convertIdentifier(propertyName, JavaIdentifier.METHOD));
propBuilder.setReturnType(type);
unionGenTransObject.addEqualsIdentity(propBuilder);
basePackageName, unionSubtype, newTOBuilderName, parentNode, schemaContext, genTypeDefsContextMap);
final GeneratedPropertyBuilder propertyBuilder;
- propertyBuilder = parentUnionGenTOBuilder.addProperty(BindingMapping.getPropertyName(newTOBuilderName));
+ propertyBuilder = parentUnionGenTOBuilder
+ .addProperty(NonJavaCharsConverter.convertIdentifier(newTOBuilderName, JavaIdentifier.METHOD));
propertyBuilder.setReturnType(subUnionGenTOBUilders.get(0));
parentUnionGenTOBuilder.addEqualsIdentity(propertyBuilder);
parentUnionGenTOBuilder.addToStringProperty(propertyBuilder);
Preconditions.checkState(!builders.isEmpty(), "No GeneratedTOBuilder objects generated from union %s", typedef);
final GeneratedTOBuilder resultTOBuilder = builders.remove(0);
- for (GeneratedTOBuilder genTOBuilder : builders) {
+ for (final GeneratedTOBuilder genTOBuilder : builders) {
resultTOBuilder.addEnclosingTransferObject(genTOBuilder);
}
*/
private static void resolveExtendedSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder, final
TypeDefinition<?> unionSubtype, final List<String> regularExpressions, final SchemaNode parentNode,
- final SchemaContext schemaContext, Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
final String unionTypeName = unionSubtype.getQName().getLocalName();
final Type genTO = findGenTO(unionTypeName, unionSubtype, schemaContext, genTypeDefsContextMap);
* @return string with the number suffix incremented by one (or 1 is added)
*/
private static String provideAvailableNameForGenTOBuilder(final String name) {
- Matcher mtch = NUMBERS_PATTERN.matcher(name);
+ final Matcher mtch = NUMBERS_PATTERN.matcher(name);
if (mtch.find()) {
final int newSuffix = Integer.valueOf(name.substring(mtch.start())) + 1;
return name.substring(0, mtch.start()) + newSuffix;
* <code>null</code> it it doesn't exist
*/
private static Type findGenTO(final String searchedTypeName, final SchemaNode parentNode,
- final SchemaContext schemaContext, Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
final Module typeModule = findParentModule(schemaContext, parentNode);
if (typeModule != null && typeModule.getName() != null) {
"Local Name in EnumTypeDefinition QName cannot be NULL!");
Preconditions.checkArgument(typeBuilder != null, "Generated Type Builder reference cannot be NULL!");
- final String enumerationName = BindingMapping.getClassName(enumName);
-
- final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumerationName);
+ final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumName);
final String enumTypedefDescription = encodeAngleBrackets(enumTypeDef.getDescription());
enumBuilder.setDescription(enumTypedefDescription);
enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
}
/////
- Module parentModule = getParentModule(parentNode, schemaContext);
+ final Module parentModule = getParentModule(parentNode, schemaContext);
if (!leafRefStrippedXPath.isAbsolute()) {
leafRefValueNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, parentModule,
parentNode, leafRefStrippedXPath);
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.javav2.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.javav2.generator.api.BindingGenerator;
+import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedProperty;
+import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedTransferObject;
+import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.javav2.model.api.MethodSignature;
+import org.opendaylight.mdsal.binding.javav2.model.api.Type;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class BindingGeneratorImplTest {
+
+ @Test
+ public void generatedTypesTest() throws Exception {
+ final BindingGenerator bg = new BindingGeneratorImpl(false);
+ final SchemaContext context = YangParserTestUtils.parseYangSource("/generator/test-list.yang");
+ final List<Type> generateTypes = bg.generateTypes(context);
+
+ assertNotNull(generateTypes);
+ assertTrue(!generateTypes.isEmpty());
+ assertEquals(7, generateTypes.size());
+ final int[] test_i = { 0 };
+ for (final Type t : generateTypes) {
+ if (t instanceof GeneratedTransferObject) {
+ final GeneratedTransferObject genTransferObj = (GeneratedTransferObject) t;
+ assertBaseGeneratedType(genTransferObj, "MyListKey",
+ "org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.key.my_list.wrapper");
+ assertEquals(3, genTransferObj.getProperties().size());
+ int test_j = 0;
+ for (final GeneratedProperty generatedProperty : genTransferObj.getProperties()) {
+ switch (generatedProperty.getName()) {
+ case "key":
+ assertEquals("MyListKey", generatedProperty.getReturnType().getName());
+ test_j++;
+ break;
+ case "key1":
+ assertEquals("MyListKey1", generatedProperty.getReturnType().getName());
+ test_j++;
+ break;
+ case "key2":
+ assertEquals("MyListKey2", generatedProperty.getReturnType().getName());
+ test_j++;
+ break;
+ default:
+ fail();
+ }
+ }
+ assertEquals(3, test_j);
+ test_i[0] += 1;
+ } else {
+ testActualType((GeneratedType) t, test_i);
+ }
+ }
+ assertEquals(7, test_i[0]);
+ }
+
+ private void testActualType(final GeneratedType t, final int[] test_i) {
+ MethodSignature methodSignature = null;
+ switch (t.getName()) {
+ case "TestListData":
+ assertEquals("org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314",
+ t.getPackageName());
+ methodSignature = t.getMethodDefinitions().get(0);
+ assertMethod(t, "getMyList", "List", "java.util", methodSignature);
+ test_i[0] += 1;
+ break;
+ case "MyListKey":
+ assertEquals("org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.key.my_list",
+ t.getPackageName());
+ methodSignature = t.getMethodDefinitions().get(0);
+ assertMethod(t, "getKey", "String", "java.lang", methodSignature);
+ test_i[0] += 1;
+ break;
+ case "MyListKey1":
+ assertEquals("org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.key.my_list",
+ t.getPackageName());
+ methodSignature = t.getMethodDefinitions().get(0);
+ assertMethod(t, "getKey1", "String", "java.lang", methodSignature);
+ test_i[0] += 1;
+ break;
+ case "MyListKey2":
+ assertEquals("org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.key.my_list",
+ t.getPackageName());
+ methodSignature = t.getMethodDefinitions().get(0);
+ assertMethod(t, "getKey2", "String", "java.lang", methodSignature);
+ test_i[0] += 1;
+ break;
+ case "MyListFoo":
+ assertEquals("org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.data.my_list",
+ t.getPackageName());
+ methodSignature = t.getMethodDefinitions().get(0);
+ assertMethod(t, "getFoo", "String", "java.lang", methodSignature);
+ test_i[0] += 1;
+ break;
+ case "MyList":
+ assertEquals("org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.data",
+ t.getPackageName());
+ assertEquals(5, t.getMethodDefinitions().size());
+ int test_j = 0;
+ for (final MethodSignature m : t.getMethodDefinitions()) {
+ switch (m.getName()) {
+ case "getKey":
+ assertMethod(t, "getKey", "MyListKey",
+ "org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.key.my_list.wrapper",
+ m);
+ test_j++;
+ break;
+ case "getMyListKey1":
+ assertMethod(t, "getMyListKey1", "MyListKey1",
+ "org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.key.my_list",
+ m);
+ test_j++;
+ break;
+ case "getMyListKey2":
+ assertMethod(t, "getMyListKey2", "MyListKey2",
+ "org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.key.my_list",
+ m);
+ test_j++;
+ break;
+ case "getMyListFoo":
+ assertMethod(t, "getMyListFoo", "MyListFoo",
+ "org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.data.my_list",
+ m);
+ test_j++;
+ break;
+ case "getMyListKey":
+ assertMethod(t, "getMyListKey", "MyListKey",
+ "org.opendaylight.mdsal.gen.javav2.urn.test.simple.test.list.rev170314.key.my_list",
+ m);
+ test_j++;
+ break;
+ default:
+ fail();
+ }
+ }
+ assertEquals(5, test_j);
+ test_i[0] += 1;
+ break;
+ default:
+ fail();
+ }
+ }
+
+ private void assertBaseGeneratedType(final GeneratedType genType, final String name, final String packageName) {
+ assertEquals(name, genType.getName());
+
+ }
+
+ private void assertMethod(final GeneratedType definingTypeExpected, final String nameExpected,
+ final String typeNameExpected, final String typePackageNameExpected,
+ final MethodSignature methodSignature) {
+ assertEquals(definingTypeExpected, methodSignature.getDefiningType());
+ assertEquals(nameExpected, methodSignature.getName());
+ assertEquals(typeNameExpected, methodSignature.getReturnType().getName());
+ assertEquals(typePackageNameExpected, methodSignature.getReturnType().getPackageName());
+ }
+
+}
--- /dev/null
+module test-lesf-module {
+ yang-version 1.1;
+
+ namespace "urn:test:simple:test:leaf";
+ prefix tlf;
+ organization "leaf.list.org";
+ revision "2017-03-14";
+
+ leaf foo {
+ type string;
+ }
+}
\ No newline at end of file
--- /dev/null
+module test-list {
+ yang-version 1.1;
+
+ namespace "urn:test:simple:test:list";
+ prefix test-list;
+ organization "test.list.org";
+ revision "2017-03-14";
+
+ list my-list {
+ key "key key1 key2";
+ leaf key{
+ type string;
+ }
+ leaf key1 {
+ type string;
+ }
+ leaf key2 {
+ type string;
+ }
+ leaf foo{
+ type string;
+ }
+ }
+
+}
\ No newline at end of file
* string with the name for this <code>Type</code>
*/
protected AbstractBaseType(final String pkName, final String name) {
- this.packageName = Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
- this.name = Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
+ Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
+ Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
+ this.packageName = NonJavaCharsConverter.convertFullPackageName(pkName);
+ this.name = NonJavaCharsConverter.normalizeClassIdentifier(pkName, name);
+ }
+
+ /**
+ * Constructs the instance of this class with the concrete package name type
+ * name.
+ *
+ * @param pkName
+ * string with the package name to which this <code>Type</code>
+ * belongs
+ * @param name
+ * string with the name for this <code>Type</code>
+ * @param isNormalized
+ * true if pkName and name are normalized
+ */
+ protected AbstractBaseType(final String pkName, final String name, final boolean isNormalized) {
+ Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
+ Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
+ if (isNormalized) {
+ this.packageName = pkName;
+ this.name = name;
+ } else {
+ this.packageName = NonJavaCharsConverter.convertFullPackageName(pkName);
+ this.name = NonJavaCharsConverter.normalizeClassIdentifier(pkName, name);
+ }
}
@Override
dout.writeUTF(to.getName());
dout.writeInt(to.isAbstract() ? 3 : 7);
- for (Type ifc : sortedCollection(SUID_NAME_COMPARATOR, to.getImplementsTypes())) {
+ for (final Type ifc : sortedCollection(SUID_NAME_COMPARATOR, to.getImplementsTypes())) {
dout.writeUTF(ifc.getFullyQualifiedName());
}
- for (GeneratedPropertyBuilder gp : sortedCollection(SUID_MEMBER_COMPARATOR, to.getProperties())) {
+ for (final GeneratedPropertyBuilder gp : sortedCollection(SUID_MEMBER_COMPARATOR, to.getProperties())) {
dout.writeUTF(gp.getName());
}
- for (MethodSignatureBuilder m : sortedCollection(SUID_MEMBER_COMPARATOR, to.getMethodDefinitions())) {
+ for (final MethodSignatureBuilder m : sortedCollection(SUID_MEMBER_COMPARATOR, to.getMethodDefinitions())) {
if (!(m.getAccessModifier().equals(AccessModifier.PRIVATE))) {
dout.writeUTF(m.getName());
dout.write(m.getAccessModifier().ordinal());
}
dout.flush();
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new IllegalStateException("Failed to hash object " + to, e);
}
sb.append(basePackageName)
.append('.')
.append(namespaceType.getPackagePrefix());
- return sb.toString();
+ return NonJavaCharsConverter.convertFullPackageName(sb.toString());
}
- return basePackageName;
+ return NonJavaCharsConverter.convertFullPackageName(basePackageName);
}
return generateNormalizedPackageName(basePackageName, pathFromRoot, size, namespaceType);
}
public static Restrictions getRestrictions(final TypeDefinition<?> type) {
- if (type == null || type.getBaseType() == null) {
+ if ((type == null) || (type.getBaseType() == null)) {
if (type instanceof DecimalTypeDefinition) {
final DecimalTypeDefinition decimal = (DecimalTypeDefinition) type;
final DecimalTypeBuilder tmpBuilder = BaseTypes.decimalTypeBuilder(decimal.getPath());
if (type instanceof BinaryTypeDefinition) {
final BinaryTypeDefinition binary = (BinaryTypeDefinition)type;
final BinaryTypeDefinition base = binary.getBaseType();
- if (base != null && base.getBaseType() != null) {
+ if ((base != null) && (base.getBaseType() != null)) {
length = currentOrEmpty(binary.getLengthConstraints(), base.getLengthConstraints());
} else {
length = binary.getLengthConstraints();
final DecimalTypeDefinition decimal = (DecimalTypeDefinition)type;
final DecimalTypeDefinition base = decimal.getBaseType();
- if (base != null && base.getBaseType() != null) {
+ if ((base != null) && (base.getBaseType() != null)) {
range = currentOrEmpty(decimal.getRangeConstraints(), base.getRangeConstraints());
} else {
range = decimal.getRangeConstraints();
final IntegerTypeDefinition integer = (IntegerTypeDefinition)type;
final IntegerTypeDefinition base = integer.getBaseType();
- if (base != null && base.getBaseType() != null) {
+ if ((base != null) && (base.getBaseType() != null)) {
range = currentOrEmpty(integer.getRangeConstraints(), base.getRangeConstraints());
} else {
range = integer.getRangeConstraints();
} else if (type instanceof StringTypeDefinition) {
final StringTypeDefinition string = (StringTypeDefinition)type;
final StringTypeDefinition base = string.getBaseType();
- if (base != null && base.getBaseType() != null) {
+ if ((base != null) && (base.getBaseType() != null)) {
length = currentOrEmpty(string.getLengthConstraints(), base.getLengthConstraints());
} else {
length = string.getLengthConstraints();
final UnsignedIntegerTypeDefinition unsigned = (UnsignedIntegerTypeDefinition)type;
final UnsignedIntegerTypeDefinition base = unsigned.getBaseType();
- if (base != null && base.getBaseType() != null) {
+ if ((base != null) && (base.getBaseType() != null)) {
range = currentOrEmpty(unsigned.getRangeConstraints(), base.getRangeConstraints());
} else {
range = unsigned.getRangeConstraints();
protected MessageDigest initialValue() {
try {
return MessageDigest.getInstance("SHA");
- } catch (NoSuchAlgorithmException e) {
+ } catch (final NoSuchAlgorithmException e) {
throw new IllegalStateException("Failed to get a SHA digest provider", e);
}
}
final Builder<PatternConstraint> builder = ImmutableList.builder();
boolean filtered = false;
- for (PatternConstraint c : constraints) {
+ for (final PatternConstraint c : constraints) {
if (containsConstraint(type.getBaseType(), c)) {
filtered = true;
} else {
package org.opendaylight.mdsal.binding.javav2.generator.util;
import com.google.common.annotations.Beta;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import java.util.List;
* - part of package name
* @return normalized name
*/
- @VisibleForTesting
public static String normalizePackageNamePart(final String packageNamePart) {
// if part of package name consist from java or windows reserved word, return it with
// underscore at the end and in lower case
import org.opendaylight.mdsal.binding.javav2.model.api.Restrictions;
import org.opendaylight.mdsal.binding.javav2.model.api.Type;
import org.opendaylight.mdsal.binding.javav2.model.api.WildcardType;
+import org.opendaylight.mdsal.binding.javav2.spec.base.RpcCallback;
import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentable;
import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
-import org.opendaylight.mdsal.binding.javav2.spec.base.RpcCallback;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
new CacheLoader<Class<?>, ConcreteType>() {
@Override
- public ConcreteType load(Class<?> key) throws Exception {
+ public ConcreteType load(final Class<?> key) throws Exception {
return new ConcreteTypeImpl(key.getPackage().getName(), key.getSimpleName(), null);
}
};
@Override
public Restrictions getRestrictions() {
- return restrictions;
+ return this.restrictions;
}
}
@Override
public Restrictions getRestrictions() {
- return restrictions;
+ return this.restrictions;
}
}
* array of actual parameters
*/
public ParameterizedTypeImpl(final Type rawType, final Type[] actTypes) {
- super(rawType.getPackageName(), rawType.getName());
+ super(rawType.getPackageName(), rawType.getName(), true);
this.rawType = rawType;
this.actualTypes = actTypes.clone();
}
@Override
public Type[] getActualTypeArguments() {
- return actualTypes;
+ return this.actualTypes;
}
@Override
public Type getRawType() {
- return rawType;
+ return this.rawType;
}
}
@Override
public List<RangeConstraint> getRangeConstraints() {
- return rangeConstraints;
+ return this.rangeConstraints;
}
@Override
private final boolean isAbstract;
public AbstractGeneratedType(final AbstractGeneratedTypeBuilder<?> builder) {
- super(builder.getPackageName(), builder.getName());
+ super(builder.getPackageName(), builder.getName(), true);
this.parent = builder.getParent();
this.comment = builder.getComment();
this.annotations = toUnmodifiableAnnotations(builder.getAnnotations());
@Override
public Type getParentType() {
- return parent;
+ return this.parent;
}
@Override
public String getComment() {
- return comment;
+ return this.comment;
}
@Override
public List<AnnotationType> getAnnotations() {
- return annotations;
+ return this.annotations;
}
@Override
public boolean isAbstract() {
- return isAbstract;
+ return this.isAbstract;
}
@Override
public List<Type> getImplements() {
- return implementsTypes;
+ return this.implementsTypes;
}
@Override
public List<GeneratedType> getEnclosedTypes() {
- return enclosedTypes;
+ return this.enclosedTypes;
}
@Override
public List<Enumeration> getEnumerations() {
- return enumerations;
+ return this.enumerations;
}
@Override
public List<Constant> getConstantDefinitions() {
- return constants;
+ return this.constants;
}
@Override
public List<MethodSignature> getMethodDefinitions() {
- return methodSignatures;
+ return this.methodSignatures;
}
@Override
public List<GeneratedProperty> getProperties() {
- return properties;
+ return this.properties;
}
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
+ final StringBuilder builder = new StringBuilder();
builder.append("GeneratedType [packageName=");
builder.append(getPackageName());
builder.append(", name=");
builder.append(getName());
- if (parent != null) {
+ if (this.parent != null) {
builder.append(", parent=");
- builder.append(parent.getFullyQualifiedName());
+ builder.append(this.parent.getFullyQualifiedName());
} else {
builder.append(", parent=null");
}
builder.append(", comment=");
- builder.append(comment);
+ builder.append(this.comment);
builder.append(", annotations=");
- builder.append(annotations);
+ builder.append(this.annotations);
builder.append(", enclosedTypes=");
- builder.append(enclosedTypes);
+ builder.append(this.enclosedTypes);
builder.append(", enumerations=");
- builder.append(enumerations);
+ builder.append(this.enumerations);
builder.append(", constants=");
- builder.append(constants);
+ builder.append(this.constants);
builder.append(", methodSignatures=");
- builder.append(methodSignatures);
+ builder.append(this.methodSignatures);
builder.append("]");
return builder.toString();
}
private List<QName> schemaPath;
public EnumerationBuilderImpl(final String packageName, final String name) {
- super(packageName, NonJavaCharsConverter.normalizeClassIdentifier(packageName, name));
+ super(packageName, name);
}
public void setReference(final String reference) {
public EnumerationImpl(final Type definingType, final List<AnnotationTypeBuilder> annotationBuilders,
final String packageName, final String name, final List<Pair> values, final String description,
final String reference, final String moduleName, final List<QName> schemaPath) {
- super(packageName, name);
+ super(packageName, name, true);
this.definingType = definingType;
this.values = values;
this.description = description;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*@
+@import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier.CLASS
+@import org.opendaylight.mdsal.binding.javav2.generator.util.NonJavaCharsConverter.convertIdentifier
@import org.opendaylight.mdsal.binding.javav2.java.api.generator.util.TextTemplateUtil.getFormattedRevision
@import org.opendaylight.mdsal.binding.javav2.java.api.generator.util.TextTemplateUtil.getSourcePath
@import org.opendaylight.mdsal.binding.javav2.java.api.generator.renderers.YangModuleInfoTemplateRenderer.getSortedQName
-@import org.opendaylight.mdsal.binding.javav2.util.BindingMapping.getClassName
@import org.opendaylight.mdsal.binding.javav2.util.BindingMapping.getRootPackageName
@import org.opendaylight.mdsal.binding.javav2.util.BindingMapping.MODULE_INFO_CLASS_NAME
@import org.opendaylight.yangtools.yang.model.api.Module
@generateSubInfo(module: Module) = {
@for(submodule <- module.getSubmodules) {
- private static final class @{getClassName(submodule.getName)}Info implements @{importedNames.get("yangModuleInfo")} {
+ private static final class @{convertIdentifier(submodule.getName, CLASS)}Info implements @{importedNames.get("yangModuleInfo")} {
- private static final @{importedNames.get("yangModuleInfo")} INSTANCE = new @{getClassName(submodule.getName)}Info();
+ private static final @{importedNames.get("yangModuleInfo")} INSTANCE = new @{convertIdentifier(submodule.getName, CLASS)}Info();
private final @{importedNames.get("string")} name = "@{submodule.getName}";
private final @{importedNames.get("string")} namespace = "@{submodule.getNamespace.toString}";
return INSTANCE;
}
- @{classBody(submodule, getClassName(submodule.getName + "Info"))}
+ @{classBody(submodule, convertIdentifier(submodule.getName + "Info", CLASS))}
}
}
}
}
@if(!module.getSubmodules.isEmpty) {
@for(submodule <- module.getSubmodules) {
- set.add(@{getClassName(submodule.getName)}Info.getInstance());
+ set.add(@{convertIdentifier(submodule.getName, CLASS)}Info.getInstance());
}
}
@if(!module.getImports.isEmpty && !module.getSubmodules.isEmpty) {
[source,yang]
----
list foo {
- key identifier key fookey;
+ key "identifier key fookey";
leaf identifier {
type union {
type string;
leaf fookey {
type string;
}
+
+ leaf boo-non-key {
+ type string;
+ }
}
----
[uml, file="list-Keyed.png"]
set namespaceSeparator none
interface data.Foo {
+ + getFooIdentifier() : key.foo.FooIdentifier
+ + getFooKey() : key.foo.FooKey
+ + getFooFooKey() : key.foo.FooFooKey
+ + getKey() : key.foo.wrapper.FooKey
+}
+
+interface key.foo.wrapper.FooKey {
+ + getFooIdentifier() : key.foo.FooIdentifier
+ + getFooKey() : key.foo.FooKey
+ + getFooFooKey() : key.foo.FooFooKey
}
+interface type.foo.identifier.IdentifierUnion
interface key.foo.FooIdentifier {
+ + getIdentifier() : type.foo.identifier.IdentifierUnion
}
interface key.foo.FooKey {
+ + getKey() : String
}
interface key.foo.FooFooKey {
+ + getFooKey() : String
}
-interface type.foo.identifier.IdentifierUnion {
+interface data.foo.FooBooNonKey {
+ + getBooNonKey() : String
}
-data.Foo o- key.foo.FooIdentifier
-data.Foo o- key.foo.FooKey
-data.Foo o- key.foo.FooFooKey
key.foo.FooIdentifier o- type.foo.identifier.IdentifierUnion
+
+data.foo.FooBooNonKey -u-|> data.Foo
+key.foo.wrapper.FooKey -u-|> data.Foo
+
+key.foo.FooKey -u-|> data.Foo
+key.foo.FooFooKey -u-|> data.Foo
+key.foo.FooIdentifier -u-|> data.Foo
+
+key.foo.FooKey -u-|> key.foo.wrapper.FooKey
+key.foo.FooFooKey -u-|> key.foo.wrapper.FooKey
+key.foo.FooIdentifier -u-|> key.foo.wrapper.FooKey
--
==== List without Key
package org.opendaylight.mdsal.binding.javav2.util;
import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.common.annotations.Beta;
-import com.google.common.base.CharMatcher;
-import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import java.text.SimpleDateFormat;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
/**
*/
public static final String PACKAGE_PREFIX = "org.opendaylight.mdsal.gen.javav2";
- private static final Splitter CAMEL_SPLITTER = Splitter.on(CharMatcher.anyOf(" _.-/").precomputed())
- .omitEmptyStrings().trimResults();
private static final Pattern COLON_SLASH_SLASH = Pattern.compile("://", Pattern.LITERAL);
private static final String QUOTED_DOT = Matcher.quoteReplacement(".");
public static final String MODULE_INFO_CLASS_NAME = "$YangModuleInfoImpl";
return packageNameBuilder.toString();
}
- /**
- * Prepares valid Java class name
- * @param localName
- * @return class name
- */
- public static String getClassName(final String localName) {
- checkArgument(localName != null, "Name should not be null.");
- return toFirstUpper(toCamelCase(localName));
- }
-
- public static String getClassName(final QName name) {
- checkArgument(name != null, "Name should not be null.");
- return toFirstUpper(toCamelCase(name.getLocalName()));
- }
-
- private static String toCamelCase(final String rawString) {
- checkArgument(rawString != null, "String should not be null");
- final Iterable<String> components = CAMEL_SPLITTER.split(rawString);
- final StringBuilder builder = new StringBuilder();
- for (final String comp : components) {
- builder.append(toFirstUpper(comp));
- }
- return checkNumericPrefix(builder.toString());
- }
-
- private static String checkNumericPrefix(final String rawString) {
- if ((rawString == null) || rawString.isEmpty()) {
- return rawString;
- }
- if (Character.isDigit(rawString.charAt(0))) {
- return "_" + rawString;
- } else {
- return rawString;
- }
- }
-
- /**
- * Returns the {@link String} {@code s} with an
- * {@link Character#isUpperCase(char) upper case} first character. This
- * function is null-safe.
- *
- * @param s
- * the string that should get an upper case first character. May
- * be <code>null</code>.
- * @return the {@link String} {@code s} with an upper case first character
- * or <code>null</code> if the input {@link String} {@code s} was
- * <code>null</code>.
- */
- public static String toFirstUpper(final String s) {
- if (s == null || s.length() == 0) {
- return s;
- }
- if (Character.isUpperCase(s.charAt(0))) {
- return s;
- }
- if (s.length() == 1) {
- return s.toUpperCase();
- }
- return s.substring(0, 1).toUpperCase() + s.substring(1);
- }
-
- /**
- * Prepares Java property name for method getter code generation
- * @param yangIdentifier given YANG element local name
- * @return property name
- */
- public static String getPropertyName(final String yangIdentifier) {
- final String potential = toFirstLower(toCamelCase(yangIdentifier));
- if ("class".equals(potential)) {
- return "xmlClass";
- }
- return potential;
- }
-
- /**
- * Returns the {@link String} {@code s} with an
- * {@link Character#isLowerCase(char) lower case} first character. This
- * function is null-safe.
- *
- * @param s
- * the string that should get an lower case first character. May
- * be <code>null</code>.
- * @return the {@link String} {@code s} with an lower case first character
- * or <code>null</code> if the input {@link String} {@code s} was
- * <code>null</code>.
- */
- private static String toFirstLower(final String s) {
- if (s == null || s.length() == 0) {
- return s;
- }
- if (Character.isLowerCase(s.charAt(0))) {
- return s;
- }
- if (s.length() == 1) {
- return s.toLowerCase();
- }
- return s.substring(0, 1).toLowerCase() + s.substring(1);
- }
-
//TODO: further implementation of static util methods...
}