admin管理员组文章数量:1384803
How to create a Structural Search Inspection in IntelliJ IDEA
for Method Name length greater than 75 characters?
What I have tried:
Add Structural Search Inspection:
Search template:
public void $MethodName$() throws Exception {}
Target: MethodName
Add Modifier : Script = MethodName.length() > 75
(Java)
My actual code line which I want to be flagged:
verify_14_10_CARSUWRecoRolesNSecFilt_CopyPasteProfileWOutOfScopeMsgCheckasdas() throws Exception { ... }
When I run the inspection, the result says:
Code inspection did not find anything to report
What am I missing?
I am using IntelliJ Community Edition
for Java.
How to create a Structural Search Inspection in IntelliJ IDEA
for Method Name length greater than 75 characters?
What I have tried:
Add Structural Search Inspection:
Search template:
public void $MethodName$() throws Exception {}
Target: MethodName
Add Modifier : Script = MethodName.length() > 75
(Java)
My actual code line which I want to be flagged:
verify_14_10_CARSUWRecoRolesNSecFilt_CopyPasteProfileWOutOfScopeMsgCheckasdas() throws Exception { ... }
When I run the inspection, the result says:
Code inspection did not find anything to report
What am I missing?
I am using IntelliJ Community Edition
for Java.
2 Answers
Reset to default 2In your case, since you need to simply check for the length of method names, you could define a Structural Search Inspection with Regex Matching.
After selecting Structural Search
in User Defined
inspections, click on the plus icon and select Add Structural Search Inspection
. Choose the search template All methods of a class (within hierarchy)
, and add a Text
modifier for $Method$
that checks whether the method name's length is greater than 75
according to the specs of Java Identifiers.
To add a modifier for a certain element, click on the desired element or select it, and then enter the modifier in the text area on the right.
Search Template
class $Class$ {
$ReturnType$ $Method$ ($ParameterType$ $Parameter$);
}
Regex
[a-zA-Z$_][a-zA-Z0-9$_]{75,}
Preview
Use the template
$ReturnType$ $Method$($BeforeType$ $BeforeParameter$);
with the following modifiers:
$ReturnType$
:Count[0, 1]
,$Method$
: Script modifierMethod.name.length() > 75
,$BeforeParameter$
:Count[0, Unlimited]
.
In the Script modifier you can refer to the variables of the template, where the variables correspond to nodes in the PSI tree. This means that all methods from PsiElement are available. In particular, the method name implements the PsiNamedElement interface, giving us access to the getName()
method. Since the script is Groovy, this can be used as .name
.
本文标签:
版权声明:本文标题:java - How to create a Structural Search Inspection in IntelliJ IDEA for Method Name length greater than 75 characters? - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744487481a2608536.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论