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
02d7015b
Commit
02d7015b
authored
May 04, 2011
by
liujisi@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow String to be used as message names.
parent
5c245648
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
22 deletions
+47
-22
test_bad_identifiers.proto
.../test/java/com/google/protobuf/test_bad_identifiers.proto
+20
-0
java_string_field.cc
src/google/protobuf/compiler/java/java_string_field.cc
+27
-22
No files found.
java/src/test/java/com/google/protobuf/test_bad_identifiers.proto
View file @
02d7015b
...
@@ -64,6 +64,26 @@ message Object {
...
@@ -64,6 +64,26 @@ message Object {
optional
int32
object
=
1
;
optional
int32
object
=
1
;
}
}
message
String
{
optional
string
string
=
1
;
}
message
Integer
{
optional
int32
integer
=
1
;
}
message
Long
{
optional
int32
long
=
1
;
}
message
Float
{
optional
float
float
=
1
;
}
message
Double
{
optional
double
double
=
1
;
}
service
TestConflictingMethodNames
{
service
TestConflictingMethodNames
{
rpc
Override
(
TestMessage
)
returns
(
TestMessage
);
rpc
Override
(
TestMessage
)
returns
(
TestMessage
);
}
}
...
...
src/google/protobuf/compiler/java/java_string_field.cc
View file @
02d7015b
...
@@ -162,7 +162,7 @@ void StringFieldGenerator::
...
@@ -162,7 +162,7 @@ void StringFieldGenerator::
GenerateInterfaceMembers
(
io
::
Printer
*
printer
)
const
{
GenerateInterfaceMembers
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"$deprecation$boolean has$capitalized_name$();
\n
"
"$deprecation$boolean has$capitalized_name$();
\n
"
"$deprecation$String get$capitalized_name$();
\n
"
);
"$deprecation$
java.lang.
String get$capitalized_name$();
\n
"
);
}
}
void
StringFieldGenerator
::
void
StringFieldGenerator
::
...
@@ -174,14 +174,14 @@ GenerateMembers(io::Printer* printer) const {
...
@@ -174,14 +174,14 @@ GenerateMembers(io::Printer* printer) const {
"}
\n
"
);
"}
\n
"
);
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"$deprecation$public String get$capitalized_name$() {
\n
"
"$deprecation$public
java.lang.
String get$capitalized_name$() {
\n
"
" java.lang.Object ref = $name$_;
\n
"
" java.lang.Object ref = $name$_;
\n
"
" if (ref instanceof String) {
\n
"
" if (ref instanceof
java.lang.
String) {
\n
"
" return (String) ref;
\n
"
" return (
java.lang.
String) ref;
\n
"
" } else {
\n
"
" } else {
\n
"
" com.google.protobuf.ByteString bs =
\n
"
" com.google.protobuf.ByteString bs =
\n
"
" (com.google.protobuf.ByteString) ref;
\n
"
" (com.google.protobuf.ByteString) ref;
\n
"
" String s = bs.toStringUtf8();
\n
"
"
java.lang.
String s = bs.toStringUtf8();
\n
"
" if (com.google.protobuf.Internal.isValidUtf8(bs)) {
\n
"
" if (com.google.protobuf.Internal.isValidUtf8(bs)) {
\n
"
" $name$_ = s;
\n
"
" $name$_ = s;
\n
"
" }
\n
"
" }
\n
"
...
@@ -190,9 +190,10 @@ GenerateMembers(io::Printer* printer) const {
...
@@ -190,9 +190,10 @@ GenerateMembers(io::Printer* printer) const {
"}
\n
"
"}
\n
"
"private com.google.protobuf.ByteString get$capitalized_name$Bytes() {
\n
"
"private com.google.protobuf.ByteString get$capitalized_name$Bytes() {
\n
"
" java.lang.Object ref = $name$_;
\n
"
" java.lang.Object ref = $name$_;
\n
"
" if (ref instanceof String) {
\n
"
" if (ref instanceof
java.lang.
String) {
\n
"
" com.google.protobuf.ByteString b =
\n
"
" com.google.protobuf.ByteString b =
\n
"
" com.google.protobuf.ByteString.copyFromUtf8((String) ref);
\n
"
" com.google.protobuf.ByteString.copyFromUtf8(
\n
"
" (java.lang.String) ref);
\n
"
" $name$_ = b;
\n
"
" $name$_ = b;
\n
"
" return b;
\n
"
" return b;
\n
"
" } else {
\n
"
" } else {
\n
"
...
@@ -210,19 +211,21 @@ GenerateBuilderMembers(io::Printer* printer) const {
...
@@ -210,19 +211,21 @@ GenerateBuilderMembers(io::Printer* printer) const {
"}
\n
"
);
"}
\n
"
);
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"$deprecation$public String get$capitalized_name$() {
\n
"
"$deprecation$public
java.lang.
String get$capitalized_name$() {
\n
"
" java.lang.Object ref = $name$_;
\n
"
" java.lang.Object ref = $name$_;
\n
"
" if (!(ref instanceof String)) {
\n
"
" if (!(ref instanceof java.lang.String)) {
\n
"
" String s = ((com.google.protobuf.ByteString) ref).toStringUtf8();
\n
"
" java.lang.String s = ((com.google.protobuf.ByteString) ref)
\n
"
" .toStringUtf8();
\n
"
" $name$_ = s;
\n
"
" $name$_ = s;
\n
"
" return s;
\n
"
" return s;
\n
"
" } else {
\n
"
" } else {
\n
"
" return (String) ref;
\n
"
" return (
java.lang.
String) ref;
\n
"
" }
\n
"
" }
\n
"
"}
\n
"
);
"}
\n
"
);
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"$deprecation$public Builder set$capitalized_name$(String value) {
\n
"
"$deprecation$public Builder set$capitalized_name$(
\n
"
" java.lang.String value) {
\n
"
"$null_check$"
"$null_check$"
" $set_has_field_bit_builder$;
\n
"
" $set_has_field_bit_builder$;
\n
"
" $name$_ = value;
\n
"
" $name$_ = value;
\n
"
...
@@ -322,7 +325,7 @@ GenerateHashCode(io::Printer* printer) const {
...
@@ -322,7 +325,7 @@ GenerateHashCode(io::Printer* printer) const {
}
}
string
StringFieldGenerator
::
GetBoxedType
()
const
{
string
StringFieldGenerator
::
GetBoxedType
()
const
{
return
"String"
;
return
"
java.lang.
String"
;
}
}
...
@@ -351,9 +354,10 @@ int RepeatedStringFieldGenerator::GetNumBitsForBuilder() const {
...
@@ -351,9 +354,10 @@ int RepeatedStringFieldGenerator::GetNumBitsForBuilder() const {
void
RepeatedStringFieldGenerator
::
void
RepeatedStringFieldGenerator
::
GenerateInterfaceMembers
(
io
::
Printer
*
printer
)
const
{
GenerateInterfaceMembers
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"$deprecation$java.util.List<String> get$capitalized_name$List();
\n
"
"$deprecation$java.util.List<java.lang.String>
\n
"
" get$capitalized_name$List();
\n
"
"$deprecation$int get$capitalized_name$Count();
\n
"
"$deprecation$int get$capitalized_name$Count();
\n
"
"$deprecation$String get$capitalized_name$(int index);
\n
"
);
"$deprecation$
java.lang.
String get$capitalized_name$(int index);
\n
"
);
}
}
...
@@ -361,14 +365,14 @@ void RepeatedStringFieldGenerator::
...
@@ -361,14 +365,14 @@ void RepeatedStringFieldGenerator::
GenerateMembers
(
io
::
Printer
*
printer
)
const
{
GenerateMembers
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"private com.google.protobuf.LazyStringList $name$_;
\n
"
"private com.google.protobuf.LazyStringList $name$_;
\n
"
"$deprecation$public java.util.List<String>
\n
"
"$deprecation$public java.util.List<
java.lang.
String>
\n
"
" get$capitalized_name$List() {
\n
"
" get$capitalized_name$List() {
\n
"
" return $name$_;
\n
"
// note: unmodifiable list
" return $name$_;
\n
"
// note: unmodifiable list
"}
\n
"
"}
\n
"
"$deprecation$public int get$capitalized_name$Count() {
\n
"
"$deprecation$public int get$capitalized_name$Count() {
\n
"
" return $name$_.size();
\n
"
" return $name$_.size();
\n
"
"}
\n
"
"}
\n
"
"$deprecation$public String get$capitalized_name$(int index) {
\n
"
"$deprecation$public
java.lang.
String get$capitalized_name$(int index) {
\n
"
" return $name$_.get(index);
\n
"
" return $name$_.get(index);
\n
"
"}
\n
"
);
"}
\n
"
);
...
@@ -406,25 +410,26 @@ GenerateBuilderMembers(io::Printer* printer) const {
...
@@ -406,25 +410,26 @@ GenerateBuilderMembers(io::Printer* printer) const {
// has been built, thus mutating the message which is supposed to be
// has been built, thus mutating the message which is supposed to be
// immutable.
// immutable.
printer
->
Print
(
variables_
,
printer
->
Print
(
variables_
,
"$deprecation$public java.util.List<String>
\n
"
"$deprecation$public java.util.List<
java.lang.
String>
\n
"
" get$capitalized_name$List() {
\n
"
" get$capitalized_name$List() {
\n
"
" return java.util.Collections.unmodifiableList($name$_);
\n
"
" return java.util.Collections.unmodifiableList($name$_);
\n
"
"}
\n
"
"}
\n
"
"$deprecation$public int get$capitalized_name$Count() {
\n
"
"$deprecation$public int get$capitalized_name$Count() {
\n
"
" return $name$_.size();
\n
"
" return $name$_.size();
\n
"
"}
\n
"
"}
\n
"
"$deprecation$public String get$capitalized_name$(int index) {
\n
"
"$deprecation$public
java.lang.
String get$capitalized_name$(int index) {
\n
"
" return $name$_.get(index);
\n
"
" return $name$_.get(index);
\n
"
"}
\n
"
"}
\n
"
"$deprecation$public Builder set$capitalized_name$(
\n
"
"$deprecation$public Builder set$capitalized_name$(
\n
"
" int index, String value) {
\n
"
" int index,
java.lang.
String value) {
\n
"
"$null_check$"
"$null_check$"
" ensure$capitalized_name$IsMutable();
\n
"
" ensure$capitalized_name$IsMutable();
\n
"
" $name$_.set(index, value);
\n
"
" $name$_.set(index, value);
\n
"
" $on_changed$
\n
"
" $on_changed$
\n
"
" return this;
\n
"
" return this;
\n
"
"}
\n
"
"}
\n
"
"$deprecation$public Builder add$capitalized_name$(String value) {
\n
"
"$deprecation$public Builder add$capitalized_name$(
\n
"
" java.lang.String value) {
\n
"
"$null_check$"
"$null_check$"
" ensure$capitalized_name$IsMutable();
\n
"
" ensure$capitalized_name$IsMutable();
\n
"
" $name$_.add(value);
\n
"
" $name$_.add(value);
\n
"
...
@@ -432,7 +437,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
...
@@ -432,7 +437,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
" return this;
\n
"
" return this;
\n
"
"}
\n
"
"}
\n
"
"$deprecation$public Builder addAll$capitalized_name$(
\n
"
"$deprecation$public Builder addAll$capitalized_name$(
\n
"
" java.lang.Iterable<String> values) {
\n
"
" java.lang.Iterable<
java.lang.
String> values) {
\n
"
" ensure$capitalized_name$IsMutable();
\n
"
" ensure$capitalized_name$IsMutable();
\n
"
" super.addAll(values, $name$_);
\n
"
" super.addAll(values, $name$_);
\n
"
" $on_changed$
\n
"
" $on_changed$
\n
"
...
...
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