當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeVariableName類代碼示例

本文整理匯總了Java中com.squareup.javapoet.TypeVariableName的典型用法代碼示例。如果您正苦於以下問題:Java TypeVariableName類的具體用法?Java TypeVariableName怎麽用?Java TypeVariableName使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeVariableName類屬於com.squareup.javapoet包,在下文中一共展示了TypeVariableName類的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);

    }

}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:22,代碼來源:CopyReplacer.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:RequestManagerGenerator.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:RequestManagerGenerator.java

示例4: writeConsumer

import com.squareup.javapoet.TypeVariableName; //導入依賴的package包/類
private static ClassName writeConsumer(int count) throws IOException {
  String packageName = "info.dourok.esactivity.function";
  MethodSpec.Builder method = MethodSpec.methodBuilder("accept")
      .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT);

  TypeSpec.Builder type = TypeSpec.interfaceBuilder("Consumer" + count)
      .addModifiers(Modifier.PUBLIC);
  for (int i = 0; i < count; i++) {
    type.addTypeVariable(TypeVariableName.get("T" + i));
    method.addParameter(
        TypeVariableName.get("T" + i), "t" + i);
  }
  type.addMethod(method.build());
  JavaFile.builder(packageName, type.build())
      .build()
      .writeTo(EasyUtils.getFiler());
  return ClassName.get(packageName, "Consumer" + count);
}
 
開發者ID:douo,項目名稱:ActivityBuilder,代碼行數:19,代碼來源:ConsumerHelper.java

示例5: createFoldSignature

import com.squareup.javapoet.TypeVariableName; //導入依賴的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

示例6: createFoldVoidSignature

import com.squareup.javapoet.TypeVariableName; //導入依賴的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

示例7: create

import com.squareup.javapoet.TypeVariableName; //導入依賴的package包/類
static OutputValue create(Value value, ClassName specOutputClass, Spec spec)
    throws ParserException {
  ClassName outputClass = specOutputClass.nestedClass(value.name());
  Iterable<TypeVariableName> typeVariables = getTypeVariables(value, spec.typeVariables());

  List<Parameter> parameters = new ArrayList<>();
  for (Parameter parameter : value.parameters()) {
    TypeName rawParamType = withoutTypeParameters(parameter.type());

    if (isDataEnumParameter(rawParamType)) {
      TypeName paramOutputType =
          withParametersFromOther(toOutputClass(rawParamType), parameter.type());
      parameters.add(new Parameter(parameter.name(), paramOutputType, parameter.canBeNull()));
    } else {
      parameters.add(parameter);
    }
  }

  return new OutputValue(outputClass, value.name(), parameters, typeVariables);
}
 
開發者ID:spotify,項目名稱:dataenum,代碼行數:21,代碼來源:OutputValueFactory.java

示例8: typeNeedsTypeVariable

import com.squareup.javapoet.TypeVariableName; //導入依賴的package包/類
private static boolean typeNeedsTypeVariable(TypeName type, TypeVariableName typeVariable) {
  if (typeVariable.equals(type)) {
    return true;
  }

  if (type instanceof ParameterizedTypeName) {
    ParameterizedTypeName parameterized = ((ParameterizedTypeName) type);
    for (TypeName typeArgument : parameterized.typeArguments) {
      if (typeVariable.equals(typeArgument)) {
        return true;
      }
    }
  }

  if (type instanceof ArrayTypeName) {
    ArrayTypeName arrayType = (ArrayTypeName) type;
    if (typeVariable.equals(arrayType.componentType)) {
      return true;
    }
  }
  return false;
}
 
開發者ID:spotify,項目名稱:dataenum,代碼行數:23,代碼來源:OutputValueFactory.java

示例9: getSuperclassForValue

import com.squareup.javapoet.TypeVariableName; //導入依賴的package包/類
private static TypeName getSuperclassForValue(OutputValue value, OutputSpec spec)
    throws ParserException {
  if (!spec.hasTypeVariables()) {
    return spec.outputClass();
  }

  List<TypeName> superParameters = new ArrayList<>();
  for (TypeVariableName typeVariable : spec.typeVariables()) {
    if (Iterables.contains(value.typeVariables(), typeVariable)) {
      superParameters.add(typeVariable);
    } else {
      if (typeVariable.bounds.size() == 0) {
        superParameters.add(TypeName.OBJECT);
      } else if (typeVariable.bounds.size() == 1) {
        superParameters.add(typeVariable.bounds.get(0));
      } else {
        throw new ParserException("More than one generic type bound is not supported ");
      }
    }
  }

  return ParameterizedTypeName.get(
      spec.outputClass(), superParameters.toArray(new TypeName[] {}));
}
 
開發者ID:spotify,項目名稱:dataenum,代碼行數:25,代碼來源:ValueTypeFactory.java

示例10: createAsSpecMethod

import com.squareup.javapoet.TypeVariableName; //導入依賴的package包/類
private static MethodSpec createAsSpecMethod(OutputValue value, OutputSpec spec) {
  List<TypeVariableName> missingTypeVariables = extractMissingTypeVariablesForValue(value, spec);

  Builder builder =
      MethodSpec.methodBuilder("as" + spec.outputClass().simpleName())
          .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
          .returns(spec.parameterizedOutputClass())
          .addTypeVariables(missingTypeVariables)
          .addStatement("return ($T) this", spec.parameterizedOutputClass());

  // if there are type variables that this sub-type doesn't use, they will lead to 'unchecked
  // cast'
  // warnings when compiling the generated code. These warnings are safe to suppress, since this
  // sub type will never use those type variables.
  if (!missingTypeVariables.isEmpty()) {
    builder.addAnnotation(SUPPRESS_UNCHECKED_WARNINGS);
  }

  return builder.build();
}
 
開發者ID:spotify,項目名稱:dataenum,代碼行數:21,代碼來源:ValueTypeFactory.java

示例11: parse

import com.squareup.javapoet.TypeVariableName; //導入依賴的package包/類
public static Spec parse(Element element, ProcessingEnvironment processingEnv) {
  Messager messager = processingEnv.getMessager();

  if (element.getKind() != ElementKind.INTERFACE) {
    messager.printMessage(
        Diagnostic.Kind.ERROR, "@DataEnum can only be used on interfaces.", element);
    return null;
  }

  TypeElement dataEnum = (TypeElement) element;

  List<TypeVariableName> typeVariableNames = new ArrayList<>();
  for (TypeParameterElement typeParameterElement : dataEnum.getTypeParameters()) {
    typeVariableNames.add(TypeVariableName.get(typeParameterElement));
  }

  List<Value> values = ValuesParser.parse(dataEnum, processingEnv);
  if (values == null) {
    return null;
  }

  ClassName enumInterface = ClassName.get(dataEnum);
  return new Spec(enumInterface, typeVariableNames, values);
}
 
開發者ID:spotify,項目名稱:dataenum,代碼行數:25,代碼來源:SpecParser.java

示例12: 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();
}
 
開發者ID:codegen-io,項目名稱:jso-builder,代碼行數:17,代碼來源:JSOBuilderProcessor.java

示例13: fromExecutableElementWithSubstitutor

import com.squareup.javapoet.TypeVariableName; //導入依賴的package包/類
/**
 * Static factory for creating a {@link MethodSignature} from an
 * {@link ExecutableElement} and a function that can perform type
 * substitutions on a {@link TypeMirror}, returning a {@link TypeName}
 * instance.
 * 
 * @param element
 * @param substitutor
 * @return
 */
public static MethodSignature fromExecutableElementWithSubstitutor(final ExecutableElement element,
		Function<TypeMirror,TypeName> substitutor) {
	return builder()
			.setName(simpleName(element))
			.setVarargs(element.isVarArgs())
			.setReturns(substitutor.apply(element.getReturnType()))
			.setIsStatic(Util.isStatic(element))
			.addParameters(element.getParameters().stream()
					.map(VariableElement::asType)
					.map(substitutor)
					.collect(toList()))
			.addExceptions(element.getThrownTypes().stream()
					.map(substitutor)
					.collect(toList()))
			.addTypeParameters(element.getTypeParameters().stream()
					.map(param -> TypeVariableName.get(simpleName(param))
							.withBounds(param.getBounds().stream()
									.map(substitutor)
									.collect(toList())))
					.collect(toList()))
			.build();
}
 
開發者ID:FermioCloud,項目名稱:java-code-templates,代碼行數:33,代碼來源:MethodSignature.java

示例14: fromExecutableElement

import com.squareup.javapoet.TypeVariableName; //導入依賴的package包/類
public static MethodSignature fromExecutableElement(final ExecutableElement element) {
	return builder()
			.setName(simpleName(element))
			.setVarargs(element.isVarArgs())
			.setReturns(TypeName.get(element.getReturnType()))
			.setIsStatic(Util.isStatic(element))
			.addParameters(element.getParameters().stream()
					.map(VariableElement::asType)
					.map(TypeName::get)
					.collect(toList()))
			.addExceptions(element.getThrownTypes().stream()
					.map(TypeName::get)
					.collect(toList()))
			.addTypeParameters(element.getTypeParameters().stream()
					.map(param -> TypeVariableName.get(simpleName(param))
							.withBounds(param.getBounds().stream()
									.map(TypeName::get)
									.collect(toList())))
					.collect(toList()))
			.build();
	
}
 
開發者ID:FermioCloud,項目名稱:java-code-templates,代碼行數:23,代碼來源:MethodSignature.java

示例15: getDeployMethodSpec

import com.squareup.javapoet.TypeVariableName; //導入依賴的package包/類
private static MethodSpec.Builder getDeployMethodSpec(
        String className, Class authType, String authName, boolean isPayable) {
    MethodSpec.Builder builder = MethodSpec.methodBuilder("deploy")
            .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
            .returns(
                    buildRemoteCall(TypeVariableName.get(className, Type.class)))
            .addParameter(Web3j.class, WEB3J)
            .addParameter(authType, authName)
            .addParameter(BigInteger.class, GAS_PRICE)
            .addParameter(BigInteger.class, GAS_LIMIT);
    if (isPayable) {
        return builder.addParameter(BigInteger.class, INITIAL_VALUE);
    } else {
        return builder;
    }
}
 
開發者ID:web3j,項目名稱:web3j,代碼行數:17,代碼來源:SolidityFunctionWrapper.java


注:本文中的com.squareup.javapoet.TypeVariableName類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。