@VisitsBefore
void visit(Method method) {
// Resolve input and output type of this method.
TypeRef inputType = resolveType(method.getLocation(),
FieldDescriptorProto.Type.TYPE_MESSAGE, method.getDescriptor().getInputTypeName());
if (inputType != null) {
method.setInputType(inputType);
}
TypeRef outputType = resolveType(method.getLocation(),
FieldDescriptorProto.Type.TYPE_MESSAGE, method.getDescriptor().getOutputTypeName());
if (outputType != null) {
method.setOutputType(outputType);
}
findOptionTypes(method.getOptionFields());
}
java类com.google.protobuf.DescriptorProtos.FieldDescriptorProto的实例源码
ReferenceResolver.java 文件源码
项目:api-compiler
阅读 14
收藏 0
点赞 0
评论 0
ExtensionPool.java 文件源码
项目:api-compiler
阅读 16
收藏 0
点赞 0
评论 0
private Extension(FieldDescriptorProto proto, DescriptorProtos.SourceCodeInfo.Location location,
String path, Location fileLocation) {
this.proto = proto;
this.location = location;
this.path = path;
this.fileLocation = fileLocation;
}
TypesBuilderFromDescriptor.java 文件源码
项目:api-compiler
阅读 20
收藏 0
点赞 0
评论 0
/**
* TODO (guptasu): only needed to create hard coded Types (Struct, ListValue, and Value). Check
* if this can be removed. Create the Protobuf.Type instance from descriptorProto.
*/
private static Type createType(String typeName, DescriptorProto descriptorProto,
String fileName) {
Type.Builder coreTypeBuilder = Type.newBuilder().setName(typeName);
int count = 1;
for (FieldDescriptorProto fieldProto : descriptorProto.getFieldList()) {
Field.Kind fieldKind = Field.Kind.valueOf(fieldProto.getType().getNumber());
Cardinality cardinality = Cardinality.CARDINALITY_OPTIONAL;
if (fieldProto.getLabel() == Label.LABEL_REPEATED) {
cardinality = Cardinality.CARDINALITY_REPEATED;
}
Field.Builder coreFieldBuilder = Field
.newBuilder()
.setName(fieldProto.getName())
.setNumber(count++)
.setKind(fieldKind)
.setCardinality(cardinality);
if (fieldKind == Kind.TYPE_MESSAGE || fieldKind == Kind.TYPE_ENUM) {
String typeFullName =
fieldProto.getTypeName().startsWith(".") ? fieldProto.getTypeName().substring(1)
: fieldProto.getTypeName();
coreFieldBuilder.setTypeUrl(TYPE_SERVICE_BASE_URL + typeFullName);
}
coreTypeBuilder.addFields(coreFieldBuilder.build());
}
coreTypeBuilder.setSourceContext(SourceContext.newBuilder().setFileName(fileName));
coreTypeBuilder.setSyntax(Syntax.SYNTAX_PROTO3);
return coreTypeBuilder.build();
}
BuilderVisitor.java 文件源码
项目:api-compiler
阅读 20
收藏 0
点赞 0
评论 0
protected void addFieldToMessageAncestor(
int generationsToSkip,
FieldDescriptorProto.Builder fieldDesc,
SourceCodeInfo.Location location) {
BuilderVisitorNodeInfo ancestorInfo = getAncestorInfo(generationsToSkip);
if (ancestorInfo instanceof MessageNodeInfo) {
((MessageNodeInfo) ancestorInfo).addNewField(fieldDesc, location);
setModified(true);
} else {
throw new RuntimeException(
String.format(
"Tried to add a field to a %s, but can only add to %s",
ancestorInfo.node().getClass(), DescriptorProto.Builder.class));
}
}
ProtobufDecompiler.java 文件源码
项目:sql-layer
阅读 18
收藏 0
点赞 0
评论 0
protected void findGroups(List<FieldDescriptorProto> fieldDescriptors,
Map<String,DescriptorProto> groups) {
for (FieldDescriptorProto fieldDescriptor : fieldDescriptors) {
if (fieldDescriptor.getType() == Type.TYPE_GROUP) {
groups.put(fieldDescriptor.getTypeName(), null);
}
}
}
ProtobufDecompiler.java 文件源码
项目:sql-layer
阅读 20
收藏 0
点赞 0
评论 0
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);
}
}
}
AISToProtobuf.java 文件源码
项目:sql-layer
阅读 20
收藏 0
点赞 0
评论 0
protected void addColumn(Column column) {
String fieldName = uniqueIdent(ident(column.getName(), false), fieldNames);
fieldBuilder = messageBuilder.addFieldBuilder();
fieldBuilder.setName(fieldName);
fieldBuilder.setLabel(Label.LABEL_OPTIONAL);
FieldOptions.Builder fieldBuilderOptions = FieldOptions.newBuilder();
ColumnOptions.Builder columnOptions = ColumnOptions.newBuilder();
if (!fieldName.equals(column.getName())) {
columnOptions.setName(column.getName());
}
columnOptions.setSqlType(column.getTypeDescription().toUpperCase());
columnOptions.setUuid(column.getUuid().toString());
priorField = null;
if (priorMessage != null) {
for (FieldDescriptorProto field : priorMessage.getFieldList()) {
FieldOptions options = field.getOptions();
if ((options != null) &&
(options.hasExtension(ColumnOptions.fdbsql))) {
ColumnOptions coptions = options.getExtension(ColumnOptions.fdbsql);
if (coptions.getUuid().equals(columnOptions.getUuid())) {
priorField = field;
break;
}
}
}
}
setColumnType(column, columnOptions);
setFieldNumber();
fieldBuilderOptions.setExtension(ColumnOptions.fdbsql, columnOptions.build());
fieldBuilder.setOptions(fieldBuilderOptions);
if (column.getNullable() &&
((column.getDefaultValue() != null) ||
(column.getDefaultFunction() != null))) {
addNullForField(column.getName(), fieldBuilder.getNumber());
}
}
AISToProtobuf.java 文件源码
项目:sql-layer
阅读 19
收藏 0
点赞 0
评论 0
protected void addNullForField(String columnName, int forField) {
String fieldName = uniqueIdent("_" + ident(columnName, false) + "_is_null", fieldNames);
fieldBuilder = messageBuilder.addFieldBuilder();
fieldBuilder.setName(fieldName);
fieldBuilder.setType(Type.TYPE_BOOL);
fieldBuilder.setLabel(Label.LABEL_OPTIONAL);
FieldOptions.Builder fieldBuilderOptions = FieldOptions.newBuilder();
ColumnOptions.Builder columnOptions = ColumnOptions.newBuilder();
columnOptions.setNullForField(forField);
priorField = null;
if (priorMessage != null) {
for (FieldDescriptorProto field : priorMessage.getFieldList()) {
FieldOptions options = field.getOptions();
if ((options != null) &&
(options.hasExtension(ColumnOptions.fdbsql))) {
ColumnOptions coptions = options.getExtension(ColumnOptions.fdbsql);
if (coptions.hasNullForField() &&
(coptions.getNullForField() == forField)) {
priorField = field;
break;
}
}
}
}
setFieldNumber();
fieldBuilderOptions.setExtension(ColumnOptions.fdbsql, columnOptions.build());
fieldBuilder.setOptions(fieldBuilderOptions);
}
AISToProtobuf.java 文件源码
项目:sql-layer
阅读 20
收藏 0
点赞 0
评论 0
protected void addChildTable(Table table) {
String fieldName = uniqueIdent(ident(table.getName().getTableName(), false), fieldNames);
fieldBuilder = messageBuilder.addFieldBuilder();
fieldBuilder.setName(fieldName);
fieldBuilder.setLabel(Label.LABEL_REPEATED);
fieldBuilder.setType(Type.TYPE_MESSAGE);
fieldBuilder.setTypeName(tableMessageNames.get(table));
FieldOptions.Builder fieldBuilderOptions = FieldOptions.newBuilder();
ColumnOptions.Builder columnOptions = ColumnOptions.newBuilder();
columnOptions.setUuid(table.getUuid().toString());
priorField = null;
if (priorMessage != null) {
for (FieldDescriptorProto field : priorMessage.getFieldList()) {
FieldOptions options = field.getOptions();
if ((options != null) &&
(options.hasExtension(ColumnOptions.fdbsql))) {
ColumnOptions coptions = options.getExtension(ColumnOptions.fdbsql);
if (coptions.getUuid().equals(columnOptions.getUuid())) {
priorField = field;
break;
}
}
}
}
setFieldNumber();
fieldBuilderOptions.setExtension(ColumnOptions.fdbsql, columnOptions.build());
fieldBuilder.setOptions(fieldBuilderOptions);
}