Fixed bug when getter for YANG leaf named class colided with getClass()
authorTony Tkacik <ttkacik@cisco.com>
Wed, 15 Jan 2014 10:55:29 +0000 (11:55 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 15 Jan 2014 12:36:15 +0000 (13:36 +0100)
  - Updated imports generation to explicitly import also files from same
    package.

Change-Id: Iadbdb2322b50e1b25c9be632960f6298bb654192
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/GeneratorUtil.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/BindingMapping.java

index e7791257d41dfcb8b57295cf058091655a98884e..10bca49c9e9493a9d34f401c13f2fa92c95e36f6 100644 (file)
@@ -1793,7 +1793,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         } else {
             method.append("get");
         }
-        method.append(BindingMapping.getClassName(localName));
+        method.append(BindingMapping.getPropertyName(localName).toFirstUpper);
         return method.toString();
     }
 
index da285e37bec39d80c12000d68d4821e367198ee2..a04dd7d0f50d2ff61fe29e46eb2e5f02da0841a2 100644 (file)
@@ -143,7 +143,7 @@ public final class GeneratorUtil {
         final String parentTypeName = parentGenType.getName();
         final String parentTypePackageName = parentGenType.getPackageName();
         if (typeName.equals(parentTypeName) || typePackageName.startsWith("java.lang")
-                || typePackageName.equals(parentTypePackageName) || typePackageName.isEmpty()) {
+                 || typePackageName.isEmpty()) {
             return;
         }
         if (!imports.containsKey(typeName)) {
@@ -252,7 +252,7 @@ public final class GeneratorUtil {
         final String typeName = type.getName();
         final String importedPackageName = imports.get(typeName);
         final StringBuilder builder;
-        if (typePackageName.equals(importedPackageName) || typePackageName.equals(parentGenType.getPackageName())) {
+        if (typePackageName.equals(importedPackageName)) {
             builder = new StringBuilder(type.getName());
             addActualTypeParameters(builder, type, parentGenType, imports);
             if (builder.toString().equals("Void")) {
index 00a36d98e8da0a5979cc401919f3debf297de6f6..a6bea0f3f9908ca233b52071d662d035c988c9be 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 
 import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableSet;
+
 import static com.google.common.base.Preconditions.*;
 
 public final class BindingMapping {
@@ -35,18 +36,32 @@ public final class BindingMapping {
 
     public static final String getMethodName(QName name) {
         checkArgument(name != null, "Name should not be null.");
-        return toFirstLower(toCamelCase(name.getLocalName()));
+        return getMethodName(name.getLocalName());
     }
 
     public static final String getClassName(String localName) {
+        checkArgument(localName != null, "Name should not be null.");
         return toFirstUpper(toCamelCase(localName));
     }
 
+    public static final String getMethodName(String yangIdentifier) {
+        checkArgument(yangIdentifier != null,"Identifier should not be null");
+        return toFirstLower(toCamelCase(yangIdentifier));
+    }
+
     public static final String getClassName(QName name) {
         checkArgument(name != null, "Name should not be null.");
         return toFirstUpper(toCamelCase(name.getLocalName()));
     }
 
+    public static String getPropertyName(String yangIdentifier) {
+        final String potential = toFirstLower(toCamelCase(yangIdentifier));
+        if("class".equals(potential)) {
+            return "xmlClass";
+        }
+        return potential;
+    }
+
     private static final String toCamelCase(String rawString) {
         checkArgument(rawString != null, "String should not be null");
         Iterable<String> components = SPACE_SPLITTER.split(rawString.replace('-', ' ').replace('_', ' '));