本文整理汇总了Java中com.google.protobuf.Descriptors.FieldDescriptor.JavaType类的典型用法代码示例。如果您正苦于以下问题:Java JavaType类的具体用法?Java JavaType怎么用?Java JavaType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaType类属于com.google.protobuf.Descriptors.FieldDescriptor包,在下文中一共展示了JavaType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueMethod
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
/**
* Returns the method to get the value for the field within its message. The message must already
* be on the execution stack. For map fields, this will be the method that returns a {@link
* java.util.Map} and for repeated fields it will be the method that returns a {@link List}.
*/
Method getValueMethod() {
StringBuilder methodName = new StringBuilder().append("get").append(camelCaseName);
if (valueJavaType() == JavaType.ENUM) {
methodName.append("Value");
}
if (isMapField()) {
methodName.append("Map");
} else if (field.isRepeated()) {
methodName.append("List");
}
try {
return containingPrototype.getClass().getDeclaredMethod(methodName.toString());
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Could not find generated getter method.", e);
}
}
示例2: javaClass
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
/**
* Return the Java {@link Class} that corresponds to the value of this field. Generally used for
* method resolution and casting generics.
*/
Class<?> javaClass() {
if (isMapField() && valueJavaType() == JavaType.MESSAGE) {
Message mapEntry = containingPrototype.newBuilderForType().newBuilderForField(field).build();
return mapEntry.getField(mapEntry.getDescriptorForType().findFieldByName("value")).getClass();
}
switch (valueJavaType()) {
case INT:
return int.class;
case LONG:
return long.class;
case FLOAT:
return float.class;
case DOUBLE:
return double.class;
case BOOLEAN:
return boolean.class;
case STRING:
return String.class;
case BYTE_STRING:
return ByteString.class;
case ENUM:
return int.class;
case MESSAGE:
return containingPrototype
.newBuilderForType()
.newBuilderForField(valueField().descriptor())
.build()
.getClass();
default:
throw new IllegalArgumentException("Unknown field type: " + valueJavaType());
}
}
示例3: getValue
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
@Override
public Object getValue(final ELContext context, final Object base, final Object property) {
if (context == null) {
throw new NullPointerException();
}
if ((property != null) && resolveType(base)) {
context.setPropertyResolved(base, property);
final Message.Builder builder = (Message.Builder) base;
final FieldDescriptor field = getPropertyFieldDescriptor(builder, property);
if (field.isRepeated()) {
return getBuilderForRepeatedField(builder, field);
} else {
if (field.getJavaType() == JavaType.MESSAGE) {
return builder.getFieldBuilder(field);
} else {
return builder.getField(field);
}
}
}
return null;
}
示例4: getBuilderForRepeatedChild
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static final IRepeatedFieldMessageBuilder getBuilderForRepeatedChild(
final Message.Builder builder, final FieldDescriptor field) {
if (!field.isRepeated()) {
throw new IllegalArgumentException("the field must be repeated");
} else if (field.getJavaType() != JavaType.MESSAGE) {
throw new IllegalArgumentException("the field must be of Message type");
} else if (builder.getDescriptorForType() != field.getContainingType()) {
throw new IllegalArgumentException("the field doen't belong to this type");
}
if (builder instanceof GeneratedMessage.Builder) {
final GeneratedMessage.Builder<?> generatedBuilder = (GeneratedMessage.Builder<?>) builder;
return getGeneratedRepeatedFieldBuilder(generatedBuilder, field, generatedBuilder.getClass());
} else if (builder instanceof IBuilder2) {
return new DynamicRepeatedFieldMessageBuilder((IBuilder2) builder, field);
} else {
throw new IllegalArgumentException("builder is not of a supported Builder type");
}
}
示例5: addField
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
@SuppressWarnings({"null", "unchecked"})
private void addField(final Message.Builder builder, final FieldDescriptor field,
final Object value, final Replacer replacer,
final LinkedList<Entry<FieldDescriptor, MessageOrBuilder>> path) {
if (field.getJavaType() == JavaType.MESSAGE) {
if (field.isRepeated()) {
for (final Message message : (List<Message>) value) {
builder.addRepeatedField(field, getMessage(field, message, replacer, path));
}
} else {
builder.setField(field, getMessage(field, (Message) value, replacer, path));
}
} else {
builder.setField(field, getValue(field, value, replacer, path));
}
}
示例6: addField
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
@SuppressWarnings({"null", "unchecked"})
private boolean addField(final Message.Builder protoBuilder, final FieldDescriptor field,
final Object value, final Iterable<Pattern> skipPatterns) {
if (isSkip(field.getFullName(), skipPatterns)) {
return false;
}
if (field.getJavaType() == JavaType.MESSAGE) {
if (field.isRepeated()) {
for (final Message message : (List<Message>) value) {
protoBuilder.addRepeatedField(field, getMessage(message, skipPatterns));
}
} else {
protoBuilder.setField(field, getMessage((Message) value, skipPatterns));
}
} else {
protoBuilder.setField(field, value);
}
return true;
}
示例7: putField
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
public FieldDescriptor putField(String descriptorShortName, String fieldShortName,
int index, boolean isRepeated, JavaType type, String fieldMessageTypeName) {
String descriptorFullName = getFullName(descriptorShortName);
MockDescriptorEntry fieldMap = descriptorMap.get(descriptorFullName);
FieldDescriptor field = null;
if (fieldMap == null) {
fieldMap = new MockDescriptorEntry(createMockDescriptor(descriptorShortName));
descriptorMap.put(descriptorFullName, fieldMap);
} else {
field = fieldMap.getField(fieldShortName);
}
if (field == null) {
field = createMockField(fieldShortName, index, isRepeated, type,
fieldMap.getDescriptor(), fieldMessageTypeName);
fieldMap.putField(fieldShortName, field);
}
return field;
}
示例8: addField
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
private <T> Builder<? extends Builder<?, GroupBuilder<T>>, GroupBuilder<T>> addField(Descriptors.FieldDescriptor descriptor, GroupBuilder<T> builder) {
Type.Repetition repetition = getRepetition(descriptor);
JavaType javaType = descriptor.getJavaType();
switch (javaType) {
case BOOLEAN: return builder.primitive(BOOLEAN, repetition);
case INT: return builder.primitive(INT32, repetition);
case LONG: return builder.primitive(INT64, repetition);
case FLOAT: return builder.primitive(FLOAT, repetition);
case DOUBLE: return builder.primitive(DOUBLE, repetition);
case BYTE_STRING: return builder.primitive(BINARY, repetition);
case STRING: return builder.primitive(BINARY, repetition).as(UTF8);
case MESSAGE: {
GroupBuilder<GroupBuilder<T>> group = builder.group(repetition);
convertFields(group, descriptor.getMessageType().getFields());
return group;
}
case ENUM: return builder.primitive(BINARY, repetition).as(ENUM);
default:
throw new UnsupportedOperationException("Cannot convert Protocol Buffer: unknown type " + javaType);
}
}
示例9: getJavaType
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
protected Class<?> getJavaType(FieldDescriptor fieldDescriptor) {
if (fieldDescriptor.getJavaType() == JavaType.BOOLEAN) {
return Boolean.class;
} else if (fieldDescriptor.getJavaType() == JavaType.BYTE_STRING) {
return DataHandler.class;
} else if (fieldDescriptor.getJavaType() == JavaType.DOUBLE) {
return Double.class;
} else if (fieldDescriptor.getJavaType() == JavaType.FLOAT) {
return Float.class;
} else if (fieldDescriptor.getJavaType() == JavaType.INT) {
return Integer.class;
} else if (fieldDescriptor.getJavaType() == JavaType.LONG) {
return Long.class;
} else if (fieldDescriptor.getJavaType() == JavaType.STRING) {
return String.class;
} else if (fieldDescriptor.getJavaType() == JavaType.ENUM) {
try {
return Class.forName("org.bimserver.interfaces.objects." + fieldDescriptor.getEnumType().getName());
} catch (ClassNotFoundException e) {
LOGGER.error("", e);
}
}
return null;
}
示例10: getJavaPrimitiveType
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
protected Class<?> getJavaPrimitiveType(FieldDescriptor fieldDescriptor) {
if (fieldDescriptor.getJavaType() == JavaType.BOOLEAN) {
return boolean.class;
} else if (fieldDescriptor.getJavaType() == JavaType.BYTE_STRING) {
return DataHandler.class;
} else if (fieldDescriptor.getJavaType() == JavaType.DOUBLE) {
return double.class;
} else if (fieldDescriptor.getJavaType() == JavaType.FLOAT) {
return float.class;
} else if (fieldDescriptor.getJavaType() == JavaType.INT) {
return int.class;
} else if (fieldDescriptor.getJavaType() == JavaType.LONG) {
return long.class;
} else if (fieldDescriptor.getJavaType() == JavaType.STRING) {
return String.class;
} else if (fieldDescriptor.getJavaType() == JavaType.ENUM) {
try {
return Class.forName("org.bimserver.interfaces.objects." + fieldDescriptor.getEnumType().getName());
} catch (ClassNotFoundException e) {
LOGGER.error("", e);
}
}
return null;
}
示例11: populateRepeatedPrimitiveSchema
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
/**
* Populates a JSON schema for a repeated primitive proto field.
*
* @param field the field being considered
* @param property the JSON schema being built
*/
private void populateRepeatedPrimitiveSchema(FieldDescriptor field,
JsonSchema.Builder property) {
property.setType(JsonType.ARRAY);
JsonSchema.Builder itemsSchema = JsonSchema.newBuilder();
if (treatLongsAsStrings && field.getJavaType().equals(JavaType.LONG)
&& !transforms.containsKey(field.getName())) {
itemsSchema.setType(JsonType.STRING);
if (field.getType().equals(Type.UINT64) || field.getType().equals(Type.FIXED64)) {
itemsSchema.setFormat(UINT64_STRING_FORMAT);
} else {
itemsSchema.setFormat(INT64_STRING_FORMAT);
}
} else {
itemsSchema.setType(getReifiedFieldType(field));
}
property.setItems(itemsSchema);
if (field.getType().equals(Type.ENUM)) {
for (EnumValueDescriptor enumValue : field.getEnumType().getValues()) {
property.addEnum(PROTO_ENUM_CASE_FORMAT.to(
enumCaseFormat, enumValue.getName()));
}
}
}
示例12: setFieldValue
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
/**
* Returns the {@link StackManipulation} for setting the value of a field. This will be all the
* elements for a repeated field.
*
* @param info description of the field to set.
* @param beforeReadField jump target for before reading a field, used once this field is
* completed being set.
* @param locals the method local variables
* @param fieldsByName the instance fields
*/
private StackManipulation setFieldValue(
ProtoFieldInfo info,
Label beforeReadField,
LocalVariables<LocalVariable> locals,
Map<String, FieldDescription> fieldsByName) {
if (info.isMapField()) {
return setMapFieldValue(info, beforeReadField, locals, fieldsByName);
} else {
final StackManipulation setConcreteValue = invoke(info.setValueMethod());
final StackManipulation setSingleValue;
if (info.valueJavaType() == JavaType.MESSAGE) {
setSingleValue =
new StackManipulation.Compound(
TypeCasting.to(new ForLoadedType(info.javaClass())), setConcreteValue);
} else {
setSingleValue = setConcreteValue;
}
if (info.descriptor().isRepeated()) {
return setRepeatedFieldValue(info, beforeReadField, locals, fieldsByName, setSingleValue);
} else {
// Set a singular value, e.g.,
// builder.setFoo(readValue());
return new StackManipulation.Compound(
locals.load(LocalVariable.builder),
locals.load(LocalVariable.parser),
readValue(info, fieldsByName, locals),
setSingleValue,
Removal.SINGLE,
new Goto(beforeReadField));
}
}
}
示例13: setMapFieldValue
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
/**
* Returns the {@link StackManipulation} for setting the value of a map field.
*
* <p>Roughly equivalent to:
*
* <pre>{@code
* ParseSupport.parseObjectStart(parser);
* while (!ParseSupport.checkObjectEnd(parser.currentToken())) {
* builder.putFoo(readKey(), readValue());
* }
* }</pre>
*/
private StackManipulation setMapFieldValue(
ProtoFieldInfo info,
Label beforeReadField,
LocalVariables<LocalVariable> locals,
Map<String, FieldDescription> fieldsByName) {
final StackManipulation setConcreteValue = invoke(info.setValueMethod());
final StackManipulation setMapEntry;
if (info.valueJavaType() == JavaType.MESSAGE) {
setMapEntry =
new StackManipulation.Compound(
TypeCasting.to(new ForLoadedType(info.javaClass())), setConcreteValue);
} else {
setMapEntry = setConcreteValue;
}
Label mapStart = new Label();
return new StackManipulation.Compound(
locals.load(LocalVariable.parser),
ParseSupport_parseObjectStart,
new SetJumpTargetLabel(mapStart),
locals.load(LocalVariable.parser),
Parser_currentToken,
ParseSupport_checkObjectEnd,
new IfTrue(beforeReadField),
locals.load(LocalVariable.builder),
locals.load(LocalVariable.parser),
readValue(info.mapKeyField(), fieldsByName, locals),
locals.load(LocalVariable.parser),
Parser_nextToken,
Removal.SINGLE,
locals.load(LocalVariable.parser),
readValue(info, fieldsByName, locals),
setMapEntry,
Removal.SINGLE,
locals.load(LocalVariable.parser),
Parser_nextToken,
Removal.SINGLE,
new Goto(mapStart));
}
示例14: collectMessages
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
/**
* Collects messages referred to by a message and its nested messages.
*
* @return {@code referenced}
*/
private static Collection<Descriptor> collectMessages(
Descriptor message, Collection<Descriptor> referenced) {
for (FieldDescriptor fd : message.getFields()) {
if (fd.getJavaType() == JavaType.MESSAGE) {
referenced.add(fd.getMessageType());
}
}
for (Descriptor nd : message.getNestedTypes()) {
collectMessages(nd, referenced);
}
return referenced;
}
示例15: collectEnums
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType; //导入依赖的package包/类
/**
* Collects enums referred to by a message and its nested messages.
*
* @return {@code referenced}
*/
private static Collection<EnumDescriptor> collectEnums(
Descriptor d, Collection<EnumDescriptor> referenced) {
for (FieldDescriptor fd : d.getFields()) {
if (fd.getJavaType() == JavaType.ENUM) {
referenced.add(fd.getEnumType());
}
}
for (Descriptor nd : d.getNestedTypes()) {
collectEnums(nd, referenced);
}
return referenced;
}