private CodeBlock(Builder builder) { this.formatParts = Util.immutableList(builder.formatParts); this.args = Util.immutableList(builder.args); }
private TypeName(String keyword, List<AnnotationSpec> annotations) { this.keyword = keyword; this.annotations = Util.immutableList(annotations); }
static <K, V> Map<K, List<V>> immutableMultimap(Map<K, List<V>> multimap) { LinkedHashMap<K, List<V>> result = new LinkedHashMap<>(); for (Map.Entry<K, List<V>> entry : multimap.entrySet()) { if (entry.getValue().isEmpty()) continue; result.put(entry.getKey(), immutableList(entry.getValue())); } return Collections.unmodifiableMap(result); }
private TypeSpec(Builder builder) { this.kind = builder.kind; this.name = builder.name; this.anonymousTypeArguments = builder.anonymousTypeArguments; this.javadoc = builder.javadoc.build(); this.annotations = Util.immutableList(builder.annotations); this.modifiers = Util.immutableSet(builder.modifiers); this.typeVariables = Util.immutableList(builder.typeVariables); this.superclass = builder.superclass; this.superinterfaces = Util.immutableList(builder.superinterfaces); this.enumConstants = Util.immutableMap(builder.enumConstants); this.fieldSpecs = Util.immutableList(builder.fieldSpecs); this.staticBlock = builder.staticBlock.build(); this.initializerBlock = builder.initializerBlock.build(); this.methodSpecs = Util.immutableList(builder.methodSpecs); this.typeSpecs = Util.immutableList(builder.typeSpecs); List<Element> originatingElementsMutable = new ArrayList<>(); originatingElementsMutable.addAll(builder.originatingElements); for (TypeSpec typeSpec : builder.typeSpecs) { originatingElementsMutable.addAll(typeSpec.originatingElements); } this.originatingElements = Util.immutableList(originatingElementsMutable); }
private MethodSpec(Builder builder) { CodeBlock code = builder.code.build(); checkArgument(code.isEmpty() || !builder.modifiers.contains(Modifier.ABSTRACT), "abstract method %s cannot have code", builder.name); checkArgument(!builder.varargs || lastParameterIsArray(builder.parameters), "last parameter of varargs method %s must be an array", builder.name); 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.typeVariables = Util.immutableList(builder.typeVariables); this.returnType = builder.returnType; this.parameters = Util.immutableList(builder.parameters); this.varargs = builder.varargs; this.exceptions = Util.immutableList(builder.exceptions); this.defaultValue = builder.defaultValue; this.code = code; }
private WildcardTypeName(List<TypeName> upperBounds, List<TypeName> lowerBounds, List<AnnotationSpec> annotations) { super(annotations); this.upperBounds = Util.immutableList(upperBounds); this.lowerBounds = Util.immutableList(lowerBounds); checkArgument(this.upperBounds.size() == 1, "unexpected extends bounds: %s", upperBounds); for (TypeName upperBound : this.upperBounds) { checkArgument(!upperBound.isPrimitive() && upperBound != VOID, "invalid upper bound: %s", upperBound); } for (TypeName lowerBound : this.lowerBounds) { checkArgument(!lowerBound.isPrimitive() && lowerBound != VOID, "invalid lower bound: %s", lowerBound); } }
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); } }
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(); }
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 TypeName(String keyword, List<AnnotationSpec> annotations) { this.keyword = keyword; this.annotations = Util.immutableList(annotations); }
private CodeBlock(Builder builder) { this.formatParts = Util.immutableList(builder.formatParts); this.args = Util.immutableList(builder.args); }
static <K, V> Map<K, List<V>> immutableMultimap(Map<K, List<V>> multimap) { LinkedHashMap<K, List<V>> result = new LinkedHashMap<>(); for (Map.Entry<K, List<V>> entry : multimap.entrySet()) { if (entry.getValue().isEmpty()) continue; result.put(entry.getKey(), immutableList(entry.getValue())); } return Collections.unmodifiableMap(result); }
static <K, V> Map<K, List<V>> immutableMultimap(Map<K, List<V>> multimap) { LinkedHashMap<K, List<V>> result = new LinkedHashMap<>(); for (Map.Entry<K, List<V>> entry : multimap.entrySet()) { if (entry.getValue().isEmpty()) continue; result.put(entry.getKey(), immutableList(entry.getValue())); } return Collections.unmodifiableMap(result); }
private ClassName(List<String> names, List<AnnotationSpec> annotations) { super(annotations); for (int i = 1; i < names.size(); i++) { checkArgument(SourceVersion.isName(names.get(i)), "part '%s' is keyword", names.get(i)); } this.names = Util.immutableList(names); this.canonicalName = (names.get(0).isEmpty() ? Util.join(".", names.subList(1, names.size())) : Util.join(".", names)); }
private ClassName(List<String> names, List<AnnotationSpec> annotations) { super(annotations); for (int i = 1; i < names.size(); i++) { checkArgument(SourceVersion.isName(names.get(i)), "part '%s' is keyword", names.get(i)); } this.names = Util.immutableList(names); this.canonicalName = (names.get(0).isEmpty() ? Util.join(".", names.subList(1, names.size())) : Util.join(".", names)); }
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"); }
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"); }
private ParameterizedTypeName(ParameterizedTypeName enclosingType, ClassName rawType, List<TypeName> typeArguments, List<AnnotationSpec> annotations) { super(annotations); this.rawType = checkNotNull(rawType, "rawType == null"); 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); } }
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 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; }