mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 15:52:01 +07:00
[lombok] IDEA-345991 Fix Error Highlighting: Lombok Builder.Default on Final Fields
GitOrigin-RevId: 839bffdf12b4c5046ed8ec0732bfce9f09801516
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ddadd53ad0
commit
6ebc72d816
@@ -678,7 +678,9 @@ public final class HighlightControlFlowUtil {
|
||||
@NotNull PsiExpression expression,
|
||||
@NotNull PsiReferenceExpression reference,
|
||||
@NotNull PsiFile containingFile) {
|
||||
if (variable.hasInitializer()) return false;
|
||||
if (variable.hasInitializer()) {
|
||||
return variable instanceof PsiField field && !PsiAugmentProvider.canTrustFieldInitializer(field);
|
||||
}
|
||||
if (variable instanceof PsiParameter) return false;
|
||||
PsiElement scope = getElementVariableReferencedFrom(variable, expression);
|
||||
if (variable instanceof PsiField field) {
|
||||
|
||||
@@ -48,6 +48,10 @@ public class LombokHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testBuilderWithDefaultReinitializeInConstructor() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testValueSealedInterface() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import lombok.Builder;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Builder
|
||||
class Bar {
|
||||
@Builder.Default
|
||||
private final String bar = "FooBar";
|
||||
|
||||
private final String foo = "Foo";
|
||||
|
||||
public Bar(String bar, String foo) {
|
||||
this.bar = bar;
|
||||
<error descr="Cannot assign a value to final variable 'foo'">this.foo</error> = foo;
|
||||
}
|
||||
}
|
||||
|
||||
@SuperBuilder
|
||||
class Foo {
|
||||
@Builder.Default
|
||||
private final String bar = "FooBar";
|
||||
|
||||
private final String foo = "Foo";
|
||||
|
||||
public Foo(String bar, String foo) {
|
||||
this.bar = bar;
|
||||
<error descr="Cannot assign a value to final variable 'foo'">this.foo</error> = foo;
|
||||
}
|
||||
}
|
||||
|
||||
public class BuilderWithDefaultReinitializeInConstructor {
|
||||
public static void main(String[] args) {
|
||||
new Bar("FooBar", "Foo");
|
||||
new Foo("FooBar", "Foo");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user