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() + "'");
}
}
}
}
}
Aggregations