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