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


Java TypeSpec类代码示例

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


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

示例1: addType

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
void addType(String name, String forName, ClassName serviceType, ClassName builderType, String param) {
    MethodSpec.Builder smartMethod = MethodSpec.methodBuilder("to" + Util.capFirstLetter(name)+ AnnotationConstants.SUFFIX_SERVICE_TARGET)
            .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
            .returns(builderType)
            .addStatement("return new $T()", builderType);
    smartTargets.addMethod(smartMethod.build());
    TypeSpec.Builder type = TypeSpec.classBuilder(builderType)
            .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
            .superclass(ParameterizedTypeName.get(ClazzNames.SERVICE_TARGET, (TypeName)builderType));
    MethodSpec.Builder clazz = MethodSpec.methodBuilder("getServiceClass")
            .addModifiers(Modifier.PROTECTED)
            .returns(ParameterizedTypeName.get(ClazzNames.CLAZZ, serviceType))
            .addStatement("return $T.class", serviceType);
    type.addMethod(clazz.build());
    types.put(forName, type);
}
 
开发者ID:foreveruseful,项目名称:smartkey,代码行数:17,代码来源:ServiceHandler.java

示例2: addType

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
public void addType(TargetDescriptor des) {
    TypeSpec.Builder type = types.get(des.name);
    if (type == null) {
        ClassName activityType = ClassName.bestGuess(des.name);
        ClassName builderName = ClassName.bestGuess(des.name + AnnotationConstants.SUFFIX_ACTIVITY_TARGET);
        addType(des.getSimpleName(), des.name, activityType, builderName, null);
    }
    if (des.filters.isEmpty() || des.filters.get(0).actions.isEmpty()) {
        return;
    }
    for (TargetFilter filter : des.filters) {
        for(String action : filter.actions) {
            if("android.intent.action.MAIN".equals(action))
                continue;
            addGoActivityMethod(des.name,
                    "goWithAction_" + action.replace('.', '_').replace(" ", "").toUpperCase(),
                    action, filter.categories);
            addGoActivityMethod(des.name,
                    "goForResultWithAction_" + action.replace('.', '_').replace(" ", "").toUpperCase(),
                    action, filter.categories);
        }
    }
}
 
开发者ID:foreveruseful,项目名称:smartkey,代码行数:24,代码来源:ActivityHandler.java

示例3: addGoActivityMethod

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
void addGoActivityMethod(String targetClz, String methodName, String action, ArrayList<String> cats) {
    TypeSpec.Builder type = types.get(targetClz);
    MethodSpec.Builder actionMethod = MethodSpec.methodBuilder(methodName)
            .addModifiers(Modifier.PUBLIC)
            .addStatement("$T in = prepare(src)", ClazzNames.INTENT)
            .addStatement("in.setAction(\"" + action + "\")");
    for (String cat : cats) {
        actionMethod.addStatement("in.addCategory(\"" + cat + "\")");
    }
    if(methodName.contains("ForResult")) {
        actionMethod.addParameter(ClazzNames.ACTIVITY, "src")
                .addParameter(ClassName.INT, "reqCode");
        actionMethod.addStatement("realGoForResult(src, in, reqCode)");
    } else {
        actionMethod.addParameter(ClazzNames.CONTEXT, "src");
        actionMethod.addStatement("realGo(src, in)");
    }
    type.addMethod(actionMethod.build());
}
 
开发者ID:foreveruseful,项目名称:smartkey,代码行数:20,代码来源:ActivityHandler.java

示例4: overrideGlideWithMethod

import com.squareup.javapoet.TypeSpec; //导入依赖的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

示例5: poetSpec

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
@Override
public TypeSpec poetSpec() {
    ClassName interfaceClass = poetExtensions.getClientClass(model.getMetadata().getAsyncInterface());
    Builder classBuilder = PoetUtils.createClassBuilder(className)
                                    .addAnnotation(SdkInternalApi.class)
                                    .addModifiers(Modifier.FINAL)
                                    .addField(AsyncClientHandler.class, "clientHandler", Modifier.PRIVATE, Modifier.FINAL)
                                    .addField(protocolSpec.protocolFactory(model))
                                    .addSuperinterface(interfaceClass)
                                    .addJavadoc("Internal implementation of {@link $1T}.\n\[email protected] $1T#builder()",
                                                interfaceClass)
                                    .addMethods(operations())
                                    .addMethod(closeMethod())
                                    .addMethods(protocolSpec.additionalMethods())
                                    .addMethod(protocolSpec.initProtocolFactory(model));

    if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
        classBuilder.addMethod(constructorWithAdvancedConfiguration());
    } else {
        classBuilder.addMethod(constructor());
    }

    protocolSpec.createErrorResponseHandler().ifPresent(classBuilder::addMethod);

    return classBuilder.build();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:27,代码来源:AsyncClientClass.java

示例6: generate

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
TypeSpec generate(String generatedCodePackageName, TypeSpec generatedRequestManagerSpec) {
  return TypeSpec.classBuilder(GENERATED_REQUEST_MANAGER_FACTORY_SIMPLE_NAME)
      .addModifiers(Modifier.FINAL)
      .addSuperinterface(ClassName.get(requestManagerFactoryInterface))
      .addJavadoc("Generated code, do not modify\n")
      .addMethod(
          MethodSpec.methodBuilder("build")
              .addModifiers(Modifier.PUBLIC)
              .addAnnotation(Override.class)
              .returns(requestManagerClassName)
              .addParameter(ClassName.get(glideType), "glide")
              .addParameter(ClassName.get(lifecycleType), "lifecycle")
              .addParameter(ClassName.get(requestManagerTreeNodeType), "treeNode")
              .addStatement(
                  "return new $T(glide, lifecycle, treeNode)",
                  ClassName.get(generatedCodePackageName, generatedRequestManagerSpec.name))
              .build()
      )
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:RequestManagerFactoryGenerator.java

示例7: generateAsMethod

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
private MethodSpec generateAsMethod(String generatedCodePackageName, TypeSpec requestBuilder) {
  TypeVariableName resourceType = TypeVariableName.get("ResourceType");
  ParameterizedTypeName classOfResouceType = ParameterizedTypeName
      .get(ClassName.get(Class.class), resourceType);

  ClassName generatedRequestBuilderClassName =
      ClassName.get(generatedCodePackageName, requestBuilder.name);

  ParameterizedTypeName requestBuilderOfResourceType = ParameterizedTypeName
      .get(generatedRequestBuilderClassName, resourceType);

  return MethodSpec.methodBuilder("as")
      .addModifiers(Modifier.PUBLIC)
      .addAnnotation(Override.class)
      .addTypeVariable(TypeVariableName.get("ResourceType"))
      .addParameter(classOfResouceType, "resourceClass")
      .returns(requestBuilderOfResourceType)
      .addStatement("return new $T<>(glide, this, resourceClass)",
          this.generatedRequestBuilderClassName)
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:RequestManagerGenerator.java

示例8: generate

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
TypeSpec generate(List<TypeElement> types) {
  List<TypeElement> modules =  new ArrayList<>();
  List<TypeElement> extensions = new ArrayList<>();
  for (TypeElement element : types) {
    if (processorUtil.isExtension(element)) {
      extensions.add(element);
    } else if (processorUtil.isLibraryGlideModule(element)) {
      modules.add(element);
    } else {
      throw new IllegalArgumentException("Unrecognized type: " + element);
    }
  }
  if (!modules.isEmpty() && !extensions.isEmpty()) {
    throw new IllegalArgumentException("Given both modules and extensions, expected one or the "
        + "other. Modules: " + modules + " Extensions: " + extensions);
  }
  if (!modules.isEmpty()) {
    return generate(types, GlideModule.class);
  } else {
    return generate(types, GlideExtension.class);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:IndexerGenerator.java

示例9: generate

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
@Override
public void generate(UserMarkerAnnotation marker, ProcessorOutputCollection into) {
    TypeName providerTypeName = marker.getServiceInterfaceTypeName();
    TypeSpec.Builder typeBuilder = TypeSpec.interfaceBuilder(marker.getServiceInterfaceProviderName())
            .addModifiers(Modifier.PUBLIC)
            .addMethod(
                    Util.publicAbstractMethod(GET_NAME_METHOD_NAME, STRING_TYPE_NAME)
                            .build())
            .addMethod(
                    Util.publicAbstractMethod(CREATE_NEW_METHOD_NAME, providerTypeName)
                            .build())
            .addMethod(
                    Util.publicAbstractMethod(CREATE_NEW_WITH_CONFIG_METHOD_NAME, providerTypeName)
                            .addParameter(CONFIG_TYPE_NAME, CONFIG_ARG_NAME)
                            .build());

    for (EasyPluginPlugin plugin : Util.getPluginLoader()) {
        plugin.updatePluginProviderInterface(typeBuilder, marker);
    }

    TypeSpec type = typeBuilder.build();

    into.putType(marker.getOutputPackage(elements), type);
}
 
开发者ID:c0d3d,项目名称:easy-plugins,代码行数:25,代码来源:PluginProviderInterfaceFileGenerator.java

示例10: generate

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
public TypeSpec generate() {
    return TypeSpec.classBuilder(getClassName())
            .addJavadoc("Generated by Kickback. (https://github.com/skydoves/Kickback).\n")
            .addModifiers(Modifier.PUBLIC)
            .addSuperinterface(LifecycleObserver.class)
            .addFields(getKickbackFields())
            .addMethods(getSetterMethodSpecs())
            .addMethods(getGetterMethodSpecs())
            .addMethods(getFreeMethodSpecs())
            .addMethod(getBoxNameSpec())
            .addMethods(getElementNameListSpecs())
            .addMethod(getFreeAllSpec())
            .addMethod(setLifecycleObserverSpec())
            .addMethod(getLifecycleObserverSpec())
            .build();
}
 
开发者ID:skydoves,项目名称:Kickback,代码行数:17,代码来源:KickbackBoxGenerator.java

示例11: generate

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
void generate() {
    TypeSpec shortbread = TypeSpec.classBuilder("ShortbreadGenerated")
            .addAnnotation(AnnotationSpec.builder(suppressLint)
                    .addMember("value", "$S", "NewApi")
                    .addMember("value", "$S", "ResourceType")
                    .build())
            .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
            .addMethod(createShortcuts())
            .addMethod(callMethodShortcut())
            .build();

    JavaFile javaFile = JavaFile.builder("shortbread", shortbread)
            .indent("    ")
            .build();

    try {
        javaFile.writeTo(filer);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:22,代码来源:CodeGenerator.java

示例12: generateAsMethod

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
private MethodSpec generateAsMethod(String generatedCodePackageName, TypeSpec requestBuilder) {
  TypeVariableName resourceType = TypeVariableName.get("ResourceType");
  ParameterizedTypeName classOfResouceType = ParameterizedTypeName
      .get(ClassName.get(Class.class), resourceType);

  ClassName generatedRequestBuilderClassName =
      ClassName.get(generatedCodePackageName, requestBuilder.name);

  ParameterizedTypeName requestBuilderOfResourceType = ParameterizedTypeName
      .get(generatedRequestBuilderClassName, resourceType);

  return MethodSpec.methodBuilder("as")
      .addModifiers(Modifier.PUBLIC)
      .addAnnotation(Override.class)
      .addTypeVariable(TypeVariableName.get("ResourceType"))
      .addParameter(classOfResouceType, "resourceClass")
      .addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build())
      .returns(requestBuilderOfResourceType)
      .addStatement("return new $T<>(glide, this, resourceClass, context)",
          this.generatedRequestBuilderClassName)
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RequestManagerGenerator.java

示例13: poetSpec

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
@Override
public TypeSpec poetSpec() {
    TypeSpec.Builder builder = TypeSpec.classBuilder(className())
            .addAnnotation(PoetUtils.GENERATED)
            .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
            .superclass(ClassName.get(AwsRequest.class))
            .addMethod(MethodSpec.constructorBuilder()
                    .addModifiers(Modifier.PROTECTED)
                    .addParameter(className().nestedClass("Builder"), "builder")
                    .addStatement("super(builder)")
                    .build())
            .addMethod(MethodSpec.methodBuilder("toBuilder")
                    .addAnnotation(Override.class)
                    .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
                    .returns(className().nestedClass("Builder"))
                    .build())
            .addType(builderInterfaceSpec())
            .addType(builderImplSpec());
    return builder.build();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:21,代码来源:AwsServiceBaseRequestSpec.java

示例14: generateEndpointsResponsesInnerClass

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
private static TypeSpec generateEndpointsResponsesInnerClass(String endpoint,
    List<BarricadeResponse> responses) {
  TypeSpec.Builder classBuilder =
      classBuilder(StringUtils.toCamelCase(endpoint)).addModifiers(PUBLIC, STATIC, FINAL);
  int count = 0;
  for (BarricadeResponse response : responses) {
    FieldSpec valuesField = FieldSpec.builder(int.class,
        StringUtils.removeAllSpecialCharactersAndExtensions(response.responseFileName).toUpperCase())
        .addModifiers(PUBLIC, STATIC, FINAL)
        .initializer("$L", count)
        .build();
    classBuilder.addField(valuesField);
    count++;
  }
  return classBuilder.build();
}
 
开发者ID:mutualmobile,项目名称:Barricade,代码行数:17,代码来源:CodeGenerator.java

示例15: constructActivityModule

import com.squareup.javapoet.TypeSpec; //导入依赖的package包/类
private void constructActivityModule() {
    final TypeSpec.Builder builder = TypeSpec.classBuilder(Constants.ACTIVITY_MODULE)
            .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
            .addAnnotation(Constants.DAGGER_MODULE);

    for (ActivityHolder activityHolder : activityHolders.values()) {
        builder.addMethod(MethodSpec.methodBuilder(Constants.METHOD_CONTRIBUTE + activityHolder.className)
                .addAnnotation(Constants.DAGGER_ANDROID_ANNOTATION)
                .addModifiers(Modifier.ABSTRACT)
                .returns(activityHolder.classNameComplete)
                .build()
        );
    }

    final TypeSpec newClass = builder.build();
    final JavaFile javaFile = JavaFile.builder(Constants.PACKAGE_NAME, newClass).build();

    try {
        javaFile.writeTo(System.out);
        javaFile.writeTo(filer);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:florent37,项目名称:DaggerAutoInject,代码行数:25,代码来源:DaggerAutoInjectProcessor.java


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