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

TryStmtAnnotation.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 edu.ksu.cis.bandera.jjjc.node.*;
00036 import edu.ksu.cis.bandera.jjjc.util.*;
00037 import ca.mcgill.sable.soot.jimple.*;
00038 import ca.mcgill.sable.util.*;
00039 import java.util.*;
00040 
00041 public class TryStmtAnnotation extends SpecializedAnnotation {
00042     protected Annotation blockAnnotation = null; 
00043     protected Vector catchClauses = new Vector();
00044 /**
00045  * TryStmtAnnotation constructor comment.
00046  * @param node edu.ksu.cis.bandera.jjjc.node.Node
00047  */
00048 public TryStmtAnnotation(edu.ksu.cis.bandera.jjjc.node.Node node) {
00049     super(node);
00050 }
00051 /**
00052  * 
00053  * @param annotation edu.ksu.cis.bandera.annotations.Statements
00054  */
00055 public void addCatchClauseAnnotation(Annotation annotation) {
00056     catchClauses.addElement(annotation);
00057     annotation.setParent(this);
00058 }
00059     public void apply(Switch sw)
00060     {
00061         ((AnnotationSwitch) sw).caseTryStmtAnnotation(this);
00062     }
00063 /**
00064  * 
00065  * @return java.lang.Object
00066  */
00067 public Object clone() {
00068     TryStmtAnnotation result = new TryStmtAnnotation((Node) node.clone());
00069 
00070     if (blockAnnotation != null) result.setBlockAnnotation((Annotation) blockAnnotation.clone());
00071 
00072     for (Enumeration e = catchClauses.elements(); e.hasMoreElements();) {
00073         result.addCatchClauseAnnotation((Annotation) ((Annotation) e.nextElement()).clone());
00074     }
00075     
00076     return result;
00077 }
00078 /**
00079  * 
00080  * @return java.util.Vector
00081  * @param includeSequential boolean
00082  */
00083 public Vector getAllAnnotations(boolean includeSequential) {
00084     Vector result = new Vector();
00085     result.addElement(this);
00086     for (Enumeration e = blockAnnotation.getAllAnnotations(includeSequential).elements(); e.hasMoreElements();) {
00087         result.addElement(e.nextElement());
00088     }
00089     for (Enumeration e = catchClauses.elements(); e.hasMoreElements();) {
00090         Annotation a = (Annotation) e.nextElement();
00091         result.addElement(a);
00092         for (Enumeration e2 = a.getAllAnnotations(includeSequential).elements();    e2.hasMoreElements();) {
00093             result.addElement(e2.nextElement());
00094         }
00095     }
00096     return result;
00097 }
00098 /**
00099  * 
00100  * @return edu.ksu.cis.bandera.annotations.Annotation
00101  */
00102 public Annotation getBlockAnnotation() {
00103     return blockAnnotation;
00104 }
00105 /**
00106  * 
00107  * @return java.util.Vector
00108  */
00109 public Vector getCatchClauses() {
00110     return catchClauses;
00111 }
00112 /**
00113  * 
00114  * @return edu.ksu.cis.bandera.annotations.Annotation
00115  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00116  */
00117 public Annotation getContainingAnnotation(Stmt stmt) throws AnnotationException {
00118     Vector result = new Vector();
00119 
00120     if (blockAnnotation != null) {
00121         Annotation a = blockAnnotation.getContainingAnnotation(stmt);
00122         if (a != null) result.addElement(a);
00123     }
00124     
00125     for (Enumeration e = catchClauses.elements(); e.hasMoreElements();) {
00126         Annotation a = (Annotation) e.nextElement();
00127         a = a.getContainingAnnotation(stmt);
00128         if (a != null) result.addElement(a);
00129     }
00130 
00131     int size = result.size();
00132     if (size == 0) return null;
00133     else if (size == 1) return (Annotation) result.elementAt(0);
00134     throw new AnnotationException("Statement " + stmt + " is contained in two or more annotations");
00135 }
00136 /**
00137  * 
00138  * @return ca.mcgill.sable.soot.jimple.Stmt[]
00139  */
00140 public Stmt[] getStatements() {
00141     Vector result = new Vector();
00142     
00143     Stmt[] blockStmts = (blockAnnotation != null) ? blockAnnotation.getStatements() : new Stmt[0];
00144 
00145     for (int i = 0; i < blockStmts.length; i++) {
00146         result.addElement(blockStmts[i]);
00147     }
00148 
00149     for (Enumeration e = catchClauses.elements(); e.hasMoreElements();) {
00150         Stmt[] stmts = ((Annotation) e.nextElement()).getStatements();
00151         for (int i = 0; i < stmts.length; i++) {
00152             result.addElement(stmts[i]);
00153         }
00154     }
00155 
00156     Stmt[] stmts = new Stmt[result.size()];
00157 
00158     for (int i = 0; i < stmts.length; i++) {
00159         stmts[i] = (Stmt) result.elementAt(i);
00160     }
00161     
00162     return stmts;
00163 }
00164 /**
00165  * 
00166  * @return boolean
00167  * @param annotation edu.ksu.cis.bandera.annotations.Annotation
00168  */
00169 public boolean removeCatchClauseAnnotation(Annotation annotation) {
00170     return catchClauses.removeElement(annotation);
00171 }
00172 /**
00173  * 
00174  * @return boolean
00175  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00176  */
00177 public boolean removeStmt(Stmt stmt) throws AnnotationException {
00178     Annotation a = getContainingAnnotation(stmt);
00179     if (a == null) return false;
00180     else return a.removeStmt(stmt);
00181 }
00182 /**
00183  * 
00184  * @return boolean
00185  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00186  */
00187 public boolean removeStmtByMark(Stmt stmt) throws AnnotationException {
00188     Annotation a = getContainingAnnotation(stmt);
00189     if (a == null) return false;
00190     else return a.removeStmtByMark(stmt);
00191 }
00192 /**
00193  * 
00194  * @return boolean
00195  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00196  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00197  */
00198 public boolean replaceStmt(Stmt oldStmt, Stmt newStmt) throws AnnotationException {
00199     Annotation a = getContainingAnnotation(oldStmt);
00200     if (a == null) return false;
00201     else return a.replaceStmt(oldStmt, newStmt);
00202 }
00203 /**
00204  * 
00205  * @return boolean
00206  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00207  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00208  */
00209 public boolean replaceStmtByMark(Stmt oldStmt, Stmt newStmt) throws AnnotationException {
00210     Annotation a = getContainingAnnotation(oldStmt);
00211     if (a == null) return false;
00212     else return a.replaceStmtByMark(oldStmt, newStmt);
00213 }
00214 /**
00215  * 
00216  * @param annotation edu.ksu.cis.bandera.annotations.Annotation
00217  */
00218 public void setBlockAnnotation(Annotation annotation) {
00219     blockAnnotation = annotation;
00220     blockAnnotation.setParent(this);
00221 }
00222 /**
00223  * 
00224  * @return java.lang.String
00225  */
00226 public String toString() {
00227     return "try";
00228 }
00229 /**
00230  * 
00231  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00232  */
00233 public void validate(JimpleBody body) {
00234     if (blockAnnotation != null) blockAnnotation.validate(body);
00235     
00236     for (Enumeration e = catchClauses.elements(); e.hasMoreElements();) {
00237         ((Annotation) e.nextElement()).validate(body);
00238     }
00239 }
00240 }

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