Repository navigation
Java
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.
- Interfaces and enums get their stereotypes with the options
-iand-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 componenthigh, reads the object.span.high()on a data memberspanof 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.
- A method reaches its object through
this. - A member class without
staticcounts the fields of its enclosing instances as its own data members.Outer.thisnames the enclosing instance of the classOuter.Outer.this.fieldtherefore counts as a data member as well. - Inside a local or an anonymous class,
thisandsupername the object of that class, whileOuter.thisstill names the object of the enclosing class.this.xthus names the memberxof the local class and counts as a local variable of the enclosing method. A call throughthisorsuperis 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.
- 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 parameterint[] 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 asimport model.*;, yields to these types. - Stereocode reads a type without its annotations, as
intfor@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
foundofother instanceof Gauge found, is a local variable of the type that the pattern names.
- 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
Objectwith its number of arguments, namelyequals,hashCode,toString,getClass, orclone. 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 typeOuter. -
Greeter.super.greet()calls the methodgreetof the interfaceGreeteron the object itself. - The creation of an object of an anonymous class, such as
new Runnable() { ... }, is a constructor call of its parent type.
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
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.
TABLE 1. Examples of the method stereotypes in Java.
| 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.
| 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.