本文整理汇总了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;
}