|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object scale.annot.Annotation
public abstract class Annotation
Annotations are a flexible mechanism for attaching information to certain class instances such as the nodes of a program representation graph.
$Id: Annotation.java,v 1.53 2007-08-27 18:37:27 burrill Exp $
Copyright 2008 by the
Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.
An annotation should be used to specify information whose lack will not result in an invalid compilation. If the information is needed for validity, it should be represented as a member field of a class instead. It should not be possible to reach from the annotation instance to the object that is annotated .
The same annotation mechanism is used for both Clef and Score and
all classes derived from the Root
class.
Annotations are not an efficient (in either space or time) mechanism for representing a given piece of information, but are flexible enough to represent varied information.
Annotations represent varied information. Some information will be immutable, and so the annotation will not change (i.e., be deleted) over time. Other information is transitory and will need to be deleted, perhaps even en masse. The annotation handling mechanism has the following capabilities:
All annotations inherit from the abstract Annotation class. Each sub-class has a static method annotationKey that returns the key for that class of annotation. Each sub-class has a static create method that is called to attach the annotation of that type to a node. This annotation instance may be a new instance or it may be an already existing instance. The constructor method in every annoation sub-class is private in order to insure that the create method is always used.
The create method takes a minimum of three arguments.
Support
,
Creator
Field Summary | |
---|---|
static java.lang.String[] |
knownAnnotations
This is a list of all the annotations classes known by the Scale system. |
Constructor Summary | |
---|---|
protected |
Annotation(Creator creator,
Support support)
Create an annotation. |
Method Summary | |
---|---|
void |
addNode(AnnotationInterface n)
Associates a node with this annotation. |
static java.util.Enumeration<Annotation> |
allAnnotations(AnnotationInterface n)
Return an enumeration of all annotations in the annotation container. |
static java.util.Enumeration<Annotation> |
allMatchingAnnotations(java.lang.Object akey,
AnnotationInterface n)
Return an enumeration of all annotations with the specified key in the annotation container. |
static java.lang.Object |
annotationKey()
All sub-classes should define annotationKey() to return a unique object for the key. |
java.lang.String |
annotationName()
For display and debugging. |
boolean |
equals(java.lang.Object o)
Return true if both annotations have the same key, creator, support, etc. |
abstract boolean |
equivalent(Annotation a)
Return true if the annotations are equivalent. |
static Annotation |
getAnnotation(java.lang.Object akey,
AnnotationInterface n)
Returns a single instance of the annotation with the given key from the annotation container. |
Creator |
getCreator()
Return the creator of the annotation. |
DColor |
getDisplayColorHint()
Return a String specifying the color to use for coloring this node in a graphical display. |
java.lang.String |
getDisplayLabel()
Return a String suitable for labeling this node in a graphical display. |
java.lang.String |
getDisplayName()
Return a unique name suitable for display. |
DShape |
getDisplayShapeHint()
Return a String specifying a shape to use when drawing this node in a graphical display. |
abstract java.lang.Object |
getKey()
Return the key for this annotation class. |
int |
getNodeID()
Return the node label. |
Support |
getSupport()
Return the support of the annotation. |
static boolean |
hasAnnotation(java.lang.Object akey,
AnnotationInterface n)
Test if the indicated annotation kind is in the container. |
static boolean |
hasEqualAnnotation(Annotation a,
AnnotationInterface n)
Test if the equivalent annotation is in the container. |
int |
hashCode()
|
abstract boolean |
isUnique()
Returns a flag indicating if a node is permitted to have multiple instances of this annotation type. |
static void |
removeAllAnnotationTables()
Remove all annotations from static lookup tables. |
void |
removeNode(AnnotationInterface n)
Removes an association of a node with this annotation. |
static void |
removeNode(AnnotationInterface n,
java.lang.Object key)
Removes an association of a node with all annotations having this key. |
boolean |
sameSupport(Creator c,
Support sup)
Return true if the annotation has this creator and this support. |
java.lang.String |
toString()
Return a string representation of the annotation. |
static java.lang.String |
toStringAnnotations(AnnotationInterface n)
Convert the container of annotations to a string representation. |
java.lang.String |
toStringClass()
Convert the class name of this node to a string representation. |
abstract java.lang.String |
toStringSpecial()
Return a string representation of the additioanl internal state of the annotation. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String[] knownAnnotations
Constructor Detail |
---|
protected Annotation(Creator creator, Support support)
creator
- indication of what Scale component created this
annotationsupport
- the support for this annotationCreator
,
Support
Method Detail |
---|
public static java.lang.Object annotationKey()
public abstract java.lang.Object getKey()
this.annotationKey()returns the wrong key when used in a parent class method, each sub-class must implement a method to return its key.
public Object getKey() { return ThisClass.annotationKey(); }
public final java.lang.String annotationName()
public final void addNode(AnnotationInterface n)
na = annotation.addNode(this, na);
n
- node being addedpublic static final void removeNode(AnnotationInterface n, java.lang.Object key) throws NoSuchElementException
n
- node being disassociatedkey
- is the annotation key
NoSuchElementException
- tried to delete a node which is
not associated with this annotation.public final void removeNode(AnnotationInterface n) throws NoSuchElementException
n
- node being disassociated
NoSuchElementException
- tried to delete a node which is
not associated with this annotation.public final Support getSupport()
public final Creator getCreator()
public abstract boolean isUnique()
public abstract boolean equivalent(Annotation a)
a
- the other annotationpublic final boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the other annotationpublic int hashCode()
hashCode
in class java.lang.Object
public final boolean sameSupport(Creator c, Support sup)
public final java.lang.String toStringClass()
public final java.lang.String toString()
toString
in class java.lang.Object
public abstract java.lang.String toStringSpecial()
public static final Annotation getAnnotation(java.lang.Object akey, AnnotationInterface n)
null
.
akey
- the annotation keyn
- is the node with annotations
null
public static final boolean hasAnnotation(java.lang.Object akey, AnnotationInterface n)
akey
- the annotation keyn
- is the node with annotations
public static final boolean hasEqualAnnotation(Annotation a, AnnotationInterface n)
Creator
and Support
are not
used in equivalence testing.
a
- is the annotationn
- is the node with annotations
public static final java.util.Enumeration<Annotation> allAnnotations(AnnotationInterface n)
n
- is the node with annotations
public static final java.util.Enumeration<Annotation> allMatchingAnnotations(java.lang.Object akey, AnnotationInterface n)
akey
- the annotation keyn
- is the node with annotations
public static final java.lang.String toStringAnnotations(AnnotationInterface n)
n
- is the node with annotationspublic int getNodeID()
public java.lang.String getDisplayName()
getDisplayName
in interface DisplayNode
public java.lang.String getDisplayLabel()
getDisplayLabel
in interface DisplayNode
public DColor getDisplayColorHint()
getDisplayColorHint
in interface DisplayNode
DColor
public DShape getDisplayShapeHint()
getDisplayShapeHint
in interface DisplayNode
DShape
public static void removeAllAnnotationTables()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |