Commit ab6950d7 authored by kenton@google.com's avatar kenton@google.com

More Java warning tweaks from Evan Jones.

parent 28c2ec0d
...@@ -769,7 +769,7 @@ public abstract class GeneratedMessage extends AbstractMessage { ...@@ -769,7 +769,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
/** For use by generated code only. */ /** For use by generated code only. */
public void internalInit(final FieldDescriptor descriptor, public void internalInit(final FieldDescriptor descriptor,
final Class type) { final Class<?> type) {
if (this.descriptor != null) { if (this.descriptor != null) {
throw new IllegalStateException("Already initialized."); throw new IllegalStateException("Already initialized.");
} }
...@@ -809,7 +809,7 @@ public abstract class GeneratedMessage extends AbstractMessage { ...@@ -809,7 +809,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
} }
private FieldDescriptor descriptor; private FieldDescriptor descriptor;
private Class type; private Class<?> type;
private Method enumValueOf; private Method enumValueOf;
private Method enumGetValueDescriptor; private Method enumGetValueDescriptor;
private Message messageDefaultInstance; private Message messageDefaultInstance;
...@@ -1054,7 +1054,7 @@ public abstract class GeneratedMessage extends AbstractMessage { ...@@ -1054,7 +1054,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
// Note: We use Java reflection to call public methods rather than // Note: We use Java reflection to call public methods rather than
// access private fields directly as this avoids runtime security // access private fields directly as this avoids runtime security
// checks. // checks.
protected final Class type; protected final Class<?> type;
protected final Method getMethod; protected final Method getMethod;
protected final Method setMethod; protected final Method setMethod;
protected final Method hasMethod; protected final Method hasMethod;
...@@ -1118,7 +1118,7 @@ public abstract class GeneratedMessage extends AbstractMessage { ...@@ -1118,7 +1118,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
} }
protected final Class type; protected final Class<?> type;
protected final Method getMethod; protected final Method getMethod;
protected final Method getRepeatedMethod; protected final Method getRepeatedMethod;
protected final Method setRepeatedMethod; protected final Method setRepeatedMethod;
......
...@@ -524,6 +524,7 @@ public abstract class GeneratedMessageLite extends AbstractMessageLite { ...@@ -524,6 +524,7 @@ public abstract class GeneratedMessageLite extends AbstractMessageLite {
} }
/** For use by generated code only. */ /** For use by generated code only. */
@SuppressWarnings("unchecked")
public void internalInitRepeated( public void internalInitRepeated(
final ContainingType containingTypeDefaultInstance, final ContainingType containingTypeDefaultInstance,
final MessageLite messageDefaultInstance, final MessageLite messageDefaultInstance,
......
...@@ -70,6 +70,7 @@ public class DescriptorsTest extends TestCase { ...@@ -70,6 +70,7 @@ public class DescriptorsTest extends TestCase {
// Regression test for bug where referencing a FieldDescriptor.Type value // Regression test for bug where referencing a FieldDescriptor.Type value
// before a FieldDescriptorProto.Type value would yield a // before a FieldDescriptorProto.Type value would yield a
// ExceptionInInitializerError. // ExceptionInInitializerError.
@SuppressWarnings("unused")
private static final Object STATIC_INIT_TEST = FieldDescriptor.Type.BOOL; private static final Object STATIC_INIT_TEST = FieldDescriptor.Type.BOOL;
public void testFieldTypeEnumMapping() throws Exception { public void testFieldTypeEnumMapping() throws Exception {
......
...@@ -138,7 +138,7 @@ void EnumGenerator::Generate(io::Printer* printer) { ...@@ -138,7 +138,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
" internalValueMap =\n" " internalValueMap =\n"
" new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n" " new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n"
" public $classname$ findValueByNumber(int number) {\n" " public $classname$ findValueByNumber(int number) {\n"
" return $classname$.valueOf(number)\n;" " return $classname$.valueOf(number);\n"
" }\n" " }\n"
" };\n" " };\n"
"\n", "\n",
...@@ -190,6 +190,7 @@ void EnumGenerator::Generate(io::Printer* printer) { ...@@ -190,6 +190,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Print( printer->Print(
"\n" "\n"
"};\n" "};\n"
"\n"
"public static $classname$ valueOf(\n" "public static $classname$ valueOf(\n"
" com.google.protobuf.Descriptors.EnumValueDescriptor desc) {\n" " com.google.protobuf.Descriptors.EnumValueDescriptor desc) {\n"
" if (desc.getType() != getDescriptor()) {\n" " if (desc.getType() != getDescriptor()) {\n"
...@@ -197,20 +198,26 @@ void EnumGenerator::Generate(io::Printer* printer) { ...@@ -197,20 +198,26 @@ void EnumGenerator::Generate(io::Printer* printer) {
" \"EnumValueDescriptor is not for this type.\");\n" " \"EnumValueDescriptor is not for this type.\");\n"
" }\n" " }\n"
" return VALUES[desc.getIndex()];\n" " return VALUES[desc.getIndex()];\n"
"}\n", "}\n"
"\n",
"classname", descriptor_->name()); "classname", descriptor_->name());
// index is only used for reflection; lite implementation does not need it
printer->Print("private final int index;\n");
} }
// ----------------------------------------------------------------- // -----------------------------------------------------------------
printer->Print( printer->Print(
"private final int index;\n" "private final int value;\n\n"
"private final int value;\n" "private $classname$(int index, int value) {\n",
"private $classname$(int index, int value) {\n"
" this.index = index;\n"
" this.value = value;\n"
"}\n",
"classname", descriptor_->name()); "classname", descriptor_->name());
if (HasDescriptorMethods(descriptor_)) {
printer->Print(" this.index = index;\n");
}
printer->Print(
" this.value = value;\n"
"}\n");
if (HasDescriptorMethods(descriptor_)) { if (HasDescriptorMethods(descriptor_)) {
// Force the static initialization code for the file to run, since it may // Force the static initialization code for the file to run, since it may
......
...@@ -420,15 +420,18 @@ GenerateMessageSerializationMethods(io::Printer* printer) { ...@@ -420,15 +420,18 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
if (descriptor_->extension_range_count() > 0) { if (descriptor_->extension_range_count() > 0) {
if (descriptor_->options().message_set_wire_format()) { if (descriptor_->options().message_set_wire_format()) {
printer->Print( printer->Print(
"com.google.protobuf.GeneratedMessage$lite$.ExtendableMessage\n" "com.google.protobuf.GeneratedMessage$lite$\n"
" .ExtensionWriter extensionWriter =\n" " .ExtendableMessage<$classname$>.ExtensionWriter extensionWriter =\n"
" newMessageSetExtensionWriter();\n", " newMessageSetExtensionWriter();\n",
"lite", HasDescriptorMethods(descriptor_) ? "" : "Lite"); "lite", HasDescriptorMethods(descriptor_) ? "" : "Lite",
"classname", ClassName(descriptor_));
} else { } else {
printer->Print( printer->Print(
"com.google.protobuf.GeneratedMessage$lite$.ExtendableMessage\n" "com.google.protobuf.GeneratedMessage$lite$\n"
" .ExtensionWriter extensionWriter = newExtensionWriter();\n", " .ExtendableMessage<$classname$>.ExtensionWriter extensionWriter =\n"
"lite", HasDescriptorMethods(descriptor_) ? "" : "Lite"); " newExtensionWriter();\n",
"lite", HasDescriptorMethods(descriptor_) ? "" : "Lite",
"classname", ClassName(descriptor_));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment