use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method visitTypeTest.
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);
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method visitForeachLoop.
public void visitForeachLoop(JCEnhancedForLoop tree) {
Env<AttrContext> loopEnv = env.dup(env.tree, env.info.dup(env.info.scope.dup()));
try {
// the Formal Parameter of a for-each loop is not in the scope when
// attributing the for-each expression; we mimick this by attributing
// the for-each expression first (against original scope).
Type exprType = types.cvarUpperBound(attribExpr(tree.expr, loopEnv));
attribStat(tree.var, loopEnv);
chk.checkNonVoid(tree.pos(), exprType);
// perhaps expr is an array?
Type elemtype = types.elemtype(exprType);
if (elemtype == null) {
// or perhaps expr implements Iterable<T>?
Type base = types.asSuper(exprType, syms.iterableType.tsym);
if (base == null) {
log.error(tree.expr.pos(), "foreach.not.applicable.to.type", exprType, diags.fragment("type.req.array.or.iterable"));
elemtype = types.createErrorType(exprType);
} else {
List<Type> iterableParams = base.allparams();
elemtype = iterableParams.isEmpty() ? syms.objectType : types.wildUpperBound(iterableParams.head);
}
}
chk.checkType(tree.expr.pos(), elemtype, tree.var.sym.type);
// before, we were not in loop!
loopEnv.tree = tree;
attribStat(tree.body, loopEnv);
result = null;
} finally {
loopEnv.info.scope.leave();
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method checkAutoCloseable.
void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) {
if (!resource.isErroneous() && types.asSuper(resource, syms.autoCloseableType.tsym) != null && !types.isSameType(resource, syms.autoCloseableType)) {
// Don't emit warning for AutoCloseable itself
Symbol close = syms.noSymbol;
Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log);
try {
close = rs.resolveQualifiedMethod(pos, env, resource, names.close, List.<Type>nil(), List.<Type>nil());
} finally {
log.popDiagnosticHandler(discardHandler);
}
if (close.kind == MTH && close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) && env.info.lint.isEnabled(LintCategory.TRY)) {
log.warning(LintCategory.TRY, pos, "try.resource.throws.interrupted.exc", resource);
}
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method checkLambdaCandidate.
private void checkLambdaCandidate(JCNewClass tree, ClassSymbol csym, Type clazztype) {
if (allowLambda && identifyLambdaCandidate && clazztype.hasTag(CLASS) && !pt().hasTag(NONE) && types.isFunctionalInterface(clazztype.tsym)) {
Symbol descriptor = types.findDescriptorSymbol(clazztype.tsym);
int count = 0;
boolean found = false;
for (Symbol sym : csym.members().getElements()) {
if ((sym.flags() & SYNTHETIC) != 0 || sym.isConstructor())
continue;
count++;
if (sym.kind != MTH || !sym.name.equals(descriptor.name))
continue;
Type mtype = types.memberType(clazztype, sym);
if (types.overrideEquivalent(mtype, types.memberType(clazztype, descriptor))) {
found = true;
}
}
if (found && count == 1) {
log.note(tree.def, "potential.lambda.found");
}
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method visitParens.
public void visitParens(JCParens tree) {
Type owntype = attribTree(tree.expr, env, resultInfo);
result = check(tree, owntype, pkind(), resultInfo);
Symbol sym = TreeInfo.symbol(tree);
if (sym != null && (sym.kind & (TYP | PCK)) != 0)
log.error(tree.pos(), "illegal.start.of.type");
}
Aggregations