[java-inspections] CodeBlockSurrounder: disable in enum initializers

We could devise something like ((Runnable)() -> {...}).run() but this kind of code looks too ugly.
Fixes IDEA-252688 Assertion error when applying fix to assert not null in enums

GitOrigin-RevId: 6f2122acb60cfcb074cc47e6bc599626fe5547fd
This commit is contained in:
Tagir Valeev
2020-10-14 12:15:25 +07:00
committed by intellij-monorepo-bot
parent 038456e4fd
commit fdb5a1025d
2 changed files with 7 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
// "Assert 'field != null'" "false"
enum A {
I(field.<caret>hashCode());
private static Object field;
A(int i) {}
}

View File

@@ -249,7 +249,7 @@ public abstract class CodeBlockSurrounder {
}
return null;
}
if (parent instanceof PsiField) {
if (parent instanceof PsiField && !(parent instanceof PsiEnumConstant)) {
return new ExtractFieldInitializerSurrounder(expression, (PsiField)parent);
}