SingularFieldAccessor( final FieldDescriptor descriptor, final String camelCaseName, final Class<? extends GeneratedMessageV3> messageClass, final Class<? extends Builder> builderClass, final String containingOneofCamelCaseName) { field = descriptor; isOneofField = descriptor.getContainingOneof() != null; hasHasMethod = supportFieldPresence(descriptor.getFile()) || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE); getMethod = getMethodOrDie(messageClass, "get" + camelCaseName); getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName); type = getMethod.getReturnType(); setMethod = getMethodOrDie(builderClass, "set" + camelCaseName, type); hasMethod = hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null; hasMethodBuilder = hasHasMethod ? getMethodOrDie(builderClass, "has" + camelCaseName) : null; clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); caseMethod = isOneofField ? getMethodOrDie( messageClass, "get" + containingOneofCamelCaseName + "Case") : null; caseMethodBuilder = isOneofField ? getMethodOrDie( builderClass, "get" + containingOneofCamelCaseName + "Case") : null; }
SingularFieldAccessor( final FieldDescriptor descriptor, final String camelCaseName, final Class<? extends GeneratedMessage> messageClass, final Class<? extends Builder> builderClass, final String containingOneofCamelCaseName) { field = descriptor; isOneofField = descriptor.getContainingOneof() != null; hasHasMethod = supportFieldPresence(descriptor.getFile()) || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE); getMethod = getMethodOrDie(messageClass, "get" + camelCaseName); getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName); type = getMethod.getReturnType(); setMethod = getMethodOrDie(builderClass, "set" + camelCaseName, type); hasMethod = hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null; hasMethodBuilder = hasHasMethod ? getMethodOrDie(builderClass, "has" + camelCaseName) : null; clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); caseMethod = isOneofField ? getMethodOrDie( messageClass, "get" + containingOneofCamelCaseName + "Case") : null; caseMethodBuilder = isOneofField ? getMethodOrDie( builderClass, "get" + containingOneofCamelCaseName + "Case") : null; }
while (input.getBytesUntilLimit() > 0) { final int rawValue = input.readEnum(); if (field.getFile().supportsUnknownEnumValue()) { target.addRepeatedField(field, field.getEnumType().findValueByNumberCreatingIfUnknown(rawValue)); if (field.getFile().supportsUnknownEnumValue()) { value = field.getEnumType().findValueByNumberCreatingIfUnknown(rawValue); } else {
/** Does this field have the {@code [packed = true]} option or is this field * packable in proto3 and not explicitly setted to unpacked? */ @Override public boolean isPacked() { if (!isPackable()) { return false; } if (getFile().getSyntax() == FileDescriptor.Syntax.PROTO2) { return getOptions().getPacked(); } else { return !getOptions().hasPacked() || getOptions().getPacked(); } }
/** * Returns whether or not we should check for presence to emulate jspb nullability semantics in * server side soy. */ static boolean shouldCheckFieldPresenceToEmulateJspbNullability(FieldDescriptor desc) { boolean hasBrokenSemantics = false; if (desc.hasDefaultValue() || desc.isRepeated()) { return false; } else if (desc.getFile().getSyntax() == Syntax.PROTO3 || !hasBrokenSemantics) { // in proto3 or proto2 with non-broken semantics we only need to check for presence for // message typed fields. return desc.getJavaType() == JavaType.MESSAGE; } else { return true; } }
/** For internal use only. */ public boolean needsUtf8Check() { return (type == Type.STRING) && (getFile().getOptions().getJavaStringCheckUtf8()); }
/** * Proto3 enums fields can accept and return unknown values via the get<Field>Value() methods, we * use those methods instead of the methods that deal with the enum constants in order to support * unknown enum values. If we didn't, any field with an unknown enum value would throw an * exception when we call {@code getNumber()} on the enum. * * <p>For comparison, in proto2 unknown values always get mapped to 0, so this problem doesn't * exist. Also, in proto2, the 'Value' functions don't exist, so we can't use them. */ private static boolean isProto3EnumField(FieldDescriptor descriptor) { return descriptor.getType() == Descriptors.FieldDescriptor.Type.ENUM && descriptor.getFile().getSyntax() == Syntax.PROTO3; }
/** Returns the JS name of the extension, suitable for passing to getExtension(). */ public static String getJsExtensionName(FieldDescriptor desc) { Descriptor scope = desc.getExtensionScope(); if (scope != null) { return calculateQualifiedJsName(scope) + "." + computeJsExtensionName(desc); } return getJsPackage(desc.getFile()) + "." + computeJsExtensionName(desc); }
/** * Proto3 enums fields can accept and return unknown values via the get<Field>Value() methods, we * use those methods instead of the methods that deal with the enum constants in order to support * unknown enum values. If we didn't, any field with an unknown enum value would throw an * exception when we call {@code getNumber()} on the enum. * * <p>For comparison, in proto2 unknown values always get mapped to 0, so this problem doesn't * exist. Also, in proto2, the 'Value' functions don't exist, so we can't use them. */ private static boolean isProto3EnumField(FieldDescriptor descriptor) { return descriptor.getType() == Descriptors.FieldDescriptor.Type.ENUM && descriptor.getFile().getSyntax() == Syntax.PROTO3; }
/** Returns the JS name of the import for the given extension, suitable for goog.require. */ public static String getJsExtensionImport(FieldDescriptor desc) { Descriptor scope = desc.getExtensionScope(); if (scope != null) { while (scope.getContainingType() != null) { scope = scope.getContainingType(); } return calculateQualifiedJsName(scope); } return getJsPackage(desc.getFile()) + "." + computeJsExtensionName(desc); }
/** Returns the JS name of the import for the given extension, suitable for goog.require. */ public static String getJsExtensionImport(FieldDescriptor desc) { Descriptor scope = desc.getExtensionScope(); if (scope != null) { while (scope.getContainingType() != null) { scope = scope.getContainingType(); } return calculateQualifiedJsName(scope); } return getJsPackage(desc.getFile()) + "." + computeJsExtensionName(desc); }
/** Returns the JS name of the extension, suitable for passing to getExtension(). */ public static String getJsExtensionName(FieldDescriptor desc) { Descriptor scope = desc.getExtensionScope(); if (scope != null) { return calculateQualifiedJsName(scope) + "." + computeJsExtensionName(desc); } return getJsPackage(desc.getFile()) + "." + computeJsExtensionName(desc); }
!fieldDescriptor.isRepeated() && fieldDescriptor.getContainingOneof() == null && fieldDescriptor.getFile().getSyntax() == Syntax.PROTO3; boolean ignoreFieldAbsence = isNonRepeatedProto3
} else if (field.getFile().getSyntax() == Descriptors.FileDescriptor.Syntax.PROTO3) { if (!field.isRepeated() && field.getJavaType() != FieldDescriptor.JavaType.MESSAGE
RepeatedEnumFieldAccessor( final FieldDescriptor descriptor, final String camelCaseName, final Class<? extends GeneratedMessage> messageClass, final Class<? extends Builder> builderClass) { super(descriptor, camelCaseName, messageClass, builderClass); enumDescriptor = descriptor.getEnumType(); valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue(); if (supportUnknownEnumValue) { getRepeatedValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class); getRepeatedValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class); setRepeatedValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class); addRepeatedValueMethod = getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class); } } private EnumDescriptor enumDescriptor;
SingularEnumFieldAccessor( final FieldDescriptor descriptor, final String camelCaseName, final Class<? extends GeneratedMessage> messageClass, final Class<? extends Builder> builderClass, final String containingOneofCamelCaseName) { super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); enumDescriptor = descriptor.getEnumType(); valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue(); if (supportUnknownEnumValue) { getValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value"); getValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value"); setValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class); } }
RepeatedEnumFieldAccessor( final FieldDescriptor descriptor, final String camelCaseName, final Class<? extends GeneratedMessageV3> messageClass, final Class<? extends Builder> builderClass) { super(descriptor, camelCaseName, messageClass, builderClass); enumDescriptor = descriptor.getEnumType(); valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue(); if (supportUnknownEnumValue) { getRepeatedValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class); getRepeatedValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class); setRepeatedValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class); addRepeatedValueMethod = getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class); } } private EnumDescriptor enumDescriptor;
SingularEnumFieldAccessor( final FieldDescriptor descriptor, final String camelCaseName, final Class<? extends GeneratedMessageV3> messageClass, final Class<? extends Builder> builderClass, final String containingOneofCamelCaseName) { super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); enumDescriptor = descriptor.getEnumType(); valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue(); if (supportUnknownEnumValue) { getValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value"); getValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value"); setValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class); } }
/** For internal use only. */ public boolean needsUtf8Check() { if (type != Type.STRING) { return false; } if (getContainingType().getOptions().getMapEntry()) { // Always enforce strict UTF-8 checking for map fields. return true; } if (getFile().getSyntax() == Syntax.PROTO3) { return true; } return getFile().getOptions().getJavaStringCheckUtf8(); }
/** Does this field have the {@code [packed = true]} option or is this field * packable in proto3 and not explicitly setted to unpacked? */ @Override public boolean isPacked() { if (!isPackable()) { return false; } if (getFile().getSyntax() == FileDescriptor.Syntax.PROTO2) { return getOptions().getPacked(); } else { return !getOptions().hasPacked() || getOptions().getPacked(); } }