本文整理汇总了Java中javax.lang.model.type.IntersectionType类的典型用法代码示例。如果您正苦于以下问题:Java IntersectionType类的具体用法?Java IntersectionType怎么用?Java IntersectionType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IntersectionType类属于javax.lang.model.type包,在下文中一共展示了IntersectionType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitIntersection
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Override
public Void visitIntersection(IntersectionType t, StringBuilderAndState<TypeMirror> state) {
List<? extends TypeMirror> bounds = IgnoreCompletionFailures.in(t::getBounds);
if (state.visitingMethod) {
//the type erasure of an intersection type is the first type
if (!bounds.isEmpty()) {
bounds.get(0).accept(this, state);
}
} else {
for (TypeMirror b : bounds) {
b.accept(this, state);
state.bld.append("+");
}
}
return null;
}
示例2: testGetUpperBoundMultipleBounds
import javax.lang.model.type.IntersectionType; //导入依赖的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));
}
示例3: getCopy
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Override
public AnnotatedIntersectionType getCopy(boolean copyAnnotations) {
AnnotatedIntersectionType type =
new AnnotatedIntersectionType((IntersectionType) actualType, atypeFactory);
if (copyAnnotations)
type.addAnnotations(annotations);
type.supertypes = this.supertypes;
return type;
}
示例4: directSuperTypes
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Override
public List<AnnotatedDeclaredType> directSuperTypes() {
if (supertypes == null) {
List<? extends TypeMirror> ubounds = ((IntersectionType)actualType).getBounds();
List<AnnotatedDeclaredType> res = new ArrayList<AnnotatedDeclaredType>(ubounds.size());
for (TypeMirror bnd : ubounds) {
res.add((AnnotatedDeclaredType) createType(bnd, atypeFactory));
}
supertypes = Collections.unmodifiableList(res);
}
return supertypes;
}
示例5: accept
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Override
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
switch (kind) {
case BOOLEAN:
case BYTE:
case SHORT:
case INT:
case LONG:
case CHAR:
case FLOAT:
case DOUBLE:
return v.visitPrimitive((PrimitiveType) this, p);
case PACKAGE:
case VOID:
case NONE:
return v.visitNoType((NoType) this, p);
case NULL:
return v.visitNull((NullType) this, p);
case ARRAY:
return v.visitArray((ArrayType) this, p);
case DECLARED:
return v.visitDeclared((DeclaredType) this, p);
case ERROR:
return v.visitError((ErrorType) this, p);
case TYPEVAR:
return v.visitTypeVariable((TypeVariable) this, p);
case WILDCARD:
return v.visitWildcard((WildcardType) this, p);
case EXECUTABLE:
return v.visitExecutable((ExecutableType) this, p);
case OTHER:
return v.visit(this, p);
case UNION:
return v.visitUnion((UnionType) this, p);
case INTERSECTION:
return v.visitIntersection((IntersectionType) this, p);
default:
throw new AssertionError(String.format("Unknown TypeKind: %s", kind));
}
}
示例6: isSameIntersectionType
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
private boolean isSameIntersectionType(IntersectionType t1, IntersectionType t2) {
List<? extends TypeMirror> t1Bounds = t1.getBounds();
List<? extends TypeMirror> t2Bounds = t2.getBounds();
if (t1Bounds.size() != t2Bounds.size()) {
return false;
}
for (TypeMirror t1Bound : t1Bounds) {
if (!listContainsType(t2Bounds, t1Bound)) {
return false;
}
}
return true;
}
示例7: testGetBounds
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Test
public void testGetBounds() throws IOException {
compile("class Foo<T extends java.lang.Runnable & java.lang.CharSequence> { }");
TypeMirror runnableType = elements.getTypeElement("java.lang.Runnable").asType();
TypeMirror charSequenceType = elements.getTypeElement("java.lang.CharSequence").asType();
IntersectionType intersectionType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
List<? extends TypeMirror> bounds = intersectionType.getBounds();
assertSame(2, bounds.size());
assertSameType(runnableType, bounds.get(0));
assertSameType(charSequenceType, bounds.get(1));
}
示例8: testIsSameTypeIntersectionType
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Test
public void testIsSameTypeIntersectionType() throws IOException {
compile(
Joiner.on('\n')
.join(
"class Foo<T extends java.lang.CharSequence & java.lang.Runnable> { }",
"class Bar<T extends java.lang.CharSequence & java.lang.Runnable> { }"));
IntersectionType fooType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
IntersectionType barType = (IntersectionType) getTypeParameterUpperBound("Bar", 0);
assertSameType(fooType, barType);
}
示例9: testIsNotSameTypeIntersectionTypeDifferentSize
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Test
public void testIsNotSameTypeIntersectionTypeDifferentSize() throws IOException {
compile(
Joiner.on('\n')
.join(
"class Foo<T extends java.lang.CharSequence & java.lang.Runnable> { }",
"class Bar<T extends java.lang.CharSequence & java.lang.Runnable & java.io.Closeable> { }"));
IntersectionType fooType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
IntersectionType barType = (IntersectionType) getTypeParameterUpperBound("Bar", 0);
assertNotSameType(fooType, barType);
}
示例10: testIsNotSameTypeIntersectionTypeDifferentSizeReversed
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Test
public void testIsNotSameTypeIntersectionTypeDifferentSizeReversed() throws IOException {
compile(
Joiner.on('\n')
.join(
"class Foo<T extends java.lang.CharSequence & java.lang.Runnable & java.io.Closeable> { }",
"class Bar<T extends java.lang.CharSequence & java.lang.Runnable> { }"));
IntersectionType fooType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
IntersectionType barType = (IntersectionType) getTypeParameterUpperBound("Bar", 0);
assertNotSameType(fooType, barType);
}
示例11: testIsSameTypeIntersectionTypeDifferentOrder
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
/**
* We're not exactly sure why intersection types with the same bounds but in a different order are
* considered the same type; after all, they can have different erasures. However, the javac
* implementation behaves that way, so we must as well.
*
* <p>The relevant JLS8 sections are 4.4 and 4.9, if any future person wants to go see if they can
* grok why this behavior is correct.
*/
@Test
public void testIsSameTypeIntersectionTypeDifferentOrder() throws IOException {
compile(
Joiner.on('\n')
.join(
"class Foo<T extends java.lang.CharSequence & java.lang.Runnable> { }",
"class Bar<T extends java.lang.Runnable & java.lang.CharSequence> { }"));
IntersectionType fooType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
IntersectionType barType = (IntersectionType) getTypeParameterUpperBound("Bar", 0);
assertSameType(fooType, barType);
}
示例12: testIsNotSameTypeIntersectionTypeDifferentContents
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Test
public void testIsNotSameTypeIntersectionTypeDifferentContents() throws IOException {
compile(
Joiner.on('\n')
.join(
"class Foo<T extends java.lang.CharSequence & java.lang.Runnable> { }",
"class Bar<T extends java.lang.CharSequence & java.io.Closeable> { }"));
IntersectionType fooType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
IntersectionType barType = (IntersectionType) getTypeParameterUpperBound("Bar", 0);
assertNotSameType(fooType, barType);
}
示例13: visitIntersection
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Override
public Void visitIntersection(IntersectionType t, Void aVoid) {
scans.add(t.toString());
return super.visitIntersection(t, aVoid);
}
示例14: fillGenerics
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
public static String fillGenerics(Map<String, String> types, List<? extends TypeMirror> params, String separator) {
String result = "";
for (TypeMirror param : params) {
if (result.length() > 0) {
result += separator;
}
/**
* "if" block's order is critically! E.g. IntersectionType is TypeVariable.
*/
if (param instanceof WildcardType) {
result += "?";
final TypeMirror extendsBound = ((WildcardType) param).getExtendsBound();
if (extendsBound != null) {
result += " extends " + fillGenerics(types, extendsBound);
}
final TypeMirror superBound = ((WildcardType) param).getSuperBound();
if (superBound != null) {
result += " super " + fillGenerics(types, superBound);
}
} else if (param instanceof IntersectionType) {
result += "?";
final List<? extends TypeMirror> bounds = ((IntersectionType) param).getBounds();
if (!bounds.isEmpty()) {
result += " extends " + fillGenerics(types, bounds, " & ");
}
} else if (param instanceof DeclaredType) {
result += ((DeclaredType) param).asElement();
final List<? extends TypeMirror> typeArguments = ((DeclaredType) param).getTypeArguments();
if (!typeArguments.isEmpty()) {
final String s = fillGenerics(types, typeArguments);
result += "<" + s + ">";
}
} else if (param instanceof TypeVariable) {
String type = types.get(param.toString());
if (type == null) {
type = param.toString();
}
result += type;
} else {
result += param;
}
}
return result;
}
示例15: visitIntersection
import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Override
public Boolean visitIntersection(IntersectionType t, Void p) {
return false;
}