@Test public void fieldPath() throws Exception { assertThat(ProtobufDescriptorJavaUtil.fieldPath(TestRequest.getDescriptor(), "nt.nnt.f1")) .extracting(Descriptors.FieldDescriptor::getName) .isEqualTo(Lists.newArrayList("nt", "nnt", "f1")); }
public static ImmutableList<Descriptors.FieldDescriptor> fieldPath(Descriptors.Descriptor root, String path) { Iterable<String> pathSegments = Splitter.on('.').omitEmptyStrings().trimResults().split(path); Iterator<String> pathIterator = pathSegments.iterator(); Descriptors.Descriptor descriptor = root; Descriptors.FieldDescriptor current; ImmutableList.Builder<Descriptors.FieldDescriptor> pathList = ImmutableList.builder(); while (pathIterator.hasNext()) { String segment = pathIterator.next(); current = descriptor.findFieldByName(segment); if (current == null) { return ImmutableList.of(); } if (current.getType() != Descriptors.FieldDescriptor.Type.MESSAGE && pathIterator.hasNext()) { throw new IllegalArgumentException("Found non-complex datatype at " + segment + " in path: " + path + ": " + current); } if (current.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) { descriptor = current.getMessageType(); } pathList.add(current); } return pathList.build(); }
ProtobufDescriptorJavaUtil { public static ImmutableList<Descriptors.FieldDescriptor> fieldPath(Descriptors.Descriptor root, String path) { Iterable<String> pathSegments = Splitter.on('.').omitEmptyStrings().trimResults().split(path); Iterator<String> pathIterator = pathSegments.iterator(); Descriptors.Descriptor descriptor = root; Descriptors.FieldDescriptor current; ImmutableList.Builder<Descriptors.FieldDescriptor> pathList = ImmutableList.builder(); while (pathIterator.hasNext()) { String segment = pathIterator.next(); current = descriptor.findFieldByName(segment); if (current == null) { return ImmutableList.of(); } if (current.getType() != Descriptors.FieldDescriptor.Type.MESSAGE && pathIterator.hasNext()) { throw new IllegalArgumentException("Found non-complex datatype at " + segment + " in path: " + path + ": " + current); } if (current.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) { descriptor = current.getMessageType(); } pathList.add(current); } return pathList.build(); } }
ProtobufDescriptorJavaUtil { public static ImmutableList<Descriptors.FieldDescriptor> fieldPath(Descriptors.Descriptor root, String path) { Iterable<String> pathSegments = Splitter.on('.').omitEmptyStrings().trimResults().split(path); Iterator<String> pathIterator = pathSegments.iterator(); Descriptors.Descriptor descriptor = root; Descriptors.FieldDescriptor current; ImmutableList.Builder<Descriptors.FieldDescriptor> pathList = ImmutableList.builder(); while (pathIterator.hasNext()) { String segment = pathIterator.next(); current = descriptor.findFieldByName(segment); if (current == null) { return ImmutableList.of(); } if (current.getType() != Descriptors.FieldDescriptor.Type.MESSAGE && pathIterator.hasNext()) { throw new IllegalArgumentException("Found non-complex datatype at " + segment + " in path: " + path + ": " + current); } if (current.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) { descriptor = current.getMessageType(); } pathList.add(current); } return pathList.build(); } private  ProtobufDescriptorJavaUtil(); }
ProtobufDescriptorJavaUtil { public static ImmutableList<Descriptors.FieldDescriptor> fieldPath(Descriptors.Descriptor root, String path) { Iterable<String> pathSegments = Splitter.on('.').omitEmptyStrings().trimResults().split(path); Iterator<String> pathIterator = pathSegments.iterator(); Descriptors.Descriptor descriptor = root; Descriptors.FieldDescriptor current; ImmutableList.Builder<Descriptors.FieldDescriptor> pathList = ImmutableList.builder(); while (pathIterator.hasNext()) { String segment = pathIterator.next(); current = descriptor.findFieldByName(segment); if (current == null) { return ImmutableList.of(); } if (current.getType() != Descriptors.FieldDescriptor.Type.MESSAGE && pathIterator.hasNext()) { throw new IllegalArgumentException("Found non-complex datatype at " + segment + " in path: " + path + ": " + current); } if (current.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) { descriptor = current.getMessageType(); } pathList.add(current); } return pathList.build(); } private  ProtobufDescriptorJavaUtil(); static String javaPackage(DescriptorProtos.FileDescriptorProto fd); static String grpcImplBaseClass(DescriptorProtos.FileDescriptorProto fd,
            DescriptorProtos.ServiceDescriptorProto sdp); static String grpcStubClass(DescriptorProtos.FileDescriptorProto fd,
            DescriptorProtos.ServiceDescriptorProto sdp); static String jerseyResourceClassName(DescriptorProtos.ServiceDescriptorProto sdp); static String genClassName(Descriptors.Descriptor descriptor); static ImmutableList<Descriptors.FieldDescriptor> fieldPath(Descriptors.Descriptor root, String path); }
ProtobufDescriptorJavaUtil { public static ImmutableList<Descriptors.FieldDescriptor> fieldPath(Descriptors.Descriptor root, String path) { Iterable<String> pathSegments = Splitter.on('.').omitEmptyStrings().trimResults().split(path); Iterator<String> pathIterator = pathSegments.iterator(); Descriptors.Descriptor descriptor = root; Descriptors.FieldDescriptor current; ImmutableList.Builder<Descriptors.FieldDescriptor> pathList = ImmutableList.builder(); while (pathIterator.hasNext()) { String segment = pathIterator.next(); current = descriptor.findFieldByName(segment); if (current == null) { return ImmutableList.of(); } if (current.getType() != Descriptors.FieldDescriptor.Type.MESSAGE && pathIterator.hasNext()) { throw new IllegalArgumentException("Found non-complex datatype at " + segment + " in path: " + path + ": " + current); } if (current.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) { descriptor = current.getMessageType(); } pathList.add(current); } return pathList.build(); } private  ProtobufDescriptorJavaUtil(); static String javaPackage(DescriptorProtos.FileDescriptorProto fd); static String grpcImplBaseClass(DescriptorProtos.FileDescriptorProto fd,
            DescriptorProtos.ServiceDescriptorProto sdp); static String grpcStubClass(DescriptorProtos.FileDescriptorProto fd,
            DescriptorProtos.ServiceDescriptorProto sdp); static String jerseyResourceClassName(DescriptorProtos.ServiceDescriptorProto sdp); static String genClassName(Descriptors.Descriptor descriptor); static ImmutableList<Descriptors.FieldDescriptor> fieldPath(Descriptors.Descriptor root, String path);  }