00001 package edu.ksu.cis.bandera.pdgslicer.dependency;
00002
00003 import javax.swing.*;
00004 import javax.swing.tree.*;
00005 import java.util.*;
00006 import java.awt.Color;
00007 import ca.mcgill.sable.soot.*;
00008 import ca.mcgill.sable.soot.jimple.*;
00009 import edu.ksu.cis.bandera.util.Preferences;
00010 import edu.ksu.cis.bandera.jjjc.CompilationManager;
00011 import edu.ksu.cis.bandera.bui.session.datastructure.Session;
00012 import edu.ksu.cis.bandera.jjjc.symboltable.Name;
00013 import edu.ksu.cis.bandera.jjjc.symboltable.Package;
00014 import edu.ksu.cis.bandera.jjjc.symboltable.Method;
00015 import edu.ksu.cis.bandera.jjjc.symboltable.Variable;
00016 import edu.ksu.cis.bandera.annotation.*;
00017 import edu.ksu.cis.bandera.bui.BUI;
00018 import edu.ksu.cis.bandera.bui.BUISessionPane;
00019 import edu.ksu.cis.bandera.bui.IconLibrary;
00020 import edu.ksu.cis.bandera.specification.predicate.datastructure.PredicateSet;
00021 import edu.ksu.cis.bandera.specification.predicate.datastructure.Predicate;
00022 import edu.ksu.cis.bandera.specification.assertion.datastructure.Assertion;
00023 import edu.ksu.cis.bandera.specification.assertion.datastructure.AssertionSet;
00024 import edu.ksu.cis.bandera.pdgslicer.PostProcessOnAnnotation;
00025 import edu.ksu.cis.bandera.pdgslicer.datastructure.*;
00026
00027
00028
00029
00030
00031 public class CodeBrowserPane extends JPanel implements java.awt.event.MouseListener, javax.swing.event.TreeSelectionListener {
00032 private PostProcessOnAnnotation postProcessOnAnnotation = null;
00033 private ca.mcgill.sable.util.Set removablePackages = new ca.mcgill.sable.util.ArraySet();
00034 private ca.mcgill.sable.util.Set modifiedPackages = new ca.mcgill.sable.util.ArraySet();
00035 private ca.mcgill.sable.util.Set removableSootClasses = new ca.mcgill.sable.util.ArraySet();
00036 ca.mcgill.sable.util.Set unreachableSootClasses = new ca.mcgill.sable.util.ArraySet();
00037 private ca.mcgill.sable.util.Set modifiedSootClasses = new ca.mcgill.sable.util.ArraySet();
00038 private ca.mcgill.sable.util.Set removableSootFields = new ca.mcgill.sable.util.ArraySet();
00039 private ca.mcgill.sable.util.Set removableSootMethods = new ca.mcgill.sable.util.ArraySet();
00040 ca.mcgill.sable.util.Set reachableSootMethods = new ca.mcgill.sable.util.ArraySet();
00041 private ca.mcgill.sable.util.Set modifiedSootMethods = new ca.mcgill.sable.util.ArraySet();
00042 private ca.mcgill.sable.util.Set parameterModifiedMethods = new ca.mcgill.sable.util.ArraySet();
00043 private Dependencies dependFrame;
00044 private boolean setSelectedByProgram = false;
00045 private JSplitPane ivjCodeSplitPane = null;
00046 private DraggableHierTree ivjHierTree = null;
00047 private JScrollPane ivjHierTreeScrollPane = null;
00048 private DraggableMethodTree ivjMethodTree = null;
00049 private JScrollPane ivjMethodTreeScrollPane = null;
00050
00051
00052
00053 public CodeBrowserPane() {
00054 super();
00055 initialize();
00056 }
00057
00058
00059
00060
00061 public CodeBrowserPane(java.awt.LayoutManager layout) {
00062 super(layout);
00063 }
00064
00065
00066
00067
00068
00069 public CodeBrowserPane(java.awt.LayoutManager layout, boolean isDoubleBuffered) {
00070 super(layout, isDoubleBuffered);
00071 }
00072
00073
00074
00075
00076 public CodeBrowserPane(boolean isDoubleBuffered) {
00077 super(isDoubleBuffered);
00078 }
00079
00080
00081
00082
00083
00084 private DefaultMutableTreeNode buildClassNode(SootClass sc) {
00085 AnnotationManager am = CompilationManager.getAnnotationManager();
00086 Set ts = new TreeSet();
00087 for (ca.mcgill.sable.util.Iterator i = sc.getFields().iterator(); i.hasNext();) {
00088 ts.add(am.getAnnotation(sc, i.next()));
00089 }
00090 for (ca.mcgill.sable.util.Iterator i = sc.getMethods().iterator(); i.hasNext();) {
00091 ts.add(am.getAnnotation(sc, i.next()));
00092 }
00093 DefaultMutableTreeNode node = new DefaultMutableTreeNode(sc);
00094 for (Iterator i = ts.iterator(); i.hasNext();) {
00095 node.add(new DefaultMutableTreeNode(i.next()));
00096 }
00097 return node;
00098 }
00099
00100
00101
00102
00103
00104 private DefaultMutableTreeNode buildPackageNode(Package p) {
00105 DefaultMutableTreeNode pNode = new DefaultMutableTreeNode(p);
00106 Hashtable compiledClasses = CompilationManager.getAnnotationManager().getAnnotationTable();
00107 ca.mcgill.sable.util.Set scs = new ca.mcgill.sable.util.ArraySet();
00108 for (Enumeration e = compiledClasses.keys(); e.hasMoreElements();) {
00109 SootClass sc = (SootClass) e.nextElement();
00110 Name cName = new Name(sc.getName());
00111 if (cName.getSuperName().equals(p.getName()))
00112 scs.add(sc);
00113 }
00114 for (ca.mcgill.sable.util.Iterator j = scs.iterator(); j.hasNext();) {
00115 SootClass sc = (SootClass) j.next();
00116
00117 pNode.add(buildClassNode(sc));
00118 }
00119 return pNode;
00120 }
00121
00122
00123
00124
00125 private void connEtoC1() {
00126 try {
00127
00128 if (!setSelectedByProgram)
00129
00130
00131 this.hierTree_TreeSelectionEvents();
00132
00133
00134 } catch (java.lang.Throwable ivjExc) {
00135
00136
00137 handleException(ivjExc);
00138 }
00139 }
00140
00141
00142
00143
00144
00145 private void connEtoC3(java.awt.event.MouseEvent arg1) {
00146 try {
00147
00148
00149 this.methodTree_MouseClicked(arg1);
00150
00151
00152 } catch (java.lang.Throwable ivjExc) {
00153
00154
00155 handleException(ivjExc);
00156 }
00157 }
00158
00159
00160
00161
00162 private void connEtoC4() {
00163 try {
00164
00165 if (!setSelectedByProgram)
00166
00167 this.methodTree_TreeSelectionEvents();
00168
00169
00170 } catch (java.lang.Throwable ivjExc) {
00171
00172
00173 handleException(ivjExc);
00174 }
00175 }
00176
00177
00178
00179
00180 private static void getBuilderData() {
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 }
00211
00212
00213
00214
00215
00216 public javax.swing.JSplitPane getCodeSplitPane() {
00217 if (ivjCodeSplitPane == null) {
00218 try {
00219 ivjCodeSplitPane = new javax.swing.JSplitPane(javax.swing.JSplitPane.HORIZONTAL_SPLIT);
00220 ivjCodeSplitPane.setName("CodeSplitPane");
00221 ivjCodeSplitPane.setDividerLocation(80);
00222 getCodeSplitPane().add(getHierTreeScrollPane(), "left");
00223 getCodeSplitPane().add(getMethodTreeScrollPane(), "right");
00224
00225 getCodeSplitPane().setDividerLocation(180);
00226
00227 } catch (java.lang.Throwable ivjExc) {
00228
00229
00230 handleException(ivjExc);
00231 }
00232 }
00233 return ivjCodeSplitPane;
00234 }
00235
00236
00237
00238
00239
00240 private DraggableHierTree getHierTree() {
00241 if (ivjHierTree == null) {
00242 try {
00243 ivjHierTree = new edu.ksu.cis.bandera.pdgslicer.dependency.DraggableHierTree();
00244 ivjHierTree.setName("HierTree");
00245 ivjHierTree.setBackground(new java.awt.Color(204, 204, 204));
00246 ivjHierTree.setBounds(0, 0, 78, 72);
00247
00248 ivjHierTree.setUI(new javax.swing.plaf.metal.MetalTreeUI() {
00249 public javax.swing.plaf.metal.MetalTreeUI setAngledColor() {
00250 setHashColor(java.awt.Color.black);
00251 return this;
00252 }
00253 }
00254 .setAngledColor());
00255 ivjHierTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
00256 ivjHierTree.setCellRenderer(new DefaultTreeCellRenderer() {
00257 public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
00258 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
00259 setIcon(null);
00260 setForeground(Color.black);
00261
00262 Object o = ((DefaultMutableTreeNode) value).getUserObject();
00263 if (o instanceof Package) {
00264 String name = ((Package) o).getName().toString().trim();
00265 name = "".equals(name) ? "<default package>" : name;
00266 setText(name);
00267 setIcon(IconLibrary.packageIcon);
00268 if (CodeBrowserPane.this.removablePackages.contains(o))
00269 setForeground(Preferences.getSlicedColor());
00270 else
00271 if (CodeBrowserPane.this.modifiedPackages.contains(o))
00272 setForeground(Preferences.getModifiedColor());
00273 } else
00274 if (o instanceof SootClass) {
00275 SootClass sc = (SootClass) o;
00276 Name cName = new Name(sc.getName());
00277 setText(cName.getLastIdentifier());
00278 setIcon(IconLibrary.classIcon);
00279 try {
00280 if (Package.getClassOrInterfaceType(cName).isInterface()) {
00281 setIcon(IconLibrary.interfaceIcon);
00282 }
00283 } catch (Exception e) {
00284 }
00285 if (CodeBrowserPane.this.unreachableSootClasses.contains(o)) {
00286 setForeground(Preferences.getUnreachableColor());
00287
00288 } else
00289 if (CodeBrowserPane.this.removableSootClasses.contains(o))
00290 setForeground(Preferences.getSlicedColor());
00291 else
00292 if (CodeBrowserPane.this.modifiedSootClasses.contains(o))
00293 setForeground(Preferences.getModifiedColor());
00294 } else
00295 if (o instanceof FieldDeclarationAnnotation) {
00296 FieldDeclarationAnnotation fda = (FieldDeclarationAnnotation) o;
00297 setText(fda.getField().getType() + " " + fda.getField().getName());
00298 setIcon(IconLibrary.fieldIcon);
00299 if (CodeBrowserPane.this.removableSootFields.contains(fda.getSootField()))
00300 setForeground(Preferences.getSlicedColor());
00301 } else
00302 if (o instanceof ConstructorDeclarationAnnotation) {
00303 ConstructorDeclarationAnnotation cda = (ConstructorDeclarationAnnotation) o;
00304 SootMethod sm = cda.getSootMethod();
00305 try {
00306 Method m = cda.getConstructor();
00307 String result = m.getDeclaringClassOrInterface().getName().getLastIdentifier().trim() + "(";
00308 JimpleBody body = (JimpleBody) sm.getBody(Jimple.v());
00309 String parm = "";
00310 for (Enumeration e = m.getParameters().elements(); e.hasMoreElements();) {
00311 Variable v = (Variable) e.nextElement();
00312 if (body.declaresLocal(v.getName().toString().trim())) {
00313 parm += (v.toString() + ", ");
00314 }
00315 }
00316 if (parm.length() > 1)
00317 parm = parm.substring(0, parm.length() - 2);
00318 result += (parm + ")");
00319 setText(result);
00320 } catch (Exception e) {
00321 }
00322 setIcon(IconLibrary.methodIcon);
00323 if (!CodeBrowserPane.this.reachableSootMethods.contains(sm))
00324 setForeground(Preferences.getUnreachableColor());
00325 else
00326 if (CodeBrowserPane.this.removableSootMethods.contains(sm))
00327 setForeground(Preferences.getSlicedColor());
00328 else
00329 if (CodeBrowserPane.this.modifiedSootMethods.contains(sm))
00330 setForeground(Preferences.getModifiedColor());
00331 } else
00332 if (o instanceof MethodDeclarationAnnotation) {
00333 MethodDeclarationAnnotation mda = (MethodDeclarationAnnotation) o;
00334 SootMethod sm = mda.getSootMethod();
00335 Method m = mda.getMethod();
00336 String result = sm.getReturnType().toString().trim() + " " + sm.getName().trim() + "(";
00337 JimpleBody body = (JimpleBody) sm.getBody(Jimple.v());
00338 String parm = "";
00339 for (Enumeration e = m.getParameters().elements(); e.hasMoreElements();) {
00340 Variable v = (Variable) e.nextElement();
00341 if (body.declaresLocal(v.getName().toString().trim())) {
00342 parm += (v.toString() + ", ");
00343 }
00344 }
00345 if (parm.length() > 1)
00346 parm = parm.substring(0, parm.length() - 2);
00347 result += (parm + ")");
00348 setText(result);
00349 setIcon(IconLibrary.methodIcon);
00350 if (!CodeBrowserPane.this.reachableSootMethods.contains(sm))
00351 setForeground(Preferences.getUnreachableColor());
00352 else
00353 if (CodeBrowserPane.this.removableSootMethods.contains(sm))
00354 setForeground(Preferences.getSlicedColor());
00355 else
00356 if (CodeBrowserPane.this.modifiedSootMethods.contains(sm))
00357 setForeground(Preferences.getModifiedColor());
00358 }
00359 return this;
00360 }
00361 });
00362 ((DefaultTreeCellRenderer) ivjHierTree.getCellRenderer()).setBackgroundNonSelectionColor(new Color(204, 204, 204));
00363 ((DefaultTreeCellRenderer) ivjHierTree.getCellRenderer()).setBackgroundSelectionColor(Preferences.getHighlightColor());
00364 ivjHierTree.putClientProperty("JTree.lineStyle", "Angled");
00365
00366
00367 } catch (java.lang.Throwable ivjExc) {
00368
00369
00370 handleException(ivjExc);
00371 }
00372 }
00373 return ivjHierTree;
00374 }
00375
00376
00377
00378
00379
00380 public javax.swing.JScrollPane getHierTreeScrollPane() {
00381 if (ivjHierTreeScrollPane == null) {
00382 try {
00383 ivjHierTreeScrollPane = new javax.swing.JScrollPane();
00384 ivjHierTreeScrollPane.setName("HierTreeScrollPane");
00385 getHierTreeScrollPane().setViewportView(getHierTree());
00386
00387
00388 } catch (java.lang.Throwable ivjExc) {
00389
00390
00391 handleException(ivjExc);
00392 }
00393 }
00394 return ivjHierTreeScrollPane;
00395 }
00396
00397
00398
00399
00400
00401
00402 private int getLocalDecState(LocalDeclarationStmtAnnotation ldsa) {
00403 Annotation mdAnnotation = CompilationManager.getAnnotationManager().getMethodAnnotationContainingAnnotation(ldsa);
00404 SootMethod sootMethod = null;
00405 if (mdAnnotation instanceof MethodDeclarationAnnotation)
00406 sootMethod = ((MethodDeclarationAnnotation) mdAnnotation).getSootMethod();
00407 else
00408 if (mdAnnotation instanceof ConstructorDeclarationAnnotation)
00409 sootMethod = ((ConstructorDeclarationAnnotation) mdAnnotation).getSootMethod();
00410 if (sootMethod == null)
00411 throw new edu.ksu.cis.bandera.pdgslicer.exceptions.SlicerException("sootMethod is null");
00412 if (postProcessOnAnnotation == null)
00413 return Statements.REMAINED;
00414 ca.mcgill.sable.util.Set removableLocals = postProcessOnAnnotation.getRemovableLocals(sootMethod);
00415 if (removableLocals == null)
00416 return ldsa.getAnnotationState();
00417 int removeNum = 0;
00418 for (Enumeration elem = ldsa.getDeclaredLocals().elements(); elem.hasMoreElements();) {
00419 Local decLocal = (Local) elem.nextElement();
00420 if (removableLocals.contains(decLocal))
00421 removeNum++;
00422 }
00423 if (removeNum == 0)
00424
00425
00426
00427 return ldsa.getAnnotationState();
00428 else
00429 if (removeNum == ldsa.getDeclaredLocals().size())
00430 return Statements.SLICED;
00431 else
00432 return Statements.MODIFIED;
00433 }
00434
00435
00436
00437
00438
00439 public DraggableMethodTree getMethodTree() {
00440 if (ivjMethodTree == null) {
00441 try {
00442 ivjMethodTree = new edu.ksu.cis.bandera.pdgslicer.dependency.DraggableMethodTree();
00443 ivjMethodTree.setName("MethodTree");
00444 ivjMethodTree.setBackground(new java.awt.Color(204, 204, 204));
00445 ivjMethodTree.setBounds(0, 0, 78, 72);
00446
00447 ivjMethodTree.setUI(new javax.swing.plaf.metal.MetalTreeUI() {
00448 public javax.swing.plaf.metal.MetalTreeUI setAngledColor() {
00449 setHashColor(Color.black);
00450 return this;
00451 }
00452 }
00453 .setAngledColor());
00454 ivjMethodTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("")));
00455 ivjMethodTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
00456 ivjMethodTree.setCellRenderer(new DefaultTreeCellRenderer() {
00457 public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
00458 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
00459 setIcon(null);
00460 Object o = ((DefaultMutableTreeNode) value).getUserObject();
00461 setForeground(Color.black);
00462 if (o instanceof Predicate) {
00463 setForeground(Preferences.getPredicateColor());
00464 if (!((Predicate) o).isValid())
00465 setIcon(IconLibrary.errorIcon);
00466 } else
00467 if (o instanceof Assertion) {
00468 setForeground(Preferences.getAssertionColor());
00469 if (!((Assertion) o).isValid())
00470 setIcon(IconLibrary.errorIcon);
00471 }
00472 if (o instanceof Annotation) {
00473 Annotation a = (Annotation) o;
00474 if (a instanceof MethodDeclarationAnnotation) {
00475 SootMethod sm = ((MethodDeclarationAnnotation) a).getSootMethod();
00476 if (parameterModifiedMethods.contains(sm))
00477 setForeground(Preferences.getModifiedColor());
00478 } else
00479 if (a instanceof ConstructorDeclarationAnnotation) {
00480 SootMethod sm = ((ConstructorDeclarationAnnotation) a).getSootMethod();
00481 if (parameterModifiedMethods.contains(sm))
00482 setForeground(Preferences.getModifiedColor());
00483 } else
00484 if (!((DefaultMutableTreeNode) value).isRoot() && !(a instanceof LocalDeclarationStmtAnnotation)) {
00485 switch (a.getAnnotationState()) {
00486 case Statements.SLICED :
00487 setForeground(Preferences.getSlicedColor());
00488 break;
00489 case Statements.MODIFIED :
00490 setForeground(Preferences.getModifiedColor());
00491 break;
00492 default :
00493 ;
00494 }
00495 } else
00496 if ((a instanceof LocalDeclarationStmtAnnotation)) {
00497 int localDecState = CodeBrowserPane.this.getLocalDecState((LocalDeclarationStmtAnnotation) a);
00498 switch (localDecState) {
00499 case Statements.SLICED :
00500 setForeground(Preferences.getSlicedColor());
00501 break;
00502 case Statements.MODIFIED :
00503 setForeground(Preferences.getModifiedColor());
00504 break;
00505 default :
00506 ;
00507 }
00508 }
00509 }
00510 return this;
00511 }
00512 });
00513 ((DefaultTreeCellRenderer) ivjMethodTree.getCellRenderer()).setBackgroundNonSelectionColor(new Color(204, 204, 204));
00514 ((DefaultTreeCellRenderer) ivjMethodTree.getCellRenderer()).setBackgroundSelectionColor(Preferences.getHighlightColor());
00515 ivjMethodTree.putClientProperty("JTree.lineStyle", "Angled");
00516
00517
00518 } catch (java.lang.Throwable ivjExc) {
00519
00520
00521 handleException(ivjExc);
00522 }
00523 }
00524 return ivjMethodTree;
00525 }
00526
00527
00528
00529
00530
00531 public javax.swing.JScrollPane getMethodTreeScrollPane() {
00532 if (ivjMethodTreeScrollPane == null) {
00533 try {
00534 ivjMethodTreeScrollPane = new javax.swing.JScrollPane();
00535 ivjMethodTreeScrollPane.setName("MethodTreeScrollPane");
00536 ivjMethodTreeScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
00537 ivjMethodTreeScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
00538 getMethodTreeScrollPane().setViewportView(getMethodTree());
00539
00540
00541
00542 } catch (java.lang.Throwable ivjExc) {
00543
00544
00545 handleException(ivjExc);
00546 }
00547 }
00548 return ivjMethodTreeScrollPane;
00549 }
00550 private StmtTreeNode getSelectedTreeNode() {
00551
00552 JTree hierTree = getHierTree();
00553 JTree methodTree = getMethodTree();
00554 DefaultMutableTreeNode hierTreeSelected = (DefaultMutableTreeNode) hierTree.getLastSelectedPathComponent();
00555 if (hierTreeSelected==null) return null;
00556 Object hierTreeSelectedObj = hierTreeSelected.getUserObject();
00557 Annotation mda = null;
00558 SootClass sc = null;
00559 Annotation stmtAnn = null;
00560 if ((hierTreeSelectedObj instanceof MethodDeclarationAnnotation) ||
00561 (hierTreeSelectedObj instanceof ConstructorDeclarationAnnotation)) {
00562 mda = (Annotation) hierTreeSelectedObj;
00563 DefaultMutableTreeNode classNode = (DefaultMutableTreeNode) hierTreeSelected.getParent();
00564 Object classObj = classNode.getUserObject();
00565 if (classObj instanceof SootClass)
00566 sc = (SootClass) classObj;
00567 else
00568 System.out.println("error: classObj is not SootClass");
00569 } else
00570 System.out.println("we do not deal with other selection currently rather than methodDeclarationAnnotation");
00571
00572 DefaultMutableTreeNode methodTreeSelected = (DefaultMutableTreeNode) methodTree.getLastSelectedPathComponent();
00573 Object methodTreeSelectedObj = methodTreeSelected.getUserObject();
00574 if (methodTreeSelectedObj instanceof Annotation) {
00575 stmtAnn = (Annotation) methodTreeSelectedObj;
00576 } else
00577 System.out.println("error: methodTreeSelected is not Annotation");
00578 dependFrame.currentMethodDecAnn = mda;
00579 return new StmtTreeNode(sc, mda, stmtAnn);
00580 }
00581
00582
00583
00584
00585 private void handleException(java.lang.Throwable exception) {
00586
00587
00588
00589
00590 }
00591
00592
00593
00594 public void hierTree_MouseClicked(java.awt.event.MouseEvent mouseEvent) {
00595
00596 int selRow = getHierTree().getRowForLocation(mouseEvent.getX(), mouseEvent.getY());
00597 TreePath selPath = getHierTree().getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
00598 if(selRow != -1) {
00599 if(mouseEvent.getClickCount() == 1) {
00600
00601 System.out.println("My sigle click on the tree");
00602 }
00603 else if(mouseEvent.getClickCount() == 2) {
00604
00605 System.out.println("My DOUBLE click on the tree");
00606 }
00607 }
00608
00609 return;
00610 }
00611
00612
00613
00614 public void hierTree_TreeSelectionAction(Object selectedObj, boolean showJimple) {
00615 if (selectedObj instanceof MethodDeclarationAnnotation) {
00616 updateMethodTree((MethodDeclarationAnnotation) selectedObj, null);
00617 SootMethod sm = ((MethodDeclarationAnnotation) selectedObj).getSootMethod();
00618 if (showJimple)
00619 dependFrame.jimpleCodeForSootMethod(sm);
00620
00621 } else
00622 if (selectedObj instanceof ConstructorDeclarationAnnotation) {
00623 ConstructorDeclarationAnnotation cda = (ConstructorDeclarationAnnotation) selectedObj;
00624 if (showJimple)
00625 dependFrame.jimpleCodeForSootMethod(cda.getSootMethod());
00626 if (cda.getNode() == null) {
00627 getMethodTree().setRootVisible(true);
00628 getMethodTree().setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Source code unavailable")));
00629 getMethodTreeScrollPane().validate();
00630 getMethodTreeScrollPane().repaint();
00631 return;
00632 }
00633 DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
00634 root.add((DefaultMutableTreeNode) BUISessionPane.buildTree(cda).elementAt(0));
00635 JTree rightTree = getMethodTree();
00636 rightTree.setRootVisible(false);
00637 rightTree.setModel(new DefaultTreeModel(root));
00638 for (int i = 0; i < rightTree.getRowCount(); i++) {
00639 rightTree.expandPath(rightTree.getPathForRow(i));
00640 }
00641 getMethodTreeScrollPane().validate();
00642 getMethodTreeScrollPane().repaint();
00643 } else
00644 if (selectedObj instanceof FieldDeclarationAnnotation) {
00645 FieldDeclarationAnnotation fda = (FieldDeclarationAnnotation) selectedObj;
00646 getMethodTree().setRootVisible(true);
00647 getMethodTree().setModel(new DefaultTreeModel(new DefaultMutableTreeNode(fda)));
00648 getMethodTreeScrollPane().validate();
00649 getMethodTreeScrollPane().repaint();
00650 } else {
00651 if (selectedObj instanceof SootClass) {
00652
00653 if (showJimple)
00654 dependFrame.jimpleCodeForSootClass((SootClass) selectedObj);
00655 }
00656 getMethodTree().setRootVisible(false);
00657 getMethodTree().setModel(new DefaultTreeModel(new DefaultMutableTreeNode("")));
00658 getMethodTreeScrollPane().validate();
00659 getMethodTreeScrollPane().repaint();
00660 }
00661 return;
00662 }
00663
00664
00665
00666 public void hierTree_TreeSelectionEvents() {
00667 Object selectedObj = ((DefaultMutableTreeNode) getHierTree().getLastSelectedPathComponent()).getUserObject();
00668 boolean showJimple = true;
00669 if (selectedObj != null)
00670 hierTree_TreeSelectionAction(selectedObj, showJimple);
00671 return;
00672 }
00673
00674
00675
00676
00677
00678 private void initConnections() throws java.lang.Exception {
00679
00680
00681 getHierTree().addTreeSelectionListener(this);
00682 getMethodTree().addMouseListener(this);
00683 getMethodTree().addTreeSelectionListener(this);
00684 }
00685
00686
00687
00688
00689 private void initialize() {
00690 try {
00691
00692
00693 setName("CodeBrowserPane");
00694 setLayout(new java.awt.BorderLayout());
00695 setSize(507, 287);
00696 add(getCodeSplitPane(), "Center");
00697 initConnections();
00698 } catch (java.lang.Throwable ivjExc) {
00699 handleException(ivjExc);
00700 }
00701
00702
00703 }
00704
00705
00706
00707
00708 public static void main(java.lang.String[] args) {
00709 try {
00710 JFrame frame = new javax.swing.JFrame();
00711 CodeBrowserPane aCodeBrowserPane;
00712 aCodeBrowserPane = new CodeBrowserPane();
00713 frame.setContentPane(aCodeBrowserPane);
00714 frame.setSize(aCodeBrowserPane.getSize());
00715 frame.addWindowListener(new java.awt.event.WindowAdapter() {
00716 public void windowClosing(java.awt.event.WindowEvent e) {
00717 System.exit(0);
00718 };
00719 });
00720 frame.setVisible(true);
00721 } catch (Throwable exception) {
00722 System.err.println("Exception occurred in main() of javax.swing.JPanel");
00723 exception.printStackTrace(System.out);
00724 }
00725 }
00726
00727
00728
00729 public void methodTree_MouseClicked(java.awt.event.MouseEvent mouseEvent) {
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747 return;
00748 }
00749
00750
00751
00752 public void methodTree_TreeSelectionAction(Annotation ann) {
00753 if (ann instanceof MethodDeclarationAnnotation) {
00754 SootMethod sm = ((MethodDeclarationAnnotation) ann).getSootMethod();
00755 dependFrame.jimpleCodeForSootMethod(sm);
00756 } else
00757 if (ann instanceof ConstructorDeclarationAnnotation) {
00758 SootMethod sm = ((ConstructorDeclarationAnnotation) ann).getSootMethod();
00759 dependFrame.jimpleCodeForSootMethod(sm);
00760 } else {
00761 dependFrame.jimpleCodeForAnnotation(ann);
00762 StmtTreeNode selectedNode = getSelectedTreeNode();
00763 dependFrame.addSelectedNodeToDependFrame(selectedNode);
00764 }
00765 return;
00766 }
00767
00768
00769
00770 public void methodTree_TreeSelectionActionByProgram(Annotation ann) {
00771 if (ann instanceof MethodDeclarationAnnotation) {
00772 SootMethod sm = ((MethodDeclarationAnnotation) ann).getSootMethod();
00773 dependFrame.jimpleCodeForSootMethod(sm);
00774 } else
00775 if (ann instanceof ConstructorDeclarationAnnotation) {
00776 SootMethod sm = ((ConstructorDeclarationAnnotation) ann).getSootMethod();
00777 dependFrame.jimpleCodeForSootMethod(sm);
00778 } else {
00779 dependFrame.jimpleCodeForAnnotation(ann);
00780
00781
00782 }
00783 return;
00784 }
00785
00786
00787
00788 public void methodTree_TreeSelectionEvents() {
00789 DefaultMutableTreeNode node = (DefaultMutableTreeNode) getMethodTree().getLastSelectedPathComponent();
00790 Annotation ann = (Annotation) node.getUserObject();
00791 if (ann != null)
00792 methodTree_TreeSelectionAction(ann);
00793 return;
00794 }
00795
00796
00797
00798
00799
00800 public void mouseClicked(java.awt.event.MouseEvent e) {
00801
00802
00803 if (e.getSource() == getMethodTree())
00804 connEtoC3(e);
00805
00806
00807 }
00808
00809
00810
00811
00812
00813 public void mouseEntered(java.awt.event.MouseEvent e) {
00814
00815
00816
00817
00818 }
00819
00820
00821
00822
00823
00824 public void mouseExited(java.awt.event.MouseEvent e) {
00825
00826
00827
00828
00829 }
00830
00831
00832
00833
00834
00835 public void mousePressed(java.awt.event.MouseEvent e) {
00836
00837
00838
00839
00840 }
00841
00842
00843
00844
00845
00846 public void mouseReleased(java.awt.event.MouseEvent e) {
00847
00848
00849
00850
00851 }
00852
00853
00854
00855
00856 void repaintTrees() {
00857
00858 getHierTreeScrollPane().validate();
00859 getHierTreeScrollPane().repaint();
00860 getHierTreeScrollPane().setVisible(true);
00861 getMethodTreeScrollPane().validate();
00862 getMethodTreeScrollPane().repaint();
00863 getMethodTreeScrollPane().setVisible(true);
00864 }
00865
00866
00867
00868
00869
00870 void setCurrentNodeSelected(Object currentNode) {
00871 if (currentNode instanceof StmtTreeNode) {
00872 StmtTreeNode currentTreeNode = (StmtTreeNode) currentNode;
00873 setSelected(getHierTree(), currentTreeNode.currentMethodDeclarationAnnotation);
00874 boolean showJimple = false;
00875 hierTree_TreeSelectionAction(currentTreeNode.currentMethodDeclarationAnnotation, showJimple);
00876 setSelected(getMethodTree(), currentTreeNode.currentStmtAnnotation);
00877 methodTree_TreeSelectionActionByProgram(currentTreeNode.currentStmtAnnotation);
00878 } else
00879 if (currentNode instanceof LocationNodeInCriterionViewer) {
00880 LocationNodeInCriterionViewer currentTreeNode = (LocationNodeInCriterionViewer) currentNode;
00881 Annotation currentMethodDeclarationAnnotation = CompilationManager.getAnnotationManager().getAnnotation(currentTreeNode.sootMethod.getDeclaringClass(), currentTreeNode.sootMethod);
00882 setSelected(getHierTree(), currentMethodDeclarationAnnotation);
00883 boolean showJimple = false;
00884 hierTree_TreeSelectionAction(currentMethodDeclarationAnnotation, showJimple);
00885 setSelected(getMethodTree(), currentTreeNode.stmtAnnotation);
00886 methodTree_TreeSelectionActionByProgram(currentTreeNode.stmtAnnotation);
00887 } else
00888 if (currentNode instanceof SliceField) {
00889 SliceField sf = (SliceField) currentNode;
00890 Annotation fieldAnnotation = CompilationManager.getAnnotationManager().getAnnotation(sf.getSootClass(), sf.getSootField());
00891 setSelected(getHierTree(), fieldAnnotation);
00892 boolean showJimple = false;
00893 hierTree_TreeSelectionAction(fieldAnnotation, showJimple);
00894 } else
00895 if (currentNode instanceof SliceLocal) {
00896 SliceLocal sliceLocal = (SliceLocal) currentNode;
00897 Annotation annotationForMd = CompilationManager.getAnnotationManager().getAnnotation(sliceLocal.getSootClass(), sliceLocal.getSootMethod());
00898 Vector allAnnotationsInMd = annotationForMd.getAllAnnotations(true);
00899 for (Enumeration annEnum = allAnnotationsInMd.elements(); annEnum.hasMoreElements();) {
00900 Object nextElement = annEnum.nextElement();
00901 if (nextElement instanceof LocalDeclarationStmtAnnotation) {
00902 Hashtable declaredLocals = ((LocalDeclarationStmtAnnotation) nextElement).getDeclaredLocals();
00903 if (declaredLocals.containsValue(sliceLocal.getLocal())) {
00904 setSelected(getHierTree(), annotationForMd);
00905 boolean showJimple = false;
00906 hierTree_TreeSelectionAction(annotationForMd, showJimple);
00907 setSelected(getMethodTree(), nextElement);
00908 methodTree_TreeSelectionActionByProgram((Annotation)nextElement);
00909 break;
00910 }
00911 }
00912 }
00913 } else
00914 System.out.println("We can not deal with other type of node currently");
00915 }
00916
00917
00918
00919
00920
00921 void setDependFrame(Dependencies dpnd) {
00922 dependFrame = dpnd;
00923 }
00924
00925
00926
00927
00928 void setPostProcessValues() {
00929 postProcessOnAnnotation = dependFrame.slicer.getPostProcessOnAnnotation();
00930 removablePackages = postProcessOnAnnotation.getRemovablePackages();
00931 modifiedPackages = postProcessOnAnnotation.getModifiedPackages();
00932 removableSootClasses = postProcessOnAnnotation.getRemovableSootClasses();
00933 modifiedSootClasses = postProcessOnAnnotation.getModifiedSootClasses();
00934 removableSootFields = postProcessOnAnnotation.getRemovableSootFields();
00935 removableSootMethods = postProcessOnAnnotation.getRemovableSootMethods();
00936 modifiedSootMethods = postProcessOnAnnotation.getModifiedSootMethods();
00937 parameterModifiedMethods = postProcessOnAnnotation.getParameterModifiedMethods();
00938 }
00939
00940
00941
00942
00943
00944 private void setSelected(JTree tree, Object object) {
00945 setSelectedByProgram = true;
00946 for (int i = 0; i < tree.getRowCount(); i++) {
00947 tree.setSelectionRow(i);
00948 DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
00949 Object o = node.getUserObject();
00950 if (o == object) {
00951 TreePath path = tree.getSelectionPath();
00952 tree.scrollPathToVisible(path);
00953 setSelectedByProgram = false;
00954 return;
00955 } else {
00956 tree.expandRow(i);
00957 }
00958 }
00959 setSelectedByProgram = false;
00960 }
00961 void updateHierTree(Object hierTreeSelectedUserObject) {
00962 Session sess = BUI.sessions.getActiveSession();
00963 String rootName = sess.getName();
00964 getHierTree().setRootVisible(true);
00965 DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootName);
00966 Hashtable compiledClasses = CompilationManager.getAnnotationManager().getAnnotationTable();
00967 TreeSet packageNames = new TreeSet();
00968 for (Enumeration e = compiledClasses.keys(); e.hasMoreElements();) {
00969 packageNames.add(new Name(((SootClass) e.nextElement()).getName()).getSuperName());
00970 }
00971 for (Iterator i = packageNames.iterator(); i.hasNext();) {
00972 try {
00973 Package p = Package.getPackage((Name) i.next());
00974 DefaultMutableTreeNode pNode = buildPackageNode(p);
00975 root.add(pNode);
00976 } catch (Exception e) {
00977 System.out.println("There is an exception");
00978 System.out.println("Exception e: " + e);
00979 e.printStackTrace();
00980 }
00981 }
00982 getHierTree().setModel(new DefaultTreeModel(root));
00983 getHierTreeScrollPane().validate();
00984 getHierTreeScrollPane().repaint();
00985 getCodeSplitPane().resetToPreferredSizes();
00986 if (hierTreeSelectedUserObject != null)
00987 setSelected(getHierTree(), hierTreeSelectedUserObject);
00988 else
00989 getMethodTree().setModel(new DefaultTreeModel(new DefaultMutableTreeNode("")));
00990 }
00991
00992
00993
00994
00995
00996
00997 void updateMethodTree(MethodDeclarationAnnotation mdAnnotation, Object lastSelectedUserObject) {
00998 DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
00999 for (java.util.Iterator i = PredicateSet.getDefinedPredicates(mdAnnotation).iterator(); i.hasNext();) {
01000 root.add(new DefaultMutableTreeNode(i.next()));
01001 }
01002 for (java.util.Iterator i = AssertionSet.getDefinedAssertions(mdAnnotation).iterator(); i.hasNext();) {
01003 root.add(new DefaultMutableTreeNode(i.next()));
01004 }
01005 root.add((DefaultMutableTreeNode) BUISessionPane.buildTree(mdAnnotation).elementAt(0));
01006 JTree methodTree = getMethodTree();
01007 methodTree.setRootVisible(false);
01008 methodTree.setModel(new DefaultTreeModel(root));
01009 for (int i = 0; i < methodTree.getRowCount(); i++) {
01010 methodTree.expandPath(methodTree.getPathForRow(i));
01011 }
01012 getMethodTreeScrollPane().validate();
01013 getMethodTreeScrollPane().repaint();
01014
01015 if (lastSelectedUserObject != null)
01016 setSelected(methodTree, lastSelectedUserObject);
01017 }
01018
01019
01020
01021
01022
01023 public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
01024
01025
01026 if (e.getSource() == getHierTree())
01027 connEtoC1();
01028 if (e.getSource() == getMethodTree())
01029 connEtoC4();
01030
01031
01032 }
01033 }