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

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

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

Types.getBounds介绍

[英]Return list of bounds of the given type variable.
[中]返回给定类型变量的边界列表。

代码示例

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

private boolean checkBounds(Unifier unifier, Inliner inliner, Warner warner)
  throws CouldNotResolveImportException {
 Types types = unifier.types();
 ListBuffer<Type> varsBuffer = new ListBuffer<>();
 ListBuffer<Type> bindingsBuffer = new ListBuffer<>();
 for (UTypeVar typeVar : typeVariables(unifier.getContext())) {
  varsBuffer.add(inliner.inlineAsVar(typeVar));
  bindingsBuffer.add(unifier.getBinding(typeVar.key()).type());
 }
 List<Type> vars = varsBuffer.toList();
 List<Type> bindings = bindingsBuffer.toList();
 for (UTypeVar typeVar : typeVariables(unifier.getContext())) {
  List<Type> bounds = types.getBounds(inliner.inlineAsVar(typeVar));
  bounds = types.subst(bounds, vars, bindings);
  if (!types.isSubtypeUnchecked(unifier.getBinding(typeVar.key()).type(), bounds, warner)) {
   logger.log(
     FINE,
     String.format("%s is not a subtype of %s", inliner.getBinding(typeVar.key()), bounds));
   return false;
  }
 }
 return true;
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

public UndetVar(TypeVar origin, Types types) {
  super(UNDETVAR, origin);
  bounds = new EnumMap<InferenceBound, List<Type>>(InferenceBound.class);
  List<Type> declaredBounds = types.getBounds(origin);
  declaredCount = declaredBounds.length();
  bounds.put(InferenceBound.UPPER, declaredBounds);
  bounds.put(InferenceBound.LOWER, List.<Type>nil());
  bounds.put(InferenceBound.EQ, List.<Type>nil());
}

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

public UndetVar(TypeVar origin, Types types) {
  super(UNDETVAR, origin);
  bounds = new EnumMap<InferenceBound, List<Type>>(InferenceBound.class);
  List<Type> declaredBounds = types.getBounds(origin);
  declaredCount = declaredBounds.length();
  bounds.put(InferenceBound.UPPER, declaredBounds);
  bounds.put(InferenceBound.LOWER, List.<Type>nil());
  bounds.put(InferenceBound.EQ, List.<Type>nil());
}

代码示例来源:origin: sc.fiji/javac

private void checkNonCyclic1(DiagnosticPosition pos, Type t, Set<TypeVar> seen) {
  final TypeVar tv;
  if (seen.contains(t)) {
    tv = (TypeVar)t;
    tv.bound = new ErrorType();
    log.error(pos, "cyclic.inheritance", t);
  } else if (t.tag == TYPEVAR) {
    tv = (TypeVar)t;
    seen.add(tv);
    for (Type b : types.getBounds(tv))
      checkNonCyclic1(pos, b, seen);
  }
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

private void checkNonCyclic1(DiagnosticPosition pos, Type t, Set<TypeVar> seen) {
  final TypeVar tv;
  if (seen.contains(t)) {
    tv = (TypeVar)t;
    tv.bound = new ErrorType();
    log.error(pos, "cyclic.inheritance", t);
  } else if (t.tag == TYPEVAR) {
    tv = (TypeVar)t;
    seen.add(tv);
    for (Type b : types.getBounds(tv))
      checkNonCyclic1(pos, b, seen);
  }
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

/** Create a type parameter tree from its name and type.
 */
public JCTypeParameter TypeParam(Name name, TypeVar tvar) {
  return (JCTypeParameter)
    TypeParameter(name, Types(types.getBounds(tvar))).setPos(pos).setType(tvar);
}

代码示例来源:origin: sc.fiji/javac

/** Create a type parameter tree from its name and type.
 */
public JCTypeParameter TypeParam(Name name, TypeVar tvar) {
  return (JCTypeParameter)
    TypeParameter(name, Types(types.getBounds(tvar))).setPos(pos).setType(tvar);
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

/** Create a type parameter tree from its name and type.
 */
public JCTypeParameter TypeParam(Name name, TypeVar tvar) {
  return (JCTypeParameter)
    TypeParameter(name, Types(types.getBounds(tvar))).setPos(pos).setType(tvar);
}

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

/**
 * Get the bounds of a type variable as listed in the "extends" clause.
 */
private static List<Type> getBounds(TypeVar v, DocEnv env) {
  final Type upperBound = v.getUpperBound();
  Name boundname = upperBound.tsym.getQualifiedName();
  if (boundname == boundname.table.names.java_lang_Object
    && !upperBound.isAnnotated()) {
    return List.nil();
  } else {
    return env.types.getBounds(v);
  }
}

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

/** Create a type parameter tree from its name and type.
 */
public JCTypeParameter TypeParam(Name name, TypeVar tvar) {
  return (JCTypeParameter)
    TypeParameter(name, Types(types.getBounds(tvar))).setPos(pos).setType(tvar);
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

/** check that type parameters are within their bounds.
   */
  private void checkWithinBounds(List<Type> tvars,
                  List<Type> arguments,
                  Warner warn)
    throws NoInstanceException {
  for (List<Type> tvs = tvars, args = arguments;
     tvs.nonEmpty();
     tvs = tvs.tail, args = args.tail) {
      if (args.head instanceof UndetVar) continue;
      List<Type> bounds = types.subst(types.getBounds((TypeVar)tvs.head), tvars, arguments);
    if (!types.isSubtypeUnchecked(args.head, bounds, warn))
    throw unambiguousNoInstanceException
      .setMessage("inferred.do.not.conform.to.bounds",
        arguments, tvars);
  }
  }
}

代码示例来源:origin: sc.fiji/javac

/** check that type parameters are within their bounds.
   */
  private void checkWithinBounds(List<Type> tvars,
                  List<Type> arguments,
                  Warner warn)
    throws InvalidInstanceException {
    for (List<Type> tvs = tvars, args = arguments;
       tvs.nonEmpty();
       tvs = tvs.tail, args = args.tail) {
      if (args.head instanceof UndetVar) continue;
      List<Type> bounds = types.subst(types.getBounds((TypeVar)tvs.head), tvars, arguments);
      if (!types.isSubtypeUnchecked(args.head, bounds, warn))
        throw invalidInstanceException
          .setMessage("inferred.do.not.conform.to.bounds",
                args.head, bounds);
    }
  }
}

代码示例来源:origin: sc.fiji/javac

void assembleParamsSig(List<Type> typarams) {
  sigbuf.appendByte('<');
  for (List<Type> ts = typarams; ts.nonEmpty(); ts = ts.tail) {
    TypeVar tvar = (TypeVar)ts.head;
    sigbuf.appendName(tvar.tsym.name);
    List<Type> bounds = types.getBounds(tvar);
    if ((bounds.head.tsym.flags() & INTERFACE) != 0) {
      sigbuf.appendByte(':');
    }
    for (List<Type> l = bounds; l.nonEmpty(); l = l.tail) {
      sigbuf.appendByte(':');
      assembleSig(l.head);
    }
  }
  sigbuf.appendByte('>');
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

private boolean isSubClass(Type t, final List<Type> ts) {
  t = t.baseType();
  if (t.tag == TYPEVAR) {
    List<Type> bounds = types.getBounds((TypeVar)t);
    for (Type s : ts) {
      if (!types.isSameType(t, s.baseType())) {
        for (Type bound : bounds) {
          if (!isSubClass(bound, List.of(s.baseType())))
            return false;
        }
      }
    }
  } else {
    for (Type s : ts) {
      if (!t.tsym.isSubClass(s.baseType().tsym, types))
        return false;
    }
  }
  return true;
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

void assembleParamsSig(List<Type> typarams) {
  sigbuf.appendByte('<');
  for (List<Type> ts = typarams; ts.nonEmpty(); ts = ts.tail) {
    TypeVar tvar = (TypeVar)ts.head;
    sigbuf.appendName(tvar.tsym.name);
    List<Type> bounds = types.getBounds(tvar);
    if ((bounds.head.tsym.flags() & INTERFACE) != 0) {
      sigbuf.appendByte(':');
    }
    for (List<Type> l = bounds; l.nonEmpty(); l = l.tail) {
      sigbuf.appendByte(':');
      assembleSig(l.head);
    }
  }
  sigbuf.appendByte('>');
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

public void assembleParamsSig(List<Type> typarams) {
  append('<');
  for (List<Type> ts = typarams; ts.nonEmpty(); ts = ts.tail) {
    Type.TypeVar tvar = (Type.TypeVar) ts.head;
    append(tvar.tsym.name);
    List<Type> bounds = types.getBounds(tvar);
    if ((bounds.head.tsym.flags() & INTERFACE) != 0) {
      append(':');
    }
    for (List<Type> l = bounds; l.nonEmpty(); l = l.tail) {
      append(':');
      assembleSig(l.head);
    }
  }
  append('>');
}

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

public void assembleParamsSig(List<Type> typarams) {
  append('<');
  for (List<Type> ts = typarams; ts.nonEmpty(); ts = ts.tail) {
    Type.TypeVar tvar = (Type.TypeVar) ts.head;
    append(tvar.tsym.name);
    List<Type> bounds = types.getBounds(tvar);
    if ((bounds.head.tsym.flags() & INTERFACE) != 0) {
      append(':');
    }
    for (List<Type> l = bounds; l.nonEmpty(); l = l.tail) {
      append(':');
      assembleSig(l.head);
    }
  }
  append('>');
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

private void checkNonCyclic1(DiagnosticPosition pos, Type t, List<TypeVar> seen) {
  final TypeVar tv;
  if  (t.hasTag(TYPEVAR) && (t.tsym.flags() & UNATTRIBUTED) != 0)
    return;
  if (seen.contains(t)) {
    tv = (TypeVar)t.unannotatedType();
    tv.bound = types.createErrorType(t);
    log.error(pos, "cyclic.inheritance", t);
  } else if (t.hasTag(TYPEVAR)) {
    tv = (TypeVar)t.unannotatedType();
    seen = seen.prepend(tv);
    for (Type b : types.getBounds(tv))
      checkNonCyclic1(pos, b, seen);
  }
}

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

private void checkNonCyclic1(DiagnosticPosition pos, Type t, List<TypeVar> seen) {
  final TypeVar tv;
  if  (t.hasTag(TYPEVAR) && (t.tsym.flags() & UNATTRIBUTED) != 0)
    return;
  if (seen.contains(t)) {
    tv = (TypeVar)t.unannotatedType();
    tv.bound = types.createErrorType(t);
    log.error(pos, "cyclic.inheritance", t);
  } else if (t.hasTag(TYPEVAR)) {
    tv = (TypeVar)t.unannotatedType();
    seen = seen.prepend(tv);
    for (Type b : types.getBounds(tv))
      checkNonCyclic1(pos, b, seen);
  }
}

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

private boolean checkBounds(Unifier unifier, Inliner inliner, Warner warner)
  throws CouldNotResolveImportException {
 Types types = unifier.types();
 ListBuffer<Type> varsBuffer = new ListBuffer<>();
 ListBuffer<Type> bindingsBuffer = new ListBuffer<>();
 for (UTypeVar typeVar : typeVariables(unifier.getContext())) {
  varsBuffer.add(inliner.inlineAsVar(typeVar));
  bindingsBuffer.add(unifier.getBinding(typeVar.key()).type());
 }
 List<Type> vars = varsBuffer.toList();
 List<Type> bindings = bindingsBuffer.toList();
 for (UTypeVar typeVar : typeVariables(unifier.getContext())) {
  List<Type> bounds = types.getBounds(inliner.inlineAsVar(typeVar));
  bounds = types.subst(bounds, vars, bindings);
  if (!types.isSubtypeUnchecked(unifier.getBinding(typeVar.key()).type(), bounds, warner)) {
   logger.log(
     FINE,
     String.format("%s is not a subtype of %s", inliner.getBinding(typeVar.key()), bounds));
   return false;
  }
 }
 return true;
}

相关文章

Types类方法