Commits

Anonymous committed 837e77e

More Java warning tweaks from Evan Jones.

  • Participants
  • Parent commits 35a4005

Comments (0)

Files changed (5)

File java/src/main/java/com/google/protobuf/GeneratedMessage.java

 
     /** For use by generated code only. */
     public void internalInit(final FieldDescriptor descriptor,
-                             final Class type) {
+                             final Class<?> type) {
       if (this.descriptor != null) {
         throw new IllegalStateException("Already initialized.");
       }
     }
 
     private FieldDescriptor descriptor;
-    private Class type;
+    private Class<?> type;
     private Method enumValueOf;
     private Method enumGetValueDescriptor;
     private Message messageDefaultInstance;
       // Note:  We use Java reflection to call public methods rather than
       //   access private fields directly as this avoids runtime security
       //   checks.
-      protected final Class type;
+      protected final Class<?> type;
       protected final Method getMethod;
       protected final Method setMethod;
       protected final Method hasMethod;
         clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
       }
 
-      protected final Class type;
+      protected final Class<?> type;
       protected final Method getMethod;
       protected final Method getRepeatedMethod;
       protected final Method setRepeatedMethod;

File java/src/main/java/com/google/protobuf/GeneratedMessageLite.java

     }
 
     /** For use by generated code only. */
+    @SuppressWarnings("unchecked")
     public void internalInitRepeated(
         final ContainingType containingTypeDefaultInstance,
         final MessageLite messageDefaultInstance,

File java/src/test/java/com/google/protobuf/DescriptorsTest.java

   // Regression test for bug where referencing a FieldDescriptor.Type value
   // before a FieldDescriptorProto.Type value would yield a
   // ExceptionInInitializerError.
+  @SuppressWarnings("unused")
   private static final Object STATIC_INIT_TEST = FieldDescriptor.Type.BOOL;
 
   public void testFieldTypeEnumMapping() throws Exception {

File src/google/protobuf/compiler/java/java_enum.cc

     "    internalValueMap =\n"
     "      new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n"
     "        public $classname$ findValueByNumber(int number) {\n"
-    "          return $classname$.valueOf(number)\n;"
+    "          return $classname$.valueOf(number);\n"
     "        }\n"
     "      };\n"
     "\n",
     printer->Print(
       "\n"
       "};\n"
+      "\n"
       "public static $classname$ valueOf(\n"
       "    com.google.protobuf.Descriptors.EnumValueDescriptor desc) {\n"
       "  if (desc.getType() != getDescriptor()) {\n"
       "      \"EnumValueDescriptor is not for this type.\");\n"
       "  }\n"
       "  return VALUES[desc.getIndex()];\n"
-      "}\n",
+      "}\n"
+      "\n",
       "classname", descriptor_->name());
+
+    // index is only used for reflection; lite implementation does not need it
+    printer->Print("private final int index;\n");
   }
 
   // -----------------------------------------------------------------
 
   printer->Print(
-    "private final int index;\n"
-    "private final int value;\n"
-    "private $classname$(int index, int value) {\n"
-    "  this.index = index;\n"
+    "private final int value;\n\n"
+    "private $classname$(int index, int value) {\n",
+    "classname", descriptor_->name());
+  if (HasDescriptorMethods(descriptor_)) {
+    printer->Print("  this.index = index;\n");
+  }
+  printer->Print(
     "  this.value = value;\n"
-    "}\n",
-    "classname", descriptor_->name());
+    "}\n");
 
   if (HasDescriptorMethods(descriptor_)) {
     // Force the static initialization code for the file to run, since it may

File src/google/protobuf/compiler/java/java_message.cc

   if (descriptor_->extension_range_count() > 0) {
     if (descriptor_->options().message_set_wire_format()) {
       printer->Print(
-        "com.google.protobuf.GeneratedMessage$lite$.ExtendableMessage\n"
-        "  .ExtensionWriter extensionWriter =\n"
+        "com.google.protobuf.GeneratedMessage$lite$\n"
+        "  .ExtendableMessage<$classname$>.ExtensionWriter extensionWriter =\n"
         "    newMessageSetExtensionWriter();\n",
-        "lite", HasDescriptorMethods(descriptor_) ? "" : "Lite");
+        "lite", HasDescriptorMethods(descriptor_) ? "" : "Lite",
+        "classname", ClassName(descriptor_));
     } else {
       printer->Print(
-        "com.google.protobuf.GeneratedMessage$lite$.ExtendableMessage\n"
-        "  .ExtensionWriter extensionWriter = newExtensionWriter();\n",
-        "lite", HasDescriptorMethods(descriptor_) ? "" : "Lite");
+        "com.google.protobuf.GeneratedMessage$lite$\n"
+        "  .ExtendableMessage<$classname$>.ExtensionWriter extensionWriter =\n"
+        "    newExtensionWriter();\n",
+        "lite", HasDescriptorMethods(descriptor_) ? "" : "Lite",
+        "classname", ClassName(descriptor_));
     }
   }