mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 15:52:01 +07:00
[Java. Inspections] disable suggestion of adding excepion to signature in base methods if they are synthetic
IDEA-358300 GitOrigin-RevId: c042955003e44d4d575569543c4247ac223c02ec
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bc8f0bf7c5
commit
ae1025c38d
@@ -135,8 +135,8 @@ public final class AddExceptionToThrowsFix extends PsiBasedModCommandAction<PsiE
|
||||
};
|
||||
}
|
||||
|
||||
static boolean isAnyOfTheMethodsInCompiledClass(@NotNull PsiMethod targetMethod) {
|
||||
return ContainerUtil.or(getSuperMethods(targetMethod), method -> method instanceof PsiCompiledElement);
|
||||
static boolean isAnyOfTheMethodsUnmodifiable(@NotNull PsiMethod targetMethod) {
|
||||
return ContainerUtil.or(getSuperMethods(targetMethod), method -> method instanceof PsiCompiledElement || method instanceof SyntheticElement);
|
||||
}
|
||||
|
||||
private static @Nullable PsiMethod collectExceptions(Set<? super PsiClassType> unhandled, PsiElement element) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class AddRuntimeExceptionToThrowsAction implements ModCommandAction
|
||||
if (method == null) return nop();
|
||||
ModCommand command =
|
||||
AddExceptionToThrowsFix.addExceptionsToThrowsList(context.project(), method, Collections.singleton(aClass), myProcessHierarchy);
|
||||
if (command == null && !AddExceptionToThrowsFix.isAnyOfTheMethodsInCompiledClass(method)) {
|
||||
if (command == null && !AddExceptionToThrowsFix.isAnyOfTheMethodsUnmodifiable(method)) {
|
||||
return chooseAction(QuickFixBundle.message("add.runtime.exception.to.throws.header"),
|
||||
new AddRuntimeExceptionToThrowsAction(ThreeState.YES),
|
||||
new AddRuntimeExceptionToThrowsAction(ThreeState.NO));
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.intellij.java.lomboktest
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle
|
||||
import com.intellij.openapi.command.executeCommand
|
||||
import com.intellij.refactoring.suggested.LightJavaCodeInsightFixtureTestCaseWithUtils
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import de.plushnikov.intellij.plugin.LombokTestUtil.LOMBOK_DESCRIPTOR
|
||||
|
||||
class LombokAddRuntimeExceptionToThrowsActionTest: LightJavaCodeInsightFixtureTestCaseWithUtils() {
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = LOMBOK_DESCRIPTOR
|
||||
|
||||
override fun getBasePath(): String = "community/plugins/lombok/testData/intention/addExceptionToThrows"
|
||||
|
||||
|
||||
fun testOverridingSyntheticElement() = doTest()
|
||||
|
||||
private fun doTest() {
|
||||
val name = getTestName(false)
|
||||
myFixture.configureByFile("before$name.java")
|
||||
val intention = myFixture.availableIntentions.singleOrNull { it.familyName == QuickFixBundle.message("add.runtime.exception.to.throws.family") }
|
||||
assertNotNull(intention)
|
||||
executeCommand { intention?.invoke(project, editor, file) }
|
||||
myFixture.checkResultByFile("after$name.java")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import lombok.Getter;
|
||||
|
||||
public class A {
|
||||
@Getter
|
||||
private String s;
|
||||
|
||||
private static class B extends A {
|
||||
@Override
|
||||
public String getS() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
private static class C extends B {
|
||||
@Override
|
||||
public String getS() throws RuntimeException {
|
||||
throw new Runtime<caret>Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import lombok.Getter;
|
||||
|
||||
public class A {
|
||||
@Getter
|
||||
private String s;
|
||||
|
||||
private static class B extends A {
|
||||
@Override
|
||||
public String getS() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
private static class C extends B {
|
||||
@Override
|
||||
public String getS() {
|
||||
throw new Runtime<caret>Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user