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

TypeTree.java

00001 package edu.ksu.cis.bandera.abstraction.gui;
00002 
00003 import java.util.Enumeration;
00004 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00005  * Bandera, a Java(TM) analysis and transformation toolkit           *
00006  * Copyright (C) 1998, 1999, 2000   Shawn Laubach (laubach@acm.org)  *
00007  * All rights reserved.                                              *
00008  *                                                                   *
00009  * Modifications by Robby (robby@cis.ksu.edu) are                    *
00010  * Copyright (C) 2000 Robby.  All rights reserved.                   *
00011  *                                                                   *
00012  * This work was done as a project in the SAnToS Laboratory,         *
00013  * Department of Computing and Information Sciences, Kansas State    *
00014  * University, USA (http://www.cis.ksu.edu/santos).                  *
00015  * It is understood that any modification not identified as such is  *
00016  * not covered by the preceding statement.                           *
00017  *                                                                   *
00018  * This work is free software; you can redistribute it and/or        *
00019  * modify it under the terms of the GNU Library General Public       *
00020  * License as published by the Free Software Foundation; either      *
00021  * version 2 of the License, or (at your option) any later version.  *
00022  *                                                                   *
00023  * This work is distributed in the hope that it will be useful,      *
00024  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00025  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00026  * Library General Public License for more details.                  *
00027  *                                                                   *
00028  * You should have received a copy of the GNU Library General Public *
00029  * License along with this toolkit; if not, write to the             *
00030  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00031  * Boston, MA  02111-1307, USA.                                      *
00032  *                                                                   *
00033  * Java is a trademark of Sun Microsystems, Inc.                     *
00034  *                                                                   *
00035  * To submit a bug report, send a comment, or get the latest news on *
00036  * this project and other SAnToS projects, please visit the web-site *
00037  *                http://www.cis.ksu.edu/santos                      *
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  * TypeTree constructor comment.
00056  * @param root java.lang.Object
00057  */
00058 public TypeTree() {
00059     super(new TypeTreeNode("empty"));
00060     inferedTypes = new TypeTable();
00061 }
00062 /**
00063  * TypeTree constructor comment.
00064  * @param root java.lang.Object
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  * getChild method comment.
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  * getChildCount method comment.
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          * getColumnCount method comment.
00115          */
00116         public int getColumnCount() {
00117                 return cName.length;
00118         }
00119         /**
00120          * getColumnName method comment.
00121          */
00122         public String getColumnName(int column) {
00123                 return cName[column];
00124         }
00125 /**
00126  * Insert the method's description here.
00127  * Creation date: (5/19/00 2:27:38 PM)
00128  * @return edu.ksu.cis.bandera.abps.typing.TypeTable
00129  */
00130 public TypeTable getInferedTypes() {
00131     return inferedTypes;
00132 }
00133 /**
00134  * Insert the method's description here.
00135  * Creation date: (5/10/00 2:59:34 PM)
00136  * @return edu.ksu.cis.bandera.abps.options.Options
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  * getValueAt method comment.
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                 //System.out.print(vnode.getVar() + "\t");
00164                 //System.out.println(inferedTypes.get(vnode.getVar()));
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 /** By default, make the column with the Tree in it the only editable one. 
00208  *  Making this column editable causes the JTable to forward mouse 
00209  *  and keyboard events in the Tree column to the underlying JTree. 
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  * Insert the method's description here.
00216  * Creation date: (5/19/00 2:27:38 PM)
00217  * @param newInferedTypes edu.ksu.cis.bandera.abps.typing.TypeTable
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  * @param table java.util.Hashtable
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  * Insert the method's description here.
00263  * Creation date: (5/4/00 2:57:29 PM)
00264  * @param node edu.ksu.cis.bandera.abps.typing.gui.TreeNode
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         //System.out.println("\t" + aValue.getClass());
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 }

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