use of com.squareup.wire.schema.Location in project wire by square.
the class ProtoParser method readOneOf.
private OneOfElement readOneOf(String documentation) {
OneOfElement.Builder builder = OneOfElement.builder().name(reader.readName()).documentation(documentation);
ImmutableList.Builder<FieldElement> fields = ImmutableList.builder();
ImmutableList.Builder<GroupElement> groups = ImmutableList.builder();
reader.require('{');
while (true) {
String nestedDocumentation = reader.readDocumentation();
if (reader.peekChar('}'))
break;
Location location = reader.location();
String type = reader.readDataType();
if (type.equals("group")) {
groups.add(readGroup(nestedDocumentation, null));
} else {
fields.add(readField(location, nestedDocumentation, null, type));
}
}
return builder.fields(fields.build()).groups(groups.build()).build();
}
use of com.squareup.wire.schema.Location in project wire by square.
the class ProtoParser method readGroup.
private GroupElement readGroup(String documentation, Field.Label label) {
String name = reader.readWord();
reader.require('=');
int tag = reader.readInt();
GroupElement.Builder builder = GroupElement.builder().label(label).name(name).tag(tag).documentation(documentation);
ImmutableList.Builder<FieldElement> fields = ImmutableList.builder();
reader.require('{');
while (true) {
String nestedDocumentation = reader.readDocumentation();
if (reader.peekChar('}'))
break;
Location location = reader.location();
String fieldLabel = reader.readWord();
Object field = readField(nestedDocumentation, location, fieldLabel);
if (!(field instanceof FieldElement)) {
throw reader.unexpected("expected field declaration, was " + field);
}
fields.add((FieldElement) field);
}
return builder.fields(fields.build()).build();
}
use of com.squareup.wire.schema.Location in project wire by square.
the class ProfileLoaderTest method pathsToAttempt.
@Test
public void pathsToAttempt() throws Exception {
FileSystem fileSystem = FileSystems.getDefault();
ImmutableSet<Location> locations = ImmutableSet.of(Location.get("/a/b", "c/d/e.proto"));
ProfileLoader loader = new ProfileLoader(fileSystem, "android");
assertThat(loader.pathsToAttempt(locations).asMap()).containsExactly(MapEntry.entry(fileSystem.getPath("/a/b"), ImmutableSet.of("c/d/android.wire", "c/android.wire", "android.wire")));
}
use of com.squareup.wire.schema.Location in project wire by square.
the class ProfileLoaderTest method pathsToAttemptMultipleRoots.
@Test
public void pathsToAttemptMultipleRoots() throws Exception {
FileSystem fileSystem = FileSystems.getDefault();
ImmutableSet<Location> locations = ImmutableSet.of(Location.get("/a/b", "c/d/e.proto"), Location.get("/a/b", "c/f/g/h.proto"), Location.get("/i/j.zip", "k/l/m.proto"), Location.get("/i/j.zip", "k/l/m/n.proto"));
ProfileLoader loader = new ProfileLoader(fileSystem, "android");
assertThat(loader.pathsToAttempt(locations).asMap()).containsExactly(MapEntry.entry(fileSystem.getPath("/a/b"), ImmutableSet.of("c/d/android.wire", "c/android.wire", "android.wire", "c/f/g/android.wire", "c/f/android.wire")), MapEntry.entry(fileSystem.getPath("/i/j.zip"), ImmutableSet.of("k/l/android.wire", "k/android.wire", "android.wire", "k/l/m/android.wire")));
}
Aggregations