inline parameter: check inner/local classes (IDEA-40703)

This commit is contained in:
anna
2010-02-11 17:56:29 +03:00
parent b26f153038
commit 20b01ce79e
8 changed files with 114 additions and 3 deletions
@@ -218,8 +218,16 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
else {
final PsiClass methodContainingClass = myMethod.getContainingClass();
LOG.assertTrue(methodContainingClass != null);
if (!(refClass.getParent() instanceof PsiFile) && !PsiTreeUtil.isAncestor(methodContainingClass, refClass, false)) {
conflicts.putValue(expression, classUnavailableMessage);
if (!PsiTreeUtil.isAncestor(myMethod, refClass, false)) {
PsiElement parent = refClass;
while ((parent = parent.getParent()) instanceof PsiClass) {
if (!PsiUtil.isAccessible((PsiClass)parent, myMethod, null)) {
break;
}
}
if (!(parent instanceof PsiFile)) {
conflicts.putValue(expression, classUnavailableMessage);
}
}
}
}
@@ -12,6 +12,6 @@ class User {
subj.withClass(new Local());
}
class Local {
private class Local {
}
}
@@ -0,0 +1,17 @@
public class Subject {
private int myInt;
public void withClass(Object <caret>o) {
myInt += o.hashCode();
}
}
class User {
private void oper() throws IOException {
Subject subj = new Subject();
subj.withClass(new Local());
}
class Local {
}
}
@@ -0,0 +1,17 @@
public class Subject {
private int myInt;
public void withClass() {
myInt += new User.Local().hashCode();
}
}
class User {
private void oper() throws IOException {
Subject subj = new Subject();
subj.withClass();
}
class Local {
}
}
@@ -0,0 +1,16 @@
public class Subject {
private int myInt;
public void withClass(Object <caret>o) {
myInt += o.hashCode();
}
private void oper() throws IOException {
Subject subj = new Subject();
class Local {
}
subj.withClass(new Local());
}
}
@@ -0,0 +1,18 @@
public class Subject {
private int myInt;
public void withClass(Object <caret>o) {
myInt += o.hashCode();
}
}
class User {
private void oper() throws IOException {
Subject subj = new Subject();
subj.withClass(new Local().new InnerLocal());
}
class Local {
class InnerLocal {}
}
}
@@ -0,0 +1,18 @@
public class Subject {
private int myInt;
public void withClass() {
myInt += new User.Local().new InnerLocal().hashCode();
}
}
class User {
private void oper() throws IOException {
Subject subj = new Subject();
subj.withClass();
}
class Local {
class InnerLocal {}
}
}
@@ -126,6 +126,23 @@ public class InlineParameterTest extends LightCodeInsightTestCase {
doTest(false);
}
public void testRefNewInnerAvailable() throws Exception {
doTest(false);
}
public void testRefNewInnerFromMethod() throws Exception {
try {
doTest(false);
}
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
assertEquals("Parameter initializer depends on class <b><code>Local</code></b> which is not available inside method and cannot be inlined", e.getMessage());
}
}
public void testRefNewInnerInHierarchyAvailable() throws Exception {
doTest(false);
}
public void testRefNewTopLevel() throws Exception {
doTest(false);
}