Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

BlockStmtAnnotation.java

00001 package edu.ksu.cis.bandera.annotation;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1999, 2000   Robby (robby@cis.ksu.edu)              *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project in the SAnToS Laboratory,         *
00009  * Department of Computing and Information Sciences, Kansas State    *
00010  * University, USA (http://www.cis.ksu.edu/santos).                  *
00011  * It is understood that any modification not identified as such is  *
00012  * not covered by the preceding statement.                           *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this toolkit; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other SAnToS projects, please visit the web-site *
00033  *                http://www.cis.ksu.edu/santos                      *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 import ca.mcgill.sable.soot.jimple.*;
00036 import ca.mcgill.sable.util.*;
00037 import java.util.*;
00038 import edu.ksu.cis.bandera.jjjc.node.*;
00039 public class BlockStmtAnnotation extends SequentialAnnotation {
00040     protected Vector containedAnnotations = new Vector();
00041 /**
00042  * 
00043  * @param node edu.ksu.cis.bandera.jjjc.node.Node
00044  */
00045 public BlockStmtAnnotation(Node node) {
00046     super(node);
00047 }
00048 /**
00049  * 
00050  * @param annotation Annotation
00051  */
00052 public void addAnnotation(Annotation annotation) {
00053     containedAnnotations.addElement(annotation);
00054     annotation.setParent(this);
00055 }
00056     public void apply(Switch sw)
00057     {
00058         ((AnnotationSwitch) sw).caseBlockStmtAnnotation(this);
00059     }
00060 /**
00061  * 
00062  * @return java.lang.Object
00063  */
00064 public Object clone() {
00065     BlockStmtAnnotation result = new BlockStmtAnnotation((Node) node.clone());
00066 
00067     for (Enumeration e = containedAnnotations.elements(); e.hasMoreElements();) {
00068         result.addAnnotation((Annotation) ((Annotation) e.nextElement()).clone());
00069     }
00070     
00071     return result;
00072 }
00073 /**
00074  * 
00075  * @return java.util.Vector
00076  * @param includeSequential boolean
00077  */
00078 public Vector getAllAnnotations(boolean includeSequential) {
00079     Vector result = new Vector();
00080     for (Enumeration e = containedAnnotations.elements(); e.hasMoreElements();) {
00081         Annotation a = (Annotation) e.nextElement();
00082         if (a instanceof BlockStmtAnnotation)
00083             result.addElement(a);
00084         for (Enumeration e2 = a.getAllAnnotations(includeSequential).elements();
00085                 e2.hasMoreElements();) {
00086             result.addElement(e2.nextElement());
00087         }
00088     }
00089     return result;
00090 }
00091 /**
00092  * 
00093  * @return java.util.Vector
00094  */
00095 public Vector getContainedAnnotations() {
00096     return containedAnnotations;
00097 }
00098 /**
00099  * 
00100  * @return edu.ksu.cis.bandera.annotations.Annotation
00101  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00102  */
00103 public Annotation getContainingAnnotation(Stmt stmt) throws AnnotationException {
00104     Vector result = new Vector();
00105     
00106     for (Enumeration e = containedAnnotations.elements(); e.hasMoreElements();) {
00107         Annotation a = ((Annotation) e.nextElement()).getContainingAnnotation(stmt);
00108         if (a != null) result.addElement(a);
00109     }
00110 
00111     int size = result.size();
00112     if (size == 0) return null;
00113     else if (size == 1) return (Annotation) result.elementAt(0);
00114     throw new AnnotationException("Statement " + stmt + " is contained in two or more annotations");
00115 }
00116 /**
00117  * 
00118  * @return java.util.Hashtable
00119  * @param annotation edu.ksu.cis.bandera.annotation.Annotation
00120  */
00121 public Hashtable getDeclaredLocalVariablesUntil(Annotation annotation) {
00122     Hashtable result = new Hashtable();
00123     for (Enumeration e = containedAnnotations.elements(); e.hasMoreElements();) {
00124         Annotation ann = (Annotation) e.nextElement();
00125         if (ann == annotation) break;
00126         
00127         if (ann instanceof LocalDeclarationStmtAnnotation) {
00128             Hashtable table = ((LocalDeclarationStmtAnnotation) ann).getDeclaredLocals();
00129             for (Enumeration e2 = table.keys(); e2.hasMoreElements();) {
00130                 Object key = e2.nextElement();
00131                 result.put(key, table.get(key));
00132             }
00133         }
00134     }
00135     return result;
00136 }
00137 /**
00138  * 
00139  * @return ca.mcgill.sable.soot.jimple.Stmt[]
00140  */
00141 public Stmt[] getStatements() {
00142     Vector result = new Vector();
00143     
00144     for (Enumeration e = containedAnnotations.elements(); e.hasMoreElements();) {
00145         Stmt[] stmts = ((Annotation) e.nextElement()).getStatements();
00146         for (int i = 0; i < stmts.length; i++) {
00147             result.addElement(stmts[i]);
00148         }
00149     }
00150 
00151     Stmt[] stmts = new Stmt[result.size()];
00152     for (int i = 0; i < stmts.length; i++) {
00153         stmts[i] = (Stmt) result.elementAt(i);
00154     }
00155     
00156     return stmts;
00157 }
00158 /**
00159  * 
00160  * @param annotation edu.ksu.cis.bandera.annotations.Annotation
00161  * @param index int
00162  */
00163 public void insertAnnotationAt(Annotation annotation, int index) {
00164     containedAnnotations.insertElementAt(annotation, index);
00165     annotation.setParent(this);
00166 }
00167 /**
00168  * 
00169  * @return boolean
00170  * @param annotation edu.ksu.cis.bandera.annotations.Annotation
00171  */
00172 public boolean removeAnnotation(Annotation annotation) {
00173     return containedAnnotations.removeElement(annotation);
00174 }
00175 /**
00176  * 
00177  * @return boolean
00178  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00179  */
00180 public boolean removeStmt(Stmt stmt) throws AnnotationException {
00181     Annotation a = getContainingAnnotation(stmt);
00182     
00183     if (a == null) return false;
00184     
00185     return a.removeStmt(stmt);
00186 }
00187 /**
00188  * 
00189  * @return boolean
00190  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00191  */
00192 public boolean removeStmtByMark(Stmt stmt) throws AnnotationException {
00193     Annotation a = getContainingAnnotation(stmt);
00194     if (a == null)
00195         return false;
00196     return a.removeStmtByMark(stmt);
00197 }
00198 /**
00199  * 
00200  * @return boolean
00201  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00202  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00203  */
00204 public boolean replaceStmt(Stmt oldStmt, Stmt newStmt) throws AnnotationException {
00205     Annotation a = getContainingAnnotation(oldStmt);
00206     
00207     if (a == null) return false;
00208     
00209     return a.replaceStmt(oldStmt, newStmt);
00210 }
00211 /**
00212  * 
00213  * @return boolean
00214  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00215  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00216  */
00217 public boolean replaceStmtByMark(Stmt oldStmt, Stmt newStmt) throws AnnotationException {
00218     Annotation a = getContainingAnnotation(oldStmt);
00219     if (a == null)
00220         return false;
00221     return a.replaceStmtByMark(oldStmt, newStmt);
00222 }
00223 /**
00224  * 
00225  * @return java.lang.String
00226  */
00227 public String toString() {
00228     return (containedAnnotations.size() > 0) ? "{...}" : "{}";
00229 }
00230 /**
00231  * 
00232  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00233  */
00234 public void validate(JimpleBody body) {
00235     for (Enumeration e = containedAnnotations.elements(); e.hasMoreElements();) {
00236         ((Annotation) e.nextElement()).validate(body);
00237     }
00238 }
00239 }

Generated at Thu Feb 7 06:41:04 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001