Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
import org.eclipse.jdt.core.dom.ThisExpression;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclarationStatement;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.manipulation.ImportReferencesCollector;

Expand Down Expand Up @@ -175,6 +176,7 @@ private IMethodBinding getBinding() {

private class UpdateCollector extends ASTVisitor {
private int fTypeCounter;
private int fLocalTypeCounter;
@Override
public boolean visit(TypeDeclaration node) {
return visitType(node);
Expand All @@ -192,6 +194,15 @@ public void endVisit(EnumDeclaration node) {
fTypeCounter--;
}
@Override
public boolean visit(TypeDeclarationStatement node) {
fLocalTypeCounter++;
return true;
}
@Override
public void endVisit(TypeDeclarationStatement node) {
fLocalTypeCounter--;
}
@Override
public boolean visit(AnnotationTypeDeclaration node) {
return visitType(node);
}
Expand Down Expand Up @@ -234,10 +245,21 @@ public boolean visit(MethodDeclaration node) {
}
@Override
public boolean visit(MethodInvocation node) {
if (fTypeCounter == 0) {
Expression receiver= node.getExpression();
if (receiver == null && !isStaticallyImported(node.getName())) {
Expression receiver= node.getExpression();
if (receiver == null && !isStaticallyImported(node.getName())) {
if (fTypeCounter == 0) {
fImplicitReceivers.add(node);
} else if (fLocalTypeCounter > 0) {
IMethodBinding methodBinding= node.resolveMethodBinding();
if (methodBinding != null) {
ITypeBinding typeBinding= methodBinding.getDeclaringClass();
while (typeBinding != null && typeBinding.isMember()) {
typeBinding= typeBinding.getDeclaringClass();
}
if (typeBinding != null && !typeBinding.isLocal()) {
fImplicitReceivers.add(node);
}
}
}
}
return true;
Expand Down Expand Up @@ -265,12 +287,10 @@ public boolean visit(SuperConstructorInvocation node) {
}
@Override
public boolean visit(ClassInstanceCreation node) {
if (fTypeCounter == 0) {
Expression receiver= node.getExpression();
if (receiver == null) {
if (node.resolveTypeBinding().isMember())
fImplicitReceivers.add(node);
}
Expression receiver= node.getExpression();
if (receiver == null) {
if (node.resolveTypeBinding().isMember())
fImplicitReceivers.add(node);
}
return true;
}
Expand Down Expand Up @@ -303,7 +323,17 @@ public boolean visit(SimpleName node) {
StructuralPropertyDescriptor location= node.getLocationInParent();
if (location != SingleVariableDeclaration.NAME_PROPERTY
&& location != VariableDeclarationFragment.NAME_PROPERTY) {
fImplicitReceivers.add(node);
if (fTypeCounter == 0) {
fImplicitReceivers.add(node);
} else if (fLocalTypeCounter > 0) {
ITypeBinding typeBinding= vb.getDeclaringClass();
while (typeBinding != null && typeBinding.isMember()) {
typeBinding= typeBinding.getDeclaringClass();
}
if (typeBinding != null && !typeBinding.isLocal()) {
fImplicitReceivers.add(node);
}
}
}
}
} else if (!vb.isField()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package bugs_in;

public class Test_issue_3069 {

int x;

public static void main(String[] args) {
Test_issue_3069 obj= new Test_issue_3069();
int result= obj.f();
}

int helper() {
return 7;
}

int /*]*/ f()/*[*/ {
class H {
int y;
int j() {
return helper();
}
class K {
int g() {
return helper();
}
int h() {
return g() + x + y;
}
}
}
return H.class.getSimpleName().length() + helper();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package bugs_in;

public class Test_issue_3069 {

int x;

public static void main(String[] args) {
Test_issue_3069 obj= new Test_issue_3069();
class H {
int y;
int j() {
return obj.helper();
}
class K {
int g() {
return obj.helper();
}
int h() {
return g() + obj.x + y;
}
}
}
int result= H.class.getSimpleName().length() + obj.helper();
}

int helper() {
return 7;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ public void test_issue_2376() throws Exception {
performBugTest();
}

@Test
public void test_issue_3069() throws Exception {
performBugTest();
}

@Test
public void test_issue_3070_1() throws Exception {
performBugTest();
Expand Down
Loading