Java 类com.google.protobuf.Descriptors.GenericDescriptor 实例源码

项目:closure-templates    文件:SoyProtoTypeProvider.java   
private SoyType doGetType(String name, SoyTypeRegistry typeRegistry,
    GenericDescriptor descriptor) {
  SoyType type;
  synchronized (lock) {
    type = typeCache.get(name);
    if (type == null) {
      if (descriptor instanceof EnumDescriptor) {
        type = new SoyProtoEnumType((EnumDescriptor) descriptor);
      } else {
        type = new SoyProtoType(typeRegistry, (Descriptor) descriptor, extensions.get(name));
      }
      typeCache.put(name, type);
    }
  }
  return type;
}
项目:closure-templates    文件:DescriptorTreeWalker.java   
final void walkDescriptor(GenericDescriptor descriptor) {
  if (!visited.add(descriptor.getFullName())) {
    // skip if we have already seen this descriptor
    return;
  }
  if (descriptor instanceof FileDescriptor) {
    walkFileDescriptor((FileDescriptor) descriptor);
  } else if (descriptor instanceof Descriptor) {
    walkMessageDescriptor((Descriptor) descriptor);
  } else if (descriptor instanceof FieldDescriptor) {
    FieldDescriptor fieldDescriptor = (FieldDescriptor) descriptor;
    if (fieldDescriptor.isExtension()) {
      visitExtensionDescriptor(fieldDescriptor);
    } else {
      visitFieldDescriptor(fieldDescriptor);
    }
  } else if (descriptor instanceof EnumDescriptor) {
    visitEnumDescriptor((EnumDescriptor) descriptor);
  }  // services, etc. not needed thus far so neither gathered nor dispatched
}
项目:beam    文件:ProtobufUtil.java   
/**
 * Recursively walks the given {@link Message} class and verifies that every field or message
 * linked in uses the Protocol Buffers proto2 syntax.
 */
static void checkProto2Syntax(Class<? extends Message> clazz, ExtensionRegistry registry) {
  for (GenericDescriptor d : getRecursiveDescriptorsForClass(clazz, registry)) {
    Syntax s = d.getFile().getSyntax();
    checkArgument(
        s == Syntax.PROTO2,
        "Message %s or one of its dependencies does not use proto2 syntax: %s in file %s",
        clazz.getName(),
        d.getFullName(),
        d.getFile().getName());
  }
}
项目:beam    文件:ProtobufUtilTest.java   
/** Helper used to test the recursive class traversal and print good error messages. */
private static Set<String> getRecursiveDescriptorFullNames(
    Class<? extends Message> clazz, ExtensionRegistry registry) {
  Set<String> result = new HashSet<>();
  for (GenericDescriptor d : getRecursiveDescriptorsForClass(clazz, registry)) {
    result.add(d.getFullName());
  }
  return result;
}
项目:closure-templates    文件:SoyProtoTypeProvider.java   
/** Registers a collection of descriptors of any type. */
public Builder addDescriptors(Iterable<? extends GenericDescriptor> descriptorsToAdd) {
  for (GenericDescriptor descriptorToAdd : descriptorsToAdd) {
    descriptors.add(descriptorToAdd);
  }
  return this;
}
项目:closure-templates    文件:SoyProtoTypeProvider.java   
@Override
public SoyType getType(String name, SoyTypeRegistry typeRegistry) {
  GenericDescriptor descriptor = descriptors.get(name);
  if (descriptor == null) {
    return null;
  }
  return doGetType(name, typeRegistry, descriptor);
}
项目:closure-templates    文件:ProtoUtils.java   
static String calculateQualifiedJsName(GenericDescriptor descriptor) {
  String protoPackage = descriptor.getFile().getPackage();
  // We need a semi-qualified name: including containing types but not the package.
  String name = descriptor.getFullName();
  if (!name.startsWith(protoPackage)) {
    throw new AssertionError("Expected \"" + name + "\" to start with \"" + protoPackage + "\"");
  }
  String jsPackage = getJsPackage(descriptor.getFile());
  // When there is no protoPackage, the semi-qualified name does not have a package prefix nor the
  // "." separator.
  if (protoPackage.isEmpty()) {
    return jsPackage + "." + name;
  }
  return jsPackage + name.substring(protoPackage.length());
}
项目:rejoiner    文件:ProtoToGql.java   
/** Returns the GraphQL name of the supplied proto. */
static String getReferenceName(GenericDescriptor descriptor) {
  return CharMatcher.anyOf(".").replaceFrom(descriptor.getFullName(), "_");
}
项目:rejoiner    文件:ProtoToGql.java   
/** Returns a reference to the GraphQL type corresponding to the supplied proto. */
static GraphQLTypeReference getReference(GenericDescriptor descriptor) {
  return new GraphQLTypeReference(getReferenceName(descriptor));
}
项目:rejoiner    文件:Type.java   
/** Finds the GraphQL type for a Proto descriptor. */
public static ModifiableType find(GenericDescriptor typeDescriptor) {
  return new ModifiableType(ProtoToGql.getReferenceName(typeDescriptor));
}
项目:rejoiner    文件:GqlInputConverter.java   
static String getReferenceName(GenericDescriptor descriptor) {
  return "Input_" + ProtoToGql.getReferenceName(descriptor);
}
项目:closure-templates    文件:SoyProtoTypeProvider.java   
/** Registers a collection of descriptors of any type. */
public Builder addDescriptors(GenericDescriptor... descriptorsToAdd) {
  Collections.addAll(descriptors, descriptorsToAdd);
  return this;
}
项目:closure-templates    文件:DescriptorTreeWalker.java   
final void walkDescriptors(Iterable<? extends GenericDescriptor> descriptors) {
  for (GenericDescriptor descriptor : descriptors) {
    walkDescriptor(descriptor);
  }
}
项目:closure-templates    文件:SoyFileSet.java   
/**
 * Registers a collection of protocol buffer descriptors. This makes all the types defined in
 * the provided descriptors available to use in soy.
 */
public Builder addProtoDescriptors(Iterable<? extends GenericDescriptor> descriptors) {
  protoTypeProviderBuilder.addDescriptors(descriptors);
  return this;
}
项目:closure-templates    文件:SoyFileSet.java   
/**
 * Registers a collection of protocol buffer descriptors. This makes all the types defined in
 * the provided descriptors available to use in soy.
 */
public Builder addProtoDescriptors(GenericDescriptor... descriptors) {
  return addProtoDescriptors(Arrays.asList(descriptors));
}