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 {
/** 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.");
}
......@@ -809,7 +809,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
}
private FieldDescriptor descriptor;
private Class type;
private Class<?> type;
private Method enumValueOf;
private Method enumGetValueDescriptor;
private Message messageDefaultInstance;
......@@ -1054,7 +1054,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
// 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;
......@@ -1118,7 +1118,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
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;
......
......@@ -524,6 +524,7 @@ public abstract class GeneratedMessageLite extends AbstractMessageLite {
}
/** For use by generated code only. */
@SuppressWarnings("unchecked")
public void internalInitRepeated(
final ContainingType containingTypeDefaultInstance,
final MessageLite messageDefaultInstance,
......
......@@ -70,6 +70,7 @@ public class DescriptorsTest extends TestCase {
// 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 {
......
......@@ -138,7 +138,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
" 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",
......@@ -190,6 +190,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Print(
"\n"
"};\n"
"\n"
"public static $classname$ valueOf(\n"
" com.google.protobuf.Descriptors.EnumValueDescriptor desc) {\n"
" if (desc.getType() != getDescriptor()) {\n"
......@@ -197,20 +198,26 @@ void EnumGenerator::Generate(io::Printer* printer) {
" \"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"
" this.value = value;\n"
"}\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");
if (HasDescriptorMethods(descriptor_)) {
// Force the static initialization code for the file to run, since it may
......
......@@ -420,15 +420,18 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
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_));
}
}
......
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