Search in sources :

Example 36 with Type

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);
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 37 with Type

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();
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 38 with Type

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);
        }
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 39 with Type

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");
        }
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 40 with Type

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");
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Aggregations

Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)164 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)46 DeferredType (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredType)13 DiagnosticType (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticType)13 ArrayType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType)10 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)10 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)9 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)9 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)8 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)7 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)7 DiagnosticPosition (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition)7 JavacType (org.eclipse.ceylon.compiler.java.loader.mirror.JavacType)5 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)5 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)5 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)5 HashSet (java.util.HashSet)4 CompletionFailure (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)4 VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)4 FreeTypeListener (org.eclipse.ceylon.langtools.tools.javac.comp.Infer.FreeTypeListener)4