Java Code Examples for com.squareup.javapoet.TypeName#toString()
The following examples show how to use
com.squareup.javapoet.TypeName#toString() .
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: BindTransformer.java From kripton with Apache License 2.0 | 6 votes |
/** * Get java.util type Transformable * * @param type * the type * @return the util transform */ static BindTransform getUtilTransform(TypeName type) { String typeName = type.toString(); // Integer.class.getCanonicalName().equals(typeName) if (Date.class.getCanonicalName().equals(typeName)) { return new DateBindTransform(); } if (Locale.class.getCanonicalName().equals(typeName)) { return new LocaleBindTransform(); } if (Currency.class.getCanonicalName().equals(typeName)) { return new CurrencyBindTransform(); } if (Calendar.class.getCanonicalName().equals(typeName)) { return new CalendarBindTransform(); } if (TimeZone.class.getCanonicalName().equals(typeName)) { return new TimeZoneBindTransform(); } return null; }
Example 2
Source File: PrefsTransformer.java From kripton with Apache License 2.0 | 6 votes |
/** * Get java.util type Transformable * * @param type the type * @return the util transform */ static PrefsTransform getUtilTransform(TypeName type) { String typeName = type.toString(); // Integer.class.getCanonicalName().equals(typeName) if (Date.class.getCanonicalName().equals(typeName)) { return new DatePrefsTransform(); } if (Locale.class.getCanonicalName().equals(typeName)) { return new LocalePrefsTransform(); } if (Currency.class.getCanonicalName().equals(typeName)) { return new CurrencyPrefsTransform(); } if (Calendar.class.getCanonicalName().equals(typeName)) { return new CalendarPrefsTransform(); } if (TimeZone.class.getCanonicalName().equals(typeName)) { return new TimeZonePrefsTransform(); } return null; }
Example 3
Source File: ColumnEntry.java From RapidORM with Apache License 2.0 | 6 votes |
public String parseDbType(TypeName typeName) { String typeNameStr = typeName.toString(); if (String.class.getCanonicalName().equals(typeNameStr)) { return "TEXT"; } else if (Long.class.getCanonicalName().equals(typeNameStr) || long.class.getCanonicalName().equals(typeNameStr)) { return "LONG"; } else if (Integer.class.getCanonicalName().equals(typeNameStr) || int.class.getCanonicalName().equals(typeNameStr) || Boolean.class.getCanonicalName().equals(typeNameStr) || boolean.class.getCanonicalName().equals(typeNameStr)) { return "INTEGER"; } else if (Short.class.getCanonicalName().equals(typeNameStr) || short.class.getCanonicalName().equals(typeNameStr)) { return "SHORT"; } else if (Double.class.getCanonicalName().equals(typeNameStr) || double.class.getCanonicalName().equals(typeNameStr)) { return "DOUBLE"; } else if (Float.class.getCanonicalName().equals(typeNameStr) || float.class.getCanonicalName().equals(typeNameStr)) { return "FLOAT"; } else if (Blob.class.getCanonicalName().equals(typeNameStr)) { return "BLOB"; } throw new RuntimeException("columnType[" + typeNameStr + "] not supported"); }
Example 4
Source File: TypeUtils.java From grouter-android with Apache License 2.0 | 6 votes |
public static String getRouterTaskTypeString(TypeName typeName) { // 判断是否泛型 if (typeName instanceof ParameterizedTypeName) { typeName = ((ParameterizedTypeName) typeName).rawType; } // 获取支持支持的类型 if (baseTypeNameSet.contains(typeName)) { return typeName.toString(); } // 判断是否数组 else if (typeName instanceof ArrayTypeName) { typeName = ((ArrayTypeName) typeName).componentType; return getRouterTaskTypeString(typeName) + "[]"; } else { String typeNameString = typeName.toString(); if (typeNameString.startsWith("android") || typeNameString.startsWith("java")) { return typeNameString; } return "Object"; } }
Example 5
Source File: TypeUtils.java From grouter-android with Apache License 2.0 | 6 votes |
/** * @return int/long/float/double/boolean/ * Integer/Long/Double/Float/Boolean/String/ * int[]/long[]/float[]/double[]/boolean[]/Object[]/String[] * Activity/Context/Application/Object/Map/HashMap/List/ArrayList */ public static String getRouterActivityTypeString(TypeName typeName) { // 判断是否泛型 if (typeName instanceof ParameterizedTypeName) { typeName = ((ParameterizedTypeName) typeName).rawType; } // 获取支持支持的类型 if (baseTypeNameSet.contains(typeName)) { return typeName.toString(); } // 判断是否数组 else if (typeName instanceof ArrayTypeName) { return "Object[]"; } else { return "Object"; } }
Example 6
Source File: TypeUtils.java From grouter-android with Apache License 2.0 | 6 votes |
/** * @return int/long/float/double/boolean/ * Integer/Long/Double/Float/Boolean/String/ * int[]/long[]/float[]/double[]/boolean[]/Object[]/String[] * Activity/Context/Application/Object/Map/HashMap/List/ArrayList */ public static String getRouterActivityTypeString(TypeName typeName) { // 判断是否泛型 if (typeName instanceof ParameterizedTypeName) { typeName = ((ParameterizedTypeName) typeName).rawType; } // 获取支持支持的类型 if (baseTypeNameSet.contains(typeName)) { return typeName.toString(); } // 判断是否数组 else if (typeName instanceof ArrayTypeName) { return "Object[]"; } else { return "Object"; } }
Example 7
Source File: SpotCompiler.java From spot with Apache License 2.0 | 6 votes |
private void handlePrefField(Element element1, MethodSpec.Builder getEntitySpecBuilder, MethodSpec.Builder putEntitySpecBuilder) { PrefField pref = element1.getAnnotation(PrefField.class); // Convert class TypeName convertClass = getConvertClass(pref); String className = convertClass.toString(); if ("java.lang.Void".equals(className)) { className = element1.asType().toString(); } if ("int".equals(className) || "java.lang.Integer".equals(className)) { handlePrefInt(element1, getEntitySpecBuilder, putEntitySpecBuilder); } else if ("long".equals(className) || "java.lang.Long".equals(className)) { handlePrefLong(element1, getEntitySpecBuilder, putEntitySpecBuilder); } else if ("float".equals(className) || "java.lang.Float".equals(className)) { handlePrefFloat(element1, getEntitySpecBuilder, putEntitySpecBuilder); } else if ("boolean".equals(className) || "java.lang.Boolean".equals(className)) { handlePrefBoolean(element1, getEntitySpecBuilder, putEntitySpecBuilder); } else if ("java.lang.String".equals(className)) { handlePrefString(element1, getEntitySpecBuilder, putEntitySpecBuilder); } else if ("java.util.Set<java.lang.String>".equals(className)) { handlePrefStringSet(element1, getEntitySpecBuilder, putEntitySpecBuilder); } }
Example 8
Source File: ColumnEntry.java From RapidORM with Apache License 2.0 | 6 votes |
protected String parseDataType(TypeName typeName) { String typeNameStr = typeName.toString(); if (String.class.getCanonicalName().equals(typeNameStr)) { return "String"; } else if (Long.class.getCanonicalName().equals(typeNameStr) || long.class.getCanonicalName().equals(typeNameStr)) { return "Long"; } else if (Integer.class.getCanonicalName().equals(typeNameStr) || int.class.getCanonicalName().equals(typeNameStr) || Boolean.class.getCanonicalName().equals(typeNameStr) || boolean.class.getCanonicalName().equals(typeNameStr)) { return "Int"; } else if (Short.class.getCanonicalName().equals(typeNameStr) || short.class.getCanonicalName().equals(typeNameStr)) { return "Short"; } else if (Double.class.getCanonicalName().equals(typeNameStr) || double.class.getCanonicalName().equals(typeNameStr)) { return "Double"; } else if (Float.class.getCanonicalName().equals(typeNameStr) || float.class.getCanonicalName().equals(typeNameStr)) { return "Float"; } else if (Blob.class.getCanonicalName().equals(typeNameStr)) { return "Blob"; } return null; }
Example 9
Source File: JniProcessor.java From cronet with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Since some types may decay to objects in the native method * this method returns a javadoc string that contains the * type information from the old method. The fully qualified * descriptor of the method is also included since the name * may be hashed. */ String createNativeMethodJavadocString(ClassName outerType, ExecutableElement oldMethod) { ArrayList<String> docLines = new ArrayList<>(); // Class descriptor. String descriptor = String.format("%s.%s.%s", outerType.packageName(), outerType.simpleName(), oldMethod.getSimpleName().toString()); docLines.add(descriptor); // Parameters. for (VariableElement param : oldMethod.getParameters()) { TypeName paramType = TypeName.get(param.asType()); String paramTypeName = paramType.toString(); String name = param.getSimpleName().toString(); docLines.add(String.format("@param %s (%s)", name, paramTypeName)); } // Return type. docLines.add(String.format("@return (%s)", oldMethod.getReturnType().toString())); return String.join("\n", docLines) + "\n"; }
Example 10
Source File: TypeUtility.java From kripton with Apache License 2.0 | 5 votes |
/** * Return simple typeName of class. * * @param clazzName * the clazz name * @return the string */ public static String simpleName(TypeName clazzName) { String clazz = clazzName.toString(); int index = clazz.lastIndexOf("."); if (index > 0) { clazz=clazz.substring(index + 1); } return clazz; }
Example 11
Source File: ProcessUtils.java From Freezer with Apache License 2.0 | 5 votes |
public static String getFieldClassName(Element element) { String name; TypeName t = getFieldClass(element); if (t instanceof ClassName) { ClassName className = (ClassName) t; name = className.simpleName(); } else { name = t.toString(); } return name; }
Example 12
Source File: AnnotatedDurableEntityClass.java From mnemonic with Apache License 2.0 | 5 votes |
private long computeTypeSize(TypeName tname) throws AnnotationProcessingException { long ret = 0L; if (isUnboxPrimitive(tname)) { TypeName tn = unboxTypeName(tname); if (tn.equals(TypeName.BOOLEAN)) { ret = 1L; } if (tn.equals(TypeName.BYTE)) { ret = 1L; } if (tn.equals(TypeName.CHAR)) { ret = 2L; } if (tn.equals(TypeName.DOUBLE)) { ret = 8L; } if (tn.equals(TypeName.FLOAT)) { ret = 4L; } if (tn.equals(TypeName.INT)) { ret = 4L; } if (tn.equals(TypeName.LONG)) { ret = 8L; } if (tn.equals(TypeName.SHORT)) { ret = 2L; } } else { ret = 8L; } if (0L == ret) { throw new AnnotationProcessingException(null, "%s is not supported for type names", tname.toString()); } return ret; }
Example 13
Source File: AnnotatedDurableEntityClass.java From mnemonic with Apache License 2.0 | 5 votes |
protected String transTypeToUnsafeMethod(TypeName tname, boolean isget) throws AnnotationProcessingException { String ret = null; if (isUnboxPrimitive(tname)) { TypeName tn = unboxTypeName(tname); if (tn.equals(TypeName.BOOLEAN)) { ret = isget ? "getByte" : "putByte"; } if (tn.equals(TypeName.BYTE)) { ret = isget ? "getByte" : "putByte"; } if (tn.equals(TypeName.CHAR)) { ret = isget ? "getChar" : "putChar"; } if (tn.equals(TypeName.DOUBLE)) { ret = isget ? "getDouble" : "putDouble"; } if (tn.equals(TypeName.FLOAT)) { ret = isget ? "getFloat" : "putFloat"; } if (tn.equals(TypeName.INT)) { ret = isget ? "getInt" : "putInt"; } if (tn.equals(TypeName.LONG)) { ret = isget ? "getLong" : "putLong"; } if (tn.equals(TypeName.SHORT)) { ret = isget ? "getShort" : "putShort"; } } else { ret = isget ? "getAddress" : "putAddress"; } if (null == ret) { throw new AnnotationProcessingException(null, "%s is not supported by getters or setters.", tname.toString()); } return ret; }
Example 14
Source File: AnnotatedDurableEntityClass.java From mnemonic with Apache License 2.0 | 5 votes |
protected String getIntialValueLiteral(TypeName tname) throws AnnotationProcessingException { String ret = null; if (isUnboxPrimitive(tname)) { TypeName tn = unboxTypeName(tname); if (tn.equals(TypeName.BOOLEAN)) { ret = "false"; } if (tn.equals(TypeName.BYTE)) { ret = "(byte)0"; } if (tn.equals(TypeName.CHAR)) { ret = "(char)0"; } if (tn.equals(TypeName.DOUBLE)) { ret = "(double)0.0"; } if (tn.equals(TypeName.FLOAT)) { ret = "(float)0.0"; } if (tn.equals(TypeName.INT)) { ret = "(int)0"; } if (tn.equals(TypeName.LONG)) { ret = "(long)0"; } if (tn.equals(TypeName.SHORT)) { ret = "(short)0"; } } else { ret = null; } if (null == ret) { throw new AnnotationProcessingException(null, "%s is not supported to determine the inital value.", tname.toString()); } return ret; }
Example 15
Source File: BindTransformer.java From kripton with Apache License 2.0 | 5 votes |
/** * Get Java primitive wrapping type Transformable. * * @param type * the type * @return the language transform */ static BindTransform getLanguageTransform(TypeName type) { String typeName = type.toString(); if (Integer.class.getCanonicalName().equals(typeName)) { return new IntegerBindTransform(true); } if (Boolean.class.getCanonicalName().equals(typeName)) { return new BooleanBindTransform(true); } if (Long.class.getCanonicalName().equals(typeName)) { return new LongBindTransform(true); } if (Double.class.getCanonicalName().equals(typeName)) { return new DoubleBindTransform(true); } if (Float.class.getCanonicalName().equals(typeName)) { return new FloatBindTransform(true); } if (Short.class.getCanonicalName().equals(typeName)) { return new ShortBindTransform(true); } if (Byte.class.getCanonicalName().equals(typeName)) { return new ByteBindTransform(true); } if (Character.class.getCanonicalName().equals(typeName)) { return new CharacterBindTransform(true); } if (String.class.getCanonicalName().equals(typeName)) { return new StringBindTransform(); } return null; }
Example 16
Source File: AdapterNameGenerator.java From paperparcel with Apache License 2.0 | 5 votes |
private String getNameInternal(TypeName typeName) { String adapterName = null; if (typeName instanceof WildcardTypeName) { WildcardTypeName wildcardTypeName = (WildcardTypeName) typeName; String upperBoundsPart = ""; String lowerBoundsPart = ""; for (TypeName upperBound : wildcardTypeName.upperBounds) { upperBoundsPart += getNameInternal(upperBound); } for (TypeName lowerBound : wildcardTypeName.lowerBounds) { lowerBoundsPart += getNameInternal(lowerBound); } adapterName = upperBoundsPart + lowerBoundsPart; } if (typeName instanceof ArrayTypeName) { ArrayTypeName arrayTypeName = (ArrayTypeName) typeName; adapterName = getNameInternal(arrayTypeName.componentType) + "Array"; } if (typeName instanceof ParameterizedTypeName) { ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName; String paramPart = ""; for (TypeName param : parameterizedTypeName.typeArguments) { paramPart += getNameInternal(param); } adapterName = paramPart + parameterizedTypeName.rawType.simpleName(); } if (typeName instanceof ClassName) { ClassName className = (ClassName) typeName; adapterName = Joiner.on("_").join(className.simpleNames()); } if (typeName.isPrimitive()) { adapterName = typeName.toString(); } if (adapterName == null) { throw new AssertionError(); } return adapterName; }
Example 17
Source File: PrefsTransformer.java From kripton with Apache License 2.0 | 5 votes |
/** * Get Java primitive wrapping type Transformable. * * @param type the type * @return the language transform */ static PrefsTransform getLanguageTransform(TypeName type) { String typeName = type.toString(); if (Integer.class.getCanonicalName().equals(typeName)) { return new IntegerPrefsTransform(true); } if (Boolean.class.getCanonicalName().equals(typeName)) { return new BooleanPrefsTransform(true); } if (Long.class.getCanonicalName().equals(typeName)) { return new LongPrefsTransform(true); } if (Double.class.getCanonicalName().equals(typeName)) { return new DoublePrefsTransform(true); } if (Float.class.getCanonicalName().equals(typeName)) { return new FloatPrefsTransform(true); } if (Short.class.getCanonicalName().equals(typeName)) { return new ShortPrefsTransform(true); } if (Byte.class.getCanonicalName().equals(typeName)) { return new BytePrefsTransform(true); } if (Character.class.getCanonicalName().equals(typeName)) { return new CharacterPrefsTransform(true); } if (String.class.getCanonicalName().equals(typeName)) { return new StringPrefsTransform(); } return null; }
Example 18
Source File: SQLTransformer.java From kripton with Apache License 2.0 | 5 votes |
/** * Get Java primitive wrapping type Transformable. * * @param type * the type * @return the language transform */ static SQLTransform getLanguageTransform(TypeName type) { String typeName = type.toString(); if (Integer.class.getCanonicalName().equals(typeName)) { return new IntegerSQLTransform(true); } if (Boolean.class.getCanonicalName().equals(typeName)) { return new BooleanSQLTransform(true); } if (Long.class.getCanonicalName().equals(typeName)) { return new LongSQLTransform(true); } if (Double.class.getCanonicalName().equals(typeName)) { return new DoubleSQLTransform(true); } if (Float.class.getCanonicalName().equals(typeName)) { return new FloatSQLTransform(true); } if (Short.class.getCanonicalName().equals(typeName)) { return new ShortSQLTransform(true); } if (Byte.class.getCanonicalName().equals(typeName)) { return new ByteSQLTransform(true); } if (Character.class.getCanonicalName().equals(typeName)) { return new CharacterSQLTransform(true); } if (String.class.getCanonicalName().equals(typeName)) { return new StringSQLTransform(); } return null; }
Example 19
Source File: SQLTransformer.java From kripton with Apache License 2.0 | 5 votes |
/** * Checks if is supported JDK type. * * @param typeName * the type name * @return true, if is supported JDK type */ public static boolean isSupportedJDKType(TypeName typeName) { if (typeName.isPrimitive()) { return getPrimitiveTransform(typeName) != null; } String name = typeName.toString(); if (name.startsWith("java.lang")) { return getLanguageTransform(typeName) != null; } if (name.startsWith("java.util")) { return getUtilTransform(typeName) != null; } if (name.startsWith("java.math")) { return getMathTransform(typeName) != null; } if (name.startsWith("java.net")) { return getNetTransform(typeName) != null; } if (name.startsWith("java.sql")) { return getSqlTransform(typeName) != null; } return false; }
Example 20
Source File: BindTransformer.java From kripton with Apache License 2.0 | 4 votes |
/** * Gets the transform. * * @param typeName * the type name * @return the transform */ static BindTransform getTransform(TypeName typeName) { if (typeName.isPrimitive()) { return getPrimitiveTransform(typeName); } if (typeName instanceof ArrayTypeName) { ArrayTypeName typeNameArray = (ArrayTypeName) typeName; if (TypeUtility.isEquals(typeNameArray.componentType, Byte.TYPE.toString())) { return new ByteArrayBindTransform(); } else { return new ArrayBindTransform(typeNameArray.componentType, typeNameArray.componentType.isPrimitive()); } } else if (typeName instanceof ParameterizedTypeName) { ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName; if (TypeUtility.isList(parameterizedTypeName.rawType)) { return new ListBindTransformation(parameterizedTypeName); } else if (TypeUtility.isSet(parameterizedTypeName.rawType)) { return new SetBindTransformation(parameterizedTypeName); } else if (TypeUtility.isMap(parameterizedTypeName.rawType)) { return new MapBindTransformation(parameterizedTypeName); } } String name = typeName.toString(); if (name.startsWith("java.lang")) { return getLanguageTransform(typeName); } if (name.startsWith("java.util")) { return getUtilTransform(typeName); } if (name.startsWith("java.math")) { return getMathTransform(typeName); } if (name.startsWith("java.net")) { return getNetTransform(typeName); } if (name.startsWith("java.sql")) { return getSqlTransform(typeName); } if (TypeUtility.isEnum(typeName)) { return new EnumBindTransform(typeName); } // for default is treated as object return new ObjectBindTransform(); }