当前位置: 首页>>代码示例>>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;未经允许,请勿转载。