com.sun.tools.javac.code.Types.cvarUpperBound()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中com.sun.tools.javac.code.Types.cvarUpperBound()方法的一些代码示例,展示了Types.cvarUpperBound()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.cvarUpperBound()方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:cvarUpperBound

Types.cvarUpperBound介绍

[英]Get a capture variable's upper bound, returning other types unchanged.
[中]获取捕获变量的上限,返回其他类型不变。

代码示例

代码示例来源:origin: google/error-prone

/**
 * Returns the upper bound of a type if it has one, or the type itself if not. Correctly handles
 * wildcards and capture variables.
 */
public static Type getUpperBound(Type type, Types types) {
 if (type.hasTag(TypeTag.WILDCARD)) {
  return types.wildUpperBound(type);
 }
 if (type.hasTag(TypeTag.TYPEVAR) && ((TypeVar) type).isCaptured()) {
  return types.cvarUpperBound(type);
 }
 if (type.getUpperBound() != null) {
  return type.getUpperBound();
 }
 // concrete type, e.g. java.lang.String, or a case we haven't considered
 return type;
}

代码示例来源:origin: konsoletyper/teavm-javac

/**
 * javac has a long-standing 'simplification' (see 6391995):
 * given an actual argument type, the method check is performed
 * on its upper bound. This leads to inconsistencies when an
 * argument type is checked against itself. For example, given
 * a type-variable T, it is not true that {@code U(T) <: T},
 * so we need to guard against that.
 */
private Type U(Type found) {
  return found == pt ?
      found : types.cvarUpperBound(found);
}

代码示例来源:origin: konsoletyper/teavm-javac

boolean isAccessible(Env<AttrContext> env, Type t, boolean checkInner) {
  return (t.hasTag(ARRAY))
    ? isAccessible(env, types.cvarUpperBound(types.elemtype(t)))
    : isAccessible(env, t.tsym, checkInner);
}

代码示例来源:origin: konsoletyper/teavm-javac

/**
* Get a capture variable's upper bound, returning other types unchanged.
* @param t a type
*/
public Type cvarUpperBound(Type t) {
  if (t.hasTag(TYPEVAR)) {
    TypeVar v = (TypeVar) t.unannotatedType();
    return v.isCaptured() ? cvarUpperBound(v.bound) : v;
  }
  else return t.unannotatedType();
}

代码示例来源:origin: com.google.errorprone/error_prone_check_api

/**
 * Returns the upper bound of a type if it has one, or the type itself if not. Correctly handles
 * wildcards and capture variables.
 */
public static Type getUpperBound(Type type, Types types) {
 if (type.hasTag(TypeTag.WILDCARD)) {
  return types.wildUpperBound(type);
 }
 if (type.hasTag(TypeTag.TYPEVAR) && ((TypeVar) type).isCaptured()) {
  return types.cvarUpperBound(type);
 }
 if (type.getUpperBound() != null) {
  return type.getUpperBound();
 }
 // concrete type, e.g. java.lang.String, or a case we haven't considered
 return type;
}

代码示例来源:origin: konsoletyper/teavm-javac

/**
 * This relation answers the question: is impossible that
 * something of type `t' can be a subtype of `s'? This is
 * different from the question "is `t' not a subtype of `s'?"
 * when type variables are involved: Integer is not a subtype of T
 * where {@code <T extends Number>} but it is not true that Integer cannot
 * possibly be a subtype of T.
 */
public boolean notSoftSubtype(Type t, Type s) {
  if (t == s) return false;
  if (t.hasTag(TYPEVAR)) {
    TypeVar tv = (TypeVar) t;
    return !isCastable(tv.bound,
              relaxBound(s),
              noWarnings);
  }
  if (!s.hasTag(WILDCARD))
    s = cvarUpperBound(s);
  return !isSubtype(t, relaxBound(s));
}

代码示例来源:origin: konsoletyper/teavm-javac

/** Check that a type is within some bounds.
 *
 *  Used in TypeApply to verify that, e.g., X in {@code V<X>} is a valid
 *  type argument.
 *  @param a             The type that should be bounded by bs.
 *  @param bound         The bound.
 */
private boolean checkExtends(Type a, Type bound) {
   if (a.isUnbound()) {
     return true;
   } else if (!a.hasTag(WILDCARD)) {
     a = types.cvarUpperBound(a);
     return types.isSubtype(a, bound);
   } else if (a.isExtendsBound()) {
     return types.isCastable(bound, types.wildUpperBound(a), types.noWarnings);
   } else if (a.isSuperBound()) {
     return !types.notSoftSubtype(types.wildLowerBound(a), bound);
   }
   return true;
 }

代码示例来源:origin: konsoletyper/teavm-javac

@Override
      public Boolean visitWildcardType(WildcardType t, Type s) {
        if (s.isPartial())
          return containedBy(s, t);
        else {
//                    debugContainsType(t, s);
          return isSameWildcard(t, s)
            || t.type == s
            || isCaptureOf(s, t)
            || ((t.isExtendsBound() || isSubtypeNoCapture(wildLowerBound(t), cvarLowerBound(wildLowerBound(s)))) &&
              // TODO: JDK-8039214, cvarUpperBound call here is incorrect
              (t.isSuperBound() || isSubtypeNoCapture(cvarUpperBound(wildUpperBound(s)), wildUpperBound(t))));
        }
      }

代码示例来源:origin: konsoletyper/teavm-javac

Type exprType = types.cvarUpperBound(attribExpr(tree.expr, loopEnv));
attribStat(tree.var, loopEnv);
chk.checkNonVoid(tree.pos(), exprType);

代码示例来源:origin: konsoletyper/teavm-javac

ClassSymbol sym = (ClassSymbol) types.cvarUpperBound(tsym.type).tsym;

代码示例来源:origin: konsoletyper/teavm-javac

make_at(tree.expr.pos());
Type iteratorTarget = syms.objectType;
Type iterableType = types.asSuper(types.cvarUpperBound(tree.expr.type),
                 syms.iterableType.tsym);
if (iterableType.getTypeArguments().nonEmpty())
JCExpression vardefinit = make.App(make.Select(make.Ident(itvar), next));
if (tree.var.type.isPrimitive())
  vardefinit = make.TypeCast(types.cvarUpperBound(iteratorTarget), vardefinit);
else
  vardefinit = make.TypeCast(tree.var.type, vardefinit);

相关文章

Types类方法