java - How to create a Structural Search Inspection in IntelliJ IDEA for Method Name length greater than 75 characters? - Stack

How to create a Structural Search Inspection in IntelliJ IDEA for Method Name length greater than 75 ch

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.

Share Improve this question edited yesterday Mister Jojo 22.6k6 gold badges25 silver badges44 bronze badges asked Mar 18 at 23:05 AutoTester999AutoTester999 6482 gold badges11 silver badges31 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 2

In 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 modifier Method.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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744487482a4576648.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信