本文整理了Java中com.sun.tools.javac.code.Types.isReifiable()
方法的一些代码示例,展示了Types.isReifiable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.isReifiable()
方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:isReifiable
暂无
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Check that type is a reifiable class, interface or array type.
* @param pos Position to be used for error reporting.
* @param t The type to be checked.
*/
Type checkReifiableReferenceType(DiagnosticPosition pos, Type t) {
if (t.tag != CLASS && t.tag != ARRAY && t.tag != ERROR) {
return typeTagError(pos,
JCDiagnostic.fragment("type.req.class.array"),
t);
} else if (!types.isReifiable(t)) {
log.error(pos, "illegal.generic.type.for.instof");
return syms.errType;
} else {
return t;
}
}
代码示例来源:origin: sc.fiji/javac
/** Check that type is a reifiable class, interface or array type.
* @param pos Position to be used for error reporting.
* @param t The type to be checked.
*/
Type checkReifiableReferenceType(DiagnosticPosition pos, Type t) {
if (t.tag != CLASS && t.tag != ARRAY && t.tag != ERROR) {
return typeTagError(pos,
JCDiagnostic.fragment("type.req.class.array"),
t);
} else if (!types.isReifiable(t)) {
log.error(pos, "illegal.generic.type.for.instof");
return syms.errType;
} else {
return t;
}
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
private void checkUnsafeVarargsConversion(Type t, Type s, Warner warn) {
if (!t.hasTag(ARRAY) || isReifiable(t)) {
return;
}
t = t.unannotatedType();
s = s.unannotatedType();
ArrayType from = (ArrayType)t;
boolean shouldWarn = false;
switch (s.getTag()) {
case ARRAY:
ArrayType to = (ArrayType)s;
shouldWarn = from.isVarargs() &&
!to.isVarargs() &&
!isReifiable(from);
break;
case CLASS:
shouldWarn = from.isVarargs();
break;
}
if (shouldWarn) {
warn.warn(LintCategory.VARARGS);
}
}
代码示例来源:origin: konsoletyper/teavm-javac
private void checkUnsafeVarargsConversion(Type t, Type s, Warner warn) {
if (!t.hasTag(ARRAY) || isReifiable(t)) {
return;
}
t = t.unannotatedType();
s = s.unannotatedType();
ArrayType from = (ArrayType)t;
boolean shouldWarn = false;
switch (s.getTag()) {
case ARRAY:
ArrayType to = (ArrayType)s;
shouldWarn = from.isVarargs() &&
!to.isVarargs() &&
!isReifiable(from);
break;
case CLASS:
shouldWarn = from.isVarargs();
break;
}
if (shouldWarn) {
warn.warn(LintCategory.VARARGS);
}
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
@Override
public void warn(LintCategory lint) {
boolean warned = this.warned;
super.warn(lint);
if (warned) return; // suppress redundant diagnostics
switch (lint) {
case UNCHECKED:
Check.this.warnUnchecked(pos(), "prob.found.req", diags.fragment(uncheckedKey), found, expected);
break;
case VARARGS:
if (method != null &&
method.attribute(syms.trustMeType.tsym) != null &&
isTrustMeAllowedOnMethod(method) &&
!types.isReifiable(method.type.getParameterTypes().last())) {
Check.this.warnUnsafeVararg(pos(), "varargs.unsafe.use.varargs.param", method.params.last());
}
break;
default:
throw new AssertionError("Unexpected lint: " + lint);
}
}
}
代码示例来源:origin: konsoletyper/teavm-javac
@Override
public void warn(LintCategory lint) {
boolean warned = this.warned;
super.warn(lint);
if (warned) return; // suppress redundant diagnostics
switch (lint) {
case UNCHECKED:
Check.this.warnUnchecked(pos(), "prob.found.req", diags.fragment(uncheckedKey), found, expected);
break;
case VARARGS:
if (method != null &&
method.attribute(syms.trustMeType.tsym) != null &&
isTrustMeAllowedOnMethod(method) &&
!types.isReifiable(method.type.getParameterTypes().last())) {
Check.this.warnUnsafeVararg(pos(), "varargs.unsafe.use.varargs.param", method.params.last());
}
break;
default:
throw new AssertionError("Unexpected lint: " + lint);
}
}
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** Check that type is a valid qualifier for a constructor reference expression
*/
Type checkConstructorRefType(DiagnosticPosition pos, Type t) {
t = checkClassOrArrayType(pos, t);
if (t.hasTag(CLASS)) {
if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) {
log.error(pos, "abstract.cant.be.instantiated", t.tsym);
t = types.createErrorType(t);
} else if ((t.tsym.flags() & ENUM) != 0) {
log.error(pos, "enum.cant.be.instantiated");
t = types.createErrorType(t);
} else {
t = checkClassType(pos, t, true);
}
} else if (t.hasTag(ARRAY)) {
if (!types.isReifiable(((ArrayType)t).elemtype)) {
log.error(pos, "generic.array.creation");
t = types.createErrorType(t);
}
}
return t;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/**
* Is t an unchecked subtype of s?
*/
public boolean isSubtypeUnchecked(Type t, Type s, Warner warn) {
if (t.tag == ARRAY && s.tag == ARRAY) {
return (((ArrayType)t).elemtype.tag <= lastBaseTag)
? isSameType(elemtype(t), elemtype(s))
: isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
} else if (isSubtype(t, s)) {
return true;
} else if (!s.isRaw()) {
Type t2 = asSuper(t, s.tsym);
if (t2 != null && t2.isRaw()) {
if (isReifiable(s))
warn.silentUnchecked();
else
warn.warnUnchecked();
return true;
}
}
return false;
}
代码示例来源:origin: konsoletyper/teavm-javac
/** Check that type is a valid qualifier for a constructor reference expression
*/
Type checkConstructorRefType(DiagnosticPosition pos, Type t) {
t = checkClassOrArrayType(pos, t);
if (t.hasTag(CLASS)) {
if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) {
log.error(pos, "abstract.cant.be.instantiated", t.tsym);
t = types.createErrorType(t);
} else if ((t.tsym.flags() & ENUM) != 0) {
log.error(pos, "enum.cant.be.instantiated");
t = types.createErrorType(t);
} else {
t = checkClassType(pos, t, true);
}
} else if (t.hasTag(ARRAY)) {
if (!types.isReifiable(((ArrayType)t).elemtype)) {
log.error(pos, "generic.array.creation");
t = types.createErrorType(t);
}
}
return t;
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
public void visitTypeTest(JCInstanceOf tree) {
Type exprtype = chk.checkNullOrRefType(
tree.expr.pos(), attribExpr(tree.expr, env));
Type clazztype = attribType(tree.clazz, env);
if (!clazztype.hasTag(TYPEVAR)) {
clazztype = chk.checkClassOrArrayType(tree.clazz.pos(), clazztype);
}
if (!clazztype.isErroneous() && !types.isReifiable(clazztype)) {
log.error(tree.clazz.pos(), "illegal.generic.type.for.instof");
clazztype = types.createErrorType(clazztype);
}
chk.validate(tree.clazz, env, false);
chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
result = check(tree, syms.booleanType, VAL, resultInfo);
}
代码示例来源:origin: konsoletyper/teavm-javac
public void visitTypeTest(JCInstanceOf tree) {
Type exprtype = chk.checkNullOrRefType(
tree.expr.pos(), attribExpr(tree.expr, env));
Type clazztype = attribType(tree.clazz, env);
if (!clazztype.hasTag(TYPEVAR)) {
clazztype = chk.checkClassOrArrayType(tree.clazz.pos(), clazztype);
}
if (!clazztype.isErroneous() && !types.isReifiable(clazztype)) {
log.error(tree.clazz.pos(), "illegal.generic.type.for.instof");
clazztype = types.createErrorType(clazztype);
}
chk.validate(tree.clazz, env, false);
chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
result = check(tree, syms.booleanType, VAL, resultInfo);
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
owntype = new ArrayType(elemtype, syms.arrayClass);
if (!types.isReifiable(elemtype))
log.error(tree.pos(), "generic.array.creation");
result = check(tree, owntype, VAL, pkind, pt);
代码示例来源:origin: sc.fiji/javac
owntype = new ArrayType(elemtype, syms.arrayClass);
if (!types.isReifiable(elemtype))
log.error(tree.pos(), "generic.array.creation");
result = check(tree, owntype, VAL, pkind, pt);
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
private boolean sideCastFinal(Type from, Type to, Warner warn) {
// We are casting from type $from$ to type $to$, which are
// unrelated types one of which is final and the other of
// which is an interface. This method
// tries to reject a cast by transferring type parameters
// from the final class to the interface.
boolean reverse = false;
Type target = to;
if ((to.tsym.flags() & INTERFACE) == 0) {
assert (from.tsym.flags() & INTERFACE) != 0;
reverse = true;
to = from;
from = target;
}
assert (from.tsym.flags() & FINAL) != 0;
Type t1 = asSuper(from, to.tsym);
if (t1 == null) return false;
Type t2 = to;
if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments()))
return false;
if (!source.allowCovariantReturns())
// reject if there is a common method signature with
// incompatible return types.
chk.checkCompatibleAbstracts(warn.pos(), from, to);
if (!isReifiable(target) &&
(reverse ? giveWarning(t2, t1) : giveWarning(t1, t2)))
warn.warnUnchecked();
return true;
}
代码示例来源:origin: sc.fiji/javac
private boolean sideCastFinal(Type from, Type to, Warner warn) {
// We are casting from type $from$ to type $to$, which are
// unrelated types one of which is final and the other of
// which is an interface. This method
// tries to reject a cast by transferring type parameters
// from the final class to the interface.
boolean reverse = false;
Type target = to;
if ((to.tsym.flags() & INTERFACE) == 0) {
assert (from.tsym.flags() & INTERFACE) != 0;
reverse = true;
to = from;
from = target;
}
assert (from.tsym.flags() & FINAL) != 0;
Type t1 = asSuper(from, to.tsym);
if (t1 == null) return false;
Type t2 = to;
if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments()))
return false;
if (!source.allowCovariantReturns())
// reject if there is a common method signature with
// incompatible return types.
chk.checkCompatibleAbstracts(warn.pos(), from, to);
if (!isReifiable(target) &&
(reverse ? giveWarning(t2, t1) : giveWarning(t1, t2)))
warn.warnUnchecked();
return true;
}
代码示例来源:origin: sc.fiji/javac
/**
* Is t an unchecked subtype of s?
*/
public boolean isSubtypeUnchecked(Type t, Type s, Warner warn) {
if (t.tag == ARRAY && s.tag == ARRAY) {
return (((ArrayType)t).elemtype.tag <= lastBaseTag)
? isSameType(elemtype(t), elemtype(s))
: isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
} else if (isSubtype(t, s)) {
return true;
}
else if (t.tag == TYPEVAR) {
return isSubtypeUnchecked(t.getUpperBound(), s, warn);
}
else if (!s.isRaw()) {
Type t2 = asSuper(t, s.tsym);
if (t2 != null && t2.isRaw()) {
if (isReifiable(s))
warn.silentUnchecked();
else
warn.warnUnchecked();
return true;
}
}
return false;
}
代码示例来源:origin: konsoletyper/teavm-javac
private boolean sideCastFinal(Type from, Type to, Warner warn) {
// We are casting from type $from$ to type $to$, which are
// unrelated types one of which is final and the other of
// which is an interface. This method
// tries to reject a cast by transferring type parameters
// from the final class to the interface.
boolean reverse = false;
Type target = to;
if ((to.tsym.flags() & INTERFACE) == 0) {
Assert.check((from.tsym.flags() & INTERFACE) != 0);
reverse = true;
to = from;
from = target;
}
Assert.check((from.tsym.flags() & FINAL) != 0);
Type t1 = asSuper(from, to.tsym);
if (t1 == null) return false;
Type t2 = to;
if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments()))
return false;
if (!allowCovariantReturns)
// reject if there is a common method signature with
// incompatible return types.
chk.checkCompatibleAbstracts(warn.pos(), from, to);
if (!isReifiable(target) &&
(reverse ? giveWarning(t2, t1) : giveWarning(t1, t2)))
warn.warn(LintCategory.UNCHECKED);
return true;
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
private boolean sideCastFinal(Type from, Type to, Warner warn) {
// We are casting from type $from$ to type $to$, which are
// unrelated types one of which is final and the other of
// which is an interface. This method
// tries to reject a cast by transferring type parameters
// from the final class to the interface.
boolean reverse = false;
Type target = to;
if ((to.tsym.flags() & INTERFACE) == 0) {
Assert.check((from.tsym.flags() & INTERFACE) != 0);
reverse = true;
to = from;
from = target;
}
Assert.check((from.tsym.flags() & FINAL) != 0);
Type t1 = asSuper(from, to.tsym);
if (t1 == null) return false;
Type t2 = to;
if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments()))
return false;
if (!allowCovariantReturns)
// reject if there is a common method signature with
// incompatible return types.
chk.checkCompatibleAbstracts(warn.pos(), from, to);
if (!isReifiable(target) &&
(reverse ? giveWarning(t2, t1) : giveWarning(t1, t2)))
warn.warn(LintCategory.UNCHECKED);
return true;
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
private boolean isSubtypeUncheckedInternal(Type t, Type s, Warner warn) {
if (t.hasTag(ARRAY) && s.hasTag(ARRAY)) {
t = t.unannotatedType();
s = s.unannotatedType();
if (((ArrayType)t).elemtype.isPrimitive()) {
return isSameType(elemtype(t), elemtype(s));
} else {
return isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
}
} else if (isSubtype(t, s)) {
return true;
} else if (t.hasTag(TYPEVAR)) {
return isSubtypeUnchecked(t.getUpperBound(), s, warn);
} else if (!s.isRaw()) {
Type t2 = asSuper(t, s.tsym);
if (t2 != null && t2.isRaw()) {
if (isReifiable(s)) {
warn.silentWarn(LintCategory.UNCHECKED);
} else {
warn.warn(LintCategory.UNCHECKED);
}
return true;
}
}
return false;
}
代码示例来源:origin: konsoletyper/teavm-javac
private boolean isSubtypeUncheckedInternal(Type t, Type s, Warner warn) {
if (t.hasTag(ARRAY) && s.hasTag(ARRAY)) {
t = t.unannotatedType();
s = s.unannotatedType();
if (((ArrayType)t).elemtype.isPrimitive()) {
return isSameType(elemtype(t), elemtype(s));
} else {
return isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
}
} else if (isSubtype(t, s)) {
return true;
} else if (t.hasTag(TYPEVAR)) {
return isSubtypeUnchecked(t.getUpperBound(), s, warn);
} else if (!s.isRaw()) {
Type t2 = asSuper(t, s.tsym);
if (t2 != null && t2.isRaw()) {
if (isReifiable(s)) {
warn.silentWarn(LintCategory.UNCHECKED);
} else {
warn.warn(LintCategory.UNCHECKED);
}
return true;
}
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!