Java Code Examples for com.google.protobuf.DescriptorProtos.FieldDescriptorProto#getName()
The following examples show how to use
com.google.protobuf.DescriptorProtos.FieldDescriptorProto#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrintMessageFile.java From saluki with Apache License 2.0 | 5 votes |
@Override protected List<String> collectFileData() { String sourePackageName = super.getSourcePackageName(); String className = super.getClassName(); String packageName = sourePackageName.toLowerCase(); List<String> fileData = Lists.newArrayList(); fileData.add("package " + packageName + ";"); fileData.add(System.getProperty("line.separator")); fileData.add("import io.github.saluki.serializer.ProtobufAttribute;"); fileData.add("import io.github.saluki.serializer.ProtobufEntity;"); fileData.add(System.getProperty("line.separator")); fileData.add("@ProtobufEntity(" + sourePackageName + "." + className + ".class)"); fileData.add("public class " + className + "{"); for (int i = 0; i < messageFields.size(); i++) { FieldDescriptorProto messageField = messageFields.get(i); String javaType = findJavaType(packageName, sourceMessageDesc, messageField); if (messageField.getLabel() == Label.LABEL_REPEATED && javaType != null) { if (!javaType.contains("java.util.Map")) { javaType = "java.util.ArrayList<" + javaType + ">"; } } String fieldName = messageField.getName(); fileData.add(System.getProperty("line.separator")); fileData.add(" @ProtobufAttribute"); fileData.add(" private " + javaType + " " + fieldName + ";"); fileData.add(System.getProperty("line.separator")); fileData.add(" public " + javaType + " get" + captureName(fieldName) + "(){"); fileData.add(" return this." + fieldName + ";"); fileData.add("}"); fileData.add(System.getProperty("line.separator")); fileData.add( " public void set" + captureName(fieldName) + "(" + javaType + " " + fieldName + "){"); fileData.add(" this." + fieldName + "=" + fieldName + ";"); fileData.add("}"); fileData.add(System.getProperty("line.separator")); } fileData.add("}"); return fileData; }
Example 2
Source File: ProtobufDecompiler.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
protected void decompileFields(List<FieldDescriptorProto> fieldDescriptors, Map<String,DescriptorProto> groups) throws IOException { for (FieldDescriptorProto fieldDescriptor : fieldDescriptors) { String label = LABELS.get(fieldDescriptor.getLabel()); String type = TYPES.get(fieldDescriptor.getType()); String name = fieldDescriptor.getName(); if (fieldDescriptor.hasTypeName()) { type = fieldDescriptor.getTypeName(); if ((absolutePackage != null) && type.startsWith(absolutePackage)) { type = type.substring(absolutePackage.length()); } } DescriptorProto groupDescriptor = null; if (fieldDescriptor.getType() == Type.TYPE_GROUP) { groupDescriptor = groups.get(type); if (groupDescriptor != null) { name = type; type = "group"; } } indentedFormat("%s %s %s = %d", label, type, name, fieldDescriptor.getNumber()); if (fieldDescriptor.hasOptions() || fieldDescriptor.hasDefaultValue()) { write(defaultAndOptions(fieldDescriptor.hasOptions() ? fieldDescriptor.getOptions() : null, fieldDescriptor.hasDefaultValue() ? fieldDescriptor.getDefaultValue() : null)); } if (groupDescriptor == null) { write(";"); } else { decompileMessageBody(groupDescriptor); } } }
Example 3
Source File: Field.java From api-compiler with Apache License 2.0 | 4 votes |
/** * Creates a field backed up by the given proto. */ public static Field create(MessageType parent, FieldDescriptorProto proto, String path, @Nullable Oneof oneof) { return new Field(parent, proto, path, oneof, proto.getName()); }