Integrating Speciﬁcation and Documentation in an Object-Oriented Language

class Shape protected attr x, y : integer; public abstract method boundingBox : Rectangle; public method area : integer return 0 public method move (dx, dy : integer) begin x : = x + dx; y := y + dy end initialization(x, y : integer) begin self.x := x; self.y := y end end class Rectangle inherit Shape protected attr w, h : integer; public method boundingBox : Rectangle return new Rectangle(x, y, w, h) public method area : integer return w * h initialization(x, y, w, h : integer) begin super.initialization(x, y); self.w := w; self.h := h end end class Polygon extend Rectangle implement Shape protected attr i, n : integer; attr Xs : array of integer; attr Ys : array of integer; invariant n> 0 initialization(Xs, Ys : array of integer, n: integer) begin self.n := n; x := Xs[0]; y := Ys[0]; w := (MAX i | 0 ≤ i < n •Xs[i])− (MIN i | 0 ≤ i < n •Xs[i]); h := (MAX i | 0 ≤ i < n • Y s[i])− (MIN i | 0 ≤ i < n • Y s[i]); i : = 0; while i < n-1 do self.Xs[i], self.Ys[i] := Xs[i+1], Ys[i+1]; end public method move (dx, dy : integer) post∀ i | 0 ≤ i < n− 1 • (dx = old Xs[i] Xs[i]) ∧ (dy = old Ys[i] -Ys[i]) begin super.move(dx, dy); i := 0; while i < n 1 do Xs[i], Ys[i] := Xs[i] dx, Ys[i] dy end public method area : integer . end end 4. DOCUMENTATION GENERATION Lime’s support for automatic documentation generation was influenced by early work on literate programming and documentation system likeJavadocand Doxygen. Both Javadoc and Doxygen generate on-line interface documentation in HTML format. The design for LimeD is along those lines: • LimeD generates documentation directly from the source code; • LimeD provides a behavioral interface specification, not only a syntactic interface; • LimeD shows the subclass and subtype hierarchies. For a project, LimeD generates a summary page and a page for each individual class. For quickly accessing class documentation, a list with linked indices for all classes is generated and acts as a navigation menu. The documentation of each individual class starts with the class description extracted from the documentation comment in the source file. Documentation comments can contain embedded HTML code. The document may contain the following parts: • Class Invariant with the invariant defined in the current class and the invariants inherited from all supertypes. The inherited invariants are conjoined to generate a single expression. All the information is extracted from the current class and from the Java class files of all supertypes. • Class Hierarchy displayed graphically; Lime supports single subclassing. • Type Hierarchy presented as an indented list; Lime supports multiple subclassing. • Attribute with all non-private attributes defined in the current class. • Inherited Attribute with all attributes inherited from superclasses and supertypes. • Method contains all methods defined in the current class. It gives the method signature and the precondition and postcondition defined in the current class. If the method redefines or implements a method of a supertype, it also gives the precondition and postcondition defined in supertypes. These are extracted from the Java classfiles of all supertypes. • Inherited Method contains all inherited methods. It gives the method signature, precondition and postcondition.