type

Note

This target doesn't match any syntactical elements. It is used as an option from another target. In case you want to search for type definitions in code, take a look at class.

Sensei allows for both a very simple and very advanced configuration to match types. It is important to note that Sensei will always try to match the simple name and fully qualified name during the analysis.

Shorthands

As stated before, we can use a very simple string-based configuration to match types. We call these configurations shorthands.

search:
  methodcall:
    type: SomeClass

Advanced configuration

These shorthand notations are insufficient in certain scenarios. That is why Sensei allows to configure the type-matching in a similar fashion as configuring a target.

reference

This is the actual name of the class that will be used to perform the matching

search:
  methodcall:
    type:
      reference: SomeClass

Note that this produces the same result as the following configuration:

search:
  methodcall:
    type: SomeClass

checkInheritance

When true, super classes (and their supers, recursively) of candidate types are also checked.

search:
  methodcall:
    returnType:
      reference: Collection
      checkInheritance: true

The example above will also match on methods with a return type of java.util.Stack since that type extends java.util.Vector, which implements java.util.List, which extends java.util.Collection.

A value of false has the same effect as not being specified.

isPrimitive

If specified, this property checks if the candidate type is one of the primitive types listed below. Matches if either the value is true and the candidate type is one of the types in the list, or if the value is false and the type is not any of the types in the list.

Primitive types:

  1. boolean

  2. byte

  3. char

  4. double

  5. float

  6. int

  7. long

  8. short

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>