ProtoParser(Location location, char[] data) { this.reader = new SyntaxReader(data, location); this.fileBuilder = ProtoFileElement.builder(location); }
/** Reads a non-whitespace character and returns it. */ public char readChar() { char result = peekChar(); pos++; return result; }
/** Reads a quoted or unquoted string and returns it. */ public String readString() { skipWhitespace(true); char c = peekChar(); return c == '"' || c == '\'' ? readQuotedString() : readWord(); }
@Test public void addMultipleOptions() { OptionElement kitKat = OptionElement.create("kit", STRING, "kat"); OptionElement fooBar = OptionElement.create("foo", STRING, "bar"); EnumElement element = EnumElement.builder(location) .name("Enum") .options(ImmutableList.of(kitKat, fooBar)) .constants(ImmutableList.of( EnumConstantElement.builder(location).name("ONE").tag(1).build())) .build(); assertThat(element.options()).hasSize(2); }
public static Builder builder(Location location) { return new AutoValue_MessageElement.Builder() .location(location) .documentation("") .fields(ImmutableList.<FieldElement>of()) .oneOfs(ImmutableList.<OneOfElement>of()) .nestedTypes(ImmutableList.<TypeElement>of()) .extensions(ImmutableList.<ExtensionsElement>of()) .options(ImmutableList.<OptionElement>of()) .reserveds(ImmutableList.<ReservedElement>of()) .groups(ImmutableList.<GroupElement>of()); }
/** Reads an enum constant like "ROCK = 0;". The label is the constant name. */ private EnumConstantElement readEnumConstant( String documentation, Location location, String label) { reader.require('='); int tag = reader.readInt(); ImmutableList<OptionElement> options = new OptionReader(reader).readOptions(); reader.require(';'); documentation = reader.tryAppendTrailingDocumentation(documentation); return EnumConstantElement.builder(location) .name(label) .tag(tag) .documentation(documentation) .options(options) .build(); }
@Test public void addMultipleOptions() { TypeElement element = MessageElement.builder(location).name("Message").build(); OptionElement kitKat = OptionElement.create("kit", Kind.STRING, "kat"); OptionElement fooBar = OptionElement.create("foo", Kind.STRING, "bar"); ProtoFileElement file = ProtoFileElement.builder(location) .options(ImmutableList.of(kitKat, fooBar)) .types(ImmutableList.of(element)) .build(); assertThat(file.options()).hasSize(2); }
public static Builder builder(Location location) { return new AutoValue_ProtoFileElement.Builder() .location(location) .imports(ImmutableList.<String>of()) .publicImports(ImmutableList.<String>of()) .types(ImmutableList.<TypeElement>of()) .services(ImmutableList.<ServiceElement>of()) .extendDeclarations(ImmutableList.<ExtendElement>of()) .options(ImmutableList.<OptionElement>of()); }
public static Builder builder(Location location) { return new AutoValue_RpcElement.Builder() .documentation("") .location(location) .requestStreaming(false) .responseStreaming(false) .options(ImmutableList.<OptionElement>of()); }
public static Builder builder(Location location) { return new AutoValue_ServiceElement.Builder() .location(location) .documentation("") .rpcs(ImmutableList.<RpcElement>of()) .options(ImmutableList.<OptionElement>of()); }
public static Builder builder(Location location) { return new AutoValue_EnumElement.Builder() .location(location) .documentation("") .constants(ImmutableList.<EnumConstantElement>of()) .options(ImmutableList.<OptionElement>of()); }
public static Builder builder(Location location) { return new AutoValue_EnumConstantElement.Builder() .location(location) .documentation("") .options(ImmutableList.<OptionElement>of()); }
public static Builder builder() { return new AutoValue_OneOfElement.Builder() .documentation("") .fields(ImmutableList.<FieldElement>of()) .groups(ImmutableList.<GroupElement>of()); }
public static Builder builder(Location location) { return new AutoValue_FieldElement.Builder() .documentation("") .options(ImmutableList.<OptionElement>of()) .location(location); }
public static Builder builder(Location location) { return new AutoValue_ExtendElement.Builder() .documentation("") .fields(ImmutableList.<FieldElement>of()) .location(location); }
public static Builder builder(Location location) { return new AutoValue_GroupElement.Builder() .location(location) .documentation("") .fields(ImmutableList.<FieldElement>of()); }
/** Reads a scalar, map, or type name. */ public String readDataType() { String name = readWord(); return readDataType(name); }
/** * Peeks a non-whitespace character and returns it. The only difference * between this and {@code readChar} is that this doesn't consume the char. */ public char peekChar() { skipWhitespace(true); if (pos == data.length) throw unexpected("unexpected end of file"); return data[pos]; }
public boolean peekChar(char c) { if (peekChar() == c) { pos++; return true; } else { return false; } }