00001 package edu.ksu.cis.bandera.annotation;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00048
00049 public Annotation(Node node) {
00050 this.node = node;
00051 }
00052
00053
00054
00055
00056 public void addStmt(Stmt stmt) {
00057 add(stmt);
00058 }
00059
00060
00061
00062
00063 public abstract Object clone();
00064
00065
00066
00067
00068
00069 public boolean contains(Annotation annotation) {
00070 return getAllAnnotations(true).contains(annotation);
00071 }
00072
00073
00074
00075
00076
00077 public Vector getAllAnnotations(boolean includeSequential) {
00078 Vector result = new Vector();
00079 result.addElement(this);
00080 return result;
00081 }
00082
00083
00084
00085
00086
00087 public Annotation getContainingAnnotation(Stmt stmt) throws AnnotationException {
00088 if (contains(stmt)) return this;
00089 else return null;
00090 }
00091
00092
00093
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
00125
00126 public int getFirstColumn() {
00127 return firstColumn;
00128 }
00129
00130
00131
00132
00133 public int getFirstLine() {
00134 return firstLine;
00135 }
00136
00137
00138
00139
00140 public int getLastColumn() {
00141 return lastColumn;
00142 }
00143
00144
00145
00146
00147 public int getLastLine() {
00148 return lastLine;
00149 }
00150
00151
00152
00153
00154 public Node getNode() {
00155 return node;
00156 }
00157
00158
00159
00160
00161 public Annotation getParent() {
00162 return parent;
00163 }
00164
00165
00166
00167
00168 public abstract Stmt[] getStatements();
00169
00170
00171
00172
00173 public Object getUserObject() {
00174 return userObject;
00175 }
00176
00177
00178
00179
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
00194
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
00209
00210
00211 public abstract boolean removeStmt(Stmt stmt) throws AnnotationException;
00212
00213
00214
00215
00216
00217 public abstract boolean removeStmtByMark(Stmt stmt) throws AnnotationException;
00218
00219
00220
00221
00222
00223
00224 public abstract boolean replaceStmt(Stmt oldStmt, Stmt newStmt) throws AnnotationException;
00225
00226
00227
00228
00229
00230
00231 public abstract boolean replaceStmtByMark(Stmt oldStmt, Stmt newStmt) throws AnnotationException;
00232
00233
00234
00235
00236 public void setFirstColumn(int newFirstColumn) {
00237 firstColumn = newFirstColumn;
00238 }
00239
00240
00241
00242
00243 public void setFirstLine(int newFirstLine) {
00244 firstLine = newFirstLine;
00245 }
00246
00247
00248
00249
00250 public void setLastColumn(int newLastColumn) {
00251 lastColumn = newLastColumn;
00252 }
00253
00254
00255
00256
00257 public void setLastLine(int newLastLine) {
00258 lastLine = newLastLine;
00259 }
00260
00261
00262
00263
00264 public void setParent(Annotation annotation) {
00265 parent = annotation;
00266 }
00267
00268
00269
00270
00271 public void setUserObject(Object object) {
00272 userObject = object;
00273 }
00274
00275
00276
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
00288
00289 public void validate(JimpleBody body) {
00290 super.validate(body);
00291 }
00292 }