[java-intentions] ModifierFix: Avoid adding modifier on separate line if modifier list consists of annotations only

IJ-CR-102194

GitOrigin-RevId: 50d4f16ee583d75be79f8c77126a5d20944bddef
This commit is contained in:
Andrey Cherkasov
2023-04-12 14:51:45 +00:00
committed by intellij-monorepo-bot
parent c27a5fdc2f
commit 56e57c4179
5 changed files with 22 additions and 5 deletions
@@ -157,7 +157,13 @@ public class ModifierFix extends LocalQuickFixAndIntentionActionOnPsiElement imp
private void changeModifierList (@NotNull PsiModifierList modifierList) {
try {
boolean needRemoveWhiteSpace = modifierList.getLastChild() instanceof PsiAnnotation &&
modifierList.getNextSibling() instanceof PsiWhiteSpace &&
myShouldHave;
modifierList.setModifierProperty(myModifier, myShouldHave);
if (needRemoveWhiteSpace) {
modifierList.getNextSibling().delete();
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
@@ -0,0 +1,6 @@
import com.intellij.openapi.components.Service;
@Service
strictfp
class <error descr="Light service must be final">MyService<caret></error> {
}
@@ -0,0 +1,6 @@
import com.intellij.openapi.components.Service;
@Service
final strictfp
class MyService {
}
@@ -1,6 +1,5 @@
import com.intellij.openapi.components.Service;
@Service
final
class MyService {
final class MyService {
}
@@ -14,7 +14,7 @@ internal class LightServiceMustBeFinalInspectionTest : LightServiceMustBeFinalIn
override fun getFileExtension() = "java"
fun testMakeFinal() {
doTest(MAKE_FINAL_FIX_NAME)
}
fun testMakeFinal() { doTest(MAKE_FINAL_FIX_NAME) }
fun testMakeFinalMultiLineModifierList() { doTest(MAKE_FINAL_FIX_NAME) }
}