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
86595020
Commit
86595020
authored
Jul 19, 2013
by
Ulas Kirazci
Committed by
Gerrit Code Review
Jul 19, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Update nano to serialize java keywords properly."
parents
b8f5dad1
d4bb971d
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
72 additions
and
11 deletions
+72
-11
NanoTest.java
java/src/test/java/com/google/protobuf/NanoTest.java
+6
-0
javanano_enum.cc
src/google/protobuf/compiler/javanano/javanano_enum.cc
+2
-2
javanano_enum_field.cc
src/google/protobuf/compiler/javanano/javanano_enum_field.cc
+2
-2
javanano_extension.cc
src/google/protobuf/compiler/javanano/javanano_extension.cc
+2
-1
javanano_helpers.cc
src/google/protobuf/compiler/javanano/javanano_helpers.cc
+47
-0
javanano_helpers.h
src/google/protobuf/compiler/javanano/javanano_helpers.h
+4
-0
javanano_message.cc
src/google/protobuf/compiler/javanano/javanano_message.cc
+2
-2
javanano_message_field.cc
...ogle/protobuf/compiler/javanano/javanano_message_field.cc
+2
-2
javanano_primitive_field.cc
...le/protobuf/compiler/javanano/javanano_primitive_field.cc
+2
-2
unittest_nano.proto
src/google/protobuf/unittest_nano.proto
+3
-0
No files found.
java/src/test/java/com/google/protobuf/NanoTest.java
View file @
86595020
...
...
@@ -2250,6 +2250,12 @@ public class NanoTest extends TestCase {
assertEquals
(
message
.
d
,
newMessage
.
d
);
}
public
void
testJavaKeyword
()
throws
Exception
{
TestAllTypesNano
msg
=
new
TestAllTypesNano
();
msg
.
synchronized_
=
123
;
assertEquals
(
123
,
msg
.
synchronized_
);
}
private
<
T
>
List
<
T
>
list
(
T
first
,
T
...
remaining
)
{
List
<
T
>
list
=
new
ArrayList
<
T
>();
list
.
add
(
first
);
...
...
src/google/protobuf/compiler/javanano/javanano_enum.cc
View file @
86595020
...
...
@@ -82,7 +82,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
}
for
(
int
i
=
0
;
i
<
canonical_values_
.
size
();
i
++
)
{
map
<
string
,
string
>
vars
;
vars
[
"name"
]
=
canonical_values_
[
i
]
->
name
(
);
vars
[
"name"
]
=
RenameJavaKeywords
(
canonical_values_
[
i
]
->
name
()
);
vars
[
"canonical_value"
]
=
SimpleItoa
(
canonical_values_
[
i
]
->
number
());
printer
->
Print
(
vars
,
"public static final int $name$ = $canonical_value$;
\n
"
);
...
...
@@ -92,7 +92,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
for
(
int
i
=
0
;
i
<
aliases_
.
size
();
i
++
)
{
map
<
string
,
string
>
vars
;
vars
[
"name"
]
=
aliases_
[
i
].
value
->
name
(
);
vars
[
"name"
]
=
RenameJavaKeywords
(
aliases_
[
i
].
value
->
name
()
);
vars
[
"canonical_name"
]
=
aliases_
[
i
].
canonical_value
->
name
();
printer
->
Print
(
vars
,
"public static final int $name$ = $canonical_name$;
\n
"
);
...
...
src/google/protobuf/compiler/javanano/javanano_enum_field.cc
View file @
86595020
...
...
@@ -54,9 +54,9 @@ namespace {
void
SetEnumVariables
(
const
Params
&
params
,
const
FieldDescriptor
*
descriptor
,
map
<
string
,
string
>*
variables
)
{
(
*
variables
)[
"name"
]
=
UnderscoresToCamelCase
(
descriptor
);
RenameJavaKeywords
(
UnderscoresToCamelCase
(
descriptor
)
);
(
*
variables
)[
"capitalized_name"
]
=
UnderscoresToCapitalizedCamelCase
(
descriptor
);
RenameJavaKeywords
(
UnderscoresToCapitalizedCamelCase
(
descriptor
)
);
(
*
variables
)[
"number"
]
=
SimpleItoa
(
descriptor
->
number
());
(
*
variables
)[
"type"
]
=
"int"
;
(
*
variables
)[
"default"
]
=
DefaultValue
(
params
,
descriptor
);
...
...
src/google/protobuf/compiler/javanano/javanano_extension.cc
View file @
86595020
...
...
@@ -45,7 +45,8 @@ using internal::WireFormat;
void
SetVariables
(
const
FieldDescriptor
*
descriptor
,
const
Params
params
,
map
<
string
,
string
>*
variables
)
{
(
*
variables
)[
"name"
]
=
UnderscoresToCamelCase
(
descriptor
);
(
*
variables
)[
"name"
]
=
RenameJavaKeywords
(
UnderscoresToCamelCase
(
descriptor
));
(
*
variables
)[
"number"
]
=
SimpleItoa
(
descriptor
->
number
());
(
*
variables
)[
"extends"
]
=
ClassName
(
params
,
descriptor
->
containing_type
());
...
...
src/google/protobuf/compiler/javanano/javanano_helpers.cc
View file @
86595020
...
...
@@ -37,6 +37,7 @@
#include <google/protobuf/compiler/javanano/javanano_helpers.h>
#include <google/protobuf/compiler/javanano/javanano_params.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/stubs/hash.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
...
...
@@ -50,6 +51,48 @@ const char kThickSeparator[] =
const
char
kThinSeparator
[]
=
"// -------------------------------------------------------------------
\n
"
;
class
RenameKeywords
{
private
:
hash_set
<
string
>
java_keywords_set_
;
public
:
RenameKeywords
()
{
static
const
char
*
kJavaKeywordsList
[]
=
{
// Reserved Java Keywords
"abstract"
,
"assert"
,
"boolean"
,
"break"
,
"byte"
,
"case"
,
"catch"
,
"char"
,
"class"
,
"const"
,
"continue"
,
"default"
,
"do"
,
"double"
,
"else"
,
"enum"
,
"extends"
,
"final"
,
"finally"
,
"float"
,
"for"
,
"goto"
,
"if"
,
"implements"
,
"import"
,
"instanceof"
,
"int"
,
"interface"
,
"long"
,
"native"
,
"new"
,
"package"
,
"private"
,
"protected"
,
"public"
,
"return"
,
"short"
,
"static"
,
"strictfp"
,
"super"
,
"switch"
,
"synchronized"
,
"this"
,
"throw"
,
"throws"
,
"transient"
,
"try"
,
"void"
,
"volatile"
,
"while"
,
// Reserved Keywords for Literals
"false"
,
"null"
,
"true"
};
for
(
int
i
=
0
;
i
<
GOOGLE_ARRAYSIZE
(
kJavaKeywordsList
);
i
++
)
{
java_keywords_set_
.
insert
(
kJavaKeywordsList
[
i
]);
}
}
// Used to rename the a field name if it's a java keyword. Specifically
// this is used to rename the ["name"] or ["capitalized_name"] field params.
// (http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html)
string
RenameJavaKeywordsImpl
(
const
string
&
input
)
{
string
result
=
input
;
if
(
java_keywords_set_
.
find
(
result
)
!=
java_keywords_set_
.
end
())
{
result
+=
"_"
;
}
return
result
;
}
};
static
RenameKeywords
sRenameKeywords
;
namespace
{
const
char
*
kDefaultPackage
=
""
;
...
...
@@ -110,6 +153,10 @@ string UnderscoresToCamelCase(const MethodDescriptor* method) {
return
UnderscoresToCamelCaseImpl
(
method
->
name
(),
false
);
}
string
RenameJavaKeywords
(
const
string
&
input
)
{
return
sRenameKeywords
.
RenameJavaKeywordsImpl
(
input
);
}
string
StripProto
(
const
string
&
filename
)
{
if
(
HasSuffixString
(
filename
,
".protodevel"
))
{
return
StripSuffixString
(
filename
,
".protodevel"
);
...
...
src/google/protobuf/compiler/javanano/javanano_helpers.h
View file @
86595020
...
...
@@ -55,6 +55,10 @@ extern const char kThinSeparator[];
string
UnderscoresToCamelCase
(
const
FieldDescriptor
*
field
);
string
UnderscoresToCapitalizedCamelCase
(
const
FieldDescriptor
*
field
);
// Appends an "_" to the end of a field where the name is a reserved java
// keyword. For example int32 public = 1 will generate int public_.
string
RenameJavaKeywords
(
const
string
&
input
);
// Similar, but for method names. (Typically, this merely has the effect
// of lower-casing the first letter of the name.)
string
UnderscoresToCamelCase
(
const
MethodDescriptor
*
method
);
...
...
src/google/protobuf/compiler/javanano/javanano_message.cc
View file @
86595020
...
...
@@ -396,12 +396,12 @@ void MessageGenerator::GenerateClear(io::Printer* printer) {
// type.
printer
->
Print
(
"$name$ = $default$.clone();
\n
"
,
"name"
,
UnderscoresToCamelCase
(
field
),
"name"
,
RenameJavaKeywords
(
UnderscoresToCamelCase
(
field
)
),
"default"
,
DefaultValue
(
params_
,
field
));
}
else
{
printer
->
Print
(
"$name$ = $default$;
\n
"
,
"name"
,
UnderscoresToCamelCase
(
field
),
"name"
,
RenameJavaKeywords
(
UnderscoresToCamelCase
(
field
)
),
"default"
,
DefaultValue
(
params_
,
field
));
}
}
...
...
src/google/protobuf/compiler/javanano/javanano_message_field.cc
View file @
86595020
...
...
@@ -56,9 +56,9 @@ namespace {
void
SetMessageVariables
(
const
Params
&
params
,
const
FieldDescriptor
*
descriptor
,
map
<
string
,
string
>*
variables
)
{
(
*
variables
)[
"name"
]
=
UnderscoresToCamelCase
(
descriptor
);
RenameJavaKeywords
(
UnderscoresToCamelCase
(
descriptor
)
);
(
*
variables
)[
"capitalized_name"
]
=
UnderscoresToCapitalizedCamelCase
(
descriptor
);
RenameJavaKeywords
(
UnderscoresToCapitalizedCamelCase
(
descriptor
)
);
(
*
variables
)[
"number"
]
=
SimpleItoa
(
descriptor
->
number
());
(
*
variables
)[
"type"
]
=
ClassName
(
params
,
descriptor
->
message_type
());
(
*
variables
)[
"group_or_message"
]
=
...
...
src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
View file @
86595020
...
...
@@ -208,9 +208,9 @@ bool AllAscii(const string& text) {
void
SetPrimitiveVariables
(
const
FieldDescriptor
*
descriptor
,
const
Params
params
,
map
<
string
,
string
>*
variables
)
{
(
*
variables
)[
"name"
]
=
UnderscoresToCamelCase
(
descriptor
);
RenameJavaKeywords
(
UnderscoresToCamelCase
(
descriptor
)
);
(
*
variables
)[
"capitalized_name"
]
=
UnderscoresToCapitalizedCamelCase
(
descriptor
);
RenameJavaKeywords
(
UnderscoresToCapitalizedCamelCase
(
descriptor
)
);
(
*
variables
)[
"number"
]
=
SimpleItoa
(
descriptor
->
number
());
(
*
variables
)[
"type"
]
=
PrimitiveTypeName
(
GetJavaType
(
descriptor
));
(
*
variables
)[
"default"
]
=
DefaultValue
(
params
,
descriptor
);
...
...
src/google/protobuf/unittest_nano.proto
View file @
86595020
...
...
@@ -157,6 +157,9 @@ message TestAllTypesNano {
optional
int32
tag
=
93
;
optional
int32
get_serialized_size
=
94
;
optional
int32
write_to
=
95
;
// Try to fail with java reserved keywords
optional
int32
synchronized
=
96
;
}
message
ForeignMessageNano
{
...
...
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