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


Java WildcardTypeName.subtypeOf方法代码示例

本文整理汇总了Java中com.squareup.javapoet.WildcardTypeName.subtypeOf方法的典型用法代码示例。如果您正苦于以下问题:Java WildcardTypeName.subtypeOf方法的具体用法?Java WildcardTypeName.subtypeOf怎么用?Java WildcardTypeName.subtypeOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.javapoet.WildcardTypeName的用法示例。


在下文中一共展示了WildcardTypeName.subtypeOf方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateConstructors

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的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

示例2: generateGetExcludedModuleClasses

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的package包/类
private MethodSpec generateGetExcludedModuleClasses(Set<String> excludedClassNames) {
  TypeName wildCardOfObject = WildcardTypeName.subtypeOf(Object.class);
  ParameterizedTypeName classOfWildcardOfObjet =
      ParameterizedTypeName.get(ClassName.get(Class.class), wildCardOfObject);
  ParameterizedTypeName setOfClassOfWildcardOfObject =
      ParameterizedTypeName.get(ClassName.get(Set.class), classOfWildcardOfObjet);
  ParameterizedTypeName hashSetOfClassOfWildcardOfObject =
      ParameterizedTypeName.get(ClassName.get(HashSet.class), classOfWildcardOfObjet);
  MethodSpec.Builder builder = MethodSpec.methodBuilder("getExcludedModuleClasses")
      .addModifiers(Modifier.PUBLIC)
      .addAnnotation(Override.class)
      .returns(setOfClassOfWildcardOfObject);

  if (excludedClassNames.isEmpty()) {
    builder.addStatement("return $T.emptySet()", Collections.class);
  } else {
    builder.addStatement(
        "$T excludedClasses = new $T()", setOfClassOfWildcardOfObject,
        hashSetOfClassOfWildcardOfObject);
    for (String excludedClassName : excludedClassNames) {
      // TODO: Remove this when we no longer support manifest parsing.
      // Using a Literal ($L) instead of a type ($T) to get a fully qualified import that allows
      // us to suppress deprecation warnings. Aimed at deprecated GlideModules.
      builder.addStatement("excludedClasses.add($L.class)", excludedClassName);
    }
    builder.addStatement("return excludedClasses");
  }

  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:AppModuleGenerator.java

示例3: generateConstructors

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:RequestBuilderGenerator.java

示例4: statement

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的package包/类
public static JavaFile statement(Domain ontology) {
	
	ClassName name = ClassName.get(ontology.getTargetPackage(), ontology.getName() + MARKER_MDC);

	ClassName markerName = MarkerGenerator.getName(ontology);
	
    TypeName wildcard = WildcardTypeName.subtypeOf(DomainMarker.class);
    TypeName classOfAny = ParameterizedTypeName.get(ClassName.get(Class.class), wildcard);
    
	ParameterSpec type = ParameterSpec.builder(classOfAny, "type").build();

	return JavaFile.builder(name.packageName(), TypeSpec.classBuilder(name)
				.superclass(ParameterizedTypeName.get( ClassName.get(DomainMdc.class), markerName))
				.addModifiers(Modifier.PUBLIC)
				.addMethod(MethodSpec.constructorBuilder()
					.addModifiers(Modifier.PUBLIC)
					.addStatement("super($T.QUALIFIER)", markerName)
					.build()
				)
				.addMethod(MethodSpec.methodBuilder("createMarker")
						.addModifiers(Modifier.PUBLIC)
						.addStatement("return new $T()", markerName)
						.returns(markerName)
						.build()
					)
				.addMethod(MethodSpec.methodBuilder("supports")
						.addModifiers(Modifier.PUBLIC)
						.addParameter(type)
						.addStatement("return $T.class == $N", markerName, type)
						.returns(boolean.class)
						.build()
					)
				.build())
			
			.build();
}
 
开发者ID:skjolber,项目名称:json-log-domain,代码行数:37,代码来源:MdcGenerator.java

示例5: parameterType

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的package包/类
public TypeName parameterType(MemberModel memberModel) {
    if (memberModel.isList()) {
        ListModel listModel = memberModel.getListModel();
        MemberModel elementModel = listModel.getListMemberModel();
        TypeName listElementType = parameterType(elementModel);
        if (elementModel.isList()) {
            listElementType = WildcardTypeName.subtypeOf(listElementType);
        }
        return ParameterizedTypeName.get(ClassName.get(Collection.class), listElementType);
    }

    if (memberModel.isMap()) {
        MapModel mapModel = memberModel.getMapModel();

        TypeName keyType;
        if (mapModel.getKeyModel().isSimple()) {
            keyType = getTypeNameForSimpleType(mapModel.getKeyModel().getVariable().getVariableType());
        } else {
            keyType = parameterType(mapModel.getKeyModel());

        }

        TypeName valueType = parameterType(mapModel.getValueModel());
        if (mapModel.getValueModel().isList()) {
            valueType = WildcardTypeName.subtypeOf(valueType);
        }

        return ParameterizedTypeName.get(ClassName.get(Map.class), keyType, valueType);
    }

    return fieldType(memberModel);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:33,代码来源:TypeProvider.java

示例6: mapEntryType

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的package包/类
public TypeName mapEntryType(MapModel mapModel) {
    TypeName keyType;
    if (mapModel.getKeyModel().isSimple()) {
        keyType = getTypeNameForSimpleType(mapModel.getKeyModel().getVariable().getVariableType());
    } else {
        keyType = parameterType(mapModel.getKeyModel());
    }

    TypeName valueType = parameterType(mapModel.getValueModel());
    if (mapModel.getValueModel().isList()) {
        valueType = WildcardTypeName.subtypeOf(valueType);
    }

    return ParameterizedTypeName.get(ClassName.get(Map.Entry.class), keyType, valueType);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:16,代码来源:TypeProvider.java

示例7: wildcardName

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的package包/类
private WildcardTypeName wildcardName( JWildcardType type ) {
    switch ( type.getBoundType() ) {
        case SUPER:
            return WildcardTypeName.supertypeOf( typeName( type.getFirstBound() ) );
        default:
            return WildcardTypeName.subtypeOf( typeName( type.getFirstBound() ) );
    }
}
 
开发者ID:nmorel,项目名称:gwt-jackson,代码行数:9,代码来源:JTypeName.java

示例8: wildcardType

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的package包/类
public static TypeName wildcardType(TypeName upperBound) {
    return WildcardTypeName.subtypeOf(upperBound);
}
 
开发者ID:c0d3d,项目名称:easy-plugins,代码行数:4,代码来源:Util.java

示例9: applyTypeSubstitution

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的package包/类
/**
 * Returns a JavaPoet {@link TypeName} representation of:
 * <ul>
 * <li>The given {@link TypeName}, if it does represent a class that is
 * eligible for substitution in this inventory; or,</li>
 * <li>The matching substitution class, based on the current output
 * class.</li>
 * </ul>
 * A substitution may be the outputClass itself, or the corresponding nested
 * class. For example, if the current output class is
 * {@code my.result.OutputCLass}, and this inventory is for the type
 * {@code my.input.Template} which has nested types
 * {@code my.input.Template.Nested} and
 * {@code my.input.Template.Nested.MoreNested}, this method would behave as
 * follows:
 * <ul>
 * <li>{@code (my.input.Template, my.result.OutputClass) => my.result.OutputClass}</li>
 * <li>{@code (my.input.Template.Nested, my.result.OutputClass) => my.result.OutputClass.Nested}</li>
 * <li>{@code (my.input.Template.Nested.MoreNested, my.result.OutputClass) => my.result.OutputClass.Nested.MoreNested}</li>
 * <li>{@code (java.lang.String, my.result.OutputClass) => java.lang.String}</li>
 * </ul>
 * 
 * @param mightBeSubstituted
 *            {@link TypeName} for the type that may get substituted.
 * @return
 */
TypeName applyTypeSubstitution(final TypeName mightBeSubstituted) {

	if (mightBeSubstituted instanceof ClassName) {
		// Attempt a raw type lookup
		if (rawTypeNameSubstitutions.containsKey(mightBeSubstituted)) {
			return rawTypeNameSubstitutions.get(mightBeSubstituted);
		}

		return mightBeSubstituted;
	}

	// Type with parameters
	if (mightBeSubstituted instanceof ParameterizedTypeName) {
		final ParameterizedTypeName parameterized = (ParameterizedTypeName)mightBeSubstituted;

		// Recurse for raw type and type parameters
		final ClassName rawType = (ClassName)applyTypeSubstitution(parameterized.rawType);
		final TypeName[] typeArgs = new TypeName[parameterized.typeArguments.size()];
		for (int i = 0; i < parameterized.typeArguments.size(); i++) {
			typeArgs[i] = applyTypeSubstitution(parameterized.typeArguments.get(i));
		}

		return ParameterizedTypeName.get(rawType, typeArgs);
	}

	// Wildcard type
	if (mightBeSubstituted instanceof WildcardTypeName) {
		final WildcardTypeName wildcard = (WildcardTypeName)mightBeSubstituted;

		// Recurse on bounds
		// JavaPoet Wildcard types always have an upper bound. The absence/presence
		// of a lower bound determines if this is an "extends" or "super". See
		// validations in private constructor and usage in emit()

		if (wildcard.lowerBounds.size() == 1) {
			return WildcardTypeName.supertypeOf(
					applyTypeSubstitution(wildcard.lowerBounds.get(0)));
		} else {
			return WildcardTypeName.subtypeOf(
					applyTypeSubstitution(wildcard.upperBounds.get(0)));
		}
	}

	return mightBeSubstituted;
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:72,代码来源:Inventory.java

示例10: anyWildcardTypeName

import com.squareup.javapoet.WildcardTypeName; //导入方法依赖的package包/类
public static WildcardTypeName anyWildcardTypeName() {
  return WildcardTypeName.subtypeOf(Object.class);
}
 
开发者ID:SiimKinks,项目名称:sqlitemagic,代码行数:4,代码来源:WriterUtil.java


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