JetBrains / JetBrains/Grammar-Kit

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

Open
#401 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
771
Forks
137
Avg merge
11h 14m
Merged PRs (30d)
1

Description

Hello,

Having the following BNF file [flexibleSearch.bnf](https://github.com/epam/sap-commerce-intellij-idea-plugin/blob/main/src/com/intellij/idea/plugin/hybris/flexibleSearch/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
```bnf
y_column_name ::= ORDER | IDENTIFIER {
mixin="com.intellij.idea.plugin.hybris.flexibleSearch.psi.impl.FlexibleSearchYColumnNameMixin"
methods=[getTableToAlias getTableAliases]
}
```

#### PSI Util method
```kotlin
fun getTableAliases(element: PsiElement): Collection {
...
}
```

##### 2023.3.8 generated code
```java
public interface FlexibleSearchYColumnName extends PsiElement {

@Nullable
Pair getTableToAlias();

@NotNull
Collection getTableAliases();

}
```

##### 2025.1.2+ generated code
```java
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](https://github.com/epam/sap-commerce-intellij-idea-plugin/blob/main/src/com/intellij/idea/plugin/hybris/flexibleSearch/psi/impl/FlexibleSearchBindParameterMixin.kt).
#### Method implemented in the Mixin
```kotlin
override fun getItemType(): TSGlobalMetaClassifier? = ....
```
##### 2025.1.2+ generated code
```java
public interface FlexibleSearchBindParameter extends PsiElement {

@NotNull
List getExtParameterNameList();

@Nullable
PsiElement getNamedParameter();

@Nullable FlexibleSearchExpression getExpression();

@Nullable TSGlobalMetaClassifier getItemType();

}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with flexibleSearch.bnf and compare its generated PSI interface under IntelliJ IDEA 2023.3.8 and 2025.1.2+. Review FlexibleSearchBindParameterMixin.kt and the PSI utility method examples to trace annotation and formatting generation. Done means custom methods no longer receive unnecessary nested annotations and generated code remains compilable with the expected formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.