public CodeWriter unindent(int levels) { checkArgument(indentLevel - levels >= 0, "cannot unindent %s from %s", levels, indentLevel); indentLevel -= levels; return this; }
public Builder addStaticImport(ClassName className, String... names) { checkArgument(className != null, "className == null"); checkArgument(names != null, "names == null"); checkArgument(names.length > 0, "names array is empty"); for (String name : names) { checkArgument(name != null, "null entry in names array: %s", Arrays.toString(names)); staticImports.add(className.canonicalName + "." + name); } return this; }
public Builder addAnnotations(Iterable<AnnotationSpec> annotationSpecs) { checkArgument(annotationSpecs != null, "annotationSpecs == null"); for (AnnotationSpec annotationSpec : annotationSpecs) { this.annotations.add(annotationSpec); } return this; }
public Builder addAnnotations(Iterable<AnnotationSpec> annotationSpecs) { checkArgument(annotationSpecs != null, "annotationSpecs == null"); for (AnnotationSpec annotationSpec : annotationSpecs) { this.annotations.add(annotationSpec); } return this; }
public Builder addParameters(Iterable<ParameterSpec> parameterSpecs) { checkArgument(parameterSpecs != null, "parameterSpecs == null"); for (ParameterSpec parameterSpec : parameterSpecs) { this.parameters.add(parameterSpec); } return this; }
public Builder addMethods(Iterable<MethodSpec> methodSpecs) { checkArgument(methodSpecs != null, "methodSpecs == null"); for (MethodSpec methodSpec : methodSpecs) { addMethod(methodSpec); } return this; }
public Builder addType(TypeSpec typeSpec) { checkArgument(typeSpec.modifiers.containsAll(kind.implicitTypeModifiers), "%s %s.%s requires modifiers %s", kind, name, typeSpec.name, kind.implicitTypeModifiers); typeSpecs.add(typeSpec); return this; }
static void requireExactlyOneOf(Set<Modifier> modifiers, Modifier... mutuallyExclusive) { int count = 0; for (Modifier modifier : mutuallyExclusive) { if (modifiers.contains(modifier)) count++; } checkArgument(count == 1, "modifiers %s must contain one of %s", modifiers, Arrays.toString(mutuallyExclusive)); }
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; }
private static String extractMemberName(String part) { checkArgument(Character.isJavaIdentifierStart(part.charAt(0)), "not an identifier: %s", part); for (int i = 1; i <= part.length(); i++) { if (!SourceVersion.isIdentifier(part.substring(0, i))) { return part.substring(0, i - 1); } } return part; }
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 addFields(Iterable<FieldSpec> fieldSpecs) { checkArgument(fieldSpecs != null, "fieldSpecs == null"); for (FieldSpec fieldSpec : fieldSpecs) { addField(fieldSpec); } return this; }
public Builder addTypes(Iterable<TypeSpec> typeSpecs) { checkArgument(typeSpecs != null, "typeSpecs == null"); for (TypeSpec typeSpec : typeSpecs) { addType(typeSpec); } return this; }
private Builder(Kind kind, String name, CodeBlock anonymousTypeArguments) { checkArgument(name == null || SourceVersion.isName(name), "not a valid name: %s", name); this.kind = kind; this.name = name; this.anonymousTypeArguments = anonymousTypeArguments; }
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 addMember(String name, CodeBlock codeBlock) { checkNotNull(name, "name == null"); checkArgument(SourceVersion.isName(name), "not a valid name: %s", name); List<CodeBlock> values = members.computeIfAbsent(name, k -> new ArrayList<>()); values.add(codeBlock); return this; }
private Builder(String name) { checkNotNull(name, "name == null"); checkArgument(name.equals(CONSTRUCTOR) || SourceVersion.isName(name), "not a valid name: %s", name); this.name = name; this.returnType = name.equals(CONSTRUCTOR) ? null : TypeName.VOID; }
private TypeVariableName(String name, List<TypeName> bounds, List<AnnotationSpec> annotations) { super(annotations); this.name = checkNotNull(name, "name == null"); this.bounds = bounds; for (TypeName bound : this.bounds) { checkArgument(!bound.isPrimitive() && bound != VOID, "invalid bound: %s", bound); } }
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 static Builder builder(TypeName type, String name, Modifier... modifiers) { checkNotNull(type, "type == null"); checkArgument(SourceVersion.isName(name), "not a valid name: %s", name); return new Builder(type, name) .addModifiers(modifiers); }