Skip to content
Ali Al-Ramadan edited this page Nov 14, 2026 · 2 revisions

The rules of the method stereotypes, the free-function stereotypes, and the class stereotypes hold in Java as in every language of Stereocode. The section Data Members and Calls of the method stereotypes states the conventions by which Stereocode determines the facts of these rules in every language. This page gives the forms that these facts take in Java, the built-in lists that Stereocode reads for Java, and one labeled example of each stereotype.

Language Facts

Classes and functions

  • Interfaces and enums get their stereotypes with the options -i and -e.
  • Each component of a record has an accessor of the same name. A call to such an accessor that the record leaves implicit, such as high() for the component high, reads the object. span.high() on a data member span of a record type reads the data member.
  • Each method that the body of an enum constant defines counts as a method of the enum. A call to a method that the enum declares takes precedence over the methods of the constant bodies. An abstract method of the enum has no definition. A call to such a method thus reaches no method with stereotypes, even where a constant body defines the method.

Data members

  • A method reaches its object through this.
  • A member class without static counts the fields of its enclosing instances as its own data members. Outer.this names the enclosing instance of the class Outer. Outer.this.field therefore counts as a data member as well.
  • Inside a local or an anonymous class, this and super name the object of that class, while Outer.this still names the object of the enclosing class. this.x thus names the member x of the local class and counts as a local variable of the enclosing method. A call through this or super is a call on an object other than the object of that method, as is a call without an object of a method that the local class defines.

Types and variables

  • A parameter of a type that is not primitive shares its object with the caller. A parameter of variable arity, such as int... values, counts as the array parameter int[] values. A write to one of its elements thus reaches the caller, as a write to an element of any array parameter does.
  • Imports decide which class of the archive a type name refers to. An import of one type, such as import model.Tag;, takes precedence over the types of the other files of the package of the current file, while an import of every type of a package, such as import model.*;, yields to these types.
  • Stereocode reads a type without its annotations, as int for @Range(min = 0) int. The arguments of an annotation inside a method body count as no read and no call.
  • The variable of a type pattern, such as found of other instanceof Gauge found, is a local variable of the type that the pattern names.

Calls

  • A call without an object whose name matches no method of the type or of its ancestors in the archive is a call to the object itself in two cases. First, the name is an accessor of Object with its number of arguments, namely equals, hashCode, toString, getClass, or clone. Second, the type has a parent outside the archive. Such a call stays a call of a free function where its name is a static method that the type can access, such as a static method of an ancestor or of a static import.
  • In a member class without static, a call without an object names the method of the nearest type that has a method of that name. The search runs through the class and its ancestors first and then through the type of each enclosing instance with its ancestors, from the innermost outward. Outer.this.m() names a method of the enclosing instance of the type Outer.
  • Greeter.super.greet() calls the method greet of the interface Greeter on the object itself.
  • The creation of an object of an anonymous class, such as new Runnable() { ... }, is a constructor call of its parent type.

Built-in Lists

Stereocode reads four built-in lists for Java. The list files of the options -p, -c, -s, and -q add entries to these lists under the section [Java], as the README states. Each list below opens with a click.

Primitive types (19 entries)

A type of this list makes no method a collaborator and no return type of a factory.

Boolean, boolean, Byte, byte, char, Character, Double, double, Float, float, int, Integer, Long, long, Short, short, String, Void, void

Ignored calls (5 entries)

The rules ignore a call of these names, also after a qualifier.

System.err.println, System.exit, System.out.print, System.out.printf, System.out.println

Specifiers and containers (44 entries)

Stereocode strips these entries from a written type before it reads the names of the type. A container counts by the types of its elements. Each entry is a regular expression, such as \.\.\. for ....

<, >, @\w+, \.\.\., \?, abstract, ArrayDeque, ArrayList, Collection, default, Deque, EnumMap, EnumSet, extends, final, HashMap, HashSet, Hashtable, Iterable, Iterator, LinkedHashMap, LinkedHashSet, LinkedList, List, Map, native, PriorityQueue, private, protected, public, Queue, Set, SortedMap, SortedSet, Stack, static, strictfp, super, synchronized, transient, TreeMap, TreeSet, Vector, volatile

Query methods (10 entries)

A call of these methods only reads the variable that the call is on.

contains, containsKey, equals, get, getClass, hashCode, isEmpty, length, size, toString

Examples

Each example below is the declaration of an element from the stereotype cases of Stereocode, whose expected stereotypes are written by hand in @stereotype comments. Each link opens the case on the branch develop. The second column gives every stereotype of the element. A stereotype without an example has no case in Java.

Methods

Stereotype Stereotypes of the element Declaration
get get public double getCelsius() { return celsius; }
predicate predicate boolean isZero(int i) { return arr[i] == 0; }
property property double offset() { return fahrenheit() - 32; }
void-accessor void-accessor void dequantize(int[] dataUnit, int iComp)
set set void level(double value) { degrees = value; }
command command void fill() { level = capacity; capacity++; }
non-void-command non-void-command default int twice() { return area() * 2; }
factory factory collaborator stateless default Widget make() { return new Widget(); }
collaborator property collaborator int scaled(Scale scale) { return value * 2; }
controller controller void paint(Widget widget) { widget.poke(level); }
wrapper wrapper void copyToPart() { Store.shared().b = b; }
incidental incidental void warn(int v) { System.err.println(v); }
stateless controller stateless void run() { Flowable.just(1).subscribe(); }
empty empty public void close() { /* nothing to release */ }
constructor constructor protected Shape(int count) { sides = count; }
copy-constructor copy-constructor Vertex(Vertex other) { kind = other.kind; }
destructor No case
unclassified unclassified void print() { System.out.println(count); }

TABLE 1. Examples of the method stereotypes in Java.

Free functions

Stereotype Stereotypes of the element Declaration
main main public static void main(String[] args) { report(args.length); }
predicate predicate public static boolean isEven(int value) { return value % 2 == 0; }
property property static int twice(int value) { return 2 * value; }
global-command global-command static void reset() { shown = 0; }
command command static void paramCStyle(int a[]) { a[0] = 1; }
factory property factory static Stack create(int start) { Stack made = new Stack(start); return made; }
literal literal public static int answer() { return 42; }
wrapper wrapper static void show() { Journal.write(NAME); }
empty empty public static void noop(int value) { }
unclassified unclassified public static void print(int value) { System.out.println(value); }

TABLE 2. Examples of the free-function stereotypes in Java, which the option -f assigns.

Types

Stereotype Stereotypes of the element Declaration
boundary boundary class Exporter
commander commander small-interface interface Shape
controller controller class Spooler
data-class data-class class Pair
data-enum data-provider data-enum small-enum enum Level
data-interface data-provider data-interface small-interface interface Chain
data-provider data-provider class Circle
data-record data-provider data-record small-record record Size(int width)
degenerate degenerate small-record record Pair(int left, int right)
empty empty class Tag
entity entity boundary class Measure
factory factory controller class WidgetFactory
large-class large-class class Box
large-enum large-enum enum Mode
large-interface large-interface interface Shape
large-record large-record record Track(int width, java.util.List<String> items)
lazy-class lazy-class class Settings
lazy-enum lazy-enum enum Phase
lazy-interface data-provider lazy-interface interface Lazy
lazy-record data-provider lazy-record small-record record Trail(int length)
minimal-entity minimal-entity commander class Counter
pure-controller pure-controller class Dispatcher
small-class small-class class Clock
small-enum data-provider small-enum enum Mode { ON, OFF;
small-interface degenerate small-interface interface Visitor
small-record data-provider small-record record Pair(int left, int right)
unclassified unclassified class Large22

TABLE 3. Examples of the class stereotypes in Java, where large-class, lazy-class, data-class, and small-class of a type of another kind take that kind in place of class, such as data-struct.

Clone this wiki locally