當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。