本文整理汇总了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);
}
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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());
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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))));
}
示例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;
}