public static Builder builder(Location location) { return new AutoValue_EnumElement.Builder() .location(location) .documentation("") .constants(ImmutableList.<EnumConstantElement>of()) .options(ImmutableList.<OptionElement>of()); }
/** Reads an enumerated type declaration and returns it. */ private EnumElement readEnumElement(Location location, String documentation) { String name = reader.readName(); EnumElement.Builder builder = EnumElement.builder(location) .name(name) .documentation(documentation); ImmutableList.Builder<EnumConstantElement> constants = ImmutableList.builder(); ImmutableList.Builder<OptionElement> options = ImmutableList.builder(); reader.require('{'); while (true) { String valueDocumentation = reader.readDocumentation(); if (reader.peekChar('}')) break; Object declared = readDeclaration(valueDocumentation, Context.ENUM); if (declared instanceof EnumConstantElement) { constants.add((EnumConstantElement) declared); } else if (declared instanceof OptionElement) { options.add((OptionElement) declared); } } return builder.options(options.build()) .constants(constants.build()) .build(); }
@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); }
/** Reads an enumerated type declaration and returns it. */ private EnumElement readEnumElement(Location location, String documentation) { String name = readName(); EnumElement.Builder builder = EnumElement.builder(location) .name(name) .documentation(documentation); if (readChar() != '{') throw unexpected("expected '{'"); ImmutableList.Builder<EnumConstantElement> constants = ImmutableList.builder(); ImmutableList.Builder<OptionElement> options = ImmutableList.builder(); while (true) { String valueDocumentation = readDocumentation(); if (peekChar() == '}') { pos++; break; } Object declared = readDeclaration(valueDocumentation, Context.ENUM); if (declared instanceof EnumConstantElement) { constants.add((EnumConstantElement) declared); } else if (declared instanceof OptionElement) { options.add((OptionElement) declared); } } return builder.options(options.build()) .constants(constants.build()) .build(); }
/** Reads an enumerated type declaration and returns it. */ private EnumElement readEnumElement(Location location, String documentation) { String name = reader.readName(); EnumElement.Builder builder = EnumElement.builder(location) .name(name) .documentation(documentation); ImmutableList.Builder<EnumConstantElement> constants = ImmutableList.builder(); ImmutableList.Builder<OptionElement> options = ImmutableList.builder(); reader.require('{'); while (true) { String valueDocumentation = reader.readDocumentation(); if (reader.peekChar('}')) break; Object declared = readDeclaration(valueDocumentation, Context.ENUM); if (declared instanceof EnumConstantElement) { constants.add((EnumConstantElement) declared); } else if (declared instanceof OptionElement) { options.add((OptionElement) declared); } } return builder.options(options.build()) .constants(constants.build()) .build(); }
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_EnumElement.Builder() .location(location) .documentation("") .constants(ImmutableList.<EnumConstantElement>of()) .options(ImmutableList.<OptionElement>of()); }
EnumElement toElement() { return EnumElement.builder(location) .name(name) .documentation(documentation) .constants(EnumConstant.toElements(constants)) .options(options.toElements()) .build(); } }
EnumElement toElement() { return EnumElement.builder(location) .name(name) .documentation(documentation) .constants(EnumConstant.toElements(constants)) .options(options.toElements()) .build(); } }
.name("Topping") .documentation("What's on my waffles.\nAlso works on pancakes.") .options( ImmutableList.of(OptionElement.create("max_choices", Kind.NUMBER, "2", true))) .constants(ImmutableList.of(
@Test public void simpleWithOptionsToSchema() { EnumElement element = EnumElement.builder(location) .name("Enum").options(ImmutableList.of(OptionElement.create("kit", STRING, "kat"))) .constants(ImmutableList.of( EnumConstantElement.builder(location).name("ONE").tag(1).build(), EnumConstantElement.builder(location).name("TWO").tag(2).build(), EnumConstantElement.builder(location).name("SIX").tag(6).build())) .build(); String expected = "" + "enum Enum {\n" + " option kit = \"kat\";\n" + "\n" + " ONE = 1;\n" + " TWO = 2;\n" + " SIX = 6;\n" + "}\n"; assertThat(element.toSchema()).isEqualTo(expected); }
EnumElement toElement() { return EnumElement.builder(location) .name(name) .documentation(documentation) .constants(EnumConstant.toElements(constants)) .options(options.toElements()) .build(); } }