avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r882707 - in /hadoop/avro/trunk: CHANGES.txt src/java/org/apache/avro/specific/SpecificCompiler.java src/java/org/apache/avro/specific/SpecificData.java
Date Fri, 20 Nov 2009 20:54:42 GMT
Author: cutting
Date: Fri Nov 20 20:54:42 2009
New Revision: 882707

URL: http://svn.apache.org/viewvc?rev=882707&view=rev
Log:
AVRO-225.  In generated Java, use dollar-sign, not underscore, to prevent name conflicts.

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java
    hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificData.java

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=882707&r1=882706&r2=882707&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Fri Nov 20 20:54:42 2009
@@ -138,6 +138,9 @@
     AVRO-221. Mangle Java reserved words in generated code to avoid
     name conflicts.  (Philip Zeyliger via cutting)
 
+    AVRO-225. In generated Java, use dollar-sign, not underscore, to
+    prevent name conflicts. (cutting)
+
 Avro 1.2.0 (14 October 2009)
 
   INCOMPATIBLE CHANGES

Modified: hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java?rev=882707&r1=882706&r2=882707&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificCompiler.java Fri Nov 20 20:54:42
2009
@@ -42,9 +42,8 @@
   private final Set<Schema> queue = new HashSet<Schema>();
   private final Protocol protocol;
 
-  /** List of Java reserved words from
-   * <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html">Sun</a>.
-   */
+  /* List of Java reserved words from
+   * http://java.sun.com/docs/books/jls/third_edition/html/lexical.html. */
   private static final Set<String> RESERVED_WORDS = new HashSet<String>(
       Arrays.asList(new String[] {
           "abstract", "assert", "boolean", "break", "byte", "case", "catch",
@@ -178,7 +177,7 @@
     StringBuilder out = new StringBuilder();
     header(out, protocol.getNamespace());
     line(out, 0, "public interface "+mangle(protocol.getName())+" {");
-    line(out, 1, "public static final Protocol _PROTOCOL = Protocol.parse(\""
+    line(out, 1, "public static final Protocol PROTOCOL = Protocol.parse(\""
            +esc(protocol)+"\");");
     for (Map.Entry<String,Message> e : protocol.getMessages().entrySet()) {
       String name = e.getKey();
@@ -266,17 +265,17 @@
              : " extends SpecificRecordBase")
            +" implements SpecificRecord {");
       // schema definition
-      line(out, 1, "public static final Schema _SCHEMA = Schema.parse(\""
+      line(out, 1, "public static final Schema SCHEMA$ = Schema.parse(\""
            +esc(schema)+"\");");
       // field declations
       for (Map.Entry<String,Schema.Field> field: schema.getFields().entrySet())
         line(out, 1, "public " + unbox(field.getValue().schema()) + " "
              + mangle(field.getKey()) + ";");
       // schema method
-      line(out, 1, "public Schema getSchema() { return _SCHEMA; }");
+      line(out, 1, "public Schema getSchema() { return SCHEMA$; }");
       // get method
-      line(out, 1, "public Object get(int _field) {");
-      line(out, 2, "switch (_field) {");
+      line(out, 1, "public Object get(int field$) {");
+      line(out, 2, "switch (field$) {");
       int i = 0;
       for (Map.Entry<String, Schema> field : schema.getFieldSchemas())
         line(out, 2, "case "+(i++)+": return "+mangle(field.getKey())+";");
@@ -285,12 +284,12 @@
       line(out, 1, "}");
       // set method
       line(out, 1, "@SuppressWarnings(value=\"unchecked\")");
-      line(out, 1, "public void set(int _field, Object _value) {");
-      line(out, 2, "switch (_field) {");
+      line(out, 1, "public void set(int field$, Object value$) {");
+      line(out, 2, "switch (field$) {");
       i = 0;
       for (Map.Entry<String, Schema> field : schema.getFieldSchemas())
         line(out, 2, "case "+(i++)+": "+field.getKey()+" = ("+
-             type(field.getValue())+")_value; break;");
+             type(field.getValue())+")value$; break;");
       line(out, 2, "default: throw new AvroRuntimeException(\"Bad index\");");
       line(out, 2, "}");
       line(out, 1, "}");

Modified: hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificData.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificData.java?rev=882707&r1=882706&r2=882707&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificData.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificData.java Fri Nov 20 20:54:42
2009
@@ -188,7 +188,7 @@
   /** Create a schema for a Java class. */
   protected Schema createClassSchema(Class c, Map<String,Schema> names) {
     try {
-      return (Schema)(c.getDeclaredField("_SCHEMA").get(null));
+      return (Schema)(c.getDeclaredField("SCHEMA$").get(null));
     } catch (NoSuchFieldException e) {
       throw new AvroRuntimeException(e);
     } catch (IllegalAccessException e) {
@@ -199,7 +199,7 @@
   /** Return the protocol for a Java interface. */
   public Protocol getProtocol(Class iface) {
     try {
-      return (Protocol)(iface.getDeclaredField("_PROTOCOL").get(null));
+      return (Protocol)(iface.getDeclaredField("PROTOCOL").get(null));
     } catch (NoSuchFieldException e) {
       throw new AvroRuntimeException(e);
     } catch (IllegalAccessException e) {



Mime
View raw message