最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论