Java Code Examples for com.squareup.javapoet.TypeName#SHORT
The following examples show how to use
com.squareup.javapoet.TypeName#SHORT .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
Source File: Scalars.java From raml-java-tools with Apache License 2.0 | 5 votes |
public static TypeName classToTypeName(Class scalar) { if (scalar.isPrimitive()) { switch (scalar.getSimpleName()) { case "int": return TypeName.INT; case "boolean": return TypeName.BOOLEAN; case "double": return TypeName.DOUBLE; case "float": return TypeName.FLOAT; case "byte": return TypeName.BYTE; case "char": return TypeName.CHAR; case "short": return TypeName.SHORT; case "long": return TypeName.LONG; case "void": return TypeName.VOID; // ? default: throw new GenerationException("can't handle type: " + scalar); } } else { return ClassName.get(scalar); } }
Example 11
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 12
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 13
Source File: EasyType.java From RapidORM with Apache License 2.0 | 5 votes |
public 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 14
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 15
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 16
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()); } }