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); } }
@Override public void serialize(Builder builder, int depth, String fieldName, List<String> processedFieldNames, String getter, boolean isObjectProperty, boolean checkIfNull, boolean writeIfNull, boolean writeCollectionElementIfNull) { if (!mTypeName.isPrimitive() && checkIfNull) { builder.beginControlFlow("if ($L != null)", getter); } builder.addStatement("$T.typeConverterFor($T.class).serialize($L, $S, $L, $L)", LoganSquare.class, mTypeName, getter, isObjectProperty ? fieldName : null, isObjectProperty, JSON_GENERATOR_VARIABLE_NAME); if (!mTypeName.isPrimitive() && checkIfNull) { if (writeIfNull) { builder.nextControlFlow("else"); if (isObjectProperty) { builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName); } builder.addStatement("$L.writeNull()", JSON_GENERATOR_VARIABLE_NAME); } builder.endControlFlow(); } }
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); } }
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; }
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); } }
.addParameter(fieldModel.field.type, fieldModel.field.name) .addStatement("_eventState.$L = $L", fieldModel.field.name, fieldModel.field.name); if (!fieldModel.field.type.isPrimitive()) { resetCode.addStatement("_eventState.$L = null", fieldModel.field.name);
.beginControlFlow("while ($L.nextToken() != $T.END_ARRAY)", JSON_PARSER_VARIABLE_NAME, JsonToken.class); if (!fieldType.isPrimitive()) { final String valueVarName = "value" + depth; if (fieldType.isPrimitive()) { builder .addStatement("$T[] array = new $T[$L.size()]", fieldType, fieldType, collectionVarName)
if (TypeName.get(mirror).isPrimitive()) { return;
if (onCreateTreePropMethod.returnType.isPrimitive() || onCreateTreePropMethod.returnType.toString().startsWith("java.lang.") || onCreateTreePropMethod.returnType.toString().startsWith("java.util.")) {
@NonNull private String getDefault(@NonNull TypeName type) { if (type.isPrimitive()) { if (type.equals(TypeName.BOOLEAN)) { return "false"; } else if (type.equals(TypeName.BYTE)) { return "0"; } else if (type.equals(TypeName.SHORT)) { return "0"; } else if (type.equals(TypeName.INT)) { return "0"; } else if (type.equals(TypeName.LONG)) { return "0L"; } else if (type.equals(TypeName.CHAR)) { return "\u0000"; } else if (type.equals(TypeName.FLOAT)) { return "0.0f"; } else if (type.equals(TypeName.DOUBLE)) { return "0.0d"; } } return "null"; }
final String forLine; final Object[] forLineArgs; if (arrayType.getTypeName().isPrimitive()) { instanceCreator = "final $T[] $L = $L"; instanceCreatorArgs = expandStringArgs(arrayType.getTypeName(), collectionVariableName, getter); .beginControlFlow(forLine, forLineArgs); if (!arrayType.getTypeName().isPrimitive()) { builder.beginControlFlow("if ($L != null)", elementVarName); if (!arrayType.getTypeName().isPrimitive()) { if (writeCollectionElementIfNull) { builder
return Comparable.ARRAY; } else if (field.getTypeName().isPrimitive()) { return Comparable.PRIMITIVE;
public Collection<AnnotationSpec> nullabilityAnnotations() { if (type.isPrimitive()) { return Collections.emptyList(); } if (nullable) { return Collections.singletonList(Annotations.nullable()); } else { return Collections.singletonList(Annotations.nonNull()); } }
private static ImmutableMap<Property, FieldSpec> createFields(List<Property> properties) { ImmutableMap.Builder<Property, FieldSpec> fields = ImmutableMap.builder(); for (Property property : properties) { TypeName type = property.type.isPrimitive() ? property.type.box() : property.type; ParameterizedTypeName adp = ParameterizedTypeName.get(ClassName.get(Validator.class), type); fields.put(property, FieldSpec.builder(adp, property.humanName + "Validator", PRIVATE, FINAL) .build()); } return fields.build(); }
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 boolean needsTypeAdapter(TypeName type) { return type instanceof ParameterizedTypeName || !(type.isPrimitive() || type.isBoxedPrimitive() || type.equals(Types.String) || type .equals(Types.ByteArray)); }
public String getAsDestructuredValue() { if (getType().isPrimitive()) { String typeName = getType().toString(); String anyGetterName = "as" + typeName.substring(0, 1).toUpperCase() + typeName.substring(1) + "()"; return destructuredVariable.getName() + ".getAny(\"" + getName() + "\")." + anyGetterName; } return "((" + getType() + ") " + destructuredVariable.getName() + ".get(\"" + getName() + "\"))"; } }
private static boolean needsNullSafeEquals(Spec enumDef) { for (Value value : enumDef.values()) { for (Parameter parameter : value.parameters()) { if (!parameter.type().isPrimitive() && parameter.canBeNull()) { return true; } } } return false; } }
ParameterSpec buildParameterSpec(ColumnDefinition column) { AssociationDefinition r = column.getAssociation(); boolean isAssociation = r != null; TypeName type = isAssociation ? r.getModelType() : column.getType(); List<AnnotationSpec> paramAnnotations = column.type.isPrimitive() ? Collections.emptyList() : Collections.singletonList(Annotations.nonNull()); return ParameterSpec.builder(type, column.name) .addAnnotations(paramAnnotations) .build(); }