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. This page gives the forms that the facts of these rules take in Java, the built-in lists that Stereocode reads for Java, and one labeled example of each stereotype. The section Data Members and Calls states in full how Stereocode reads data members, types, returned values, and calls in Java.
- A method reaches its object through
this. A member class withoutstaticcounts the data members of its enclosing instances as its own, whileOuter.thisnames the enclosing instance of the classOuter. - A parameter of a type that is not primitive shares its object with the caller, as does a variadic parameter such as
int... out. - Each component of a record has an accessor of its name. Each method of the body of an enum constant counts as a method of the enum.
- Inside a local or an anonymous class,
thisandsupername the object of that class.new Runnable() { }creates an object. - A call without an object to a method that no type of the archive defines is a call to the object itself when its name is an accessor of
Objectwith its number of arguments, namelyequals,hashCode,toString,getClass, orclone. The same holds when the class has a parent outside the archive. - Interfaces and enums get their stereotypes with the options
-iand-e.
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, as std::exit for exit and System.Console.WriteLine for Console.WriteLine.
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.