Search in sources :

Example 1 with Super

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

the class SelfReferenceVisitor method checkSelfReference.

private void checkSelfReference(Node that, Tree.Term term) {
    Tree.Term t = eliminateParensAndWidening(term);
    if (directlyInBody() && t instanceof Tree.Super) {
        that.addError("leaks 'super' reference: '" + typeDeclaration.getName() + "'");
    }
    if (mayNotLeakThis() && t instanceof Tree.This) {
        that.addError("leaks 'this' reference in initializer: '" + typeDeclaration.getName() + "'");
    }
    if (mayNotLeakOuter() && t instanceof Tree.Outer) {
        that.addError("leaks 'outer' reference in initializer: '" + typeDeclaration.getName() + "'");
    }
    if (typeDeclaration.isObjectClass() && mayNotLeakAnonymousClass() && t instanceof Tree.BaseMemberExpression) {
        Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) t;
        Declaration declaration = bme.getDeclaration();
        if (declaration instanceof TypedDeclaration) {
            TypedDeclaration td = (TypedDeclaration) declaration;
            if (td.getTypeDeclaration() == typeDeclaration) {
                that.addError("anonymous class leaks self reference in initializer: '" + typeDeclaration.getName() + "'");
            }
        }
    }
    if (typeDeclaration.isObjectClass() && mayNotLeakAnonymousClass() && t instanceof Tree.QualifiedMemberExpression) {
        Tree.QualifiedMemberExpression qme = (Tree.QualifiedMemberExpression) t;
        if (qme.getPrimary() instanceof Tree.Outer) {
            Declaration declaration = qme.getDeclaration();
            if (declaration instanceof TypedDeclaration) {
                TypedDeclaration td = (TypedDeclaration) declaration;
                if (td.getTypeDeclaration() == typeDeclaration) {
                    that.addError("anonymous class leaks self reference in initializer: '" + typeDeclaration.getName() + "'");
                }
            }
        }
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Super(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Super)

Aggregations

CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)1 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)1 Super (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Super)1 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)1 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)1 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)1