mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
convert anonym to inner: ignore used type params as they would be propagated anyway (IDEA-87171)
This commit is contained in:
+1
-1
@@ -240,7 +240,7 @@ public class AnonymousToInnerHandler implements RefactoringActionHandler {
|
||||
}
|
||||
|
||||
private Boolean cachedNeedsThis = null;
|
||||
private boolean needsThis() {
|
||||
public boolean needsThis() {
|
||||
if(cachedNeedsThis == null) {
|
||||
|
||||
ElementNeedsThis memberNeedsThis = new ElementNeedsThis(myTargetClass, myAnonClass);
|
||||
|
||||
@@ -41,9 +41,14 @@ public class ElementNeedsThis extends ClassThisReferencesVisitor {
|
||||
if (classMember == null || classMember.equals(myMember)) return;
|
||||
if (classMember.hasModifierProperty(PsiModifier.STATIC)) return;
|
||||
|
||||
if (ignoreUsedTypeParams() && classMember instanceof PsiTypeParameter) return;
|
||||
myResult = true;
|
||||
}
|
||||
|
||||
protected boolean ignoreUsedTypeParams() {
|
||||
return myMember != null;
|
||||
}
|
||||
|
||||
protected void visitExplicitThis(PsiClass referencedClass, PsiThisExpression reference) {
|
||||
myResult = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
public class Foo {
|
||||
public<T> void foo() {
|
||||
Predicate<T> predicate = ne<caret>w Predicate<T>() {
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private interface Predicate<K> {
|
||||
boolean test(K t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
public class Foo {
|
||||
public<T> void foo() {
|
||||
Predicate<T> predicate = new MyPredicate<T>();
|
||||
}
|
||||
|
||||
private interface Predicate<K> {
|
||||
boolean test(K t);
|
||||
}
|
||||
|
||||
private static class MyPredicate<T> implements Predicate<T> {
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,22 @@ public class AnonymousToInnerTest extends LightCodeInsightTestCase {
|
||||
public void testInsideInterface() throws Exception { // IDEADEV-29446
|
||||
doTest("MyRunnable", true);
|
||||
}
|
||||
|
||||
public void testCanBeStatic() throws Exception {
|
||||
configureByFile(TEST_ROOT + getTestName(true) + ".java");
|
||||
AnonymousToInnerHandler handler = new AnonymousToInnerHandler(){
|
||||
@Override
|
||||
protected boolean showRefactoringDialog() {
|
||||
myNewClassName = "MyPredicate";
|
||||
myMakeStatic = !needsThis();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
handler.invoke(getProject(), myEditor, myFile, null);
|
||||
assertFalse(handler.needsThis());
|
||||
checkResultByFile(TEST_ROOT + getTestName(true) + "_after.java");
|
||||
}
|
||||
|
||||
|
||||
private void doTest(final String newClassName, final boolean makeStatic) throws Exception {
|
||||
configureByFile(TEST_ROOT + getTestName(true) + ".java");
|
||||
|
||||
Reference in New Issue
Block a user