Fixed bug in GeneratedPropertyBuilderImpl. 29/529/1
authorlsedlak <lsedlak@cisco.com>
Thu, 27 Jun 2013 14:26:15 +0000 (16:26 +0200)
committerlsedlak <lsedlak@cisco.com>
Thu, 27 Jun 2013 14:26:15 +0000 (16:26 +0200)
Default value for GeneratedProperty is set to true;
Added extends of AbstractBaseType for EnumerationBuilderImpl, AnnotationTypeBuilderImpl, AbstractGeneratedTypeBuilder and AbstractGeneratedType;

Signed-off-by: Lukas Sedlak <lsedlak@cisco.com>
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/BindingGeneratorUtil.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractGeneratedType.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/DataNodeIterator.java

index ef65a0e8f03add4a1653406c6069ed18e6c3f148..b37f91fe4474acd8e4d6c5fd8697c80dda753121 100644 (file)
@@ -1,5 +1,7 @@
 package org.opendaylight.controller.binding.generator.util;
 
+import java.util.*;
+
 import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
 import org.opendaylight.controller.yang.common.QName;
@@ -8,25 +10,19 @@ import org.opendaylight.controller.yang.model.api.SchemaNode;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 
-import java.util.*;
-
 public final class BindingGeneratorUtil {
 
-    private static final String[] SET_VALUES = new String[]{"abstract",
-            "assert", "boolean", "break", "byte", "case", "catch", "char",
-            "class", "const", "continue", "default", "double", "do", "else",
-            "enum", "extends", "false", "final", "finally", "float", "for",
-            "goto", "if", "implements", "import", "instanceof", "int",
-            "interface", "long", "native", "new", "null", "package", "private",
-            "protected", "public", "return", "short", "static", "strictfp",
-            "super", "switch", "synchronized", "this", "throw", "throws",
-            "transient", "true", "try", "void", "volatile", "while"};
+    private static final String[] SET_VALUES = new String[] { "abstract", "assert", "boolean", "break", "byte", "case",
+            "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends",
+            "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",
+            "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return",
+            "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient",
+            "true", "try", "void", "volatile", "while" };
 
     private BindingGeneratorUtil() {
     }
 
-    public static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(
-            Arrays.asList(SET_VALUES));
+    public static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(Arrays.asList(SET_VALUES));
 
     public static String validateJavaPackage(final String packageName) {
         if (packageName != null) {
@@ -57,16 +53,12 @@ public final class BindingGeneratorUtil {
         return parameterName;
     }
 
-    public static GeneratedTOBuilder schemaNodeToTransferObjectBuilder(
-            final String packageName, final SchemaNode schemaNode,
-            final String transObjectName) {
-        if (packageName != null && schemaNode != null
-                && transObjectName != null) {
+    public static GeneratedTOBuilder schemaNodeToTransferObjectBuilder(final String packageName,
+            final SchemaNode schemaNode, final String transObjectName) {
+        if (packageName != null && schemaNode != null && transObjectName != null) {
 
-            final String genTOName = BindingGeneratorUtil
-                    .parseToClassName(transObjectName);
-            final GeneratedTOBuilder newType = new GeneratedTOBuilderImpl(
-                    packageName, genTOName);
+            final String genTOName = BindingGeneratorUtil.parseToClassName(transObjectName);
+            final GeneratedTOBuilder newType = new GeneratedTOBuilderImpl(packageName, genTOName);
 
             return newType;
 
@@ -74,14 +66,12 @@ public final class BindingGeneratorUtil {
         return null;
     }
 
-    public static String moduleNamespaceToPackageName(
-            final Module module) {
+    public static String moduleNamespaceToPackageName(final Module module) {
         final StringBuilder packageNameBuilder = new StringBuilder();
 
         final Calendar calendar = Calendar.getInstance();
         if (module.getRevision() == null) {
-            throw new IllegalArgumentException("Module " + module.getName()
-                    + " does not specify revision date!");
+            throw new IllegalArgumentException("Module " + module.getName() + " does not specify revision date!");
         }
         packageNameBuilder.append("org.opendaylight.yang.gen.v");
         packageNameBuilder.append(module.getYangVersion());
@@ -112,11 +102,9 @@ public final class BindingGeneratorUtil {
         return validateJavaPackage(packageNameBuilder.toString());
     }
 
-    public static String packageNameForGeneratedType(
-            final String basePackageName, final SchemaPath schemaPath) {
+    public static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath) {
         if (basePackageName == null) {
-            throw new IllegalArgumentException("Base Package Name cannot be " +
-                    "NULL!");
+            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
         }
         if (schemaPath == null) {
             throw new IllegalArgumentException("Schema Path cannot be NULL!");
@@ -137,15 +125,13 @@ public final class BindingGeneratorUtil {
         return validateJavaPackage(builder.toString());
     }
 
-    public static String packageNameForTypeDefinition(
-            final String basePackageName, final TypeDefinition<?> typeDefinition) {
+    public static String packageNameForTypeDefinition(final String basePackageName,
+            final TypeDefinition<?> typeDefinition) {
         if (basePackageName == null) {
-            throw new IllegalArgumentException("Base Package Name cannot be " +
-                    "NULL!");
+            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
         }
         if (typeDefinition == null) {
-            throw new IllegalArgumentException("Type Definition reference " +
-                    "cannot be NULL!");
+            throw new IllegalArgumentException("Type Definition reference cannot be NULL!");
         }
 
         final StringBuilder builder = new StringBuilder();
@@ -199,11 +185,9 @@ public final class BindingGeneratorUtil {
             // check if 'toBeRemoved' character is not the only character in
             // 'text'
             if (sb.length() == 0) {
-                throw new IllegalArgumentException("Name can not be '"
-                        + toBeRemoved + "'");
+                throw new IllegalArgumentException("Name can not be '" + toBeRemoved + "'");
             }
-            String replacement = String.valueOf(sb.charAt(toBeRemovedPos))
-                    .toUpperCase();
+            String replacement = String.valueOf(sb.charAt(toBeRemovedPos)).toUpperCase();
             sb.setCharAt(toBeRemovedPos, replacement.charAt(0));
             toBeRemovedPos = sb.indexOf(toBeRemoved);
         }
index 5609f730644912ab5f807c2b36e4594c321b6bf4..8c7ee353442d7c2fb6ec221c08100bf3b26fb7c7 100644 (file)
@@ -43,7 +43,7 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
         this.comment = comment;
         this.annotations = toUnmodifiableAnnotations(annotationBuilders);
         this.implementsTypes = Collections.unmodifiableList(implementsTypes);
-        this.constants = toUnmodifiableConstants(constants);
+        this.constants = Collections.unmodifiableList(constants);
         this.enumerations = toUnmodifiableEnumerations(enumBuilders);
         this.methodSignatures = toUnmodifiableMethods(methodBuilders);
         this.enclosedTypes = toUnmodifiableEnclosedTypes(enclosedGenTypeBuilders, enclosedGenTOBuilders);
@@ -94,15 +94,6 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
         return Collections.unmodifiableList(enums);
     }
 
-    protected List<Constant> toUnmodifiableConstants(
-            List<Constant> constants) {
-        for (final Constant constant : constants) {
-            constants.add(new ConstantImpl(this, constant.getType(),
-                    constant.getName(), constant.getValue()));
-        }
-        return Collections.unmodifiableList(constants);
-    }
-
     @Override
     public Type getParentType() {
         return parent;
index 02c0060dff946f90dfba45824897e2c4757b26b0..5aeb2c5177ee7f869a7e6b7d07ddc457d05ac04d 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.binding.generator.util.generated.type.builder;
 
+import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
 import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
 import org.opendaylight.controller.sal.binding.model.api.Constant;
 import org.opendaylight.controller.sal.binding.model.api.Type;
@@ -15,7 +16,7 @@ import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
 import java.util.ArrayList;
 import java.util.List;
 
-abstract class AbstractGeneratedTypeBuilder implements GeneratedTypeBuilder {
+abstract class AbstractGeneratedTypeBuilder extends AbstractBaseType implements GeneratedTypeBuilder {
 
     private final String packageName;
     private String comment = "";
@@ -31,6 +32,7 @@ abstract class AbstractGeneratedTypeBuilder implements GeneratedTypeBuilder {
     private boolean isAbstract;
 
     public AbstractGeneratedTypeBuilder(final String packageName, final String name) {
+        super(packageName, name);
         if (packageName == null) {
             throw new IllegalArgumentException("Package Name for Generated Type cannot be null!");
         }
@@ -41,22 +43,6 @@ abstract class AbstractGeneratedTypeBuilder implements GeneratedTypeBuilder {
         this.name = name;
     }
 
-    @Override
-    public String getPackageName() {
-        return packageName;
-    }
-
-    @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
-    public String getFullyQualifiedName() {
-        return packageName + "." + name;
-    }
-
-
     protected String getComment() {
         return comment;
     }
index c125af556a14551eb9af51c3faa70b87460f55e5..3b49952483e886ddc5f79012d5a5bd0ba9341035 100644 (file)
@@ -11,10 +11,11 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
 
-final class AnnotationTypeBuilderImpl implements AnnotationTypeBuilder {
+final class AnnotationTypeBuilderImpl extends AbstractBaseType implements AnnotationTypeBuilder {
     
     private final String packageName;
     private final String name;
@@ -22,28 +23,13 @@ final class AnnotationTypeBuilderImpl implements AnnotationTypeBuilder {
     private final List<AnnotationType.Parameter> parameters;
     
     public AnnotationTypeBuilderImpl(final String packageName, final String name) {
-        super();
+        super(packageName, name);
         this.packageName = packageName;
         this.name = name;
         annotationBuilders = new ArrayList<>();
         parameters = new ArrayList<>();
     }
 
-    @Override
-    public String getPackageName() {
-        return packageName;
-    }
-
-    @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
-    public String getFullyQualifiedName() {
-        return packageName + "." + name;
-    }
-
     @Override
     public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
         if (packageName != null && name != null) {
index 8bf5b5d4cb587d13270773a4104e5a82965edca9..c45c76584bd6fc3d30931efd85db01386ae8898f 100644 (file)
@@ -11,39 +11,25 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
 import org.opendaylight.controller.sal.binding.model.api.Enumeration;
 import org.opendaylight.controller.sal.binding.model.api.Type;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder;
 
-public final class EnumerationBuilderImpl implements EnumBuilder {
+public final class EnumerationBuilderImpl extends AbstractBaseType implements EnumBuilder {
     private final String packageName;
     private final String name;
     private final List<Enumeration.Pair> values;
-    private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
+    private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<>();
     
     public EnumerationBuilderImpl(final String packageName, final String name) {
-        super();
+        super(packageName, name);
         this.packageName = packageName;
         this.name = name;
         values = new ArrayList<>();
     }
-    
-    @Override
-    public String getPackageName() {
-        return packageName;
-    }
-
-    @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
-    public String getFullyQualifiedName() {
-        return packageName + "." + name;
-    }
 
     @Override
     public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
index 7c26531f37efbddd520b31623539d011511719f7..d55f84923c4fd6dae5cf8bf58b08c18ba9f433f0 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.yang.model.util;
 
 import java.util.ArrayList;
@@ -5,41 +12,30 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.controller.yang.model.api.DataNodeContainer;
-import org.opendaylight.controller.yang.model.api.DataSchemaNode;
-import org.opendaylight.controller.yang.model.api.GroupingDefinition;
-import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
-import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.*;
 
 public class DataNodeIterator implements Iterator<DataSchemaNode> {
 
     private final DataNodeContainer container;
-    private List<ListSchemaNode> allLists;
-    private List<ContainerSchemaNode> allContainers;
-    private List<LeafSchemaNode> allLeafs;
-    private List<LeafListSchemaNode> allLeafLists;
-    private List<DataSchemaNode> allChilds;
+    private final List<ListSchemaNode> allLists;
+    private final List<ContainerSchemaNode> allContainers;
+    private final List<ChoiceNode> allChoices;
+    private final List<DataSchemaNode> allChilds;
 
     public DataNodeIterator(final DataNodeContainer container) {
         if (container == null) {
             throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");
         }
 
-        init();
+        this.allContainers = new ArrayList<>();
+        this.allLists = new ArrayList<>();
+        this.allChilds = new ArrayList<>();
+        this.allChoices = new ArrayList<>();
+
         this.container = container;
         traverse(this.container);
     }
 
-    private void init() {
-        this.allContainers = new ArrayList<ContainerSchemaNode>();
-        this.allLists = new ArrayList<ListSchemaNode>();
-        this.allLeafs = new ArrayList<LeafSchemaNode>();
-        this.allLeafLists = new ArrayList<LeafListSchemaNode>();
-        this.allChilds = new ArrayList<DataSchemaNode>();
-    }
-
     public List<ContainerSchemaNode> allContainers() {
         return allContainers;
     }
@@ -48,12 +44,8 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
         return allLists;
     }
 
-    public List<LeafSchemaNode> allLeafs() {
-        return allLeafs;
-    }
-
-    public List<LeafListSchemaNode> allLeafLists() {
-        return allLeafLists;
+    public List<ChoiceNode> allChoices() {
+        return allChoices;
     }
 
     private void traverse(final DataNodeContainer dataNode) {
@@ -61,9 +53,9 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
             return;
         }
 
-        final Set<DataSchemaNode> childs = dataNode.getChildNodes();
-        if (childs != null) {
-            for (DataSchemaNode childNode : childs) {
+        final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
+        if (childNodes != null) {
+            for (DataSchemaNode childNode : childNodes) {
                 if (childNode.isAugmenting()) {
                     continue;
                 }
@@ -76,19 +68,22 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
                     final ListSchemaNode list = (ListSchemaNode) childNode;
                     allLists.add(list);
                     traverse(list);
-                } else if (childNode instanceof LeafSchemaNode) {
-                    final LeafSchemaNode leaf = (LeafSchemaNode) childNode;
-                    allLeafs.add(leaf);
-                } else if (childNode instanceof LeafListSchemaNode) {
-                    final LeafListSchemaNode leafList = (LeafListSchemaNode) childNode;
-                    allLeafLists.add(leafList);
+                } else if (childNode instanceof ChoiceNode) {
+                    final ChoiceNode choiceNode = (ChoiceNode) childNode;
+                    allChoices.add(choiceNode);
+                    final Set<ChoiceCaseNode> cases = choiceNode.getCases();
+                    if (cases != null) {
+                        for (final ChoiceCaseNode caseNode : cases) {
+                            traverse(caseNode);
+                        }
+                    }
                 }
             }
         }
 
         final Set<GroupingDefinition> groupings = dataNode.getGroupings();
-        if(groupings != null) {
-            for(GroupingDefinition grouping : groupings) {
+        if (groupings != null) {
+            for (GroupingDefinition grouping : groupings) {
                 traverse(grouping);
             }
         }
@@ -97,10 +92,10 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
     @Override
     public boolean hasNext() {
         if (container.getChildNodes() != null) {
-            Set<DataSchemaNode> childs = container.getChildNodes();
+            final Set<DataSchemaNode> childNodes = container.getChildNodes();
 
-            if ((childs != null) && !childs.isEmpty()) {
-                return childs.iterator().hasNext();
+            if ((childNodes != null) && !childNodes.isEmpty()) {
+                return childNodes.iterator().hasNext();
             }
         }
         return false;