当前位置: 首页>>代码示例>>Java>>正文


Java ParameterizedTypeName类代码示例

本文整理汇总了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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:RequestManagerGenerator.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:RequestBuilderGenerator.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:RequestManagerGenerator.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:RequestManagerGenerator.java

示例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();
}
 
开发者ID:arez,项目名称:arez,代码行数:22,代码来源:ComponentDescriptor.java

示例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();
}
 
开发者ID:uber,项目名称:auto-value-bundle,代码行数:26,代码来源:GsonDeserializer.java

示例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();
}
 
开发者ID:skjolber,项目名称:json-log-domain,代码行数:19,代码来源:LoggerGenerator.java

示例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();
}
 
开发者ID:sedstrom,项目名称:Witch-Android,代码行数:18,代码来源:OnBindPropertySetter.java

示例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;
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:20,代码来源:Validator.java

示例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);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:24,代码来源:AsyncClientInterface.java

示例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;
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:25,代码来源:MapMethods.java

示例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;
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:20,代码来源:MatchMethods.java

示例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();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:23,代码来源:AbstractMemberSetters.java

示例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());
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:22,代码来源:JavaConverter.java

示例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);
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:20,代码来源:EndpointsRegisterMethodWriter.java


注:本文中的com.squareup.javapoet.ParameterizedTypeName类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。