Selectors

The job of a selector (FieldSelector, TypeSelector or MethodSelector) is to provide a yes or no verdict when presented with a particular Java element (field, method or type) from the Eclipse Java model. The verdict is reached as a result of testing the presented Java element against specified criteria to see if matches. When specifying a selector one or more criteria must be specified. Where multiple criteria are specified they must all be either anded (&) or ored (|).

For the criteria documented below we use FieldSelector examples; please note that all of these criteria are equally valid for use in the specification of a TypeSelector or a MethodSelector.

Name Criterion

The name is the simple unqualified name of the Java element. The criterion tests it against a wildcard pattern. The pattern may be supplied directly in the definition, or may be sourced from a PatternSwitch.

Examples:

Matches fields named serialVersionUID

FieldSelector fieldsNamedSerialVersionUID {
  fields named "serialVersionUID";
}

Matches fields with a name ending in ID

FieldSelector fieldsNamedId{
  fields named "*ID";
}

Matches fields with a name matching a PatternSwitch (this contains just a reference to the PatternSwitch, the PatternSwitch itself is specified elsewhere)

FieldSelector fieldsNamedId {
  
fields named namePatternSwitch;
}

Javadoc

The Javadoc is the comment present in the source code just before the declaration of the Java element. A Javadoc comment can be treated as a collection of tag-value pairs. Below is a Javadoc comment with three tags:

/** This text has a value but no tag.
 * @tagWithoutValue
 * @tagWithValue Value for tagWithValue
 */

The javadoc criterion can apply to either the tag name or the value.

Examples

Matches fields with a Javadoc value containing the word persistence

FieldSelector persistenceFields {
  fields javadoc value "*persistence*" ;
}

Matches fields with a Javadoc value matching a PatternSwitch (again, authorPattern is specified elsewhere)

FieldSelector switchableAuthorFields {
  fields javadoc value authorPattern ;
}

Matches fields with an @author Javadoc tag and a Javadoc value matching Flintstone

FieldSelector switchableAuthorFields {
  fields javadoc tag "@author" & javadoc value "Flintstone";
}

Modifiers

Modifiers are the familiar Java keywords like final static abstract public which are prepended to the declaration of a Java element in the source code. The modified criterion differentiates between Java elements which have a given modifier and those which do not.

Example

Matches all final fields

FieldSelector finalFields {
  fields modified final ;
}

Declared By

The owner of a Java element is the type in which it is declared. Inner types are declared by their outer type. Top level types do not have an owner (see TypeSelector). This criterion selects based upon the selection of the Java element's owner.

Example

Matches all fields declared in a unit test. (What constitutes a unit test is dealt with by the unitTests TypeSelector).

FieldSelector unitTestFields {
  fields declared by unitTests ;
}

Included Other Selector

Inclusion by another selector allows new selectors to be composed of an aggregation of many other selectors without the need to repeat all of the criteria of the aggregates.

Example

Matches all final fields declared in a unit test

FieldSelector finalUnitTestFields {
  fields included in unitTestFields & included in finalFields
}

Excluded Other Selector

Exclusion from another selector means that this Java element is required to not meet the criteria of another selector.

Examples

Matches all fields which are mutable (non-final)

FieldSelector mutableFields {
  fields excluded from finalFields
}