00001 package edu.ksu.cis.bandera.abstraction.gui;
00002
00003 import java.util.Enumeration;
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
00036
00037
00038
00039 import java.util.Stack;
00040 import java.util.Vector;
00041 import java.util.Iterator;
00042 import java.util.Hashtable;
00043 import ca.mcgill.sable.soot.*;
00044 import javax.swing.tree.TreeNode;
00045 import ca.mcgill.sable.soot.jimple.*;
00046 import edu.ksu.cis.bandera.abstraction.*;
00047 import edu.ksu.cis.bandera.abstraction.util.*;
00048 import edu.ksu.cis.bandera.abstraction.options.*;
00049 import edu.ksu.cis.bandera.abstraction.typeinference.*;
00050 public class TypeTree extends AbstractTreeTableModel implements TreeTableModel {
00051 static protected String cName[] = {"Tree", "Type", "Abstraction", "Value", "Inferred Type"};
00052 static protected Class[] cTypes = {TreeTableModel.class, Type.class, Abstraction.class, Abstraction.class, String.class};
00053 protected edu.ksu.cis.bandera.abstraction.typeinference.TypeTable inferedTypes;
00054
00055
00056
00057
00058 public TypeTree() {
00059 super(new TypeTreeNode("empty"));
00060 inferedTypes = new TypeTable();
00061 }
00062
00063
00064
00065
00066 public static AbstractTreeNode createTree(Vector classes) {
00067 MethodTreeNode.methodsTable = new Hashtable();
00068 LocalTreeNode.locals = new Vector();
00069 FieldTreeNode.fields = new Vector();
00070 AbstractTreeNode root = new TypeTreeNode("Packages");
00071 Hashtable packages = new Hashtable();
00072 for (int i = 0; i < classes.size(); i++) {
00073 SootClass c = (SootClass) classes.get(i);
00074 String pack;
00075 if (c.getName().lastIndexOf(".") >= 0)
00076 pack = c.getName().substring(0, c.getName().lastIndexOf("."));
00077 else
00078 pack = "";
00079 TypeTreeNode node = (TypeTreeNode) packages.get(pack);
00080 if (node == null) {
00081 if (pack.equals(""))
00082 node = new TypeTreeNode("Default Package");
00083 else
00084 node = new TypeTreeNode(pack);
00085 packages.put(pack, node);
00086 ((AbstractTreeNode) root).addChild(node);
00087 }
00088 node.addChild(new ClassTreeNode(c));
00089 }
00090 return root;
00091 }
00092
00093
00094
00095 public Object getChild(Object parent, int index) {
00096 if (parent instanceof AbstractTreeNode)
00097 return ((AbstractTreeNode) parent).getChildAt(index);
00098 else
00099 return null;
00100 }
00101
00102
00103
00104 public int getChildCount(Object parent) {
00105 if (parent instanceof AbstractTreeNode)
00106 return ((AbstractTreeNode) parent).getChildCount();
00107 else
00108 return 0;
00109 }
00110 public Class getColumnClass(int column) {
00111 return cTypes[column];
00112 }
00113
00114
00115
00116 public int getColumnCount() {
00117 return cName.length;
00118 }
00119
00120
00121
00122 public String getColumnName(int column) {
00123 return cName[column];
00124 }
00125
00126
00127
00128
00129
00130 public TypeTable getInferedTypes() {
00131 return inferedTypes;
00132 }
00133
00134
00135
00136
00137
00138 public Hashtable getOptions() {
00139 Hashtable result = new Hashtable();
00140 for (int i = 0; i < getChildCount(root); i++) {
00141 Object pack = getChild(root, i);
00142 for (int j = 0; j < getChildCount(pack); j++) {
00143 ClassTreeNode cls = (ClassTreeNode) getChild(pack, j);
00144 cls.getOption(result);
00145 }
00146 }
00147 return result;
00148 }
00149
00150
00151
00152 public Object getValueAt(Object node, int column) {
00153 if (node instanceof VarTreeNode) {
00154 VarTreeNode vnode = (VarTreeNode) node;
00155 switch (column) {
00156 case 0 :
00157 return vnode.getName();
00158 case 1 :
00159 return vnode.getType();
00160 case 2 :
00161 return vnode.getAbstraction();
00162 case 4 :
00163
00164
00165 return inferedTypes.get(vnode.getVar());
00166 }
00167 } else
00168 if (node instanceof MethodTreeNode) {
00169 MethodTreeNode mnode = (MethodTreeNode) node;
00170 switch (column) {
00171 case 0 :
00172 return mnode.getName();
00173 case 1 :
00174 return mnode.getParams();
00175 }
00176 } else
00177 if (node instanceof TypeTreeNode) {
00178 TypeTreeNode tnode = (TypeTreeNode) node;
00179 switch (column) {
00180 case 0 :
00181 return tnode.getName();
00182 }
00183 } else
00184 switch (column) {
00185 case 0 :
00186 if (node instanceof Vector)
00187 return "Root";
00188 else
00189 if (node instanceof SootClass)
00190 return ((SootClass) node).getName();
00191 else
00192 if (node instanceof SootField)
00193 return ((SootField) node).getName();
00194 else
00195 return null;
00196 case 1 :
00197 if (node instanceof SootField)
00198 return ((SootField) node).getType();
00199 else
00200 if (node instanceof Local)
00201 return ((Local) node).getType();
00202 else
00203 return "";
00204 }
00205 return "";
00206 }
00207
00208
00209
00210
00211 public boolean isCellEditable(Object node, int column) {
00212 return super.isCellEditable(node, column) || ((node instanceof MethodTreeNode || node instanceof VarTreeNode) && column == 2);
00213 }
00214
00215
00216
00217
00218
00219 public void setInferedTypes(TypeTable newInferedTypes) {
00220 inferedTypes = newInferedTypes;
00221 Iterator i;
00222 if (LocalTreeNode.locals != null) {
00223 i = LocalTreeNode.locals.iterator();
00224 while (i.hasNext())
00225 nodeChanged(((TreeNode) i.next()).getParent());
00226 }
00227 if (FieldTreeNode.fields != null) {
00228 i = FieldTreeNode.fields.iterator();
00229 while (i.hasNext())
00230 nodeChanged((TreeNode) i.next());
00231 }
00232 }
00233
00234
00235
00236
00237 public void setSelectedTypes(Hashtable table) {
00238 RefHashTable refTable = new RefHashTable();
00239 for (Iterator i = LocalTreeNode.locals.iterator(); i.hasNext();) {
00240 LocalTreeNode ltn = (LocalTreeNode) i.next();
00241 refTable.put(ltn.getVar(), ltn);
00242 }
00243 for (Iterator i = FieldTreeNode.fields.iterator(); i.hasNext();) {
00244 FieldTreeNode ftn = (FieldTreeNode) i.next();
00245 refTable.put(ftn.getField(), ftn);
00246 }
00247 for (Enumeration e = table.keys(); e.hasMoreElements();) {
00248 Object key = e.nextElement();
00249 if (key instanceof SootField) {
00250 FieldTreeNode ftn = (FieldTreeNode) refTable.get(key);
00251 ftn.setAbstraction((Abstraction) table.get(key));
00252 nodeChanged(ftn.getParent());
00253 } else if (key instanceof LocalMethod) {
00254 LocalMethod lm = (LocalMethod) key;
00255 LocalTreeNode ltn = (LocalTreeNode) refTable.get(lm.getLocal());
00256 ltn.setAbstraction((Abstraction) table.get(key));
00257 nodeChanged(ltn.getParent());
00258 }
00259 }
00260 }
00261
00262
00263
00264
00265
00266 public void setTree(AbstractTreeNode node) {
00267 root = node;
00268 inferedTypes = new TypeTable();
00269 }
00270 public void setValueAt(Object aValue, Object node, int column) {
00271 if (node instanceof VarTreeNode) {
00272 VarTreeNode vnode = (VarTreeNode) node;
00273
00274 switch (column) {
00275 case 2 :
00276 if (aValue instanceof Abstraction)
00277 vnode.setAbstraction((Abstraction) aValue);
00278 else
00279 vnode.setAbstraction(null);
00280 break;
00281 }
00282 }
00283 }
00284 }