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


Java WildcardTypeName類代碼示例

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


WildcardTypeName類屬於com.squareup.javapoet包,在下文中一共展示了WildcardTypeName類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bestGuess

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private 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);
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:BindingSet.java

示例2: 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

示例3: createIsJsObject

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private MethodSpec createIsJsObject() {
    CodeBlock.Builder builder = CodeBlock.builder();
    builder.addStatement("$1T jsType = type.getAnnotation($1T.class)", ClassNames.JSINTEROP_JSTYPE);
    Stream.of(
            "jsType == null",
            "!jsType.isNative()",
            "!JsPackage.GLOBAL.equals(jsType.namespace())",
            "!\"Object\".equals(jsType.name())")
        .forEachOrdered(statement -> builder
                .beginControlFlow("if (" + statement + ")")
                    .addStatement("return false")
                .endControlFlow());
    builder.addStatement("return true");

    return MethodSpec.methodBuilder("isJsObject")
            .addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
            .addAnnotation(ClassNames.GWT_INCOMPATIBLE)
            .addParameter(ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(Object.class)), "type")
            .returns(Boolean.TYPE)
            .addCode(builder.build())
            .build();
}
 
開發者ID:codegen-io,項目名稱:jso-builder,代碼行數:23,代碼來源:SerializerGenerator.java

示例4: builderCopyMethodForList

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private MethodSpec builderCopyMethodForList() {
    TypeName keyType = typeProvider.getTypeNameForSimpleType(memberModel.getMapModel().getKeyModel()
                                                                        .getVariable().getVariableType());
    ClassName valueParameter = poetExtensions.getModelClass(memberModel.getMapModel().getValueModel().getC2jShape());
    ClassName builderForParameter = valueParameter.nestedClass("Builder");
    TypeName parameterType =
        ParameterizedTypeName.get(ClassName.get(Map.class), keyType, WildcardTypeName.subtypeOf(builderForParameter));

    CodeBlock code =
        CodeBlock.builder()
                 .beginControlFlow("if ($N == null)", memberParamName())
                 .addStatement("return null")
                 .endControlFlow()
                 .addStatement("return $N($N.entrySet().stream().collect(toMap($T::getKey, e -> e.getValue().build())))",
                               serviceModelCopiers.copyMethodName(),
                               memberParamName(),
                               Map.Entry.class)
                 .build();

    return MethodSpec.methodBuilder(serviceModelCopiers.builderCopyMethodName())
                     .addModifiers(Modifier.STATIC)
                     .addParameter(parameterType, memberParamName())
                     .returns(typeProvider.fieldType(memberModel))
                     .addCode(code)
                     .build();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:27,代碼來源:MemberCopierSpec.java

示例5: builderCopyMethodForMap

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private MethodSpec builderCopyMethodForMap() {
    ClassName listParameter = poetExtensions.getModelClass(memberModel.getListModel().getListMemberModel().getC2jShape());
    ClassName builderForParameter = listParameter.nestedClass("Builder");

    TypeName parameterType =
        ParameterizedTypeName.get(ClassName.get(Collection.class), WildcardTypeName.subtypeOf(builderForParameter));

    CodeBlock code = CodeBlock.builder()
                              .beginControlFlow("if ($N == null)", memberParamName())
                              .addStatement("return null")
                              .endControlFlow()
                              .addStatement("return $N($N.stream().map($T::$N).collect(toList()))",
                                            serviceModelCopiers.copyMethodName(),
                                            memberParamName(),
                                            builderForParameter,
                                            "build")
                              .build();

    return MethodSpec.methodBuilder(serviceModelCopiers.builderCopyMethodName())
                     .addModifiers(Modifier.STATIC)
                     .addParameter(parameterType, memberParamName())
                     .returns(typeProvider.fieldType(memberModel))
                     .addCode(code)
                     .build();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:26,代碼來源:MemberCopierSpec.java

示例6: generateConstructor

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private void generateConstructor(TypeSpec.Builder classBuilder) {
    MethodSpec.Builder builder = MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PUBLIC)
            .addParameter(TypeName.get(targetType), PocketBusConst.VAR_TARGET);

    if (parentAdapter != null) {
        builder.addStatement("super($N)", PocketBusConst.VAR_TARGET);
    }

    builder.addStatement("this.$N = new $T($N)", PocketBusConst.VAR_TARGET_REF, getWeakReferenceType(), PocketBusConst.VAR_TARGET)
            .addStatement("$T $N = new $T()", LIST_TYPE, PocketBusConst.VAR_SUBSCRIPTIONS, ParameterizedTypeName.get(ClassName.get(ArrayList.class),
                    ParameterizedTypeName.get(ClassName.get(Subscription.class), WildcardTypeName.subtypeOf(TypeName.OBJECT))));

    if (parentAdapter != null) {
        builder.addStatement("$N.addAll(super.$L())", PocketBusConst.VAR_SUBSCRIPTIONS, PocketBusConst.METHOD_GET_SUBSCRIPTIONS);
    }

    for (SubscriptionMethod method : methods) {
        builder.addStatement("$N.add($N)", PocketBusConst.VAR_SUBSCRIPTIONS, PocketBusConst.VAR_SUBSCRIPTION + method.getIndex());
    }

    builder.addStatement("this.$N = $T.unmodifiableList($N)", PocketBusConst.VAR_SUBSCRIPTIONS, ClassName.get(Collections.class),
            PocketBusConst.VAR_SUBSCRIPTIONS);

    classBuilder.addMethod(builder.build());
}
 
開發者ID:hansenji,項目名稱:PocketBus,代碼行數:27,代碼來源:SubscriptionGenerator.java

示例7: isBindable

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
/**
 * Returns true if the given type can be bound to some type. Note: this should
 * not be used with raw type of generic type.
 */
public static boolean isBindable(TypeName typeName) {
  if (typeName instanceof ParameterizedTypeName) {
    for (TypeName t : ((ParameterizedTypeName) typeName).typeArguments) {
      if (!isBindable(t)) {
        return false;
      }
    }
    return true;
  } else if (typeName instanceof ClassName) {
    return true;
  } else if (typeName instanceof WildcardTypeName) {
    return true;
  } else
    return typeName.isPrimitive();
}
 
開發者ID:google,項目名稱:tiger,代碼行數:20,代碼來源:Utils.java

示例8: generate

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
public void generate() {
    MethodSpec.Builder addHandlerMethod = MethodSpec.methodBuilder("addHandler")
                                                    .addAnnotation(Override.class)
                                                    .addModifiers(Modifier.PUBLIC)
                                                    .addParameter(ParameterizedTypeName.get(ClassName.get(IsPresenter.class),
                                                                                            WildcardTypeName.subtypeOf(Object.class),
                                                                                            WildcardTypeName.subtypeOf(Object.class)),
                                                                  "presenter")
                                                    .returns(ClassName.get(PresenterRegistration.class));
    // TODO implementing addHandler feature ...
//    // List of already created EventHandler used to avoid a second create ...
//    List<ClassNameModel> listOfEventHandlersToCreate = this.createListOfEventHandlersToCreate();
//    listOfEventHandlersToCreate.forEach(handlerClassName -> this.addHandlerToMetaList(loadEventHandlerMethod,
//                                                                                      handlerClassName));




    addHandlerMethod.addStatement("return null");
    typeSpec.addMethod(addHandlerMethod.build());
  }
 
開發者ID:mvp4g,項目名稱:mvp4g2,代碼行數:22,代碼來源:AddPresenterGenerator.java

示例9: appendTypes

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private void appendTypes(TypeSpec.Builder builder) {
  // Field
  TypeName classTypeName = ParameterizedTypeName.get(ClassName.get(Class.class),
      WildcardTypeName.subtypeOf(Resource.class));

  specTypes =
      createMapWithInitializer("types", LinkedHashMap.class, ClassName.get(String.class),
          classTypeName)
          .addModifiers(Modifier.FINAL)
          .build();

  builder.addField(specTypes);

  // Getter
  builder.addMethod(createGetterImpl(specTypes, "getTypes").build());
}
 
開發者ID:contentful,項目名稱:vault,代碼行數:17,代碼來源:SpaceInjection.java

示例10: appendModels

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private void appendModels(TypeSpec.Builder builder) {
  // Field
  TypeName classTypeName = ParameterizedTypeName.get(ClassName.get(Class.class),
      WildcardTypeName.subtypeOf(Object.class));

  TypeName helperTypeName = ParameterizedTypeName.get(ClassName.get(ModelHelper.class),
      WildcardTypeName.subtypeOf(Object.class));

  specModels = createMapWithInitializer("models", LinkedHashMap.class, classTypeName,
      helperTypeName).addModifiers(Modifier.FINAL).build();

  builder.addField(specModels);

  // Getter
  builder.addMethod(createGetterImpl(specModels, "getModels").build());
}
 
開發者ID:contentful,項目名稱:vault,代碼行數:17,代碼來源:SpaceInjection.java

示例11: testAdderAll

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
@Test
public void testAdderAll() throws Exception {
    BuildableRDFSProperty loadCap = getPropertyFromModel("http://example.de/ont#load_capacity");
    assertNotNull(loadCap);

    MethodSpec loadCapSpec = loadCap.buildAdderAll(declaringClass, generationConfig);

    // Test signature:
    assertEquals("addAllMaximumLoadCapacities", loadCapSpec.name);
    assertTrue(loadCapSpec.modifiers.contains(Modifier.PUBLIC));
    assertEquals(1, loadCapSpec.parameters.size());
    ClassName setClass = ClassName.get("java.util", "Set");
    assertEquals(ParameterizedTypeName.get(setClass, WildcardTypeName.subtypeOf(ClassName.get(Float.class))), loadCapSpec.parameters.get(0).type);

    // Test JavaDoc:
    assertNotNull(loadCapSpec.javadoc);
    assertTrue(loadCapSpec.javadoc.toString().startsWith("Ladung in Tonnen"));

    // Test annotation:
    assertEquals(0, loadCapSpec.annotations.size());
}
 
開發者ID:anno4j,項目名稱:anno4j,代碼行數:22,代碼來源:RDFSPropertySpecTest.java

示例12: testRemoverAll

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
@Test
public void testRemoverAll() throws Exception {
    BuildableRDFSProperty loadCap = getPropertyFromModel("http://example.de/ont#load_capacity");
    assertNotNull(loadCap);

    MethodSpec loadCapSpec = loadCap.buildRemoverAll(declaringClass, generationConfig);

    // Test signature:
    assertEquals("removeAllMaximumLoadCapacities", loadCapSpec.name);
    assertTrue(loadCapSpec.modifiers.contains(Modifier.PUBLIC));
    assertEquals(1, loadCapSpec.parameters.size());
    ClassName setClass = ClassName.get("java.util", "Set");
    assertEquals(ParameterizedTypeName.get(setClass, WildcardTypeName.subtypeOf(ClassName.get(Float.class))), loadCapSpec.parameters.get(0).type);

    // Test JavaDoc:
    assertNotNull(loadCapSpec.javadoc);
    assertTrue(loadCapSpec.javadoc.toString().startsWith("Ladung in Tonnen"));

    // Test annotation:
    assertEquals(0, loadCapSpec.annotations.size());
}
 
開發者ID:anno4j,項目名稱:anno4j,代碼行數:22,代碼來源:RDFSPropertySpecTest.java

示例13: simpleName

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private static String simpleName(TypeName typeName) {
  if (typeName instanceof ClassName) {
    return UPPER_CAMEL.to(LOWER_CAMEL, ((ClassName) typeName).simpleName());
  } else if (typeName instanceof ParameterizedTypeName) {
    ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName;
    return UPPER_CAMEL.to(LOWER_CAMEL, parameterizedTypeName.rawType.simpleName())
        + (parameterizedTypeName.typeArguments.isEmpty() ? "" : "__")
        + simpleName(parameterizedTypeName.typeArguments);
  } else if (typeName instanceof ArrayTypeName) {
    return "array__" + simpleName(((ArrayTypeName) typeName).componentType);
  } else if (typeName instanceof WildcardTypeName) {
    WildcardTypeName wildcardTypeName = (WildcardTypeName) typeName;
    return "wildcard__"
        + simpleName(ImmutableList.<TypeName>builder().addAll(wildcardTypeName.lowerBounds)
        .addAll(wildcardTypeName.upperBounds)
        .build());
  } else if (typeName instanceof TypeVariableName) {
    TypeVariableName variable = (TypeVariableName) typeName;
    return variable.name
        + (variable.bounds.isEmpty() ? "" : "__")
        + simpleName(variable.bounds);
  } else {
    return typeName.toString();
  }
}
 
開發者ID:rharter,項目名稱:auto-value-gson,代碼行數:26,代碼來源:AutoValueGsonExtension.java

示例14: createStartServices

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private MethodSpec createStartServices() {
    ClassName memoryServiceConnection = ClassName.get(PACKAGE, "MemoryServiceConnection");

    CodeBlock code = CodeBlock.builder()
            .beginControlFlow("for($T service: $L)", ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(Service.class)), FIELD_SERVICES)
            .addStatement("$T intent = new $T(context, service)", Intent.class, Intent.class)
            .addStatement("context.startService(intent)")
            .add("\n")
            .addStatement("$T connection = new $T()", memoryServiceConnection, memoryServiceConnection)
            .addStatement("context.bindService(intent, connection, Context.BIND_AUTO_CREATE)")
            .endControlFlow()
            .build();

    return MethodSpec.methodBuilder("startServices")
            .addAnnotation(Override.class)
            .addModifiers(Modifier.PUBLIC)
            .addParameter(ClassName.get(Context.class), "context")
            .addCode(code)
            .build();
}
 
開發者ID:T-Spoon,項目名稱:Android-Developer-Toolbelt,代碼行數:21,代碼來源:ServiceHolderWriter.java

示例15: collectionCollectionSetter

import com.squareup.javapoet.WildcardTypeName; //導入依賴的package包/類
private MethodSpec collectionCollectionSetter(final Descriptor d, final ExecutableElement field) {
  String fieldName = fieldName(field);
  ClassName collectionType = ClassName.get(Collection.class);
  TypeName itemType = genericArgument(field, 0);
  WildcardTypeName extendedType = subtypeOf(itemType);

  MethodSpec.Builder setter = MethodSpec.methodBuilder(fieldName)
      .addModifiers(PUBLIC)
      .addParameter(ParameterizedTypeName.get(collectionType, extendedType), fieldName)
      .returns(builderType(d));

  collectionNullGuard(setter, field);
  if (shouldEnforceNonNull(field)) {
    setter.beginControlFlow("for ($T item : $N)", itemType, fieldName);
    assertNotNull(setter, "item", fieldName + ": null item");
    setter.endControlFlow();
  }

  setter.addStatement("this.$N = new $T($N)", fieldName, collectionImplType(field), fieldName);
  return setter.addStatement("return this").build();
}
 
開發者ID:danielnorberg,項目名稱:auto-matter,代碼行數:22,代碼來源:AutoMatterProcessor.java


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