本文整理汇总了Java中com.squareup.javapoet.ParameterizedTypeName.get方法的典型用法代码示例。如果您正苦于以下问题:Java ParameterizedTypeName.get方法的具体用法?Java ParameterizedTypeName.get怎么用?Java ParameterizedTypeName.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javapoet.ParameterizedTypeName
的用法示例。
在下文中一共展示了ParameterizedTypeName.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildResultWrapperMethod
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
@Nonnull
private MethodSpec buildResultWrapperMethod()
{
final ParameterizedTypeName listType =
ParameterizedTypeName.get( ClassName.get( List.class ), TypeName.get( getElement().asType() ) );
return MethodSpec.methodBuilder( "wrap" ).
addModifiers( Modifier.PROTECTED, Modifier.FINAL ).
addJavadoc( "If config option enabled, wrap the specified list in an immutable list and return it.\n" +
"This method should be called by repository extensions when returning list results " +
"when not using {@link #toList(List)}.\n" ).
addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).
addParameter( ParameterSpec.builder( listType, "list", Modifier.FINAL ).
addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).build() ).
returns( listType ).
addStatement( "return $T.areRepositoryResultsModifiable() ? $T.unmodifiableList( list ) : list",
GeneratorUtil.AREZ_CLASSNAME,
Collections.class ).
build();
}
示例2: generateConstructors
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
private List<MethodSpec> generateConstructors() {
ParameterizedTypeName classOfTranscodeType =
ParameterizedTypeName.get(ClassName.get(Class.class), transcodeTypeName);
TypeName wildcardOfObject = WildcardTypeName.subtypeOf(Object.class);
ParameterizedTypeName requestBuilderOfWildcardOfObject =
ParameterizedTypeName.get(ClassName.get(requestBuilderType), wildcardOfObject);
MethodSpec firstConstructor =
MethodSpec.constructorBuilder()
.addParameter(classOfTranscodeType, "transcodeClass")
.addParameter(requestBuilderOfWildcardOfObject, "other")
.addStatement("super($N, $N)", "transcodeClass", "other")
.build();
ClassName glide = ClassName.get("com.bumptech.glide", "Glide");
ClassName requestManager = ClassName.get("com.bumptech.glide", "RequestManager");
MethodSpec secondConstructor =
MethodSpec.constructorBuilder()
.addParameter(glide, "glide")
.addParameter(requestManager, "requestManager")
.addParameter(classOfTranscodeType, "transcodeClass")
.addStatement("super($N, $N ,$N)", "glide", "requestManager", "transcodeClass")
.build();
return ImmutableList.of(firstConstructor, secondConstructor);
}
示例3: memberAsBeanStyleParameter
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
protected ParameterSpec memberAsBeanStyleParameter() {
if (memberModel.hasBuilder()) {
TypeName builderName = poetExtensions.getModelClass(memberModel.getC2jShape()).nestedClass("BuilderImpl");
return ParameterSpec.builder(builderName, fieldName()).build();
}
if (memberModel.isList() && hasBuilder(memberModel.getListModel().getListMemberModel())) {
TypeName memberName = poetExtensions.getModelClass(memberModel.getListModel().getListMemberModel().getC2jShape())
.nestedClass("BuilderImpl");
TypeName listType = ParameterizedTypeName.get(ClassName.get(Collection.class), memberName);
return ParameterSpec.builder(listType, fieldName()).build();
}
if (memberModel.isMap() && hasBuilder(memberModel.getMapModel().getValueModel())) {
TypeName keyType = typeProvider.getTypeNameForSimpleType(memberModel.getMapModel().getKeyModel()
.getVariable().getVariableType());
TypeName valueType = poetExtensions.getModelClass(memberModel.getMapModel().getValueModel().getC2jShape())
.nestedClass("BuilderImpl");
TypeName mapType = ParameterizedTypeName.get(ClassName.get(Map.class), keyType, valueType);
return ParameterSpec.builder(mapType, fieldName()).build();
}
return memberAsParameter();
}
示例4: regionId
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
private FieldSpec regionId(Set<String> allRegionIds) {
CodeBlock.Builder builder = CodeBlock.builder()
.add("$T.asList(\n$>$>", Arrays.class);
Iterator<String> iterator = allRegionIds.iterator();
while (iterator.hasNext()) {
builder.add("$S", iterator.next());
if (iterator.hasNext()) {
builder.add(",\n");
}
}
builder.add("$<$<)");
TypeName listType = ParameterizedTypeName.get(List.class, String.class);
return FieldSpec.builder(listType, "REGION_IDS", STATIC, FINAL)
.initializer(builder.build())
.build();
}
示例5: createFoldSignature
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
private MethodSpec.Builder createFoldSignature(Iterable<TypeVariableName> availableTypeVariables)
throws ParserException {
MethodSpec.Builder builder =
MethodSpec.methodBuilder("map")
.addTypeVariable(FOLD_RETURN_TYPE)
.addModifiers(Modifier.PUBLIC)
.returns(FOLD_RETURN_TYPE);
for (OutputValue arg : values) {
TypeName visitor =
ParameterizedTypeName.get(
ClassName.get(Function.class),
TypeVariableUtils.withoutMissingTypeVariables(
arg.parameterizedOutputClass(), availableTypeVariables),
FOLD_RETURN_TYPE);
builder.addParameter(
ParameterSpec.builder(visitor, asCamelCase(arg.name()))
.addAnnotation(Nonnull.class)
.build());
}
return builder;
}
示例6: mapOfBuildersGetter
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
private MethodSpec mapOfBuildersGetter(MemberModel memberModel) {
TypeName keyType = typeProvider.getTypeNameForSimpleType(memberModel.getMapModel().getKeyModel()
.getVariable().getVariableType());
ClassName valueType = poetExtensions.getModelClass(memberModel.getMapModel().getValueModel().getC2jShape());
TypeName returnType = ParameterizedTypeName.get(ClassName.get(Map.class), keyType, valueType.nestedClass("Builder"));
return basicGetter(memberModel,
returnType,
"return $1N != null ? $2T.mapValues($1N, $3T::toBuilder) : null",
memberModel.getVariable().getVariableName(),
CollectionUtils.class,
valueType);
}
示例7: generateDownloadOnlyRequestMethod
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
/**
* Overrides the protected downloadOnly method in {@link com.bumptech.glide.RequestBuilder} to
* return our generated subclass instead.
*/
private MethodSpec generateDownloadOnlyRequestMethod() {
ParameterizedTypeName generatedRequestBuilderOfFile
= ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(File.class));
return MethodSpec.methodBuilder("getDownloadOnlyRequest")
.addAnnotation(Override.class)
.returns(generatedRequestBuilderOfFile)
.addModifiers(Modifier.PROTECTED)
.addStatement("return new $T<>($T.class, $N).apply($N)",
generatedRequestBuilderClassName, File.class, "this",
"DOWNLOAD_ONLY_OPTIONS")
.build();
}
示例8: create
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
public FieldSpec create(Column column, VariableElement element, TypeElement entityClass) {
ColumnType columnType = ColumnType.fromVariable(element);
ParameterizedTypeName typeName = ParameterizedTypeName.get(ClassName.get(columnType.getColumnClass()), ClassName.get(entityClass));
String fieldName = NamingUtils.columnFieldName(element.getSimpleName().toString());
FieldSpec.Builder builder = FieldSpec.builder(typeName, fieldName, Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL);
builder.initializer("$T.$N($T.class, $S)", DbColumn.class, columnType.getFactoryMethod(), ClassName.get(entityClass), column.value());
return builder.build();
}
示例9: getJsConstructorFnType
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
@Nonnull
private static ParameterizedTypeName getJsConstructorFnType( @Nonnull final ComponentDescriptor descriptor )
{
return ParameterizedTypeName.get( COMPONENT_CONSTRUCTOR_FUNCTION_CLASSNAME,
TypeName.get( descriptor.getPropsType().asType() ),
TypeName.get( descriptor.getContextType().asType() ) );
}
示例10: bestGuess
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
public static TypeName bestGuess(String type) {
switch (type) {
case "void":
return TypeName.VOID;
case "boolean":
return TypeName.BOOLEAN;
case "byte":
return TypeName.BYTE;
case "char":
return TypeName.CHAR;
case "double":
return TypeName.DOUBLE;
case "float":
return TypeName.FLOAT;
case "int":
return TypeName.INT;
case "long":
return TypeName.LONG;
case "short":
return TypeName.SHORT;
default:
int left = type.indexOf('<');
if (left != -1) {
ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
List<TypeName> typeArguments = new ArrayList<>();
do {
typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
left = type.indexOf('<', left + 1);
} while (left != -1);
return ParameterizedTypeName.get(typeClassName,
typeArguments.toArray(new TypeName[typeArguments.size()]));
}
return ClassName.bestGuess(type);
}
}
示例11: generateConstructors
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
private List<MethodSpec> generateConstructors() {
ParameterizedTypeName classOfTranscodeType =
ParameterizedTypeName.get(ClassName.get(Class.class), transcodeTypeName);
TypeName wildcardOfObject = WildcardTypeName.subtypeOf(Object.class);
ParameterizedTypeName requestBuilderOfWildcardOfObject =
ParameterizedTypeName.get(ClassName.get(requestBuilderType), wildcardOfObject);
MethodSpec firstConstructor =
MethodSpec.constructorBuilder()
.addParameter(classOfTranscodeType, "transcodeClass")
.addParameter(requestBuilderOfWildcardOfObject, "other")
.addStatement("super($N, $N)", "transcodeClass", "other")
.build();
ClassName context = ClassName.get("android.content", "Context");
ClassName glide = ClassName.get("com.bumptech.glide", "Glide");
ClassName requestManager = ClassName.get("com.bumptech.glide", "RequestManager");
MethodSpec secondConstructor =
MethodSpec.constructorBuilder()
.addParameter(glide, "glide")
.addParameter(requestManager, "requestManager")
.addParameter(classOfTranscodeType, "transcodeClass")
.addParameter(context, "context")
.addStatement(
"super($N, $N ,$N, $N)", "glide", "requestManager", "transcodeClass", "context")
.build();
return ImmutableList.of(firstConstructor, secondConstructor);
}
示例12: generateDownloadOnlyRequestMethod
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
/**
* Overrides the protected downloadOnly method in {@code com.bumptech.glide.RequestBuilder} to
* return our generated subclass instead.
*/
private MethodSpec generateDownloadOnlyRequestMethod() {
ParameterizedTypeName generatedRequestBuilderOfFile
= ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(File.class));
return MethodSpec.methodBuilder("getDownloadOnlyRequest")
.addAnnotation(Override.class)
.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build())
.returns(generatedRequestBuilderOfFile)
.addModifiers(Modifier.PROTECTED)
.addStatement("return new $T<>($T.class, $N).apply($N)",
generatedRequestBuilderClassName, File.class, "this",
"DOWNLOAD_ONLY_OPTIONS")
.build();
}
示例13: generate
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
public TypeSpec generate() {
final TypeVariableName T = TypeVariableName.get("T");
final TypeName LIST_OF_T = ParameterizedTypeName.get(ClassName.get("java.util", "List"), T);
final TypeName RETURN_T = ProcessUtils.observableOf(T);
final TypeName RETURN_LIST_T = ProcessUtils.observableOf(LIST_OF_T);
return TypeSpec.interfaceBuilder(Constants.DATABASE_COMMON_INTERFACE_NAME)
.addModifiers(Modifier.PUBLIC)
.addTypeVariable(T)
.addMethod(MethodSpec.methodBuilder("select")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(Constants.queryBuilderClassName)
.build())
.addMethod(MethodSpec.methodBuilder("add")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.addParameter(T, "object", Modifier.FINAL)
.returns(RETURN_T)
.build())
.addMethod(MethodSpec.methodBuilder("add")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.addParameter(LIST_OF_T, "objects", Modifier.FINAL)
.returns(RETURN_LIST_T)
.build())
.addMethod(MethodSpec.methodBuilder("update")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.addParameter(T, "object", Modifier.FINAL)
.returns(RETURN_T)
.build())
.addMethod(MethodSpec.methodBuilder("update")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.addParameter(LIST_OF_T, "objects", Modifier.FINAL)
.returns(RETURN_LIST_T)
.build())
.addMethod(MethodSpec.methodBuilder("delete")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.addParameter(T, "object", Modifier.FINAL)
.returns(ProcessUtils.observableOf(TypeName.BOOLEAN.box()))
.build())
.addMethod(MethodSpec.methodBuilder("delete")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.addParameter(LIST_OF_T, "objects", Modifier.FINAL)
.returns(ProcessUtils.observableOf(TypeName.BOOLEAN.box()))
.build())
.addMethod(MethodSpec.methodBuilder("deleteAll")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(ProcessUtils.observableOf(TypeName.BOOLEAN.box()))
.build())
.addMethod(MethodSpec.methodBuilder("count")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(ProcessUtils.observableOf(TypeName.INT.box()))
.build())
.build();
}
示例14: updateRegistry
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
@Override
public void updateRegistry(TypeSpec.Builder registry, UserMarkerAnnotation annotation) {
TypeName retType = annotation.getServiceInterfaceTypeName();
TypeSpec.Builder deserializerBuilder = TypeSpec.classBuilder(DESERIALIZER_CLASS)
.superclass(ParameterizedTypeName.get(ClassName.get(StdDeserializer.class), retType))
.addModifiers(Modifier.PUBLIC)
.addModifiers(Modifier.STATIC)
.addModifiers(Modifier.FINAL)
.addMethod(MethodSpec.constructorBuilder().addStatement("this(null)").build())
.addMethod(MethodSpec.constructorBuilder().addParameter(Class.class, "clazz").addStatement("super(clazz)").build());
String jsonParser = "jsonParser";
String registeredName = "registeredName";
String node = "node";
String fieldNames = "fieldNames";
MethodSpec deserializerMethod = MethodSpec.methodBuilder("deserialize")
.addModifiers(Modifier.PUBLIC)
.addParameter(JsonParser.class, jsonParser)
.addParameter(DeserializationContext.class, "ctxt")
.addException(IOException.class)
.addException(JsonProcessingException.class)
.returns(annotation.getServiceInterfaceTypeName())
.addStatement("$T $L", String.class, registeredName)
.beginControlFlow("if ($L.isExpectedStartObjectToken())", jsonParser)
.addStatement("$T $L = $L.getCodec().readTree($L)", TreeNode.class, node, jsonParser, jsonParser)
// Check that object has exactly one key
.addComment("Check that object has exactly one key")
.addStatement("$T $L = $L.fieldNames()", ITERATOR_STRING, fieldNames, node)
.beginControlFlow("if (!$L.hasNext())", fieldNames)
// No keys; throw an exception
.addComment("No keys; throw an exception")
.addStatement(String.format("throw new RuntimeException(\"Failed to deserialize %s: no field names found\")", annotation.getServiceInterfaceName()))
.endControlFlow()
// At least one key; get the registered name
.addComment("At least one key; get the registered name")
.addStatement("$L = $L.next()", registeredName, fieldNames)
.beginControlFlow("if ($L.hasNext())", fieldNames)
.addComment("Too many keys; input is malformed")
.addStatement(String.format("throw new RuntimeException(\"Failed to deserialize %s: too many field names found\")", annotation.getServiceInterfaceName()))
.endControlFlow()
.addComment("Check that service is registered and initialize")
.beginControlFlow("if (getInstance().$L.containsKey($L))", "pluginMap", registeredName)
.addStatement("return getInstance().$L.get($L).deserialize($L.get($L).traverse($L.getCodec()))", "pluginMap", registeredName, node, registeredName, jsonParser)
.nextControlFlow("else")
.addStatement(String.format("throw new RuntimeException($T.format(\"Failed to deserialize %s: Service \\\"%%s\\\" not found in registry\", $L))",
annotation.getServiceInterfaceName()), String.class, registeredName)
.endControlFlow()
.nextControlFlow("else")
.addComment("Not an object; assume we're working with a string that corresponds to a configuration-less service")
.addStatement("$L = $L.getValueAsString()", registeredName, jsonParser)
.addComment("Check that service is registered and initialize")
.beginControlFlow("if (getInstance().$L.containsKey($L))", "pluginMap", registeredName)
.addStatement("return getInstance().$L.get($L).deserialize()", "pluginMap", registeredName)
.nextControlFlow("else")
.addStatement(String.format("throw new RuntimeException($T.format(\"Failed to deserialize %s: Service \\\"%%s\\\" not found in registry\", $L))",
annotation.getServiceInterfaceName()), String.class, registeredName)
.endControlFlow()
.endControlFlow()
.build();
deserializerBuilder = deserializerBuilder.addMethod(deserializerMethod);
TypeName configType = ParameterizedTypeName.get(ClassName.get(TypeReference.class), WildcardTypeName.subtypeOf(Object.class));
String serviceName = "serviceName";
MethodSpec getConfigTypeReference = MethodSpec.methodBuilder("getConfigTypeReference")
.addModifiers(Modifier.PUBLIC)
.addModifiers(Modifier.STATIC)
.addParameter(String.class, serviceName)
.returns(configType)
.beginControlFlow("if (getInstance().$L.containsKey($L))", "pluginMap", serviceName)
.addStatement("return getInstance().$L.get($L).getConfigTypeReference()", "pluginMap", serviceName)
.nextControlFlow("else")
.addStatement("return null")
.endControlFlow()
.build();
registry.addType(deserializerBuilder.build());
registry.addMethod(getConfigTypeReference);
}
示例15: generate
import com.squareup.javapoet.ParameterizedTypeName; //导入方法依赖的package包/类
TypeSpec generate(String generatedCodePackageName, @Nullable TypeSpec generatedOptions) {
generatedRequestBuilderClassName =
ClassName.get(generatedCodePackageName, GENERATED_REQUEST_BUILDER_SIMPLE_NAME);
generatedRequestBuilderOfTranscodeType =
ParameterizedTypeName.get(generatedRequestBuilderClassName, transcodeTypeName);
if (generatedOptions != null) {
requestOptionsClassName =
ClassName.get(generatedCodePackageName, generatedOptions.name);
} else {
requestOptionsClassName =
ClassName.get(
RequestOptionsGenerator.REQUEST_OPTIONS_PACKAGE_NAME,
RequestBuilderGenerator.REQUEST_OPTIONS_SIMPLE_NAME);
}
ParameterizedTypeName requestBuilderOfTranscodeType =
ParameterizedTypeName.get(
ClassName.get(REQUEST_BUILDER_PACKAGE_NAME, REQUEST_BUILDER_SIMPLE_NAME),
transcodeTypeName);
return TypeSpec.classBuilder(GENERATED_REQUEST_BUILDER_SIMPLE_NAME)
.addJavadoc("Contains all public methods from {@link $T}, all options from\n",
requestBuilderType)
.addJavadoc("{@link $T} and all generated options from\n", requestOptionsType)
.addJavadoc("{@link $T} in annotated methods in\n", GlideOption.class)
.addJavadoc("{@link $T} annotated classes.\n", GlideExtension.class)
.addJavadoc("\n")
.addJavadoc("<p>Generated code, do not modify.\n")
.addJavadoc("\n")
.addJavadoc("@see $T\n", requestBuilderType)
.addJavadoc("@see $T\n", requestOptionsType)
.addAnnotation(
AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "unused")
.addMember("value", "$S", "deprecation")
.build())
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.addTypeVariable(transcodeTypeName)
.superclass(requestBuilderOfTranscodeType)
.addMethods(generateConstructors())
.addMethod(generateDownloadOnlyRequestMethod())
.addMethods(generateGeneratedRequestOptionsEquivalents(generatedOptions))
.addMethods(generateRequestBuilderOverrides())
.build();
}