本文整理了Java中com.sun.tools.javac.code.Types.subst()
方法的一些代码示例,展示了Types.subst()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.subst()
方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:subst
[英]Substitute all occurrences of a type in from' with the corresponding type in
to' in 't'. Match lists from' and
to' from the right: If lists have different length, discard leading elements of the longer list.
[中]将“from”中出现的所有类型替换为“t”中“to”中的相应类型。右起的“from”和“to”匹配列表:如果列表长度不同,则丢弃较长列表的前导元素。
代码示例来源: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.jvnet.sorcerer/sorcerer-javac
@Override
public Type visitForAll(ForAll t, Void ignored) {
List<Type> tvars1 = substBounds(t.tvars, from, to);
Type qtype1 = subst(t.qtype);
if (tvars1 == t.tvars && qtype1 == t.qtype) {
return t;
} else if (tvars1 == t.tvars) {
return new ForAll(tvars1, qtype1);
} else {
return new ForAll(tvars1, Types.this.subst(qtype1, t.tvars, tvars1));
}
}
代码示例来源:origin: konsoletyper/teavm-javac
/**
* Replace all free variables in a given type with corresponding
* undet vars (used ahead of subtyping/compatibility checks to allow propagation
* of inference constraints).
*/
final Type asUndetVar(Type t) {
return types.subst(t, inferencevars, undetvars);
}
代码示例来源:origin: sc.fiji/javac
@Override
public Type visitForAll(ForAll t, Void ignored) {
List<Type> tvars1 = substBounds(t.tvars, from, to);
Type qtype1 = subst(t.qtype);
if (tvars1 == t.tvars && qtype1 == t.qtype) {
return t;
} else if (tvars1 == t.tvars) {
return new ForAll(tvars1, qtype1);
} else {
return new ForAll(tvars1, Types.this.subst(qtype1, t.tvars, tvars1));
}
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/**
* Replace all free variables in a given type with corresponding
* undet vars (used ahead of subtyping/compatibility checks to allow propagation
* of inference constraints).
*/
final Type asFree(Type t) {
return types.subst(t, inferencevars, undetvars);
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/**
* Replace all free variables in a given type with corresponding
* instantiated types - if one or more free variable has not been
* fully instantiated, it will still be available in the resulting type.
*/
Type asInstType(Type t) {
return types.subst(t, inferencevars, instTypes());
}
代码示例来源:origin: konsoletyper/teavm-javac
/**
* Replace all free variables in a given type with corresponding
* instantiated types - if one or more free variable has not been
* fully instantiated, it will still be available in the resulting type.
*/
Type asInstType(Type t) {
return types.subst(t, inferencevars, instTypes());
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
public TypeVar substBound(TypeVar t, List<Type> from, List<Type> to) {
Type bound1 = subst(t.bound, from, to);
if (bound1 == t.bound)
return t;
else
return new TypeVar(t.tsym, bound1);
}
// </editor-fold>
代码示例来源:origin: sc.fiji/javac
public TypeVar substBound(TypeVar t, List<Type> from, List<Type> to) {
Type bound1 = subst(t.bound, from, to);
if (bound1 == t.bound)
return t;
else
return new TypeVar(t.tsym, bound1, syms.botType);
}
// </editor-fold>
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
@Override
public Boolean visitForAll(ForAll t, Type s) {
if (s.tag != FORALL)
return false;
ForAll forAll = (ForAll)s;
return hasSameBounds(t, forAll)
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars));
}
代码示例来源:origin: sc.fiji/javac
/** Create new vector of type variables from list of variables
* changing all recursive bounds from old to new list.
*/
public List<Type> newInstances(List<Type> tvars) {
List<Type> tvars1 = Type.map(tvars, newInstanceFun);
for (List<Type> l = tvars1; l.nonEmpty(); l = l.tail) {
TypeVar tv = (TypeVar) l.head;
tv.bound = subst(tv.bound, tvars, tvars1);
}
return tvars1;
}
static private Mapping newInstanceFun = new Mapping("newInstanceFun") {
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** Create new vector of type variables from list of variables
* changing all recursive bounds from old to new list.
*/
public List<Type> newInstances(List<Type> tvars) {
List<Type> tvars1 = Type.map(tvars, newInstanceFun);
for (List<Type> l = tvars1; l.nonEmpty(); l = l.tail) {
TypeVar tv = (TypeVar) l.head;
tv.bound = subst(tv.bound, tvars, tvars1);
}
return tvars1;
}
private static final Mapping newInstanceFun = new Mapping("newInstanceFun") {
代码示例来源:origin: konsoletyper/teavm-javac
/** Create new vector of type variables from list of variables
* changing all recursive bounds from old to new list.
*/
public List<Type> newInstances(List<Type> tvars) {
List<Type> tvars1 = Type.map(tvars, newInstanceFun);
for (List<Type> l = tvars1; l.nonEmpty(); l = l.tail) {
TypeVar tv = (TypeVar) l.head;
tv.bound = subst(tv.bound, tvars, tvars1);
}
return tvars1;
}
private static final Mapping newInstanceFun = new Mapping("newInstanceFun") {
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
@Override
public Boolean visitForAll(ForAll t, Type s) {
if (s.tag != FORALL)
return false;
ForAll forAll = (ForAll)s;
return hasSameBounds(t, forAll)
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars));
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Create new vector of type variables from list of variables
* changing all recursive bounds from old to new list.
*/
public List<Type> newInstances(List<Type> tvars) {
List<Type> tvars1 = Type.map(tvars, newInstanceFun);
for (List<Type> l = tvars1; l.nonEmpty(); l = l.tail) {
TypeVar tv = (TypeVar) l.head;
tv.bound = subst(tv.bound, tvars, tvars1);
}
return tvars1;
}
static private Mapping newInstanceFun = new Mapping("newInstanceFun") {
代码示例来源:origin: sc.fiji/javac
@Override
public Boolean visitForAll(ForAll t, Type s) {
if (s.tag != FORALL)
return false;
ForAll forAll = (ForAll)s;
return hasSameBounds(t, forAll)
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars));
}
代码示例来源:origin: sc.fiji/javac
@Override
public Boolean visitForAll(ForAll t, Type s) {
if (s.tag != FORALL)
return false;
ForAll forAll = (ForAll)s;
return hasSameBounds(t, forAll)
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars));
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
@Override
public Boolean visitForAll(ForAll t, Type s) {
if (!s.hasTag(FORALL)) {
return false;
}
ForAll forAll = (ForAll)s;
return hasSameBounds(t, forAll)
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars));
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
@Override
public Boolean visitForAll(ForAll t, Type s) {
if (!s.hasTag(FORALL))
return strict ? false : visitMethodType(t.asMethodType(), s);
ForAll forAll = (ForAll)s;
return hasSameBounds(t, forAll)
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars));
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public Boolean visitForAll(ForAll t, Type s) {
if (!s.hasTag(FORALL))
return strict ? false : visitMethodType(t.asMethodType(), s);
ForAll forAll = (ForAll)s;
return hasSameBounds(t, forAll)
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars));
}
内容来源于网络,如有侵权,请联系作者删除!