Search in sources :

Example 1 with CaseClause

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.CaseClause in project ceylon by eclipse.

the class TreeUtil method hasUncheckedNulls.

private static boolean hasUncheckedNulls(Tree.Term term, boolean invoking) {
    if (term instanceof Tree.MemberOrTypeExpression) {
        Tree.MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) term;
        Declaration d = mte.getDeclaration();
        if (d instanceof TypedDeclaration) {
            TypedDeclaration td = (TypedDeclaration) d;
            return td.hasUncheckedNullType() && // because java method references can't be null
            (!(d instanceof Function) || invoking);
        } else {
            return false;
        }
    } else if (term instanceof Tree.QualifiedMemberOrTypeExpression) {
        Tree.QualifiedMemberOrTypeExpression qmte = (Tree.QualifiedMemberOrTypeExpression) term;
        return hasUncheckedNulls(qmte.getPrimary(), invoking);
    } else if (term instanceof Tree.InvocationExpression) {
        Tree.InvocationExpression ite = (Tree.InvocationExpression) term;
        return hasUncheckedNulls(ite.getPrimary(), true);
    } else if (term instanceof Tree.DefaultOp) {
        Tree.DefaultOp op = (Tree.DefaultOp) term;
        return hasUncheckedNulls(op.getRightTerm(), invoking);
    } else if (term instanceof Tree.Expression) {
        Tree.Expression e = (Tree.Expression) term;
        return hasUncheckedNulls(e.getTerm(), invoking);
    } else if (term instanceof Tree.LetExpression) {
        Tree.LetExpression e = (Tree.LetExpression) term;
        return hasUncheckedNulls(e.getLetClause().getExpression(), invoking);
    } else if (term instanceof Tree.IfExpression) {
        Tree.IfExpression e = (Tree.IfExpression) term;
        return hasUncheckedNulls(e.getIfClause().getExpression(), invoking) || hasUncheckedNulls(e.getElseClause().getExpression(), invoking);
    } else if (term instanceof Tree.SwitchExpression) {
        Tree.SwitchExpression e = (Tree.SwitchExpression) term;
        for (CaseClause clause : e.getSwitchCaseList().getCaseClauses()) {
            if (hasUncheckedNulls(clause.getExpression(), invoking)) {
                return true;
            }
        }
        if (e.getSwitchCaseList().getElseClause() != null) {
            return hasUncheckedNulls(e.getSwitchCaseList().getElseClause().getExpression(), invoking);
        }
        return false;
    } else {
        return false;
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) CaseClause(org.eclipse.ceylon.compiler.typechecker.tree.Tree.CaseClause) Function(org.eclipse.ceylon.model.typechecker.model.Function) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Aggregations

Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)1 CaseClause (org.eclipse.ceylon.compiler.typechecker.tree.Tree.CaseClause)1 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)1 Function (org.eclipse.ceylon.model.typechecker.model.Function)1 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)1