Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Side by Side Diff: third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 for (String getter : getters) { 90 for (String getter : getters) {
91 String suffix = getter.replaceFirst("get", ""); 91 String suffix = getter.replaceFirst("get", "");
92 if (suffix.endsWith(LIST_SUFFIX) && !suffix.endsWith(BUILDER_LIST_SUFFIX)) { 92 if (suffix.endsWith(LIST_SUFFIX) && !suffix.endsWith(BUILDER_LIST_SUFFIX)) {
93 String camelCase = suffix.substring(0, 1).toLowerCase() 93 String camelCase = suffix.substring(0, 1).toLowerCase()
94 + suffix.substring(1, suffix.length() - LIST_SUFFIX.length()); 94 + suffix.substring(1, suffix.length() - LIST_SUFFIX.length());
95 // Try to reflectively get the value and toString() the field as if it w ere repeated. This 95 // Try to reflectively get the value and toString() the field as if it w ere repeated. This
96 // only works if the method names have not be proguarded out or renamed. 96 // only works if the method names have not be proguarded out or renamed.
97 Method listMethod = nameToNoArgMethod.get("get" + suffix); 97 Method listMethod = nameToNoArgMethod.get("get" + suffix);
98 if (listMethod != null) { 98 if (listMethod != null && listMethod.getReturnType().equals(List.class)) {
99 printField( 99 printField(
100 buffer, 100 buffer,
101 indent, 101 indent,
102 camelCaseToSnakeCase(camelCase), 102 camelCaseToSnakeCase(camelCase),
103 GeneratedMessageLite.invokeOrDie(listMethod, messageLite)); 103 GeneratedMessageLite.invokeOrDie(listMethod, messageLite));
104 continue; 104 continue;
105 } 105 }
106 } 106 }
107 107
108 Method setter = nameToMethod.get("set" + suffix); 108 Method setter = nameToMethod.get("set" + suffix);
109 if (setter == null) { 109 if (setter == null) {
110 continue; 110 continue;
111 } 111 }
112 if (suffix.endsWith(BYTES_SUFFIX) 112 if (suffix.endsWith(BYTES_SUFFIX)
113 && nameToNoArgMethod.containsKey( 113 && nameToNoArgMethod.containsKey(
114 "get" + suffix.substring(0, suffix.length() - "Bytes".length()))) { 114 "get" + suffix.substring(0, suffix.length() - "Bytes".length()))) {
115 // Heuristic to skip bytes based accessors for string fields. 115 // Heuristic to skip bytes based accessors for string fields.
116 continue; 116 continue;
117 } 117 }
118 118
119 String camelCase = suffix.substring(0, 1).toLowerCase() + suffix.substring (1); 119 String camelCase = suffix.substring(0, 1).toLowerCase() + suffix.substring (1);
120 120
121 // Try to reflectively get the value and toString() the field as if it wer e optional. This 121 // Try to reflectively get the value and toString() the field as if it wer e optional. This
122 // only works if the method names have not be proguarded out or renamed. 122 // only works if the method names have not be proguarded out or renamed.
123 Method getMethod = nameToNoArgMethod.get("get" + suffix); 123 Method getMethod = nameToNoArgMethod.get("get" + suffix);
124 Method hasMethod = nameToNoArgMethod.get("has" + suffix); 124 Method hasMethod = nameToNoArgMethod.get("has" + suffix);
125 // TODO(dweis): Fix proto3 semantics. 125 // TODO(dweis): Fix proto3 semantics.
126 if (getMethod != null) { 126 if (getMethod != null) {
127 Object value = GeneratedMessageLite.invokeOrDie(getMethod, messageLite); 127 Object value = GeneratedMessageLite.invokeOrDie(getMethod, messageLite);
128 final boolean hasValue = hasMethod == null 128 final boolean hasValue = hasMethod == null
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 for (int i = 0; i < camelCase.length(); i++) { 230 for (int i = 0; i < camelCase.length(); i++) {
231 char ch = camelCase.charAt(i); 231 char ch = camelCase.charAt(i);
232 if (Character.isUpperCase(ch)) { 232 if (Character.isUpperCase(ch)) {
233 builder.append("_"); 233 builder.append("_");
234 } 234 }
235 builder.append(Character.toLowerCase(ch)); 235 builder.append(Character.toLowerCase(ch));
236 } 236 }
237 return builder.toString(); 237 return builder.toString();
238 } 238 }
239 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698