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
43a2dee7
Commit
43a2dee7
authored
Jul 30, 2015
by
Jan Tattermusch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor umbrella class helpers
parent
12febd0a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
34 deletions
+28
-34
csharp_generator.cc
src/google/protobuf/compiler/csharp/csharp_generator.cc
+1
-1
csharp_helpers.cc
src/google/protobuf/compiler/csharp/csharp_helpers.cc
+10
-22
csharp_helpers.h
src/google/protobuf/compiler/csharp/csharp_helpers.h
+5
-6
csharp_message.cc
src/google/protobuf/compiler/csharp/csharp_message.cc
+1
-2
csharp_names.h
src/google/protobuf/compiler/csharp/csharp_names.h
+8
-0
csharp_umbrella_class.cc
src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc
+3
-3
No files found.
src/google/protobuf/compiler/csharp/csharp_generator.cc
View file @
43a2dee7
...
...
@@ -50,7 +50,7 @@ namespace csharp {
std
::
string
GetOutputFile
(
const
google
::
protobuf
::
FileDescriptor
*
file
,
const
std
::
string
file_extension
)
{
return
Get
FileUmbrellaClassn
ame
(
file
)
+
file_extension
;
return
Get
UmbrellaClassUnqualifiedN
ame
(
file
)
+
file_extension
;
}
void
GenerateFile
(
const
google
::
protobuf
::
FileDescriptor
*
file
,
...
...
src/google/protobuf/compiler/csharp/csharp_helpers.cc
View file @
43a2dee7
...
...
@@ -117,21 +117,18 @@ std::string GetFileNamespace(const FileDescriptor* descriptor) {
return
UnderscoresToCamelCase
(
descriptor
->
package
(),
true
,
true
);
}
std
::
string
GetUmbrellaClassNameInternal
(
const
std
::
string
&
proto_file
)
{
std
::
string
GetUmbrellaClassUnqualifiedName
(
const
FileDescriptor
*
descriptor
)
{
// umbrella_classname can no longer be set using message option.
std
::
string
proto_file
=
descriptor
->
name
();
int
lastslash
=
proto_file
.
find_last_of
(
"/"
);
std
::
string
base
=
proto_file
.
substr
(
lastslash
+
1
);
return
UnderscoresToPascalCase
(
StripDotProto
(
base
));
}
std
::
string
GetFileUmbrellaClassname
(
const
FileDescriptor
*
descriptor
)
{
// umbrella_classname can no longer be set using message option.
return
GetUmbrellaClassNameInternal
(
descriptor
->
name
());
}
std
::
string
GetFileUmbrellaNamespace
(
const
FileDescriptor
*
descriptor
)
{
std
::
string
GetUmbrellaClassNestedNamespace
(
const
FileDescriptor
*
descriptor
)
{
// TODO(jtattermusch): reintroduce csharp_umbrella_namespace option
bool
collision
=
false
;
std
::
string
umbrella_classname
=
Get
FileUmbrellaClassn
ame
(
descriptor
);
std
::
string
umbrella_classname
=
Get
UmbrellaClassUnqualifiedN
ame
(
descriptor
);
for
(
int
i
=
0
;
i
<
descriptor
->
message_type_count
();
i
++
)
{
if
(
descriptor
->
message_type
(
i
)
->
name
()
==
umbrella_classname
)
{
collision
=
true
;
...
...
@@ -215,26 +212,17 @@ std::string ToCSharpName(const std::string& name, const FileDescriptor* file) {
return
"global::"
+
result
;
}
std
::
string
GetFullUmbrellaClassName
(
const
FileDescriptor
*
descriptor
)
{
std
::
string
GetUmbrellaClassName
(
const
FileDescriptor
*
descriptor
)
{
std
::
string
result
=
GetFileNamespace
(
descriptor
);
if
(
!
result
.
empty
())
{
result
+=
'.'
;
}
result
+=
GetQualifiedUmbrellaClassName
(
descriptor
);
return
"global::"
+
result
;
}
std
::
string
GetQualifiedUmbrellaClassName
(
const
FileDescriptor
*
descriptor
)
{
std
::
string
umbrellaNamespace
=
GetFileUmbrellaNamespace
(
descriptor
);
std
::
string
umbrellaClassname
=
GetFileUmbrellaClassname
(
descriptor
);
std
::
string
fullName
=
umbrellaClassname
;
std
::
string
umbrellaNamespace
=
GetUmbrellaClassNestedNamespace
(
descriptor
);
if
(
!
umbrellaNamespace
.
empty
())
{
fullName
=
umbrellaNamespace
+
"."
+
umbrellaClassname
;
result
+=
umbrellaNamespace
+
"."
;
}
return
fullName
;
result
+=
GetUmbrellaClassUnqualifiedName
(
descriptor
);
return
"global::"
+
result
;
}
std
::
string
GetClassName
(
const
Descriptor
*
descriptor
)
{
...
...
src/google/protobuf/compiler/csharp/csharp_helpers.h
View file @
43a2dee7
...
...
@@ -69,13 +69,12 @@ CSharpType GetCSharpType(FieldDescriptor::Type type);
std
::
string
StripDotProto
(
const
std
::
string
&
proto_file
);
std
::
string
GetFileUmbrellaClassname
(
const
FileDescriptor
*
descriptor
);
// Gets unqualified name of the umbrella class
std
::
string
GetUmbrellaClassUnqualifiedName
(
const
FileDescriptor
*
descriptor
);
std
::
string
GetFileUmbrellaNamespace
(
const
FileDescriptor
*
descriptor
);
std
::
string
GetFullUmbrellaClassName
(
const
FileDescriptor
*
descriptor
);
std
::
string
GetQualifiedUmbrellaClassName
(
const
FileDescriptor
*
descriptor
);
// Gets name of the nested for umbrella class (just the nested part,
// not including the GetFileNamespace part).
std
::
string
GetUmbrellaClassNestedNamespace
(
const
FileDescriptor
*
descriptor
);
std
::
string
GetClassName
(
const
Descriptor
*
descriptor
);
...
...
src/google/protobuf/compiler/csharp/csharp_message.cc
View file @
43a2dee7
...
...
@@ -100,7 +100,6 @@ void MessageGenerator::Generate(io::Printer* printer) {
map
<
string
,
string
>
vars
;
vars
[
"class_name"
]
=
class_name
();
vars
[
"access_level"
]
=
class_access_level
();
vars
[
"umbrella_class_name"
]
=
GetFullUmbrellaClassName
(
descriptor_
->
file
());
printer
->
Print
(
"[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
\n
"
);
...
...
@@ -118,7 +117,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
// Access the message descriptor via the relevant file descriptor or containing message descriptor.
if
(
!
descriptor_
->
containing_type
())
{
vars
[
"descriptor_accessor"
]
=
Get
Full
UmbrellaClassName
(
descriptor_
->
file
())
vars
[
"descriptor_accessor"
]
=
GetUmbrellaClassName
(
descriptor_
->
file
())
+
".Descriptor.MessageTypes["
+
SimpleItoa
(
descriptor_
->
index
())
+
"]"
;
}
else
{
vars
[
"descriptor_accessor"
]
=
GetClassName
(
descriptor_
->
containing_type
())
...
...
src/google/protobuf/compiler/csharp/csharp_names.h
View file @
43a2dee7
...
...
@@ -65,6 +65,14 @@ string GetFileNamespace(const FileDescriptor* descriptor);
// The fully-qualified C# class name.
string
GetClassName
(
const
Descriptor
*
descriptor
);
// Requires:
// descriptor != NULL
//
// Returns:
// The fully-qualified name of the C# class that provides
// access to the file descriptor. Proto compiler generates
// such class for each .proto file processed.
std
::
string
GetUmbrellaClassName
(
const
FileDescriptor
*
descriptor
);
}
// namespace csharp
}
// namespace compiler
...
...
src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc
View file @
43a2dee7
...
...
@@ -54,8 +54,8 @@ UmbrellaClassGenerator::UmbrellaClassGenerator(const FileDescriptor* file)
:
SourceGeneratorBase
(
file
),
file_
(
file
)
{
namespace_
=
GetFileNamespace
(
file
);
umbrellaClassname_
=
Get
FileUmbrellaClassn
ame
(
file
);
umbrellaNamespace_
=
Get
FileUmbrella
Namespace
(
file
);
umbrellaClassname_
=
Get
UmbrellaClassUnqualifiedN
ame
(
file
);
umbrellaNamespace_
=
Get
UmbrellaClassNested
Namespace
(
file
);
}
UmbrellaClassGenerator
::~
UmbrellaClassGenerator
()
{
...
...
@@ -183,7 +183,7 @@ void UmbrellaClassGenerator::WriteDescriptor(io::Printer* printer) {
printer
->
Print
(
"$full_umbrella_class_name$.Descriptor, "
,
"full_umbrella_class_name"
,
Get
Full
UmbrellaClassName
(
file_
->
dependency
(
i
)));
GetUmbrellaClassName
(
file_
->
dependency
(
i
)));
}
printer
->
Print
(
"},
\n
"
" new pbr::GeneratedCodeInfo("
);
...
...
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