method

class Example {
    public void myMethod() {
        //...
    }
}

A declaration of executable code that can be invoked.

Configuration options

name

Checks the name of the defined method.

search:
  method:
    name: someMethod
 class Example {
     public void someMethod() {
     }
 }

See also

The examples above use shorthands, see string target for more advanced configurations

annotation

Checks if the specified annotation is present. This option is configured using the annotation target.

search:
  method:
    annotation:
      type: Deprecated
 class Example {
     @Deprecated
     public void someMethod() {
     }
 }

type

Checks the type of where this method has been declared.

search:
  method:
    type: MyClass
 class MyClass {
     public void example() {
     }
 }

See also

The examples above use shorthands, see type target for more advanced configurations

child

Checks if this method contains a child that matches the target specification.

search:
  method:
    child:
      methodcall:
        name: println
 class Example {
     public void example() {
         System.out.println("example");
     }
 }

returnType

Checks the return type of the method.

search:
  method:
    returnType: String
 class Example {
     public String example() {
     }
 }

javadoc

Checks if the defined method contains a javadoc comment that matches the javadoc target.

search:
  method:
    javadoc:
      contents:
        matches: ".*example.*"
 class Example {
     /**
      * this is an example.
      */
     public String example() {
     }
 }

modifier

Checks if the method contains a modifier that matches the string target. All modifiers are matched separately. To match multiple modifiers, use allOf or anyOf.

search:
  method:
    modifier: "public"
 class Example {
     public String example() {
     }
 }

example of multiple modifiers

search:
  method:
    allOf:
    - modifier: "public"
    - modifier: "static"
 class Example {
     public static String example() {
     }
 }

constructor

Checks if the defined method is a constructor.

search:
  method:
    constructor: true
 class Example {
     public Example() {
     }

     public String example() {
     }
 }

Generic Configuration options

The following options are generic and available for every target.

anyOf

Similar to the logical operator OR: one or more descendant options should match.

search:
  <target>:
    anyOf:
    - name: "illegal"
    - name: "alsoIllegal"

allOf

Similar to the logical operator AND: all descendant options must match.

search:
  <target>:
    allOf:
    - annotation: "HttpPost"
    - annotation: "AllowUnAuthorized"

with

The only purpose to use this field is to make the recipe easier to read. It provides no additional functionality.

search:
  <target>:
    with:
      annotation: "HttpPost"

not, without

Works as the logical operator NOT. It will negate the result of the descendant options. Sensei presents the user with both options. They display the same behavior, but certain scenarios tend to read better using without.

search:
  <target>:
    not:
      annotation: "HttpPost"
search:
  <target>:
    without:
      annotation: "HttpPost"

in

Performs a structural search, this option is mainly used to narrow down recipes. Examples of this would be to only analyze and mark code inside a certain class or method that has a specific annotation. However, we haven't limited this option to only support these two scenarios. More advanced configuration can be achieved.

search:
  <target>:
    in:
      class:
        name:
          contains: "Controller"
search:
  <target>:
    in:
      method:
        annotation:
          type: "HttpPost"

label

Labels do not modify the behavior of searching elements, but they allow addressing a specific element in a quick fix.

search:
  element:
    tagName: inner
    attribute:
      name: data
    in:
      element:
        label: outerelement

availableFixes:
- name: add the 'type' attribute on the outer element
  actions:
  - add:
      attribute:
        name: type
        value: '"unsafe"'
      target: label:outerelement
- <outer>
+ <outer type="unsafe">
      <inner data="test"/>
  </outer>