1414import java .util .Collection ;
1515
1616import javax .annotation .Nonnull ;
17- import javax .annotation .Nullable ;
1817
1918/**
2019 * {@code ProtoTypeMap} maintains a dictionary for looking up Java type names when given proto types.
2120 */
2221public final class ProtoTypeMap {
2322
23+ private static final Joiner DOT_JOINER = Joiner .on ('.' ).skipNulls ();
2424 private final ImmutableMap <String , String > types ;
2525
2626 private ProtoTypeMap (@ Nonnull ImmutableMap <String , String > types ) {
@@ -58,7 +58,7 @@ public static ProtoTypeMap of(@Nonnull Collection<DescriptorProtos.FileDescripto
5858 fileDescriptor .getEnumTypeList ().forEach (
5959 e -> types .put (
6060 protoPackage + "." + e .getName (),
61- toJavaTypeName ( e . getName () , enclosingClassName , javaPackage )));
61+ DOT_JOINER . join ( javaPackage , enclosingClassName , e . getName () )));
6262
6363 // Identify top-level messages, and nested types
6464 fileDescriptor .getMessageTypeList ().forEach (
@@ -74,23 +74,21 @@ private static void recursivelyAddTypes(ImmutableMap.Builder<String, String> typ
7474 String protoTypeName = protoPackage + "." + m .getName ();
7575 types .put (
7676 protoTypeName ,
77- toJavaTypeName ( m . getName () , enclosingClassName , javaPackage ));
77+ DOT_JOINER . join ( javaPackage , enclosingClassName , m . getName () ));
7878
7979 // Identify any nested Enums
8080 m .getEnumTypeList ().forEach (
8181 e -> types .put (
8282 protoPackage + "." + m .getName () + "." + e .getName (),
83- toJavaTypeName (e .getName (),
84- enclosingClassName + "." + m .getName (),
85- javaPackage )));
83+ DOT_JOINER .join (javaPackage , enclosingClassName , m .getName (), e .getName ())));
8684
8785 // Recursively identify any nested types
8886 m .getNestedTypeList ().forEach (
8987 n -> recursivelyAddTypes (
9088 types ,
9189 n ,
9290 protoPackage + "." + m .getName (),
93- enclosingClassName + "." + m .getName (),
91+ DOT_JOINER . join ( enclosingClassName , m .getName () ),
9492 javaPackage ));
9593 }
9694
@@ -104,24 +102,6 @@ public String toJavaTypeName(@Nonnull String protoTypeName) {
104102 return types .get (protoTypeName );
105103 }
106104
107- /**
108- * Returns the full Java type name based on the given protobuf type parameters.
109- *
110- * @param className the protobuf type name
111- * @param enclosingClassName the optional enclosing class for the given type
112- * @param javaPackage the proto file's configured java package name
113- */
114- public static String toJavaTypeName (
115- @ Nonnull String className ,
116- @ Nullable String enclosingClassName ,
117- @ Nullable String javaPackage ) {
118-
119- Preconditions .checkNotNull (className , "className" );
120-
121- Joiner dotJoiner = Joiner .on ('.' ).skipNulls ();
122- return dotJoiner .join (javaPackage , enclosingClassName , className );
123- }
124-
125105 private static String getJavaOuterClassname (
126106 DescriptorProtos .FileDescriptorProto fileDescriptor ,
127107 DescriptorProtos .FileOptions fileOptions ) {
0 commit comments