Class AScene

java.lang.Object
org.checkerframework.afu.scenelib.el.AScene
All Implemented Interfaces:
Cloneable

public class AScene extends Object implements Cloneable
An AScene (annotated scene) represents the annotations on a set of Java classes and packages along with the definitions of some or all of the annotation types used.

Each client of the annotation library may wish to use its own representation for certain kinds of annotations instead of a simple name-value map; thus, a layer of abstraction in the storage of annotations was introduced.

AScenes and many AElements can contain other AElements. When these objects are created, their collections of subelements are empty. In order to associate an annotation with a particular Java element in an AScene, one must first ensure that an appropriate AElement exists in the AScene. To this end, the maps of subelements have a vivify method. Calling vivify to access a particular subelement will return the subelement if it already exists; otherwise it will create and then return the subelement. (Compare to vivification in Perl.) For example, the following code will obtain an AMethod representing Foo.bar in the AScene s, creating it if it did not already exist:

 AMethod<A> m = s.classes.getVivify("Foo").methods.getVivify("bar");
 

Then one can add an annotation to the method:

 m.annotationsHere.add(new Annotation(
     new AnnotationDef(taintedDef, RetentionPolicy.RUNTIME, true),
     new Annotation(taintedDef, Collections.emptyMap())
 ));
 
  • Field Details

    • packages

      public final VivifyingMap<String,AElement> packages
      This scene's annotated packages; map key is package name.
    • imports

      public final Map<String,Set<String>> imports
      Contains for each annotation type a set of imports to be added to the source if the annotation is inserted with the "abbreviate" option on.
      Key: fully-qualified name of an annotation. e.g. for @com.foo.Bar(x) , the fully-qualified name is com.foo.Bar
      Value: names of packages this annotation needs
    • classes

      public final VivifyingMap<String,AClass> classes
      This scene's annotated classes; map key is class name.
  • Constructor Details

    • AScene

      public AScene()
      Creates a new AScene with no classes or packages.
    • AScene

      public AScene(AScene scene)
      Copy constructor for AScene.
      Parameters:
      scene - the scene to make a copy of
  • Method Details

    • clone

      public AScene clone()
      Overrides:
      clone in class Object
    • equals

      public boolean equals(Object o)
      Returns true if this AScene equals o; the commentary and the cautionary remarks on AElement.equals(Object) also apply to equals(Object).
      Overrides:
      equals in class Object
    • equals

      public boolean equals(AScene o)
      Returns true if this AScene equals o; a slightly faster variant of equals(Object) for when the argument is statically known to be another nonnull AScene.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getClasses

      public Map<String,AClass> getClasses()
      Fetch the classes in this scene, represented as AClass objects.
      Returns:
      an immutable map from binary names to AClass objects
    • isEmpty

      public boolean isEmpty()
      Returns true if this AScene is empty.
    • prune

      public void prune()
      Removes empty subelements of this AScene depth-first.
    • unparse

      public String unparse()
      Returns a string representation.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • checkClone

      public static void checkClone(AScene s0, AScene s1)
      Checks that the arguments are clones of one another.

      Throws an exception if the arguments 1) are the same reference; 2) are not equal() in both directions; or 3) contain corresponding elements that meet either of the preceding two conditions.

      Parameters:
      s0 - the first AScene to compare
      s1 - the second Ascene to compare
    • checkCloneMap

      public static <K, V extends AElement> void checkCloneMap(VivifyingMap<K,V> m0, VivifyingMap<K,V> m1)
      Throw exception if m0 == m1 or !m0.equals(m1). (See checkClone(AScene, AScene) for explanation.)
      Type Parameters:
      K - the type of map keys
      V - the type of map values
      Parameters:
      m0 - the first map to compare
      m1 - the second map to compare
    • main

      public static void main(String[] args)
      Temporary main for easy testing on JAIFs.
      Parameters:
      args - command-line arguments