Skip to content

Tucos/intellij-issue-ssr-method-param-annotation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Replace Structurally - issue

This project demonstrates an issue with IntelliJ's "Replace Structurally".

The aim of the pattern is to replace a method annotation referring to a parameter by name, with an annotation on that parameter.

This issue has been reported as IDEA-358911

Code example

Code before:

@MyMethodAnnotation("paramName")
public void method1(String paramName) {
}

Expected code after:

@MyMethodAnnotation
public void method1(@MyParamAnnotation String paramName) {
}

Pattern

Search pattern (target method):

@org.example.MyMethodAnnotation("$text$")
$ReturnType$ $method$($ArgType$ $text$);

Replacement pattern:

@org.example.MyMethodAnnotation
$ReturnType$ $method$(@MyParamAnnotation $ArgType$ $text$);

The exact pattern is included in the project settings (.idea/structuralSearch.xml).

The issue

The pattern matches just fine. Even more complicated variations of the pattern / code match without issue (e.g. additional annotations, additional annotation parameters, additional method parameters).

The replacement, however, drops the argument type. Running the structural replacement on this project, results in the following code:

@MyMethodAnnotation
public void method1(@MyParamAnnotation paramName) {
}

i.e. the $ArgType$ is dropped. Swapping $ArgType$ with $text$ in the replacement pattern results in @MyParamAnnotation String, dropping $text$ instead.

Side note: just inserting the annotation on the method parameter works fine if not referencing the method annotation.

About

Demonstrates an issue with structural replace in intellij

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages