本文整理汇总了Java中javax.lang.model.type.TypeVariable.getUpperBound方法的典型用法代码示例。如果您正苦于以下问题:Java TypeVariable.getUpperBound方法的具体用法?Java TypeVariable.getUpperBound怎么用?Java TypeVariable.getUpperBound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.type.TypeVariable
的用法示例。
在下文中一共展示了TypeVariable.getUpperBound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitTypeVariable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override
public StringBuilder visitTypeVariable(TypeVariable t, Boolean p) {
Element e = t.asElement();
if (e != null) {
String name = e.getSimpleName().toString();
if (!CAPTURED_WILDCARD.equals(name))
return DEFAULT_VALUE.append(name);
}
DEFAULT_VALUE.append("?"); //NOI18N
TypeMirror bound = t.getLowerBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" super "); //NOI18N
visit(bound, p);
} else {
bound = t.getUpperBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" extends "); //NOI18N
if (bound.getKind() == TypeKind.TYPEVAR)
bound = ((TypeVariable)bound).getLowerBound();
visit(bound, p);
}
}
return DEFAULT_VALUE;
}
示例2: visitTypeVariable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override
public Void visitTypeVariable(TypeVariable type, Void p) {
Element e = type.asElement();
if (e != null) {
CharSequence name = e.getSimpleName();
if (!CAPTURED_WILDCARD.contentEquals(name)) {
builder.append(name);
return null;
}
}
builder.append("?"); //NOI18N
TypeMirror bound = type.getLowerBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
builder.append(" super "); //NOI18N
visit(bound);
} else {
bound = type.getUpperBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
builder.append(" extends "); //NOI18N
if (bound.getKind() == TypeKind.TYPEVAR)
bound = ((TypeVariable)bound).getLowerBound();
visit(bound);
}
}
return null;
}
示例3: getMethodParameterTypes
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
/**
* 取得方法参数类型列表
*/
private List<String> getMethodParameterTypes(ExecutableElement executableElement) {
List<? extends VariableElement> methodParameters = executableElement.getParameters();
if (methodParameters.size() == 0) {
return null;
}
List<String> types = new ArrayList<>();
for (VariableElement variableElement : methodParameters) {
TypeMirror methodParameterType = variableElement.asType();
if (methodParameterType instanceof TypeVariable) {
TypeVariable typeVariable = (TypeVariable) methodParameterType;
methodParameterType = typeVariable.getUpperBound();
}
types.add(methodParameterType.toString());
}
return types;
}
示例4: capture
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
/**
* Verifies {@link AbstractTypes#capture(TypeMirror)}.
*/
@Test
public void capture() {
assertEquals(types.capture(type(Integer.class)), type(Integer.class));
DeclaredType outerClassType = types.getDeclaredType(element(OuterClass.class), type(Integer.class));
DeclaredType arrayListOfIntegersType = types.getDeclaredType(element(ArrayList.class), type(Integer.class));
// innerClassType: OuterClass<Integer>.InnerClass<? extends ArrayList<Integer>>
DeclaredType innerClassType = types.getDeclaredType(
outerClassType,
element(OuterClass.InnerClass.class),
types.getWildcardType(arrayListOfIntegersType, null)
);
DeclaredType capturedType = (DeclaredType) types.capture(innerClassType);
TypeVariable actualTypeArgument = (TypeVariable) capturedType.getTypeArguments().get(0);
// intersectionType = glb(ArrayList<Integer>, List<?>, Serializable)
IntersectionType intersectionType = (IntersectionType) actualTypeArgument.getUpperBound();
assertTrue(isSubtypeOfOneOf(arrayListOfIntegersType, intersectionType.getBounds()));
PrimitiveType intType = types.getPrimitiveType(TypeKind.INT);
assertTrue(types.isSameType(types.capture(intType), intType));
}
示例5: captureSingleRecursiveBound
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Test
public void captureSingleRecursiveBound() {
// enumType: Enum<?>
DeclaredType enumType = types.getDeclaredType(element(Enum.class), types.getWildcardType(null, null));
// capture: java.lang.Enum<capture<?>>
DeclaredType capture = (DeclaredType) types.capture(enumType);
assertEquals(capture.getTypeArguments().size(), 1);
TypeVariable newTypeVariable = (TypeVariable) capture.getTypeArguments().get(0);
DeclaredType upperBound = (DeclaredType) newTypeVariable.getUpperBound();
assertEquals(upperBound.getKind(), TypeKind.DECLARED);
// Since Enum has a recursive type bound, upperBound must represent Enum<capture<?>> as well!
assertEquals(capture, upperBound);
// The following should be implied, but explicit test does not hurt
TypeElement upperBoundAsElement = (TypeElement) upperBound.asElement();
assertTrue(upperBoundAsElement.getQualifiedName().contentEquals(Enum.class.getName()));
}
示例6: upperBound
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
/**
* If the argument is a bounded TypeVariable or WildcardType,
* return its non-variable, non-wildcard upper bound. Otherwise,
* return the type itself.
*
* @param type a type
* @return the non-variable, non-wildcard upper bound of a type,
* if it has one, or itself if it has no bounds
*/
public static TypeMirror upperBound(TypeMirror type) {
do {
if (type instanceof TypeVariable) {
TypeVariable tvar = (TypeVariable) type;
if (tvar.getUpperBound() != null) {
type = tvar.getUpperBound();
} else {
break;
}
} else if (type instanceof WildcardType) {
WildcardType wc = (WildcardType) type;
if (wc.getExtendsBound() != null) {
type = wc.getExtendsBound();
} else {
break;
}
} else {
break;
}
} while (true);
return type;
}
示例7: upperBound
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
/**
* If the argument is a bounded TypeVariable or WildcardType, return its non-variable,
* non-wildcard upper bound. Otherwise, return the type itself.
*
* @param type a type
* @return the non-variable, non-wildcard upper bound of a type, if it has one, or itself if it
* has no bounds
*/
public static TypeMirror upperBound(TypeMirror type) {
do {
if (type instanceof TypeVariable) {
TypeVariable tvar = (TypeVariable) type;
if (tvar.getUpperBound() != null) {
type = tvar.getUpperBound();
} else {
break;
}
} else if (type instanceof WildcardType) {
WildcardType wc = (WildcardType) type;
if (wc.getExtendsBound() != null) {
type = wc.getExtendsBound();
} else {
break;
}
} else {
break;
}
} while (true);
return type;
}
示例8: testGetUpperBoundMultipleBounds
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Test
public void testGetUpperBoundMultipleBounds() throws IOException {
compile("class Foo<T extends java.lang.CharSequence & java.lang.Runnable> { }");
TypeMirror charSequenceType = elements.getTypeElement("java.lang.CharSequence").asType();
TypeMirror runnableType = elements.getTypeElement("java.lang.Runnable").asType();
TypeVariable tVar =
(TypeVariable) elements.getTypeElement("Foo").getTypeParameters().get(0).asType();
IntersectionType upperBound = (IntersectionType) tVar.getUpperBound();
List<? extends TypeMirror> bounds = upperBound.getBounds();
assertSame(2, bounds.size());
assertSameType(charSequenceType, bounds.get(0));
assertSameType(runnableType, bounds.get(1));
}
示例9: visitTypeVariable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override
public StringBuilder visitTypeVariable(TypeVariable t, Boolean p) {
Element e = t.asElement();
if (e != null) {
String name = e.getSimpleName().toString();
if (!CAPTURED_WILDCARD.equals(name)) {
return DEFAULT_VALUE.append(name);
}
}
DEFAULT_VALUE.append("?"); //NOI18N
if (!insideCapturedWildcard) {
insideCapturedWildcard = true;
TypeMirror bound = t.getLowerBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" super "); //NOI18N
visit(bound, p);
} else {
bound = t.getUpperBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" extends "); //NOI18N
if (bound.getKind() == TypeKind.TYPEVAR) {
bound = ((TypeVariable)bound).getLowerBound();
}
visit(bound, p);
}
}
insideCapturedWildcard = false;
}
return DEFAULT_VALUE;
}
示例10: visitTypeVariable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override
public StringBuilder visitTypeVariable(TypeVariable t, Boolean p) {
Element e = t.asElement();
if (e != null) {
String name = e.getSimpleName().toString();
if (!CAPTURED_WILDCARD.equals(name))
return DEFAULT_VALUE.append(name);
}
DEFAULT_VALUE.append("?"); //NOI18N
if (!insideCapturedWildcard) {
insideCapturedWildcard = true;
TypeMirror bound = t.getLowerBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" super "); //NOI18N
visit(bound, p);
} else {
bound = t.getUpperBound();
if (bound != null && bound.getKind() != TypeKind.NULL) {
DEFAULT_VALUE.append(" extends "); //NOI18N
if (bound.getKind() == TypeKind.TYPEVAR)
bound = ((TypeVariable)bound).getLowerBound();
visit(bound, p);
}
}
insideCapturedWildcard = false;
}
return DEFAULT_VALUE;
}
示例11: visitMethodInvocation
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override
public Tree visitMethodInvocation(MethodInvocationTree node, Element p) {
List<? extends ExpressionTree> arguments = node.getArguments();
for (int i = 0; i < arguments.size(); i++) {
ExpressionTree argument = arguments.get(i);
Element argElement = asElement(argument); // TODO: Slow and misses ternary expressions
if(p.equals(argElement)) {
Element element = asElement(node);
if (element.getKind() == ElementKind.METHOD) {
ExecutableElement method = (ExecutableElement) element;
VariableElement parameter = method.getParameters().get(i);
Types types = workingCopy.getTypes();
TypeMirror parameterType = parameter.asType();
if(parameterType.getKind().equals(TypeKind.TYPEVAR)) {
TypeVariable typeVariable = (TypeVariable) parameterType;
TypeMirror upperBound = typeVariable.getUpperBound();
TypeMirror lowerBound = typeVariable.getLowerBound();
if(upperBound != null && !types.isSubtype(superTypeElement.asType(), upperBound)) {
isReplCandidate = false;
}
if(lowerBound != null && !types.isSubtype(lowerBound, superTypeElement.asType())) {
isReplCandidate = false;
}
} else if(!types.isAssignable(superTypeElement.asType(), parameterType)) {
isReplCandidate = false;
}
}
}
}
return super.visitMethodInvocation(node, p);
}
示例12: visitTypeVariable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override
public Void visitTypeVariable(TypeVariable t, Collection<DeclaredType> p) {
if (t.getLowerBound() != null) {
visit(t.getLowerBound(), p);
}
if (t.getUpperBound() != null) {
visit(t.getUpperBound(), p);
}
return DEFAULT_VALUE;
}
示例13: visitTypeVariable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override
public TypeMirror visitTypeVariable(TypeVariable t, CompilationInfo p) {
TypeMirror lb = t.getLowerBound() == null ? null : visit(t.getLowerBound(), p);
TypeMirror ub = t.getUpperBound() == null ? null : visit(t.getUpperBound(), p);
if (ub.getKind() == TypeKind.DECLARED) {
DeclaredType dt = (DeclaredType)ub;
TypeElement tel = (TypeElement)dt.asElement();
if (tel.getQualifiedName().contentEquals("java.lang.Object")) { // NOI18N
ub = null;
} else if (tel.getSimpleName().length() == 0) {
ub = null;
}
}
return p.getTypes().getWildcardType(ub, lb);
}
示例14: parseElement
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
private void parseElement(Element element, List<ParsedInfo> infos, Class<? extends Annotation> annotationClass) {
if (isBindingInWrongPackage(annotationClass, element)) {
return;
}
TypeElement enclosingElement = (TypeElement) element;
// Verify that the target type extends from ViewGroup.
TypeMirror elementType = element.asType();
if (elementType.getKind() == TypeKind.TYPEVAR) {
TypeVariable typeVariable = (TypeVariable) elementType;
elementType = typeVariable.getUpperBound();
}
if (!isSubtypeOfType(elementType, VIEW_GROUP)) {
error(element, "@%s fields must extend from ViewGroup. (%s)",
annotationClass.getSimpleName(), enclosingElement.getQualifiedName());
}
String name = element.getSimpleName().toString();
String canonicalName = enclosingElement.getQualifiedName().toString();
String superCanonicalName = ((TypeElement) element).getSuperclass().toString();
String superName = superCanonicalName.substring(superCanonicalName.lastIndexOf('.') + 1);
if (superCanonicalName.startsWith("android.widget.")) {
superCanonicalName = superCanonicalName.substring(superCanonicalName.lastIndexOf('.') + 1);
}
ParsedInfo info = new ParsedInfo();
info.name = name;
info.canonicalName = canonicalName;
info.superName = superName;
info.superCanonicalName = superCanonicalName;
infos.add(info);
}
示例15: parseBindTopping
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
private void parseBindTopping(Element element, Map<TypeElement, BindingClass> targetClassMap){
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
// Start by verifying common generated code restrictions.
boolean hasError = isInaccessibleViaGeneratedCode(BindTopping.class, "fields", element)
|| isBindingInWrongPackage(BindTopping.class, element);
// Verify that the target type extends from View.
TypeMirror elementType = element.asType();
if (elementType.getKind() == TypeKind.TYPEVAR) {
TypeVariable typeVariable = (TypeVariable) elementType;
elementType = typeVariable.getUpperBound();
}
if (!isSubtypeOfType(elementType, VIEW_TYPE) && !isInterface(elementType)) {
error(element, "@%s fields must extend from View or be an interface. (%s.%s)",
BindTopping.class.getSimpleName(), enclosingElement.getQualifiedName(),
element.getSimpleName());
hasError = true;
}
if (hasError) {
return;
}
BindTopping annotation = element.getAnnotation(BindTopping.class);
// Start assembling binding information
BindingClass bindingClass = getOrCreateTargetClass(targetClassMap, enclosingElement);
String name = element.getSimpleName().toString();
TypeName type = TypeName.get(elementType);
ClassName adapter = className(asTypeElement(getAdapterTypeMirror(annotation)));
ClassName interpolator = className(asTypeElement(getInterpolatorTypeMirror(annotation)));
FieldViewBinding binding = new FieldViewBinding(annotation.value(), name, adapter, interpolator, annotation.duration());
bindingClass.addViewBinding(binding);
}