You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2009/07/29 22:55:04 UTC

svn commit: r799073 - in /xmlbeans/trunk/src: common/org/apache/xmlbeans/impl/common/NameUtil.java typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java

Author: cezar
Date: Wed Jul 29 20:55:04 2009
New Revision: 799073

URL: http://svn.apache.org/viewvc?rev=799073&view=rev
Log:
Fix src generator to avoid vars that colide with used package names.


Modified:
    xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/NameUtil.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java

Modified: xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/NameUtil.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/NameUtil.java?rev=799073&r1=799072&r2=799073&view=diff
==============================================================================
--- xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/NameUtil.java (original)
+++ xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/NameUtil.java Wed Jul 29 20:55:04 2009
@@ -93,6 +93,16 @@
         }
     ));
 
+    private final static Set extraWords = new HashSet(Arrays.asList(
+        new String[]
+        {
+              "i",          // used for indexes
+              "target",     // used for parameter
+              "org",        // used for package names
+              "com",        // used for package names
+        }
+    ));
+
     /*
     private final static Set javaNames = new HashSet(Arrays.asList(
         new String[]
@@ -756,6 +766,18 @@
     }
 
     /**
+     * Intended to be applied to a lowercase-starting identifier that
+     * may collide with a Java keyword.  If it does collide, this
+     * prepends the letter "x".
+     */
+    public static String nonExtraKeyword(String word)
+    {
+        if (isExtraReservedWord(word, true))
+            return word + "Value";
+        return word;
+    }
+
+    /**
      * Intended to be applied to an uppercase-starting identifier that
      * may collide with a java.lang.* classname.  If it does collide, this
      * prepends the letter "X".
@@ -779,6 +801,13 @@
         return javaWords.contains(word);
     }
 
+    private static boolean isExtraReservedWord(String word, boolean ignore_case)
+    {
+        if (ignore_case)
+            word = word.toLowerCase();
+        return extraWords.contains(word);
+    }
+
     public static boolean isJavaCommonClassName(String word)
     {
         return javaNames.contains(word);

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java?rev=799073&r1=799072&r2=799073&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java Wed Jul 29 20:55:04 2009
@@ -2299,10 +2299,7 @@
         throws IOException
     {
         String safeVarName = NameUtil.nonJavaKeyword(NameUtil.lowerCamelCase(propertyName));
-        if (safeVarName.equals("i"))
-            safeVarName = "iValue";
-        else if (safeVarName.equals("target"))
-            safeVarName = "targetValue";
+        safeVarName = NameUtil.nonExtraKeyword(safeVarName);
 
         boolean xmltype = (javaType == SchemaProperty.XML_OBJECT);
         boolean isobj = (javaType == SchemaProperty.JAVA_OBJECT);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org