本文整理匯總了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);
}
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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());
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}
}
示例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();
}
示例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();
}