Find fields in class annotated with the same values (Structural Search ?)
已回答
Hello,
I would like to find solution for detecting (java) class fields which are annotated with the same value.
It's possible to do via Structural Search? I'm struggling with search template with groovy script here.
Example:
public class SomePageObject {
@FindBy(name = "first-name")
private WebElement name;
@FindBy(name = "first-name")
private WebElement firstName; //duplicated (annotation value is already used)
// other propreties...
}
My template:
class $Class$ {
@$Annotation$($key$ = $value$)
$FieldType$ $Field$ = $Init$;
}
variables:
- Annotation - Text/regexp: FindBys?
-
Value - Text/regexp: ".*"
-
FieldType - Text/regexp: .*Element
- Complete Match - script text: ???
I tried some scripting with __context__ and variables but without success.
I didn't find much documentation about Script constraints in context of structural search.
Can you help me please or point me to some docs? Thanks.
//edit: I can achieve this using unit test with reflection or with ArchUnit library but I'm still interested how to achieve this in IntelliJ IDEA :) - I want custom inspection based on structural search
请先登录再写评论。
It seems this is currently not easily possible. I have created the following issue, which you may want to follow:
https://youtrack.jetbrains.com/issue/IDEA-195166
Bas
Please check this thread https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000045970/comments/360000052644. I hope it will be of help.