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

Annotation.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 ca.mcgill.sable.soot.jimple.*;
00037 import ca.mcgill.sable.util.*;
00038 import java.util.*;
00039 import edu.ksu.cis.bandera.pdgslicer.PostProcessOnAnnotation;
00040 public abstract class Annotation extends Statements implements Cloneable, Switchable {
00041     protected Annotation parent = null;
00042     protected Node node;
00043     protected Object userObject = null;
00044     protected int firstLine, firstColumn, lastLine, lastColumn;
00045 /**
00046  * 
00047  * @param node edu.ksu.cis.bandera.jjjc.node.Node
00048  */
00049 public Annotation(Node node) {
00050     this.node = node;
00051 }
00052 /**
00053  * 
00054  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00055  */
00056 public void addStmt(Stmt stmt) {
00057     add(stmt);
00058 }
00059 /**
00060  * 
00061  * @return java.lang.Object
00062  */
00063 public abstract Object clone();
00064 /**
00065  * 
00066  * @return boolean
00067  * @param annotation edu.ksu.cis.bandera.annotation.Annotation
00068  */
00069 public boolean contains(Annotation annotation) {
00070     return getAllAnnotations(true).contains(annotation);
00071 }
00072 /**
00073  *
00074  * @return java.util.Vector
00075  * @param includeSequential boolean
00076  */
00077 public Vector getAllAnnotations(boolean includeSequential) {
00078     Vector result = new Vector();
00079     result.addElement(this);
00080     return result;
00081 }
00082 /**
00083  * 
00084  * @return edu.ksu.cis.bandera.annotations.Annotation
00085  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00086  */
00087 public Annotation getContainingAnnotation(Stmt stmt) throws AnnotationException {
00088     if (contains(stmt)) return this;
00089     else return null;
00090 }
00091 /**
00092  * 
00093  * @return java.util.Hashtable
00094  */
00095 public Hashtable getDeclaredLocalVariables() {
00096     Hashtable result = new Hashtable();
00097 
00098     if (parent == null) return result;
00099 
00100     if (parent instanceof BlockStmtAnnotation) {
00101         Hashtable table = ((BlockStmtAnnotation) parent).getDeclaredLocalVariablesUntil(this);
00102         for (Enumeration e = table.keys(); e.hasMoreElements();) {
00103             Object key = e.nextElement();
00104             result.put(key, table.get(key));
00105         }
00106     } else if (parent instanceof ForStmtAnnotation) {
00107         Hashtable table = ((ForStmtAnnotation) parent).getDeclaredLocals();
00108         for (Enumeration e = table.keys(); e.hasMoreElements();) {
00109             Object key = e.nextElement();
00110             result.put(key, table.get(key));
00111         }
00112     }
00113 
00114     Hashtable table = parent.getDeclaredLocalVariables();
00115     for (Enumeration e = table.keys(); e.hasMoreElements();) {
00116         Object key = e.nextElement();
00117         result.put(key, table.get(key));
00118     }
00119     
00120     return result;
00121 }
00122 /**
00123  * 
00124  * @return int
00125  */
00126 public int getFirstColumn() {
00127     return firstColumn;
00128 }
00129 /**
00130  * 
00131  * @return int
00132  */
00133 public int getFirstLine() {
00134     return firstLine;
00135 }
00136 /**
00137  * 
00138  * @return int
00139  */
00140 public int getLastColumn() {
00141     return lastColumn;
00142 }
00143 /**
00144  * 
00145  * @return int
00146  */
00147 public int getLastLine() {
00148     return lastLine;
00149 }
00150 /**
00151  * 
00152  * @return edu.ksu.cis.bandera.jjjc.node.Node
00153  */
00154 public Node getNode() {
00155     return node;
00156 }
00157 /**
00158  * 
00159  * @return edu.ksu.cis.bandera.annotation.Annotation
00160  */
00161 public Annotation getParent() {
00162     return parent;
00163 }
00164 /**
00165  * 
00166  * @return ca.mcgill.sable.soot.jimple.Stmt[]
00167  */
00168 public abstract Stmt[] getStatements();
00169 /**
00170  * 
00171  * @return java.lang.Object
00172  */
00173 public Object getUserObject() {
00174     return userObject;
00175 }
00176 /**
00177  * 
00178  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00179  * @param point ca.mcgill.sable.soot.jimple.Stmt
00180  */
00181 public void insertStmtAfter(Stmt stmt, Stmt point) {
00182     try {
00183         Annotation a = getContainingAnnotation(point);
00184         if (a != null) {
00185             int i = a.indexOf(point);
00186             a.insertStmtAt(stmt, i + 1);
00187         }
00188     } catch (Exception e) {
00189     }
00190 }
00191 /**
00192  * 
00193  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00194  * @param point ca.mcgill.sable.soot.jimple.Stmt
00195  */
00196 public void insertStmtBefore(Stmt stmt, Stmt point) {
00197     try {
00198         Annotation a = getContainingAnnotation(point);
00199         if (a != null) {
00200             int i = a.indexOf(point);
00201             a.insertStmtAt(stmt, i);
00202         }
00203     } catch (Exception e) {
00204     }
00205 }
00206 /**
00207  * 
00208  * @return boolean
00209  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00210  */
00211 public abstract boolean removeStmt(Stmt stmt) throws AnnotationException;
00212 /**
00213  * 
00214  * @return boolean
00215  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00216  */
00217 public abstract boolean removeStmtByMark(Stmt stmt) throws AnnotationException;
00218 /**
00219  * 
00220  * @return boolean
00221  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00222  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00223  */
00224 public abstract boolean replaceStmt(Stmt oldStmt, Stmt newStmt) throws AnnotationException;
00225 /**
00226  * 
00227  * @return boolean
00228  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00229  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00230  */
00231 public abstract boolean replaceStmtByMark(Stmt oldStmt, Stmt newStmt) throws AnnotationException;
00232 /**
00233  * 
00234  * @param newFirstColumn int
00235  */
00236 public void setFirstColumn(int newFirstColumn) {
00237     firstColumn = newFirstColumn;
00238 }
00239 /**
00240  * 
00241  * @param newFirstLine int
00242  */
00243 public void setFirstLine(int newFirstLine) {
00244     firstLine = newFirstLine;
00245 }
00246 /**
00247  * 
00248  * @param newLastColumn int
00249  */
00250 public void setLastColumn(int newLastColumn) {
00251     lastColumn = newLastColumn;
00252 }
00253 /**
00254  * 
00255  * @param newLastLine int
00256  */
00257 public void setLastLine(int newLastLine) {
00258     lastLine = newLastLine;
00259 }
00260 /**
00261  * 
00262  * @param annotation edu.ksu.cis.bandera.annotation.Annotation
00263  */
00264 public void setParent(Annotation annotation) {
00265     parent = annotation;
00266 }
00267 /**
00268  * 
00269  * @param object java.lang.Object
00270  */
00271 public void setUserObject(Object object) {
00272     userObject = object;
00273 }
00274 /**
00275  * 
00276  * @return java.lang.String
00277  */
00278 public String toString() {
00279     if (node == null) return "";
00280 
00281     String result = node.toString().trim();
00282     
00283     return (result.endsWith(";")) ? result.substring(0, result.length() - 1) : result;
00284 }
00285 /**
00286  * 
00287  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00288  */
00289 public void validate(JimpleBody body) {
00290     super.validate(body);
00291 }
00292 }

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