From 01f1cc7dc812876c96c10567764505b23d93812e Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Thu, 8 Aug 2024 19:21:04 +0200 Subject: [PATCH] fix missing optional check on anonymousTypeFields (issue #1181) --- src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf | 4 ++-- .../java/com/intellij/plugins/haxe/model/HaxeFieldModel.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf b/src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf index 06f25ef69..403489ebb 100644 --- a/src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf +++ b/src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf @@ -413,7 +413,7 @@ private enumConstructorParameters ::= parenthesizedParameterList fieldDeclaration ::= fieldModifier* mutabilityModifier componentName propertyDeclaration? typeTag? varInit? <> {pin=3 mixin="com.intellij.plugins.haxe.lang.psi.impl.HaxePsiFieldImpl" implements="com.intellij.plugins.haxe.lang.psi.HaxePsiField"} -optionalFieldDeclaration ::= fieldModifier* mutabilityModifier '?' componentName propertyDeclaration? typeTag? varInit? <> +optionalFieldDeclaration ::= fieldModifier* mutabilityModifier optionalMark componentName propertyDeclaration? typeTag? varInit? <> {pin=3 implements=fieldDeclaration mixin="com.intellij.plugins.haxe.lang.psi.impl.HaxePsiFieldImpl" implements="com.intellij.plugins.haxe.lang.psi.HaxePsiField"} //NOTE: static local variable is a haxe 4.3+ feature localVarDeclarationList ::='static'? mutabilityModifier localVarDeclaration (',' localVarDeclaration)* <>{pin=3} @@ -969,7 +969,7 @@ typeExtendsList ::= '>' type (',' '>' type)* {pin=1} anonymousTypeFieldList ::= anonymousTypeField (',' anonymousTypeField)* ','? {recoverWhile="object_literal_part_recover" pin=1} private sep ::= ',' | ';' -anonymousTypeField ::= "?"? componentName typeTag +anonymousTypeField ::= optionalMark? componentName typeTag {pin=3 mixin="com.intellij.plugins.haxe.lang.psi.impl.HaxePsiFieldImpl" implements="com.intellij.plugins.haxe.lang.psi.HaxePsiField"} // Do NOT genericize objectLiteral by making objectLiteralElementList optional. Doing so diff --git a/src/main/java/com/intellij/plugins/haxe/model/HaxeFieldModel.java b/src/main/java/com/intellij/plugins/haxe/model/HaxeFieldModel.java index 0e3ab08df..369e24952 100644 --- a/src/main/java/com/intellij/plugins/haxe/model/HaxeFieldModel.java +++ b/src/main/java/com/intellij/plugins/haxe/model/HaxeFieldModel.java @@ -214,6 +214,9 @@ public HaxeExpression getInitializerExpression() { public boolean isOptional() { if(getBasePsi() instanceof HaxeOptionalFieldDeclaration) return true; + if(getBasePsi() instanceof HaxeAnonymousTypeField anonymous) { + if (anonymous.getOptionalMark() != null)return true; + } return hasOptionalMeta(); } }