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


Java TypeVariableName.get方法代碼示例

本文整理匯總了Java中com.squareup.javapoet.TypeVariableName.get方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeVariableName.get方法的具體用法?Java TypeVariableName.get怎麽用?Java TypeVariableName.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.javapoet.TypeVariableName的用法示例。


在下文中一共展示了TypeVariableName.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: replaceReturnType

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
@Override
public TypeName replaceReturnType(String currentPkg, String directParentInterface, String curClassname,
                                  List<? extends TypeMirror> superInterfaces, TypeName superClass, ExecutableElement method) {
    final TypeMirror returnType = method.getReturnType();
    switch (method.getSimpleName().toString()){
        case TypeCopyableFiller.NAME_COPY: {
            switch (returnType.getKind()) {
                case TYPEVAR: //泛型
                    return  TypeVariableName.get(directParentInterface);

                default:
                    return TypeName.get(returnType);
            }
        }

        default:
            return TypeName.get(returnType);

    }

}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:22,代碼來源:CopyReplacer.java

示例2: generateAsMethod

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的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

示例3: generateAsMethod

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的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

示例4: createJsArrayInterface

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
private TypeSpec createJsArrayInterface() {
    TypeVariableName variableName = TypeVariableName.get("T");
    return TypeSpec.classBuilder("JsArray")
            .addModifiers(Modifier.STATIC, Modifier.FINAL)
            .addTypeVariable(variableName)
            .addAnnotation(AnnotationSpec.builder(ClassNames.JSINTEROP_JSTYPE)
                    .addMember("isNative", "true")
                    .addMember("namespace", "$T.GLOBAL", ClassNames.JSINTEROP_JSPACKAGE)
                    .addMember("name", "$S", "Array")
                    .build())
            .addMethod(MethodSpec.methodBuilder("push")
                    .addModifiers(Modifier.PUBLIC, Modifier.NATIVE)
                    .addParameter(variableName, "item")
                    .build())
            .build();
}
 
開發者ID:codegen-io,項目名稱:jso-builder,代碼行數:17,代碼來源:JSOBuilderProcessor.java

示例5: getFeatureParameterTypeVariableName

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
private TypeName getFeatureParameterTypeVariableName(DeclaredType featureType,
                                                     int featureParameterIndex) {
    Element paramElem = getFeatureParameterElement(featureType, featureParameterIndex);
    if (paramElem == null) {
        return null;
    }

    if (paramElem.getKind() == ElementKind.TYPE_PARAMETER) {
        return TypeVariableName.get((TypeVariable) paramElem.asType());

    } else if (paramElem.getKind() == ElementKind.CLASS) {
        return TypeName.get(paramElem.asType());
    }

    return null;
}
 
開發者ID:beworker,項目名稱:featured,代碼行數:17,代碼來源:Names.java

示例6: generateGetUpdaterMethod

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
private MethodSpec generateGetUpdaterMethod(FieldSpec mapField) {
    TypeVariableName typeVariableName = TypeVariableName.get("T");
    ParameterizedTypeName returnType = ParameterizedTypeName.get(ClassName.get(Updater.class), typeVariableName);
    ParameterSpec parameterSpec = ParameterSpec.builder(
            ParameterizedTypeName.get(ClassName.get(Class.class), typeVariableName),
            "tClass"
    ).build();

    final String returnVariableName = "updater";
    return MethodSpec.methodBuilder("getUpdater")
            .addAnnotation(AnnotationSpec.builder(SuppressWarnings.class)
                    .addMember("value", "$S", "unchecked")
                    .build())
            .addModifiers(Modifier.PUBLIC)
            .addTypeVariable(typeVariableName)
            .addParameter(parameterSpec)
            .returns(returnType)
            .addStatement("$T $N = ($T)$N.get($N)", returnType, returnVariableName, returnType, mapField, parameterSpec)
            .beginControlFlow("if ($N == null)", returnVariableName)
            .addStatement("throw new $T(\"Updater for $N not found\")", RuntimeException.class, parameterSpec)
            .endControlFlow()
            .addStatement("return updater")
            .build();
}
 
開發者ID:campusappcn,項目名稱:pojo-updater-compiler,代碼行數:25,代碼來源:ManagerGenerator.java

示例7: from

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
public static ColumnClassWriter from(@NonNull TransformerElement transformerElement,
                                     @NonNull Environment environment,
                                     boolean createUniqueClass) {
  final TypeName deserializedTypeName = transformerElement.getDeserializedTypeNameForGenerics();
  final ClassName superClassName = transformerElement.isNumericType() ? NUMERIC_COLUMN : COLUMN;
  final TypeVariableName parentTableType = TypeVariableName.get("T");
  final TypeVariableName nullabilityType = TypeVariableName.get("N");
  final ExtendedTypeElement serializedType = transformerElement.getSerializedType();
  final String className = createUniqueClass ? getUniqueClassName(transformerElement) : getClassName(transformerElement);

  return ColumnClassWriter.builder()
      .environment(environment)
      .className(className)
      .deserializedTypeName(deserializedTypeName)
      .serializedType(serializedType)
      .superClass(ParameterizedTypeName.get(superClassName,
          deserializedTypeName, deserializedTypeName, deserializedTypeName,
          parentTableType, nullabilityType))
      .parentTableType(parentTableType)
      .nullabilityType(nullabilityType)
      .valueGetter(transformerElement.serializedValueGetter(VAL_VARIABLE))
      .transformerElement(transformerElement)
      .nullable(!serializedType.isPrimitiveElement())
      .unique(createUniqueClass)
      .build();
}
 
開發者ID:SiimKinks,項目名稱:sqlitemagic,代碼行數:27,代碼來源:ColumnClassWriter.java

示例8: addOperationByColumnToOperationBuilder

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
public static void addOperationByColumnToOperationBuilder(TypeSpec.Builder builder,
                                                          TypeName interfaceName) {
  final TypeVariableName inputColumnType = TypeVariableName.get("C", ParameterizedTypeName.get(UNIQUE, NOT_NULLABLE_COLUMN));

  builder
      .addField(FieldSpec
          .builder(OPERATION_BY_COLUMNS, OPERATION_BY_COLUMNS_VARIABLE, PRIVATE, FINAL)
          .addAnnotation(NON_NULL)
          .initializer("new $T<>(2)", ARRAY_LIST)
          .build())
      .addMethod(MethodSpec
          .methodBuilder(METHOD_BY_COLUMN)
          .addModifiers(Modifier.PUBLIC)
          .addAnnotation(Override.class)
          .addAnnotation(NON_NULL)
          .addAnnotation(CHECK_RESULT)
          .addTypeVariable(inputColumnType)
          .addParameter(ParameterSpec.builder(inputColumnType, "column").build())
          .returns(interfaceName)
          .addStatement("this.$L.add(($T) column)",
              OPERATION_BY_COLUMNS_VARIABLE, COLUMN)
          .addStatement("return this")
          .build());
}
 
開發者ID:SiimKinks,項目名稱:sqlitemagic,代碼行數:25,代碼來源:WriterUtil.java

示例9: RequestBuilderGenerator

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
RequestBuilderGenerator(ProcessingEnvironment processingEnv, ProcessorUtil processorUtil) {
  this.processingEnv = processingEnv;
  this.processorUtil = processorUtil;

  requestBuilderType = processingEnv.getElementUtils()
      .getTypeElement(REQUEST_BUILDER_QUALIFIED_NAME);

  transcodeTypeName = TypeVariableName.get(TRANSCODE_TYPE_NAME);

  requestOptionsType = processingEnv.getElementUtils().getTypeElement(
      REQUEST_OPTIONS_QUALIFIED_NAME);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:RequestBuilderGenerator.java

示例10: generateClass

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
@Override public String generateClass(Context context, String className, String classToExtend,
    boolean isFinal) {
  List<JsonProperty> properties = JsonProperty.from(context);
  validateProperties(context.processingEnvironment(), properties);

  Map<String, TypeName> types = convertPropertiesToTypes(context.properties());
  NameAllocator nameAllocator = new NameAllocator();
  Map<TypeMirror, FieldSpec> typeAdapters = getTypeAdapters(properties, nameAllocator);

  TypeName superClass = TypeVariableName.get(classToExtend);
  TypeSpec.Builder subclass = TypeSpec.classBuilder(className)
      .superclass(superClass)
      .addMethod(generateConstructor(types));

  if (generateReadMethod(context)) {
    subclass.addMethod(
        generateFromJson(context, properties, typeAdapters, nameAllocator.clone()));
  }

  Optional<ExecutableElement> writeMethod = getJsonWriteMethod(context);
  if (writeMethod.isPresent()) {
    subclass.addMethod(generateWriteToJson(context, writeMethod.get(), properties, typeAdapters,
        nameAllocator.clone()));
  }

  if (!typeAdapters.isEmpty()) {
    for (FieldSpec field : typeAdapters.values()) {
      subclass.addField(field);
    }
  }

  if (isFinal) {
    subclass.addModifiers(FINAL);
  } else {
    subclass.addModifiers(ABSTRACT);
  }

  return JavaFile.builder(context.packageName(), subclass.build()).build().toString();
}
 
開發者ID:setheclark,項目名稱:auto-value-json,代碼行數:40,代碼來源:AutoValueJsonExtension.java

示例11: getConsumerTypeWithContext

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
public TypeName getConsumerTypeWithContext() throws IOException {
  int count = getParameters().size() + 1;
  TypeName[] types = new TypeName[count];
  types[0] = TypeVariableName.get("A");
  for (int i = 1; i < count; i++) {
    types[i] = TypeName.get(getParameters().get(i - 1).getObjectType());
  }
  return ParameterizedTypeName
      .get(ConsumerHelper.get(count), types);
}
 
開發者ID:douo,項目名稱:ActivityBuilder,代碼行數:11,代碼來源:ResultModel.java

示例12: generateHandler

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
SenderGenerator generateHandler() {

        MethodSpec.Builder handlerBuilder = MethodSpec.methodBuilder("handle");

        TypeVariableName Tvariable = TypeVariableName.get("T");

        handlerBuilder.addModifiers(Modifier.PRIVATE)
                .addTypeVariable(Tvariable)
                .addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "unchecked").build());

        ParameterSpec futureParameter = ParameterSpec.builder(ParameterizedTypeName.get(ClassName.get(io.vertx.core.Future.class), Tvariable), "future").build();
        ParameterSpec asyncResultParameter = ParameterSpec.builder(
                ParameterizedTypeName.get(ClassName.get(io.vertx.core.AsyncResult.class),
                        ParameterizedTypeName.get(ClassName.get(io.vertx.core.eventbus.Message.class), TypeName.get(Object.class))),
                "asyncResult").build();

        handlerBuilder.addParameter(futureParameter)
                .addParameter(asyncResultParameter)
                .beginControlFlow("if ($N.succeeded())", asyncResultParameter)
                .addStatement("$T reply = ($T) $N.result().body()", RIFAMessage.class, RIFAMessage.class, asyncResultParameter)
                .addStatement("$N.complete(($T) reply.get(0))", futureParameter, Tvariable)
                .nextControlFlow("else")
                .addStatement("$N.fail($N.cause().getMessage())", futureParameter, asyncResultParameter)
                .endControlFlow()
                .returns(TypeName.VOID);

        classBuilder.addMethod(handlerBuilder.build());

        return this;

    }
 
開發者ID:nsforth,項目名稱:vxrifa,代碼行數:32,代碼來源:SenderGenerator.java

示例13: emitGetterMethods

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
private void emitGetterMethods(TypeSpec.Builder registryTypeSpec) {
  TypeVariableName t = TypeVariableName.get("T");
  MethodSpec.Builder getMethod = MethodSpec.methodBuilder(registryInjectionTarget.getterName)
      .addTypeVariable(t)
      .addAnnotation(Override.class)
      .addModifiers(Modifier.PUBLIC)
      .addParameter(ParameterizedTypeName.get(ClassName.get(Class.class), t), "clazz")
      .returns(ParameterizedTypeName.get(ClassName.get(registryInjectionTarget.type), t));

  getMethod.addStatement("String className = clazz.getName()");
  int numOfBuckets = getNumberOfBuckets(registryInjectionTarget.injectionTargetList);
  getMethod.addStatement("int bucket = (className.hashCode() & $L)", numOfBuckets - 1);
  CodeBlock.Builder switchBlockBuilder = CodeBlock.builder().beginControlFlow("switch(bucket)");

  List<MethodSpec> getterMethodForBucketList = new ArrayList<>(numOfBuckets);
  Map<Integer, List<TypeElement>> getterMethodBuckets = getGetterMethodBuckets(registryInjectionTarget.injectionTargetList);
  for (int i = 0; i < numOfBuckets; i++) {
    List<TypeElement> methodBucket = getterMethodBuckets.get(i);
    if (methodBucket == null) {
      methodBucket = Collections.emptyList();
    }
    MethodSpec getterMethodForBucket = generateGetterMethod(methodBucket, i);
    getterMethodForBucketList.add(getterMethodForBucket);
    switchBlockBuilder.add("case ($L):" + LINE_SEPARATOR, i);
    switchBlockBuilder.addStatement("return $L(clazz, className)", getterMethodForBucket.name);
  }

  switchBlockBuilder.add("default:" + LINE_SEPARATOR);
  switchBlockBuilder.addStatement("return $L(clazz)", registryInjectionTarget.childrenGetterName);
  switchBlockBuilder.endControlFlow();
  getMethod.addCode(switchBlockBuilder.build());
  registryTypeSpec.addMethod(getMethod.build());
  registryTypeSpec.addMethods(getterMethodForBucketList);
}
 
開發者ID:stephanenicolas,項目名稱:toothpick,代碼行數:35,代碼來源:RegistryGenerator.java

示例14: testExtractTypeVars

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
@Test
public void testExtractTypeVars() {
  TypeVariableName a = TypeVariableName.get("A");
  TypeVariableName b = TypeVariableName.get("B");
  TypeVariableName c = TypeVariableName.get("C");
  TypeVariableName d = TypeVariableName.get("D");
  ParameterizedTypeName ab = ParameterizedTypeName.get(ClassName.get(HashMap.class), a, b);
  ParameterizedTypeName abc = ParameterizedTypeName.get(ClassName.get(HashMap.class), ab, c);
  ParameterizedTypeName dabc = ParameterizedTypeName.get(ClassName.get(HashMap.class), d, abc);
  ParameterizedTypeName dabca = ParameterizedTypeName.get(ClassName.get(HashMap.class), dabc, a);
  ParameterizedTypeName dabcab = ParameterizedTypeName.get(ClassName.get(HashMap.class), dabca, b);
  ParameterizedTypeName ddabcab = ParameterizedTypeName.get(ClassName.get(HashMap.class), d, dabcab);
  List<TypeVariableName> vars = extractTypeVars(ddabcab);
  assertThat(new HashSet<>(vars), is(new HashSet<>(asList(a, b, c, d))));
}
 
開發者ID:h908714124,項目名稱:zerobuilder,代碼行數:16,代碼來源:ZeroUtilTest.java

示例15: getTypeVariables

import com.squareup.javapoet.TypeVariableName; //導入方法依賴的package包/類
private static TypeVariableName[] getTypeVariables(TypeElement autoValueClass) {
    List<? extends TypeParameterElement> parameters = autoValueClass.getTypeParameters();
    TypeVariableName[] typeVariables = new TypeVariableName[parameters.size()];
    for (int i = 0, length = typeVariables.length; i < length; i++) {
        typeVariables[i] = TypeVariableName.get(parameters.get(i));
    }
    return typeVariables;
}
 
開發者ID:gabrielittner,項目名稱:auto-value-extension-util,代碼行數:9,代碼來源:AutoValueUtil.java


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