I am trying to find and replace all usages of @JsonCreator
on nonstatic methods by using an inspection to suggest a replacement for the method to make it static. I have the following template:
// Search template
@$Annotation$
$MethodType$ $Method$($ParameterType$ $Parameter$)
/** Modifiers
* Annotation{count=[1, inf], text=JsonCreator}
* Method{Script=!__context__.hasModifierProperty("static")}
* Parameter{count=[0, inf]}
*/
// Replace template
@$Annotation$
static $MethodType$ $Method$($ParameterType$ $Parameter$)
/** Modifiers
* Annotation{count=[1, inf], text=JsonCreator}
* Method{Script=!__context__.hasModifierProperty("static")}
* Parameter{count=[0, inf]}
*/
When the target for the search is Complete Match
or Method
, this works as desired, performing the following:
// Before
@JsonCreator
BasicEnum fromString(String value)
{
// ...
}
// After
@JsonCreator
static BasicEnum fromString(String value)
{
// ...
}
However, when the target is Annotation
, it fails, performing the following instead.
// Before
@JsonCreator
BasicEnum fromString(String value)
{
// ...
}
//After
BasicEnum fromString(String value)
{
// ...
}
It removes the annotation and does not add the static modifier.
I’d like to have the target be Annotation
, as getting the warning squiggles across the whole method feels clunky. Why does the replace fail when targeting Annotation
? Is there a way around this such that the squiggles only show up on the annotation?
To note, I’m aware that @JsonCreator
can also be used on constructor methods, but managing those are not something I’m concerned about right now. I just want to find situations where @JsonCreator
is used on a nonstatic method, and provide an inspection to replace.