LineWrapper(Appendable out, String indent, int columnLimit) { checkNotNull(out, "out == null"); this.out = out; this.indent = indent; this.columnLimit = columnLimit; }
public Builder addAnnotation(AnnotationSpec annotationSpec) { checkNotNull(annotationSpec, "annotationSpec == null"); this.annotations.add(annotationSpec); return this; }
public Builder addModifiers(Modifier... modifiers) { checkNotNull(modifiers, "modifiers == null"); Collections.addAll(this.modifiers, modifiers); return this; }
public Builder addModifiers(Iterable<Modifier> modifiers) { checkNotNull(modifiers, "modifiers == null"); for (Modifier modifier : modifiers) { this.modifiers.add(modifier); } return this; }
public static Builder builder(String packageName, TypeSpec typeSpec) { checkNotNull(packageName, "packageName == null"); checkNotNull(typeSpec, "typeSpec == null"); return new Builder(packageName, typeSpec); }
CodeWriter(Appendable out, String indent, Map<String, ClassName> importedTypes, Set<String> staticImports) { this.out = new LineWrapper(out, indent, 100); this.indent = checkNotNull(indent, "indent == null"); this.importedTypes = checkNotNull(importedTypes, "importedTypes == null"); this.staticImports = checkNotNull(staticImports, "staticImports == null"); this.staticImportClassNames = new LinkedHashSet<>(); for (String signature : staticImports) { staticImportClassNames.add(signature.substring(0, signature.lastIndexOf('.'))); } }
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 defaultValue(CodeBlock codeBlock) { checkState(this.defaultValue == null, "defaultValue was already set"); this.defaultValue = checkNotNull(codeBlock, "codeBlock == null"); 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(Iterable<Modifier> modifiers) { checkNotNull(modifiers, "modifiers == null"); for (Modifier modifier : modifiers) { if (!modifier.equals(Modifier.FINAL)) { throw new IllegalStateException("unexpected parameter modifier: " + modifier); } this.modifiers.add(modifier); } return this; }
/** * Returns a new {@link ParameterizedTypeName} instance for the specified {@code name} as nested * inside this class. */ public ParameterizedTypeName nestedClass(String name) { checkNotNull(name, "name == null"); return new ParameterizedTypeName(this, rawType.nestedClass(name), new ArrayList<>(), new ArrayList<>()); }
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 ParameterSpec(Builder builder) { this.name = checkNotNull(builder.name, "name == null"); this.annotations = Util.immutableList(builder.annotations); this.modifiers = Util.immutableSet(builder.modifiers); this.type = checkNotNull(builder.type, "type == null"); this.javadoc = builder.javadoc.build(); }
/** * Returns a new {@link ParameterizedTypeName} instance for the specified {@code name} as nested * inside this class, with the specified {@code typeArguments}. */ public ParameterizedTypeName nestedClass(String name, List<TypeName> typeArguments) { checkNotNull(name, "name == null"); return new ParameterizedTypeName(this, rawType.nestedClass(name), typeArguments, new ArrayList<>()); }
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); } }
private FieldSpec(Builder builder) { this.type = checkNotNull(builder.type, "type == null"); this.name = checkNotNull(builder.name, "name == null"); this.javadoc = builder.javadoc.build(); this.annotations = Util.immutableList(builder.annotations); this.modifiers = Util.immutableSet(builder.modifiers); this.initializer = (builder.initializer == null) ? CodeBlock.builder().build() : builder.initializer; }
private ParameterizedTypeName(ParameterizedTypeName enclosingType, ClassName rawType, List<TypeName> typeArguments, List<AnnotationSpec> annotations) { super(annotations); this.rawType = checkNotNull(rawType, "rawType == null").annotated(annotations); this.enclosingType = enclosingType; this.typeArguments = Util.immutableList(typeArguments); checkArgument(!this.typeArguments.isEmpty() || enclosingType != null, "no type arguments: %s", rawType); for (TypeName typeArgument : this.typeArguments) { checkArgument(!typeArgument.isPrimitive() && typeArgument != VOID, "invalid type parameter: %s", typeArgument); } }
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); }
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); }