From 4a3150133d1eb5790a0e3304dc4734c94f40966c Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Sun, 4 Feb 2024 20:52:41 +0100 Subject: [PATCH] Do not annotate uninitialized static final fields if parent type is extern. --- .../semantics/HaxeFieldAnnotator.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeFieldAnnotator.java b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeFieldAnnotator.java index d812d4b48..31c5ae10b 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeFieldAnnotator.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeFieldAnnotator.java @@ -35,28 +35,30 @@ public static void check(final HaxeFieldDeclaration var, final AnnotationHolder else { if (FINAL_FIELD_IS_INITIALIZED.isEnabled(var)) { if (field.isFinal()) { - if (!field.hasInitializer()) { - if (!isParentInterface(var) && !isParentAnonymousStructure(var)) { - if (field.isStatic()) { - holder.newAnnotation(HighlightSeverity.ERROR, HaxeBundle.message("haxe.semantic.final.static.var.init", field.getName())) - .range(var) - .create(); + if (field.getDeclaringClass() == null || !field.getDeclaringClass().isExtern()) { + if (!field.hasInitializer()) { + if (!isParentInterface(var) && !isParentAnonymousStructure(var)) { + if (field.isStatic()) { + holder.newAnnotation(HighlightSeverity.ERROR, HaxeBundle.message("haxe.semantic.final.static.var.init", field.getName())) + .range(var) + .create(); + } + else if (!isFieldInitializedInTheConstructor(field)) { + holder.newAnnotation(HighlightSeverity.ERROR, HaxeBundle.message("haxe.semantic.final.var.init", field.getName())) + .range(var) + .create(); + } } - else if (!isFieldInitializedInTheConstructor(field)) { - holder.newAnnotation(HighlightSeverity.ERROR, HaxeBundle.message("haxe.semantic.final.var.init", field.getName())) + } + else { + if (isParentInterface(var)) { + holder.newAnnotation(HighlightSeverity.ERROR, + HaxeBundle.message("haxe.semantic.final.static.var.init.interface", field.getName())) .range(var) .create(); } } } - else { - if (isParentInterface(var)) { - holder.newAnnotation(HighlightSeverity.ERROR, - HaxeBundle.message("haxe.semantic.final.static.var.init.interface", field.getName())) - .range(var) - .create(); - } - } } } }