From 4dbd2fdfdd225fe007751a7277687da84a607d75 Mon Sep 17 00:00:00 2001 From: Martin Vitez Date: Wed, 6 Nov 2013 15:26:02 +0100 Subject: [PATCH] Implemented length statement. Added new method to Builder classes. - Implemented type length restriction in generated code (Bug 93). - Setters for binary and string fields contains check for valid length. - Added new "fieldsFrom(DataObject arg)" method to Builder classes. - Method accepts class generated from grouping and serves as setter of properties based on grouping type. Change-Id: I402ef1d76a68cdde3f4a8a8c74d2100ac38a6487 Signed-off-by: Martin Vitez --- .../generator/impl/BindingGeneratorImpl.xtend | 7 +- .../binding/generator/spi/TypeProvider.java | 3 + .../generator/util/BindingGeneratorUtil.java | 39 ++++++ .../binding/generator/util/Types.java | 80 ++++++------ .../type/builder/GeneratedTOBuilderImpl.java | 16 ++- .../sal/java/api/generator/BaseTemplate.xtend | 42 ++++++ .../java/api/generator/BuilderTemplate.xtend | 75 +++++++++-- .../java/api/generator/ClassTemplate.xtend | 1 + .../test/CascadeUsesCompilationTest.java | 11 ++ .../sal/binding/model/api/ConcreteType.java | 2 + .../model/api/GeneratedTransferObject.java | 14 +- .../sal/binding/model/api/Restrictions.java | 23 ++++ .../api/type/builder/GeneratedTOBuilder.java | 17 ++- .../sal/binding/yang/types/BaseYangTypes.java | 22 +++- .../binding/yang/types/TypeProviderImpl.java | 122 ++++++++++-------- yang/yang-binding/pom.xml | 4 + 16 files changed, 349 insertions(+), 129 deletions(-) create mode 100644 code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/Restrictions.java diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend index 257a5c4c76..8a6d638c5d 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend @@ -71,6 +71,8 @@ import org.opendaylight.yangtools.yang.model.api.AugmentationTarget import java.util.Collection import org.opendaylight.yangtools.yang.model.api.YangNode import org.opendaylight.yangtools.yang.model.api.NotificationDefinition +import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil +import org.opendaylight.yangtools.sal.binding.model.api.Restrictions public class BindingGeneratorImpl implements BindingGenerator { @@ -1322,8 +1324,9 @@ public class BindingGeneratorImpl implements BindingGenerator { if (genTOBuilder !== null) { returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); } - } else { - returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); + } else { + val Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef); + returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, restrictions); } if (returnType !== null) { val MethodSignatureBuilder getter = constructGetter(typeBuilder, leafName, leafDesc, returnType); diff --git a/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java b/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java index b0722b4164..d8b1338593 100644 --- a/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java +++ b/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java @@ -7,6 +7,7 @@ */ package org.opendaylight.yangtools.sal.binding.generator.spi; +import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaNode; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; @@ -33,4 +34,6 @@ public interface TypeProvider { * @return Resolved Type */ Type javaTypeForSchemaDefinitionType(final TypeDefinition type, final SchemaNode parentNode); + + Type javaTypeForSchemaDefinitionType(final TypeDefinition type, final SchemaNode parentNode, final Restrictions restrictions); } diff --git a/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java b/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java index 092c47c72d..f0b7b808f7 100644 --- a/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java +++ b/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java @@ -2,15 +2,21 @@ package org.opendaylight.yangtools.binding.generator.util; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; +import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; +import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; +import org.opendaylight.yangtools.yang.model.util.ExtendedType; /** * Contains the methods for converting strings to valid JAVA language strings @@ -320,4 +326,37 @@ public final class BindingGeneratorUtil { } return sb.toString(); } + + public static Restrictions getRestrictions(TypeDefinition type) { + final List length = new ArrayList<>(); + final List pattern = new ArrayList<>(); + final List range = new ArrayList<>(); + + if (type instanceof ExtendedType) { + ExtendedType ext = (ExtendedType)type; + length.addAll(ext.getLengthConstraints()); + pattern.addAll(ext.getPatternConstraints()); + range.addAll(ext.getRangeConstraints()); + } + + return new Restrictions() { + @Override + public List getRangeConstraints() { + return range; + } + @Override + public List getPatternConstraints() { + return pattern; + } + @Override + public List getLengthConstraints() { + return length; + } + @Override + public boolean isEmpty() { + return range.isEmpty() && pattern.isEmpty() && length.isEmpty(); + } + }; + } + } diff --git a/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java b/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java index a96e000b4c..ffcbf175b6 100644 --- a/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java +++ b/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java @@ -7,18 +7,16 @@ */ package org.opendaylight.yangtools.binding.generator.util; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl; import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; +import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.binding.model.api.WildcardType; import org.opendaylight.yangtools.yang.binding.Augmentable; @@ -29,24 +27,10 @@ public final class Types { private static final Type SET_TYPE = typeForClass(Set.class); private static final Type LIST_TYPE = typeForClass(List.class); private static final Type MAP_TYPE = typeForClass(Map.class); - public static final ConcreteType NUMBER = typeForClass(Number.class); - public static final ConcreteType BIG_DECIMAL = typeForClass(BigDecimal.class); - public static final ConcreteType BIG_INTEGER = typeForClass(BigInteger.class); - public static final ConcreteType BYTE = typeForClass(Byte.class); + public static final ConcreteType BOOLEAN = typeForClass(Boolean.class); - public static final ConcreteType DOUBLE = typeForClass(Double.class); - public static final ConcreteType FLOAT = typeForClass(Float.class); - public static final ConcreteType INTEGER = typeForClass(Integer.class); - public static final ConcreteType LONG = typeForClass(Long.class); - public static final ConcreteType SHORT = typeForClass(Short.class); - public static final ConcreteType STRING = typeForClass(String.class); - public static final ConcreteType CHAR_SEQUENCE = typeForClass(CharSequence.class); - public static final ConcreteType THREAD = typeForClass(Thread.class); public static final ConcreteType FUTURE = typeForClass(Future.class); - public static final ConcreteType CALLABLE = typeForClass(Callable.class); public static final ConcreteType VOID = typeForClass(Void.class); - public static final ConcreteType THROWABLE = typeForClass(Throwable.class); - public static final ConcreteType EXCEPTION = typeForClass(Exception.class); /** * It is not desirable to create instance of this class @@ -58,7 +42,7 @@ public final class Types { * Creates the instance of type * {@link org.opendaylight.yangtools.sal.binding.model.api.ConcreteType * ConcreteType} which represents JAVA void type. - * + * * @return ConcreteType instance which represents JAVA * void */ @@ -71,32 +55,36 @@ public final class Types { * {@link org.opendaylight.yangtools.sal.binding.model.api.ConcreteType * ConcreteType} which represents primitive JAVA type for which package * doesn't exist. - * + * * @param primitiveType * string containing programaticall construction based on * primitive type (e.g byte[]) * @return ConcreteType instance which represents programatic * construction with primitive JAVA type */ - public static Type primitiveType(final String primitiveType) { - return new ConcreteTypeImpl("", primitiveType); + public static Type primitiveType(final String primitiveType, final Restrictions restrictions) { + return new ConcreteTypeImpl("", primitiveType, restrictions); } /** * Returns an instance of {@link ConcreteType} describing the class - * + * * @param cls * Class to describe * @return Description of class */ public static ConcreteType typeForClass(Class cls) { - return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName()); + return typeForClass(cls, null); + } + + public static ConcreteType typeForClass(Class cls, Restrictions restrictions) { + return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions); } /** * Returns an instance of {@link ParameterizedType} describing the typed * {@link Map} - * + * * @param keyType * Key Type * @param valueType @@ -110,7 +98,7 @@ public final class Types { /** * Returns an instance of {@link ParameterizedType} describing the typed * {@link Set} with concrete type of value. - * + * * @param valueType * Value Type * @return Description of generic type instance of Set @@ -122,7 +110,7 @@ public final class Types { /** * Returns an instance of {@link ParameterizedType} describing the typed * {@link List} with concrete type of value. - * + * * @param valueType * Value Type * @return Description of type instance of List @@ -134,7 +122,7 @@ public final class Types { /** * Creates generated transfer object for * {@link org.opendaylight.yangtools.yang.binding.BaseIdentity BaseIdentity} - * + * * @return generated transfer object which is used as extension when YANG * identity is mapped to generated TO */ @@ -148,7 +136,7 @@ public final class Types { * Creates instance of type * {@link org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType * ParameterizedType} - * + * * @param type * JAVA Type for raw type * @param parameters @@ -164,7 +152,7 @@ public final class Types { * Creates instance of type * {@link org.opendaylight.yangtools.sal.binding.model.api.WildcardType * WildcardType} - * + * * @param packageName * string with the package name * @param typeName @@ -182,7 +170,7 @@ public final class Types { * ParameterizedType} where raw type is * {@link org.opendaylight.yangtools.yang.binding.Augmentable} and actual * parameter is valueType. - * + * * @param valueType * JAVA Type with actual parameter * @return ParametrizedType reprezentation of raw type @@ -200,7 +188,7 @@ public final class Types { * ParameterizedType} where raw type is * {@link org.opendaylight.yangtools.yang.binding.Augmentation} and actual * parameter is valueType. - * + * * @param valueType * JAVA Type with actual parameter * @return ParametrizedType reprezentation of raw type @@ -213,29 +201,37 @@ public final class Types { } /** - * + * * Represents concrete JAVA type. - * + * */ private static final class ConcreteTypeImpl extends AbstractBaseType implements ConcreteType { + private final Restrictions restrictions; + /** * Creates instance of this class with package pkName and * with the type name name. - * + * * @param pkName * string with package name * @param name * string with the name of the type */ - private ConcreteTypeImpl(String pkName, String name) { + private ConcreteTypeImpl(String pkName, String name, Restrictions restrictions) { super(pkName, name); + this.restrictions = restrictions; + } + + @Override + public Restrictions getRestrictions() { + return restrictions; } } /** - * + * * Represents parametrized JAVA type. - * + * */ private static class ParametrizedTypeImpl extends AbstractBaseType implements ParameterizedType { /** @@ -262,7 +258,7 @@ public final class Types { /** * Creates instance of this class with concrete rawType and array of * actual parameters. - * + * * @param rawType * JAVA Type for raw type * @param actTypes @@ -277,14 +273,14 @@ public final class Types { } /** - * + * * Represents JAVA bounded wildcard type. - * + * */ private static class WildcardTypeImpl extends AbstractBaseType implements WildcardType { /** * Creates instance of this class with concrete package and type name. - * + * * @param packageName * string with the package name * @param typeName diff --git a/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java b/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java index 55223398c6..3b45b342a6 100644 --- a/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java +++ b/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java @@ -12,6 +12,7 @@ import java.util.List; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; +import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder; @@ -25,6 +26,7 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder hashProperties = new ArrayList<>(); private final List toStringProperties = new ArrayList<>(); private boolean isUnionType = false; + private Restrictions restrictions; public GeneratedTOBuilderImpl(String packageName, String name) { super(packageName, name); @@ -49,7 +51,7 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuildernew instance of Method Signature Builder. @@ -84,6 +86,11 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder stringProperties; private final GeneratedTransferObject extendsType; private final boolean isUnionType; + private final Restrictions restrictions; public GeneratedTransferObjectImpl(GeneratedTOBuilderImpl builder) { super(builder); @@ -139,6 +147,7 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder> lengthConstraints = new «ArrayList.importedName»<>(); + «FOR r : restrictions.lengthConstraints» + lengthConstraints.add(«Range.importedName».closed(«r.min», «r.max»)); + «ENDFOR» + for («Range.importedName»<«Integer.importedName»> r : lengthConstraints) { + «IF type.name.contains("[")» + if (r.contains(«paramName».length)) { + «ELSE» + if (r.contains(«paramName».length())) { + «ENDIF» + isValidLength = true; + } + } + if (!isValidLength) { + throw new IllegalArgumentException("illegal length"); + } + ''' + } \ No newline at end of file diff --git a/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BuilderTemplate.xtend b/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BuilderTemplate.xtend index 7534f38959..0bf6252fbb 100644 --- a/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BuilderTemplate.xtend +++ b/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BuilderTemplate.xtend @@ -16,8 +16,9 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type import org.opendaylight.yangtools.yang.binding.Augmentable import static org.opendaylight.yangtools.binding.generator.util.Types.* import java.util.HashMap -import java.util.Collections - +import java.util.Collections import org.opendaylight.yangtools.yang.binding.DataObject +import java.util.ArrayList + /** * Template for generating JAVA builder classes. */ @@ -204,7 +205,9 @@ class BuilderTemplate extends BaseTemplate { «generateFields(false)» - «generateBuilderConstructor(type)» + «generateConstructorsFromIfcs(type)» + + «generateSetterFromIfcs(type)» «generateGetters(false)» @@ -232,39 +235,81 @@ class BuilderTemplate extends BaseTemplate { } ''' - - def private generateBuilderConstructor(Type type) ''' + def private generateConstructorsFromIfcs(Type type) ''' public «type.name»«BUILDER»() { - } + } «IF (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject))» «val ifc = type as GeneratedType» «FOR impl : ifc.implements» - «generateSingleBuilderConstructor(impl)» + «generateConstructorFromIfc(impl)» «ENDFOR» «ENDIF» ''' - def private generateSingleBuilderConstructor(Type impl) ''' + def private generateConstructorFromIfc(Type impl) ''' «IF (impl instanceof GeneratedType) && !((impl as GeneratedType).methodDefinitions.empty)» - «val implType = impl as GeneratedType» + public «type.name»«BUILDER»(«implType.fullyQualifiedName» arg) { - «printBuilderConstructorProperties(implType)» + «printConstructorProperties(implType)» } «FOR implTypeImplement : implType.implements» - «generateSingleBuilderConstructor(implTypeImplement)» + «generateConstructorFromIfc(implTypeImplement)» «ENDFOR» «ENDIF» ''' - def private printBuilderConstructorProperties(Type implementedIfc) ''' + def private printConstructorProperties(Type implementedIfc) ''' «IF (implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))» «val ifc = implementedIfc as GeneratedType» «FOR getter : ifc.methodDefinitions» this._«getter.propertyNameFromGetter» = arg.«getter.name»(); «ENDFOR» «FOR impl : ifc.implements» - «printBuilderConstructorProperties(impl)» + «printConstructorProperties(impl)» + «ENDFOR» + «ENDIF» + ''' + + def private generateSetterFromIfcs(Type type) ''' + «IF (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject))» + «val ifc = type as GeneratedType» + «val List done = new ArrayList()» + public void fieldsFrom(«DataObject.importedName» arg) { + «FOR impl : ifc.implements» + «generateSettersForIfc(impl, done)» + «ENDFOR» + } + «ENDIF» + ''' + + def private generateSettersForIfc(Type impl, List done) ''' + «IF (impl instanceof GeneratedType) && !((impl as GeneratedType).methodDefinitions.empty)» + «val implType = impl as GeneratedType» + «val boolean added = done.contains(impl)» + «IF !(added)» + if (arg instanceof «implType.fullyQualifiedName») { + «printSetterProperties(implType, done)» + } + «ENDIF» + «FOR implTypeImplement : implType.implements» + «generateSettersForIfc(implTypeImplement, done)» + «ENDFOR» + «ENDIF» + ''' + + def private printSetterProperties(Type implementedIfc, List done) ''' + «IF (implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))» + «val ifc = implementedIfc as GeneratedType» + «val boolean added = done.contains(ifc)» + «IF !(added)» + «FOR getter : ifc.methodDefinitions» + this._«getter.propertyNameFromGetter» = ((«implementedIfc.fullyQualifiedName»)arg).«getter.name»(); + «ENDFOR» + «val add = done.add(ifc)» + «ENDIF» + «FOR impl : ifc.implements» + «printSetterProperties(impl, done)» «ENDFOR» «ENDIF» ''' @@ -294,6 +339,8 @@ class BuilderTemplate extends BaseTemplate { def private generateSetters() ''' «FOR field : properties SEPARATOR '\n'» public «type.name»«BUILDER» set«field.name.toFirstUpper»(«field.returnType.importedName» value) { + «generateLengthRestrictions(field.returnType, "value")» + this.«field.fieldName» = value; return this; } @@ -306,7 +353,7 @@ class BuilderTemplate extends BaseTemplate { } «ENDIF» ''' - + /** * Template method which generate constructor for IMPL class. * diff --git a/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend b/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend index 102c7c62b8..31c2e38310 100644 --- a/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend +++ b/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend @@ -142,6 +142,7 @@ class ClassTemplate extends BaseTemplate { super(«parentProperties.asArguments»); «ENDIF» «FOR p : properties» + «generateLengthRestrictions(p.returnType, p.fieldName.toString)» this.«p.fieldName» = «p.fieldName»; «ENDFOR» } diff --git a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CascadeUsesCompilationTest.java b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CascadeUsesCompilationTest.java index 6528c48dee..06ac678afe 100644 --- a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CascadeUsesCompilationTest.java +++ b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CascadeUsesCompilationTest.java @@ -12,6 +12,7 @@ import static org.opendaylight.yangtools.sal.java.api.generator.test.Compilation import java.io.File; import java.lang.reflect.Constructor; +import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.HashSet; @@ -117,6 +118,16 @@ public class CascadeUsesCompilationTest extends BaseCompilationTest { assertNotNull(usesBarGr1); assertNotNull(usesBazGr1); + Method fieldsFromMethod = null; + for (Method m : nodesBuilderClass.getDeclaredMethods()) { + String methodName = m.getName(); + if ("fieldsFrom".equals(methodName)) { + fieldsFromMethod = m; + } + } + assertNotNull(fieldsFromMethod); + assertEquals(1, fieldsFromMethod.getParameterTypes().length); + cleanUp(sourcesOutputDir, compiledOutputDir); } diff --git a/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/ConcreteType.java b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/ConcreteType.java index f57f6e52ca..52adeb9325 100644 --- a/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/ConcreteType.java +++ b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/ConcreteType.java @@ -13,4 +13,6 @@ package org.opendaylight.yangtools.sal.binding.model.api; */ public interface ConcreteType extends Type { + Restrictions getRestrictions(); + } diff --git a/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/GeneratedTransferObject.java b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/GeneratedTransferObject.java index 2bfe8ed6bb..f26b4cab27 100644 --- a/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/GeneratedTransferObject.java +++ b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/GeneratedTransferObject.java @@ -20,14 +20,14 @@ import java.util.List; * 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. */ @@ -36,7 +36,7 @@ public interface GeneratedTransferObject extends GeneratedType { /** * 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. */ @@ -45,7 +45,7 @@ public interface GeneratedTransferObject extends GeneratedType { /** * 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. */ @@ -54,7 +54,7 @@ public interface GeneratedTransferObject extends GeneratedType { /** * 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. */ @@ -63,10 +63,12 @@ public interface GeneratedTransferObject extends GeneratedType { /** * Return boolean value which describe whether Generated Transfer Object * was/wasn't created from union YANG type. - * + * * @return true value if Generated Transfer Object was created from union * YANG type. */ @Deprecated boolean isUnionType(); + + Restrictions getRestrictions(); } diff --git a/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/Restrictions.java b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/Restrictions.java new file mode 100644 index 0000000000..292b63244a --- /dev/null +++ b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/Restrictions.java @@ -0,0 +1,23 @@ +/* + * 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.yangtools.sal.binding.model.api; + +import java.util.List; + +import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; +import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; +import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; + +public interface Restrictions { + + List getLengthConstraints(); + List getPatternConstraints(); + List getRangeConstraints(); + boolean isEmpty(); + +} diff --git a/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/builder/GeneratedTOBuilder.java b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/builder/GeneratedTOBuilder.java index a0c81617be..0f12f78008 100644 --- a/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/builder/GeneratedTOBuilder.java +++ b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/builder/GeneratedTOBuilder.java @@ -8,11 +8,12 @@ package org.opendaylight.yangtools.sal.binding.model.api.type.builder; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; +import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; /** * Generated Transfer Object Builder is interface that contains methods to build * and instantiate Generated Transfer Object definition. - * + * * @see GeneratedTransferObject */ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase { @@ -25,7 +26,7 @@ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase * If Generated Transfer Object is null the method SHOULD throw * {@link IllegalArgumentException} - * + * * @param genTransObj * Generated Transfer Object * @return This instance of builder @@ -36,7 +37,7 @@ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBaseequals definition.
* If Generated Property Builder is null the method SHOULD * throw {@link IllegalArgumentException} - * + * * @param property * Generated Property Builder * @return This instance of builder @@ -47,7 +48,7 @@ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBasehashCode definition.
* If Generated Property Builder is null the method SHOULD * throw {@link IllegalArgumentException} - * + * * @param property * Generated Property Builder * @return This instance of builder @@ -58,23 +59,25 @@ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBasetoString definition.
* If Generated Property Builder is null the method SHOULD * throw {@link IllegalArgumentException} - * + * * @param property * Generated Property Builder * @return This instance of builder */ GeneratedTOBuilder addToStringProperty(final GeneratedPropertyBuilder property); + void setRestrictions(Restrictions restrictions); + /** * Returns instance of GeneratedTransferObject which data are * build from the data of this builder - * + * * @return generated transfer object instance */ GeneratedTransferObject toInstance(); /** - * + * * @param isUnion */ void setIsUnion(boolean isUnion); diff --git a/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java b/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java index b77878ffc4..adffbf0105 100644 --- a/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java +++ b/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java @@ -14,6 +14,7 @@ import java.util.Map; import org.opendaylight.yangtools.binding.generator.util.Types; import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider; +import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.SchemaNode; @@ -90,7 +91,7 @@ public final class BaseYangTypes { /** * Type representation of binary YANG type */ - public static final Type BINARY_TYPE = Types.primitiveType("byte[]"); + public static final Type BINARY_TYPE = Types.primitiveType("byte[]", null); public static final Type INSTANCE_IDENTIFIER = Types.parameterizedTypeFor(Types .typeForClass(InstanceIdentifier.class)); @@ -151,5 +152,24 @@ public final class BaseYangTypes { return null; } + + @Override + public Type javaTypeForSchemaDefinitionType(TypeDefinition type, SchemaNode parentNode, Restrictions restrictions) { + String typeName = type.getQName().getLocalName(); + switch (typeName) { + case "binary" : return Types.primitiveType("byte[]", restrictions); + case "decimal64": return Types.typeForClass(BigDecimal.class, restrictions); + case "int8": return Types.typeForClass(Byte.class, restrictions); + case "int16": return Types.typeForClass(Short.class, restrictions); + case "int32": return Types.typeForClass(Integer.class, restrictions); + case "int64": return Types.typeForClass(Long.class, restrictions); + case "string": return Types.typeForClass(String.class, restrictions); + case "uint8": return Types.typeForClass(Short.class, restrictions); + case "uint16": Types.typeForClass(Integer.class, restrictions); + case "uint32": Types.typeForClass(Long.class, restrictions); + case "uint64": Types.typeForClass(BigInteger.class, restrictions); + default: return javaTypeForSchemaDefinitionType(type, parentNode); + } + } }; } diff --git a/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java b/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java index 063cbc61ca..b7d1657e85 100644 --- a/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java +++ b/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java @@ -27,8 +27,10 @@ import org.opendaylight.yangtools.binding.generator.util.Types; import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.EnumerationBuilderImpl; import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl; import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider; +import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType; import org.opendaylight.yangtools.sal.binding.model.api.Enumeration; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; +import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.EnumBuilder; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder; @@ -79,7 +81,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Creates new instance of class TypeProviderImpl. - * + * * @param schemaContext * contains the schema data red from YANG files * @throws IllegalArgumentException @@ -96,7 +98,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Puts refType to map with key refTypePath - * + * * @param refTypePath * schema path used as the map key * @param refType @@ -106,7 +108,7 @@ public final class TypeProviderImpl implements TypeProvider { *
  • if refTypePath equal null
  • *
  • if refType equal null
  • * - * + * */ public void putReferencedType(final SchemaPath refTypePath, final Type refType) { Preconditions.checkArgument(refTypePath != null, @@ -116,9 +118,9 @@ public final class TypeProviderImpl implements TypeProvider { } /** - * + * * Converts basic YANG type type to JAVA Type. - * + * * @param type * string with YANG name of type * @return JAVA Type for YANG type type @@ -129,10 +131,15 @@ public final class TypeProviderImpl implements TypeProvider { return BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForYangType(type); } + @Override + public Type javaTypeForSchemaDefinitionType(final TypeDefinition typeDefinition, final SchemaNode parentNode) { + return javaTypeForSchemaDefinitionType(typeDefinition, parentNode, null); + } + /** * Converts schema definition type typeDefinition to JAVA * Type - * + * * @param typeDefinition * type definition which is converted to JAVA type * @throws IllegalArgumentException @@ -143,7 +150,7 @@ public final class TypeProviderImpl implements TypeProvider { * */ @Override - public Type javaTypeForSchemaDefinitionType(final TypeDefinition typeDefinition, final SchemaNode parentNode) { + public Type javaTypeForSchemaDefinitionType(final TypeDefinition typeDefinition, final SchemaNode parentNode, Restrictions r) { Type returnType = null; Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!"); if (typeDefinition.getQName() == null) { @@ -159,7 +166,7 @@ public final class TypeProviderImpl implements TypeProvider { returnType = javaTypeForLeafrefOrIdentityRef(typeDefinition, parentNode); if (returnType == null) { returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition, - parentNode); + parentNode, r); } } // TODO: add throw exception when we will be able to resolve ALL yang @@ -175,7 +182,7 @@ public final class TypeProviderImpl implements TypeProvider { * Returns JAVA Type for instances of the type * LeafrefTypeDefinition or * IdentityrefTypeDefinition. - * + * * @param typeDefinition * type definition which is converted to JAVA Type * @return JAVA Type instance for typeDefinition @@ -195,7 +202,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Returns JAVA Type for instances of the type * ExtendedType. - * + * * @param typeDefinition * type definition which is converted to JAVA Type * @return JAVA Type instance for typeDefinition @@ -211,6 +218,7 @@ public final class TypeProviderImpl implements TypeProvider { returnType = provideTypeForEnum(enumTypeDef, typedefName, typeDefinition); } else { final Module module = findParentModule(schemaContext, typeDefinition); + Restrictions r = BindingGeneratorUtil.getRestrictions(typeDefinition); if (module != null) { final Map genTOs = genTypeDefsContextMap.get(module.getName()); if (genTOs != null) { @@ -218,7 +226,7 @@ public final class TypeProviderImpl implements TypeProvider { } if (returnType == null) { returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType( - baseTypeDef, typeDefinition); + baseTypeDef, typeDefinition, r); } } } @@ -236,11 +244,11 @@ public final class TypeProviderImpl implements TypeProvider { * Seeks for identity reference idref the JAVA * type.
    *
    - * + * * Example:
    * If identy which is referenced via idref has name Idn * then returning type is {@code Class}
    - * + * * @param idref * identityref type definition for which JAVA Type * is sought @@ -270,7 +278,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts typeDefinition to concrete JAVA Type. - * + * * @param typeDefinition * type definition which should be converted to JAVA * Type @@ -315,7 +323,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Gets base type definition for extendTypeDef. The method is * recursivelly called until non ExtendedType type is found. - * + * * @param extendTypeDef * type definition for which is the base type definition sought * @return type definition which is base type for extendTypeDef @@ -335,10 +343,10 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts leafrefType to JAVA Type. - * + * * The path of leafrefType is followed to find referenced node * and its Type is returned. - * + * * @param leafrefType * leafref type definition for which is the type sought * @return JAVA Type of data schema node which is referenced in @@ -348,7 +356,7 @@ public final class TypeProviderImpl implements TypeProvider { *
  • if leafrefType equal null
  • *
  • if path statement of leafrefType equal null
  • * - * + * */ public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType, final SchemaNode parentNode) { Type returnType = null; @@ -389,7 +397,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Checks if dataNode is LeafSchemaNode and if it * so then checks if it is of type EnumTypeDefinition. - * + * * @param dataNode * data schema node for which is checked if it is leaf and if it * is of enum type @@ -412,7 +420,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Checks if dataNode is LeafListSchemaNode and if * it so then checks if it is of type EnumTypeDefinition. - * + * * @param dataNode * data schema node for which is checked if it is leaflist and if * it is of enum type @@ -437,7 +445,7 @@ public final class TypeProviderImpl implements TypeProvider { * Converts enumTypeDef to * {@link org.opendaylight.yangtools.sal.binding.model.api.Enumeration * enumeration}. - * + * * @param enumTypeDef * enumeration type definition which is converted to enumeration * @param enumName @@ -474,7 +482,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Adds enumeration to typeBuilder. The enumeration data are * taken from enumTypeDef. - * + * * @param enumTypeDef * enumeration type definition is source of enumeration data for * typeBuilder @@ -492,7 +500,7 @@ public final class TypeProviderImpl implements TypeProvider { *
  • if name of enumTypeDef equal null
  • *
  • if name of typeBuilder equal null
  • * - * + * */ private Enumeration addInnerEnumerationToTypeBuilder(final EnumTypeDefinition enumTypeDef, final String enumName, final GeneratedTypeBuilderBase typeBuilder) { @@ -513,7 +521,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts dataNode to JAVA Type. - * + * * @param dataNode * contains information about YANG type * @return JAVA Type representation of dataNode @@ -535,7 +543,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Passes through all modules and through all its type definitions and * convert it to generated types. - * + * * The modules are firstly sorted by mutual dependencies. The modules are * sequentially passed. All type definitions of a module are at the * beginning sorted so that type definition with less amount of references @@ -544,7 +552,7 @@ public final class TypeProviderImpl implements TypeProvider { * {@link TypeProviderImpl#genTypeDefsContextMap genTypeDefsContextMap} * which map current module name to the map which maps type names to * returned types (generated types). - * + * */ private void resolveTypeDefsFromContext() { final Set modules = schemaContext.getModules(); @@ -579,7 +587,7 @@ public final class TypeProviderImpl implements TypeProvider { } /** - * + * * @param basePackageName * string with name of package to which the module belongs * @param moduleName @@ -604,7 +612,7 @@ public final class TypeProviderImpl implements TypeProvider { Type returnType = null; if (innerTypeDefinition instanceof ExtendedType) { ExtendedType innerExtendedType = (ExtendedType) innerTypeDefinition; - returnType = provideGeneratedTOFromExtendedType(innerExtendedType, basePackageName, typedefName); + returnType = provideGeneratedTOFromExtendedType(typedef, innerExtendedType, basePackageName); } else if (innerTypeDefinition instanceof UnionTypeDefinition) { final GeneratedTOBuilder genTOBuilder = provideGeneratedTOBuilderForUnionTypeDef(basePackageName, (UnionTypeDefinition) innerTypeDefinition, typedefName, typedef); @@ -620,8 +628,9 @@ public final class TypeProviderImpl implements TypeProvider { returnType = genTOBuilder.toInstance(); } else { + Restrictions r = BindingGeneratorUtil.getRestrictions(typedef); final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType( - innerTypeDefinition, typedef); + innerTypeDefinition, typedef, r); returnType = wrapJavaTypeIntoTO(basePackageName, typedef, javaType); } @@ -639,7 +648,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Wraps base YANG type to generated TO. - * + * * @param basePackageName * string with name of package to which the module belongs * @param typedef @@ -659,7 +668,7 @@ public final class TypeProviderImpl implements TypeProvider { genTOBuilder.addEqualsIdentity(genPropBuilder); genTOBuilder.addHashIdentity(genPropBuilder); genTOBuilder.addToStringProperty(genPropBuilder); - if (javaType == BaseYangTypes.STRING_TYPE && typedef instanceof ExtendedType) { + if (javaType instanceof ConcreteType && "String".equals(javaType.getName()) && typedef instanceof ExtendedType) { final List regExps = resolveRegExpressionsFromTypedef((ExtendedType) typedef); addStringRegExAsConstant(genTOBuilder, regExps); } @@ -671,7 +680,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts output list of generated TO builders to one TO builder (first * from list) which contains the remaining builders as its enclosing TO. - * + * * @param basePackageName * string with name of package to which the module belongs * @param typedef @@ -701,7 +710,7 @@ public final class TypeProviderImpl implements TypeProvider { * Converts typedef to generated TO with * typeDefName. Every union type from typedef is * added to generated TO builder as property. - * + * * @param basePackageName * string with name of package to which the module belongs * @param typedef @@ -769,14 +778,14 @@ public final class TypeProviderImpl implements TypeProvider { /** * Wraps code which handle case when union subtype is also of the type * UnionType. - * + * * In this case the new generated TO is created for union subtype (recursive * call of method * {@link #provideGeneratedTOBuildersForUnionTypeDef(String, TypeDefinition, String) * provideGeneratedTOBuilderForUnionTypeDef} and in parent TO builder * parentUnionGenTOBuilder is created property which type is * equal to new generated TO. - * + * * @param parentUnionGenTOBuilder * generated TO builder to which is the property with the child * union subtype added @@ -807,11 +816,11 @@ public final class TypeProviderImpl implements TypeProvider { /** * Wraps code which handle case when union subtype is of the type * ExtendedType. - * + * * If TO for this type already exists it is used for the creation of the * property in parentUnionGenTOBuilder. In other case the base * type is used for the property creation. - * + * * @param parentUnionGenTOBuilder * generated TO builder in which new property is created * @param unionSubtype @@ -846,7 +855,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Searches for generated TO for searchedTypeDef type * definition in {@link #genTypeDefsContextMap genTypeDefsContextMap} - * + * * @param searchedTypeName * string with name of searchedTypeDef * @return generated TO for searchedTypeDef or @@ -867,7 +876,7 @@ public final class TypeProviderImpl implements TypeProvider { * Stores generated TO created from genTOBuilder for * newTypeDef to {@link #genTypeDefsContextMap * genTypeDefsContextMap} if the module for newTypeDef exists - * + * * @param newTypeDef * type definition for which is genTOBuilder created * @param genTOBuilder @@ -888,7 +897,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Adds a new property with the name propertyName and with type * type to unonGenTransObject. - * + * * @param unionGenTransObject * generated TO to which should be property added * @param type @@ -913,7 +922,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts typedef to the generated TO builder. - * + * * @param basePackageName * string with name of package to which the module belongs * @param typedef @@ -938,10 +947,10 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts typeDef which should be of the type * BitsTypeDefinition to GeneratedTOBuilder. - * + * * All the bits of the typeDef are added to returning generated TO as * properties. - * + * * @param basePackageName * string with name of package to which the module belongs * @param typeDef @@ -988,13 +997,13 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts the pattern constraints from typedef to the list of * the strings which represents these constraints. - * + * * @param typedef * extended type in which are the pattern constraints sought * @return list of strings which represents the constraint patterns * @throws IllegalArgumentException * if typedef equals null - * + * */ private List resolveRegExpressionsFromTypedef(ExtendedType typedef) { final List regExps = new ArrayList(); @@ -1016,10 +1025,10 @@ public final class TypeProviderImpl implements TypeProvider { } /** - * + * * Adds to the genTOBuilder the constant which contains regular * expressions from the regularExpressions - * + * * @param genTOBuilder * generated TO builder to which are * regular expressions added @@ -1049,11 +1058,11 @@ public final class TypeProviderImpl implements TypeProvider { * innerExtendedType, about the package name * typedefName and about the generated TO name * typedefName. - * + * * It is supposed that innerExtendedType is already present in * {@link TypeProviderImpl#genTypeDefsContextMap genTypeDefsContextMap} to * be possible set it as extended type for the returning generated TO. - * + * * @param innerExtendedType * extended type which is part of some other extended type * @param basePackageName @@ -1069,16 +1078,17 @@ public final class TypeProviderImpl implements TypeProvider { *
  • if typedefName equals null
  • * */ - private GeneratedTransferObject provideGeneratedTOFromExtendedType(final ExtendedType innerExtendedType, - final String basePackageName, final String typedefName) { - + private GeneratedTransferObject provideGeneratedTOFromExtendedType(final TypeDefinition typedef, final ExtendedType innerExtendedType, + final String basePackageName) { Preconditions.checkArgument(innerExtendedType != null, "Extended type cannot be NULL!"); Preconditions.checkArgument(basePackageName != null, "String with base package name cannot be NULL!"); - Preconditions.checkArgument(typedefName != null, "String with type definition name cannot be NULL!"); + final String typedefName = typedef.getQName().getLocalName(); final String classTypedefName = parseToClassName(typedefName); final String innerTypeDef = innerExtendedType.getQName().getLocalName(); final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, classTypedefName); + Restrictions r = BindingGeneratorUtil.getRestrictions(typedef); + genTOBuilder.setRestrictions(r); Map typeMap = null; final Module parentModule = findParentModule(schemaContext, innerExtendedType); @@ -1103,7 +1113,7 @@ public final class TypeProviderImpl implements TypeProvider { * equal depth. In next step are lists from this map concatenated to one * list in ascending order according to their depth. All type definitions * are in the list behind all type definitions on which depends. - * + * * @param unsortedTypeDefinitions * list of type definitions which should be sorted by depth * @return list of type definitions sorted according their each other @@ -1136,7 +1146,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Returns how many immersion is necessary to get from the type definition * to the base type. - * + * * @param typeDefinition * type definition for which is depth sought. * @return number of immersions which are necessary to get from the type @@ -1170,7 +1180,7 @@ public final class TypeProviderImpl implements TypeProvider { * Returns string which contains the same value as name but * integer suffix is incremented by one. If name contains no * number suffix then number 1 is added. - * + * * @param name * string with name of augmented node * @return string with the number suffix incremented by one (or 1 is added) diff --git a/yang/yang-binding/pom.xml b/yang/yang-binding/pom.xml index 8efa9ac92d..34727ec373 100644 --- a/yang/yang-binding/pom.xml +++ b/yang/yang-binding/pom.xml @@ -23,6 +23,10 @@ yang-common 0.5.9-SNAPSHOT + + com.google.guava + guava + 0.6.0-SNAPSHOT -- 2.36.6