Grammar-Kit icon indicating copy to clipboard operation
Grammar-Kit copied to clipboard

Grammar-Kit generates unnecessary annotations for custom methods (IntelliJ IDEA 2025.1.2+)

Open mlytvyn opened this issue 6 months ago • 0 comments

Hello,

Having the following BNF file flexibleSearch.bnf Grammar-Kit generates non-compilable code with unnecessary @NotNull / @Nullable annotations for custom methods implemented in the Mixin or psiImplUtilClass in IntelliJ IDEA 2025.1.2+.

In addition to that code style for those generated methods is different and missing new lines.

Code generated via IntelliJ IDEA 2023.3.8 (version from the latest master branch) looks good and compilable.

BNF rule

y_column_name ::= ORDER | IDENTIFIER {
    mixin="com.intellij.idea.plugin.hybris.flexibleSearch.psi.impl.FlexibleSearchYColumnNameMixin"
    methods=[getTableToAlias getTableAliases]
}

PSI Util method

fun getTableAliases(element: PsiElement): Collection<FlexibleSearchTableAliasName> {
...
}
2023.3.8 generated code
public interface FlexibleSearchYColumnName extends PsiElement {

  @Nullable
  Pair<FlexibleSearchDefinedTableName, FlexibleSearchTableAliasName> getTableToAlias();

  @NotNull
  Collection<FlexibleSearchTableAliasName> getTableAliases();

}
2025.1.2+ generated code
public interface FlexibleSearchYColumnName extends PsiElement {

  @Nullable Pair<@NotNull FlexibleSearchDefinedTableName, @Nullable FlexibleSearchTableAliasName> getTableToAlias();

  @NotNull Collection<@NotNull FlexibleSearchTableAliasName> getTableAliases();

}

Same happens for methods implemented in the Mixin, f.e. FlexibleSearchBindParameterMixin.

Method implemented in the Mixin

override fun getItemType(): TSGlobalMetaClassifier<out DomElement>? = ....
2025.1.2+ generated code
public interface FlexibleSearchBindParameter extends PsiElement {

  @NotNull
  List<FlexibleSearchExtParameterName> getExtParameterNameList();

  @Nullable
  PsiElement getNamedParameter();

  @Nullable FlexibleSearchExpression getExpression();

  @Nullable TSGlobalMetaClassifier<? extends @NotNull DomElement> getItemType();

}

mlytvyn avatar Jun 25 '25 08:06 mlytvyn