Java Code Examples for com.squareup.javapoet.TypeName#FLOAT
The following examples show how to use
com.squareup.javapoet.TypeName#FLOAT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JTypeName.java From gwt-jackson with Apache License 2.0 | 6 votes |
private TypeName primitiveName( JPrimitiveType type, boolean boxed ) { if ( "boolean".equals( type.getSimpleSourceName() ) ) { return boxed ? BOOLEAN_NAME : TypeName.BOOLEAN; } else if ( "byte".equals( type.getSimpleSourceName() ) ) { return boxed ? BYTE_NAME : TypeName.BYTE; } else if ( "short".equals( type.getSimpleSourceName() ) ) { return boxed ? SHORT_NAME : TypeName.SHORT; } else if ( "int".equals( type.getSimpleSourceName() ) ) { return boxed ? INTEGER_NAME : TypeName.INT; } else if ( "long".equals( type.getSimpleSourceName() ) ) { return boxed ? LONG_NAME : TypeName.LONG; } else if ( "char".equals( type.getSimpleSourceName() ) ) { return boxed ? CHARACTER_NAME : TypeName.CHAR; } else if ( "float".equals( type.getSimpleSourceName() ) ) { return boxed ? FLOAT_NAME : TypeName.FLOAT; } else if ( "double".equals( type.getSimpleSourceName() ) ) { return boxed ? DOUBLE_NAME : TypeName.DOUBLE; } else { return boxed ? VOID_NAME : TypeName.VOID; } }
Example 2
Source File: TypeUtility.java From kripton with Apache License 2.0 | 6 votes |
public static String getDefaultValue(TypeName value) { if (!isTypePrimitive(value)) { return null; } else { if (value == TypeName.BOOLEAN) { return "false"; } else if (value == TypeName.BYTE) { return "(byte)0"; } else if (value == TypeName.CHAR) { return "(char)0"; } else if (value == TypeName.DOUBLE) { return "0.0"; } else if (value == TypeName.FLOAT) { return "0.0f"; } else if (value == TypeName.INT) { return "0"; } else if (value == TypeName.LONG) { return "0"; } else if (value == TypeName.SHORT) { return "(short)0"; } else { return "0"; } } }
Example 3
Source File: TypeUtility.java From kripton with Apache License 2.0 | 6 votes |
/** * Convert a TypeMirror in a typeName. * * @param typeMirror * the type mirror * @return typeName */ public static TypeName typeName(TypeMirror typeMirror) { LiteralType literalType = LiteralType.of(typeMirror.toString()); if (literalType.isArray()) { return ArrayTypeName.of(typeName(literalType.getRawType())); } else if (literalType.isCollection()) { return ParameterizedTypeName.get(TypeUtility.className(literalType.getRawType()), typeName(literalType.getTypeParameter())); } TypeName[] values = { TypeName.BOOLEAN, TypeName.BYTE, TypeName.CHAR, TypeName.DOUBLE, TypeName.FLOAT, TypeName.INT, TypeName.LONG, TypeName.SHORT, TypeName.VOID }; for (TypeName item : values) { if (typeMirror.toString().equals(item.toString())) { return item; } } return TypeName.get(typeMirror); }
Example 4
Source File: TypeUtil.java From Intimate with Apache License 2.0 | 6 votes |
public static String typeDefaultReturnCode(CName cName) { if (cName.isPrimitive) { if (cName.typeName == TypeName.VOID) return ""; if (cName.typeName == TypeName.BOOLEAN) return "return false;"; if (cName.typeName == TypeName.BYTE) return "return 0;"; if (cName.typeName == TypeName.SHORT) return "return 0;"; if (cName.typeName == TypeName.INT) return "return 0;"; if (cName.typeName == TypeName.LONG) return "return 0;"; if (cName.typeName == TypeName.CHAR) return "return 0;"; if (cName.typeName == TypeName.FLOAT) return "return 0;"; if (cName.typeName == TypeName.DOUBLE) return "return 0;"; } else if (cName.fullName.equals("void")) { return ""; } return "return null;"; }
Example 5
Source File: PsiTypeUtils.java From litho with Apache License 2.0 | 6 votes |
private static TypeName getPrimitiveTypeName(PsiPrimitiveType type) { switch (type.getCanonicalText()) { case "void": return TypeName.VOID; case "boolean": return TypeName.BOOLEAN; case "byte": return TypeName.BYTE; case "short": return TypeName.SHORT; case "int": return TypeName.INT; case "long": return TypeName.LONG; case "char": return TypeName.CHAR; case "float": return TypeName.FLOAT; case "double": return TypeName.DOUBLE; default: throw new UnsupportedOperationException( "Unknown primitive type: " + type.getCanonicalText()); } }
Example 6
Source File: BindingSet.java From butterknife with Apache License 2.0 | 6 votes |
private static TypeName bestGuess(String type) { switch (type) { case "void": return TypeName.VOID; case "boolean": return TypeName.BOOLEAN; case "byte": return TypeName.BYTE; case "char": return TypeName.CHAR; case "double": return TypeName.DOUBLE; case "float": return TypeName.FLOAT; case "int": return TypeName.INT; case "long": return TypeName.LONG; case "short": return TypeName.SHORT; default: int left = type.indexOf('<'); if (left != -1) { ClassName typeClassName = ClassName.bestGuess(type.substring(0, left)); List<TypeName> typeArguments = new ArrayList<>(); do { typeArguments.add(WildcardTypeName.subtypeOf(Object.class)); left = type.indexOf('<', left + 1); } while (left != -1); return ParameterizedTypeName.get(typeClassName, typeArguments.toArray(new TypeName[typeArguments.size()])); } return ClassName.bestGuess(type); } }
Example 7
Source File: ParameAnnotationClass.java From EasyRouter with Apache License 2.0 | 6 votes |
private static TypeName convertClass(String originClazz) { switch (originClazz) { case "int": return TypeName.INT; case "long": return TypeName.LONG; case "float": return TypeName.FLOAT; case "double": return TypeName.DOUBLE; case "short": return TypeName.SHORT; case "boolean": return TypeName.BOOLEAN; case "char": return TypeName.CHAR; default: return ClassName.bestGuess(originClazz); } }
Example 8
Source File: TypeUtils.java From data-mediator with Apache License 2.0 | 5 votes |
public static TypeName getTypeName(String type){ switch (type){ case NAME_int: return TypeName.INT; case NAME_long: return TypeName.LONG; case NAME_short: return TypeName.SHORT; case NAME_byte: return TypeName.BYTE; case NAME_boolean: return TypeName.BOOLEAN; case NAME_float: return TypeName.FLOAT; case NAME_double: return TypeName.DOUBLE; case NAME_char: return TypeName.CHAR; case NAME_void: return TypeName.VOID; } return ClassName.bestGuess(type); }
Example 9
Source File: EasyType.java From RapidORM with Apache License 2.0 | 5 votes |
/** * @param type * @return */ public static TypeName bestGuessDeep(String type) { switch (type) { case "void": return TypeName.VOID; case "boolean": return TypeName.BOOLEAN; case "byte": return TypeName.BYTE; case "char": return TypeName.CHAR; case "double": return TypeName.DOUBLE; case "float": return TypeName.FLOAT; case "int": return TypeName.INT; case "long": return TypeName.LONG; case "short": return TypeName.SHORT; default: int left = type.indexOf('<'); int right = type.indexOf('>'); if (-1 != left && -1 != right) { ClassName typeClassName = ClassName.bestGuess(type.substring(0, left)); List<TypeName> typeArguments = new ArrayList<>(); do { typeArguments.add(WildcardTypeName.subtypeOf(bestGuess(type.substring(left + 1, right)))); left = type.indexOf('<', left + 1); right = type.indexOf('>', right - 1); } while (left != -1); return ParameterizedTypeName.get(typeClassName, typeArguments.toArray(new TypeName[typeArguments.size()])); } return ClassName.bestGuess(type); } }
Example 10
Source File: Names.java From featured with Apache License 2.0 | 5 votes |
public TypeName getTypeNameByKind(VariableElement param) { switch (param.asType().getKind()) { case BOOLEAN: return TypeName.BOOLEAN; case BYTE: return TypeName.BYTE; case CHAR: return TypeName.CHAR; case DOUBLE: return TypeName.DOUBLE; case FLOAT: return TypeName.FLOAT; case INT: return TypeName.INT; case LONG: return TypeName.LONG; case SHORT: return TypeName.SHORT; case DECLARED: TypeMirror type = param.asType(); TypeName typeName = ClassName.get(type); typeName = applyAnnotations(typeName, param); return typeName; case ARRAY: ArrayType arrayType = (ArrayType) param.asType(); TypeName arrayTypeName = ArrayTypeName.get(arrayType); arrayTypeName = applyAnnotations(arrayTypeName, param); return arrayTypeName; default: throw new IllegalStateException("unsupported kind: " + param.asType().getKind()); } }
Example 11
Source File: ProcessUtils.java From Freezer with Apache License 2.0 | 5 votes |
public static String getFieldTableType(Element variableElement) { TypeName typeName = getFieldClass(variableElement); if (typeName == TypeName.INT || typeName == TypeName.BOOLEAN || typeName == TypeName.LONG || typeName == TypeName.BYTE) { return "integer"; } if (typeName == TypeName.FLOAT) { return "real"; } else if (ClassName.get(String.class).equals(typeName) || isDate(typeName)) { return "text"; } return null; }
Example 12
Source File: ProcessUtils.java From Freezer with Apache License 2.0 | 5 votes |
public static String getFieldType(VariableElement variableElement) { TypeName typeName = getFieldClass(variableElement); if (typeName == TypeName.INT || typeName == TypeName.BOOLEAN || typeName == TypeName.BYTE) { return "Int"; } else if (typeName == TypeName.LONG) { return "Long"; } else if (typeName == TypeName.FLOAT) { return "Float"; } else if (typeName == TypeName.DOUBLE) { return "Double"; } else if (ClassName.get(String.class).equals(typeName)) { return "String"; } return ""; }
Example 13
Source File: CodeBlockBuilder.java From aircon with MIT License | 5 votes |
public CodeBlockBuilder addPrimitiveCaster(TypeName className, Object var) { String caster = ""; if (className == TypeName.FLOAT) { caster = FLOAT_CASTER; } else if (className == TypeName.DOUBLE) { caster = DOUBLE_CASTER; } else if (className == TypeName.LONG) { caster = LONG_CASTER; } return add(var).add(caster); }
Example 14
Source File: ProcessUtils.java From RxAndroidOrm with Apache License 2.0 | 5 votes |
public static String getFieldTableType(Element variableElement) { TypeName typeName = getFieldClass(variableElement); if (typeName == TypeName.INT || typeName == TypeName.BOOLEAN || typeName == TypeName.LONG || typeName == TypeName.BYTE) { return "integer"; } if (typeName == TypeName.FLOAT) { return "real"; } else if (ClassName.get(String.class).equals(typeName) || isDate(typeName)) { return "text"; } return null; }
Example 15
Source File: ProcessUtils.java From RxAndroidOrm with Apache License 2.0 | 5 votes |
public static String getFieldType(VariableElement variableElement) { TypeName typeName = getFieldClass(variableElement); if (typeName == TypeName.INT || typeName == TypeName.BOOLEAN || typeName == TypeName.BYTE) { return "Int"; } else if (typeName == TypeName.LONG) { return "Long"; } else if (typeName == TypeName.FLOAT) { return "Float"; } else if (typeName == TypeName.DOUBLE) { return "Double"; } else if (ClassName.get(String.class).equals(typeName)) { return "String"; } return ""; }
Example 16
Source File: TypeNameUtils.java From componentrouter with Apache License 2.0 | 5 votes |
public static String getDefaultValue(String fullClassName) { TypeName typeName = getTypeName(fullClassName); if (typeName == TypeName.SHORT || typeName == TypeName.INT || typeName == TypeName.LONG || typeName == TypeName.FLOAT || typeName == TypeName.DOUBLE || typeName == TypeName.CHAR || typeName == TypeName.BYTE) { return String.format("(%s)0", typeName.toString()); } if (typeName == TypeName.BOOLEAN) { return "false"; } return String.format("(%s)null", typeName.toString()); }
Example 17
Source File: TypeNameUtils.java From componentrouter with Apache License 2.0 | 5 votes |
public static TypeName getTypeName(String fullClassName) { if (fullClassName.contains("[]")) { TypeName simpleName = getTypeName(fullClassName.replace("[]", "")); return ArrayTypeName.of(simpleName); } int index = fullClassName.lastIndexOf("."); if (index == -1) { fullClassName = fullClassName.toLowerCase(); switch (fullClassName) { case "short": return TypeName.SHORT; case "int": return TypeName.INT; case "long": return TypeName.LONG; case "float": return TypeName.FLOAT; case "double": return TypeName.DOUBLE; case "char": return TypeName.CHAR; case "byte": return TypeName.BYTE; case "boolean": return TypeName.BOOLEAN; default: return TypeName.INT; } } String packageName = fullClassName.substring(0, index); String className = fullClassName.replace(packageName, "").replace(".", ""); return ClassName.get(packageName, className); }
Example 18
Source File: OpenApi2JaxRs.java From apicurio-studio with Apache License 2.0 | 4 votes |
/** * Generates the java type name for a collection (optional) and type. Examples include list/string, * null/org.example.Bean, list/org.example.OtherBean, etc. * @param collection * @param type * @param format * @param required * @param defaultType */ private TypeName generateTypeName(String collection, String type, String format, Boolean required, TypeName defaultType) { if (type == null) { return defaultType; } if (required == null) { required = Boolean.FALSE; } boolean isList = "list".equals(collection); TypeName coreType = null; if (type.equals("string")) { coreType = ClassName.get(String.class); if (format != null) { if (format.equals("date") || format.equals("date-time")) { coreType = ClassName.get(Date.class); } // TODO handle byte, binary } } else if (type.equals("integer")) { coreType = ClassName.get(Integer.class); if (format != null) { if (format.equals("int32")) { coreType = required && !isList ? TypeName.INT : ClassName.get(Integer.class); } else if (format.equals("int64")) { coreType = required && !isList ? TypeName.LONG : ClassName.get(Long.class); } } } else if (type.equals("number")) { coreType = ClassName.get(Number.class); if (format != null) { if (format.equals("float")) { coreType = required && !isList ? TypeName.FLOAT : ClassName.get(Float.class); } else if (format.equals("double")) { coreType = required && !isList ? TypeName.DOUBLE : ClassName.get(Double.class); } } } else if (type.equals("boolean")) { coreType = ClassName.get(Boolean.class); } else { try { coreType = ClassName.bestGuess(type); } catch (Exception e) { return defaultType; } } if (collection == null) { return coreType; } if ("list".equals(collection)) { return ParameterizedTypeName.get(ClassName.get(List.class), coreType); } return defaultType; }
Example 19
Source File: ClassNameModel.java From nalu with Apache License 2.0 | 4 votes |
public TypeName getTypeName() { switch (className) { case "void": return TypeName.VOID; case "boolean": return TypeName.BOOLEAN; case "byte": return TypeName.BYTE; case "short": return TypeName.SHORT; case "int": return TypeName.INT; case "long": return TypeName.LONG; case "char": return TypeName.CHAR; case "float": return TypeName.FLOAT; case "double": return TypeName.DOUBLE; case "Object": return TypeName.OBJECT; case "Void": return ClassName.get("java.lang", "Void"); case "Boolean": return ClassName.get("java.lang", "Boolean"); case "Byte": return ClassName.get("java.lang", "Byte"); case "Short": return ClassName.get("java.lang", "Short"); case "Integer": return ClassName.get("java.lang", "Integer"); case "Long": return ClassName.get("java.lang", "Long"); case "Character": return ClassName.get("java.lang", "Character"); case "Float": return ClassName.get("java.lang", "Float"); case "Double": return ClassName.get("java.lang", "Double"); default: return ClassName.get(this.getPackage(), this.getSimpleName()); } }
Example 20
Source File: ClassNameModel.java From nalu with Apache License 2.0 | 4 votes |
public TypeName getTypeName() { switch (className) { case "void": return TypeName.VOID; case "boolean": return TypeName.BOOLEAN; case "byte": return TypeName.BYTE; case "short": return TypeName.SHORT; case "int": return TypeName.INT; case "long": return TypeName.LONG; case "char": return TypeName.CHAR; case "float": return TypeName.FLOAT; case "double": return TypeName.DOUBLE; case "Object": return TypeName.OBJECT; case "Void": return ClassName.get("java.lang", "Void"); case "Boolean": return ClassName.get("java.lang", "Boolean"); case "Byte": return ClassName.get("java.lang", "Byte"); case "Short": return ClassName.get("java.lang", "Short"); case "Integer": return ClassName.get("java.lang", "Integer"); case "Long": return ClassName.get("java.lang", "Long"); case "Character": return ClassName.get("java.lang", "Character"); case "Float": return ClassName.get("java.lang", "Float"); case "Double": return ClassName.get("java.lang", "Double"); default: return ClassName.get(this.getPackage(), this.getSimpleName()); } }