All Downloads are FREE. Search and download functionalities are using the official Maven repository.

soot.JastAddJ.Annotation Maven / Gradle / Ivy

/* This file was generated with JastAdd2 (http://jastadd.org) version R20130212 (r1031) */
package soot.JastAddJ;

import java.util.HashSet;
import java.io.File;
import java.util.*;
import beaver.*;
import java.util.ArrayList;
import java.util.zip.*;
import java.io.*;
import java.io.FileNotFoundException;
import java.util.Collection;
import soot.*;
import soot.util.*;
import soot.jimple.*;
import soot.coffi.ClassFile;
import soot.coffi.method_info;
import soot.coffi.CONSTANT_Utf8_info;
import soot.tagkit.SourceFileTag;
import soot.coffi.CoffiMethodSource;

/**
 * @production Annotation : {@link Modifier} ::= <ID:String> {@link Access} {@link ElementValuePair}*;
 * @ast node
 * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.ast:6
 */
public class Annotation extends Modifier implements Cloneable {
  /**
   * @apilevel low-level
   */
  public void flushCache() {
    super.flushCache();
    decl_computed = false;
    decl_value = null;
  }
  /**
   * @apilevel internal
   */
  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Annotation clone() throws CloneNotSupportedException {
    Annotation node = (Annotation)super.clone();
    node.decl_computed = false;
    node.decl_value = null;
    node.in$Circle(false);
    node.is$Final(false);
    return node;
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Annotation copy() {
    try {
      Annotation node = (Annotation) clone();
      node.parent = null;
      if(children != null)
        node.children = (ASTNode[]) children.clone();
      return node;
    } catch (CloneNotSupportedException e) {
      throw new Error("Error: clone not supported for " +
        getClass().getName());
    }
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Annotation fullCopy() {
    Annotation tree = (Annotation) copy();
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        ASTNode child = (ASTNode) children[i];
        if(child != null) {
          child = child.fullCopy();
          tree.setChild(child, i);
        }
      }
    }
    return tree;
  }
  /**
   * @ast method 
   * @aspect Annotations
   * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:41
   */
  public void checkModifiers() {
    super.checkModifiers();
    if(decl() instanceof AnnotationDecl) {
      AnnotationDecl T = (AnnotationDecl)decl();
      Annotation m = T.annotation(lookupType("java.lang.annotation", "Target"));
      if(m != null && m.getNumElementValuePair() == 1 && m.getElementValuePair(0).getName().equals("value")) {
        ElementValue v = m.getElementValuePair(0).getElementValue();
        //System.out.println("ElementValue: \n" + v.dumpTree());
        //System.out.println("Annotation: \n" + dumpTree());
        if(!v.validTarget(this))
          error("annotation type " + T.typeName() + " is not applicable to this kind of declaration");
      }
    }
  }
  /**
   * @ast method 
   * @aspect Annotations
   * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:383
   */
  public void typeCheck() {
    if(!decl().isAnnotationDecl()) {
      /* TypeName names the annotation type corresponding to the annotation. It is a
      compile-time error if TypeName does not name an annotation type.*/
      if(!decl().isUnknown())
        error(decl().typeName() + " is not an annotation type");
    } else {
      TypeDecl typeDecl = decl();
      /* It is a compile-time error if a declaration is annotated with more than one
      annotation for a given annotation type.*/
      if(lookupAnnotation(typeDecl) != this)
        error("duplicate annotation " + typeDecl.typeName());
      /* Annotations must contain an element-value pair for every element of the
      corresponding annotation type, except for those elements with default
      values, or a compile-time error occurs. Annotations may, but are not
      required to, contain element-value pairs for elements with default values.*/
      for(int i = 0; i < typeDecl.getNumBodyDecl(); i++) {
        if(typeDecl.getBodyDecl(i) instanceof MethodDecl) {
          MethodDecl decl = (MethodDecl)typeDecl.getBodyDecl(i);
          if(elementValueFor(decl.name()) == null && (!(decl instanceof AnnotationMethodDecl) || !((AnnotationMethodDecl)decl).hasDefaultValue()))
            error("missing value for " + decl.name());
        }
      }
      /* The Identifier in an ElementValuePair must be the simple name of one of the
      elements of the annotation type identified by TypeName in the containing
      annotation. Otherwise, a compile-time error occurs. (In other words, the
      identifier in an element-value pair must also be a method name in the interface
      identified by TypeName.) */
      for(int i = 0; i < getNumElementValuePair(); i++) {
        ElementValuePair pair = getElementValuePair(i);
        if(typeDecl.memberMethods(pair.getName()).isEmpty())
          error("can not find element named " + pair.getName() + " in " + typeDecl.typeName());
      }
    }
    checkOverride();
  }
  /**
   * @ast method 
   * @aspect Annotations
   * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:582
   */
  public void toString(StringBuffer s) {
    s.append("@");
    getAccess().toString(s);
    s.append("(");
    for(int i = 0; i < getNumElementValuePair(); i++) {
      if(i != 0)
        s.append(", ");
      getElementValuePair(i).toString(s);
    }
    s.append(")");
  }
  /**
   * @ast method 
   * @aspect AnnotationsCodegen
   * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag:305
   */
  public void appendAsAttributeTo(Collection list) {
      soot.tagkit.AnnotationTag tag = new soot.tagkit.AnnotationTag(decl().typeDescriptor(), getNumElementValuePair());
      ArrayList elements = new ArrayList(getNumElementValuePair());
      for(int i = 0; i < getNumElementValuePair(); i++) {
        String name = getElementValuePair(i).getName();
        ElementValue value = getElementValuePair(i).getElementValue();
        value.appendAsAttributeTo(elements, name);
      }
      tag.setElems(elements);
      list.add(tag);
  }
  /**
   * @ast method 
   * 
   */
  public Annotation() {
    super();


  }
  /**
   * Initializes the child array to the correct size.
   * Initializes List and Opt nta children.
   * @apilevel internal
   * @ast method
   * @ast method 
   * 
   */
  public void init$Children() {
    children = new ASTNode[2];
    setChild(new List(), 1);
  }
  /**
   * @ast method 
   * 
   */
  public Annotation(String p0, Access p1, List p2) {
    setID(p0);
    setChild(p1, 0);
    setChild(p2, 1);
  }
  /**
   * @ast method 
   * 
   */
  public Annotation(beaver.Symbol p0, Access p1, List p2) {
    setID(p0);
    setChild(p1, 0);
    setChild(p2, 1);
  }
  /**
   * @apilevel low-level
   * @ast method 
   * 
   */
  protected int numChildren() {
    return 2;
  }
  /**
   * @apilevel internal
   * @ast method 
   * 
   */
  public boolean mayHaveRewrite() {
    return false;
  }
  /**
   * Replaces the lexeme ID.
   * @param value The new value for the lexeme ID.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public void setID(String value) {
    tokenString_ID = value;
  }
  /**
   * JastAdd-internal setter for lexeme ID using the Beaver parser.
   * @apilevel internal
   * @ast method 
   * 
   */
  public void setID(beaver.Symbol symbol) {
    if(symbol.value != null && !(symbol.value instanceof String))
      throw new UnsupportedOperationException("setID is only valid for String lexemes");
    tokenString_ID = (String)symbol.value;
    IDstart = symbol.getStart();
    IDend = symbol.getEnd();
  }
  /**
   * Retrieves the value for the lexeme ID.
   * @return The value for the lexeme ID.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public String getID() {
    return tokenString_ID != null ? tokenString_ID : "";
  }
  /**
   * Replaces the Access child.
   * @param node The new node to replace the Access child.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public void setAccess(Access node) {
    setChild(node, 0);
  }
  /**
   * Retrieves the Access child.
   * @return The current node used as the Access child.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public Access getAccess() {
    return (Access)getChild(0);
  }
  /**
   * Retrieves the Access child.
   * 

This method does not invoke AST transformations.

* @return The current node used as the Access child. * @apilevel low-level * @ast method * */ public Access getAccessNoTransform() { return (Access)getChildNoTransform(0); } /** * Replaces the ElementValuePair list. * @param list The new list node to be used as the ElementValuePair list. * @apilevel high-level * @ast method * */ public void setElementValuePairList(List list) { setChild(list, 1); } /** * Retrieves the number of children in the ElementValuePair list. * @return Number of children in the ElementValuePair list. * @apilevel high-level * @ast method * */ public int getNumElementValuePair() { return getElementValuePairList().getNumChild(); } /** * Retrieves the number of children in the ElementValuePair list. * Calling this method will not trigger rewrites.. * @return Number of children in the ElementValuePair list. * @apilevel low-level * @ast method * */ public int getNumElementValuePairNoTransform() { return getElementValuePairListNoTransform().getNumChildNoTransform(); } /** * Retrieves the element at index {@code i} in the ElementValuePair list.. * @param i Index of the element to return. * @return The element at position {@code i} in the ElementValuePair list. * @apilevel high-level * @ast method * */ @SuppressWarnings({"unchecked", "cast"}) public ElementValuePair getElementValuePair(int i) { return (ElementValuePair)getElementValuePairList().getChild(i); } /** * Append an element to the ElementValuePair list. * @param node The element to append to the ElementValuePair list. * @apilevel high-level * @ast method * */ public void addElementValuePair(ElementValuePair node) { List list = (parent == null || state == null) ? getElementValuePairListNoTransform() : getElementValuePairList(); list.addChild(node); } /** * @apilevel low-level * @ast method * */ public void addElementValuePairNoTransform(ElementValuePair node) { List list = getElementValuePairListNoTransform(); list.addChild(node); } /** * Replaces the ElementValuePair list element at index {@code i} with the new node {@code node}. * @param node The new node to replace the old list element. * @param i The list index of the node to be replaced. * @apilevel high-level * @ast method * */ public void setElementValuePair(ElementValuePair node, int i) { List list = getElementValuePairList(); list.setChild(node, i); } /** * Retrieves the ElementValuePair list. * @return The node representing the ElementValuePair list. * @apilevel high-level * @ast method * */ public List getElementValuePairs() { return getElementValuePairList(); } /** * Retrieves the ElementValuePair list. *

This method does not invoke AST transformations.

* @return The node representing the ElementValuePair list. * @apilevel low-level * @ast method * */ public List getElementValuePairsNoTransform() { return getElementValuePairListNoTransform(); } /** * Retrieves the ElementValuePair list. * @return The node representing the ElementValuePair list. * @apilevel high-level * @ast method * */ @SuppressWarnings({"unchecked", "cast"}) public List getElementValuePairList() { List list = (List)getChild(1); list.getNumChild(); return list; } /** * Retrieves the ElementValuePair list. *

This method does not invoke AST transformations.

* @return The node representing the ElementValuePair list. * @apilevel low-level * @ast method * */ @SuppressWarnings({"unchecked", "cast"}) public List getElementValuePairListNoTransform() { return (List)getChildNoTransform(1); } /** * @ast method * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java7Frontend/Override.jrag:20 */ public void checkOverride() { if (decl().fullName().equals("java.lang.Override") && enclosingBodyDecl() instanceof MethodDecl) { MethodDecl method = (MethodDecl)enclosingBodyDecl(); TypeDecl host = method.hostType(); SimpleSet ancestors = host.ancestorMethods(method.signature()); boolean found = false; for (Iterator iter = ancestors.iterator(); iter.hasNext(); ) { MethodDecl decl = (MethodDecl)iter.next(); if (method.overrides(decl)) { found = true; break; } } if (!found) { TypeDecl typeObject = lookupType("java.lang", "Object"); SimpleSet overrides = typeObject.localMethodsSignature(method.signature()); if (overrides.isEmpty() || !((MethodDecl) overrides.iterator().next()).isPublic()) error("method does not override a method from a supertype"); } } } /** * @apilevel internal */ protected boolean decl_computed = false; /** * @apilevel internal */ protected TypeDecl decl_value; /** * @attribute syn * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:420 */ @SuppressWarnings({"unchecked", "cast"}) public TypeDecl decl() { if(decl_computed) { return decl_value; } ASTNode$State state = state(); int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); decl_value = decl_compute(); if(isFinal && num == state().boundariesCrossed) decl_computed = true; return decl_value; } /** * @apilevel internal */ private TypeDecl decl_compute() { return getAccess().type(); } /** * @attribute syn * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:432 */ public ElementValue elementValueFor(String name) { ASTNode$State state = state(); try { for(int i = 0; i < getNumElementValuePair(); i++) { ElementValuePair pair = getElementValuePair(i); if(pair.getName().equals(name)) return pair.getElementValue(); } return null; } finally { } } /** * @attribute syn * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:514 */ public TypeDecl type() { ASTNode$State state = state(); try { return getAccess().type(); } finally { } } /* An annotation on an annotation type declaration is known as a meta-annotation. An annotation type may be used to annotate its own declaration. More generally, circularities in the transitive closure of the "annotates" relation are permitted. For example, it is legal to annotate an annotation type declaration with another annotation type, and to annotate the latter type's declaration with the former type. (The pre-defined meta-annotation types contain several such circularities.) Comment: no problems with reference attributes. * @attribute syn * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:543 */ public boolean isMetaAnnotation() { ASTNode$State state = state(); try { return hostType().isAnnotationDecl(); } finally { } } /** * @attribute syn * @aspect AnnotationsCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag:143 */ public boolean isRuntimeVisible() { ASTNode$State state = state(); try { Annotation a = decl().annotation(lookupType("java.lang.annotation", "Retention")); if(a == null) return false; ElementConstantValue value = (ElementConstantValue)a.getElementValuePair(0).getElementValue(); Variable v = value.getExpr().varDecl(); return v != null && v.name().equals("RUNTIME"); } finally { } } /** * @attribute syn * @aspect AnnotationsCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag:153 */ public boolean isRuntimeInvisible() { ASTNode$State state = state(); try { Annotation a = decl().annotation(lookupType("java.lang.annotation", "Retention")); if(a == null) return true; // default bahavior if not annotated ElementConstantValue value = (ElementConstantValue)a.getElementValuePair(0).getElementValue(); Variable v = value.getExpr().varDecl(); return v != null && v.name().equals("CLASS"); } finally { } } /** * @attribute inh * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:55 */ @SuppressWarnings({"unchecked", "cast"}) public TypeDecl lookupType(String packageName, String typeName) { ASTNode$State state = state(); TypeDecl lookupType_String_String_value = getParent().Define_TypeDecl_lookupType(this, null, packageName, typeName); return lookupType_String_String_value; } /** * @attribute inh * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:69 */ @SuppressWarnings({"unchecked", "cast"}) public boolean mayUseAnnotationTarget(String name) { ASTNode$State state = state(); boolean mayUseAnnotationTarget_String_value = getParent().Define_boolean_mayUseAnnotationTarget(this, null, name); return mayUseAnnotationTarget_String_value; } /** * @attribute inh * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:258 */ @SuppressWarnings({"unchecked", "cast"}) public BodyDecl enclosingBodyDecl() { ASTNode$State state = state(); BodyDecl enclosingBodyDecl_value = getParent().Define_BodyDecl_enclosingBodyDecl(this, null); return enclosingBodyDecl_value; } /** * @attribute inh * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:422 */ @SuppressWarnings({"unchecked", "cast"}) public Annotation lookupAnnotation(TypeDecl typeDecl) { ASTNode$State state = state(); Annotation lookupAnnotation_TypeDecl_value = getParent().Define_Annotation_lookupAnnotation(this, null, typeDecl); return lookupAnnotation_TypeDecl_value; } /** * @attribute inh * @aspect Annotations * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:544 */ @SuppressWarnings({"unchecked", "cast"}) public TypeDecl hostType() { ASTNode$State state = state(); TypeDecl hostType_value = getParent().Define_TypeDecl_hostType(this, null); return hostType_value; } /** * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:462 * @apilevel internal */ public TypeDecl Define_TypeDecl_enclosingAnnotationDecl(ASTNode caller, ASTNode child) { if(caller == getElementValuePairListNoTransform()) { int childIndex = caller.getIndexOfChild(child); return decl(); } else { return getParent().Define_TypeDecl_enclosingAnnotationDecl(this, caller); } } /** * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.5Frontend/Annotations.jrag:549 * @apilevel internal */ public NameType Define_NameType_nameType(ASTNode caller, ASTNode child) { if(caller == getAccessNoTransform()) { return NameType.TYPE_NAME; } else { return getParent().Define_NameType_nameType(this, caller); } } /** * @apilevel internal */ public ASTNode rewriteTo() { return super.rewriteTo(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy