Skip to content

Commit

Permalink
Fix move of method with private method call when classes in same CU (#…
Browse files Browse the repository at this point in the history
…1405)

* Fix move of method with private method call when classes in same CU

- fix MemberVisibilityAdjustor.thresholdTypeToMethod() so that when
  two classes are in same compilation unit but are separate, use
  a threshold of default (null) instead of private
- add new test to MoveInstanceMethodTests
- fixes #1300
  • Loading branch information
jjohnstn committed May 15, 2024
1 parent 9fa4117 commit 2289ee0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1272,7 +1272,15 @@ private ModifierKeyword thresholdTypeToMethod(final IType referencing, final IMe
}
final ICompilationUnit typeUnit= referencing.getCompilationUnit();
if (referencedUnit != null && referencedUnit.equals(typeUnit)) {
if (referenced.getDeclaringType().getDeclaringType() != null)
IType referencedType= referenced.getDeclaringType();
while (referencedType.getDeclaringType() != null) {
referencedType= referencedType.getDeclaringType();
}
IType referencingType= referencing;
while (referencingType.getDeclaringType() != null) {
referencingType= referencingType.getDeclaringType();
}
if (!referencedType.getFullyQualifiedName().equals(referencingType.getFullyQualifiedName()))
keyword= null;
else
keyword= ModifierKeyword.PRIVATE_KEYWORD;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class B {
public void f() {

}
}

class A {
B b;

public void m() {
n();
}

private void n() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class B {
public void f() {

}

public void m(A a) {
a.n();
}
}

class A {
B b;

void n() {

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -650,6 +650,12 @@ public void test69() throws Exception {
helper1(new String[] { "p1.A", "p2.B"}, "p1.A", 11, 17, 11, 23, FIELD, "b", true, true);
}

// Issue 1300
@Test
public void test70() throws Exception {
helper1(new String[] { "A" }, "A", 10, 17, 10, 18, FIELD, "b", true, true);
}

// Move mA1 to field fB, do not inline delegator
@Test
public void test3() throws Exception {
Expand Down

0 comments on commit 2289ee0

Please sign in to comment.