mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
IDEA-228553 - separated two intention actions between different language levels not to prevent users confusing what to choose
GitOrigin-RevId: 76677d371b01ba501716756d9ea1dafa61c85404
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2bf945f71c
commit
3d8460f557
@@ -24,6 +24,7 @@ import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.source.PsiClassReferenceType;
|
||||
@@ -41,6 +42,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static com.intellij.pom.java.LanguageLevel.JDK_11;
|
||||
|
||||
public final class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentionActionOnPsiElement implements HighPriorityAction {
|
||||
static class Wrapper extends ArgumentFixerActionFactory {
|
||||
final Predicate<? super PsiType> myInTypeFilter;
|
||||
@@ -149,10 +152,10 @@ public final class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentio
|
||||
outType -> outType.equalsToText(CommonClassNames.JAVA_IO_FILE)),
|
||||
new Wrapper("java.nio.file.Path.of({0})",
|
||||
inType -> inType.equalsToText(CommonClassNames.JAVA_LANG_STRING),
|
||||
outType -> outType.equalsToText("java.nio.file.Path")),
|
||||
outType -> outType.equalsToText("java.nio.file.Path") && isAppropriateLanguageLevel(outType, level -> level.isAtLeast(JDK_11))),
|
||||
new Wrapper("java.nio.file.Paths.get({0})",
|
||||
inType -> inType.equalsToText(CommonClassNames.JAVA_LANG_STRING),
|
||||
outType -> outType.equalsToText("java.nio.file.Path")),
|
||||
outType -> outType.equalsToText("java.nio.file.Path") && isAppropriateLanguageLevel(outType, level -> level.isLessThan(JDK_11))),
|
||||
new Wrapper("java.util.Arrays.asList({0})",
|
||||
inType -> inType instanceof PsiArrayType && ((PsiArrayType)inType).getComponentType() instanceof PsiClassType,
|
||||
outType -> InheritanceUtil.isInheritor(outType, CommonClassNames.JAVA_LANG_ITERABLE)),
|
||||
@@ -171,6 +174,11 @@ public final class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentio
|
||||
outType -> InheritanceUtil.isInheritor(outType, CommonClassNames.JAVA_UTIL_STREAM_BASE_STREAM))
|
||||
};
|
||||
|
||||
private static boolean isAppropriateLanguageLevel(@NotNull PsiType psiType, @NotNull Predicate<LanguageLevel> level) {
|
||||
if (!(psiType instanceof PsiClassType)) return true;
|
||||
return level.test(((PsiClassType)psiType).getLanguageLevel());
|
||||
}
|
||||
|
||||
@SafeFieldForPreview
|
||||
@Nullable private final PsiType myType;
|
||||
@SafeFieldForPreview
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Wrap using 'Paths.get()'" "true"
|
||||
// "Wrap using 'Path.of()'" "false"
|
||||
import java.nio.file.*;
|
||||
|
||||
class Test {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// "Wrap parameter using 'Paths.get()'" "true"
|
||||
import java.nio.file.*;
|
||||
|
||||
class Test {
|
||||
|
||||
void m() {
|
||||
Files.readString(Paths.get("path"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// "Wrap parameter using 'Paths.get()'" "true"
|
||||
import java.nio.file.*;
|
||||
|
||||
class Test {
|
||||
|
||||
void m() {
|
||||
Files.readString("<caret>path");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Wrap parameter using 'Path.of()'" "true"
|
||||
// "Wrap parameter using 'Paths.get()'" "false"
|
||||
import java.nio.file.*;
|
||||
|
||||
class Test {
|
||||
|
||||
Reference in New Issue
Block a user