Search in sources :

Example 6 with Location

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Location(com.squareup.wire.schema.Location)

Example 7 with Location

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Location(com.squareup.wire.schema.Location)

Example 8 with Location

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")));
}
Also used : FileSystem(java.nio.file.FileSystem) Location(com.squareup.wire.schema.Location) Test(org.junit.Test)

Example 9 with Location

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")));
}
Also used : FileSystem(java.nio.file.FileSystem) Location(com.squareup.wire.schema.Location) Test(org.junit.Test)

Aggregations

Location (com.squareup.wire.schema.Location)9 ImmutableList (com.google.common.collect.ImmutableList)2 FileSystem (java.nio.file.FileSystem)2 Test (org.junit.Test)2 ProfileFileElement (com.squareup.wire.java.internal.ProfileFileElement)1 ProfileParser (com.squareup.wire.java.internal.ProfileParser)1 ProtoFile (com.squareup.wire.schema.ProtoFile)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 LinkedHashSet (java.util.LinkedHashSet)1 Source (okio.Source)1