本文整理匯總了Java中com.squareup.javapoet.ParameterizedTypeName類的典型用法代碼示例。如果您正苦於以下問題:Java ParameterizedTypeName類的具體用法?Java ParameterizedTypeName怎麽用?Java ParameterizedTypeName使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ParameterizedTypeName類屬於com.squareup.javapoet包,在下文中一共展示了ParameterizedTypeName類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateAdditionalRequestManagerMethod
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
private MethodSpec generateAdditionalRequestManagerMethod(ExecutableElement extensionMethod) {
String returnType = processorUtil.findClassValuesFromAnnotationOnClassAsNames(extensionMethod,
GlideType.class).iterator().next();
ClassName returnTypeClassName = ClassName.bestGuess(returnType);
ParameterizedTypeName parameterizedTypeName =
ParameterizedTypeName.get(generatedRequestBuilderClassName, returnTypeClassName);
return MethodSpec.methodBuilder(extensionMethod.getSimpleName().toString())
.addModifiers(Modifier.PUBLIC)
.returns(parameterizedTypeName)
.addJavadoc(processorUtil.generateSeeMethodJavadoc(extensionMethod))
.addStatement(
"$T requestBuilder = this.as($T.class)", parameterizedTypeName, returnTypeClassName)
.addStatement("$T.$N(requestBuilder)",
extensionMethod.getEnclosingElement(), extensionMethod.getSimpleName())
.addStatement("return requestBuilder")
.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: generateRequestManagerRequestBuilderMethodOverride
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
/**
* Generates overrides of existing RequestManager methods so that they return our generated
* RequestBuilder subtype.
*/
private MethodSpec generateRequestManagerRequestBuilderMethodOverride(
ExecutableElement methodToOverride) {
// We've already verified that this method returns a RequestBuilder and RequestBuilders have
// exactly one type argument, so this is safe unless those assumptions change.
TypeMirror typeArgument =
((DeclaredType) methodToOverride.getReturnType()).getTypeArguments().get(0);
ParameterizedTypeName generatedRequestBuilderOfType =
ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(typeArgument));
MethodSpec.Builder builder = ProcessorUtil.overriding(methodToOverride)
.returns(generatedRequestBuilderOfType)
.addCode(
ProcessorUtil.generateCastingSuperCall(
generatedRequestBuilderOfType, methodToOverride));
for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
builder.addAnnotation(AnnotationSpec.get(mirror));
}
return builder.build();
}
示例4: generateAdditionalRequestManagerMethodLegacy
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
private MethodSpec generateAdditionalRequestManagerMethodLegacy(
ExecutableElement extensionMethod) {
String returnType = processorUtil.findClassValuesFromAnnotationOnClassAsNames(extensionMethod,
GlideType.class).iterator().next();
ClassName returnTypeClassName = ClassName.bestGuess(returnType);
ParameterizedTypeName parameterizedTypeName =
ParameterizedTypeName.get(generatedRequestBuilderClassName, returnTypeClassName);
return MethodSpec.methodBuilder(extensionMethod.getSimpleName().toString())
.addModifiers(Modifier.PUBLIC)
.returns(parameterizedTypeName)
.addJavadoc(processorUtil.generateSeeMethodJavadoc(extensionMethod))
.addStatement(
"$T requestBuilder = this.as($T.class)", parameterizedTypeName, returnTypeClassName)
.addStatement("$T.$N(requestBuilder)",
extensionMethod.getEnclosingElement(), extensionMethod.getSimpleName())
.addStatement("return requestBuilder")
.build();
}
示例5: buildGetByQueryMethod
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
@Nonnull
private MethodSpec buildGetByQueryMethod()
{
final TypeName entityType = TypeName.get( getElement().asType() );
final ParameterizedTypeName queryType =
ParameterizedTypeName.get( ClassName.get( Predicate.class ), entityType );
return MethodSpec.methodBuilder( "getByQuery" ).
addModifiers( Modifier.PUBLIC, Modifier.FINAL ).
addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).
addParameter( ParameterSpec.builder( queryType, "query", Modifier.FINAL ).
addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).build() ).
returns( entityType ).
addStatement( "final $T entity = findByQuery( query )", entityType ).
addCode( CodeBlock.builder().
beginControlFlow( "if ( null == entity )" ).
addStatement( "throw new $T()", GeneratorUtil.NO_RESULT_EXCEPTION_CLASSNAME ).
endControlFlow().
build() ).
addStatement( "return entity" ).
build();
}
示例6: deserializeUnknownParameterizedObject
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
@Override
public String deserializeUnknownParameterizedObject(
String readFromBundle,
ParameterizedTypeName parameterizedTypeName,
VariableElement deserializerElement) {
StringBuilder typeToken = new StringBuilder("new ")
.append(TYPE_TOKEN_FULLY_QUALIFIED)
.append("<")
.append(parameterizedTypeName.rawType.simpleName())
.append("<");
for (TypeName typeName : parameterizedTypeName.typeArguments) {
typeToken.append(deserializeParameterizedObject(typeName))
.append(", ");
}
typeToken.deleteCharAt(typeToken.length() - 1);
typeToken.deleteCharAt(typeToken.length() - 1);
typeToken.append(">(){}.getType()");
return CodeBlock.builder()
.add("$L.$L($L, $L)", deserializerElement.getSimpleName().toString(), "fromJson", readFromBundle,
typeToken)
.build()
.toString();
}
示例7: logger
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
public static JavaFile logger(Domain ontology) {
ClassName name = ClassName.get(ontology.getTargetPackage(), ontology.getName() + LOGGER);
ClassName statementName = ClassName.get(ontology.getTargetPackage(), ontology.getName() + STATEMENT);
ParameterSpec loggerParameter = ParameterSpec.builder(org.slf4j.Logger.class, "logger").build();
return JavaFile.builder(name.packageName(), TypeSpec.classBuilder(name)
.superclass(ParameterizedTypeName.get(ClassName.get(AbstractDomainLogger.class), statementName))
.addJavadoc(composeJavadoc(ontology, name))
.addModifiers(Modifier.PUBLIC)
.addMethod(MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addParameter(loggerParameter)
.addStatement("super($N)", loggerParameter)
.build())
.addMethod(getCreateLogStatementMethod(statementName)).build()).build();
}
示例8: create
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
@Override
public String create() {
MethodSpec method = MethodSpec.methodBuilder("onBind")
.addModifiers(Modifier.PUBLIC)
.addParameter(viewType, "target")
.addParameter(valueType, "value")
.returns(void.class)
.addStatement("$N.$N(value)", "target", getPropertySetter(property))
.build();
TypeSpec anonymous = TypeSpec.anonymousClassBuilder("")
.addSuperinterface(ParameterizedTypeName.get(TypeUtils.SYNC_ON_BIND, viewType, valueType))
.addMethod(method)
.build();
return anonymous.toString();
}
示例9: visitVariableAsField
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
@Override
public Void visitVariableAsField(VariableElement element, Trees trees) {
if (isForEachVariable(element) && Util.hasInitializer(element, trees) && retainTypeFromTemplate(element)) {
// If we are retaining the type from the template of a static final field,
// the value has to be initialized with a value passed to a descriptor
// initialization annotation, which limits the types that can be used.
TypeName fieldType = TypeName.get(element.asType());
if (fieldType instanceof ParameterizedTypeName) {
fieldType = ((ParameterizedTypeName)fieldType).rawType;
}
assertThat(fieldType.isPrimitive()
|| STRING_CLASS_NAME.equals(fieldType)
|| CLASS_CLASS_NAME.equals(fieldType), element,
ValidationMessages.TEMPLATE_INITIALIZED_FOREACH_FIELDS);
}
return null;
}
示例10: traditionalMethod
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
/**
* Generates the traditional method for an operation (i.e. one that takes a request and returns a response).
*/
private MethodSpec.Builder traditionalMethod(OperationModel opModel) {
ClassName responsePojoType = getPojoResponseType(opModel);
ClassName requestType = ClassName.get(modelPackage, opModel.getInput().getVariableType());
MethodSpec.Builder builder = methodSignatureWithReturnType(opModel)
.addParameter(requestType, opModel.getInput().getVariableName())
.addJavadoc(opModel.getDocs(model, ClientType.ASYNC));
if (opModel.hasStreamingInput()) {
builder.addParameter(ClassName.get(AsyncRequestProvider.class), "requestProvider");
}
if (opModel.hasStreamingOutput()) {
builder.addTypeVariable(STREAMING_TYPE_VARIABLE);
final ParameterizedTypeName asyncResponseHandlerType = ParameterizedTypeName
.get(ClassName.get(AsyncResponseHandler.class), responsePojoType, STREAMING_TYPE_VARIABLE);
builder.addParameter(asyncResponseHandlerType, "asyncResponseHandler");
}
return operationBody(builder, opModel);
}
示例11: 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;
}
示例12: createFoldVoidSignature
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
private MethodSpec.Builder createFoldVoidSignature(
Iterable<TypeVariableName> availableTypeVariables) throws ParserException {
MethodSpec.Builder builder =
MethodSpec.methodBuilder("match").addModifiers(Modifier.PUBLIC).returns(void.class);
for (OutputValue arg : values) {
TypeName visitor =
ParameterizedTypeName.get(
ClassName.get(Consumer.class),
withoutMissingTypeVariables(arg.parameterizedOutputClass(), availableTypeVariables));
builder.addParameter(
ParameterSpec.builder(visitor, asCamelCase(arg.name()))
.addAnnotation(Nonnull.class)
.build());
}
return builder;
}
示例13: 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();
}
示例14: generateListType
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
@Nonnull
private TypeName generateListType(@Nonnull String className, @Nonnull JsonValue value, @Nonnull ClassBuilder builder) {
if (value.isArray()) {
final JsonValue firstValue = value.asArray()
.stream()
.findFirst()
.orElse(new JsonNull());
final TypeName type = generateListType(className, firstValue, builder);
return ParameterizedTypeName.get(ClassName.get(List.class), type);
}
if (value.isObject()) {
final TypeSpec innerClass = fromObject(className, value.asObject(), Modifier.PUBLIC, Modifier.STATIC);
builder.addInnerType(innerClass);
final TypeName innerClassType = ClassName.bestGuess(innerClass.name);
return ParameterizedTypeName.get(ClassName.get(List.class), innerClassType);
}
return ParameterizedTypeName.get(ClassName.get(List.class), value.getType().box());
}
示例15: registerItem
import com.squareup.javapoet.ParameterizedTypeName; //導入依賴的package包/類
@Override
protected void registerItem(EndpointsEntry entry, MethodSpec.Builder methodBuilder) {
final FullClassName handlerEndpoint = new FullClassName(entry.element.fullQualifiedNoneGenericName() + "EndpointHandler");
String path = entry.element.getAnnotation(Handler.class).value();
ClassName handlerEndpointType = ClassName.get(handlerEndpoint.asPackage(), handlerEndpoint.asSimpleName());
MethodSpec getMethod = MethodSpec.methodBuilder("get")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(handlerEndpointType)
.addStatement("return new $T()", handlerEndpointType)
.build();
TypeSpec factoryType = TypeSpec.anonymousClassBuilder("")
.addSuperinterface(ParameterizedTypeName.get(ClassName.get(Supplier.class), handlerEndpointType.box()))
.addMethod(getMethod)
.build();
methodBuilder.addStatement("registry.registerEndpoint(\"" + path + "\", $L)", factoryType);
}