本文整理汇总了Java中com.squareup.javapoet.ClassName.simpleName方法的典型用法代码示例。如果您正苦于以下问题:Java ClassName.simpleName方法的具体用法?Java ClassName.simpleName怎么用?Java ClassName.simpleName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javapoet.ClassName
的用法示例。
在下文中一共展示了ClassName.simpleName方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: builderBuild
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
public static MethodSpec builderBuild(ClassName className, List<MethodSpec> methodSpecList, List<FieldSpec> fieldSpecList) {
String name = className.simpleName();
CodeBlock.Builder codeBlock = CodeBlock.builder();
for (int i = 0; i < methodSpecList.size(); i++) {
codeBlock.add("$N.$N(this.$N);\n", name.toLowerCase(), methodSpecList.get(i).name, fieldSpecList.get(i).name);
}
return MethodSpec
.methodBuilder("build")
.addModifiers(Modifier.PUBLIC)
.addStatement("$N $N = new $N()", name, name.toLowerCase(), name)
.addCode(codeBlock.build())
.returns(className)
.addStatement("return $N", name.toLowerCase())
.build();
}
示例2: builderGroupBuild
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
public static MethodSpec builderGroupBuild(ClassName className, List<MethodSpec> methodSpecList, List<FieldSpec> fieldSpecList) {
String name = className.simpleName();
CodeBlock.Builder codeBlock = CodeBlock.builder();
for (int i = 0; i < methodSpecList.size(); i++) {
codeBlock.add("$N.$N(this.$N);\n", name.toLowerCase(), methodSpecList.get(i).name, fieldSpecList.get(i).name);
}
return MethodSpec
.methodBuilder("build")
.addModifiers(Modifier.PUBLIC)
.addStatement("$N $N = new $N($N)", name, name.toLowerCase(), name, "this.kiiGroup")
.addCode(codeBlock.build())
.returns(className)
.addStatement("return $N", name.toLowerCase())
.build();
}
示例3: generateUnboxMethod
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private MethodSpec generateUnboxMethod(
ClassName className,
TypeName typeName,
String primitiveType) {
String paramName = className.simpleName() + "Param";
paramName = Character.toLowerCase(paramName.charAt(0)) + paramName.substring(1);
String primitiveArray = primitiveType + "s";
return MethodSpec.methodBuilder("toPrimitive")
.addParameters(ImmutableList.of(ParameterSpec.builder(ArrayTypeName.of(className), paramName).build()))
.returns(ArrayTypeName.of(typeName))
.addModifiers(PUBLIC)
.addModifiers(STATIC)
.addStatement("$L[] $L = new $L[$L.length]", primitiveType, primitiveArray, primitiveType, paramName)
.beginControlFlow("for (int i = 0; i < $L.length; i++)", paramName)
.addStatement("$L[i] = $L[i]", primitiveArray, paramName)
.endControlFlow()
.addStatement("return $L", primitiveArray)
.build();
}
示例4: getPrimitiveArrayClassName
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
public static String getPrimitiveArrayClassName(Element element) {
if (element.asType().getKind() != TypeKind.ARRAY) {
throw new IllegalArgumentException("element is not array: " + element.toString());
}
ArrayType arrayType = (ArrayType) element.asType();
TypeMirror componentType = arrayType.getComponentType();
ClassName className = (ClassName) TypeName.get(componentType).box();
return className.simpleName() + "Array";
}
示例5: toOutputClass
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
public static ClassName toOutputClass(TypeName dataEnumType) throws ParserException {
ClassName dataEnumClass = (ClassName) dataEnumType;
String packageName = dataEnumClass.packageName();
String name = dataEnumClass.simpleName();
if (!name.endsWith(SUFFIX)) {
throw new ParserException(
String.format(
"Bad name for DataEnum interface! Name must end with '%s', found: %s", SUFFIX, name));
}
String nameWithoutSuffix = name.substring(0, name.length() - SUFFIX.length());
return ClassName.get(packageName, nameWithoutSuffix);
}
示例6: getFieldClassName
import com.squareup.javapoet.ClassName; //导入方法依赖的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;
}
示例7: writeRxObserve
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private void writeRxObserve() {
final TypeSpec.Builder builder = TypeSpec.classBuilder(Constants.CLASS)
.addModifiers(Modifier.PUBLIC);
for (ClassName className : observeHolders.keySet()) {
final ObserveHolder observeHolder = observeHolders.get(className);
final String simpleName = className.simpleName();
final TypeName returnType = ClassName.bestGuess(className.packageName() + "." + simpleName + Constants.OBSERVE_CLASS);
if (processUtils.allMethodsAreStatic(observeHolder.methods)) {
builder.addMethod(MethodSpec.methodBuilder(Constants.METHOD_OF + simpleName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(returnType)
.addStatement("return new $T()", returnType)
.build());
} else {
builder.addMethod(MethodSpec.methodBuilder(Constants.METHOD_OF)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addParameter(className, Constants.TARGET)
.returns(returnType)
.addStatement("return new $T($L)", returnType, Constants.TARGET)
.build());
}
}
final TypeSpec newClass = builder.build();
final JavaFile javaFile = JavaFile.builder(Constants.PACKAGE, newClass).build();
try {
javaFile.writeTo(System.out);
javaFile.writeTo(filer);
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: findDaggerComponent
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private ClassName findDaggerComponent(TypeMirror typeMirror) {
final ClassName typeName = (ClassName) TypeName.get(typeMirror);
final String packageName = typeName.packageName();
final String className = typeName.simpleName();
return ClassName.bestGuess(packageName + "." + Constants.DAGGER + className);
}
示例9: findComponent
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private ClassName findComponent(TypeMirror typeMirror) {
final ClassName typeName = (ClassName) TypeName.get(typeMirror);
final String packageName = typeName.packageName();
final String className = typeName.simpleName();
return ClassName.bestGuess(packageName + "." + className);
}
示例10: asString
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private String asString(ClassName className) {
return className.packageName() + "." + className.simpleName();
}
示例11: getMethodName
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private static String getMethodName(ClassName className) {
return "get" + className.simpleName();
}
示例12: process
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Set<? extends Element> reactModuleListElements = roundEnv.getElementsAnnotatedWith(
ReactModuleList.class);
for (Element reactModuleListElement : reactModuleListElements) {
if (!(reactModuleListElement instanceof TypeElement)) {
continue;
}
TypeElement typeElement = (TypeElement) reactModuleListElement;
ReactModuleList reactModuleList = typeElement.getAnnotation(ReactModuleList.class);
if (reactModuleList == null) {
continue;
}
ClassName className = ClassName.get(typeElement);
String packageName = ClassName.get(typeElement).packageName();
String fileName = className.simpleName();
List<String> nativeModules = new ArrayList<>();
try {
reactModuleList.nativeModules(); // throws MirroredTypesException
} catch (MirroredTypesException mirroredTypesException) {
List<? extends TypeMirror> typeMirrors = mirroredTypesException.getTypeMirrors();
for (TypeMirror typeMirror : typeMirrors) {
nativeModules.add(typeMirror.toString());
}
}
MethodSpec getReactModuleInfosMethod;
try {
getReactModuleInfosMethod = MethodSpec.methodBuilder("getReactModuleInfos")
.addAnnotation(Override.class)
.addModifiers(PUBLIC)
.addCode(getCodeBlockForReactModuleInfos(nativeModules))
.returns(MAP_TYPE)
.build();
} catch (ReactModuleSpecException reactModuleSpecException) {
mMessager.printMessage(ERROR, reactModuleSpecException.mMessage);
return false;
}
TypeSpec reactModulesInfosTypeSpec = TypeSpec.classBuilder(
fileName + "$$ReactModuleInfoProvider")
.addModifiers(Modifier.PUBLIC)
.addMethod(getReactModuleInfosMethod)
.addSuperinterface(ReactModuleInfoProvider.class)
.build();
JavaFile javaFile = JavaFile.builder(packageName, reactModulesInfosTypeSpec)
.addFileComment("Generated by " + getClass().getName())
.build();
try {
javaFile.writeTo(mFiler);
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}