mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
AddTypeArgumentsFix: make robust to parenthesizing
GitOrigin-RevId: d8cd64e88d314d4362e7ee577ed043f6516c34c1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
40e73aab84
commit
bbd7f0443f
+11
-1
@@ -28,6 +28,8 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class AddTypeArgumentsFix extends MethodArgumentFix {
|
||||
private static final Logger LOG = Logger.getInstance(AddTypeArgumentsFix.class);
|
||||
|
||||
@@ -66,6 +68,8 @@ public class AddTypeArgumentsFix extends MethodArgumentFix {
|
||||
public static PsiExpression addTypeArguments(PsiExpression expression, PsiType toType) {
|
||||
if (!PsiUtil.isLanguageLevel5OrHigher(expression)) return null;
|
||||
|
||||
PsiExpression orig = expression;
|
||||
expression = PsiUtil.skipParenthesizedExprDown(expression);
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)expression;
|
||||
final PsiReferenceParameterList list = methodCall.getMethodExpression().getParameterList();
|
||||
@@ -116,7 +120,13 @@ public class AddTypeArgumentsFix extends MethodArgumentFix {
|
||||
methodExpression.setQualifierExpression(qualifierExpression);
|
||||
}
|
||||
|
||||
return (PsiExpression)JavaCodeStyleManager.getInstance(copy.getProject()).shortenClassReferences(copy);
|
||||
PsiExpression result = (PsiExpression)JavaCodeStyleManager.getInstance(copy.getProject()).shortenClassReferences(copy);
|
||||
if (orig != expression) {
|
||||
PsiExpression parenthesized = (PsiExpression)orig.copy();
|
||||
Objects.requireNonNull(PsiUtil.skipParenthesizedExprDown(parenthesized)).replace(result);
|
||||
return parenthesized;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Add explicit type arguments" "true"
|
||||
import java.util.Iterator;
|
||||
|
||||
public abstract class MyIterable<E> implements Iterable<E> {
|
||||
static native <E> MyIterable<E> of(E e);
|
||||
final native MyIterable<E> append(E element);
|
||||
final native MyIterable<E> append(Iterable<? extends E> other);
|
||||
|
||||
static native <E> MyIterable<E> once(Iterator<? extends E> iterator);
|
||||
|
||||
void split() {
|
||||
E next = iterator().next();
|
||||
of(next).append(once(foo().takeWhile(e -> e)));
|
||||
of(next).append((MyIterable.<E>once(foo().takeWhile(e -> e))));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Add explicit type arguments" "true"
|
||||
import java.util.Iterator;
|
||||
|
||||
public abstract class MyIterable<E> implements Iterable<E> {
|
||||
static native <E> MyIterable<E> of(E e);
|
||||
final native MyIterable<E> append(E element);
|
||||
final native MyIterable<E> append(Iterable<? extends E> other);
|
||||
|
||||
static native <E> MyIterable<E> once(Iterator<? extends E> iterator);
|
||||
|
||||
void split() {
|
||||
E next = iterator().next();
|
||||
of(next).append(once(foo().takeWhile(e -> e)));
|
||||
of(next).append((once(foo().takeWhile(e -><caret> e))));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user