From: lsedlak Date: Wed, 19 Jun 2013 15:26:23 +0000 (+0200) Subject: Extended binding-model-api to support of Enclosed Generated Types and TOs. X-Git-Tag: releasepom-0.1.0~341^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=f607c4b0b922281f1ddd5fda2e7b49ca67d26ecd Extended binding-model-api to support of Enclosed Generated Types and TOs. Added javadocs for whole binding-model-api project (including builders); Refactored model structure for MethodSignature - added TypeMember interface which extracts common functionality for methods and properties. MethodSignature and GeneratedProperty now extends TypeMember. Added TypeMemberBuilder interface. In Binding-generator-util project Refactored whole Building mechanism - removed code duplicities and added more abstraction layeres for abstract builders. Automaticly modified all dependant project java files that uses binding-model-api. Added isAbstract flag method into GeneratedType interface and setAbstract method into GeneratedTypeBuilder to notify if generated type (class) is declared as abstract. Added isAbstract flag method into MethodSignature interface and setAbstract method into MethodSignatureBuilder to notify if generated method is declared as abstract. Fixed bug (bad typecast) when resolving Identityref type definition in TypeProviderImpl in binding-generator-impl. Added Support to generate Bits types - JG. Change-Id: I983cdad79c8779940e75937f97ba0575e753830e Signed-off-by: Lukas Sedlak Signed-off-by: Jozef Gloncak --- diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java index b89dbb44ac..2235bfb2a3 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java @@ -334,7 +334,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { final Type rpcRes = Types.parameterizedTypeFor( Types.typeForClass(RpcResult.class), outTypeInstance); - method.addReturnType(Types.parameterizedTypeFor(future, rpcRes)); + method.setReturnType(Types.parameterizedTypeFor(future, rpcRes)); for (DataNodeIterator it : rpcInOut) { List nContainers = it.allContainers(); if ((nContainers != null) && !nContainers.isEmpty()) { @@ -446,16 +446,16 @@ public final class BindingGeneratorImpl implements BindingGenerator { GeneratedTransferObject gto = new GeneratedTOBuilderImpl( returnTypePkgName, returnTypeName).toInstance(); - newType.addExtendsType(gto); + newType.setExtendsType(gto); } else { - newType.addExtendsType(Types.getBaseIdentityTO()); + newType.setExtendsType(Types.getBaseIdentityTO()); } - - return newType.toIdentityInstance(); + newType.setAbstract(true); + return newType.toInstance(); } private List allGroupingsToGenTypes(Module module) { - final List genTypes = new ArrayList(); + final List genTypes = new ArrayList<>(); final String basePackageName = moduleNamespaceToPackageName(module); Set groupings = module.getGroupings(); if (groupings != null && !groupings.isEmpty()) { @@ -804,8 +804,8 @@ public final class BindingGeneratorImpl implements BindingGenerator { .addProperty(parseToClassName(leafName)); propBuilder.setReadOnly(isReadOnly); - propBuilder.addReturnType(returnType); - propBuilder.addComment(leafDesc); + propBuilder.setReturnType(returnType); + propBuilder.setComment(leafDesc); toBuilder.addEqualsIdentity(propBuilder); toBuilder.addHashIdentity(propBuilder); @@ -946,8 +946,8 @@ public final class BindingGeneratorImpl implements BindingGenerator { final MethodSignatureBuilder getMethod = interfaceBuilder .addMethod(getterMethodName(schemaNodeName)); - getMethod.addComment(comment); - getMethod.addReturnType(returnType); + getMethod.setComment(comment); + getMethod.setReturnType(returnType); return getMethod; } @@ -959,10 +959,10 @@ public final class BindingGeneratorImpl implements BindingGenerator { final MethodSignatureBuilder setMethod = interfaceBuilder .addMethod(setterMethodName(schemaNodeName)); - setMethod.addComment(comment); + setMethod.setComment(comment); setMethod.addParameter(parameterType, parseToValidParamName(schemaNodeName)); - setMethod.addReturnType(Types.voidType()); + setMethod.setReturnType(Types.voidType()); return setMethod; } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/TypeProviderImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/TypeProviderImpl.java index 96069c273c..9410ffe1de 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/TypeProviderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/TypeProviderImpl.java @@ -21,11 +21,9 @@ import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedT import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder; import org.opendaylight.controller.yang.common.QName; import org.opendaylight.controller.yang.model.api.*; -import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition; +import org.opendaylight.controller.yang.model.api.type.*; +import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition.Bit; import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition.EnumPair; -import org.opendaylight.controller.yang.model.api.type.IdentityrefTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition; import org.opendaylight.controller.yang.model.util.ExtendedType; import java.util.HashMap; @@ -56,13 +54,13 @@ public final class TypeProviderImpl implements TypeProvider { public void putReferencedType(final SchemaPath refTypePath, final Type refType) { if (refTypePath == null) { - throw new IllegalArgumentException("Path reference of " + - "Enumeration Type Definition cannot be NULL!"); + throw new IllegalArgumentException("Path reference of " + + "Enumeration Type Definition cannot be NULL!"); } if (refType == null) { - throw new IllegalArgumentException("Reference to Enumeration " + - "Type cannot be NULL!"); + throw new IllegalArgumentException("Reference to Enumeration " + + "Type cannot be NULL!"); } referencedTypes.put(refTypePath, refType); } @@ -85,16 +83,13 @@ public final class TypeProviderImpl implements TypeProvider { final TypeDefinition typeDefinition) { Type returnType = null; if (typeDefinition == null) { - throw new IllegalArgumentException("Type Definition cannot be " + - "NULL!"); + throw new IllegalArgumentException("Type Definition cannot be NULL!"); } if (typeDefinition.getQName() == null) { - throw new IllegalArgumentException("Type Definition cannot have " + - "non specified QName (QName cannot be NULL!)"); + throw new IllegalArgumentException("Type Definition cannot have non specified QName (QName cannot be NULL!)"); } if (typeDefinition.getQName().getLocalName() == null) { - throw new IllegalArgumentException("Type Definitions Local Name " + - "cannot be NULL!"); + throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!"); } final String typedefName = typeDefinition.getQName().getLocalName(); if (typeDefinition instanceof ExtendedType) { @@ -104,15 +99,15 @@ public final class TypeProviderImpl implements TypeProvider { final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) baseTypeDef; returnType = provideTypeForLeafref(leafref); } else if (baseTypeDef instanceof IdentityrefTypeDefinition) { - final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition)typeDefinition; + final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) baseTypeDef; returnType = returnTypeForIdentityref(idref); } else if (baseTypeDef instanceof EnumTypeDefinition) { final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef; returnType = resolveEnumFromTypeDefinition(enumTypeDef, typedefName); } else { - final Module module = findParentModuleForTypeDefinition(schemaContext, - typeDefinition); + final Module module = findParentModuleForTypeDefinition( + schemaContext, typeDefinition); if (module != null) { final Map genTOs = genTypeDefsContextMap .get(module.getName()); @@ -130,32 +125,32 @@ public final class TypeProviderImpl implements TypeProvider { final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition; returnType = provideTypeForLeafref(leafref); } else if (typeDefinition instanceof IdentityrefTypeDefinition) { - final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition)typeDefinition; + final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) typeDefinition; returnType = returnTypeForIdentityref(idref); } else { returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER .javaTypeForSchemaDefinitionType(typeDefinition); } } - //TODO: add throw exception when we will be able to resolve ALL yang + // TODO: add throw exception when we will be able to resolve ALL yang // types! -// if (returnType == null) { -// throw new IllegalArgumentException("Type Provider can't resolve " + -// "type for specified Type Definition " + typedefName); -// } + // if (returnType == null) { + // throw new IllegalArgumentException("Type Provider can't resolve " + + // "type for specified Type Definition " + typedefName); + // } return returnType; } - + private Type returnTypeForIdentityref(IdentityrefTypeDefinition idref) { QName baseIdQName = idref.getIdentity(); Module module = schemaContext.findModuleByNamespace(baseIdQName.getNamespace()); IdentitySchemaNode identity = null; - for(IdentitySchemaNode id : module.getIdentities()) { - if(id.getQName().equals(baseIdQName)) { + for (IdentitySchemaNode id : module.getIdentities()) { + if (id.getQName().equals(baseIdQName)) { identity = id; } } - if(identity == null) { + if (identity == null) { throw new IllegalArgumentException("Target identity '" + baseIdQName + "' do not exists"); } @@ -173,16 +168,13 @@ public final class TypeProviderImpl implements TypeProvider { final TypeDefinition typeDefinition) { Type returnType = null; if (typeDefinition == null) { - throw new IllegalArgumentException("Type Definition cannot be " + - "NULL!"); + throw new IllegalArgumentException("Type Definition cannot be NULL!"); } if (typeDefinition.getQName() == null) { - throw new IllegalArgumentException("Type Definition cannot have " + - "non specified QName (QName cannot be NULL!)"); + throw new IllegalArgumentException("Type Definition cannot have non specified QName (QName cannot be NULL!)"); } if (typeDefinition.getQName() == null) { - throw new IllegalArgumentException("Type Definitions Local Name " + - "cannot be NULL!"); + throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!"); } final String typedefName = typeDefinition.getQName().getLocalName(); @@ -191,8 +183,8 @@ public final class TypeProviderImpl implements TypeProvider { if (!(baseTypeDef instanceof LeafrefTypeDefinition) && !(baseTypeDef instanceof IdentityrefTypeDefinition)) { - final Module module = findParentModuleForTypeDefinition(schemaContext, - typeDefinition); + final Module module = findParentModuleForTypeDefinition( + schemaContext, typeDefinition); if (module != null) { final Map genTOs = genTypeDefsContextMap @@ -209,8 +201,7 @@ public final class TypeProviderImpl implements TypeProvider { private TypeDefinition baseTypeDefForExtendedType( final TypeDefinition extendTypeDef) { if (extendTypeDef == null) { - throw new IllegalArgumentException("Type Definiition reference " + - "cannot be NULL!"); + throw new IllegalArgumentException("Type Definiition reference cannot be NULL!"); } final TypeDefinition baseTypeDef = extendTypeDef.getBaseType(); if (baseTypeDef instanceof ExtendedType) { @@ -224,13 +215,11 @@ public final class TypeProviderImpl implements TypeProvider { public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType) { Type returnType = null; if (leafrefType == null) { - throw new IllegalArgumentException("Leafref Type Definition " + - "reference cannot be NULL!"); + throw new IllegalArgumentException("Leafref Type Definition reference cannot be NULL!"); } if (leafrefType.getPathStatement() == null) { - throw new IllegalArgumentException("The Path Statement for " + - "Leafref Type Definition cannot be NULL!"); + throw new IllegalArgumentException("The Path Statement for Leafref Type Definition cannot be NULL!"); } final RevisionAwareXPath xpath = leafrefType.getPathStatement(); @@ -240,22 +229,23 @@ public final class TypeProviderImpl implements TypeProvider { if (strXPath.matches(".*//[.* | .*//].*")) { returnType = Types.typeForClass(Object.class); } else { - final Module module = findParentModuleForTypeDefinition(schemaContext, leafrefType); + final Module module = findParentModuleForTypeDefinition( + schemaContext, leafrefType); if (module != null) { final DataSchemaNode dataNode; if (xpath.isAbsolute()) { dataNode = findDataSchemaNode(schemaContext, module, xpath); } else { - dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, - module, leafrefType, xpath); + dataNode = findDataSchemaNodeForRelativeXPath( + schemaContext, module, leafrefType, xpath); } if (leafContainsEnumDefinition(dataNode)) { returnType = referencedTypes.get(dataNode.getPath()); } else if (leafListContainsEnumDefinition(dataNode)) { - returnType = Types.listTypeFor(referencedTypes.get( - dataNode.getPath())); + returnType = Types.listTypeFor(referencedTypes + .get(dataNode.getPath())); } else { returnType = resolveTypeFromDataSchemaNode(dataNode); } @@ -275,8 +265,7 @@ public final class TypeProviderImpl implements TypeProvider { return false; } - private boolean leafListContainsEnumDefinition( - final DataSchemaNode dataNode) { + private boolean leafListContainsEnumDefinition(final DataSchemaNode dataNode) { if (dataNode instanceof LeafListSchemaNode) { final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode; if (leafList.getType() instanceof EnumTypeDefinition) { @@ -289,25 +278,22 @@ public final class TypeProviderImpl implements TypeProvider { private Enumeration resolveEnumFromTypeDefinition( final EnumTypeDefinition enumTypeDef, final String enumName) { if (enumTypeDef == null) { - throw new IllegalArgumentException("EnumTypeDefinition reference " + - "cannot be NULL!"); + throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!"); } if (enumTypeDef.getValues() == null) { - throw new IllegalArgumentException("EnumTypeDefinition MUST " + - "contain at least ONE value definition!"); + throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!"); } if (enumTypeDef.getQName() == null) { - throw new IllegalArgumentException("EnumTypeDefinition MUST " + - "contain NON-NULL QName!"); + throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!"); } if (enumTypeDef.getQName().getLocalName() == null) { - throw new IllegalArgumentException("Local Name in " + - "EnumTypeDefinition QName cannot be NULL!"); + throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!"); } final String enumerationName = parseToClassName(enumName); - Module module = findParentModuleForTypeDefinition(schemaContext, enumTypeDef); + Module module = findParentModuleForTypeDefinition(schemaContext, + enumTypeDef); final String basePackageName = moduleNamespaceToPackageName(module); final EnumBuilder enumBuilder = new EnumerationBuilderImpl( @@ -320,24 +306,19 @@ public final class TypeProviderImpl implements TypeProvider { final EnumTypeDefinition enumTypeDef, final String enumName, final GeneratedTypeBuilder typeBuilder) { if (enumTypeDef == null) { - throw new IllegalArgumentException("EnumTypeDefinition reference " + - "cannot be NULL!"); + throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!"); } if (enumTypeDef.getValues() == null) { - throw new IllegalArgumentException("EnumTypeDefinition MUST " + - "contain at least ONE value definition!"); + throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!"); } if (enumTypeDef.getQName() == null) { - throw new IllegalArgumentException("EnumTypeDefinition MUST " + - "contain NON-NULL QName!"); + throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!"); } if (enumTypeDef.getQName().getLocalName() == null) { - throw new IllegalArgumentException("Local Name in " + - "EnumTypeDefinition QName cannot be NULL!"); + throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!"); } if (typeBuilder == null) { - throw new IllegalArgumentException("Generated Type Builder " + - "reference cannot be NULL!"); + throw new IllegalArgumentException("Generated Type Builder reference cannot be NULL!"); } final String enumerationName = parseToClassName(enumName); @@ -350,8 +331,7 @@ public final class TypeProviderImpl implements TypeProvider { } private void updateEnumPairsFromEnumTypeDef( - final EnumTypeDefinition enumTypeDef, - final EnumBuilder enumBuilder) { + final EnumTypeDefinition enumTypeDef, final EnumBuilder enumBuilder) { if (enumBuilder != null) { final List enums = enumTypeDef.getValues(); if (enums != null) { @@ -390,8 +370,7 @@ public final class TypeProviderImpl implements TypeProvider { private void resolveTypeDefsFromContext() { final Set modules = schemaContext.getModules(); if (modules == null) { - throw new IllegalArgumentException("Sef of Modules cannot be " + - "NULL!"); + throw new IllegalArgumentException("Sef of Modules cannot be NULL!"); } for (final Module module : modules) { if (module == null) { @@ -413,7 +392,8 @@ public final class TypeProviderImpl implements TypeProvider { final List extUnions = UnionDependencySort .sort(typeDefinitions); for (final ExtendedType extUnionType : extUnions) { - addUnionGeneratedTypeDefinition(basePackageName, extUnionType); + addUnionGeneratedTypeDefinition(basePackageName, + extUnionType); } } } @@ -424,7 +404,6 @@ public final class TypeProviderImpl implements TypeProvider { if ((basePackageName != null) && (moduleName != null) && (typedef != null) && (typedef.getQName() != null)) { - final String typedefName = typedef.getQName().getLocalName(); final TypeDefinition baseTypeDefinition = baseTypeDefForExtendedType(typedef); if (!(baseTypeDefinition instanceof LeafrefTypeDefinition) @@ -435,6 +414,11 @@ public final class TypeProviderImpl implements TypeProvider { returnType = resolveEnumFromTypeDefinition(enumTypeDef, typedefName); + } else if (baseTypeDefinition instanceof BitsTypeDefinition) { + final BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) baseTypeDefinition; + returnType = bitsTypedefToTransferObject(bitsTypeDefinition, + basePackageName, typedefName); + } else { final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER .javaTypeForSchemaDefinitionType(baseTypeDefinition); @@ -443,8 +427,8 @@ public final class TypeProviderImpl implements TypeProvider { javaType); } if (returnType != null) { - final Map typeMap = genTypeDefsContextMap.get - (moduleName); + final Map typeMap = genTypeDefsContextMap + .get(moduleName); if (typeMap != null) { typeMap.put(typedefName, returnType); } @@ -468,7 +452,7 @@ public final class TypeProviderImpl implements TypeProvider { final GeneratedPropertyBuilder genPropBuilder = genTOBuilder .addProperty(propertyName); - genPropBuilder.addReturnType(javaType); + genPropBuilder.setReturnType(javaType); genTOBuilder.addEqualsIdentity(genPropBuilder); genTOBuilder.addHashIdentity(genPropBuilder); genTOBuilder.addToStringProperty(genPropBuilder); @@ -480,26 +464,22 @@ public final class TypeProviderImpl implements TypeProvider { private void addUnionGeneratedTypeDefinition(final String basePackageName, final TypeDefinition typedef) { if (basePackageName == null) { - throw new IllegalArgumentException("Base Package Name cannot be " + - "NULL!"); + throw new IllegalArgumentException("Base Package Name cannot be NULL!"); } if (typedef == null) { - throw new IllegalArgumentException("Type Definition cannot be " + - "NULL!"); + throw new IllegalArgumentException("Type Definition cannot be NULL!"); } if (typedef.getQName() == null) { - throw new IllegalArgumentException("Type Definition cannot have " + - "non specified QName (QName cannot be NULL!)"); + throw new IllegalArgumentException("Type Definition cannot have non specified QName (QName cannot be NULL!)"); } final TypeDefinition baseTypeDefinition = typedef.getBaseType(); if ((baseTypeDefinition != null) && (baseTypeDefinition instanceof UnionTypeDefinition)) { final UnionTypeDefinition unionTypeDef = (UnionTypeDefinition) baseTypeDefinition; - final List> unionTypes = unionTypeDef - .getTypes(); - final Module parentModule = findParentModuleForTypeDefinition(schemaContext, - typedef); + final List> unionTypes = unionTypeDef.getTypes(); + final Module parentModule = findParentModuleForTypeDefinition( + schemaContext, typedef); Map genTOsMap = null; if (parentModule != null && parentModule.getName() != null) { @@ -510,17 +490,17 @@ public final class TypeProviderImpl implements TypeProvider { basePackageName, typedef); if ((unionTypes != null) && (unionGenTransObject != null)) { for (final TypeDefinition unionType : unionTypes) { - final String typeName = unionType.getQName() - .getLocalName(); + final String typeName = unionType.getQName().getLocalName(); if (unionType instanceof ExtendedType) { - final Module unionTypeModule = findParentModuleForTypeDefinition(schemaContext, - unionType); - if (unionTypeModule != null && unionTypeModule.getName() != null) { + final Module unionTypeModule = findParentModuleForTypeDefinition( + schemaContext, unionType); + if (unionTypeModule != null + && unionTypeModule.getName() != null) { final Map innerGenTOs = genTypeDefsContextMap .get(unionTypeModule.getName()); - final GeneratedTransferObject genTransferObject = - (GeneratedTransferObject) innerGenTOs.get(typeName); + final GeneratedTransferObject genTransferObject = (GeneratedTransferObject) innerGenTOs + .get(typeName); if (genTransferObject != null) { updateUnionTypeAsProperty(unionGenTransObject, genTransferObject, @@ -528,8 +508,7 @@ public final class TypeProviderImpl implements TypeProvider { } } } else if (unionType instanceof EnumTypeDefinition) { - final EnumBuilder - enumBuilder = resolveInnerEnumFromTypeDefinition( + final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition( (EnumTypeDefinition) unionType, typeName, unionGenTransObject); final Type enumRefType = new ReferencedTypeImpl( @@ -556,10 +535,9 @@ public final class TypeProviderImpl implements TypeProvider { final GeneratedTOBuilder unionGenTransObject, final Type type, final String propertyName) { if (unionGenTransObject != null && type != null) { - final GeneratedPropertyBuilder propBuilder = - unionGenTransObject.addProperty(parseToValidParamName( - propertyName)); - propBuilder.addReturnType(type); + final GeneratedPropertyBuilder propBuilder = unionGenTransObject + .addProperty(parseToValidParamName(propertyName)); + propBuilder.setReturnType(type); propBuilder.setReadOnly(false); if (!(type instanceof Enumeration)) { @@ -587,4 +565,35 @@ public final class TypeProviderImpl implements TypeProvider { } return null; } + + private GeneratedTransferObject bitsTypedefToTransferObject( + final BitsTypeDefinition bitsTypeDefinition, final String basePackageName, final String typedefName) { + + if (bitsTypeDefinition == null) { + throw new IllegalArgumentException("Bits TypeDefinition cannot be NULL!"); + } + if (basePackageName == null) { + throw new IllegalArgumentException("Base Package Name cannot be NULL!"); + } + if (typedefName == null) { + throw new IllegalArgumentException("Type Definition Local Name cannot be NULL!"); + } + + final String typeDefName = parseToClassName(typedefName); + final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeDefName); + + final List bitList = bitsTypeDefinition.getBits(); + GeneratedPropertyBuilder genPropertyBuilder; + for (final Bit bit : bitList) { + String name = bit.getName(); + genPropertyBuilder = genTOBuilder.addProperty(parseToValidParamName(name)); + genPropertyBuilder.setReadOnly(false); + genPropertyBuilder.setReturnType(BaseYangTypes.BOOLEAN_TYPE); + + genTOBuilder.addEqualsIdentity(genPropertyBuilder); + genTOBuilder.addHashIdentity(genPropertyBuilder); + genTOBuilder.addToStringProperty(genPropertyBuilder); + } + return genTOBuilder.toInstance(); + } } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenEnumResolvingTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenEnumResolvingTest.java index a95eb072ba..10ea9fae1f 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenEnumResolvingTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenEnumResolvingTest.java @@ -76,7 +76,7 @@ public class GenEnumResolvingTest { Enumeration linkUpDownTrapEnable = null; Enumeration operStatus = null; - final List enums = genInterface.getEnumDefintions(); + final List enums = genInterface.getEnumerations(); assertNotNull("Generated Type Interface cannot contain NULL reference" + " to Enumeration types!", enums); assertEquals("Generated Type Interface MUST contain 2 Enumeration " + diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java index b226252eae..cfa74a005f 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java @@ -16,7 +16,6 @@ import java.util.Set; import org.junit.Test; import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.controller.sal.binding.model.api.Enumeration; import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty; import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.controller.sal.binding.model.api.GeneratedType; diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneretedTypesBitsTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneretedTypesBitsTest.java new file mode 100644 index 0000000000..646efd1a78 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneretedTypesBitsTest.java @@ -0,0 +1,159 @@ +package org.opendaylight.controller.sal.binding.generator.impl; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.junit.Test; +import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator; +import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty; +import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject; +import org.opendaylight.controller.sal.binding.model.api.GeneratedType; +import org.opendaylight.controller.sal.binding.model.api.MethodSignature; +import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Parameter; +import org.opendaylight.controller.sal.binding.model.api.Type; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.SchemaContext; +import org.opendaylight.controller.yang.model.parser.api.YangModelParser; +import org.opendaylight.controller.yang.parser.impl.YangParserImpl; + +public class GeneretedTypesBitsTest { + + private SchemaContext resolveSchemaContextFromFiles( + final String... yangFiles) { + final YangModelParser parser = new YangParserImpl(); + + final List inputFiles = new ArrayList(); + for (int i = 0; i < yangFiles.length; ++i) { + inputFiles.add(new File(yangFiles[i])); + } + + final Set modules = parser.parseYangModels(inputFiles); + return parser.resolveSchemaContext(modules); + } + + @Test + public void testGeneretedTypesBitsTest() { + final String yangTypesPath = getClass().getResource( + "/simple-bits-demo.yang").getPath(); + + final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath); + assertTrue(context != null); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + assertTrue(genTypes != null); + + List methodSignaturesList = null; + + boolean leafParentFound = false; + + boolean byteTypeFound = false; + int classPropertiesNumb = 0; + int toStringPropertiesNum = 0; + int equalPropertiesNum = 0; + int hashPropertiesNum = 0; + + String nameReturnParamType = ""; + String nameMethodeParamType = ""; + boolean getByteLeafMethodFound = false; + boolean setByteLeafMethodFound = false; + int setByteLeafMethodParamNum = 0; + + for (final Type type : genTypes) { + if (type instanceof GeneratedTransferObject) { // searching for + // ByteType + final GeneratedTransferObject genTO = (GeneratedTransferObject) type; + if (genTO.getName().equals("ByteType")) { + byteTypeFound = true; + List genProperties = genTO + .getProperties(); + classPropertiesNumb = genProperties.size(); + + genProperties = null; + genProperties = genTO.getToStringIdentifiers(); + toStringPropertiesNum = genProperties.size(); + + genProperties = null; + genProperties = genTO.getEqualsIdentifiers(); + equalPropertiesNum = genProperties.size(); + + genProperties = null; + genProperties = genTO.getHashCodeIdentifiers(); + hashPropertiesNum = genProperties.size(); + + } + } else if (type instanceof GeneratedType) { // searching for + // interface + // LeafParameterContainer + final GeneratedType genType = (GeneratedType) type; + if (genType.getName().compareTo("LeafParentContainer") == 0) { + leafParentFound = true; + // check of methods + methodSignaturesList = genType.getMethodDefinitions(); + if (methodSignaturesList != null) { + for (MethodSignature methodSignature : methodSignaturesList) { // loop + // through + // all + // methods + if (methodSignature.getName().compareTo( + "getByteLeaf") == 0) { + getByteLeafMethodFound = true; + + nameReturnParamType = methodSignature + .getReturnType().getName(); + } else if (methodSignature.getName().compareTo( + "setByteLeaf") == 0) { + setByteLeafMethodFound = true; + + List parameters = methodSignature + .getParameters(); + setByteLeafMethodParamNum = parameters.size(); + for (Parameter parameter : parameters) { + nameMethodeParamType = parameter.getType() + .getName(); + } + + } + + } + } + } + } + + } + + assertTrue("type >ByteType< wasn't in YANG file", byteTypeFound == true); + + assertTrue("Incorrect number of bit properties in class", + classPropertiesNumb == 8); + + assertTrue("Incorrect number of properties in toString method", + toStringPropertiesNum == 8); + assertTrue("Incorrect number of properties in equals method", + equalPropertiesNum == 8); + assertTrue("Incorrect number of properties in hash method", + hashPropertiesNum == 8); + assertTrue("LeafParameterContainer container wasn't found", + leafParentFound == true); + + assertTrue("No methods were generated", methodSignaturesList != null); + + assertTrue("Method getByteLeaf wasn't generated.", + getByteLeafMethodFound == true); + assertTrue("Wrong returning parameter type of method getByteLeaf", + nameReturnParamType.compareTo("ByteType") == 0); + + assertTrue("Method setByteLeaf wasn't generated.", + setByteLeafMethodFound == true); + assertTrue("Incorrect number of input parameters for setByteLeaf", + setByteLeafMethodParamNum == 1); + assertTrue("Wrong input parameter type", + nameMethodeParamType.compareTo("ByteType") == 0); + + } + +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/simple-bits-demo.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/simple-bits-demo.yang new file mode 100644 index 0000000000..d7e69d1c4e --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/simple-bits-demo.yang @@ -0,0 +1,54 @@ +module simple-bits-demo { + + namespace "urn:simple:bits:demo"; + prefix "sbd"; + + organization "OPEN DAYLIGHT"; + contact "http://www.opendaylight.org/"; + + revision 2013-06-11 { + + } + + typedef byte-type { + type bits { + bit first-bit { + position 10; + } + bit second-bit { + position 20; + } + bit third-bit { + position 30; + } + bit forth-bit { + position 40; + } + bit fifth-bit { + position 50; + } + bit sixth-bit { + position 60; + } + bit seventh-bit { + position 70; + } + bit eight-bit { + position 80; + } + + } + + typedef jo { + type uint32; + } + + + container leaf-parent-container { + leaf byte-leaf { + type byte-type; + } + + } + +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/AbstractBaseType.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/AbstractBaseType.java index a9d1cf5227..a67e4163e9 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/AbstractBaseType.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/AbstractBaseType.java @@ -24,6 +24,15 @@ public class AbstractBaseType implements Type { return name; } + @Override + public String getFullyQualifiedName() { + if (packageName.isEmpty()) { + return name; + } else { + return packageName + "." + name; + } + } + protected AbstractBaseType(String pkName, String name) { this.packageName = pkName; this.name = name; @@ -68,5 +77,4 @@ public class AbstractBaseType implements Type { } return "Type (" + packageName + "." + name + ")"; } - } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/ReferencedTypeImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/ReferencedTypeImpl.java index 8f265c4ec3..bffa013f84 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/ReferencedTypeImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/ReferencedTypeImpl.java @@ -7,82 +7,19 @@ */ package org.opendaylight.controller.binding.generator.util; -import org.opendaylight.controller.sal.binding.model.api.Type; +public final class ReferencedTypeImpl extends AbstractBaseType { - -public final class ReferencedTypeImpl implements Type { - - private final String packageName; - private final String name; - public ReferencedTypeImpl(String packageName, String name) { - super(); - this.packageName = packageName; - this.name = name; - } - - /* (non-Javadoc) - * @see org.opendaylight.controller.sal.binding.model.api.Type#getPackageName() - */ - @Override - public String getPackageName() { - return packageName; - } - - /* (non-Javadoc) - * @see org.opendaylight.controller.sal.binding.model.api.Type#getName() - */ - @Override - public String getName() { - return name; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result - + ((packageName == null) ? 0 : packageName.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ReferencedTypeImpl other = (ReferencedTypeImpl) obj; - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (packageName == null) { - if (other.packageName != null) { - return false; - } - } else if (!packageName.equals(other.packageName)) { - return false; - } - return true; + super(packageName, name); } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ReferencedTypeImpl [packageName="); - builder.append(packageName); + builder.append(getPackageName()); builder.append(", name="); - builder.append(name); + builder.append(getName()); builder.append("]"); return builder.toString(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractGeneratedType.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractGeneratedType.java new file mode 100644 index 0000000000..5609f73064 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractGeneratedType.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; + + +import org.opendaylight.controller.binding.generator.util.AbstractBaseType; +import org.opendaylight.controller.sal.binding.model.api.*; +import org.opendaylight.controller.sal.binding.model.api.type.builder.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +abstract class AbstractGeneratedType extends AbstractBaseType implements GeneratedType { + + private final Type parent; + private final String comment; + private final List annotations; + private final List implementsTypes; + private final List enumerations; + private final List constants; + private final List methodSignatures; + private final List enclosedTypes; + private final boolean isAbstract; + + public AbstractGeneratedType(final Type parent, final String packageName, + final String name, final String comment, + final List annotationBuilders, + final boolean isAbstract, + final List implementsTypes, + final List enclosedGenTypeBuilders, + final List enclosedGenTOBuilders, + final List enumBuilders, + final List constants, + final List methodBuilders) { + super(packageName, name); + this.parent = parent; + this.comment = comment; + this.annotations = toUnmodifiableAnnotations(annotationBuilders); + this.implementsTypes = Collections.unmodifiableList(implementsTypes); + this.constants = toUnmodifiableConstants(constants); + this.enumerations = toUnmodifiableEnumerations(enumBuilders); + this.methodSignatures = toUnmodifiableMethods(methodBuilders); + this.enclosedTypes = toUnmodifiableEnclosedTypes(enclosedGenTypeBuilders, enclosedGenTOBuilders); + this.isAbstract = isAbstract; + } + + private List toUnmodifiableEnclosedTypes(final List enclosedGenTypeBuilders, + final List enclosedGenTOBuilders) { + final List enclosedTypes = new ArrayList<>(); + for (final GeneratedTypeBuilder builder : enclosedGenTypeBuilders) { + if (builder != null) { + enclosedTypes.add(builder.toInstance()); + } + } + + for (final GeneratedTOBuilder builder : enclosedGenTOBuilders) { + if (builder != null) { + enclosedTypes.add(builder.toInstance()); + } + } + return enclosedTypes; + } + + protected List toUnmodifiableAnnotations( + final List annotationBuilders) { + final List annotations = new ArrayList<>(); + for (final AnnotationTypeBuilder builder : annotationBuilders) { + annotations.add(builder.toInstance()); + } + return Collections.unmodifiableList(annotations); + } + + protected List toUnmodifiableMethods( + List methodBuilders) { + final List methods = new ArrayList<>(); + for (final MethodSignatureBuilder methodBuilder : methodBuilders) { + methods.add(methodBuilder.toInstance(this)); + } + return Collections.unmodifiableList(methods); + } + + protected List toUnmodifiableEnumerations( + List enumBuilders) { + final List enums = new ArrayList<>(); + for (final EnumBuilder enumBuilder : enumBuilders) { + enums.add(enumBuilder.toInstance(this)); + } + return Collections.unmodifiableList(enums); + } + + protected List toUnmodifiableConstants( + List constants) { + for (final Constant constant : constants) { + constants.add(new ConstantImpl(this, constant.getType(), + constant.getName(), constant.getValue())); + } + return Collections.unmodifiableList(constants); + } + + @Override + public Type getParentType() { + return parent; + } + + @Override + public String getComment() { + return comment; + } + + @Override + public List getAnnotations() { + return annotations; + } + + @Override + public boolean isAbstract() { + return isAbstract; + } + + @Override + public List getImplements() { + return implementsTypes; + } + + @Override + public List getEnclosedTypes() { + return enclosedTypes; + } + + @Override + public List getEnumerations() { + return enumerations; + } + + @Override + public List getConstantDefinitions() { + return constants; + } + + @Override + public List getMethodDefinitions() { + return methodSignatures; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedType [packageName="); + builder.append(getPackageName()); + builder.append(", name="); + builder.append(getName()); + if (parent != null) { + builder.append(", parent="); + builder.append(parent.getFullyQualifiedName()); + } else { + builder.append(", parent=null"); + } + builder.append(", comment="); + builder.append(comment); + builder.append(", annotations="); + builder.append(annotations); + builder.append(", enclosedTypes="); + builder.append(enclosedTypes); + builder.append(", enumerations="); + builder.append(enumerations); + builder.append(", constants="); + builder.append(constants); + builder.append(", methodSignatures="); + builder.append(methodSignatures); + builder.append("]"); + return builder.toString(); + } +} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java new file mode 100644 index 0000000000..02c0060dff --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; + +import org.opendaylight.controller.sal.binding.model.api.AccessModifier; +import org.opendaylight.controller.sal.binding.model.api.Constant; +import org.opendaylight.controller.sal.binding.model.api.Type; +import org.opendaylight.controller.sal.binding.model.api.type.builder.*; + +import java.util.ArrayList; +import java.util.List; + +abstract class AbstractGeneratedTypeBuilder implements GeneratedTypeBuilder { + + private final String packageName; + private String comment = ""; + private final String name; + + private final List annotationBuilders = new ArrayList<>(); + private final List implementsTypes = new ArrayList<>(); + private final List enumDefinitions = new ArrayList<>(); + private final List constants = new ArrayList<>(); + private final List methodDefinitions = new ArrayList<>(); + private final List enclosedTypes = new ArrayList<>(); + private final List enclosingTransferObjects = new ArrayList<>(); + private boolean isAbstract; + + public AbstractGeneratedTypeBuilder(final String packageName, final String name) { + if (packageName == null) { + throw new IllegalArgumentException("Package Name for Generated Type cannot be null!"); + } + if (name == null) { + throw new IllegalArgumentException("Name of Generated Type cannot be null!"); + } + this.packageName = packageName; + this.name = name; + } + + @Override + public String getPackageName() { + return packageName; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getFullyQualifiedName() { + return packageName + "." + name; + } + + + protected String getComment() { + return comment; + } + + protected List getAnnotations() { + return annotationBuilders; + } + + protected boolean isAbstract() { + return isAbstract; + } + + protected List getImplementsTypes() { + return implementsTypes; + } + + protected List getEnumerations() { + return enumDefinitions; + } + + protected List getConstants() { + return constants; + } + + protected List getMethodDefinitions() { + return methodDefinitions; + } + + protected List getEnclosedTypes() { + return enclosedTypes; + } + + protected List getEnclosedTransferObjects() { + return enclosingTransferObjects; + } + + @Override + public GeneratedTypeBuilder addEnclosingType(String name) { + if (name == null) { + throw new IllegalArgumentException("Name for Enclosing Generated Type cannot be null!"); + } + GeneratedTypeBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name); + enclosedTypes.add(builder); + return builder; + } + + @Override + public GeneratedTOBuilder addEnclosingTransferObject(String name) { + if (name == null) { + throw new IllegalArgumentException("Name for Enclosing Generated Transfer Object cannot be null!"); + } + GeneratedTOBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name); + enclosingTransferObjects.add(builder); + return builder; + } + + @Override + public void addComment(String comment) { + this.comment = comment; + } + + @Override + public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) { + if (packageName == null) { + throw new IllegalArgumentException("Package Name for Annotation Type cannot be null!"); + } + if (name == null) { + throw new IllegalArgumentException("Name of Annotation Type cannot be null!"); + } + + final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name); + annotationBuilders.add(builder); + return builder; + } + + @Override + public void setAbstract(boolean isAbstract) { + this.isAbstract = isAbstract; + } + + @Override + public boolean addImplementsType(Type genType) { + if (genType == null) { + throw new IllegalArgumentException("Type cannot be null"); + } + return implementsTypes.add(genType); + } + + @Override + public Constant addConstant(Type type, String name, Object value) { + if (type == null) { + throw new IllegalArgumentException("Returning Type for Constant cannot be null!"); + } + if (name == null) { + throw new IllegalArgumentException("Name of constant cannot be null!"); + } + + final Constant constant = new ConstantImpl(this, type, name, value); + constants.add(constant); + return constant; + } + + @Override + public EnumBuilder addEnumeration(String name) { + if (name == null) { + throw new IllegalArgumentException("Name of enumeration cannot be null!"); + } + final EnumBuilder builder = new EnumerationBuilderImpl( + getFullyQualifiedName(), name); + enumDefinitions.add(builder); + return builder; + } + + @Override + public MethodSignatureBuilder addMethod(String name) { + if (name == null) { + throw new IllegalArgumentException("Name of method cannot be null!"); + } + final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(name); + builder.setAccessModifier(AccessModifier.PUBLIC); + builder.setAbstract(true); + methodDefinitions.add(builder); + return builder; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); + result = prime * result + + ((getPackageName() == null) ? 0 : getPackageName().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AbstractGeneratedTypeBuilder other = (AbstractGeneratedTypeBuilder) obj; + if (getName() == null) { + if (other.getName() != null) { + return false; + } + } else if (!getName().equals(other.getName())) { + return false; + } + if (getPackageName() == null) { + if (other.getPackageName() != null) { + return false; + } + } else if (!getPackageName().equals(other.getPackageName())) { + return false; + } + return true; + } +} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractTypeMember.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractTypeMember.java new file mode 100644 index 0000000000..5719d35f57 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractTypeMember.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; + + +import org.opendaylight.controller.sal.binding.model.api.AccessModifier; +import org.opendaylight.controller.sal.binding.model.api.AnnotationType; +import org.opendaylight.controller.sal.binding.model.api.Type; +import org.opendaylight.controller.sal.binding.model.api.TypeMember; + +import java.util.Collections; +import java.util.List; + +abstract class AbstractTypeMember implements TypeMember { + + private final String name; + private final String comment; + private final Type definingType; + private final Type returnType; + private final List annotations; + private final boolean isFinal; + private final AccessModifier accessModifier; + + public AbstractTypeMember(final Type definingType, final String name, final List annotations, + final String comment, final AccessModifier accessModifier, final Type returnType, + boolean isFinal) { + super(); + this.definingType = definingType; + this.name = name; + this.annotations = Collections.unmodifiableList(annotations); + this.comment = comment; + this.accessModifier = accessModifier; + this.returnType = returnType; + this.isFinal = isFinal; + } + + @Override + public List getAnnotations() { + return annotations; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getComment() { + return comment; + } + + @Override + public Type getDefiningType() { + return definingType; + } + + @Override + public AccessModifier getAccessModifier() { + return accessModifier; + } + + @Override + public Type getReturnType() { + return returnType; + } + + @Override + public boolean isFinal() { + return isFinal; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); + result = prime * result + + ((getReturnType() == null) ? 0 : getReturnType().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MethodSignatureImpl other = (MethodSignatureImpl) obj; + if (getName() == null) { + if (other.getName() != null) { + return false; + } + } else if (!getName().equals(other.getName())) { + return false; + } + if (getReturnType() == null) { + if (other.getReturnType() != null) { + return false; + } + } else if (!getReturnType().equals(other.getReturnType())) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MethodSignatureImpl [name="); + builder.append(getName()); + builder.append(", comment="); + builder.append(getComment()); + if (getDefiningType() != null) { + builder.append(", definingType="); + builder.append(getDefiningType().getPackageName()); + builder.append("."); + builder.append(getDefiningType().getName()); + } else { + builder.append(", definingType= null"); + } + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java new file mode 100644 index 0000000000..391c3afb7a --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; + +import org.opendaylight.controller.sal.binding.model.api.AccessModifier; +import org.opendaylight.controller.sal.binding.model.api.AnnotationType; +import org.opendaylight.controller.sal.binding.model.api.Type; +import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder; +import org.opendaylight.controller.sal.binding.model.api.type.builder.TypeMemberBuilder; + +import java.util.ArrayList; +import java.util.List; + +abstract class AbstractTypeMemberBuilder implements TypeMemberBuilder { + private final String name; + private Type returnType; + private final List annotationBuilders; + private String comment = ""; + private boolean isFinal; + private AccessModifier accessModifier; + + public AbstractTypeMemberBuilder(final String name) { + this.name = name; + this.annotationBuilders = new ArrayList<>(); + } + + @Override + public AnnotationTypeBuilder addAnnotation(String packageName, String name) { + if (packageName == null) { + throw new IllegalArgumentException("Annotation Type cannot have package name null!"); + } + if (name == null) { + throw new IllegalArgumentException("Annotation Type cannot have name as null!"); + } + final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl( + packageName, name); + annotationBuilders.add(builder); + return builder; + } + + protected Type getReturnType() { + return returnType; + } + + protected List getAnnotationBuilders() { + return annotationBuilders; + } + + protected String getComment() { + return comment; + } + + protected boolean isFinal() { + return isFinal; + } + + protected AccessModifier getAccessModifier() { + return accessModifier; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setReturnType(Type returnType) { + if (returnType == null) { + throw new IllegalArgumentException("Return Type of member cannot be null!"); + } + this.returnType = returnType; + } + + @Override + public void setAccessModifier(AccessModifier modifier) { + if (modifier == null) { + throw new IllegalArgumentException("Access Modifier for member type cannot be null!"); + } + this.accessModifier = modifier; + } + + @Override + public void setComment(String comment) { + if (comment == null) { + throw new IllegalArgumentException("Comment string cannot be null!"); + } + this.comment = comment; + } + + @Override + public void setFinal(boolean isFinal) { + this.isFinal = isFinal; + } + + protected List toAnnotationTypes() { + final List annotations = new ArrayList<>(); + for (final AnnotationTypeBuilder annotBuilder : getAnnotationBuilders()) { + if (annotBuilder != null) { + annotations.add(annotBuilder.toInstance()); + } + } + return annotations; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); + result = prime * result + + ((getReturnType() == null) ? 0 : getReturnType().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj; + if (getName() == null) { + if (other.getName() != null) { + return false; + } + } else if (!getName().equals(other.getName())) { + return false; + } + if (getReturnType() == null) { + if (other.getReturnType() != null) { + return false; + } + } else if (!getReturnType().equals(other.getReturnType())) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedPropertyImpl [name="); + builder.append(getName()); + builder.append(", annotations="); + builder.append(getAnnotationBuilders()); + builder.append(", comment="); + builder.append(getComment()); + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", isFinal="); + builder.append(isFinal()); + builder.append(", modifier="); + builder.append(getAccessModifier()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java index 6eaa769563..c125af556a 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; import java.util.ArrayList; @@ -18,9 +25,8 @@ final class AnnotationTypeBuilderImpl implements AnnotationTypeBuilder { super(); this.packageName = packageName; this.name = name; - - annotationBuilders = new ArrayList(); - parameters = new ArrayList(); + annotationBuilders = new ArrayList<>(); + parameters = new ArrayList<>(); } @Override @@ -33,6 +39,11 @@ final class AnnotationTypeBuilderImpl implements AnnotationTypeBuilder { return name; } + @Override + public String getFullyQualifiedName() { + return packageName + "." + name; + } + @Override public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) { if (packageName != null && name != null) { @@ -134,7 +145,7 @@ final class AnnotationTypeBuilderImpl implements AnnotationTypeBuilder { this.packageName = packageName; this.name = name; - this.annotations = new ArrayList(); + this.annotations = new ArrayList<>(); for (final AnnotationTypeBuilder builder : annotationBuilders) { annotations.add(builder.toInstance()); } @@ -142,7 +153,7 @@ final class AnnotationTypeBuilderImpl implements AnnotationTypeBuilder { this.annotations = Collections.unmodifiableList(annotations); this.parameters = Collections.unmodifiableList(parameters); - paramNames = new ArrayList(); + paramNames = new ArrayList<>(); for (final AnnotationType.Parameter parameter : parameters) { paramNames.add(parameter.getName()); } @@ -159,6 +170,11 @@ final class AnnotationTypeBuilderImpl implements AnnotationTypeBuilder { return name; } + @Override + public String getFullyQualifiedName() { + return packageName + "." + name; + } + @Override public List getAnnotations() { return annotations; diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/ConstantBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/ConstantBuilderImpl.java deleted file mode 100644 index 16e89e08ab..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/ConstantBuilderImpl.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; - -import org.opendaylight.controller.sal.binding.model.api.Constant; -import org.opendaylight.controller.sal.binding.model.api.Type; -import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder; - -final class ConstantBuilderImpl implements ConstantBuilder { - - private final Type type; - private final String name; - private Object value; - - public ConstantBuilderImpl(Type type, String name, Object value) { - super(); - this.type = type; - this.name = name; - this.value = value; - } - - public ConstantBuilderImpl(Type type, String name) { - super(); - this.type = type; - this.name = name; - } - - @Override - public void assignValue(Object value) { - this.value = value; - } - - @Override - public Constant toInstance(final Type definingType) { - return new ConstantImpl(definingType, type, name, value); - } - - private static final class ConstantImpl implements Constant { - - final Type definingType; - private final Type type; - private final String name; - private final Object value; - - public ConstantImpl(final Type definingType, final Type type, - final String name, final Object value) { - super(); - this.definingType = definingType; - this.type = type; - this.name = name; - this.value = value; - } - - @Override - public Type getDefiningType() { - return definingType; - } - - @Override - public Type getType() { - return type; - } - - @Override - public String getName() { - return name; - } - - @Override - public Object getValue() { - return value; - } - - @Override - public String toFormattedString() { - StringBuilder builder = new StringBuilder(); - builder.append(type); - builder.append(" "); - builder.append(name); - builder.append(" "); - builder.append(value); - return builder.toString(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ConstantImpl other = (ConstantImpl) obj; - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (type == null) { - if (other.type != null) { - return false; - } - } else if (!type.equals(other.type)) { - return false; - } - if (value == null) { - if (other.value != null) { - return false; - } - } else if (!value.equals(other.value)) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("Constant [type="); - builder.append(type); - builder.append(", name="); - builder.append(name); - builder.append(", value="); - builder.append(value); - if (definingType != null) { - builder.append(", definingType="); - builder.append(definingType.getPackageName()); - builder.append("."); - builder.append(definingType.getName()); - } else { - builder.append(", definingType= null"); - } - builder.append("]"); - return builder.toString(); - } - } -} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/ConstantImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/ConstantImpl.java new file mode 100644 index 0000000000..5d7ba4ee4c --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/ConstantImpl.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; + +import org.opendaylight.controller.sal.binding.model.api.Constant; +import org.opendaylight.controller.sal.binding.model.api.Type; + +final class ConstantImpl implements Constant { + + final Type definingType; + private final Type type; + private final String name; + private final Object value; + + public ConstantImpl(final Type definingType, final Type type, + final String name, final Object value) { + super(); + this.definingType = definingType; + this.type = type; + this.name = name; + this.value = value; + } + + @Override + public Type getDefiningType() { + return definingType; + } + + @Override + public Type getType() { + return type; + } + + @Override + public String getName() { + return name; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public String toFormattedString() { + StringBuilder builder = new StringBuilder(); + builder.append(type); + builder.append(" "); + builder.append(name); + builder.append(" "); + builder.append(value); + return builder.toString(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ConstantImpl other = (ConstantImpl) obj; + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Constant [type="); + builder.append(type); + builder.append(", name="); + builder.append(name); + builder.append(", value="); + builder.append(value); + if (definingType != null) { + builder.append(", definingType="); + builder.append(definingType.getPackageName()); + builder.append("."); + builder.append(definingType.getName()); + } else { + builder.append(", definingType= null"); + } + builder.append("]"); + return builder.toString(); + } +} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java index 62945ea451..8bf5b5d4cb 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java @@ -27,7 +27,7 @@ public final class EnumerationBuilderImpl implements EnumBuilder { super(); this.packageName = packageName; this.name = name; - values = new ArrayList(); + values = new ArrayList<>(); } @Override @@ -39,7 +39,12 @@ public final class EnumerationBuilderImpl implements EnumBuilder { public String getName() { return name; } - + + @Override + public String getFullyQualifiedName() { + return packageName + "." + name; + } + @Override public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) { if (packageName != null && name != null) { @@ -220,7 +225,7 @@ public final class EnumerationBuilderImpl implements EnumBuilder { private final String packageName; private final String name; private final List values; - private List annotations = new ArrayList(); + private List annotations = new ArrayList<>(); public EnumerationImpl(final Type definingType, final List annotationBuilders, @@ -252,6 +257,11 @@ public final class EnumerationBuilderImpl implements EnumBuilder { return name; } + @Override + public String getFullyQualifiedName() { + return packageName + "." + name; + } + @Override public List getValues() { return values; diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java new file mode 100644 index 0000000000..9b61163fc0 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; + +import org.opendaylight.controller.sal.binding.model.api.AnnotationType; +import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty; +import org.opendaylight.controller.sal.binding.model.api.Type; +import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder; + +import java.util.List; + +final class GeneratedPropertyBuilderImpl extends AbstractTypeMemberBuilder implements GeneratedPropertyBuilder { + + private boolean isReadOnly; + + public GeneratedPropertyBuilderImpl(String name) { + super(name); + } + + @Override + public void setReadOnly(boolean isReadOnly) { + this.isReadOnly = isReadOnly; + } + + @Override + public GeneratedProperty toInstance(Type definingType) { + final List annotations = toAnnotationTypes(); + return new GeneratedPropertyImpl(definingType, getName(), annotations, getComment(), getAccessModifier(), + getReturnType(), isFinal(), isReadOnly); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedPropertyImpl [name="); + builder.append(getName()); + builder.append(", annotations="); + builder.append(getAnnotationBuilders()); + builder.append(", comment="); + builder.append(getComment()); + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", isFinal="); + builder.append(isFinal()); + builder.append(", isReadOnly="); + builder.append(isReadOnly); + builder.append(", modifier="); + builder.append(getAccessModifier()); + builder.append("]"); + return builder.toString(); + } +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java new file mode 100644 index 0000000000..6d11bfdc81 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; + +import org.opendaylight.controller.sal.binding.model.api.AccessModifier; +import org.opendaylight.controller.sal.binding.model.api.AnnotationType; +import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty; +import org.opendaylight.controller.sal.binding.model.api.Type; + +import java.util.List; + +final class GeneratedPropertyImpl extends AbstractTypeMember implements GeneratedProperty { + + private boolean isReadOnly; + + public GeneratedPropertyImpl(Type definingType, String name, List annotations, String comment, + AccessModifier accessModifier, Type returnType, boolean isFinal, boolean isReadOnly) { + super(definingType, name, annotations, comment, accessModifier, returnType, isFinal); + this.isReadOnly = isReadOnly; + } + + @Override + public boolean isReadOnly() { + return isReadOnly; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedPropertyImpl [name="); + builder.append(getName()); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append(", comment="); + builder.append(getComment()); + if (getDefiningType() != null) { + builder.append(", parent="); + builder.append(getDefiningType().getPackageName()); + builder.append("."); + builder.append(getDefiningType().getName()); + } else { + builder.append(", parent=null"); + } + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", isFinal="); + builder.append(isFinal()); + builder.append(", isReadOnly="); + builder.append(isReadOnly); + builder.append(", modifier="); + builder.append(getAccessModifier()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java index f1683fdc64..de3e19223f 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java @@ -7,129 +7,60 @@ */ package org.opendaylight.controller.binding.generator.util.generated.type.builder; +import org.opendaylight.controller.sal.binding.model.api.*; +import org.opendaylight.controller.sal.binding.model.api.type.builder.*; + import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.opendaylight.controller.sal.binding.model.api.AccessModifier; -import org.opendaylight.controller.sal.binding.model.api.AnnotationType; -import org.opendaylight.controller.sal.binding.model.api.Constant; -import org.opendaylight.controller.sal.binding.model.api.Enumeration; -import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferIdentityObject; -import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.controller.sal.binding.model.api.MethodSignature; -import org.opendaylight.controller.sal.binding.model.api.Type; -import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder; -import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder; -import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder; -import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder; -import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder; -import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder; - -public class GeneratedTOBuilderImpl implements GeneratedTOBuilder { - private String packageName; - private final String name; - private String comment = ""; +public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder implements GeneratedTOBuilder { private GeneratedTransferObject extendsType; - private final List implementsTypes = new ArrayList(); - private final List enumerations = new ArrayList(); - private final List properties = new ArrayList(); - private final List equalsProperties = new ArrayList(); - private final List hashProperties = new ArrayList(); - private final List toStringProperties = new ArrayList(); - - private final List constantDefintions = new ArrayList(); - private final List methodDefinitions = new ArrayList(); - private final List annotationBuilders = new ArrayList(); + private final List properties = new ArrayList<>(); + private final List equalsProperties = new ArrayList<>(); + private final List hashProperties = new ArrayList<>(); + private final List toStringProperties = new ArrayList<>(); public GeneratedTOBuilderImpl(String packageName, String name) { - super(); - this.packageName = packageName; - this.name = name; - } - - @Override - public String getPackageName() { - return packageName; - } - - @Override - public String getName() { - return name; - } - - @Override - public Type getParentType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void addComment(final String comment) { - this.comment = comment; - } - - @Override - public AnnotationTypeBuilder addAnnotation(String packageName, String name) { - if (packageName != null && name != null) { - final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl( - packageName, name); - if (annotationBuilders.add(builder)) { - return builder; - } - } - return null; - } - - @Override - public boolean addImplementsType(final Type genType) { - if (genType != null) { - return implementsTypes.add(genType); - } - return false; + super(packageName, name); + setAbstract(false); } @Override - public boolean addExtendsType(final GeneratedTransferObject genTransObj) { - if (genTransObj != null) { - extendsType = genTransObj; - return true; + public void setExtendsType(final GeneratedTransferObject genTransObj) { + if (genTransObj == null) { + throw new IllegalArgumentException("Generated Transfer Object cannot be null!"); } - return false; - } - - @Override - public EnumBuilder addEnumeration(String name) { - final String innerPackageName = packageName + "." + this.name; - final EnumBuilder builder = new EnumerationBuilderImpl(innerPackageName, - name); - enumerations.add(builder); - return builder; + extendsType = genTransObj; } @Override - public ConstantBuilder addConstant(Type type, String name, Object value) { - final ConstantBuilder builder = new ConstantBuilderImpl(type, name, - value); - constantDefintions.add(builder); + public GeneratedPropertyBuilder addProperty(String name) { + final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(name); + builder.setAccessModifier(AccessModifier.PUBLIC); + properties.add(builder); return builder; } + /** + * Add new Method Signature definition for Generated Type Builder and + * returns Method Signature Builder for specifying all Method parameters. + *
+ * Name of Method cannot be null, + * if it is null the method SHOULD throw {@link IllegalArgumentException} + *
+ * By Default the MethodSignatureBuilder SHOULD be pre-set as + * {@link MethodSignatureBuilder#setAbstract(false)}, {@link MethodSignatureBuilder#setFinal(false)} and + * {@link MethodSignatureBuilder#setAccessModifier(PUBLIC)} + * + * @param name Name of Method + * @return new instance of Method Signature Builder. + */ @Override public MethodSignatureBuilder addMethod(String name) { - final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl( - this, name); - methodDefinitions.add(builder); - return builder; - } - - @Override - public GeneratedPropertyBuilder addProperty(String name) { - final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl( - name); - properties.add(builder); + final MethodSignatureBuilder builder = super.addMethod(name); + builder.setAbstract(false); return builder; } @@ -150,381 +81,83 @@ public class GeneratedTOBuilderImpl implements GeneratedTOBuilder { @Override public GeneratedTransferObject toInstance() { - return new GeneratedTransferObjectImpl(packageName, name, comment, - annotationBuilders, extendsType, implementsTypes, - constantDefintions, enumerations, methodDefinitions, - properties, equalsProperties, hashProperties, - toStringProperties); - } - - @Override - public GeneratedTransferObject toIdentityInstance() { - return new GeneratedTransferIdentityObjectImpl(packageName, name, comment, - annotationBuilders, extendsType, implementsTypes, - constantDefintions, enumerations, methodDefinitions, - properties, equalsProperties, hashProperties, - toStringProperties); - } - - private static final class GeneratedPropertyBuilderImpl implements - GeneratedPropertyBuilder { - - private final String name; - private final List annotationBuilders = new ArrayList(); - private Type returnType; - private final List parameters; - private String comment = ""; - private AccessModifier accessModifier; - private boolean isFinal; - private boolean isReadOnly; - - public GeneratedPropertyBuilderImpl(final String name) { - super(); - this.name = name; - parameters = new ArrayList(); - isFinal = true; - this.isReadOnly = true; - accessModifier = AccessModifier.PUBLIC; - } - - public String getName() { - return name; - } - - @Override - public AnnotationTypeBuilder addAnnotation(String packageName, - String name) { - if (packageName != null && name != null) { - final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl( - packageName, name); - if (annotationBuilders.add(builder)) { - return builder; - } - } - return null; - } - - @Override - public boolean addReturnType(Type returnType) { - if (returnType != null) { - this.returnType = returnType; - this.parameters.add(new MethodParameterImpl(name, returnType)); - return true; - } - return false; - } - - @Override - public void accessorModifier(final AccessModifier modifier) { - accessModifier = modifier; - } - - @Override - public void addComment(String comment) { - if (comment != null) { - this.comment = comment; - } - } - - @Override - public void setFinal(boolean isFinal) { - this.isFinal = isFinal; - } - - @Override - public void setReadOnly(boolean isReadOnly) { - this.isReadOnly = isReadOnly; - } - - @Override - public GeneratedProperty toInstance(final Type definingType) { - return new GeneratedPropertyImpl(name, comment, annotationBuilders, - definingType, returnType, isFinal, isReadOnly, parameters, - accessModifier); - } - } - - private static final class GeneratedPropertyImpl implements - GeneratedProperty { - - private final String name; - private List annotations; - private final String comment; - private final Type parent; - private final Type returnType; - private final boolean isFinal; - private final boolean isReadOnly; - private final List parameters; - private final AccessModifier modifier; - - public GeneratedPropertyImpl(final String name, final String comment, - final List annotationBuilders, - final Type parent, final Type returnType, - final boolean isFinal, final boolean isReadOnly, - final List parameters, final AccessModifier modifier) { - super(); - this.name = name; - this.annotations = new ArrayList(); - for (final AnnotationTypeBuilder builder : annotationBuilders) { - this.annotations.add(builder.toInstance()); - } - this.annotations = Collections.unmodifiableList(this.annotations); - this.comment = comment; - this.parent = parent; - this.returnType = returnType; - this.isFinal = isFinal; - this.isReadOnly = isReadOnly; - this.parameters = Collections.unmodifiableList(parameters); - this.modifier = modifier; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getComment() { - return comment; - } - - @Override - public Type getDefiningType() { - return parent; - } - - @Override - public List getAnnotations() { - return annotations; - } - - @Override - public Type getReturnType() { - return returnType; - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public AccessModifier getAccessModifier() { - return modifier; - } - - @Override - public boolean isReadOnly() { - return isReadOnly; - } - - @Override - public boolean isFinal() { - return isFinal; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result - + ((parameters == null) ? 0 : parameters.hashCode()); - result = prime * result - + ((returnType == null) ? 0 : returnType.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - GeneratedPropertyImpl other = (GeneratedPropertyImpl) obj; - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (parameters == null) { - if (other.parameters != null) { - return false; - } - } else if (!parameters.equals(other.parameters)) { - return false; - } - if (returnType == null) { - if (other.returnType != null) { - return false; - } - } else if (!returnType.getPackageName().equals( - other.returnType.getPackageName())) { - return false; - } else if (!returnType.getName().equals(other.returnType.getName())) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("GeneratedPropertyImpl [name="); - builder.append(name); - builder.append(", annotations="); - builder.append(annotations); - builder.append(", comment="); - builder.append(comment); - if (parent != null) { - builder.append(", parent="); - builder.append(parent.getPackageName()); - builder.append("."); - builder.append(parent.getName()); - } else { - builder.append(", parent=null"); - } - builder.append(", returnType="); - builder.append(returnType); - builder.append(", isFinal="); - builder.append(isFinal); - builder.append(", isReadOnly="); - builder.append(isReadOnly); - builder.append(", parameters="); - builder.append(parameters); - builder.append(", modifier="); - builder.append(modifier); - builder.append("]"); - return builder.toString(); - } - } - - private static class GeneratedTransferObjectImpl implements + return new GeneratedTransferObjectImpl(null, getPackageName(), getName(), getComment(), + getAnnotations(), isAbstract(), extendsType, getImplementsTypes(), getEnclosedTypes(), + getEnclosedTransferObjects(), getConstants(), getEnumerations(), getMethodDefinitions(), properties, + equalsProperties, hashProperties, toStringProperties); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedTransferObject [packageName="); + builder.append(getPackageName()); + builder.append(", name="); + builder.append(getName()); + builder.append(", comment="); + builder.append(getComment()); + builder.append(", constants="); + builder.append(getConstants()); + builder.append(", enumerations="); + builder.append(getEnumerations()); + builder.append(", properties="); + builder.append(properties); + builder.append(", equalsProperties="); + builder.append(equalsProperties); + builder.append(", hashCodeProperties="); + builder.append(hashProperties); + builder.append(", stringProperties="); + builder.append(toStringProperties); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append(", methods="); + builder.append(getMethodDefinitions()); + builder.append("]"); + return builder.toString(); + } + + private static final class GeneratedTransferObjectImpl extends AbstractGeneratedType implements GeneratedTransferObject { - private final String packageName; - private final String name; - private final String comment; - private final List constants; - private final List enumerations; private final List properties; private final List equalsProperties; private final List hashCodeProperties; private final List stringProperties; - private final List annotations; - private final List methods; private final GeneratedTransferObject extendsType; - private final List implementsTypes; - public GeneratedTransferObjectImpl(final String packageName, - final String name, final String comment, - final List annotationBuilders, - final GeneratedTransferObject extendsType, - final List implementsTypes, - final List constantBuilders, - final List enumBuilders, - final List methodBuilders, - final List propBuilers, - final List equalsBuilers, - final List hashCodeBuilers, - final List stringBuilers) { - super(); - this.packageName = packageName; - this.name = name; - this.comment = comment; - this.annotations = toUnmodifiableAnnotations(annotationBuilders); + GeneratedTransferObjectImpl(final Type parent, + final String packageName, + final String name, final String comment, + final List annotationBuilders, + final boolean isAbstract, + final GeneratedTransferObject extendsType, + final List implementsTypes, + final List enclosedGenTypeBuilders, + final List enclosedGenTOBuilders, + final List constants, + final List enumBuilders, + final List methodBuilders, + final List propBuilders, + final List equalsBuilders, + final List hashCodeBuilders, + final List stringBuilders) { + super(parent, packageName, name, comment, annotationBuilders, isAbstract, implementsTypes, + enclosedGenTypeBuilders, + enclosedGenTOBuilders, enumBuilders, constants, methodBuilders); this.extendsType = extendsType; - this.implementsTypes = Collections - .unmodifiableList(implementsTypes); - this.constants = toUnmodifiableConstant(constantBuilders); - this.enumerations = toUnmodifiableEnumerations(enumBuilders); - this.properties = toUnmodifiableProperties(propBuilers); - this.methods = toUnmodifiableMethods(methodBuilders); - this.equalsProperties = toUnmodifiableProperties(equalsBuilers); - this.hashCodeProperties = toUnmodifiableProperties(hashCodeBuilers); - this.stringProperties = toUnmodifiableProperties(stringBuilers); - } - - private List toUnmodifiableAnnotations( - final List annotationBuilders) { - final List annotations = new ArrayList(); - for (final AnnotationTypeBuilder builder : annotationBuilders) { - annotations.add(builder.toInstance()); - } - return Collections.unmodifiableList(annotations); - } - - private List toUnmodifiableEnumerations( - final List enumBuilders) { - final List enumerations = new ArrayList(); - for (final EnumBuilder builder : enumBuilders) { - enumerations.add(builder.toInstance(this)); - } - return Collections.unmodifiableList(enumerations); - } - - private List toUnmodifiableConstant( - final List constBuilders) { - final List constants = new ArrayList(); - for (final ConstantBuilder builder : constBuilders) { - constants.add(builder.toInstance(this)); - } - return Collections.unmodifiableList(constants); - } - - private List toUnmodifiableMethods( - final List methodBuilders) { - final List methods = new ArrayList(); - for (final MethodSignatureBuilder builder : methodBuilders) { - methods.add(builder.toInstance(this)); - } - return Collections.unmodifiableList(methods); + this.properties = toUnmodifiableProperties(propBuilders); + this.equalsProperties = toUnmodifiableProperties(equalsBuilders); + this.hashCodeProperties = toUnmodifiableProperties(hashCodeBuilders); + this.stringProperties = toUnmodifiableProperties(stringBuilders); } private List toUnmodifiableProperties( final List propBuilders) { - final List constants = new ArrayList(); + final List properties = new ArrayList<>(); for (final GeneratedPropertyBuilder builder : propBuilders) { - constants.add(builder.toInstance(this)); + properties.add(builder.toInstance(this)); } - return Collections.unmodifiableList(constants); - } - - @Override - public String getPackageName() { - return packageName; - } - - @Override - public String getName() { - return name; - } - - @Override - public Type getParentType() { - return null; - } - - @Override - public String getComment() { - return comment; - } - - @Override - public List getAnnotations() { - return annotations; - } - - @Override - public List getImplements() { - return implementsTypes; + return Collections.unmodifiableList(properties); } @Override @@ -532,21 +165,6 @@ public class GeneratedTOBuilderImpl implements GeneratedTOBuilder { return extendsType; } - @Override - public List getEnumDefintions() { - return enumerations; - } - - @Override - public List getConstantDefinitions() { - return constants; - } - - @Override - public List getMethodDefinitions() { - return methods; - } - @Override public List getProperties() { return properties; @@ -567,58 +185,27 @@ public class GeneratedTOBuilderImpl implements GeneratedTOBuilder { return stringProperties; } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result - + ((packageName == null) ? 0 : packageName.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - GeneratedTransferObjectImpl other = (GeneratedTransferObjectImpl) obj; - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (packageName == null) { - if (other.packageName != null) { - return false; - } - } else if (!packageName.equals(other.packageName)) { - return false; - } - return true; - } - @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("GeneratedTransferObject [packageName="); - builder.append(packageName); + builder.append(getPackageName()); builder.append(", name="); - builder.append(name); + builder.append(getName()); builder.append(", comment="); - builder.append(comment); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append(getComment()); + builder.append(", extends="); + builder.append(getExtends()); + builder.append(", implements="); + builder.append(getImplements()); + builder.append(", enclosedTypes="); + builder.append(getEnclosedTypes()); builder.append(", constants="); - builder.append(constants); + builder.append(getConstantDefinitions()); builder.append(", enumerations="); - builder.append(enumerations); + builder.append(getEnumerations()); builder.append(", properties="); builder.append(properties); builder.append(", equalsProperties="); @@ -627,34 +214,10 @@ public class GeneratedTOBuilderImpl implements GeneratedTOBuilder { builder.append(hashCodeProperties); builder.append(", stringProperties="); builder.append(stringProperties); - builder.append(", annotations="); - builder.append(annotations); builder.append(", methods="); - builder.append(methods); + builder.append(getMethodDefinitions()); builder.append("]"); return builder.toString(); } } - - private static final class GeneratedTransferIdentityObjectImpl extends - GeneratedTransferObjectImpl implements - GeneratedTransferIdentityObject { - public GeneratedTransferIdentityObjectImpl(final String packageName, - final String name, final String comment, - final List annotationBuilders, - final GeneratedTransferObject extendsType, - final List implementsTypes, - final List constantBuilders, - final List enumBuilders, - final List methodBuilders, - final List propBuilers, - final List equalsBuilers, - final List hashCodeBuilers, - final List stringBuilers) { - super(packageName, name, comment, annotationBuilders, extendsType, - implementsTypes, constantBuilders, enumBuilders, - methodBuilders, propBuilers, equalsBuilers, - hashCodeBuilers, stringBuilers); - } - } } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java index 3a3ded39ba..a3ffbda4f5 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java @@ -7,321 +7,64 @@ */ package org.opendaylight.controller.binding.generator.util.generated.type.builder; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.opendaylight.controller.sal.binding.model.api.AnnotationType; import org.opendaylight.controller.sal.binding.model.api.Constant; -import org.opendaylight.controller.sal.binding.model.api.Enumeration; import org.opendaylight.controller.sal.binding.model.api.GeneratedType; -import org.opendaylight.controller.sal.binding.model.api.MethodSignature; import org.opendaylight.controller.sal.binding.model.api.Type; -import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder; -import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder; -import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder; -import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder; -import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder; - -public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder { - - private final String packageName; - private String comment = ""; - private final String name; - private final List annotationBuilders = new ArrayList(); - private final List implementsTypes = new ArrayList(); - private final List enumDefinitions = new ArrayList(); - private final List constantDefintions = new ArrayList(); - private final List methodDefinitions = new ArrayList(); - - public GeneratedTypeBuilderImpl(final String packageName, final String name) { - this.packageName = packageName; - this.name = name; - } - - @Override - public Type getParentType() { - return this; - } - - @Override - public String getPackageName() { - return packageName; - } - - @Override - public String getName() { - return name; - } - - @Override - public void addComment(String comment) { - this.comment = comment; - } +import org.opendaylight.controller.sal.binding.model.api.type.builder.*; - @Override - public AnnotationTypeBuilder addAnnotation(String packageName, String name) { - if (packageName != null && name != null) { - final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl( - packageName, name); - if (annotationBuilders.add(builder)) { - return builder; - } - } - return null; - } +import java.util.List; - @Override - public ConstantBuilder addConstant(Type type, String name, Object value) { - final ConstantBuilder builder = new ConstantBuilderImpl(type, name, - value); - constantDefintions.add(builder); - return builder; - } +public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder { - @Override - public EnumBuilder addEnumeration(final String name) { - final String innerPackageName = packageName + "." + this.name; - final EnumBuilder builder = new EnumerationBuilderImpl( - innerPackageName, name); - enumDefinitions.add(builder); - return builder; + public GeneratedTypeBuilderImpl(String packageName, String name) { + super(packageName, name); + setAbstract(true); } @Override - public MethodSignatureBuilder addMethod(final String name) { - final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl( - this, name); - methodDefinitions.add(builder); - return builder; + public GeneratedType toInstance() { + return new GeneratedTypeImpl(null, getPackageName(), getName(), getComment(), getAnnotations(), isAbstract(), + getImplementsTypes(), getEnclosedTypes(), getEnclosedTransferObjects(), getEnumerations(), + getConstants(), getMethodDefinitions()); } @Override - public boolean addImplementsType(final Type genType) { - if (genType != null) { - return implementsTypes.add(genType); - } - return false; + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedTransferObject [packageName="); + builder.append(getPackageName()); + builder.append(", name="); + builder.append(getName()); + builder.append(", comment="); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append(getComment()); + builder.append(", implements="); + builder.append(getImplementsTypes()); + builder.append(", enclosedTypes="); + builder.append(getEnclosedTypes()); + builder.append(", constants="); + builder.append(getConstants()); + builder.append(", enumerations="); + builder.append(getEnumerations()); + builder.append(", properties="); + builder.append(", methods="); + builder.append(getMethodDefinitions()); + builder.append("]"); + return builder.toString(); } - - @Override - public GeneratedType toInstance() { - return new GeneratedTypeImpl(this, packageName, name, comment, - annotationBuilders, implementsTypes, enumDefinitions, constantDefintions, - methodDefinitions); - } - - private static final class GeneratedTypeImpl implements GeneratedType { - - private final Type parent; - private final String packageName; - private final String name; - private final String comment; - private final List annotations; - private final List implementsTypes; - private final List enumDefinitions; - private final List constantDefintions; - private final List methodDefinitions; - - public GeneratedTypeImpl(final Type parent, final String packageName, - final String name, final String comment, - final List annotationBuilders, - final List implementsTypes, - final List enumBuilders, - final List constantBuilders, - final List methodBuilders) { - super(); - this.parent = parent; - this.packageName = packageName; - this.name = name; - this.comment = comment; - this.annotations = toUnmodifiableAnnotations(annotationBuilders); - this.implementsTypes = Collections.unmodifiableList(implementsTypes); - this.constantDefintions = toUnmodifiableConstants(constantBuilders); - this.enumDefinitions = toUnmodifiableEnums(enumBuilders); - this.methodDefinitions = toUnmodifiableMethods(methodBuilders); - } - - private List toUnmodifiableAnnotations( - final List annotationBuilders) { - final List annotations = new ArrayList(); - for (final AnnotationTypeBuilder builder : annotationBuilders) { - annotations.add(builder.toInstance()); - } - return Collections.unmodifiableList(annotations); - } - - private List toUnmodifiableMethods( - List methodBuilders) { - final List methods = new ArrayList(); - for (final MethodSignatureBuilder methodBuilder : methodBuilders) { - methods.add(methodBuilder.toInstance(this)); - } - return Collections.unmodifiableList(methods); - } - - private List toUnmodifiableEnums( - List enumBuilders) { - final List enums = new ArrayList(); - for (final EnumBuilder enumBuilder : enumBuilders) { - enums.add(enumBuilder.toInstance(this)); - } - return Collections.unmodifiableList(enums); - } - - private List toUnmodifiableConstants( - List constantBuilders) { - final List constants = new ArrayList(); - for (final ConstantBuilder enumBuilder : constantBuilders) { - constants.add(enumBuilder.toInstance(this)); - } - return Collections.unmodifiableList(constants); - } - - @Override - public String getPackageName() { - return packageName; - } - - @Override - public String getName() { - return name; - } - - @Override - public Type getParentType() { - return parent; - } - - @Override - public String getComment() { - return comment; - } - - @Override - public List getAnnotations() { - return annotations; - } - - @Override - public List getImplements() { - return implementsTypes; - } - - @Override - public List getEnumDefintions() { - return enumDefinitions; - } - - @Override - public List getConstantDefinitions() { - return constantDefintions; - } - - @Override - public List getMethodDefinitions() { - return methodDefinitions; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime - * result - + ((constantDefintions == null) ? 0 : constantDefintions - .hashCode()); - result = prime - * result - + ((enumDefinitions == null) ? 0 : enumDefinitions - .hashCode()); - result = prime - * result - + ((methodDefinitions == null) ? 0 : methodDefinitions - .hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result - + ((packageName == null) ? 0 : packageName.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - GeneratedTypeImpl other = (GeneratedTypeImpl) obj; - if (constantDefintions == null) { - if (other.constantDefintions != null) { - return false; - } - } else if (!constantDefintions.equals(other.constantDefintions)) { - return false; - } - if (enumDefinitions == null) { - if (other.enumDefinitions != null) { - return false; - } - } else if (!enumDefinitions.equals(other.enumDefinitions)) { - return false; - } - if (methodDefinitions == null) { - if (other.methodDefinitions != null) { - return false; - } - } else if (!methodDefinitions.equals(other.methodDefinitions)) { - return false; - } - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (packageName == null) { - if (other.packageName != null) { - return false; - } - } else if (!packageName.equals(other.packageName)) { - return false; - } - return true; - } - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("GeneratedType [packageName="); - builder.append(packageName); - builder.append(", name="); - builder.append(name); - if (parent != null) { - builder.append(", parent="); - builder.append(parent.getPackageName()); - builder.append("."); - builder.append(parent.getName()); - } else { - builder.append(", parent=null"); - } - builder.append(", comment="); - builder.append(comment); - builder.append(", annotations="); - builder.append(annotations); - builder.append(", enumDefinitions="); - builder.append(enumDefinitions); - builder.append(", constantDefintions="); - builder.append(constantDefintions); - builder.append(", methodDefinitions="); - builder.append(methodDefinitions); - builder.append("]"); - return builder.toString(); + private static final class GeneratedTypeImpl extends AbstractGeneratedType { + + public GeneratedTypeImpl(final Type parent, final String packageName, final String name, final String comment, + final List annotationBuilders, final boolean isAbstract, + final List implementsTypes, + final List enclosedGenTypeBuilders, + final List enclosedGenTOBuilders, + final List enumBuilders, final List constants, + final List methodBuilders) { + super(parent, packageName, name, comment, annotationBuilders, isAbstract, implementsTypes, + enclosedGenTypeBuilders, enclosedGenTOBuilders, enumBuilders, constants, methodBuilders); } } } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java index a2ce27c72a..ebb68647bf 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java @@ -1,49 +1,34 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.opendaylight.controller.sal.binding.model.api.AccessModifier; import org.opendaylight.controller.sal.binding.model.api.AnnotationType; import org.opendaylight.controller.sal.binding.model.api.MethodSignature; import org.opendaylight.controller.sal.binding.model.api.Type; import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder; import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder; -final class MethodSignatureBuilderImpl implements MethodSignatureBuilder { - private final String name; - private Type returnType; +final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder implements MethodSignatureBuilder { + private final List parameters; - private final List annotationBuilders; - private String comment = ""; - private final Type parent; + private boolean isAbstract; - public MethodSignatureBuilderImpl(final Type parent, final String name) { - super(); - this.name = name; - this.parent = parent; - this.parameters = new ArrayList(); - this.annotationBuilders = new ArrayList(); + public MethodSignatureBuilderImpl(final String name) { + super(name); + this.parameters = new ArrayList<>(); } @Override - public AnnotationTypeBuilder addAnnotation(String packageName, String name) { - if (packageName != null && name != null) { - final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl( - packageName, name); - if (annotationBuilders.add(builder)) { - return builder; - } - } - return null; - } - - @Override - public void addReturnType(Type returnType) { - if (returnType != null) { - this.returnType = returnType; - } + public void setAbstract(boolean isAbstract) { + this.isAbstract = isAbstract; } @Override @@ -51,26 +36,22 @@ final class MethodSignatureBuilderImpl implements MethodSignatureBuilder { parameters.add(new MethodParameterImpl(name, type)); } - @Override - public void addComment(String comment) { - this.comment = comment; - } - @Override public MethodSignature toInstance(Type definingType) { - return new MethodSignatureImpl(definingType, name, annotationBuilders, - comment, returnType, parameters); + final List annotations = toAnnotationTypes(); + return new MethodSignatureImpl(definingType, getName(), annotations, + getComment(), getAccessModifier(), getReturnType(), parameters, isFinal(), isAbstract); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((parameters == null) ? 0 : parameters.hashCode()); result = prime * result - + ((returnType == null) ? 0 : returnType.hashCode()); + + ((getReturnType() == null) ? 0 : getReturnType().hashCode()); return result; } @@ -86,11 +67,11 @@ final class MethodSignatureBuilderImpl implements MethodSignatureBuilder { return false; } MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj; - if (name == null) { - if (other.name != null) { + if (getName() == null) { + if (other.getName() != null) { return false; } - } else if (!name.equals(other.name)) { + } else if (!getName().equals(other.getName())) { return false; } if (parameters == null) { @@ -100,11 +81,11 @@ final class MethodSignatureBuilderImpl implements MethodSignatureBuilder { } else if (!parameters.equals(other.parameters)) { return false; } - if (returnType == null) { - if (other.returnType != null) { + if (getReturnType() == null) { + if (other.getReturnType() != null) { return false; } - } else if (!returnType.equals(other.returnType)) { + } else if (!getReturnType().equals(other.getReturnType())) { return false; } return true; @@ -114,160 +95,16 @@ final class MethodSignatureBuilderImpl implements MethodSignatureBuilder { public String toString() { StringBuilder builder = new StringBuilder(); builder.append("MethodSignatureBuilderImpl [name="); - builder.append(name); + builder.append(getName()); builder.append(", returnType="); - builder.append(returnType); + builder.append(getReturnType()); builder.append(", parameters="); builder.append(parameters); builder.append(", annotationBuilders="); - builder.append(annotationBuilders); + builder.append(getAnnotationBuilders()); builder.append(", comment="); - builder.append(comment); - if (parent != null) { - builder.append(", parent="); - builder.append(parent.getPackageName()); - builder.append("."); - builder.append(parent.getName()); - } else { - builder.append(", parent=null"); - } + builder.append(getComment()); builder.append("]"); return builder.toString(); } - - private static final class MethodSignatureImpl implements MethodSignature { - - private final String name; - private final String comment; - private final Type definingType; - private final Type returnType; - private final List params; - private List annotations; - - public MethodSignatureImpl(final Type definingType, final String name, - final List annotationBuilders, - final String comment, final Type returnType, - final List params) { - super(); - this.name = name; - this.comment = comment; - this.definingType = definingType; - this.returnType = returnType; - this.params = Collections.unmodifiableList(params); - - this.annotations = new ArrayList(); - for (final AnnotationTypeBuilder builder : annotationBuilders) { - this.annotations.add(builder.toInstance()); - } - this.annotations = Collections.unmodifiableList(this.annotations); - } - - @Override - public List getAnnotations() { - return annotations; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getComment() { - return comment; - } - - @Override - public Type getDefiningType() { - return definingType; - } - - @Override - public Type getReturnType() { - return returnType; - } - - @Override - public List getParameters() { - return params; - } - - @Override - public AccessModifier getAccessModifier() { - return AccessModifier.PUBLIC; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result - + ((params == null) ? 0 : params.hashCode()); - result = prime * result - + ((returnType == null) ? 0 : returnType.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - MethodSignatureImpl other = (MethodSignatureImpl) obj; - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (params == null) { - if (other.params != null) { - return false; - } - } else if (!params.equals(other.params)) { - return false; - } - if (returnType == null) { - if (other.returnType != null) { - return false; - } - } else if (!returnType.equals(other.returnType)) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("MethodSignatureImpl [name="); - builder.append(name); - builder.append(", comment="); - builder.append(comment); - if (definingType != null) { - builder.append(", definingType="); - builder.append(definingType.getPackageName()); - builder.append("."); - builder.append(definingType.getName()); - } else { - builder.append(", definingType= null"); - } - builder.append(", returnType="); - builder.append(returnType); - builder.append(", params="); - builder.append(params); - builder.append(", annotations="); - builder.append(annotations); - builder.append("]"); - return builder.toString(); - } - } } \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/MethodSignatureImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/MethodSignatureImpl.java new file mode 100644 index 0000000000..5be1cc933b --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/MethodSignatureImpl.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2013 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.controller.binding.generator.util.generated.type.builder; + +import org.opendaylight.controller.sal.binding.model.api.AccessModifier; +import org.opendaylight.controller.sal.binding.model.api.AnnotationType; +import org.opendaylight.controller.sal.binding.model.api.MethodSignature; +import org.opendaylight.controller.sal.binding.model.api.Type; + +import java.util.Collections; +import java.util.List; + +class MethodSignatureImpl extends AbstractTypeMember implements MethodSignature { + + private final List params; + private final boolean isAbstract; + + public MethodSignatureImpl(final Type definingType, final String name, + final List annotations, + final String comment, final AccessModifier accessModifier, + final Type returnType, final List params, boolean isFinal, + boolean isAbstract) { + super(definingType, name, annotations, comment, accessModifier, returnType, isFinal); + this.params = Collections.unmodifiableList(params); + this.isAbstract = isAbstract; + } + + @Override + public boolean isAbstract() { + return isAbstract; + } + + @Override + public List getParameters() { + return params; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); + result = prime * result + + ((params == null) ? 0 : params.hashCode()); + result = prime * result + + ((getReturnType() == null) ? 0 : getReturnType().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MethodSignatureImpl other = (MethodSignatureImpl) obj; + if (getName() == null) { + if (other.getName() != null) { + return false; + } + } else if (!getName().equals(other.getName())) { + return false; + } + if (params == null) { + if (other.params != null) { + return false; + } + } else if (!params.equals(other.params)) { + return false; + } + if (getReturnType() == null) { + if (other.getReturnType() != null) { + return false; + } + } else if (!getReturnType().equals(other.getReturnType())) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MethodSignatureImpl [name="); + builder.append(getName()); + builder.append(", comment="); + builder.append(getComment()); + if (getDefiningType() != null) { + builder.append(", definingType="); + builder.append(getDefiningType().getPackageName()); + builder.append("."); + builder.append(getDefiningType().getName()); + } else { + builder.append(", definingType= null"); + } + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", params="); + builder.append(params); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/test/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/test/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationBuilderTest.java index 107dc5910b..0f2daa86c3 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/test/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationBuilderTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/test/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationBuilderTest.java @@ -17,7 +17,6 @@ import java.util.List; import org.junit.Test; import org.opendaylight.controller.binding.generator.util.Types; -import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl; import org.opendaylight.controller.sal.binding.model.api.AnnotationType; import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.controller.sal.binding.model.api.GeneratedType; @@ -76,7 +75,7 @@ public class AnnotationBuilderTest { final MethodSignatureBuilder methodBuilder = genTypeBuilder .addMethod("simpleMethod"); - methodBuilder.addReturnType(Types.typeForClass(Integer.class)); + methodBuilder.setReturnType(Types.typeForClass(Integer.class)); final AnnotationTypeBuilder annotManAttr = methodBuilder .addAnnotation("org.springframework.jmx.export.annotation", "ManagedAttribute"); @@ -142,7 +141,7 @@ public class AnnotationBuilderTest { final GeneratedPropertyBuilder propertyBuilder = genTOBuilder .addProperty("simpleProperty"); - propertyBuilder.addReturnType(Types.typeForClass(Integer.class)); + propertyBuilder.setReturnType(Types.typeForClass(Integer.class)); final AnnotationTypeBuilder annotManAttr = propertyBuilder .addAnnotation("org.springframework.jmx.export.annotation", "ManagedAttribute"); diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassCodeGenerator.java b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassCodeGenerator.java index aaeec40604..877bcfce63 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassCodeGenerator.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassCodeGenerator.java @@ -30,7 +30,6 @@ public final class ClassCodeGenerator implements CodeGenerator { @Override public Writer generate(Type type) throws IOException { final Writer writer = new StringWriter(); - boolean isIdentity = type instanceof GeneratedTransferIdentityObject; if (type instanceof GeneratedTransferObject) { GeneratedTransferObject genTO = (GeneratedTransferObject) type; @@ -38,7 +37,7 @@ public final class ClassCodeGenerator implements CodeGenerator { final String currentPkg = genTO.getPackageName(); final List fields = genTO.getProperties(); - final List enums = genTO.getEnumDefintions(); + final List enums = genTO.getEnumerations(); writer.write(GeneratorUtil.createPackageDeclaration(currentPkg)); writer.write(NL); @@ -50,7 +49,7 @@ public final class ClassCodeGenerator implements CodeGenerator { writer.write(NL); writer.write(GeneratorUtil.createClassDeclaration(genTO, "", - imports, isIdentity)); + imports, genTO.isAbstract())); writer.write(NL); writer.write(NL); @@ -69,7 +68,7 @@ public final class ClassCodeGenerator implements CodeGenerator { } writer.write(NL); writer.write(GeneratorUtil.createConstructor(genTO, TAB, - imports, isIdentity) + NL); + imports, genTO.isAbstract()) + NL); writer.write(NL); for (GeneratedProperty field : fields) { writer.write(GeneratorUtil.createGetter(field, TAB, diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/GeneratorUtil.java b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/GeneratorUtil.java index 5b3b17dbf6..804ac99ff2 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/GeneratorUtil.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/GeneratorUtil.java @@ -622,7 +622,7 @@ public final class GeneratorUtil { final String genTypePkg = genType.getPackageName(); final List constants = genType.getConstantDefinitions(); - final List methods = genType.getMethodDefinitions(); + final List methods = genType.getMethodDefinitions(); List impl = genType.getImplements(); // IMPLEMENTATIONS diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/InterfaceGenerator.java b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/InterfaceGenerator.java index 38d3bcdc07..16d63efe1b 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/InterfaceGenerator.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/InterfaceGenerator.java @@ -82,7 +82,7 @@ public final class InterfaceGenerator implements CodeGenerator { final List constants = genType.getConstantDefinitions(); final List methods = genType .getMethodDefinitions(); - final List enums = genType.getEnumDefintions(); + final List enums = genType.getEnumerations(); writer.write(GeneratorUtil.createPackageDeclaration(genType .getPackageName())); @@ -105,5 +105,4 @@ public final class InterfaceGenerator implements CodeGenerator { } return writer; } - } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/ClassCodeGeneratorTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/ClassCodeGeneratorTest.java index 5dd011be32..8916131a3f 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/ClassCodeGeneratorTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/ClassCodeGeneratorTest.java @@ -110,11 +110,11 @@ public class ClassCodeGeneratorTest { "simple.pack", "DefCtor"); GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo"); - propBuilder.addReturnType(Types.typeForClass(String.class)); + propBuilder.setReturnType(Types.typeForClass(String.class)); propBuilder.setReadOnly(false); propBuilder = toBuilder.addProperty("bar"); - propBuilder.addReturnType(Types.typeForClass(Integer.class)); + propBuilder.setReturnType(Types.typeForClass(Integer.class)); propBuilder.setReadOnly(false); final GeneratedTransferObject genTO = toBuilder.toInstance(); @@ -141,12 +141,12 @@ public class ClassCodeGeneratorTest { "simple.pack", "DefCtor"); GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo"); - propBuilder.addReturnType(Types.typeForClass(String.class)); + propBuilder.setReturnType(Types.typeForClass(String.class)); propBuilder.setReadOnly(false); toBuilder.addToStringProperty(propBuilder); propBuilder = toBuilder.addProperty("bar"); - propBuilder.addReturnType(Types.typeForClass(Integer.class)); + propBuilder.setReturnType(Types.typeForClass(Integer.class)); propBuilder.setReadOnly(false); toBuilder.addToStringProperty(propBuilder); final GeneratedTransferObject genTO = toBuilder.toInstance(); diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/AccessModifier.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/AccessModifier.java index 5096dd88f8..52529e254e 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/AccessModifier.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/AccessModifier.java @@ -7,6 +7,10 @@ */ package org.opendaylight.controller.sal.binding.model.api; +/** + * Enum definition which provides four access modifiers that are described + * in Java programming language (Default, Private, Protected, Public). + */ public enum AccessModifier { - PRIVATE, PUBLIC, PROTECTED + DEFAULT, PRIVATE, PUBLIC, PROTECTED } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/AnnotationType.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/AnnotationType.java index 7868675b1e..eec0339d0f 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/AnnotationType.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/AnnotationType.java @@ -9,25 +9,94 @@ package org.opendaylight.controller.sal.binding.model.api; import java.util.List; - +/** + * The Annotation Type interface is designed to hold information about + * annotation for any type that could be annotated in Java. + *
+ * For sake of simplicity the Annotation Type is not designed to model exact + * behaviour of annotation mechanism, but just to hold information needed to + * model annotation over java Type definition. + */ public interface AnnotationType extends Type { - + + /** + * Returns the List of Annotations. + *
+ * Each Annotation Type MAY have defined multiple Annotations. + * + * @return the List of Annotations. + */ public List getAnnotations(); - + + /** + * Returns Parameter Definition assigned for given parameter name. + *
+ * If Annotation does not contain parameter with specified param name, + * the method MAY return null value. + * + * @param paramName Parameter Name + * @return Parameter Definition assigned for given parameter name. + */ public Parameter getParameter(final String paramName); - + + /** + * Returns List of all parameters assigned to Annotation Type. + * + * @return List of all parameters assigned to Annotation Type. + */ public List getParameters(); - + + /** + * Returns List of parameter names. + * + * @return List of parameter names. + */ public List getParameterNames(); - + + /** + * Returns true if annotation contains parameters. + * + * @return true if annotation contains parameters. + */ public boolean containsParameters(); - + + /** + * Annotation Type parameter interface. For simplicity the Parameter + * contains values and value types as Strings. Every annotation which + * contains parameters could contain either single parameter or array of + * parameters. To model this purposes the by contract if the parameter + * contains single parameter the {@link #getValues()} method will return + * empty List and {@link #getValue()} MUST always return non-null + * parameter. If the Parameter holds List of values the singular {@link + * #getValue()} parameter MAY return null value. + */ interface Parameter { - + + /** + * Returns the Name of the parameter. + * + * @return the Name of the parameter. + */ public String getName(); - + + /** + * Returns value in String format if Parameter contains singular value, + * otherwise MAY return null. + * + * @return value in String format if Parameter contains singular value. + */ public String getValue(); - + + /** + * Returns List of Parameter assigned values in order in which they + * were assigned for given parameter name. + *
+ * If there are multiple values assigned for given parameter name the + * method MUST NOT return empty List. + * + * @return List of Parameter assigned values in order in which they + * were assigned for given parameter name. + */ public List getValues(); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/CodeGenerator.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/CodeGenerator.java index abde0da5e7..092efc066b 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/CodeGenerator.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/CodeGenerator.java @@ -10,8 +10,18 @@ package org.opendaylight.controller.sal.binding.model.api; import java.io.IOException; import java.io.Writer; +/** + * + * + */ public interface CodeGenerator { + /** + * + * @param type + * @return + * @throws IOException + */ Writer generate(Type type) throws IOException; } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/ConcreteType.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/ConcreteType.java index ea11abacdb..7af50a7a62 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/ConcreteType.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/ConcreteType.java @@ -7,6 +7,10 @@ */ package org.opendaylight.controller.sal.binding.model.api; +/** + * The Concrete Type is marker interface that encapsulates definition of java + * concrete type. + */ public interface ConcreteType extends Type { } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Constant.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Constant.java index cad3460913..921a473341 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Constant.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Constant.java @@ -7,15 +7,61 @@ */ package org.opendaylight.controller.sal.binding.model.api; +/** + * Interface Contact is designed to hold and model java constant. In Java + * there are no constant keywords instead of the constant is defined as + * static final field with assigned value. For this purpose the Constant + * interface contains methods {@link #getType()} to provide wrapped return + * Type of Constant, {@link #getName()} the Name of constant and the {@link + * #getValue()} for providing of value assigned to Constant. To determine of + * which type the constant value is it is recommended firstly to retrieve + * Type from constant. The Type interface holds base information like java + * package name and java type name (e.g. fully qualified name). From this + * string user should be able to determine to which type can be {@link + * #getValue()} type typecasted to unbox and provide value assigned to + * constant. + */ public interface Constant { + /** + * Returns the Type that declares constant. + * + * @return the Type that declares constant. + */ public Type getDefiningType(); + /** + * Returns the return Type (or just Type) of the Constant. + * + * @return the return Type (or just Type) of the Constant. + */ public Type getType(); + /** + * Returns the name of constant. + *
+ * By conventions the name SHOULD be in CAPITALS separated with + * underscores. + * + * @return the name of constant. + */ public String getName(); + /** + * Returns boxed value that is assigned for context. + * + * @return boxed value that is assigned for context. + */ public Object getValue(); + /** + * Returns Constant definition in formatted string. + *
+ *
+ * The expected string SHOULD be in format: public final + * static [Type] CONSTANT_NAME = [value]; + * + * @return Constant definition in formatted string. + */ public String toFormattedString(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Enumeration.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Enumeration.java index 996423bb1b..4115424ac8 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Enumeration.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Enumeration.java @@ -9,16 +9,38 @@ package org.opendaylight.controller.sal.binding.model.api; import java.util.List; +/** + * + */ public interface Enumeration extends Type { - + + /** + * + * @return + */ public List getAnnotations(); - + + /** + * + * @return + */ public Type getDefiningType(); + /** + * + * @return + */ public List getValues(); + /** + * + * @return + */ public String toFormattedString(); + /** + * + */ interface Pair { public String getName(); diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedProperty.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedProperty.java index 462e1e1f63..119823d7a4 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedProperty.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedProperty.java @@ -7,9 +7,24 @@ */ package org.opendaylight.controller.sal.binding.model.api; -public interface GeneratedProperty extends MethodSignature { +/** + * Generated Property extends interface {@link MethodSignature} interface. + *
+ * The Generated Property interface is designed to store information of + * fields (or members) declared in Java Transfer Objects (or any java + * classes) and their access counterparts (getters and setters). + * + * @see MethodSignature + */ +public interface GeneratedProperty extends TypeMember { + /** + * Returns true if the property si declared as read-only. + *
+ * If the property has flag isReadOnly == true the property + * SHOULD be generated as getter only. + * + * @return true if the property si declared as read-only. + */ public boolean isReadOnly(); - - public boolean isFinal(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedTransferObject.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedTransferObject.java index 6fa551e821..e92dc77eee 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedTransferObject.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedTransferObject.java @@ -9,15 +9,64 @@ package org.opendaylight.controller.sal.binding.model.api; import java.util.List; +/** + * Generated Transfer Object extends {@link GeneratedType} and is designed to + * represent Java Class. The Generated Transfer Object contains declarations + * of member fields stored in List of Properties. The Generated Transfer + * Object can be extended by exactly ONE Generated Transfer Object as Java + * don't allow multiple inheritance. For retrieval of implementing Generated + * Types use {@link #getImplements()} method. + *
+ * Every transfer object SHOULD contain equals, hashCode and toString definitions. + * For this purpose retrieve definitions through {@link #getEqualsIdentifiers + * ()}, {@link #getHashCodeIdentifiers()} and {@link #getToStringIdentifiers + * ()}. + * + */ public interface GeneratedTransferObject extends GeneratedType { - + + /** + * Returns the extending Generated Transfer Object or null + * if there is no extending Generated Transfer Object. + * + * @return the extending Generated Transfer Object or null + * if there is no extending Generated Transfer Object. + */ public GeneratedTransferObject getExtends(); - + + /** + * Returns List of Properties that are declared for Generated Transfer + * Object. + * + * @return List of Properties that are declared for Generated Transfer + * Object. + */ public List getProperties(); - + + /** + * Returns List of Properties that are designated to define equality for + * Generated Transfer Object. + * + * @return List of Properties that are designated to define equality for + * Generated Transfer Object. + */ public List getEqualsIdentifiers(); - + + /** + * Returns List of Properties that are designated to define identity for + * Generated Transfer Object. + * + * @return List of Properties that are designated to define identity for + * Generated Transfer Object. + */ public List getHashCodeIdentifiers(); - + + /** + * Returns List of Properties that will be members of toString definition + * for Generated Transfer Object. + * + * @return List of Properties that will be members of toString definition + * for Generated Transfer Object. + */ public List getToStringIdentifiers(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedType.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedType.java index 82d1720714..7a1a8f4f27 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedType.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedType.java @@ -16,6 +16,12 @@ import java.util.List; *
  • interface name (with commentary that SHOULD be * present to proper define interface and base contracts specified for * interface)
  • + *
  • Each Generated Type can define list of types that Generated Type + * can implement to extend it's definition (i.e. interface extends list of + * interfaces or java class implements list of interfaces)
  • + *
  • Each Generated Type can contain multiple enclosed definitions of + * Generated Types (i.e. interface can contain N enclosed interface + * definitions or enclosed classes)
  • *
  • enum and constant definitions (i.e. each * constant definition is by default defined as public static final * + type (either primitive or object) and constant name
  • @@ -23,40 +29,76 @@ import java.util.List; * types) and return values * * - * By the definition of the interface constant, enum and method definitions MUST + * By the definition of the interface constant, enum, + * enclosed types and method definitions MUST * be public, so there is no need to specify the scope of visibility. - * - * */ public interface GeneratedType extends Type { + /** + * Returns the parent type if Generated Type is defined as enclosing type, + * otherwise returns null + * + * @return the parent type if Generated Type is defined as enclosing type, + * otherwise returns null + */ public Type getParentType(); - + + /** + * Returns comment string associated with Generated Type. + * + * @return comment string associated with Generated Type. + */ public String getComment(); - + + /** + * Returns List of annotation definitions associated with generated type. + * + * @return List of annotation definitions associated with generated type. + */ public List getAnnotations(); - + + /** + * Returns true if The Generated Type is defined as abstract. + * + * @return true if The Generated Type is defined as abstract. + */ + public boolean isAbstract(); + + /** + * Returns List of Types that Generated Type will implement. + * + * @return List of Types that Generated Type will implement. + */ public List getImplements(); - + /** - * Returns Set of all Enumerator definitions associated with interface. - * - * @return Set of all Enumerator definitions associated with interface. + * Returns List of enclosing Generated Types. + * + * @return List of enclosing Generated Types. */ - public List getEnumDefintions(); + public List getEnclosedTypes(); /** + * Returns List of all Enumerator definitions associated with Generated + * Type. * - * - * @return + * @return List of all Enumerator definitions associated with Generated + * Type. + */ + public List getEnumerations(); + + /** + * Returns List of Constant definitions associated with Generated Type. + * + * @return List of Constant definitions associated with Generated Type. */ public List getConstantDefinitions(); /** + * Returns List of Method Definitions associated with Generated Type. * - * - * @return + * @return List of Method Definitions associated with Generated Type. */ public List getMethodDefinitions(); - } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/MethodSignature.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/MethodSignature.java index dda1f01291..88542e86f2 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/MethodSignature.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/MethodSignature.java @@ -9,25 +9,62 @@ package org.opendaylight.controller.sal.binding.model.api; import java.util.List; -public interface MethodSignature { - - public List getAnnotations(); - - public String getName(); - - public String getComment(); - - public Type getDefiningType(); +/** + * The Method Signature interface contains simplified meta model for java + * method definition. Each method MUST be defined by name, return type, + * parameters and access modifier. + *
    + * Additionally method MAY contain associated annotations and comment. By + * contract if method does not contain any comments or annotation definitions + * the {@link #getComment()} SHOULD rather return empty string and {@link + * #getAnnotations()} SHOULD rather return empty list than null + * values. + *
    + * The defining Type contains the reference to Generated Type that declares + * Method Signature. + */ +public interface MethodSignature extends TypeMember { - public Type getReturnType(); + /** + * Returns true if the method signature is defined as abstract. + *
    + * By default in java all method declarations in interface are defined as abstract, + * but the user don't need necessary to declare abstract keyword in front of each method. + *
    + * The abstract methods are allowed in Class definitions but only when the class is declared as abstract. + * + * @return true if the method signature is defined as abstract. + */ + public boolean isAbstract(); + /** + * Returns the List of parameters that method declare. If the method does + * not contain any parameters, the method will return empty List. + * + * @return the List of parameters that method declare. + */ public List getParameters(); - public AccessModifier getAccessModifier(); - + /** + * The Parameter interface is designed to hold the information of method + * Parameter(s). The parameter is defined by his Name which MUST be + * unique as java does not allow multiple parameters with same names for + * one method and Type that is associated with parameter. + */ interface Parameter { + + /** + * Returns the parameter name. + * + * @return the parameter name. + */ public String getName(); + /** + * Returns Type that is bounded to parameter name. + * + * @return Type that is bounded to parameter name. + */ public Type getType(); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/ParameterizedType.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/ParameterizedType.java index 1e800acaa9..86c4f5af04 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/ParameterizedType.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/ParameterizedType.java @@ -9,10 +9,29 @@ package org.opendaylight.controller.sal.binding.model.api; /** * Represents an instance of simple parametrized type such as List. + * + * The parametrized Type is designed to be used to store information of Java + * Generic Type. The array of {@link #getActualTypeArguments()} holds + * information of all generic parameters defined for Parameterized Type. */ public interface ParameterizedType extends Type { + /** + * Returns array of Types that are defined for Parameterized Type. + *
    + * (for example if ParameterizedType encapsulates java generic Map that + * specifies two parameters Map and the K is java.lang.Integer and V + * is defined as GeneratedType the array will contain two Types to store + * the information of generic parameters.) + * + * @return array of Types that are defined for Parameterized Type. + */ Type[] getActualTypeArguments(); + /** + * Returns the Raw Type definition of Parameterized Type. + * + * @return the Raw Type definition of Parameterized Type. + */ Type getRawType(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Type.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Type.java index 1ec3c9fab2..c564ab46e4 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Type.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/Type.java @@ -7,6 +7,13 @@ */ package org.opendaylight.controller.sal.binding.model.api; +/** + * The Type interface defines the base type for all types defined in java. + * Each Type defined in java MUST contain name and package name, + * except of primitive types like int, byte etc. In case of mapping of + * primitive type the package name MUST be left as empty string. + * + */ public interface Type { /** * Returns name of the package that interface belongs to. @@ -21,4 +28,19 @@ public interface Type { * @return name of the interface. */ public String getName(); + + /** + * Returns fully qualified name of Type. + *
    + * The fully qualified name of Type MUST be returned in following format: + *
      + *
    • If does not contains package name: [type name] (e.g. int, byte, + * byte[],...)
    • + *
    • If Type contains package name: [package name].[type name] + * (e.g java.lang.Byte, org.opendaylight.controller.gen.GenType)
    • + *
    + * + * @return fully qualified name of Type. + */ + public String getFullyQualifiedName(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/TypeMember.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/TypeMember.java new file mode 100644 index 0000000000..e2176ff66d --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/TypeMember.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013 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.controller.sal.binding.model.api; + +import java.util.List; + +public interface TypeMember { + + /** + * Returns List of annotation definitions associated with generated type. + * + * @return List of annotation definitions associated with generated type. + */ + public List getAnnotations(); + + /** + * Returns the name of method. + * + * @return the name of method. + */ + public String getName(); + + /** + * Returns comment string associated with method. + * + * @return comment string associated with method. + */ + public String getComment(); + + /** + * Returns the Type that declares method. + * + * @return the Type that declares method. + */ + public Type getDefiningType(); + + /** + * Returns the access modifier of method. + * + * @return the access modifier of method. + */ + public AccessModifier getAccessModifier(); + + /** + * Returns the returning Type that methods returns. + * + * @return the returning Type that methods returns. + */ + public Type getReturnType(); + + /** + * Returns true if method is declared as final. + * + * @return true if method is declared as final. + */ + public boolean isFinal(); +} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/AnnotationTypeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/AnnotationTypeBuilder.java index 6016274260..543c47b55d 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/AnnotationTypeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/AnnotationTypeBuilder.java @@ -12,13 +12,83 @@ import java.util.List; import org.opendaylight.controller.sal.binding.model.api.AnnotationType; import org.opendaylight.controller.sal.binding.model.api.Type; +/** + * Annotation Type Builder Interface serves for creation and instantiation of + * immutable copy of Annotation Type. The Annotation Type Builder extends + * from {@link Type} interface. The Annotation Type contains set of methods + * which are capable to provide information about other Annotation Types and + * Annotation Parameters. + * + * @see AnnotationType + */ public interface AnnotationTypeBuilder extends Type { - + + /** + * The method creates new AnnotationTypeBuilder containing specified + * package name an annotation name. + *
    + * Neither the package name or annotation name can contain + * null references. In case that + * any of parameters contains null the method SHOULD thrown + * {@link IllegalArgumentException} + * + * @param packageName Package Name of Annotation Type + * @param name Name of Annotation Type + * @return new instance of Annotation Type Builder. + */ public AnnotationTypeBuilder addAnnotation(final String packageName, final String name); - + + /** + * Adds the parameter into List of parameters for Annotation Type. + *
    + * If there is already stored parameter with the same name as the new + * parameter, the value of the old one will be simply overwritten by the + * newer parameter. + *
    + * Neither the param name or value can contain + * null references. In case that + * any of parameters contains null the method SHOULD thrown + * {@link IllegalArgumentException} + * + * @param paramName Parameter Name + * @param value Parameter Value + * @return true if the parameter has been successfully + * assigned for Annotation Type + */ public boolean addParameter(final String paramName, String value); - + + /** + * Adds the parameter with specified List of parameter values into List of + * parameters for Annotation Type. + *
    + * If there is already stored parameter with the same name as the new + * parameter, the value of the old one will be simply overwritten by the + * newer parameter. + *
    + * Neither the param name or value can contain + * null references. In case that + * any of parameters contains null the method SHOULD thrown + * {@link IllegalArgumentException} + * + * @param paramName Parameter Name + * @param values List of Values bounded to Parameter Name + * @return true if the parameter has been successfully + * assigned for Annotation Type + */ public boolean addParameters(final String paramName, List values); - + + /** + * Returns new immutable instance of Annotation Type + * with values assigned in current instance of Annotation Type Builder. + *
    + * The return Annotation Type instance is immutable thus no additional + * modification to Annotation Type Builder will have an impact to + * instantiated Annotation Type. + *
    + * For this purpose call this method after + * all additions are complete. + * + * @return new immutable instance of Annotation Type. + */ public AnnotationType toInstance(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/ConstantBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/ConstantBuilder.java index 1a16f86439..fd643783ed 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/ConstantBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/ConstantBuilder.java @@ -11,7 +11,6 @@ import org.opendaylight.controller.sal.binding.model.api.Constant; import org.opendaylight.controller.sal.binding.model.api.Type; /** - * */ public interface ConstantBuilder { diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/EnumBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/EnumBuilder.java index 9716c6053e..5f3d84c1d6 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/EnumBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/EnumBuilder.java @@ -11,14 +11,39 @@ import org.opendaylight.controller.sal.binding.model.api.Enumeration; import org.opendaylight.controller.sal.binding.model.api.Type; /** - + * Enum Builder is interface that contains methods to build and instantiate + * Enumeration definition. * + * @see Enumeration */ public interface EnumBuilder extends Type { - + + /** + * The method creates new AnnotationTypeBuilder containing specified + * package name an annotation name. + *
    + * Neither the package name or annotation name can contain + * null references. In case that + * any of parameters contains null the method SHOULD thrown + * {@link IllegalArgumentException} + * + * @param packageName Package Name of Annotation Type + * @param name Name of Annotation Type + * @return new instance of Annotation Type Builder. + */ public AnnotationTypeBuilder addAnnotation(final String packageName, final String name); - + + /** + * + * @param name + * @param value + */ public void addValue(final String name, final Integer value); + /** + * + * @param definingType + * @return + */ public Enumeration toInstance(final Type definingType); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedPropertyBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedPropertyBuilder.java index fd64cec8b7..f1df1fbc3b 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedPropertyBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedPropertyBuilder.java @@ -7,29 +7,38 @@ */ package org.opendaylight.controller.sal.binding.model.api.type.builder; -import org.opendaylight.controller.sal.binding.model.api.AccessModifier; import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty; import org.opendaylight.controller.sal.binding.model.api.Type; /** - + * Generated Property Builder is interface that contains methods to build and + * instantiate Generated Property definition. * + * @see GeneratedProperty */ -public interface GeneratedPropertyBuilder { - - public AnnotationTypeBuilder addAnnotation(final String packageName, final String name); - - public String getName(); - - public boolean addReturnType(final Type returnType); - - public void accessorModifier(final AccessModifier modifier); - - public void addComment(final String comment); - - public void setFinal(final boolean isFinal); - +public interface GeneratedPropertyBuilder extends TypeMemberBuilder { + + /** + * Sets isReadOnly flag for property. If property is marked as read only + * it is the same as set property in java as final. + * + * @param isReadOnly Read Only property flag. + */ public void setReadOnly(final boolean isReadOnly); - + + /** + * Returns new immutable instance of Generated + * Property. + *
    + * The definingType param cannot be null. The + * every member in Java MUST be declared and defined inside the scope of + * class definition. In case that + * defining Type will be passed as null reference the method + * SHOULD thrown {@link IllegalArgumentException}. + * + * @param definingType Defining Type of Generated Property + * @return new immutable instance of Generated + * Property. + */ public GeneratedProperty toInstance(final Type definingType); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTOBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTOBuilder.java index fc3495e184..8d36ad6c46 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTOBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTOBuilder.java @@ -10,23 +10,77 @@ package org.opendaylight.controller.sal.binding.model.api.type.builder; import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject; /** - + * Generated Transfer Object Builder is interface that contains methods to + * build and instantiate Generated Transfer Object definition. + * + * @see GeneratedTransferObject */ public interface GeneratedTOBuilder extends GeneratedTypeBuilder { - public boolean addExtendsType(final GeneratedTransferObject genTransObj); + /** + * Add Generated Transfer Object from which will be extended current + * Generated Transfer Object. + *
    + * By definition Java does not allow multiple + * inheritance, hence if there is already definition of Generated + * Transfer Object the extending object will be overwritten by lastly + * added Generated Transfer Object. + *
    + * If Generated Transfer Object is null the method SHOULD + * throw {@link IllegalArgumentException} + * + * @param genTransObj Generated Transfer Object + */ + public void setExtendsType(final GeneratedTransferObject genTransObj); + /** + * Add new Generated Property definition for Generated Transfer Object + * Builder and returns Generated Property Builder for specifying Property. + *
    + * Name of Property cannot be null, + * if it is null the method SHOULD throw {@link IllegalArgumentException} + * + * @param name Name of Property + * @return new instance of Generated Property Builder. + */ public GeneratedPropertyBuilder addProperty(final String name); + /** + * Add Property that will be part of equals definition. + *
    + * If Generated Property Builder is null the method SHOULD + * throw {@link IllegalArgumentException} + * + * @param property Generated Property Builder + * @return true if addition of Generated Property into list + * of equals properties is successful. + */ public boolean addEqualsIdentity(final GeneratedPropertyBuilder property); + /** + * Add Property that will be part of hashCode definition. + *
    + * If Generated Property Builder is null the method SHOULD + * throw {@link IllegalArgumentException} + * + * @param property Generated Property Builder + * @return true if addition of Generated Property into list + * of hashCode properties is successful. + */ public boolean addHashIdentity(final GeneratedPropertyBuilder property); + /** + * Add Property that will be part of toString definition. + *
    + * If Generated Property Builder is null the method SHOULD + * throw {@link IllegalArgumentException} + * + * @param property Generated Property Builder + * @return true if addition of Generated Property into list + * of toString properties is successful. + */ public boolean addToStringProperty(final GeneratedPropertyBuilder property); @Override public GeneratedTransferObject toInstance(); - - public GeneratedTransferObject toIdentityInstance(); - } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTypeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTypeBuilder.java index 689e8311e2..6bb58e0ca9 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTypeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTypeBuilder.java @@ -7,29 +7,150 @@ */ package org.opendaylight.controller.sal.binding.model.api.type.builder; +import org.opendaylight.controller.sal.binding.model.api.Constant; import org.opendaylight.controller.sal.binding.model.api.GeneratedType; import org.opendaylight.controller.sal.binding.model.api.Type; /** - + * Generated Type Builder interface is helper interface for building and + * defining the GeneratedType. * + * @see GeneratedType */ public interface GeneratedTypeBuilder extends Type { - public Type getParentType(); + /** + * Adds new Enclosing Type into definition of Generated Type and returns + * new Instance of Generated Type Builder. + *
    + * There is no need of specifying of Package Name because enclosing Type + * is already defined inside Generated Type with specific package name. + *
    + * The name of enclosing Type cannot be same as Name of parent type and + * if there is already defined enclosing type with the same name, + * the new enclosing type will simply overwrite the older definition. + *
    + * If the name of enclosing type is null the method SHOULD + * throw {@link IllegalArgumentException} + * + * @param name Name of Enclosing Type + * @return new Instance of Generated Type Builder. + */ + public GeneratedTypeBuilder addEnclosingType(final String name); + + /** + * Adds new Enclosing Transfer Object into definition of Generated Type + * and returns new Instance of Generated TO Builder. + *
    + * There is no need of specifying of Package Name because enclosing Type + * is already defined inside Generated Type with specific package name. + *
    + * The name of enclosing Type cannot be same as Name of parent type and + * if there is already defined enclosing type with the same name, + * the new enclosing type will simply overwrite the older definition. + *
    + * If the name of enclosing type is null the method SHOULD + * throw {@link IllegalArgumentException} + * + * @param name Name of Enclosing Type + * @return new Instance of Generated Type Builder. + */ + public GeneratedTOBuilder addEnclosingTransferObject(final String name); + /** + * Adds String definition of comment into Method Signature definition. + *
    + * The comment String MUST NOT contain anny comment specific chars (i.e. + * "/**" or "//") just plain String text description. + * + * @param comment Comment String. + */ public void addComment(final String comment); - + + /** + * The method creates new AnnotationTypeBuilder containing specified + * package name an annotation name. + *
    + * Neither the package name or annotation name can contain + * null references. In case that + * any of parameters contains null the method SHOULD thrown + * {@link IllegalArgumentException} + * + * @param packageName Package Name of Annotation Type + * @param name Name of Annotation Type + * @return new instance of Annotation Type Builder. + */ public AnnotationTypeBuilder addAnnotation(final String packageName, final String name); - + + /** + * Sets the abstract flag to define Generated Type as abstract type. + * + * @param isAbstract abstract flag + */ + public void setAbstract(boolean isAbstract); + + /** + * Add Type to implements. + * + * @param genType Type to implement + * @return true if the addition of type is successful. + */ public boolean addImplementsType(final Type genType); - - public ConstantBuilder addConstant(final Type type, final String name, + + /** + * Adds Constant definition and returns new Constant instance. + *
    + * By definition Constant MUST be defined by return Type, + * Name and assigned value. The name SHOULD be defined with cpaital + * letters. Neither of method parameters can be null and the + * method SHOULD throw {@link IllegalArgumentException} if the contract + * is broken. + * + * @param type Constant Type + * @param name Name of Constant + * @param value Assigned Value + * @return new Constant instance. + */ + public Constant addConstant(final Type type, final String name, final Object value); + /** + * Adds new Enumeration definition for Generated Type Builder and returns + * Enum Builder for specifying all Enum parameters. + *
    + * If there is already Enumeration stored with the same name, + * the old enum will be simply overwritten byt new enum definition. + *
    + * Name of Enumeration cannot be null, + * if it is null the method SHOULD throw {@link IllegalArgumentException} + * + * @param name Enumeration Name + * @return new instance of Enumeration Builder. + */ public EnumBuilder addEnumeration(final String name); + /** + * Add new Method Signature definition for Generated Type Builder and + * returns Method Signature Builder for specifying all Method parameters. + *
    + * Name of Method cannot be null, + * if it is null the method SHOULD throw {@link IllegalArgumentException} + *
    + * By Default the MethodSignatureBuilder SHOULD be pre-set as + * {@link MethodSignatureBuilder#setAbstract(true)}, {@link MethodSignatureBuilder#setFinal(false)} and + * {@link MethodSignatureBuilder#setAccessModifier(PUBLIC)} + * + * @param name Name of Method + * @return new instance of Method Signature Builder. + */ public MethodSignatureBuilder addMethod(final String name); + /** + * Returns the new immutable instance of Generated + * Type. + * + * @return the new immutable instance of Generated + * Type. + */ public GeneratedType toInstance(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/MethodSignatureBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/MethodSignatureBuilder.java index 572d15faf4..70ea9bbb00 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/MethodSignatureBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/MethodSignatureBuilder.java @@ -11,15 +11,58 @@ package org.opendaylight.controller.sal.binding.model.api.type.builder; import org.opendaylight.controller.sal.binding.model.api.MethodSignature; import org.opendaylight.controller.sal.binding.model.api.Type; -public interface MethodSignatureBuilder { - - public AnnotationTypeBuilder addAnnotation(final String packageName, final String name); - - public void addReturnType(final Type returnType); +/** + * Method Signature Builder serves solely for building Method Signature and + * returning the new instance of Method Signature. + *
    + * By definition of {@link MethodSignature} the Method in java MUST contain + * Name, Return Type and Access Modifier. By default the Access Modifier can + * be set to public. The Method Signature builder does not contain method for + * addName due to enforce reason that MethodSignatureBuilder SHOULD be + * instantiated only once with defined method name. + *
    + * The methods as {@link #addAnnotation(String, String)} and {@link #setComment(String)} + * can be used as optional because not all methods MUST contain annotation or + * comment definitions. + * + * + * @see MethodSignature + */ +public interface MethodSignatureBuilder extends TypeMemberBuilder { - public void addParameter(final Type type, final String name); + /** + * Sets the flag for declaration of method as abstract or non abstract. If the flag isAbstract == true + * The instantiated Method Signature MUST have return value for {@link org.opendaylight.controller.sal.binding + * .model.api.MethodSignature#isAbstract()} also equals to true. + * + * @param isAbstract is abstract flag + */ + public void setAbstract(boolean isAbstract); - public void addComment(final String comment); + /** + * Adds Parameter into the List of method parameters. Neither the Name or + * Type of parameter can be null. + * + *
    + * In case that any of parameters are defined as null the + * method SHOULD throw an {@link IllegalArgumentException} + * + * @param type Parameter Type + * @param name Parameter Name + */ + public void addParameter(final Type type, final String name); + /** + * Returns new immutable instance of Method Signature. + *
    + * The definingType param cannot be null. The + * every method in Java MUST be declared and defined inside the scope of + * class or interface definition. In case that + * defining Type will be passed as null reference the method + * SHOULD thrown {@link IllegalArgumentException}. + * + * @param definingType Defining Type of Method Signature + * @return new immutable instance of Method Signature. + */ public MethodSignature toInstance(final Type definingType); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/TypeMemberBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/TypeMemberBuilder.java new file mode 100644 index 0000000000..de19360dc2 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/TypeMemberBuilder.java @@ -0,0 +1,69 @@ +package org.opendaylight.controller.sal.binding.model.api.type.builder; + +import org.opendaylight.controller.sal.binding.model.api.AccessModifier; +import org.opendaylight.controller.sal.binding.model.api.Type; + +/** + * + */ +public interface TypeMemberBuilder { + + /** + * The method creates new AnnotationTypeBuilder containing specified + * package name an annotation name. + *
    + * Neither the package name or annotation name can contain + * null references. In case that + * any of parameters contains null the method SHOULD thrown + * {@link IllegalArgumentException} + * + * @param packageName Package Name of Annotation Type + * @param name Name of Annotation Type + * @return new instance of Annotation Type Builder. + */ + public AnnotationTypeBuilder addAnnotation(final String packageName, final String name); + + /** + * Returns the name of property. + * + * @return the name of property. + */ + public String getName(); + + /** + * Adds return Type into Builder definition for Generated Property. + *
    + * The return Type MUST NOT be null, + * otherwise the method SHOULD throw {@link IllegalArgumentException} + * + * @param returnType Return Type of property. + */ + public void setReturnType(final Type returnType); + + /** + * Sets the access modifier of property. + * + * @param modifier Access Modifier value. + */ + public void setAccessModifier(final AccessModifier modifier); + + /** + * Adds String definition of comment into Method Signature definition. + *
    + * The comment String MUST NOT contain anny comment specific chars (i.e. + * "/**" or "//") just plain String text description. + * + * @param comment Comment String. + */ + public void setComment(final String comment); + + /** + * Sets the flag final for method signature. If this is set the method will be prohibited from overriding. + *
    + * This setting is irrelevant for methods designated to be defined in interface definitions because interface + * can't have final method. + * + * @param isFinal Is Final + */ + public void setFinal(final boolean isFinal); +}