当前位置: 首页>>代码示例>>Java>>正文


Java ClassName类代码示例

本文整理汇总了Java中com.squareup.javapoet.ClassName的典型用法代码示例。如果您正苦于以下问题:Java ClassName类的具体用法?Java ClassName怎么用?Java ClassName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClassName类属于com.squareup.javapoet包,在下文中一共展示了ClassName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: modelSuperInterfaces

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
private List<TypeName> modelSuperInterfaces() {
    List<TypeName> interfaces = new ArrayList<>();

    if (implementStructuredPojoInterface()) {
        interfaces.add(ClassName.get(StructuredPojo.class));
    }

    switch (shapeModel.getShapeType()) {
        case Exception:
        case Model:
        case Request:
        case Response:
            interfaces.add(toCopyableBuilderInterface());
            break;
        default:
            break;
    }

    return interfaces;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:21,代码来源:AwsServiceModel.java

示例2: newBuilder

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
static Builder newBuilder(TypeElement enclosingElement) {
  TypeMirror typeMirror = enclosingElement.asType();

  boolean isView = isSubtypeOfType(typeMirror, VIEW_TYPE);
  boolean isActivity = isSubtypeOfType(typeMirror, ACTIVITY_TYPE);
  boolean isDialog = isSubtypeOfType(typeMirror, DIALOG_TYPE);

  TypeName targetType = TypeName.get(typeMirror);
  if (targetType instanceof ParameterizedTypeName) {
    targetType = ((ParameterizedTypeName) targetType).rawType;
  }

  String packageName = getPackage(enclosingElement).getQualifiedName().toString();
  String className = enclosingElement.getQualifiedName().toString().substring(
      packageName.length() + 1).replace('.', '$');
  ClassName bindingClassName = ClassName.get(packageName, className + "_ViewBinding");

  boolean isFinal = enclosingElement.getModifiers().contains(Modifier.FINAL);
  return new Builder(targetType, bindingClassName, isFinal, isView, isActivity, isDialog);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:BindingSet.java

示例3: BindingSet

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
private BindingSet(TypeName targetTypeName, ClassName bindingClassName, boolean isFinal,
                   boolean isView, boolean isActivity,boolean isFragment, boolean isDialog, ImmutableList<ViewBinding> viewBindings,
                   ImmutableList<FieldCollectionViewBinding> collectionBindings,
                   ImmutableList<ResourceBinding> resourceBindings, BindingSet parentBinding, @LayoutRes int layoutId) {
    this.isFinal = isFinal;
    this.targetTypeName = targetTypeName;
    this.bindingClassName = bindingClassName;
    this.isView = isView;
    this.isActivity = isActivity;
    this.isFragment = isFragment;
    this.isDialog = isDialog;
    this.viewBindings = viewBindings;
    this.collectionBindings = collectionBindings;
    this.resourceBindings = resourceBindings;
    this.parentBinding = parentBinding;
    this.layoutId = layoutId;
}
 
开发者ID:qq542391099,项目名称:butterknife-parent,代码行数:18,代码来源:BindingSet.java

示例4: buildDaggerModule

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
@Nonnull
private static TypeSpec buildDaggerModule( @Nonnull final ComponentDescriptor descriptor )
{
  final TypeSpec.Builder builder = TypeSpec.classBuilder( "DaggerModule" );

  builder.addModifiers( Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL );
  builder.addAnnotation( ClassName.bestGuess( Constants.DAGGER_MODULE_CLASSNAME ) );

  final MethodSpec.Builder method =
    MethodSpec.methodBuilder( "provideComponent" ).
      addAnnotation( ClassName.bestGuess( Constants.DAGGER_PROVIDES_CLASSNAME ) ).
      addModifiers( Modifier.STATIC ).
      addParameter( descriptor.getClassNameToConstruct(), "component", Modifier.FINAL ).
      returns( COMPONENT_CLASSNAME ).
      addStatement( "return component" );
  builder.addMethod( method.build() );

  return builder.build();
}
 
开发者ID:react4j,项目名称:react4j,代码行数:20,代码来源:Generator.java

示例5: registerItem

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
@Override
protected void registerItem(EndpointsEntry entry, MethodSpec.Builder methodBuilder) {
    final FullClassName handlerEndpoint = new FullClassName(entry.element.fullQualifiedNoneGenericName() + "EndpointHandler");
    String path = entry.element.getAnnotation(Handler.class).value();

    ClassName handlerEndpointType = ClassName.get(handlerEndpoint.asPackage(), handlerEndpoint.asSimpleName());
    MethodSpec getMethod = MethodSpec.methodBuilder("get")
            .addAnnotation(Override.class)
            .addModifiers(Modifier.PUBLIC)
            .returns(handlerEndpointType)
            .addStatement("return new $T()", handlerEndpointType)
            .build();

    TypeSpec factoryType = TypeSpec.anonymousClassBuilder("")
            .addSuperinterface(ParameterizedTypeName.get(ClassName.get(Supplier.class), handlerEndpointType.box()))
            .addMethod(getMethod)
            .build();
    methodBuilder.addStatement("registry.registerEndpoint(\"" + path + "\", $L)", factoryType);
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:20,代码来源:EndpointsRegisterMethodWriter.java

示例6: generateSharedProperties

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
public static boolean generateSharedProperties(Collection<FieldData> fields,
                                               Elements elements, Filer filer, ProcessorPrinter pp){
    final ClassName cn_sp = ClassName.get(PKG_DM_INTERNAL, SIMPLE_NAME_SHARED_PROP);
    CodeBlock.Builder staticBuilder = CodeBlock.builder();
    for(FieldData fd : fields){
        staticBuilder.add("$T.putToCache($S, $S, $L);\n", cn_sp, fd.getTypeCompat().toString(),
                fd.getPropertyName(), fd.getComplexType());
    }
    String classSimpleName = SIMPLE_NAME_SHARED_PROP + "_" + findBestIndex(elements);
    TypeSpec typeSpec = TypeSpec.classBuilder(classSimpleName)
            .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
            .addStaticBlock(staticBuilder.build())
            .addJavadoc(CodeBlock.of(DOC))
            .build();

    try {
        JavaFile javaFile = JavaFile.builder(PKG_DM_INTERNAL, typeSpec)
                .build();
       // System.out.println(javaFile.toString());
        javaFile.writeTo(filer);
    } catch (IOException e) {
        pp.error(TAG, "generateSharedProperties", Util.toString(e));
        return false;
    }
    return true;
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:27,代码来源:SharedPropertiesNGenerator.java

示例7: parseCompiledR

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
  for (Element element : rClass.getEnclosedElements()) {
    String innerClassName = element.getSimpleName().toString();
    if (SUPPORTED_TYPES.contains(innerClassName)) {
      for (Element enclosedElement : element.getEnclosedElements()) {
        if (enclosedElement instanceof VariableElement) {
          VariableElement variableElement = (VariableElement) enclosedElement;
          Object value = variableElement.getConstantValue();

          if (value instanceof Integer) {
            int id = (Integer) value;
            ClassName rClassName =
                ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R",
                    innerClassName);
            String resourceName = variableElement.getSimpleName().toString();
            QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
            symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
          }
        }
      }
    }
  }
}
 
开发者ID:qq542391099,项目名称:butterknife-parent,代码行数:24,代码来源:ButterKnifeProcessor.java

示例8: builderCopyMethodForList

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
private MethodSpec builderCopyMethodForList() {
    TypeName keyType = typeProvider.getTypeNameForSimpleType(memberModel.getMapModel().getKeyModel()
                                                                        .getVariable().getVariableType());
    ClassName valueParameter = poetExtensions.getModelClass(memberModel.getMapModel().getValueModel().getC2jShape());
    ClassName builderForParameter = valueParameter.nestedClass("Builder");
    TypeName parameterType =
        ParameterizedTypeName.get(ClassName.get(Map.class), keyType, WildcardTypeName.subtypeOf(builderForParameter));

    CodeBlock code =
        CodeBlock.builder()
                 .beginControlFlow("if ($N == null)", memberParamName())
                 .addStatement("return null")
                 .endControlFlow()
                 .addStatement("return $N($N.entrySet().stream().collect(toMap($T::getKey, e -> e.getValue().build())))",
                               serviceModelCopiers.copyMethodName(),
                               memberParamName(),
                               Map.Entry.class)
                 .build();

    return MethodSpec.methodBuilder(serviceModelCopiers.builderCopyMethodName())
                     .addModifiers(Modifier.STATIC)
                     .addParameter(parameterType, memberParamName())
                     .returns(typeProvider.fieldType(memberModel))
                     .addCode(code)
                     .build();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:27,代码来源:MemberCopierSpec.java

示例9: generateListType

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
@Nonnull
private TypeName generateListType(@Nonnull String className, @Nonnull JsonValue value, @Nonnull ClassBuilder builder) {
    if (value.isArray()) {
        final JsonValue firstValue = value.asArray()
                .stream()
                .findFirst()
                .orElse(new JsonNull());
        final TypeName type = generateListType(className, firstValue, builder);
        return ParameterizedTypeName.get(ClassName.get(List.class), type);
    }

    if (value.isObject()) {
        final TypeSpec innerClass = fromObject(className, value.asObject(), Modifier.PUBLIC, Modifier.STATIC);
        builder.addInnerType(innerClass);

        final TypeName innerClassType = ClassName.bestGuess(innerClass.name);
        return ParameterizedTypeName.get(ClassName.get(List.class), innerClassType);
    }

    return ParameterizedTypeName.get(ClassName.get(List.class), value.getType().box());
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:22,代码来源:JavaConverter.java

示例10: 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

示例11: createFoldVoidSignature

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
private MethodSpec.Builder createFoldVoidSignature(
    Iterable<TypeVariableName> availableTypeVariables) throws ParserException {
  MethodSpec.Builder builder =
      MethodSpec.methodBuilder("match").addModifiers(Modifier.PUBLIC).returns(void.class);

  for (OutputValue arg : values) {
    TypeName visitor =
        ParameterizedTypeName.get(
            ClassName.get(Consumer.class),
            withoutMissingTypeVariables(arg.parameterizedOutputClass(), availableTypeVariables));

    builder.addParameter(
        ParameterSpec.builder(visitor, asCamelCase(arg.name()))
            .addAnnotation(Nonnull.class)
            .build());
  }

  return builder;
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:20,代码来源:MatchMethods.java

示例12: writeBinding

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
private void writeBinding(String targetClassName, Set<Element> annotationFields)
    throws IOException {
  String packageName = null;
  int lastDot = targetClassName.lastIndexOf('.');
  if (lastDot > 0) {
    packageName = targetClassName.substring(0, lastDot);
  }

  String targetSimpleClassName = targetClassName.substring(lastDot + 1);
  String bindingClassName = targetClassName + "_PrefBinding";
  String bindingSimpleClassName = bindingClassName.substring(lastDot + 1);

  ClassName targetClass = ClassName.get(packageName, targetSimpleClassName);

  TypeSpec binding = TypeSpec.classBuilder(bindingSimpleClassName)
      .addModifiers(Modifier.PUBLIC)
      .addMethod(buildConstructor(targetClass, annotationFields))
      .build();

  JavaFile javaFile = JavaFile.builder(packageName, binding).build();

  javaFile.writeTo(processingEnv.getFiler());
}
 
开发者ID:quangctkm9207,项目名称:prefpin,代码行数:24,代码来源:PrefPinProcessor.java

示例13: generateAdditionalRequestManagerMethodNew

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
private MethodSpec generateAdditionalRequestManagerMethodNew(
    ExecutableElement extensionMethod) {
   String returnType = processorUtil.findClassValuesFromAnnotationOnClassAsNames(extensionMethod,
      GlideType.class).iterator().next();
  ClassName returnTypeClassName = ClassName.bestGuess(returnType);
  ParameterizedTypeName parameterizedTypeName =
      ParameterizedTypeName.get(generatedRequestBuilderClassName, returnTypeClassName);

  return MethodSpec.methodBuilder(extensionMethod.getSimpleName().toString())
      .addModifiers(Modifier.PUBLIC)
      .returns(parameterizedTypeName)
      .addJavadoc(processorUtil.generateSeeMethodJavadoc(extensionMethod))
      .addStatement(
          "return ($T) $T.$N(this.as($T.class))",
          parameterizedTypeName,
          extensionMethod.getEnclosingElement(),
          extensionMethod.getSimpleName(),
          returnTypeClassName)
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:RequestManagerGenerator.java

示例14: overrideGlideWithMethod

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
private MethodSpec overrideGlideWithMethod(
    String packageName, TypeSpec generatedRequestManager, ExecutableElement methodToOverride) {
  ClassName generatedRequestManagerClassName =
      ClassName.get(packageName, generatedRequestManager.name);
  List<? extends VariableElement> parameters = methodToOverride.getParameters();
  Preconditions.checkArgument(
      parameters.size() == 1, "Expected size of 1, but got %s", methodToOverride);
  VariableElement parameter = parameters.iterator().next();
  return MethodSpec.methodBuilder(methodToOverride.getSimpleName().toString())
      .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
      .addJavadoc(processorUtil.generateSeeMethodJavadoc(methodToOverride))
      .returns(generatedRequestManagerClassName)
      .addParameter(ClassName.get(parameter.asType()), parameter.getSimpleName().toString())
      .addStatement("return ($T) $T.$N($L)",
          generatedRequestManagerClassName, glideType,
          methodToOverride.getSimpleName().toString(),
          parameter.getSimpleName())
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:GlideGenerator.java

示例15: getSuperMethodSpecs

import com.squareup.javapoet.ClassName; //导入依赖的package包/类
private List<MethodSpec> getSuperMethodSpecs() {
    List<MethodSpec> methodSpecs = new ArrayList<>();
    this.annotatedClazz.annotatedElement.getEnclosedElements().stream()
            .filter(element -> element instanceof ExecutableElement)
            .map(element -> (ExecutableElement) element)
            .forEach(method -> {
                ClassName preferenceRoom = ClassName.get(PreferenceRoom.class);
                MethodSpec.Builder builder = MethodSpec.overriding(method);
                MethodSpec methodSpec = builder.addStatement("$T.inject($N)", preferenceRoom, method.getParameters().get(0).getSimpleName()).build();
                if(methodSpec.returnType != TypeName.get(Void.TYPE)) {
                    throw new VerifyException(String.format("Returned '%s'. only return type can be void.", methodSpec.returnType.toString()));
                }
                methodSpecs.add(methodSpec);
            });
    return methodSpecs;
}
 
开发者ID:skydoves,项目名称:PreferenceRoom,代码行数:17,代码来源:PreferenceComponentGenerator.java


注:本文中的com.squareup.javapoet.ClassName类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。