annotation

@Deprecated
private int myIntField;

Adds additional metadata to a class, field, parameter, ...

Configuration options

type

Checks the type of the annotation.

search:
  annotation:
    type: HttpPost
 @HttpPost
 public void createUser(UserDTO request) {
 }
 @my.framework.HttpPost
 public void createUser(UserDTO request) {
 }

See also

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

simplified

Checks if the usage of the annotation uses a simple name. This is the opposite of using a fully qualified name.

search:
  annotation:
    simplified: true
 @HttpPost
 public void createUser(UserDTO request) {
 }
@my.framework.HttpPost
public void createUser(UserDTO request) {
}

owner

Every annotation adds metadata to a definition. This definition is what we call the owner of the annotation. Usually, this is a method or class and can be defined by their targets respectively.

search:
  annotation:
    name: Deprecated
    owner:
      method:
@Deprecated
class Example {
    public void doSomething() {
    }
}
 class Example {
     @Deprecated
     public void doSomething() {
     }
 }

parameters

Additional options can be configured when using annotations. These options are often referred to as annotation parameters. This configuration is a list of annotationParameter targets.

search:
  annotation:
    parameters:
    - name: "authorize"
      value:
        value: "all"
 class Example {
     @HttpPost(authorize = "all")
     public void doSomething() {
     }
 }

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>