mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
convert anonymous to inner: collapse diamonds (IDEA-87265)
This commit is contained in:
+7
-2
@@ -26,6 +26,7 @@ import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.PsiDiamondTypeUtil;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -184,8 +185,12 @@ public class AnonymousToInnerHandler implements RefactoringActionHandler {
|
||||
}
|
||||
}
|
||||
buf.append(")");
|
||||
PsiExpression newClassExpression = JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory().createExpressionFromText(buf.toString(), null);
|
||||
newExpr.replace(newClassExpression);
|
||||
PsiNewExpression newClassExpression =
|
||||
(PsiNewExpression)JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory().createExpressionFromText(buf.toString(), null);
|
||||
newClassExpression = (PsiNewExpression)newExpr.replace(newClassExpression);
|
||||
if (PsiDiamondTypeUtil.canCollapseToDiamond(newClassExpression, newClassExpression, newClassExpression.getType())) {
|
||||
PsiDiamondTypeUtil.replaceExplicitWithDiamond(newClassExpression.getClassOrAnonymousClassReference().getParameterList());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
public class Foo {
|
||||
public<T> void foo() {
|
||||
Predicate<T> predicate = new MyPredicate<T>();
|
||||
Predicate<T> predicate = new MyPredicate<>();
|
||||
}
|
||||
|
||||
private interface Predicate<K> {
|
||||
|
||||
@@ -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<>();
|
||||
}
|
||||
|
||||
private interface Predicate<K> {
|
||||
boolean test(K t);
|
||||
}
|
||||
|
||||
private static class MyPredicate<T> implements Predicate<T> {
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@ import java.util.*;
|
||||
|
||||
class A<K, V> {
|
||||
public Iterator<Map.Entry<K, V>> iterator(long revision) {
|
||||
return new MyIterator<K, V>();
|
||||
return new MyIterator<>();
|
||||
}
|
||||
|
||||
private static class MyIterator<K, V> implements Iterator<Map.Entry<K, V>> {
|
||||
|
||||
@@ -38,6 +38,10 @@ public class AnonymousToInnerTest extends LightCodeInsightTestCase {
|
||||
doTest("MyRunnable", true);
|
||||
}
|
||||
|
||||
public void testCollapseDiamonds() throws Exception { // IDEADEV-29446
|
||||
doTest("MyPredicate", true);
|
||||
}
|
||||
|
||||
public void testCanBeStatic() throws Exception {
|
||||
configureByFile(TEST_ROOT + getTestName(true) + ".java");
|
||||
AnonymousToInnerHandler handler = new AnonymousToInnerHandler(){
|
||||
|
||||
Reference in New Issue
Block a user