當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassName.simpleName方法代碼示例

本文整理匯總了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();
}
 
開發者ID:daisuke-nomura,項目名稱:KiiAnnotation,代碼行數:18,代碼來源:BuilderGenerator.java

示例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();
}
 
開發者ID:daisuke-nomura,項目名稱:KiiAnnotation,代碼行數:18,代碼來源:BuilderGenerator.java

示例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();
}
 
開發者ID:uber,項目名稱:auto-value-bundle,代碼行數:20,代碼來源:BundleExtension.java

示例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";
}
 
開發者ID:srym,項目名稱:vulture,代碼行數:11,代碼來源:TypeUtils.java

示例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);
}
 
開發者ID:spotify,項目名稱:dataenum,代碼行數:16,代碼來源:OutputSpecFactory.java

示例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;
}
 
開發者ID:florent37,項目名稱:RxAndroidOrm,代碼行數:14,代碼來源:ProcessUtils.java

示例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();
    }
}
 
開發者ID:florent37,項目名稱:Rx.Observe,代碼行數:37,代碼來源:RxObserveProcessor.java

示例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);
}
 
開發者ID:florent37,項目名稱:DaggerAutoInject,代碼行數:7,代碼來源:DaggerAutoInjectProcessor.java

示例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);
}
 
開發者ID:florent37,項目名稱:DaggerAutoInject,代碼行數:7,代碼來源:DaggerAutoInjectProcessor.java

示例10: asString

import com.squareup.javapoet.ClassName; //導入方法依賴的package包/類
private String asString(ClassName className) {
    return className.packageName() + "." + className.simpleName();
}
 
開發者ID:sedstrom,項目名稱:Witch-Android,代碼行數:4,代碼來源:TypeUtils.java

示例11: getMethodName

import com.squareup.javapoet.ClassName; //導入方法依賴的package包/類
private static String getMethodName(ClassName className) {
    return "get" + className.simpleName();
}
 
開發者ID:uber,項目名稱:auto-value-bundle,代碼行數:4,代碼來源:Bundlables.java

示例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;
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:63,代碼來源:ReactModuleSpecProcessor.java


注:本文中的com.squareup.javapoet.ClassName.simpleName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。