本文整理汇总了Java中com.squareup.javapoet.ClassName.simpleNames方法的典型用法代码示例。如果您正苦于以下问题:Java ClassName.simpleNames方法的具体用法?Java ClassName.simpleNames怎么用?Java ClassName.simpleNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javapoet.ClassName
的用法示例。
在下文中一共展示了ClassName.simpleNames方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEnhancedClassName
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
@Nonnull
ClassName getEnhancedClassName()
{
final ClassName className = ClassName.get( getElement() );
final ArrayList<String> names = new ArrayList<>( className.simpleNames() );
final String cname = getElement().getSimpleName() + "_";
if ( names.size() > 1 )
{
names.remove( names.size() - 1 );
names.add( cname );
return ClassName.get( getPackageName(),
names.get( 0 ),
names.subList( 1, names.size() ).toArray( new String[ 0 ] ) );
}
else
{
return ClassName.get( getPackageName(), cname );
}
}
示例2: toTypeMirror
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private TypeMirror toTypeMirror(Object name) {
if (name instanceof TypeMirror) {
return (TypeMirror)name;
} else if (name instanceof Class) {
return this.elements.getTypeElement(((Class)name).getCanonicalName()).asType();
} else if (name instanceof String) {
return this.elements.getTypeElement((String) name).asType();
} else if (name instanceof ClassName) {
ClassName clazz = (ClassName)name;
StringBuilder classNameBuilder = new StringBuilder();
classNameBuilder.append(clazz.packageName());
for (String elt : clazz.simpleNames()) {
classNameBuilder.append(".");
classNameBuilder.append(elt);
}
return this.elements.getTypeElement(classNameBuilder.toString()).asType();
} else if (name instanceof ParameterizedTypeName) {
return this.toTypeMirror(((ParameterizedTypeName)name).rawType);
} else if (name instanceof TypeName) {
return this.elements.getTypeElement(((TypeName)name).withoutAnnotations().toString()).asType();
} else {
throw new IllegalArgumentException(String.format("Invalid type name: %s", name));
}
}
示例3: getInjectedFQCN
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
public static String getInjectedFQCN(ClassName className) {
StringBuilder name = new StringBuilder();
for (String part : className.simpleNames()) {
if (name.length() > 0) {
name.append("$");
}
name.append(part);
}
return className.packageName() + "." + name.toString() + Constants.MAPPER_CLASS_SUFFIX;
}