@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); }
static ProtoFile get(ProtoFileElement protoFileElement) { String packageName = protoFileElement.packageName(); ImmutableList<Type> types = Type.fromElements(packageName, protoFileElement.types()); ImmutableList<Service> services = Service.fromElements(packageName, protoFileElement.services()); ImmutableList<Extend> wireExtends = Extend.fromElements(packageName, protoFileElement.extendDeclarations()); Options options = new Options(Options.FILE_OPTIONS, protoFileElement.options()); return new ProtoFile(protoFileElement.location(), protoFileElement.imports(), protoFileElement.publicImports(), packageName, types, services, wireExtends, options, protoFileElement.syntax()); }
public boolean protoFileMatchesPackage(ProtoFileElement element) { String packageFound = element.packageName(); if (packageFound == null) { List<OptionElement> options = element.options(); if (options != null) { for (OptionElement option : options) { if (option.name().equals("java_package")) { if (option.value().toString().contains(serviceName)) { System.out.println("Please update protofile for " + serviceName); return true; } } } } } else { return matchesServiceName(packageFound); } return false; }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof ProtoFileElement) { ProtoFileElement that = (ProtoFileElement) o; return (this.location.equals(that.location())) && ((this.packageName == null) ? (that.packageName() == null) : this.packageName.equals(that.packageName())) && ((this.syntax == null) ? (that.syntax() == null) : this.syntax.equals(that.syntax())) && (this.imports.equals(that.imports())) && (this.publicImports.equals(that.publicImports())) && (this.types.equals(that.types())) && (this.services.equals(that.services())) && (this.extendDeclarations.equals(that.extendDeclarations())) && (this.options.equals(that.options())); } return false; }
Builder(ProtoFileElement source) { this.location = source.location(); this.packageName = source.packageName(); this.syntax = source.syntax(); this.imports = source.imports(); this.publicImports = source.publicImports(); this.types = source.types(); this.services = source.services(); this.extendDeclarations = source.extendDeclarations(); this.options = source.options(); } @Override
static ProtoFile get(ProtoFileElement protoFileElement) { String packageName = protoFileElement.packageName(); ImmutableList<Type> types = Type.fromElements(packageName, protoFileElement.types()); ImmutableList<Service> services = Service.fromElements(packageName, protoFileElement.services()); ImmutableList<Extend> wireExtends = Extend.fromElements(packageName, protoFileElement.extendDeclarations()); Options options = new Options(Options.FILE_OPTIONS, protoFileElement.options()); return new ProtoFile(protoFileElement.location(), protoFileElement.imports(), protoFileElement.publicImports(), packageName, types, services, wireExtends, options, protoFileElement.syntax()); }
static ProtoFile get(ProtoFileElement protoFileElement) { String packageName = protoFileElement.packageName(); ImmutableList<Type> types = Type.fromElements(packageName, protoFileElement.types()); ImmutableList<Service> services = Service.fromElements(packageName, protoFileElement.services()); ImmutableList<Extend> wireExtends = Extend.fromElements(packageName, protoFileElement.extendDeclarations()); Options options = new Options(Options.FILE_OPTIONS, protoFileElement.options()); return new ProtoFile(protoFileElement.location(), protoFileElement.imports(), protoFileElement.publicImports(), packageName, types, services, wireExtends, options, protoFileElement.syntax()); }