本文整理匯總了Java中com.squareup.javapoet.TypeName.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeName.toString方法的具體用法?Java TypeName.toString怎麽用?Java TypeName.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.javapoet.TypeName
的用法示例。
在下文中一共展示了TypeName.toString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processNonSetTypes
import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
void processNonSetTypes(ElementDescription elem, MethodSpec.Builder fill) {
TypeName fieldType = elem.fieldType;
String key = elem.key;
String left = "smart." + elem.fieldName;
if(Util.isWrapper(fieldType)) { // 包裝類型需要使用Serializable才能保持null值的正確傳遞
fill.addStatement(left + " = (" + elem.fieldType + ") source.getSerializableExtra(\"" + key + "\")");
} else if(fieldType.equals(TypeName.BOOLEAN)) {
fill.addStatement(left + " = source.getBooleanExtra(\"" + key + "\", false)");
} else if(fieldType.equals(TypeName.BYTE)) {
fill.addStatement(left + " = source.getByteExtra(\"" + key + "\", (byte) 0)");
} else if(fieldType.equals(TypeName.CHAR)) {
fill.addStatement(left + " = source.getCharExtra(\"" + key + "\", '\\0')");
} else if(fieldType.equals(TypeName.SHORT)) {
fill.addStatement(left + " = source.getShortExtra(\"" + key + "\", (short) 0)");
} else if(fieldType.equals(TypeName.INT)) {
fill.addStatement(left + " = source.getIntExtra(\"" + key + "\", 0)");
} else if(fieldType.equals(TypeName.LONG)) {
fill.addStatement(left + " = source.getLongExtra(\"" + key + "\", 0)");
} else if(fieldType.equals(TypeName.FLOAT)) {
fill.addStatement(left + " = source.getFloatExtra(\"" + key + "\", 0.0f)");
} else if(fieldType.equals(TypeName.DOUBLE)) {
fill.addStatement(left + " = source.getDoubleExtra(\"" + key + "\", 0.0)");
} else if(fieldType.equals(ClazzNames.STRING)) {
fill.addStatement(left + " = source.getStringExtra(\"" + key + "\")");
} else if(fieldType.equals(ClazzNames.CHARSEQUENCE)) {
fill.addStatement(left + " = source.getCharSequenceExtra(\"" + key + "\")");
} else {
String tn = fieldType.toString();
if(tn.indexOf('<') >= 0) {
tn = tn.substring(0, tn.indexOf('<'));
}
fill.addStatement(left + " = ($T) $T.getValue(source, \"" + key + "\", " + tn + ".class)", fieldType, ClazzNames.INTENT_VALUE_GETTER);
}
}
示例2: getFieldClassName
import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
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;
}