net.percederberg.grammatica.code
Class CodeElement

java.lang.Object
  |
  +--net.percederberg.grammatica.code.CodeElement
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
CodeElementContainer, CSharpComment, CSharpConstructor, CSharpMethod, CSharpUsing, JavaComment, JavaConstructor, JavaImport, JavaMethod, JavaPackage, JavaVariable

public abstract class CodeElement
extends java.lang.Object
implements java.lang.Comparable

The abstract base class for all code elements. The code element classes handles some source code construct and allows printing and comparing it to other constructs.

Version:
1.0
Author:
Per Cederberg,

Constructor Summary
CodeElement()
           
 
Method Summary
abstract  int category()
          Returns a numeric category number for the code element.
 int compareTo(java.lang.Object obj)
          Compares this object to another one.
abstract  void print(java.io.PrintWriter out, CodeStyle style, int indent)
          Prints the code element to the specified output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeElement

public CodeElement()
Method Detail

compareTo

public int compareTo(java.lang.Object obj)
Compares this object to another one. The comparison is based on the code element category, reporting equality between elements within the same category. Objects not being code elements will cause zero (0) to be returned.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - the object to compare to
Returns:
negative if this object preceeds the other one, zero (0) if the objects are equal, or positive if this object succeeds the other one

category

public abstract int category()
Returns a numeric category number for the code element. A lower category number implies that the code element should be placed before code elements with a higher category number within a declaration.

Returns:
the category number

print

public abstract void print(java.io.PrintWriter out,
                           CodeStyle style,
                           int indent)
Prints the code element to the specified output stream.

Parameters:
out - the output stream
style - the code style to use
indent - the indentation level