下面列出了com.google.protobuf.Descriptors.FieldDescriptor.Type#MESSAGE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** Returns a GraphQLOutputType generated from a FieldDescriptor. */
static GraphQLOutputType convertType(
FieldDescriptor fieldDescriptor, SchemaOptions schemaOptions) {
final GraphQLOutputType type;
if (fieldDescriptor.getType() == Type.MESSAGE) {
type = getReference(fieldDescriptor.getMessageType());
} else if (fieldDescriptor.getType() == Type.GROUP) {
type = getReference(fieldDescriptor.getMessageType());
} else if (fieldDescriptor.getType() == Type.ENUM) {
type = getReference(fieldDescriptor.getEnumType());
} else if (schemaOptions.useProtoScalarTypes()) {
type = PROTO_TYPE_MAP.get(fieldDescriptor.getType());
} else {
type = TYPE_MAP.get(fieldDescriptor.getType());
}
if (type == null) {
throw new RuntimeException("Unknown type: " + fieldDescriptor.getType());
}
if (fieldDescriptor.isRepeated()) {
return new GraphQLList(type);
} else {
return type;
}
}
protected static HashMap<Integer, Declaration> collectDeclarations(FieldDescriptor field, Object value) {
HashMap<Integer, Declaration> nodeDeclaration = new HashMap<Integer, Declaration>();
if (field.isRepeated()) {
// Repeated field. Print each element.
for (Iterator<?> iter = ((List<?>) value).iterator(); iter.hasNext();)
if (field.getType() == Type.MESSAGE)
nodeDeclaration.putAll(collectDeclarations((Message) iter.next()));
}
return nodeDeclaration;
}
private void visitFieldValue(FieldDescriptor field, Object value) {
if (field.getType() == Type.MESSAGE)
visit((Message) value);
}