javaintellij-ideacode-inspectionstructural-searchintellij-inspections

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


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.


Solution

  • 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

    Inspection Config