Generation of java files from templates 87/787/2
authormsunal <msunal@cisco.com>
Mon, 5 Aug 2013 09:09:48 +0000 (11:09 +0200)
committermsunal <msunal@cisco.com>
Mon, 5 Aug 2013 09:36:55 +0000 (11:36 +0200)
- generation of classes, interfaces, enums, builders is doing by using Xtend templates
- deleted unnecessary file BuilderClassDescriptor

Change-Id: I385604abdb883f2a1ca927b8e7245a692c179744
Signed-off-by: Martin Sunal <msunal@cisco.com>
13 files changed:
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/BuilderClassDescriptor.java [deleted file]
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/BuilderGenerator.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/BuilderTemplate.xtend
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassCodeGenerator.java [deleted file]
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassGenerator.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassTemplate.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/EnumGenerator.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/EnumTemplate.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/GeneratorJavaFile.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/GeneratorUtil.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/InterfaceGenerator.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/InterfaceTemplate.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/ClassCodeGeneratorTest.java

diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/BuilderClassDescriptor.java b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/BuilderClassDescriptor.java
deleted file mode 100644 (file)
index 716afc9..0000000
+++ /dev/null
@@ -1,331 +0,0 @@
-package org.opendaylight.controller.sal.java.api.generator;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-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.ParameterizedType;
-import org.opendaylight.controller.sal.binding.model.api.Type;
-import org.opendaylight.yangtools.yang.binding.Augmentable;
-
-public class BuilderClassDescriptor {
-
-    private static final String GET_PREFIX = "get";
-    private static final String JAVA_UTIL = "java.util";
-    private static final String HASH_MAP = "HashMap";
-    private static final String MAP = "Map";
-    private static final String GET_AUGMENTATION_METHOD_NAME = "getAugmentation";
-
-    private final GeneratedType genType;
-    private Map<String, String> imports;
-    private final String packageName;
-    private final String className;
-    private final Set<MethodDeclaration> methods;
-    private final Set<FieldDeclaration> fields;
-    private final List<String> importsNames;
-    private FieldDeclaration augmentField;
-
-    class TypeDeclaration {
-
-        private final static String JAVA_LANG_PREFIX = "java.lang";
-        private final String name;
-        private final TypeDeclaration[] generics;
-
-        public TypeDeclaration(String pkg, String name, TypeDeclaration... generics) {
-            this.name = removeJavaLangPkgName(getRightTypeName(pkg, name));
-            if (generics != null && generics.length > 0) {
-                this.generics = generics;
-            } else {
-                this.generics = null;
-            }
-        }
-
-        public TypeDeclaration(final Type type) {
-            if (type == null) {
-                throw new IllegalArgumentException("Type cannot be NULL");
-            }
-
-            this.name = removeJavaLangPkgName(getRightTypeName(type.getPackageName(), type.getName()));
-            TypeDeclaration[] generics = null;
-            if (type instanceof ParameterizedType) {
-                final ParameterizedType pType = (ParameterizedType) type;
-                final Type[] actualTypeArguments = pType.getActualTypeArguments();
-                generics = new TypeDeclaration[actualTypeArguments.length];
-                for (int i = 0; i < actualTypeArguments.length; i++) {
-                    generics[i] = new TypeDeclaration(actualTypeArguments[i].getPackageName(),
-                            actualTypeArguments[i].getName());
-                }
-            }
-            if (generics != null && generics.length > 0) {
-                this.generics = generics;
-            } else {
-                this.generics = null;
-            }
-        }
-
-        private String removeJavaLangPkgName(final String typeName) {
-            if (typeName.startsWith(JAVA_LANG_PREFIX)) {
-                return typeName.substring(typeName.lastIndexOf(Constants.DOT) + 1);
-            }
-            return typeName;
-        }
-
-        private String getRightTypeName(final String pkg, final String name) {
-            if (name == null) {
-                throw new IllegalArgumentException("Name cannot be NULL!");
-            }
-
-            if (imports == null) {
-                return name;
-            }
-            final String pkgFromImports = imports.get(name);
-            if (pkgFromImports == null || pkgFromImports.equals(pkg)) {
-                return name;
-            }
-            return (pkg == null ? "" : pkg) + Constants.DOT + name;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public TypeDeclaration[] getGenerics() {
-            return generics;
-        }
-
-    }
-
-    class ParameterDeclaration {
-
-        private final TypeDeclaration type;
-        private final String name;
-
-        public ParameterDeclaration(TypeDeclaration type, String name) {
-            this.type = type;
-            this.name = name;
-        }
-
-        public TypeDeclaration getType() {
-            return type;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-    }
-
-    class MethodDeclaration {
-
-        private final TypeDeclaration returnType;
-        private final String name;
-        private final List<ParameterDeclaration> parameters;
-
-        public MethodDeclaration(final TypeDeclaration returnType, final String name,
-                final List<ParameterDeclaration> parameters) {
-            this.returnType = returnType;
-            this.name = name;
-            if (parameters != null && !parameters.isEmpty()) {
-                this.parameters = parameters;
-            } else {
-                this.parameters = null;
-            }
-        }
-
-        public TypeDeclaration getReturnType() {
-            return returnType;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public List<ParameterDeclaration> getParameters() {
-            return parameters;
-        }
-
-    }
-
-    class FieldDeclaration extends ParameterDeclaration {
-
-        public FieldDeclaration(final TypeDeclaration type, final String name) {
-            super(type, name);
-        }
-
-    }
-
-    public BuilderClassDescriptor(final GeneratedType genType) {
-        if (genType == null) {
-            throw new IllegalArgumentException("Generated type reference cannot be NULL!");
-        }
-        this.genType = genType;
-        this.imports = GeneratorUtil.createImports(genType);
-        addToImports(genType.getPackageName(), genType.getName());
-        packageName = genType.getPackageName();
-        className = genType.getName();
-        methods = createMethods();
-        fields = createFieldsFromMethods();
-        importsNames = createImportsNames();
-    }
-
-    private Set<MethodDeclaration> createMethods() {
-        final Set<MethodDeclaration> methods = new LinkedHashSet<>();
-        storeMethodsOfIfc(methods, genType);
-        storeMethodsOfImplementedIfcs(methods, genType.getImplements());
-        return methods;
-    }
-
-    private void storeMethodsOfIfc(final Set<MethodDeclaration> methodStorage, final GeneratedType ifc) {
-        for (MethodSignature methodSignature : ifc.getMethodDefinitions()) {
-            final List<ParameterDeclaration> parameterDeclarations = getParameterDeclarationsFrom(methodSignature
-                    .getParameters());
-            methodStorage.add(new MethodDeclaration(new TypeDeclaration(methodSignature.getReturnType()),
-                    methodSignature.getName(), parameterDeclarations));
-        }
-        if (ifc.getEnclosedTypes() != null && !ifc.getEnclosedTypes().isEmpty()) {
-            addToImports(ifc.getPackageName(), ifc.getName() + ".*");
-        }
-    }
-
-    private List<ParameterDeclaration> getParameterDeclarationsFrom(final List<MethodSignature.Parameter> parameters) {
-        final List<ParameterDeclaration> parameterDeclarations = new ArrayList<>();
-        for (MethodSignature.Parameter mp : parameters) {
-            parameterDeclarations.add(new ParameterDeclaration(new TypeDeclaration(mp.getType()), mp.getName()));
-        }
-        return parameterDeclarations;
-    }
-
-    private void storeMethodsOfImplementedIfcs(final Set<MethodDeclaration> methodStorage,
-            final List<Type> implementedIfcs) {
-        if (implementedIfcs == null || implementedIfcs.isEmpty()) {
-            return;
-        }
-        for (Type implementedIfc : implementedIfcs) {
-            if ((implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))) {
-                final GeneratedType ifc = ((GeneratedType) implementedIfc);
-                storeMethodsOfIfc(methodStorage, ifc);
-                storeMethodsOfImplementedIfcs(methodStorage, ifc.getImplements());
-            } else if (implementedIfc.getFullyQualifiedName().equals(Augmentable.class.getName())) {
-                for (Method m : Augmentable.class.getMethods()) {
-                    if (m.getName().equals(GET_AUGMENTATION_METHOD_NAME)) {
-                        addToImports(JAVA_UTIL, HASH_MAP);
-                        addToImports(JAVA_UTIL, MAP);
-                        java.lang.reflect.Type returnType = m.getReturnType();
-                        final String fullyQualifiedName = ((Class<?>) returnType).getName();
-                        addToImports(getPackageFrom(fullyQualifiedName), getNameFrom(fullyQualifiedName));
-                        TypeDeclaration augmentMethodType = new TypeDeclaration(getPackageFrom(fullyQualifiedName),
-                                getNameFrom(fullyQualifiedName), new TypeDeclaration(genType));
-                        augmentField = createFieldFromGetMethod(new MethodDeclaration(augmentMethodType, m.getName(),
-                                null));
-                    }
-                }
-            }
-        }
-    }
-
-    private void addToImports(final String pkg, final String name) {
-        if (imports == null) {
-            imports = new LinkedHashMap<>();
-        }
-        if (imports.get(name) == null) {
-            imports.put(name, pkg);
-        }
-    }
-
-    private String getPackageFrom(final String fullyQualifiedName) {
-        final int lastDotIndex = fullyQualifiedName.lastIndexOf(Constants.DOT);
-        return lastDotIndex == -1 ? "" : fullyQualifiedName.substring(0, lastDotIndex);
-    }
-
-    private String getNameFrom(final String fullyQualifiedName) {
-        final int lastDotIndex = fullyQualifiedName.lastIndexOf(Constants.DOT);
-        return lastDotIndex == -1 ? fullyQualifiedName : fullyQualifiedName.substring(lastDotIndex + 1);
-    }
-
-    private Set<FieldDeclaration> createFieldsFromMethods() {
-        final Set<FieldDeclaration> result = new LinkedHashSet<>();
-
-        if (methods == null || methods.isEmpty()) {
-            return result;
-        }
-
-        for (MethodDeclaration m : methods) {
-            final FieldDeclaration createdField = createFieldFromGetMethod(m);
-            if (createdField != null) {
-                result.add(createdField);
-            }
-        }
-        return result;
-    }
-
-    private FieldDeclaration createFieldFromGetMethod(final MethodDeclaration method) {
-        if (method == null || method.getName() == null || method.getName().isEmpty()) {
-            return null;
-        } else if (method.getName().startsWith(GET_PREFIX)) {
-            final String fieldNameFromMethod = method.getName().substring(GET_PREFIX.length());
-            final String fieldName = Character.toLowerCase(fieldNameFromMethod.charAt(0))
-                    + fieldNameFromMethod.substring(1);
-            return new FieldDeclaration(method.getReturnType(), fieldName);
-        }
-        return null;
-    }
-
-    private List<String> createImportsNames() {
-        final List<String> result = new ArrayList<>();
-
-        if (imports == null || imports.isEmpty()) {
-            return result;
-        }
-
-        for (Map.Entry<String, String> entry : imports.entrySet()) {
-            final String typeName = entry.getKey();
-            final String packageName = entry.getValue();
-            result.add(packageName + Constants.DOT + typeName);
-        }
-        return result;
-    }
-
-    public String getPackageName() {
-        return packageName;
-    }
-
-    /**
-     * @return list of imports or empty list
-     */
-    public List<String> getImportsNames() {
-        return importsNames;
-    }
-
-    public String getClassName() {
-        return className;
-    }
-
-    /**
-     * @return set of methods or empty set
-     */
-    public Set<FieldDeclaration> getFields() {
-        return fields;
-    }
-
-    /**
-     * @return set of methods or empty set
-     */
-    public Set<MethodDeclaration> getMethods() {
-        return methods;
-    }
-
-    /**
-     * @return declaration of augment field or NULL
-     */
-    public FieldDeclaration getAugmentField() {
-        return augmentField;
-    }
-
-}
index 07ee733..ec99f1e 100644 (file)
@@ -15,10 +15,11 @@ public final class BuilderGenerator implements CodeGenerator {
 
     @Override
     public Writer generate(Type type) throws IOException {
-        Writer writer = new StringWriter();
+        final Writer writer = new StringWriter();
         if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
-            BuilderTemplate builerGeneratorXtend = new BuilderTemplate();
-            writer.write(builerGeneratorXtend.generate(new BuilderClassDescriptor((GeneratedType) type)).toString());
+            final GeneratedType genType = (GeneratedType) type;
+            final BuilderTemplate template = new BuilderTemplate(genType);
+            writer.write(template.generate().toString());
         }
         return writer;
     }
index 484fbfb..6fe9c1b 100644 (file)
 package org.opendaylight.controller.sal.java.api.generator
 
+import java.util.LinkedHashSet
 import java.util.List
+import java.util.Map
 import java.util.Set
+import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl
+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.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.Type
+import org.opendaylight.yangtools.yang.binding.Augmentable
 
 class BuilderTemplate {
 
+    val static GET_PREFIX = "get"
+    val static JAVA_UTIL = "java.util"
+    val static HASH_MAP = "HashMap"
+    val static MAP = "Map"
+    val static GET_AUGMENTATION_METHOD_NAME = "getAugmentation"
     val static BUILDER = 'Builder'
     val static IMPL = 'Impl'
-
-    def generate(BuilderClassDescriptor cd) '''
-        package «cd.packageName»;
-        «IF !cd.importsNames.empty»
-            
-            «FOR in : cd.importsNames»
-                import «in»;
-            «ENDFOR»
-        «ENDIF»
-        
-        public class «cd.className»«BUILDER» {
+    
+    val GeneratedType genType
+    val Map<String, String> imports
+    var GeneratedProperty augmentField
+    val Set<GeneratedProperty> fields
+    
+    new(GeneratedType genType) {
+        if (genType == null) {
+            throw new IllegalArgumentException("Generated type reference cannot be NULL!")
+        }
         
-            «fields(cd.fields, cd.augmentField)»
-
-            «IF !cd.fields.empty»
-                «FOR field : cd.fields SEPARATOR '\n'»
-                    public «cd.className»«BUILDER» set«field.name.toFirstUpper»(«field.type.name»«field.type.generics.print» «field.name») {
-                        this.«field.name» = «field.name»;
-                        return this;
+        this.genType = genType
+        this.imports = GeneratorUtil.createChildImports(genType)
+        this.fields = createFieldsFromMethods(createMethods)
+    }
+    
+    def private Set<MethodSignature> createMethods() {
+        val Set<MethodSignature> methods = new LinkedHashSet
+        methods.addAll(genType.methodDefinitions)
+        storeMethodsOfImplementedIfcs(methods, genType.implements)
+        return methods
+    }
+    
+    def private void storeMethodsOfImplementedIfcs(Set<MethodSignature> methods, List<Type> implementedIfcs) {
+        if (implementedIfcs == null || implementedIfcs.empty) {
+            return
+        }
+        for (implementedIfc : implementedIfcs) {
+            if ((implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))) {
+                val ifc = implementedIfc as GeneratedType
+                methods.addAll(ifc.methodDefinitions)
+                storeMethodsOfImplementedIfcs(methods, ifc.implements)
+            } else if (implementedIfc.fullyQualifiedName == Augmentable.name) {
+                for (m : Augmentable.methods) {
+                    if (m.name == GET_AUGMENTATION_METHOD_NAME) {
+                        addToImports(JAVA_UTIL, HASH_MAP)
+                        addToImports(JAVA_UTIL, MAP)
+                        val fullyQualifiedName = m.returnType.name
+                        val pkg = fullyQualifiedName.package
+                        val name = fullyQualifiedName.name
+                        addToImports(pkg, name)
+                        val tmpGenTO = new GeneratedTOBuilderImpl(pkg, name)
+                        val type = new ReferencedTypeImpl(pkg, name)
+                        val generic = new ReferencedTypeImpl(genType.packageName, genType.name)
+                        val parametrizedReturnType = Types.parameterizedTypeFor(type, generic)
+                        tmpGenTO.addMethod(m.name).setReturnType(parametrizedReturnType)
+                        augmentField = tmpGenTO.toInstance.methodDefinitions.first.createFieldFromGetter
                     }
-                «ENDFOR»
-            «ENDIF»
-            «IF cd.augmentField != null»
-                
-                public «cd.className»«BUILDER» add«cd.augmentField.name.toFirstUpper»(Class<? extends «cd.augmentField.type.name»«cd.augmentField.type.generics.print»> augmentationType, «cd.augmentField.type.name»«cd.augmentField.type.generics.print» augmentation) {
-                    this.«cd.augmentField.name».put(augmentationType, augmentation);
-                    return this;
                 }
-            «ENDIF»
+            }
+        }
+    }
+    
+    def private void addToImports(String typePackageName,String typeName) {
+        if (typePackageName.startsWith("java.lang") || typePackageName.isEmpty()) {
+            return
+        }
+        if (!imports.containsKey(typeName)) {
+            imports.put(typeName, typePackageName)
+        }
+    }
+    
+    def private <E> first(List<E> elements) {
+        elements.get(0)
+    }
+    
+    def private String getPackage(String fullyQualifiedName) {
+        val lastDotIndex = fullyQualifiedName.lastIndexOf(Constants.DOT)
+        return if (lastDotIndex == -1) "" else fullyQualifiedName.substring(0, lastDotIndex)
+    }
+
+    def private String getName(String fullyQualifiedName) {
+        val lastDotIndex = fullyQualifiedName.lastIndexOf(Constants.DOT)
+        return if (lastDotIndex == -1) fullyQualifiedName else fullyQualifiedName.substring(lastDotIndex + 1)
+    }
+    
+    def private createFieldsFromMethods(Set<MethodSignature> methods) {
+        val Set<GeneratedProperty> result = new LinkedHashSet
+
+        if (methods == null || methods.isEmpty()) {
+            return result
+        }
 
-            public «cd.className» build() {
-                return new «cd.className»«IMPL»();
+        for (m : methods) {
+            val createdField = m.createFieldFromGetter
+            if (createdField != null) {
+                result.add(createdField)
             }
+        }
+        return result
+    }
+    
+    def private GeneratedProperty createFieldFromGetter(MethodSignature method) {
+        if (method == null || method.name == null || method.name.empty || method.returnType == null) {
+            throw new IllegalArgumentException("Method, method name, method return type reference cannot be NULL or empty!")
+        }
+        if (method.name.startsWith(GET_PREFIX)) {
+            val fieldName = method.getName().substring(GET_PREFIX.length()).toFirstLower
+            val tmpGenTO = new GeneratedTOBuilderImpl("foo", "foo")
+            tmpGenTO.addProperty(fieldName).setReturnType(method.returnType)
+            return tmpGenTO.toInstance.properties.first
+        }
+    }
+
+    def generate() {
+        val body = generateBody
+        val pkgAndImports = generatePkgAndImports
+        return pkgAndImports.toString + body.toString
+    }
+    
+    def private generateBody() '''
+        public class «genType.name»«BUILDER» {
+        
+            «generateFields»
 
-            private class «cd.className»«IMPL» implements «cd.className» {
+            «generateSetters»
 
-                «fields(cd.fields, cd.augmentField)»
+            public «genType.name» build() {
+                return new «genType.name»«IMPL»();
+            }
 
-                private «cd.className»«IMPL»() {
-                    «IF !cd.fields.empty»
-                        «FOR field : cd.fields»
-                            this.«field.name» = «cd.className»«BUILDER».this.«field.name»;
-                        «ENDFOR»
-                    «ENDIF»
-                    «IF cd.augmentField != null»
-                        this.«cd.augmentField.name».putAll(«cd.className»«BUILDER».this.«cd.augmentField.name»);
-                    «ENDIF»
-                }
+            private class «genType.name»«IMPL» implements «genType.name» {
 
-                «IF !cd.fields.empty»
-                    «FOR field : cd.fields SEPARATOR '\n'»
-                        @Override
-                        public «field.type.name»«field.type.generics.print» get«field.name.toFirstUpper»() {
-                            return «field.name»;
-                        }
-                    «ENDFOR»
-                «ENDIF»
-                «IF cd.augmentField != null»
-
-                    @Override
-                    public <E extends «cd.augmentField.type.name»«cd.augmentField.type.generics.print»> E get«cd.augmentField.name.toFirstUpper»(Class<E> augmentationType) {
-                        if (augmentationType == null) {
-                            throw new IllegalArgumentException("Augmentation Type reference cannot be NULL!");
-                        }
-                        return (E) «cd.augmentField.name».get(augmentationType);
-                    }
-                «ENDIF»
+                «generateFields»
+
+                «generateConstructor»
+
+                «generateGetters»
 
             }
 
         }
     '''
 
-    def private fields(Set<BuilderClassDescriptor.FieldDeclaration> fields, BuilderClassDescriptor.FieldDeclaration augmentField) '''
+    def private generateFields() '''
         «IF !fields.empty»
-            «FOR field : fields»
-                private «field.type.name»«field.type.generics.print» «field.name»;
+            «FOR f : fields»
+                private «f.returnType.resolveName» «f.name»;
             «ENDFOR»
         «ENDIF»
         «IF augmentField != null»
-            private Map<Class<? extends «augmentField.type.name»«augmentField.type.generics.print»>, «augmentField.type.name»«augmentField.type.generics.print»> «augmentField.name» = new HashMap<>();
+            private Map<Class<? extends «augmentField.returnType.resolveName»>, «augmentField.returnType.resolveName»> «augmentField.name» = new HashMap<>();
         «ENDIF»
     '''
 
-    def private print(List<BuilderClassDescriptor.TypeDeclaration> generics) '''«IF generics != null && !generics.empty»<«FOR generic : generics SEPARATOR ', '»«generic.name»«ENDFOR»>«ENDIF»'''
+    def private generateSetters() '''
+        «FOR field : fields SEPARATOR '\n'»
+            public «genType.name»«BUILDER» set«field.name.toFirstUpper»(«field.returnType.resolveName» «field.name») {
+                this.«field.name» = «field.name»;
+                return this;
+            }
+        «ENDFOR»
+        «IF augmentField != null»
+            
+            public «genType.name»«BUILDER» add«augmentField.name.toFirstUpper»(Class<? extends «augmentField.returnType.resolveName»> augmentationType, «augmentField.returnType.resolveName» augmentation) {
+                this.«augmentField.name».put(augmentationType, augmentation);
+                return this;
+            }
+        «ENDIF»
+    '''
+    
+    def private generateConstructor() '''
+        private «genType.name»«IMPL»() {
+            «IF !fields.empty»
+                «FOR field : fields»
+                    this.«field.name» = «genType.name»«BUILDER».this.«field.name»;
+                «ENDFOR»
+            «ENDIF»
+            «IF augmentField != null»
+                this.«augmentField.name».putAll(«genType.name»«BUILDER».this.«augmentField.name»);
+            «ENDIF»
+        }
+    '''
+    
+    def private generateGetters() '''
+        «IF !fields.empty»
+            «FOR field : fields SEPARATOR '\n'»
+                @Override
+                public «field.returnType.resolveName» get«field.name.toFirstUpper»() {
+                    return «field.name»;
+                }
+            «ENDFOR»
+        «ENDIF»
+        «IF augmentField != null»
 
+            @SuppressWarnings("unchecked")
+            @Override
+            public <E extends «augmentField.returnType.resolveName»> E get«augmentField.name.toFirstUpper»(Class<E> augmentationType) {
+                if (augmentationType == null) {
+                    throw new IllegalArgumentException("Augmentation Type reference cannot be NULL!");
+                }
+                return (E) «augmentField.name».get(augmentationType);
+            }
+        «ENDIF»
+    '''    
+    
+    def private generatePkgAndImports() '''
+        package «genType.packageName»;
+        
+        
+        «IF !imports.empty»
+            «FOR entry : imports.entrySet»
+                import «entry.value».«entry.key»;
+            «ENDFOR»
+        «ENDIF»
+        
+    '''
+    
+    def private resolveName(Type type) {
+        GeneratorUtil.putTypeIntoImports(genType, type, imports);
+        GeneratorUtil.getExplicitType(genType, type, imports)
+    }
+    
 }
+
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
deleted file mode 100644 (file)
index 31b94a6..0000000
+++ /dev/null
@@ -1,138 +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.sal.java.api.generator;
-
-import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.controller.sal.binding.model.api.*;
-
-public final class ClassCodeGenerator implements CodeGenerator {
-
-    private Map<String, String> imports;
-
-    private void generatePackage(Writer writer, String packageName) throws IOException {
-        writer.write(GeneratorUtil.createPackageDeclaration(packageName));
-        writer.write(NL);
-    }
-
-    private void generateImports(Writer writer) throws IOException {
-        List<String> importLines = GeneratorUtil.createImportLines(imports, null);
-        for (String line : importLines) {
-            writer.write(line + NL);
-        }
-        writer.write(NL);
-    }
-
-    private void generateClassBody(Writer writer, GeneratedTransferObject genTO, String packageName, String indent,
-            boolean isInnerClass) throws IOException {
-        final List<GeneratedProperty> fields = genTO.getProperties();
-        final List<Enumeration> enums = genTO.getEnumerations();
-        final List<Constant> consts = genTO.getConstantDefinitions();
-
-        writer.write(GeneratorUtil.createClassDeclaration(genTO, indent, imports, genTO.isAbstract(), isInnerClass));
-        writer.write(NL);
-        writer.write(NL);
-
-        if (consts != null) {
-            for (Constant con : consts) {
-                writer.write(GeneratorUtil.createConstant(con, indent + TAB, imports, packageName));
-                writer.write(NL);
-            }
-        }
-
-        if (enums != null) {
-            EnumGenerator enumGenerator = new EnumGenerator();
-            for (Enumeration e : enums) {
-                writer.write(enumGenerator.generateInnerEnumeration(e, indent + TAB).toString());
-                writer.write(NL);
-            }
-        }
-
-        writer.write(GeneratorUtil.createStaticInicializationBlock(genTO, indent + TAB));
-
-        if (fields != null) {
-            for (GeneratedProperty field : fields) {
-                writer.write(GeneratorUtil.createField(field, indent + TAB, imports, packageName) + NL);
-            }
-
-            writer.write(NL);
-            final boolean oneConstructor;
-            if (genTO.isUnionType()) {
-                oneConstructor = false;
-            } else {
-                oneConstructor = true;
-            }
-            writer.write(GeneratorUtil.createConstructor(genTO, indent + TAB, imports, genTO.isAbstract(),
-                    oneConstructor));
-            writer.write(NL);
-
-            for (GeneratedProperty field : fields) {
-                writer.write(GeneratorUtil.createGetter(field, indent + TAB, imports, packageName) + NL);
-                if (!field.isReadOnly()) {
-                    writer.write(GeneratorUtil.createSetter(field, indent + TAB, imports, packageName) + NL);
-                }
-            }
-
-            if (!genTO.getHashCodeIdentifiers().isEmpty()) {
-                writer.write(GeneratorUtil.createHashCode(genTO.getHashCodeIdentifiers(), indent + TAB) + NL);
-            }
-
-            if (!genTO.getEqualsIdentifiers().isEmpty()) {
-                writer.write(GeneratorUtil.createEquals(genTO, genTO.getEqualsIdentifiers(), indent + TAB) + NL);
-            }
-
-            if (!genTO.getToStringIdentifiers().isEmpty()) {
-                writer.write(GeneratorUtil.createToString(genTO, genTO.getToStringIdentifiers(), indent + TAB) + NL);
-            }
-
-            writer.write(indent + RCB);
-        }
-    }
-
-    @Override
-    public Writer generate(Type type) throws IOException {
-        final Writer writer = new StringWriter();
-
-        if (type instanceof GeneratedTransferObject) {
-            GeneratedTransferObject genTO = (GeneratedTransferObject) type;
-            imports = GeneratorUtil.createImports(genTO);
-
-            final String currentPkg = genTO.getPackageName();
-
-            generatePackage(writer, currentPkg);
-
-            generateImports(writer);
-
-            generateClassBody(writer, genTO, currentPkg, NO_INDENT, false);
-
-        }
-        return writer;
-    }
-
-    public Writer generateOnlyClass(Type type, Map<String, String> imports) throws IOException {
-        this.imports = imports;
-        Writer writer = new StringWriter();
-
-        if (type instanceof GeneratedTransferObject) {
-            GeneratedTransferObject genTO = (GeneratedTransferObject) type;
-
-            final String currentPkg = "";
-
-            generateClassBody(writer, genTO, currentPkg, TAB, true);
-
-        }
-
-        return writer;
-    }
-}
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassGenerator.java b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassGenerator.java
new file mode 100644 (file)
index 0000000..17940a0
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.java.api.generator;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+public final class ClassGenerator implements CodeGenerator {
+
+    @Override
+    public Writer generate(Type type) throws IOException {
+        final Writer writer = new StringWriter();
+        if (type instanceof GeneratedTransferObject) {
+            final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
+            final ClassTemplate template = new ClassTemplate(genTO);
+            writer.write(template.generate().toString());
+        }
+        return writer;
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassTemplate.xtend b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassTemplate.xtend
new file mode 100644 (file)
index 0000000..47a94eb
--- /dev/null
@@ -0,0 +1,291 @@
+package org.opendaylight.controller.sal.java.api.generator
+
+import java.util.List
+import java.util.Map
+import org.opendaylight.controller.binding.generator.util.TypeConstants
+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.GeneratedTransferObject
+import org.opendaylight.controller.sal.binding.model.api.Type
+
+class ClassTemplate {
+    
+    val GeneratedTransferObject genTO
+    val Map<String, String> imports
+    val List<GeneratedProperty> fields
+    val List<Enumeration> enums
+    val List<Constant> consts
+    
+    new(GeneratedTransferObject genTO) {
+        if (genTO == null) {
+            throw new IllegalArgumentException("Generated transfer object reference cannot be NULL!")
+        }
+        
+        this.genTO = genTO
+        this.imports = GeneratorUtil.createImports(genTO)
+        this.fields = genTO.properties
+        this.enums = genTO.enumerations
+        this.consts = genTO.constantDefinitions
+    }
+    
+    def generate() {
+        val body = generateBody(false)
+        val pkgAndImports = generatePkgAndImports
+        return pkgAndImports.toString + body.toString
+    }
+    
+    def generateAsInnerClass() {
+        return generateBody(true)
+    }
+    
+    def private generateBody(boolean isInnerClass) '''
+        «genTO.comment.generateComment»
+        «generateClassDeclaration(isInnerClass)» {
+
+            «generateEnums»
+        
+            «generateConstants»
+        
+            «generateFields»
+        
+            «generateConstructor»
+        
+            «FOR field : fields SEPARATOR "\n"»
+                «field.generateGetter»
+                «IF !field.readOnly»
+                
+                    «field.generateSetter»
+                «ENDIF»
+            «ENDFOR»
+        
+            «generateHashCode»
+        
+            «generateEquals»
+        
+            «generateToString»
+        
+        }
+    '''
+    
+    def private generateComment(String comment) '''
+        «IF comment != null && !comment.empty»
+            /*
+            «comment»
+            */
+        «ENDIF»
+    '''
+    
+    def private generateClassDeclaration(boolean isInnerClass) '''
+        public«
+        IF (isInnerClass)»«
+            " static final "»«
+        ELSEIF (genTO.abstract)»«
+            " abstract "»«
+        ELSE»«
+            " "»«
+        ENDIF»class «genTO.name»«
+        IF (genTO.extends != null)»«
+            " extends "»«genTO.extends.resolveName»«
+        ENDIF»«
+        IF (!genTO.implements.empty)»«
+            " implements "»«
+            FOR type : genTO.implements SEPARATOR ", "»«
+                type.resolveName»«
+            ENDFOR»«
+        ENDIF
+    »'''
+    
+    def private generateEnums() '''
+        «IF !enums.empty»
+            «FOR e : enums SEPARATOR "\n"»
+                «val enumTemplate = new EnumTemplate(e)»
+                «enumTemplate.generateAsInnerClass»
+            «ENDFOR»
+        «ENDIF»
+    '''
+    
+    def private generateConstants() '''
+        «IF !consts.empty»
+            «FOR c : consts»
+                «IF c.name == TypeConstants.PATTERN_CONSTANT_NAME»
+                    «val cValue = c.value»
+                    «IF cValue instanceof List<?>»
+                        «val cValues = cValue as List<?>»
+                        private static final List<Pattern> «Constants.MEMBER_PATTERN_LIST» = new ArrayList<Pattern>();
+                        public static final List<String> «TypeConstants.PATTERN_CONSTANT_NAME» = Arrays.asList(«
+                        FOR v : cValues SEPARATOR ", "»«
+                            IF v instanceof String»"«
+                                v as String»"«
+                            ENDIF»«
+                        ENDFOR»);
+                        
+                        «generateStaticInicializationBlock»
+                    «ENDIF»
+                «ELSE»
+                    public static final «c.type.resolveName» «c.name» = «c.value»;
+                «ENDIF»
+            «ENDFOR»
+        «ENDIF»
+    '''
+    
+    def private generateStaticInicializationBlock() '''
+        static {
+            for (String regEx : «TypeConstants.PATTERN_CONSTANT_NAME») {
+                «Constants.MEMBER_PATTERN_LIST».add(Pattern.compile(regEx));
+            }
+        }
+    '''
+    def private generateFields() '''
+        «IF !fields.empty»
+            «FOR f : fields»
+                private «f.returnType.resolveName» «f.name»;
+            «ENDFOR»
+        «ENDIF»
+    '''
+    
+    def private generateConstructor() '''
+        «val genTOTopParent = GeneratorUtil.getTopParrentTransportObject(genTO)»
+        «val properties = GeneratorUtil.resolveReadOnlyPropertiesFromTO(genTO.properties)»
+        «val propertiesAllParents = GeneratorUtil.getPropertiesOfAllParents(genTO)»
+        «IF !genTO.unionType»
+«««            create constructor for every parent property
+            «IF genTOTopParent != genTO && genTOTopParent.unionType»
+                «FOR parentProperty : propertiesAllParents SEPARATOR "\n"»
+                    «val parentPropertyAndProperties = properties + #[parentProperty]»
+                    «if (genTO.abstract) "protected" else "public"» «genTO.name»(«parentPropertyAndProperties.generateParameters») {
+                        super(«#[parentProperty].generateParameterNames»);
+                        «FOR property : properties»
+                            this.«property.name» = «property.name»;
+                        «ENDFOR»
+                    }
+                «ENDFOR»
+«««            create one constructor
+            «ELSE»
+                «val propertiesAll = propertiesAllParents + properties»
+                «if (genTO.abstract) "protected" else "public"» «genTO.name»(«propertiesAll.generateParameters») {
+                    super(«propertiesAllParents.generateParameterNames()»);
+                    «FOR property : properties»
+                        this.«property.name» = «property.name»;
+                    «ENDFOR»
+                }
+            «ENDIF»
+«««        create constructor for every property
+        «ELSE»
+            «FOR property : properties SEPARATOR "\n"»
+                «val propertyAndTopParentProperties = propertiesAllParents + #[property]»
+                «if (genTO.abstract) "protected" else "public"» «genTO.name»(«propertyAndTopParentProperties.generateParameters») {
+                    super(«propertiesAllParents.generateParameterNames()»);
+                    this.«property.name» = «property.name»;
+                }
+            «ENDFOR»
+        «ENDIF»
+    '''
+    
+    def private generateGetter(GeneratedProperty field) '''
+        public «field.returnType.resolveName» get«field.name.toFirstUpper»() {
+            return «field.name»;
+        }
+    '''
+    
+    def private generateSetter(GeneratedProperty field) '''
+        «val type = field.returnType.resolveName»
+        public void set«field.name.toFirstUpper»(«type» «field.name») {
+            this.«field.name» = «field.name»;
+        }
+    '''
+    
+    def private generateParameters(Iterable<GeneratedProperty> parameters) '''«
+        IF !parameters.empty»«
+            FOR parameter : parameters SEPARATOR ", "»«
+                parameter.returnType.resolveName» «parameter.name»«
+            ENDFOR»«
+        ENDIF
+    »'''
+    
+    def private generateParameterNames(Iterable<GeneratedProperty> parameters) '''«
+        IF !parameters.empty»«
+            FOR parameter : parameters SEPARATOR ", "»«
+                parameter.name»«
+            ENDFOR»«
+        ENDIF
+    »'''
+    
+    def private generateHashCode() '''
+        «IF !genTO.hashCodeIdentifiers.empty»
+            @Override
+            public int hashCode() {
+                final int prime = 31;
+                int result = 1;
+                «FOR property : genTO.hashCodeIdentifiers»
+                    result = prime * result + ((«property.name» == null) ? 0 : «property.name».hashCode());
+                «ENDFOR»
+                return result;
+            }
+        «ENDIF»
+    '''
+    def private generateEquals() '''
+        «IF !genTO.equalsIdentifiers.empty»
+            @Override
+            public boolean equals(Object obj) {
+                if (this == obj) {
+                    return true;
+                }
+                if (obj == null) {
+                    return false;
+                }
+                if (getClass() != obj.getClass()) {
+                    return false;
+                }
+                «genTO.name» other = («genTO.name») obj;
+                «FOR property : genTO.equalsIdentifiers»
+                    «val fieldName = property.name»
+                    if («fieldName» == null) {
+                        if (other.«fieldName» != null) {
+                            return false;
+                        }
+                    } else if(!«fieldName».equals(other.«fieldName»)) {
+                        return false;
+                    }
+                «ENDFOR»
+                return true;
+            }
+        «ENDIF»
+    '''
+    
+    def private generateToString() '''
+        «IF !genTO.toStringIdentifiers.empty»
+            @Override
+            public String toString() {
+                StringBuilder builder = new StringBuilder();
+                «val properties = genTO.toStringIdentifiers»
+                builder.append("«genTO.name» [«properties.get(0).name»=");
+                builder.append(«properties.get(0).name»);
+                «FOR i : 1..<genTO.toStringIdentifiers.size»
+                    builder.append(", «properties.get(i).name»=");
+                    builder.append(«properties.get(i).name»);
+                «ENDFOR»
+                builder.append("]");
+                return builder.toString();
+            }
+        «ENDIF»
+    '''
+    
+    def private generatePkgAndImports() '''
+        package «genTO.packageName»;
+        
+        
+        «IF !imports.empty»
+            «FOR entry : imports.entrySet»
+                import «entry.value».«entry.key»;
+            «ENDFOR»
+        «ENDIF»
+        
+    '''
+    
+    def private resolveName(Type type) {
+        GeneratorUtil.putTypeIntoImports(genTO, type, imports);
+        GeneratorUtil.getExplicitType(genTO, type, imports)
+    }
+    
+}
\ No newline at end of file
index 760365d..f2acefd 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.controller.sal.java.api.generator;
 
-import static org.opendaylight.controller.sal.java.api.generator.Constants.NL;
-
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
@@ -22,25 +20,11 @@ public class EnumGenerator implements CodeGenerator {
     @Override
     public Writer generate(Type type) throws IOException {
         final Writer writer = new StringWriter();
-
         if (type instanceof Enumeration) {
-            Enumeration enums = (Enumeration) type;
-            writer.write(GeneratorUtil.createPackageDeclaration(enums.getPackageName()));
-            writer.write(NL + NL);
-            writer.write(GeneratorUtil.createEnum(enums, ""));
+            final Enumeration enums = (Enumeration) type;
+            final EnumTemplate enumTemplate = new EnumTemplate(enums);
+            writer.write(enumTemplate.generate().toString());
         }
-
-        return writer;
-    }
-
-    public Writer generateInnerEnumeration(Type type, String indent) throws IOException {
-        final Writer writer = new StringWriter();
-
-        if (type instanceof Enumeration) {
-            Enumeration enums = (Enumeration) type;
-            writer.write(GeneratorUtil.createEnum(enums, indent));
-        }
-
         return writer;
     }
 
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/EnumTemplate.xtend b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/EnumTemplate.xtend
new file mode 100644 (file)
index 0000000..62e24ab
--- /dev/null
@@ -0,0 +1,43 @@
+package org.opendaylight.controller.sal.java.api.generator
+
+import org.opendaylight.controller.sal.binding.model.api.Enumeration
+
+class EnumTemplate {
+    
+    val Enumeration enums
+    
+    new(Enumeration enums) {
+        this.enums = enums
+    }
+    
+    def generate() {
+        val body = generateBody
+        val pkg = generatePkg
+        return pkg.toString + body.toString
+    }
+    
+    def generateAsInnerClass() {
+        return generateBody
+    }
+    
+    def private generateBody() '''
+        public enum «enums.name» {
+        «FOR v : enums.values SEPARATOR ",\n"»
+            «"    "»«v.name»(«v.value»)«
+        ENDFOR»;
+        
+            int value;
+        
+            private «enums.name»(int value) {
+                this.value = value;
+            }
+        }
+    '''
+    
+    def private generatePkg() '''
+        package «enums.packageName»;
+        
+        
+    '''
+    
+}
\ No newline at end of file
index 1d2e60f..a7496e8 100644 (file)
@@ -21,7 +21,7 @@ public final class GeneratorJavaFile {
 
     private static final Logger log = LoggerFactory.getLogger(GeneratorJavaFile.class);
     private final CodeGenerator interfaceGenerator;
-    private final ClassCodeGenerator classGenerator;
+    private final ClassGenerator classGenerator;
     private final EnumGenerator enumGenerator;
     private final BuilderGenerator builderGenerator;
 
@@ -34,7 +34,7 @@ public final class GeneratorJavaFile {
         this.genTypes = types;
         this.genTransferObjects = new HashSet<>();
         this.enumerations = new HashSet<>();
-        this.classGenerator = new ClassCodeGenerator();
+        this.classGenerator = new ClassGenerator();
         this.enumGenerator = new EnumGenerator();
         this.builderGenerator = new BuilderGenerator();
     }
@@ -42,7 +42,7 @@ public final class GeneratorJavaFile {
     public GeneratorJavaFile(final Set<GeneratedType> types, final Set<GeneratedTransferObject> genTransferObjects,
             final Set<Enumeration> enumerations) {
         this.interfaceGenerator = new InterfaceGenerator();
-        this.classGenerator = new ClassCodeGenerator();
+        this.classGenerator = new ClassGenerator();
         this.enumGenerator = new EnumGenerator();
         this.builderGenerator = new BuilderGenerator();
 
index 0e2da81..34e9abd 100644 (file)
  */
 package org.opendaylight.controller.sal.java.api.generator;
 
-import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
+import static org.opendaylight.controller.sal.java.api.generator.Constants.COMMA;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.opendaylight.controller.binding.generator.util.TypeConstants;
-import org.opendaylight.controller.sal.binding.model.api.*;
 import org.opendaylight.controller.binding.generator.util.Types;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration.Pair;
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Parameter;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
+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.ParameterizedType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.WildcardType;
+
 
 public final class GeneratorUtil {
 
     private GeneratorUtil() {
     }
-
-    public static String createIfcDeclaration(final GeneratedType genType, final String indent,
-            final Map<String, String> availableImports) {
-        return createFileDeclaration(IFC, genType, indent, availableImports, false, false);
-    }
-
-    public static String createClassDeclaration(final GeneratedTransferObject genTransferObject, final String indent,
-            final Map<String, String> availableImports, boolean isIdentity, boolean isInnerClass) {
-        return createFileDeclaration(CLASS, genTransferObject, indent, availableImports, isIdentity, isInnerClass);
-    }
-
-    public static String createPackageDeclaration(final String packageName) {
-        return PKG + GAP + packageName + SC;
-    }
-
-    private static String createFileDeclaration(final String type, final GeneratedType genType, final String indent,
-            final Map<String, String> availableImports, boolean isIdentity, boolean innerClass) {
-        final StringBuilder builder = new StringBuilder();
-        final String currentPkg = genType.getPackageName();
-
-        createComment(builder, genType.getComment(), indent);
-
-        if (!genType.getAnnotations().isEmpty()) {
-            final List<AnnotationType> annotations = genType.getAnnotations();
-            appendAnnotations(builder, annotations);
-            builder.append(NL);
-        }
-
-        if (innerClass) {
-            builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP + type + GAP + genType.getName() + GAP);
-        } else if (isIdentity) {
-            if (!(CLASS.equals(type))) {
-                throw new IllegalArgumentException("'identity' has to be generated as a class");
-            }
-            builder.append(indent + PUBLIC + GAP + ABSTRACT + GAP + type + GAP + genType.getName() + GAP);
-        } else {
-            builder.append(indent + PUBLIC + GAP + type + GAP + genType.getName() + GAP);
-        }
-
-        if (genType instanceof GeneratedTransferObject) {
-            GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
-
-            if (genTO.getExtends() != null) {
-                builder.append(EXTENDS + GAP);
-                String gtoString = getExplicitType(genTO.getExtends(), availableImports, currentPkg);
-                builder.append(gtoString + GAP);
-            }
-        }
-
-        final List<Type> genImplements = genType.getImplements();
-        if (!genImplements.isEmpty()) {
-            if (genType instanceof GeneratedTransferObject) {
-                builder.append(IMPLEMENTS + GAP);
-            } else {
-                builder.append(EXTENDS + GAP);
-            }
-            builder.append(getExplicitType(genImplements.get(0), availableImports, currentPkg));
-
-            for (int i = 1; i < genImplements.size(); ++i) {
-                builder.append(", ");
-                builder.append(getExplicitType(genImplements.get(i), availableImports, currentPkg));
-            }
-        }
-        builder.append(GAP + LCB);
-        return builder.toString();
-    }
-
-    private static StringBuilder appendAnnotations(final StringBuilder builder, final List<AnnotationType> annotations) {
-        if ((builder != null) && (annotations != null)) {
-            for (final AnnotationType annotation : annotations) {
-                builder.append("@");
-                builder.append(annotation.getPackageName());
-                builder.append(".");
-                builder.append(annotation.getName());
-
-                if (annotation.containsParameters()) {
-                    builder.append("(");
-                    final List<AnnotationType.Parameter> parameters = annotation.getParameters();
-                    appendAnnotationParams(builder, parameters);
-                    builder.append(")");
-                }
-            }
-        }
-        return builder;
-    }
-
-    private static StringBuilder appendAnnotationParams(final StringBuilder builder,
-            final List<AnnotationType.Parameter> parameters) {
-        if (parameters != null) {
-            int i = 0;
-            for (final AnnotationType.Parameter param : parameters) {
-                if (param == null) {
-                    continue;
-                }
-                if (i > 0) {
-                    builder.append(", ");
-                }
-                final String paramName = param.getName();
-                if (param.getValue() != null) {
-                    builder.append(paramName);
-                    builder.append(" = ");
-                    builder.append(param.getValue());
-                } else {
-                    builder.append(paramName);
-                    builder.append(" = {");
-                    final List<String> values = param.getValues();
-                    builder.append(values.get(0));
-                    for (int j = 1; j < values.size(); ++j) {
-                        builder.append(", ");
-                        builder.append(values.get(j));
-                    }
-                    builder.append("}");
-                }
-                i++;
-            }
-        }
-        return builder;
-    }
-
-    public static String createConstant(final Constant constant, final String indent,
-            final Map<String, String> availableImports, final String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-        if (constant == null)
-            throw new IllegalArgumentException();
-        builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP);
-        builder.append(getExplicitType(constant.getType(), availableImports, currentPkg) + GAP + constant.getName());
-        builder.append(GAP + "=" + GAP);
-
-        if (constant.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
-            return "";
-        } else {
-            builder.append(constant.getValue());
-        }
-        builder.append(SC);
-
-        return builder.toString();
-    }
-
-    public static String createField(final GeneratedProperty property, final String indent,
-            final Map<String, String> availableImports, final String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-        if (!property.getAnnotations().isEmpty()) {
-            final List<AnnotationType> annotations = property.getAnnotations();
-            appendAnnotations(builder, annotations);
-            builder.append(NL);
-        }
-        builder.append(indent + PRIVATE + GAP);
-        builder.append(getExplicitType(property.getReturnType(), availableImports, currentPkg) + GAP
-                + property.getName());
-        builder.append(SC);
-        return builder.toString();
-    }
-
-    /**
-     * Create method declaration in interface.
-     * 
-     * @param method
-     * @param indent
-     * @return
-     */
-    public static String createMethodDeclaration(final MethodSignature method, final String indent,
-            Map<String, String> availableImports, final String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-
-        if (method == null) {
-            throw new IllegalArgumentException("Method Signature parameter MUST be specified and cannot be NULL!");
-        }
-
-        final String comment = method.getComment();
-        final String name = method.getName();
-        if (name == null) {
-            throw new IllegalStateException("Method Name cannot be NULL!");
-        }
-
-        final Type type = method.getReturnType();
-        if (type == null) {
-            throw new IllegalStateException("Method Return type cannot be NULL!");
-        }
-
-        final List<Parameter> parameters = method.getParameters();
-
-        createComment(builder, comment, indent);
-        builder.append(NL);
-
-        if (!method.getAnnotations().isEmpty()) {
-            builder.append(indent);
-            final List<AnnotationType> annotations = method.getAnnotations();
-            appendAnnotations(builder, annotations);
-            builder.append(NL);
-        }
-
-        builder.append(indent + getExplicitType(type, availableImports, currentPkg) + GAP + name);
-        builder.append(LB);
-        for (int i = 0; i < parameters.size(); i++) {
-            Parameter p = parameters.get(i);
-            String separator = COMMA;
-            if (i + 1 == parameters.size()) {
-                separator = "";
-            }
-            builder.append(getExplicitType(p.getType(), availableImports, currentPkg) + GAP + p.getName() + separator);
-        }
-        builder.append(RB);
-        builder.append(SC);
-
-        return builder.toString();
-    }
-
-    public static String createConstructor(final GeneratedTransferObject genTransferObject, final String indent,
-            final Map<String, String> availableImports, final boolean isIdentity, final boolean oneConstructor) {
-        if (genTransferObject == null) {
-            throw new IllegalArgumentException("Generated transfer object can't be null");
-        }
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        if (availableImports == null) {
-            throw new IllegalArgumentException("Map of available imports can't be null");
-        }
-        GeneratedTransferObject genTOTopParent = getTopParrentTransportObject(genTransferObject);
-        final List<GeneratedProperty> ctorProperties = resolveReadOnlyPropertiesFromTO(genTransferObject
-                .getProperties());
-        final List<GeneratedProperty> ctorPropertiesAllParents = getPropertiesOfAllParents(genTransferObject
-                .getExtends());
-
-        final String currentPkg = genTransferObject.getPackageName();
-        final String className = genTransferObject.getName();
-
-        String constructorPart = "";
-        if (oneConstructor) {
-            if (genTOTopParent != genTransferObject && genTOTopParent.isUnionType()) {
-                constructorPart = createConstructorForEveryParentProperty(indent, isIdentity, ctorProperties,
-                        ctorPropertiesAllParents, availableImports, currentPkg, className);
-
-            } else {
-                constructorPart = createOneConstructor(indent, isIdentity, ctorProperties, ctorPropertiesAllParents,
-                        availableImports, currentPkg, className);
-            }
-
-        } else { // union won't be extended
-            constructorPart = createConstructorForEveryProperty(indent, isIdentity, ctorProperties,
-                    ctorPropertiesAllParents, availableImports, currentPkg, className);
-        }
-
-        return constructorPart;
-    }
-
-    private static String createOneConstructor(final String indent, boolean isIdentity,
-            final List<GeneratedProperty> properties, final List<GeneratedProperty> propertiesAllParents,
-            final Map<String, String> availableImports, final String currentPkg, final String className) {
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        if (properties == null) {
-            throw new IllegalArgumentException("List of generated properties can't be null");
-        }
-        if (propertiesAllParents == null) {
-            throw new IllegalArgumentException(
-                    "List of generated properties of all parent transport objects can't be null");
-        }
-        if (availableImports == null) {
-            throw new IllegalArgumentException("Map of available imports can't be null");
-        }
-        if (currentPkg == null) {
-            throw new IllegalArgumentException("String with current package can't be null");
-        }
-        if (className == null) {
-            throw new IllegalArgumentException("String with class name can't be null");
-        }
-
-        final StringBuilder builder = new StringBuilder();
-
-        List<GeneratedProperty> propertiesAll = new ArrayList<GeneratedProperty>(properties);
-        propertiesAll.addAll(propertiesAllParents);
-
-        builder.append(createConstructorDeclarationToLeftParenthesis(className, indent, isIdentity));
-        builder.append(createMethodPropertiesDeclaration(propertiesAll, availableImports, currentPkg, COMMA + GAP));
-        builder.append(createConstructorDeclarationFromRightParenthesis());
-        builder.append(createConstructorSuper(propertiesAllParents, indent));
-        builder.append(createClassPropertiesInitialization(propertiesAll, indent));
-        builder.append(createConstructorClosingPart(indent));
-        return builder.toString();
-    }
-
-    private static String createConstructorForEveryParentProperty(final String indent, final boolean isIdentity,
-            final List<GeneratedProperty> properties, final List<GeneratedProperty> propertiesAllParents,
-            final Map<String, String> availableImports, final String currentPkg, final String className) {
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        if (properties == null) {
-            throw new IllegalArgumentException("List of generated properties can't be null");
-        }
-        if (propertiesAllParents == null) {
-            throw new IllegalArgumentException(
-                    "List of generated properties of all parent transport objects can't be null");
-        }
-        if (availableImports == null) {
-            throw new IllegalArgumentException("Map of available imports can't be null");
-        }
-        if (currentPkg == null) {
-            throw new IllegalArgumentException("String with current package can't be null");
-        }
-        if (className == null) {
-            throw new IllegalArgumentException("String with class name can't be null");
-        }
-        final StringBuilder builder = new StringBuilder();
-        GeneratedProperty parentProperty;
-        Iterator<GeneratedProperty> parentPropertyIterator = propertiesAllParents.iterator();
-
-        do {
-            parentProperty = null;
-            if (parentPropertyIterator.hasNext()) {
-                parentProperty = parentPropertyIterator.next();
-            }
-
-            List<GeneratedProperty> propertiesAndParentProperties = new ArrayList<GeneratedProperty>();
-            if (parentProperty != null) {
-                propertiesAndParentProperties.add(parentProperty);
-            }
-            propertiesAndParentProperties.addAll(properties);
-
-            builder.append(createConstructorDeclarationToLeftParenthesis(className, indent, isIdentity));
-            builder.append(createMethodPropertiesDeclaration(propertiesAndParentProperties, availableImports,
-                    currentPkg, COMMA + GAP));
-            builder.append(createConstructorDeclarationFromRightParenthesis());
-            builder.append(createConstructorSuper(parentProperty, indent));
-            builder.append(createClassPropertiesInitialization(properties, indent));
-            builder.append(createConstructorClosingPart(indent));
-        } while (parentPropertyIterator.hasNext());
-
-        return builder.toString();
-    }
-
-    private static String createConstructorForEveryProperty(final String indent, final boolean isIdentity,
-            final List<GeneratedProperty> properties, final List<GeneratedProperty> propertiesAllParents,
-            final Map<String, String> availableImports, final String currentPkg, final String className) {
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        if (properties == null) {
-            throw new IllegalArgumentException("List of generated properties can't be null");
-        }
-        if (propertiesAllParents == null) {
-            throw new IllegalArgumentException(
-                    "List of generated properties of all parent transport objects can't be null");
-        }
-        if (availableImports == null) {
-            throw new IllegalArgumentException("Map of available imports can't be null");
-        }
-        if (currentPkg == null) {
-            throw new IllegalArgumentException("String with current package can't be null");
-        }
-        if (className == null) {
-            throw new IllegalArgumentException("String with class name can't be null");
-        }
-
-        final StringBuilder builder = new StringBuilder();
-
-        GeneratedProperty property;
-        Iterator<GeneratedProperty> propertyIterator = properties.iterator();
-
-        do {
-            property = null;
-            if (propertyIterator.hasNext()) {
-                property = propertyIterator.next();
-            }
-
-            List<GeneratedProperty> propertyAndTopParentProperties = new ArrayList<GeneratedProperty>();
-            if (property != null) {
-                propertyAndTopParentProperties.add(property);
-            }
-            propertyAndTopParentProperties.addAll(propertiesAllParents);
-
-            builder.append(createConstructorDeclarationToLeftParenthesis(className, indent, isIdentity));
-            builder.append(createMethodPropertiesDeclaration(propertyAndTopParentProperties, availableImports,
-                    currentPkg, COMMA + GAP));
-            builder.append(createConstructorDeclarationFromRightParenthesis());
-            builder.append(createConstructorSuper(propertiesAllParents, indent));
-            builder.append(createClassPropertyInitialization(property, indent));
-            builder.append(createConstructorClosingPart(indent));
-        } while (propertyIterator.hasNext());
-
-        return builder.toString();
-    }
-
-    /**
-     * The method selects from input list of properties only those which have
-     * read only attribute set to true.
-     * 
-     * @param properties
-     *            contains list of properties of generated transfer object
-     * @return subset of <code>properties</code> which have read only attribute
-     *         set to true
-     */
-    private static List<GeneratedProperty> resolveReadOnlyPropertiesFromTO(List<GeneratedProperty> properties) {
-        List<GeneratedProperty> readOnlyProperties = new ArrayList<GeneratedProperty>();
-        if (properties != null) {
-            for (final GeneratedProperty property : properties) {
-                if (property.isReadOnly()) {
-                    readOnlyProperties.add(property);
-                }
-            }
-        }
-        return readOnlyProperties;
-    }
-
-    private static String createMethodPropertiesDeclaration(final List<GeneratedProperty> parameters,
-            final Map<String, String> availableImports, final String currentPkg, final String parameterSeparator) {
-        StringBuilder builder = new StringBuilder();
-        if (parameters == null) {
-            throw new IllegalArgumentException("List of generated properties can't be null");
-        }
-        if (availableImports == null) {
-            throw new IllegalArgumentException("Map of available imports can't be null");
-        }
-        if (currentPkg == null) {
-            throw new IllegalArgumentException("String with current package can't be null");
-        }
-        if (parameterSeparator == null) {
-            throw new IllegalArgumentException("String with separator of parameters can't be null");
-        }
-
-        for (final GeneratedProperty parameter : parameters) {
-            builder.append(createMethodPropertyDeclaration(parameter, availableImports, currentPkg));
-            builder.append(parameterSeparator);
-        }
-        if (!parameters.isEmpty()) {
-            builder = builder.delete(builder.length() - parameterSeparator.length(), builder.length());
-        }
-        return builder.toString();
-    }
-
-    private static String createConstructorDeclarationToLeftParenthesis(final String className, final String indent,
-            final boolean isIdentity) {
-        if (className == null) {
-            throw new IllegalArgumentException("String with class name can't be null");
-        }
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        final StringBuilder builder = new StringBuilder();
-        builder.append(indent);
-        builder.append(isIdentity ? PROTECTED : PUBLIC);
-        builder.append(GAP);
-        builder.append(className);
-        builder.append(LB);
-        return builder.toString();
-    }
-
-    private static String createConstructorDeclarationFromRightParenthesis() {
-        final StringBuilder builder = new StringBuilder();
-        builder.append(RB + GAP + LCB + NL);
-        return builder.toString();
-    }
-
-    private static String createConstructorSuper(final List<GeneratedProperty> propertiesAllParents, final String indent) {
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        if (propertiesAllParents == null) {
-            throw new IllegalArgumentException("List of all parent's properties can't be null");
-        }
-        StringBuilder builder = new StringBuilder();
-        builder.append(indent + TAB + "super(");
-        String propertySeparator = COMMA + GAP;
-        for (GeneratedProperty superProperty : propertiesAllParents) {
-            builder.append(superProperty.getName());
-            builder.append(propertySeparator);
-        }
-        if (!propertiesAllParents.isEmpty()) {
-            builder = builder.delete(builder.length() - propertySeparator.length(), builder.length());
-        }
-
-        builder.append(");" + NL);
-        return builder.toString();
-    }
-
-    private static String createConstructorSuper(final GeneratedProperty parentProperty, final String indent) {
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        if (parentProperty == null) {
-            throw new IllegalArgumentException("Parent property can't be null");
-        }
-        StringBuilder builder = new StringBuilder();
-        if (parentProperty != null) {
-            builder.append(indent + TAB + "super(");
-            builder.append(parentProperty.getName());
-            builder.append(");" + NL);
-        }
-        return builder.toString();
-    }
-
-    private static String createConstructorClosingPart(final String indent) {
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        final StringBuilder builder = new StringBuilder();
-        builder.append(indent);
-        builder.append(RCB);
-        builder.append(NL + NL);
-        return builder.toString();
-    }
-
-    private static String createClassPropertiesInitialization(final List<GeneratedProperty> properties,
-            final String indent) {
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        if (properties == null) {
-            throw new IllegalArgumentException("List of generated class properties can't be null");
-        }
-        final StringBuilder builder = new StringBuilder();
-        for (final GeneratedProperty property : properties) {
-            createClassPropertyInitialization(property, indent);
-        }
-        return builder.toString();
-    }
-
-    private static String createClassPropertyInitialization(final GeneratedProperty property, final String indent) {
-        if (indent == null) {
-            throw new IllegalArgumentException("String with indent can't be null");
-        }
-        if (property == null) {
-            throw new IllegalArgumentException("List of generated class properties can't be null");
-        }
-        final StringBuilder builder = new StringBuilder();
-        builder.append(indent);
-        builder.append(TAB);
-        builder.append("this.");
-        builder.append(property.getName());
-        builder.append(" = ");
-        builder.append(property.getName());
-        builder.append(SC);
-        builder.append(NL);
-        return builder.toString();
-    }
-
-    private static String createMethodPropertyDeclaration(final GeneratedProperty property,
-            final Map<String, String> availableImports, final String currentPkg) {
-        if (property == null) {
-            throw new IllegalArgumentException("Generated property can't be null");
-        }
-        if (availableImports == null) {
-            throw new IllegalArgumentException("Map of available imports can't be null");
-        }
-        if (currentPkg == null) {
-            throw new IllegalArgumentException("String with current package can't be null");
-        }
-        final StringBuilder builder = new StringBuilder();
-        builder.append(getExplicitType(property.getReturnType(), availableImports, currentPkg));
-        builder.append(GAP);
-        builder.append(property.getName());
-        return builder.toString();
-    }
-
-    public static String createGetter(final GeneratedProperty property, final String indent,
-            final Map<String, String> availableImports, final String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-
-        final Type type = property.getReturnType();
-        final String varName = property.getName();
-        final char first = Character.toUpperCase(varName.charAt(0));
-        final String methodName = "get" + first + varName.substring(1);
-
-        builder.append(indent + PUBLIC + GAP + getExplicitType(type, availableImports, currentPkg) + GAP + methodName);
-        builder.append(LB + RB + LCB + NL);
-
-        String currentIndent = indent + TAB;
-
-        builder.append(currentIndent + "return " + varName + SC + NL);
-
-        builder.append(indent + RCB);
-        return builder.toString();
-    }
-
-    public static String createSetter(final GeneratedProperty property, final String indent,
-            final Map<String, String> availableImports, final String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-
-        final Type type = property.getReturnType();
-        final String varName = property.getName();
-        final char first = Character.toUpperCase(varName.charAt(0));
-        final String methodName = "set" + first + varName.substring(1);
-
-        builder.append(indent + PUBLIC + GAP + "void" + GAP + methodName);
-        builder.append(LB + getExplicitType(type, availableImports, currentPkg) + GAP + varName + RB + LCB + NL);
-        String currentIndent = indent + TAB;
-        builder.append(currentIndent + "this." + varName + " = " + varName + SC + NL);
-        builder.append(indent + RCB);
-        return builder.toString();
-    }
-
-    public static String createHashCode(final List<GeneratedProperty> properties, final String indent) {
-        StringBuilder builder = new StringBuilder();
-        builder.append(indent + "public int hashCode() {" + NL);
-        builder.append(indent + TAB + "final int prime = 31;" + NL);
-        builder.append(indent + TAB + "int result = 1;" + NL);
-
-        for (GeneratedProperty property : properties) {
-            String fieldName = property.getName();
-            builder.append(indent + TAB + "result = prime * result + ((" + fieldName + " == null) ? 0 : " + fieldName
-                    + ".hashCode());" + NL);
-        }
-
-        builder.append(indent + TAB + "return result;" + NL);
-        builder.append(indent + RCB + NL);
-        return builder.toString();
-    }
-
-    public static String createEquals(final GeneratedTransferObject type, final List<GeneratedProperty> properties,
-            final String indent) {
-        final StringBuilder builder = new StringBuilder();
-        final String indent1 = indent + TAB;
-        final String indent2 = indent1 + TAB;
-        final String indent3 = indent2 + TAB;
-
-        builder.append(indent + "public boolean equals(Object obj) {" + NL);
-        builder.append(indent1 + "if (this == obj) {" + NL);
-        builder.append(indent2 + "return true;" + NL);
-        builder.append(indent1 + "}" + NL);
-        builder.append(indent1 + "if (obj == null) {" + NL);
-        builder.append(indent2 + "return false;" + NL);
-        builder.append(indent1 + "}" + NL);
-        builder.append(indent1 + "if (getClass() != obj.getClass()) {" + NL);
-        builder.append(indent2 + "return false;" + NL);
-        builder.append(indent1 + "}" + NL);
-
-        String typeStr = type.getName();
-        builder.append(indent1 + typeStr + " other = (" + typeStr + ") obj;" + NL);
-
-        for (final GeneratedProperty property : properties) {
-            String fieldName = property.getName();
-            builder.append(indent1 + "if (" + fieldName + " == null) {" + NL);
-            builder.append(indent2 + "if (other." + fieldName + " != null) {" + NL);
-            builder.append(indent3 + "return false;" + NL);
-            builder.append(indent2 + "}" + NL);
-            builder.append(indent1 + "} else if (!" + fieldName + ".equals(other." + fieldName + ")) {" + NL);
-            builder.append(indent2 + "return false;" + NL);
-            builder.append(indent1 + "}" + NL);
-        }
-
-        builder.append(indent1 + "return true;" + NL);
-        builder.append(indent + RCB + NL);
-        return builder.toString();
-    }
-
-    public static String createToString(final GeneratedTransferObject type, final List<GeneratedProperty> properties,
-            final String indent) {
-        StringBuilder builder = new StringBuilder();
-        builder.append(indent);
-        builder.append("public String toString() {");
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(TAB);
-        builder.append("StringBuilder builder = new StringBuilder();");
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(TAB);
-        builder.append("builder.append(\"");
-        builder.append(type.getName());
-        builder.append(" [");
-
-        boolean first = true;
-        for (final GeneratedProperty property : properties) {
-            if (first) {
-                builder.append(property.getName());
-                builder.append("=\");");
-                builder.append(NL);
-                builder.append(indent);
-                builder.append(TAB);
-                builder.append("builder.append(");
-                builder.append(property.getName());
-                builder.append(");");
-                first = false;
-            } else {
-                builder.append(NL);
-                builder.append(indent);
-                builder.append(TAB);
-                builder.append("builder.append(\", ");
-                builder.append(property.getName());
-                builder.append("=\");");
-                builder.append(NL);
-                builder.append(indent);
-                builder.append(TAB);
-                builder.append("builder.append(");
-                builder.append(property.getName());
-                builder.append(");");
-            }
-        }
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(TAB);
-        builder.append("builder.append(\"]\");");
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(TAB);
-        builder.append("return builder.toString();");
-
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(RCB);
-        builder.append(NL);
-        return builder.toString();
-    }
-
-    public static String createEnum(final Enumeration enumeration, final String indent) {
-        if (enumeration == null || indent == null)
-            throw new IllegalArgumentException();
-        final StringBuilder builder = new StringBuilder(indent + PUBLIC + GAP + ENUM + GAP + enumeration.getName()
-                + GAP + LCB + NL);
-
-        String separator = COMMA + NL;
-        final List<Pair> values = enumeration.getValues();
-
-        for (int i = 0; i < values.size(); i++) {
-            if (i + 1 == values.size()) {
-                separator = SC;
-            }
-            builder.append(indent + TAB + values.get(i).getName() + LB + values.get(i).getValue() + RB + separator);
-        }
-        builder.append(NL);
-        builder.append(NL);
-        final String ENUMERATION_NAME = "value";
-        final String ENUMERATION_TYPE = "int";
-        builder.append(indent + TAB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME + SC);
-        builder.append(NL);
-        builder.append(indent + TAB + PRIVATE + GAP + enumeration.getName() + LB + ENUMERATION_TYPE + GAP
-                + ENUMERATION_NAME + RB + GAP + LCB + NL);
-        builder.append(indent + TAB + TAB + "this." + ENUMERATION_NAME + GAP + "=" + GAP + ENUMERATION_NAME + SC + NL);
-        builder.append(indent + TAB + RCB + NL);
-
-        builder.append(indent + RCB);
-        builder.append(NL);
-        return builder.toString();
-    }
-
-    private static String getExplicitType(final Type type, final Map<String, String> imports, final String currentPkg) {
-        if (type == null) {
-            throw new IllegalArgumentException("Type parameter MUST be specified and cannot be NULL!");
-        }
-        if (type.getName() == null) {
-            throw new IllegalArgumentException("Type name cannot be NULL!");
-        }
-        if (type.getPackageName() == null) {
-            throw new IllegalArgumentException("Type cannot have Package Name referenced as NULL!");
-        }
-        if (imports == null) {
-            throw new IllegalArgumentException("Imports Map cannot be NULL!");
-        }
-
-        final String typePackageName = type.getPackageName();
-        final String typeName = type.getName();
-        final String importedPackageName = imports.get(typeName);
-        if (typePackageName.equals(importedPackageName) || typePackageName.equals(currentPkg)) {
-            final StringBuilder builder = new StringBuilder(type.getName());
-            if (type instanceof ParameterizedType) {
-                final ParameterizedType pType = (ParameterizedType) type;
-                final Type[] pTypes = pType.getActualTypeArguments();
-                builder.append("<");
-                builder.append(getParameters(pTypes, imports, currentPkg));
-                builder.append(">");
-            }
-            if (builder.toString().equals("Void")) {
-                return "void";
-            }
-            return builder.toString();
-        } else {
-            final StringBuilder builder = new StringBuilder();
-            if (typePackageName.startsWith("java.lang")) {
-                builder.append(type.getName());
-            } else {
-                if (!typePackageName.isEmpty()) {
-                    builder.append(typePackageName + "." + type.getName());
-                } else {
-                    builder.append(type.getName());
-                }
-            }
-            if (type.equals(Types.voidType())) {
-                return "void";
-            }
-            if (type instanceof ParameterizedType) {
-                final ParameterizedType pType = (ParameterizedType) type;
-                final Type[] pTypes = pType.getActualTypeArguments();
-                builder.append("<");
-                builder.append(getParameters(pTypes, imports, currentPkg));
-                builder.append(">");
-            }
-            return builder.toString();
-        }
-    }
-
-    private static String getParameters(final Type[] pTypes, Map<String, String> availableImports, String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-        for (int i = 0; i < pTypes.length; i++) {
-            final Type t = pTypes[i];
-
-            String separator = COMMA;
-            if (i == (pTypes.length - 1)) {
-                separator = "";
-            }
-
-            String wildcardParam = "";
-            if (t.equals(Types.voidType())) {
-                builder.append("java.lang.Void" + separator);
-                continue;
-            } else {
-
-                if (t instanceof WildcardType) {
-                    wildcardParam = "? extends ";
-                }
-
-                builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg) + separator);
-            }
-        }
-        return builder.toString();
-    }
-
-    private static void createComment(final StringBuilder builder, final String comment, final String indent) {
-        if (comment != null && comment.length() > 0) {
-            builder.append(indent + "/*" + NL);
-            builder.append(indent + comment + NL);
-            builder.append(indent + "*/" + NL);
-        }
-    }
-
+    
     public static Map<String, String> createImports(GeneratedType genType) {
         if (genType == null) {
             throw new IllegalArgumentException("Generated Type cannot be NULL!");
         }
         final Map<String, String> imports = new LinkedHashMap<>();
+        imports.put(genType.getName(), genType.getPackageName());
         List<GeneratedType> childGeneratedTypes = genType.getEnclosedTypes();
         if (!childGeneratedTypes.isEmpty()) {
             for (GeneratedType genTypeChild : childGeneratedTypes) {
@@ -916,20 +97,8 @@ public final class GeneratorUtil {
 
         return imports;
     }
-
-    public static Map<String, String> createChildImports(GeneratedType genType) {
-        Map<String, String> childImports = new LinkedHashMap<>();
-        List<GeneratedType> childGeneratedTypes = genType.getEnclosedTypes();
-        if (!childGeneratedTypes.isEmpty()) {
-            for (GeneratedType genTypeChild : childGeneratedTypes) {
-                createChildImports(genTypeChild);
-                childImports.put(genTypeChild.getName(), genTypeChild.getPackageName());
-            }
-        }
-        return childImports;
-    }
-
-    private static void putTypeIntoImports(final GeneratedType parentGenType, final Type type,
+    
+    public static void putTypeIntoImports(final GeneratedType parentGenType, final Type type,
             final Map<String, String> imports) {
         if (parentGenType == null) {
             throw new IllegalArgumentException("Parent Generated Type parameter MUST be specified and cannot be "
@@ -970,26 +139,7 @@ public final class GeneratorUtil {
             }
         }
     }
-
-    public static List<String> createImportLines(final Map<String, String> imports,
-            final Map<String, String> innerTypeImports) {
-        final List<String> importLines = new ArrayList<>();
-
-        for (Map.Entry<String, String> entry : imports.entrySet()) {
-            final String typeName = entry.getKey();
-            final String packageName = entry.getValue();
-            if (innerTypeImports != null) {
-                String innerTypePackageName = innerTypeImports.get(typeName);
-                if (innerTypePackageName != null) {
-                    if (innerTypePackageName.equals(packageName))
-                        continue;
-                }
-            }
-            importLines.add("import " + packageName + "." + typeName + SC);
-        }
-        return importLines;
-    }
-
+    
     public static boolean isConstantInTO(String constName, GeneratedTransferObject genTO) {
         if (constName == null || genTO == null)
             throw new IllegalArgumentException();
@@ -1002,7 +152,100 @@ public final class GeneratorUtil {
         }
         return false;
     }
+    
+    public static Map<String, String> createChildImports(GeneratedType genType) {
+        Map<String, String> childImports = new LinkedHashMap<>();
+        List<GeneratedType> childGeneratedTypes = genType.getEnclosedTypes();
+        if (!childGeneratedTypes.isEmpty()) {
+            for (GeneratedType genTypeChild : childGeneratedTypes) {
+                createChildImports(genTypeChild);
+                childImports.put(genTypeChild.getName(), genTypeChild.getPackageName());
+            }
+        }
+        return childImports;
+    }
+
+    public static String getExplicitType(final GeneratedType parentGenType, final Type type, final Map<String, String> imports) {
+        if (type == null) {
+            throw new IllegalArgumentException("Type parameter MUST be specified and cannot be NULL!");
+        }
+        if (type.getName() == null) {
+            throw new IllegalArgumentException("Type name cannot be NULL!");
+        }
+        if (type.getPackageName() == null) {
+            throw new IllegalArgumentException("Type cannot have Package Name referenced as NULL!");
+        }
+        if (imports == null) {
+            throw new IllegalArgumentException("Imports Map cannot be NULL!");
+        }
+
+        final String typePackageName = type.getPackageName();
+        final String typeName = type.getName();
+        final String importedPackageName = imports.get(typeName);
+        if (typePackageName.equals(importedPackageName) || typePackageName.equals(parentGenType.getPackageName())) {
+            final StringBuilder builder = new StringBuilder(type.getName());
+            if (type instanceof ParameterizedType) {
+                final ParameterizedType pType = (ParameterizedType) type;
+                final Type[] pTypes = pType.getActualTypeArguments();
+                builder.append("<");
+                builder.append(getParameters(parentGenType, pTypes, imports));
+                builder.append(">");
+            }
+            if (builder.toString().equals("Void")) {
+                return "void";
+            }
+            return builder.toString();
+        } else {
+            final StringBuilder builder = new StringBuilder();
+            if (typePackageName.startsWith("java.lang")) {
+                builder.append(type.getName());
+            } else {
+                if (!typePackageName.isEmpty()) {
+                    builder.append(typePackageName + Constants.DOT + type.getName());
+                } else {
+                    builder.append(type.getName());
+                }
+            }
+            if (type.equals(Types.voidType())) {
+                return "void";
+            }
+            if (type instanceof ParameterizedType) {
+                final ParameterizedType pType = (ParameterizedType) type;
+                final Type[] pTypes = pType.getActualTypeArguments();
+                builder.append("<");
+                builder.append(getParameters(parentGenType, pTypes, imports));
+                builder.append(">");
+            }
+            return builder.toString();
+        }
+    }
+    
+    private static String getParameters(final GeneratedType parentGenType, final Type[] pTypes, Map<String, String> availableImports) {
+        final StringBuilder builder = new StringBuilder();
+        for (int i = 0; i < pTypes.length; i++) {
+            final Type t = pTypes[i];
+
+            String separator = COMMA;
+            if (i == (pTypes.length - 1)) {
+                separator = "";
+            }
+
+            String wildcardParam = "";
+            if (t.equals(Types.voidType())) {
+                builder.append("java.lang.Void" + separator);
+                continue;
+            } else {
+
+                if (t instanceof WildcardType) {
+                    wildcardParam = "? extends ";
+                }
 
+                builder.append(wildcardParam + getExplicitType(parentGenType, t, availableImports) + separator);
+            }
+        }
+        return builder.toString();
+    }
+    
     /**
      * The method returns reference to highest (top parent) Generated Transfer
      * Object.
@@ -1014,7 +257,7 @@ public final class GeneratorUtil {
      *         extended then <code>childTransportObject</code> is returned. In
      *         second case the method is recursive called until first case.
      */
-    private static GeneratedTransferObject getTopParrentTransportObject(GeneratedTransferObject childTransportObject) {
+    public static GeneratedTransferObject getTopParrentTransportObject(GeneratedTransferObject childTransportObject) {
         if (childTransportObject == null) {
             throw new IllegalArgumentException("Parameter childTransportObject can't be null.");
         }
@@ -1024,7 +267,28 @@ public final class GeneratorUtil {
             return getTopParrentTransportObject(childTransportObject.getExtends());
         }
     }
-
+    
+    /**
+     * The method selects from input list of properties only those which have
+     * read only attribute set to true.
+     * 
+     * @param properties
+     *            contains list of properties of generated transfer object
+     * @return subset of <code>properties</code> which have read only attribute
+     *         set to true
+     */
+    public static List<GeneratedProperty> resolveReadOnlyPropertiesFromTO(List<GeneratedProperty> properties) {
+        List<GeneratedProperty> readOnlyProperties = new ArrayList<GeneratedProperty>();
+        if (properties != null) {
+            for (final GeneratedProperty property : properties) {
+                if (property.isReadOnly()) {
+                    readOnlyProperties.add(property);
+                }
+            }
+        }
+        return readOnlyProperties;
+    }
+    
     /**
      * The method returns the list of the properties of all extending generated
      * transfer object from <code>genTO</code> to highest parent generated
@@ -1035,62 +299,15 @@ public final class GeneratorUtil {
      *         generated transfer object. In case when extension exists the
      *         method is recursive called.
      */
-    private static List<GeneratedProperty> getPropertiesOfAllParents(GeneratedTransferObject genTO) {
+    public static List<GeneratedProperty> getPropertiesOfAllParents(GeneratedTransferObject genTO) {
         List<GeneratedProperty> propertiesOfAllParents = new ArrayList<GeneratedProperty>();
-        if (genTO != null) {
-            final List<GeneratedProperty> allPropertiesOfTO = genTO.getProperties();
+        if (genTO.getExtends() != null) {
+            final List<GeneratedProperty> allPropertiesOfTO = genTO.getExtends().getProperties();
             List<GeneratedProperty> readOnlyPropertiesOfTO = resolveReadOnlyPropertiesFromTO(allPropertiesOfTO);
             propertiesOfAllParents.addAll(readOnlyPropertiesOfTO);
-            if (genTO.getExtends() != null) {
-                propertiesOfAllParents.addAll(getPropertiesOfAllParents(genTO.getExtends()));
-            }
+            propertiesOfAllParents.addAll(getPropertiesOfAllParents(genTO.getExtends()));
         }
         return propertiesOfAllParents;
     }
-
-    public static String createStaticInicializationBlock(GeneratedTransferObject genTransferObject, String indent) {
-
-        final StringBuilder builder = new StringBuilder();
-
-        List<Constant> constants = genTransferObject.getConstantDefinitions();
-        for (Constant constant : constants) {
-            if (constant.getName() == null || constant.getType() == null || constant.getValue() == null) {
-                continue;
-            }
-            if (constant.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
-                final Object constValue = constant.getValue();
-                List<String> regularExpressions = new ArrayList<>();
-                if (constValue instanceof List) {
-                    builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP + "List<String>" + GAP
-                            + TypeConstants.PATTERN_CONSTANT_NAME + GAP + "=" + GAP + "Arrays.asList" + LB);
-                    final List<?> constantValues = (List<?>) constValue;
-                    int stringsCount = 0;
-                    for (Object value : constantValues) {
-                        if (value instanceof String) {
-                            if (stringsCount > 0) {
-                                builder.append(COMMA);
-                            }
-                            stringsCount++;
-                            regularExpressions.add((String) value);
-                            builder.append(DOUBLE_QUOTE + (String) value + DOUBLE_QUOTE);
-                        }
-                    }
-                    builder.append(RB + SC + NL);
-                }
-                builder.append(indent + PRIVATE + GAP + STATIC + GAP + FINAL + GAP + "List<Pattern>" + GAP
-                        + MEMBER_PATTERN_LIST + GAP + ASSIGN + GAP + "new ArrayList<Pattern>()" + GAP + SC + NL + NL);
-
-                if (!regularExpressions.isEmpty()) {
-                    builder.append(indent + STATIC + LCB + NL);
-                    builder.append(indent + TAB + "for (String regEx : " + TypeConstants.PATTERN_CONSTANT_NAME + ") {"
-                            + NL);
-                    builder.append(indent + TAB + TAB + MEMBER_PATTERN_LIST + ".add(Pattern.compile(regEx))" + SC + NL);
-                    builder.append(indent + TAB + RCB + NL);
-                    builder.append(indent + RCB + NL + NL);
-                }
-
-            }
-        }
-        return builder.toString();
-    }
+    
 }
index 27570ca..381b157 100644 (file)
  */
 package org.opendaylight.controller.sal.java.api.generator;
 
-import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
-
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
-import java.util.List;
-import java.util.Map;
 
-import org.opendaylight.controller.sal.binding.model.api.*;
+import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
+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.Type;
 
 public final class InterfaceGenerator implements CodeGenerator {
 
-    private Map<String, String> imports;
-    private Map<String, String> innerTypeImports;
-
-    private String generateEnums(List<Enumeration> enums) {
-        String result = "";
-        if (enums != null) {
-            EnumGenerator enumGenerator = new EnumGenerator();
-            for (Enumeration en : enums) {
-                try {
-                    result = result + (enumGenerator.generateInnerEnumeration(en, TAB).toString() + NL);
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-        return result;
-    }
-
-    private String generateConstants(List<Constant> constants, String pkgName) {
-        String result = "";
-        if (constants != null) {
-            for (Constant c : constants) {
-                result = result + GeneratorUtil.createConstant(c, TAB, imports, pkgName) + NL;
-            }
-            result.concat(NL);
-        }
-        return result;
-    }
-
-    public String generateMethods(List<MethodSignature> methods, String pkgName) {
-        String result = "";
-
-        if (methods != null) {
-            for (MethodSignature m : methods) {
-                result = result + GeneratorUtil.createMethodDeclaration(m, TAB, imports, pkgName) + NL;
-            }
-            result = result + NL;
-        }
-        return result;
-    }
-
-    public String generateInnerClasses(final List<GeneratedType> generatedTypes) throws IOException {
-        String result = "";
-
-        if (generatedTypes != null) {
-            ClassCodeGenerator classCodeGenerator = new ClassCodeGenerator();
-            for (GeneratedType genType : generatedTypes) {
-                if (genType instanceof GeneratedTransferObject) {
-                    result = result + classCodeGenerator.generateOnlyClass(genType, imports).toString();
-                    result = result + NL + NL;
-                }
-            }
-        }
-
-        return result;
-    }
-
+    @Override
     public Writer generate(Type type) throws IOException {
-        Writer writer = new StringWriter();
+        final Writer writer = new StringWriter();
         if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
             final GeneratedType genType = (GeneratedType) type;
-            imports = GeneratorUtil.createImports(genType);
-            innerTypeImports = GeneratorUtil.createChildImports(genType);
-
-            final String currentPkg = genType.getPackageName();
-            final List<Constant> constants = genType.getConstantDefinitions();
-            final List<MethodSignature> methods = genType.getMethodDefinitions();
-            final List<Enumeration> enums = genType.getEnumerations();
-            final List<GeneratedType> enclosedGeneratedTypes = genType.getEnclosedTypes();
-
-            writer.write(GeneratorUtil.createPackageDeclaration(genType.getPackageName()));
-            writer.write(NL);
-
-            List<String> importLines = GeneratorUtil.createImportLines(imports, innerTypeImports);
-
-            for (String line : importLines) {
-                writer.write(line + NL);
-            }
-            writer.write(NL);
-            writer.write(GeneratorUtil.createIfcDeclaration(genType, "", imports));
-            writer.write(NL);
-
-            writer.write(generateInnerClasses(enclosedGeneratedTypes));
-            writer.write(generateEnums(enums));
-            writer.write(generateConstants(constants, currentPkg));
-            writer.write(generateMethods(methods, currentPkg));
-
-            writer.write(RCB);
+            final InterfaceTemplate interfaceTemplate = new InterfaceTemplate(genType);
+            writer.write(interfaceTemplate.generate().toString());
         }
         return writer;
     }
+    
 }
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/InterfaceTemplate.xtend b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/InterfaceTemplate.xtend
new file mode 100644 (file)
index 0000000..fb9d606
--- /dev/null
@@ -0,0 +1,153 @@
+package org.opendaylight.controller.sal.java.api.generator
+
+import java.util.List
+import java.util.Map
+import org.opendaylight.controller.binding.generator.util.TypeConstants
+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.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.Type
+import java.util.LinkedHashMap
+
+class InterfaceTemplate {
+    
+    val GeneratedType genType
+    val Map<String, String> imports
+    val List<Constant> consts
+    val List<MethodSignature> methods
+    val List<Enumeration> enums
+    val List<GeneratedType> enclosedGeneratedTypes
+    
+    new(GeneratedType genType) {
+        if (genType == null) {
+            throw new IllegalArgumentException("Generated type reference cannot be NULL!")
+        }
+        
+        this.genType = genType
+        imports = GeneratorUtil.createImports(genType)
+        consts = genType.constantDefinitions
+        methods = genType.methodDefinitions
+        enums = genType.enumerations
+        enclosedGeneratedTypes = genType.enclosedTypes
+    }
+    
+    def generate() {
+        val body = generateBody
+        val pkgAndImports = generatePkgAndImports
+        return pkgAndImports.toString + body.toString
+    }
+    
+    def private generateBody() '''
+        «genType.comment.generateComment»
+        «generateIfcDeclaration» {
+        
+            «generateInnerClasses»
+        
+            «generateEnums»
+        
+            «generateConstants»
+        
+            «generateMethods»
+        
+        }
+        
+    '''
+    
+    def private generateComment(String comment) '''
+        «IF comment != null && !comment.empty»
+            /*
+            «comment»
+            */
+        «ENDIF»
+    '''
+    
+    def private generateIfcDeclaration() '''
+        public interface «genType.name»«
+        IF (!genType.implements.empty)»«
+            " extends "»«
+            FOR type : genType.implements SEPARATOR ", "»«
+                type.resolveName»«
+            ENDFOR»«
+        ENDIF
+    »'''
+    
+    def private generateInnerClasses() '''
+        «IF !enclosedGeneratedTypes.empty»
+            «FOR innerClass : enclosedGeneratedTypes SEPARATOR "\n"»
+                «IF (innerClass instanceof GeneratedTransferObject)»
+                    «val classTemplate = new ClassTemplate(innerClass as GeneratedTransferObject)»
+                    «classTemplate.generateAsInnerClass»
+                «ENDIF»
+            «ENDFOR»
+        «ENDIF»
+    '''
+    
+    def private generateEnums() '''
+        «IF !enums.empty»
+            «FOR e : enums SEPARATOR "\n"»
+                «val enumTemplate = new EnumTemplate(e)»
+                «enumTemplate.generateAsInnerClass»
+            «ENDFOR»
+        «ENDIF»
+    '''
+    
+    def private generateConstants() '''
+        «IF !consts.empty»
+            «FOR c : consts»
+                «IF c.name != TypeConstants.PATTERN_CONSTANT_NAME»
+                    public static final «c.type.resolveName» «c.name» = «c.value»;
+                «ENDIF»
+            «ENDFOR»
+        «ENDIF»
+    '''
+    
+    def private generateMethods() '''
+        «IF !methods.empty»
+            «FOR m : methods SEPARATOR "\n"»
+                «m.comment.generateComment»
+                «m.returnType.resolveName» «m.name»(«m.parameters.generateParameters»);
+            «ENDFOR»
+        «ENDIF»
+    '''
+    
+    def private generateParameters(List<MethodSignature.Parameter> parameters) '''«
+        IF !parameters.empty»«
+            FOR parameter : parameters SEPARATOR ", "»«
+                parameter.type.resolveName» «parameter.name»«
+            ENDFOR»«
+        ENDIF
+    »'''
+    
+    def private generatePkgAndImports() '''
+        package «genType.packageName»;
+        
+        
+        «IF !imports.empty»
+            «FOR entry : resolveImports.entrySet»
+                import «entry.value».«entry.key»;
+            «ENDFOR»
+        «ENDIF»
+        
+    '''
+    
+    def private Map<String, String> resolveImports() {
+        val innerTypeImports = GeneratorUtil.createChildImports(genType)
+        val Map<String, String> resolvedImports = new LinkedHashMap
+        for (Map.Entry<String, String> entry : imports.entrySet() + innerTypeImports.entrySet) {
+            val typeName = entry.getKey();
+            val packageName = entry.getValue();
+            if (packageName != genType.packageName && packageName != genType.fullyQualifiedName) {
+                resolvedImports.put(typeName, packageName);
+            }
+        }
+        return resolvedImports
+    }
+    
+    def private resolveName(Type type) {
+        GeneratorUtil.putTypeIntoImports(genType, type, imports);
+        GeneratorUtil.getExplicitType(genType, type, imports)
+    }
+    
+}   
\ No newline at end of file
index 54856d1..3f41f1e 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
 import org.opendaylight.controller.sal.binding.model.api.Type;
 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.java.api.generator.ClassCodeGenerator;
+import org.opendaylight.controller.sal.java.api.generator.ClassGenerator;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
@@ -72,7 +72,7 @@ public class ClassCodeGeneratorTest {
                         }
                     }
 
-                    final ClassCodeGenerator clsGen = new ClassCodeGenerator();
+                    final ClassGenerator clsGen = new ClassGenerator();
                     try {
                         final Writer writer = clsGen.generate(genTO);
                         assertNotNull(writer);
@@ -119,7 +119,7 @@ public class ClassCodeGeneratorTest {
 
         final GeneratedTransferObject genTO = toBuilder.toInstance();
 
-        final ClassCodeGenerator clsGen = new ClassCodeGenerator();
+        final ClassGenerator clsGen = new ClassGenerator();
         try {
             final Writer writer = clsGen.generate(genTO);
             assertNotNull(writer);
@@ -150,7 +150,7 @@ public class ClassCodeGeneratorTest {
         propBuilder.setReadOnly(false);
         toBuilder.addToStringProperty(propBuilder);
         final GeneratedTransferObject genTO = toBuilder.toInstance();
-        final ClassCodeGenerator clsGen = new ClassCodeGenerator();
+        final ClassGenerator clsGen = new ClassGenerator();
         try {
             final Writer writer = clsGen.generate(genTO);
             assertNotNull(writer);