public CodeWriter popPackage() { checkState(this.packageName != NO_PACKAGE, "package not set"); this.packageName = NO_PACKAGE; return this; }
public Builder addTypeVariable(TypeVariableName typeVariable) { checkState(anonymousTypeArguments == null, "forbidden on anonymous types."); typeVariables.add(typeVariable); return this; }
public Builder returns(TypeName returnType) { checkState(!name.equals(CONSTRUCTOR), "constructor cannot have return type."); this.returnType = returnType; return this; }
public Builder superclass(TypeName superclass) { checkState(this.kind == Kind.CLASS, "only classes have super classes, not " + this.kind); checkState(this.superclass == ClassName.OBJECT, "superclass already set to " + this.superclass); checkArgument(!superclass.isPrimitive(), "superclass may not be a primitive"); this.superclass = superclass; return this; }
public Builder addTypeVariables(Iterable<TypeVariableName> typeVariables) { checkState(anonymousTypeArguments == null, "forbidden on anonymous types."); checkArgument(typeVariables != null, "typeVariables == null"); for (TypeVariableName typeVariable : typeVariables) { this.typeVariables.add(typeVariable); } return this; }
public Builder initializer(CodeBlock codeBlock) { checkState(this.initializer == null, "initializer was already set"); this.initializer = checkNotNull(codeBlock, "codeBlock == null"); return this; }
public Builder addModifiers(Modifier... modifiers) { checkState(anonymousTypeArguments == null, "forbidden on anonymous types."); for (Modifier modifier : modifiers) { checkArgument(modifier != null, "modifiers contain null"); this.modifiers.add(modifier); } return this; }
public Builder defaultValue(CodeBlock codeBlock) { checkState(this.defaultValue == null, "defaultValue was already set"); this.defaultValue = checkNotNull(codeBlock, "codeBlock == null"); return this; }
public Builder addField(FieldSpec fieldSpec) { if (kind == Kind.INTERFACE || kind == Kind.ANNOTATION) { requireExactlyOneOf(fieldSpec.modifiers, Modifier.PUBLIC, Modifier.PRIVATE); Set<Modifier> check = EnumSet.of(Modifier.STATIC, Modifier.FINAL); checkState(fieldSpec.modifiers.containsAll(check), "%s %s.%s requires modifiers %s", kind, name, fieldSpec.name, check); } fieldSpecs.add(fieldSpec); return this; }
public CodeWriter pushPackage(String packageName) { checkState(this.packageName == NO_PACKAGE, "package already set: %s", this.packageName); this.packageName = checkNotNull(packageName, "packageName == null"); return this; }
public Builder addMethod(MethodSpec methodSpec) { if (kind == Kind.INTERFACE) { requireExactlyOneOf(methodSpec.modifiers, Modifier.ABSTRACT, Modifier.STATIC, Modifier.DEFAULT); requireExactlyOneOf(methodSpec.modifiers, Modifier.PUBLIC, Modifier.PRIVATE); } else if (kind == Kind.ANNOTATION) { checkState(methodSpec.modifiers.equals(kind.implicitMethodModifiers), "%s %s.%s requires modifiers %s", kind, name, methodSpec.name, kind.implicitMethodModifiers); } if (kind != Kind.ANNOTATION) { checkState(methodSpec.defaultValue == null, "%s %s.%s cannot have a default value", kind, name, methodSpec.name); } if (kind != Kind.INTERFACE) { checkState(!methodSpec.hasModifier(Modifier.DEFAULT), "%s %s.%s cannot be default", kind, name, methodSpec.name); } methodSpecs.add(methodSpec); return this; }
public Builder addEnumConstant(String name, TypeSpec typeSpec) { checkState(kind == Kind.ENUM, "%s is not enum", this.name); checkArgument(typeSpec.anonymousTypeArguments != null, "enum constants must have anonymous type arguments"); checkArgument(SourceVersion.isName(name), "not a valid enum constant: %s", name); enumConstants.put(name, typeSpec); return this; }
ClassName candidate = (ClassName) typeName; if (staticImportClassNames.contains(candidate.canonicalName)) { checkState(deferredTypeName == null, "pending type for static import?!"); deferredTypeName = candidate; break; checkState(statementLine == -1, "statement enter $[ followed by statement enter $["); statementLine = 0; break; checkState(statementLine != -1, "statement exit $] has no matching statement enter $["); if (statementLine > 0) { unindent(2); // End a multi-line statement. Decrease the indentation level.
public Builder returns(TypeName returnType) { checkState(!name.equals(CONSTRUCTOR), "constructor cannot have return type."); this.returnType = returnType; return this; }
public Builder addField(FieldSpec fieldSpec) { if (kind == Kind.INTERFACE || kind == Kind.ANNOTATION) { requireExactlyOneOf(fieldSpec.modifiers, Modifier.PUBLIC, Modifier.PRIVATE); Set<Modifier> check = EnumSet.of(Modifier.STATIC, Modifier.FINAL); checkState(fieldSpec.modifiers.containsAll(check), "%s %s.%s requires modifiers %s", kind, name, fieldSpec.name, check); } fieldSpecs.add(fieldSpec); return this; }
public Builder addModifiers(Modifier... modifiers) { checkState(anonymousTypeArguments == null, "forbidden on anonymous types."); for (Modifier modifier : modifiers) { checkArgument(modifier != null, "modifiers contain null"); this.modifiers.add(modifier); } return this; }
public Builder initializer(CodeBlock codeBlock) { checkState(this.initializer == null, "initializer was already set"); this.initializer = checkNotNull(codeBlock, "codeBlock == null"); return this; }
public Builder superclass(TypeName superclass) { checkState(this.kind == Kind.CLASS, "only classes have super classes, not " + this.kind); checkState(this.superclass == ClassName.OBJECT, "superclass already set to " + this.superclass); checkArgument(!superclass.isPrimitive(), "superclass may not be a primitive"); this.superclass = superclass; return this; }
public CodeWriter pushPackage(String packageName) { checkState(this.packageName == NO_PACKAGE, "package already set: %s", this.packageName); this.packageName = checkNotNull(packageName, "packageName == null"); return this; }
public Builder addEnumConstant(String name, TypeSpec typeSpec) { checkState(kind == Kind.ENUM, "%s is not enum", this.name); checkArgument(typeSpec.anonymousTypeArguments != null, "enum constants must have anonymous type arguments"); checkArgument(SourceVersion.isName(name), "not a valid enum constant: %s", name); enumConstants.put(name, typeSpec); return this; }