@interface

@interface MyAnnotation {}

Defines an annotation type.

Configuration options

There are no options to narrow down searching for an annotation interface declaration.

Generic Type Declaration Configuration options

name

Matches the name of the type declaration.

search:
  typeDeclaration:
    name: Example
 class Example {
 }

See also

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

super

Checks if the type declaration extends or implements another type declaration. This options is configured using the typeDeclaration target.

search:
  typeDeclaration:
    super:
      name: Runnable
 class Example implements Runnable {
 }
 interface Example implements Runnable {
 }

package

Checks if the current type declaration is inside a package.

search:
  typeDeclaration:
    package: "com.securecodewarrior"
 package com.securecodewarrior;

 class Example {
 }

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:
  typeDeclaration:
    annotation:
     type: "Deprecated"
 @Deprecated
 class Example {
 }

child

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

search:
  typeDeclaration:
    child:
     method:
       name: "someFunction"
 class Example {
    public void someFunction() {
    }
 }

modifier

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

search:
  typeDeclaration:
   modifier: public
 public class Example {
 }

Example using multiple modifiers

search:
  typeDeclaration:
   allOf:
   - modifier: public
   - modifier: final
 public final class Example {
 }

javadoc

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

search:
  typeDeclaration:
    javadoc:
      contents:
        matches: ".*example.*"
 /**
  * this is an example.
  */
 class Example {
 }

member

Checks if this type declaration contains a member (field or method) that matches the target specification. This option will take inheritance into account.

search:
  typeDeclaration:
    member:
      method:
        name: someFunction
 // the following typeDeclaration matches because it inherits the members of Superclass
 class Example extends Superclass {
 }

 class Superclass {
     public void someFunction() {
     }
 }

Common type declaration patterns

Searching only for inner type declarations

While there is no dedicated option to only match inner type declarations, this behavior can be achieved using the in option.

search:
  typeDeclaration:
    in:
      typeDeclaration: {}
 class Example {
     private class ExampleInner {
     }
 }

This will only match type declarations that are inside another type declaration.

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>