当前位置: 首页>>代码示例>>Java>>正文


Java IntersectionType类代码示例

本文整理汇总了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;
}
 
开发者ID:revapi,项目名称:revapi,代码行数:18,代码来源:Util.java

示例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));
}
 
开发者ID:facebook,项目名称:buck,代码行数:18,代码来源:StandaloneTypeVariableTest.java

示例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;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:10,代码来源:AnnotatedTypeMirror.java

示例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;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:13,代码来源:AnnotatedTypeMirror.java

示例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));
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:41,代码来源:StandaloneTypeMirror.java

示例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;
}
 
开发者ID:facebook,项目名称:buck,代码行数:16,代码来源:TreeBackedTypes.java

示例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));
}
 
开发者ID:facebook,项目名称:buck,代码行数:15,代码来源:StandaloneIntersectionTypeTest.java

示例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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:14,代码来源:TreeBackedTypesTest.java

示例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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:14,代码来源:TreeBackedTypesTest.java

示例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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:14,代码来源:TreeBackedTypesTest.java

示例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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:22,代码来源:TreeBackedTypesTest.java

示例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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:14,代码来源:TreeBackedTypesTest.java

示例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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:6,代码来源:TypeScanner8Test.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:51,代码来源:Util.java

示例15: visitIntersection

import javax.lang.model.type.IntersectionType; //导入依赖的package包/类
@Override
public Boolean visitIntersection(IntersectionType t, Void p) {
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:ExportNonAccessibleElement.java


注:本文中的javax.lang.model.type.IntersectionType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。