/** * Construct a field selector by resolving a field path (as in 'a.b.c') against a message. Returns * null if resolution fails. */ public static FieldSelector resolve(MessageType message, String fieldPath) { Iterator<String> path = FIELD_PATH_SPLITTER.split(fieldPath).iterator(); ImmutableList.Builder<Field> fieldsBuilder = ImmutableList.builder(); MessageType currMessage = message; while (path.hasNext()) { String fieldName = path.next(); Field field = currMessage.lookupField(fieldName); if (field == null) { return null; } fieldsBuilder.add(field); if (path.hasNext()) { if (!field.getType().isMessage()) { return null; } currMessage = field.getType().getMessageType(); } } return new FieldSelector(fieldsBuilder.build()); }
/** * Construct a field selector by resolving a field path (as in 'a.b.c') against a message. Returns * null if resolution fails. */ public static FieldSelector resolve(MessageType message, String fieldPath) { Iterator<String> path = FIELD_PATH_SPLITTER.split(fieldPath).iterator(); ImmutableList.Builder<Field> fieldsBuilder = ImmutableList.builder(); MessageType currMessage = message; while (path.hasNext()) { String fieldName = path.next(); Field field = currMessage.lookupField(fieldName); if (field == null) { return null; } fieldsBuilder.add(field); if (path.hasNext()) { if (!field.getType().isMessage()) { return null; } currMessage = field.getType().getMessageType(); } } return new FieldSelector(fieldsBuilder.build()); }
@Override public ProtoField getInputField(String fieldName) { Field inputField = method.getInputType().getMessageType().lookupField(fieldName); return inputField == null ? null : new ProtoField(inputField); }
@Override public ProtoField getOutputField(String fieldName) { Field outputField = method.getOutputType().getMessageType().lookupField(fieldName); return outputField == null ? null : new ProtoField(outputField); }
/** * Creates an instance of GrpcStreamingConfig for gRPC response streaming, based on * PageStreamingConfigProto, linking it up with the provided method. On errors, null will be * returned, and diagnostics are reported to the diag collector. * * <p>TODO: Create a separate GrpcStreamingConfigProto */ @Nullable public static GrpcStreamingConfig createGrpcStreaming( DiagCollector diagCollector, PageStreamingConfigProto pageStreaming, Method method) { String resourcesFieldName = pageStreaming.getResponse().getResourcesField(); Field resourcesField = method.getOutputType().getMessageType().lookupField(resourcesFieldName); GrpcStreamingType type = getGrpcStreamingType(diagCollector, method); if (type == null) { return null; } return new GrpcStreamingConfig(resourcesField, type); }
return ((MessageType) parent).lookupField(lastName);
Field matchingField = subMessageType.lookupField(fieldNameToken); if (matchingField == null) { throw new IllegalArgumentException(
return ((MessageType) parent).lookupField(lastName);
Mockito.when(nameField.getType()).thenReturn(TypeRef.fromPrimitiveName("string")); Mockito.when(nameField.getSimpleName()).thenReturn("name"); Mockito.when(createShelvesRequest.lookupField("book")).thenReturn(bookField); Mockito.when(createShelvesRequest.lookupField("name")).thenReturn(nameField); Mockito.when(createShelvesRequest.getFields()) .thenReturn(ImmutableList.of(bookField, nameField));