Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b450d7d

Browse files
author
zhourenjian
committed
Fixed bug that "AClass.this.someMethod()" invocations inside AClass is compiled to this.callbacks["AClass"].someMethod() which is wrong. Fixed now without "callbacks" segment.
1 parent bcc0d87 commit b450d7d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/net/sf/j2s/core/astvisitors/ASTScriptVisitor.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,9 +2011,25 @@ public boolean visit(SuperMethodInvocation node) {
20112011
public boolean visit(ThisExpression node) {
20122012
Name qualifier = node.getQualifier();
20132013
if (qualifier != null) {
2014-
buffer.append("this.callbacks[\"");
2015-
qualifier.accept(this);
2016-
buffer.append("\"]");
2014+
ASTNode xparent = node.getParent();
2015+
while (xparent != null
2016+
&& !(xparent instanceof AbstractTypeDeclaration)
2017+
&& !(xparent instanceof AnonymousClassDeclaration)) {
2018+
xparent = xparent.getParent();
2019+
}
2020+
if (xparent == null
2021+
|| xparent.getParent() == null // CompilationUnit
2022+
|| xparent.getParent().getParent() == null) {
2023+
buffer.append("this");
2024+
} else {
2025+
/*
2026+
* only need callbacks wrapper in inner classes
2027+
* or anonymous classes.
2028+
*/
2029+
buffer.append("this.callbacks[\"");
2030+
qualifier.accept(this);
2031+
buffer.append("\"]");
2032+
}
20172033
} else {
20182034
buffer.append("this");
20192035
}

0 commit comments

Comments
 (0)