avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r890997 - in /hadoop/avro/trunk: CHANGES.txt src/java/org/apache/avro/specific/SpecificCompiler.java src/test/java/org/apache/avro/specific/TestSpecificCompiler.java
Date Tue, 15 Dec 2009 21:23:38 GMT
Author: cutting
Date: Tue Dec 15 21:23:37 2009
New Revision: 890997

URL: http://svn.apache.org/viewvc?rev=890997&view=rev
Log:
AVRO-256. Use fully-qualified class names in generated Java code to eliminate name conflicts.

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

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=890997&r1=890996&r2=890997&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Dec 15 21:23:37 2009
@@ -193,6 +193,9 @@
 
     AVRO-184. Better eclipse configuration support. (thiru)
 
+    AVRO-256. Use fully-qualified class names in generated Java code
+    to eliminate 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=890997&r1=890996&r2=890997&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 Tue Dec 15 21:23:37
2009
@@ -179,7 +179,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 org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse(\""
            +esc(protocol)+"\");");
     for (Map.Entry<String,Message> e : protocol.getMessages().entrySet()) {
       String name = e.getKey();
@@ -187,7 +187,7 @@
       Schema request = message.getRequest();
       Schema response = message.getResponse();
       line(out, 1, unbox(response)+" "+ mangle(name)+"("+params(request)+")");
-      line(out, 2,"throws AvroRemoteException"+errors(message.getErrors())+";");
+      line(out, 2,"throws org.apache.avro.ipc.AvroRemoteException"+errors(message.getErrors())+";");
     }
     line(out, 0, "}");
 
@@ -208,26 +208,6 @@
     if(namespace != null) {
       line(out, 0, "package "+namespace+";\n");
     }
-    line(out, 0, "import java.nio.ByteBuffer;");
-    line(out, 0, "import java.util.Map;");
-    line(out, 0, "import org.apache.avro.Protocol;");
-    line(out, 0, "import org.apache.avro.Schema;");
-    line(out, 0, "import org.apache.avro.AvroRuntimeException;");
-    line(out, 0, "import org.apache.avro.Protocol;");
-    line(out, 0, "import org.apache.avro.util.Utf8;");
-    line(out, 0, "import org.apache.avro.ipc.AvroRemoteException;");
-    line(out, 0, "import org.apache.avro.generic.GenericArray;");
-    line(out, 0, "import org.apache.avro.specific.SpecificExceptionBase;");
-    line(out, 0, "import org.apache.avro.specific.SpecificRecordBase;");
-    line(out, 0, "import org.apache.avro.specific.SpecificRecord;");
-    line(out, 0, "import org.apache.avro.specific.SpecificFixed;");
-    line(out, 0, "import org.apache.avro.specific.FixedSize;");
-    for (Schema s : queue)
-      if (namespace == null
-          ? (s.getNamespace() != null)
-          : !namespace.equals(s.getNamespace()))
-        line(out, 0, "import "+SpecificData.get().getClassName(s)+";");
-    line(out, 0, "");
     line(out, 0, "@SuppressWarnings(\"all\")");
   }
 
@@ -249,56 +229,57 @@
     StringBuilder b = new StringBuilder();
     for (Schema error : errs.getTypes().subList(1, errs.getTypes().size())) {
       b.append(", ");
-      b.append(mangle(error.getName()));
+      b.append(mangle(error.getFullName()));
     }
     return b.toString();
   }
 
   private OutputFile compile(Schema schema) {
     OutputFile outputFile = new OutputFile();
-    outputFile.path = makePath(schema.getName(), schema.getNamespace());
+    String name = mangle(schema.getName());
+    outputFile.path = makePath(name, schema.getNamespace());
     StringBuilder out = new StringBuilder();
     header(out, schema.getNamespace());
     switch (schema.getType()) {
     case RECORD:
-      line(out, 0, "public class "+type(schema)+
+      line(out, 0, "public class "+name+
            (schema.isError()
-            ? " extends SpecificExceptionBase"
-             : " extends SpecificRecordBase")
-           +" implements SpecificRecord {");
+            ? " extends org.apache.avro.specific.SpecificExceptionBase"
+             : " extends org.apache.avro.specific.SpecificRecordBase")
+           +" implements org.apache.avro.specific.SpecificRecord {");
       // schema definition
-      line(out, 1, "public static final Schema SCHEMA$ = Schema.parse(\""
+      line(out, 1, "public static final org.apache.avro.Schema SCHEMA$ = org.apache.avro.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 org.apache.avro.Schema getSchema() { return SCHEMA$; }");
       // get method
-      line(out, 1, "public Object get(int field$) {");
+      line(out, 1, "public java.lang.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())+";");
-      line(out, 2, "default: throw new AvroRuntimeException(\"Bad index\");");
+      line(out, 2, "default: throw new org.apache.avro.AvroRuntimeException(\"Bad index\");");
       line(out, 2, "}");
       line(out, 1, "}");
       // set method
       line(out, 1, "@SuppressWarnings(value=\"unchecked\")");
-      line(out, 1, "public void set(int field$, Object value$) {");
+      line(out, 1, "public void set(int field$, java.lang.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;");
-      line(out, 2, "default: throw new AvroRuntimeException(\"Bad index\");");
+      line(out, 2, "default: throw new org.apache.avro.AvroRuntimeException(\"Bad index\");");
       line(out, 2, "}");
       line(out, 1, "}");
       line(out, 0, "}");
       break;
     case ENUM:
-      line(out, 0, "public enum "+type(schema)+" { ");
+      line(out, 0, "public enum "+name+" { ");
       StringBuilder b = new StringBuilder();
       int count = 0;
       for (String symbol : schema.getEnumSymbols()) {
@@ -310,8 +291,8 @@
       line(out, 0, "}");
       break;
     case FIXED:
-      line(out, 0, "@FixedSize("+schema.getFixedSize()+")");
-      line(out, 0, "public class "+type(schema)+" extends SpecificFixed {}");
+      line(out, 0, "@org.apache.avro.specific.FixedSize("+schema.getFixedSize()+")");
+      line(out, 0, "public class "+name+" extends org.apache.avro.specific.SpecificFixed
{}");
       break;
     case MAP: case ARRAY: case UNION: case STRING: case BYTES:
     case INT: case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case NULL:
@@ -330,24 +311,24 @@
     case RECORD:
     case ENUM:
     case FIXED:
-      return mangle(schema.getName());
+      return mangle(schema.getFullName());
     case ARRAY:
-      return "GenericArray<"+type(schema.getElementType())+">";
+      return "org.apache.avro.generic.GenericArray<"+type(schema.getElementType())+">";
     case MAP:
-      return "Map<Utf8,"+type(schema.getValueType())+">";
+      return "java.util.Map<org.apache.avro.util.Utf8,"+type(schema.getValueType())+">";
     case UNION:
       List<Schema> types = schema.getTypes();     // elide unions with null
       if ((types.size() == 2) && types.contains(NULL_SCHEMA))
         return type(types.get(types.get(0).equals(NULL_SCHEMA) ? 1 : 0));
-      return "Object";
-    case STRING:  return "Utf8";
-    case BYTES:   return "ByteBuffer";
-    case INT:     return "Integer";
-    case LONG:    return "Long";
-    case FLOAT:   return "Float";
-    case DOUBLE:  return "Double";
-    case BOOLEAN: return "Boolean";
-    case NULL:    return "Void";
+      return "java.lang.Object";
+    case STRING:  return "org.apache.avro.util.Utf8";
+    case BYTES:   return "java.nio.ByteBuffer";
+    case INT:     return "java.lang.Integer";
+    case LONG:    return "java.lang.Long";
+    case FLOAT:   return "java.lang.Float";
+    case DOUBLE:  return "java.lang.Double";
+    case BOOLEAN: return "java.lang.Boolean";
+    case NULL:    return "java.lang.Void";
     default: throw new RuntimeException("Unknown type: "+schema);
     }
   }

Modified: hadoop/avro/trunk/src/test/java/org/apache/avro/specific/TestSpecificCompiler.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/specific/TestSpecificCompiler.java?rev=890997&r1=890996&r2=890997&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/specific/TestSpecificCompiler.java (original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/specific/TestSpecificCompiler.java Tue
Dec 15 21:23:37 2009
@@ -94,12 +94,12 @@
     String errType = i.next().contents;
     String protocol = i.next().contents;
 
-    assertTrue(errType.contains("public class finally$ extends SpecificExceptionBase"));
+    assertTrue(errType.contains("public class finally$ extends org.apache.avro.specific.SpecificExceptionBase"));
     assertTrue(errType.contains("public boolean catch$;"));
 
-    assertTrue(protocol.contains("Utf8 goto$(Utf8 break$)"));
+    assertTrue(protocol.contains("org.apache.avro.util.Utf8 goto$(org.apache.avro.util.Utf8
break$)"));
     assertTrue(protocol.contains("public interface default$"));
-    assertTrue(protocol.contains("throws AvroRemoteException, finally$"));
+    assertTrue(protocol.contains("throws org.apache.avro.ipc.AvroRemoteException, finally$"));
 
   }
 
@@ -114,7 +114,7 @@
     assertEquals(1, c.size());
     String contents = c.iterator().next().contents;
 
-    assertTrue(contents.contains("public Utf8 package$;"));
+    assertTrue(contents.contains("public org.apache.avro.util.Utf8 package$;"));
     assertTrue(contents.contains("class volatile$ extends"));
     assertTrue(contents.contains("volatile$ short$;"));
   }



Mime
View raw message