EA-65822 - assert: EncapsulateFieldsProcessor.checkExistingMethods

(cherry picked from commit ba6d1cbd27710de60a1d918ff478fe3094f94012)
This commit is contained in:
Anna Kozlova
2015-03-11 20:36:27 +01:00
parent 50043d2bd9
commit a439f0184a
4 changed files with 56 additions and 11 deletions
@@ -219,18 +219,19 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
if (existing != null) {
for (PsiReference reference : ReferencesSearch.search(existing)) {
final PsiElement place = reference.getElement();
LOG.assertTrue(place instanceof PsiReferenceExpression);
final PsiExpression qualifierExpression = ((PsiReferenceExpression)place).getQualifierExpression();
final PsiClass inheritor;
if (qualifierExpression == null) {
inheritor = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
} else {
inheritor = PsiUtil.resolveClassInType(qualifierExpression.getType());
}
if (place instanceof PsiReferenceExpression) {
final PsiExpression qualifierExpression = ((PsiReferenceExpression)place).getQualifierExpression();
final PsiClass inheritor;
if (qualifierExpression == null) {
inheritor = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
} else {
inheritor = PsiUtil.resolveClassInType(qualifierExpression.getType());
}
if (InheritanceUtil.isInheritorOrSelf(inheritor, myClass, true)) {
conflicts.putValue(existing, "There is already a " + RefactoringUIUtil.getDescription(existing, true) + " which would be hidden by generated " + (isGetter ? "getter" : "setter"));
break;
if (InheritanceUtil.isInheritorOrSelf(inheritor, myClass, true)) {
conflicts.putValue(existing, "There is already a " + RefactoringUIUtil.getDescription(existing, true) + " which would be hidden by generated " + (isGetter ? "getter" : "setter"));
break;
}
}
}
}
@@ -0,0 +1,24 @@
class B {
public int getI() {
return 0;
}
static class A {
private int i = 0;
/**
* {@link B#getI()}
*/
void f() {}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
}
}
@@ -0,0 +1,16 @@
class B {
public int getI() {
return 0;
}
static class A {
private int i = 0;
/**
* {@link B#getI()}
*/
void f() {}
}
}
@@ -63,6 +63,10 @@ public class EncapsulateFieldsTest extends MultiFileTestCase{
public void testJavadocRefs() throws Exception {
doTest("i", "A", null);
}
public void testJavadocRefs1() throws Exception {
doTest("i", "B.A", null);
}
public void testHideOuterclassMethod() throws Exception {
doTest("i", "A.B", "There is already a method <b><code>A.getI()</code></b> which would be hidden by generated getter");