Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
86fdad0f
Commit
86fdad0f
authored
Jan 27, 2018
by
David Ostrovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Java: Generate warning free code
Partially fixes #4230.
parent
c236896e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
java_message.cc
src/google/protobuf/compiler/java/java_message.cc
+9
-0
java_message_builder.cc
src/google/protobuf/compiler/java/java_message_builder.cc
+21
-0
No files found.
src/google/protobuf/compiler/java/java_message.cc
View file @
86fdad0f
...
...
@@ -554,6 +554,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
GenerateParser
(
printer
);
printer
->
Print
(
"@java.lang.Override
\n
"
"public $classname$ getDefaultInstanceForType() {
\n
"
" return DEFAULT_INSTANCE;
\n
"
"}
\n
"
...
...
@@ -587,6 +588,7 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
std
::
sort
(
sorted_extensions
.
begin
(),
sorted_extensions
.
end
(),
ExtensionRangeOrdering
());
printer
->
Print
(
"@java.lang.Override
\n
"
"public void writeTo(com.google.protobuf.CodedOutputStream output)
\n
"
" throws java.io.IOException {
\n
"
);
printer
->
Indent
();
...
...
@@ -647,6 +649,7 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
printer
->
Print
(
"}
\n
"
"
\n
"
"@java.lang.Override
\n
"
"public int getSerializedSize() {
\n
"
" int size = memoizedSize;
\n
"
" if (size != -1) return size;
\n
"
...
...
@@ -788,6 +791,7 @@ void ImmutableMessageGenerator::GenerateSerializeOneExtensionRange(
void
ImmutableMessageGenerator
::
GenerateBuilder
(
io
::
Printer
*
printer
)
{
// LITE_RUNTIME implements this at the GeneratedMessageLite level.
printer
->
Print
(
"@java.lang.Override
\n
"
"public Builder newBuilderForType() { return newBuilder(); }
\n
"
);
printer
->
Print
(
...
...
@@ -797,6 +801,7 @@ void ImmutableMessageGenerator::GenerateBuilder(io::Printer* printer) {
"public static Builder newBuilder($classname$ prototype) {
\n
"
" return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
\n
"
"}
\n
"
"@java.lang.Override
\n
"
"public Builder toBuilder() {
\n
"
" return this == DEFAULT_INSTANCE
\n
"
" ? new Builder() : new Builder().mergeFrom(this);
\n
"
...
...
@@ -840,6 +845,7 @@ GenerateDescriptorMethods(io::Printer* printer) {
if
(
!
map_fields
.
empty
())
{
printer
->
Print
(
"@SuppressWarnings({
\"
rawtypes
\"
})
\n
"
"@java.lang.Override
\n
"
"protected com.google.protobuf.MapField internalGetMapField(
\n
"
" int number) {
\n
"
" switch (number) {
\n
"
);
...
...
@@ -865,6 +871,7 @@ GenerateDescriptorMethods(io::Printer* printer) {
"}
\n
"
);
}
printer
->
Print
(
"@java.lang.Override
\n
"
"protected com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable
\n
"
" internalGetFieldAccessorTable() {
\n
"
" return $fileclass$.internal_$identifier$_fieldAccessorTable
\n
"
...
...
@@ -888,6 +895,7 @@ void ImmutableMessageGenerator::GenerateIsInitialized(
printer
->
Print
(
"private byte memoizedIsInitialized = -1;
\n
"
);
printer
->
Print
(
"@java.lang.Override
\n
"
"public final boolean isInitialized() {
\n
"
);
printer
->
Indent
();
...
...
@@ -1357,6 +1365,7 @@ void ImmutableMessageGenerator::GenerateParser(io::Printer* printer) {
"classname"
,
descriptor_
->
name
());
printer
->
Indent
();
printer
->
Print
(
"@java.lang.Override
\n
"
"public $classname$ parsePartialFrom(
\n
"
" com.google.protobuf.CodedInputStream input,
\n
"
" com.google.protobuf.ExtensionRegistryLite extensionRegistry)
\n
"
...
...
src/google/protobuf/compiler/java/java_message_builder.cc
View file @
86fdad0f
...
...
@@ -180,11 +180,13 @@ Generate(io::Printer* printer) {
// to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
// we changed all generated code to subclass GeneratedMessageV3).
printer
->
Print
(
"@java.lang.Override
\n
"
"public final Builder setUnknownFields(
\n
"
" final com.google.protobuf.UnknownFieldSet unknownFields) {
\n
"
" return super.setUnknownFields$suffix$(unknownFields);
\n
"
"}
\n
"
"
\n
"
"@java.lang.Override
\n
"
"public final Builder mergeUnknownFields(
\n
"
" final com.google.protobuf.UnknownFieldSet unknownFields) {
\n
"
" return super.mergeUnknownFields(unknownFields);
\n
"
...
...
@@ -277,6 +279,7 @@ GenerateDescriptorMethods(io::Printer* printer) {
"}
\n
"
);
}
printer
->
Print
(
"@java.lang.Override
\n
"
"protected com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable
\n
"
" internalGetFieldAccessorTable() {
\n
"
" return $fileclass$.internal_$identifier$_fieldAccessorTable
\n
"
...
...
@@ -333,6 +336,7 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
"}
\n
"
);
printer
->
Print
(
"@java.lang.Override
\n
"
"public Builder clear() {
\n
"
" super.clear();
\n
"
);
...
...
@@ -361,6 +365,7 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
"
\n
"
);
printer
->
Print
(
"@java.lang.Override
\n
"
"public com.google.protobuf.Descriptors.Descriptor
\n
"
" getDescriptorForType() {
\n
"
" return $fileclass$.internal_$identifier$_descriptor;
\n
"
...
...
@@ -371,6 +376,7 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
// LITE runtime implements this in GeneratedMessageLite.
printer
->
Print
(
"@java.lang.Override
\n
"
"public $classname$ getDefaultInstanceForType() {
\n
"
" return $classname$.getDefaultInstance();
\n
"
"}
\n
"
...
...
@@ -378,6 +384,7 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
"classname"
,
name_resolver_
->
GetImmutableClassName
(
descriptor_
));
printer
->
Print
(
"@java.lang.Override
\n
"
"public $classname$ build() {
\n
"
" $classname$ result = buildPartial();
\n
"
" if (!result.isInitialized()) {
\n
"
...
...
@@ -389,6 +396,7 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
"classname"
,
name_resolver_
->
GetImmutableClassName
(
descriptor_
));
printer
->
Print
(
"@java.lang.Override
\n
"
"public $classname$ buildPartial() {
\n
"
" $classname$ result = new $classname$(this);
\n
"
,
"classname"
,
name_resolver_
->
GetImmutableClassName
(
descriptor_
));
...
...
@@ -457,27 +465,33 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
// to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
// we changed all generated code to subclass GeneratedMessageV3).
printer
->
Print
(
"@java.lang.Override
\n
"
"public Builder clone() {
\n
"
" return (Builder) super.clone();
\n
"
"}
\n
"
"@java.lang.Override
\n
"
"public Builder setField(
\n
"
" com.google.protobuf.Descriptors.FieldDescriptor field,
\n
"
" java.lang.Object value) {
\n
"
" return (Builder) super.setField(field, value);
\n
"
"}
\n
"
"@java.lang.Override
\n
"
"public Builder clearField(
\n
"
" com.google.protobuf.Descriptors.FieldDescriptor field) {
\n
"
" return (Builder) super.clearField(field);
\n
"
"}
\n
"
"@java.lang.Override
\n
"
"public Builder clearOneof(
\n
"
" com.google.protobuf.Descriptors.OneofDescriptor oneof) {
\n
"
" return (Builder) super.clearOneof(oneof);
\n
"
"}
\n
"
"@java.lang.Override
\n
"
"public Builder setRepeatedField(
\n
"
" com.google.protobuf.Descriptors.FieldDescriptor field,
\n
"
" int index, java.lang.Object value) {
\n
"
" return (Builder) super.setRepeatedField(field, index, value);
\n
"
"}
\n
"
"@java.lang.Override
\n
"
"public Builder addRepeatedField(
\n
"
" com.google.protobuf.Descriptors.FieldDescriptor field,
\n
"
" java.lang.Object value) {
\n
"
...
...
@@ -486,24 +500,28 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
if
(
descriptor_
->
extension_range_count
()
>
0
)
{
printer
->
Print
(
"@java.lang.Override
\n
"
"public <Type> Builder setExtension(
\n
"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<
\n
"
" $classname$, Type> extension,
\n
"
" Type value) {
\n
"
" return (Builder) super.setExtension(extension, value);
\n
"
"}
\n
"
"@java.lang.Override
\n
"
"public <Type> Builder setExtension(
\n
"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<
\n
"
" $classname$, java.util.List<Type>> extension,
\n
"
" int index, Type value) {
\n
"
" return (Builder) super.setExtension(extension, index, value);
\n
"
"}
\n
"
"@java.lang.Override
\n
"
"public <Type> Builder addExtension(
\n
"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<
\n
"
" $classname$, java.util.List<Type>> extension,
\n
"
" Type value) {
\n
"
" return (Builder) super.addExtension(extension, value);
\n
"
"}
\n
"
"@java.lang.Override
\n
"
"public <Type> Builder clearExtension(
\n
"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<
\n
"
" $classname$, ?> extension) {
\n
"
...
...
@@ -516,6 +534,7 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
if
(
context_
->
HasGeneratedMethods
(
descriptor_
))
{
printer
->
Print
(
"@java.lang.Override
\n
"
"public Builder mergeFrom(com.google.protobuf.Message other) {
\n
"
" if (other instanceof $classname$) {
\n
"
" return mergeFrom(($classname$)other);
\n
"
...
...
@@ -602,6 +621,7 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
void
MessageBuilderGenerator
::
GenerateBuilderParsingMethods
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
"@java.lang.Override
\n
"
"public Builder mergeFrom(
\n
"
" com.google.protobuf.CodedInputStream input,
\n
"
" com.google.protobuf.ExtensionRegistryLite extensionRegistry)
\n
"
...
...
@@ -627,6 +647,7 @@ GenerateBuilderParsingMethods(io::Printer* printer) {
void
MessageBuilderGenerator
::
GenerateIsInitialized
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
"@java.lang.Override
\n
"
"public final boolean isInitialized() {
\n
"
);
printer
->
Indent
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment