00001 package edu.ksu.cis.bandera.pdgslicer.dependency;
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
00036 import javax.swing.*;
00037 import java.util.*;
00038 import edu.ksu.cis.bandera.pdgslicer.datastructure.*;
00039 import edu.ksu.cis.bandera.jjjc.CompilationManager;
00040 import edu.ksu.cis.bandera.annotation.*;
00041 import ca.mcgill.sable.soot.*;
00042 import ca.mcgill.sable.soot.jimple.*;
00043
00044
00045
00046
00047
00048 public class CriterionViewer extends JPanel {
00049 private boolean setSelectedByProgram = false;
00050 private Vector currentCriterion = new Vector();
00051 private Vector lastTimeRunningCriterion = new Vector();
00052 Vector runningCriterion = null;
00053 private JLabel ivjLocationsLabel = null;
00054 private DroppableLocationsList ivjLocationsList = null;
00055 private JPanel ivjLocationsPanel = null;
00056 private JScrollPane ivjLocationsScrollPane = null;
00057 private JSplitPane ivjPointVarSplitPane = null;
00058 private JButton ivjRemoveLocationButton = null;
00059 private JButton ivjRemoveStatementButton = null;
00060 private JButton ivjRemoveVarsButton = null;
00061 private JLabel ivjStatementLabel = null;
00062 private JPanel ivjStatementPanel = null;
00063 private JScrollPane ivjStatementScrollPane = null;
00064 private JSplitPane ivjStmtControlSplitPane = null;
00065 private JLabel ivjVarsLabel = null;
00066 private DroppableVariablesList ivjVarsList = null;
00067 private JPanel ivjVarsPanel = null;
00068 private JScrollPane ivjVarsScrollPane = null;
00069 private JSplitPane ivjLocationsVarsSplitPane = null;
00070 private DraggableVariablesList ivjLocationVarsList = null;
00071 private JScrollPane ivjLocationVarsScrollPane = null;
00072 private DroppableStatementsList ivjStatementsList = null;
00073 private Dependencies dependFrame;
00074 IvjEventHandler ivjEventHandler = new IvjEventHandler();
00075
00076 class IvjEventHandler implements java.awt.event.ActionListener, java.awt.event.MouseListener, javax.swing.event.ListSelectionListener {
00077 public void actionPerformed(java.awt.event.ActionEvent e) {
00078 if (e.getSource() == CriterionViewer.this.getRemoveStatementButton())
00079 connEtoC1();
00080 if (e.getSource() == CriterionViewer.this.getRemoveLocationButton())
00081 connEtoC2();
00082 if (e.getSource() == CriterionViewer.this.getRemoveVarsButton())
00083 connEtoC3();
00084 };
00085 public void mouseClicked(java.awt.event.MouseEvent e) {
00086 if (e.getSource() == CriterionViewer.this.getStatementsList())
00087 connEtoC6(e);
00088 if (e.getSource() == CriterionViewer.this.getLocationsList())
00089 connEtoC7(e);
00090 };
00091 public void mouseEntered(java.awt.event.MouseEvent e) {};
00092 public void mouseExited(java.awt.event.MouseEvent e) {};
00093 public void mousePressed(java.awt.event.MouseEvent e) {};
00094 public void mouseReleased(java.awt.event.MouseEvent e) {};
00095 public void valueChanged(javax.swing.event.ListSelectionEvent e) {
00096 if (e.getSource() == CriterionViewer.this.getLocationsList())
00097 connEtoC4();
00098 if (e.getSource() == CriterionViewer.this.getStatementsList())
00099 connEtoC5();
00100 if (e.getSource() == CriterionViewer.this.getVarsList())
00101 connEtoC8();
00102 if (e.getSource() == CriterionViewer.this.getLocationVarsList())
00103 connEtoC9();
00104 };
00105 };
00106
00107
00108
00109 public CriterionViewer() {
00110 super();
00111 initialize();
00112 }
00113
00114
00115
00116
00117 public CriterionViewer(java.awt.LayoutManager layout) {
00118 super(layout);
00119 }
00120
00121
00122
00123
00124
00125 public CriterionViewer(java.awt.LayoutManager layout, boolean isDoubleBuffered) {
00126 super(layout, isDoubleBuffered);
00127 }
00128
00129
00130
00131
00132 public CriterionViewer(boolean isDoubleBuffered) {
00133 super(isDoubleBuffered);
00134 }
00135
00136
00137
00138
00139
00140 void addLocationToCriterion(Object location, Annotation locationAnnotation) {
00141 if (!dependFrame.getBackwardSliceToolBarButton().isEnabled())
00142 dependFrame.getBackwardSliceToolBarButton().setEnabled(true);
00143 int locationIndex = currentCriterion.indexOf(location);
00144 if (locationIndex >= 0) {
00145 System.out.println("the point has been in the current criterion");
00146 return;
00147 }
00148 currentCriterion.add(location);
00149 DefaultListModel listModel = null;
00150
00151 SlicePoint sp = (SlicePoint) location;
00152 LocationNodeInCriterionViewer ln = null;
00153 ln = new LocationNodeInCriterionViewer(sp.getSootMethod(), locationAnnotation, sp);
00154 listModel = (DefaultListModel) getLocationsList().getModel();
00155
00156 listModel.addElement(ln);
00157 setSelectedByProgram = true;
00158 getLocationsList().setSelectedValue(ln, true);
00159 getStatementsList().clearSelection();
00160 calculateLocalsFor(ln);
00161 setSelectedByProgram = false;
00162 }
00163
00164
00165
00166
00167
00168 void addStatementToCriterion(Object location, SlicePoint[] locationArray, Annotation locationAnnotation) {
00169 if (!dependFrame.getBackwardSliceToolBarButton().isEnabled())
00170 dependFrame.getBackwardSliceToolBarButton().setEnabled(true);
00171 int locationIndex = currentCriterion.indexOf(location);
00172 if (locationIndex >= 0) {
00173 Object location2 = currentCriterion.get(locationIndex);
00174 if (location2 instanceof SliceStatement) {
00175 System.out.println("the statement has been in the current criterion");
00176 return;
00177 } else
00178 if (location2 instanceof SlicePoint) {
00179 currentCriterion.remove(location2);
00180 currentCriterion.add(location);
00181 SlicePoint sp = (SlicePoint) location;
00182 LocationNodeInCriterionViewer ln = new StatementNodeInCriterionViewer(sp.getSootMethod(), locationAnnotation, sp,locationArray);
00183 DefaultListModel listModel = (DefaultListModel) getStatementsList().getModel();
00184 listModel.addElement(ln);
00185 setSelectedByProgram = true;
00186 getStatementsList().setSelectedValue(ln, true);
00187 getLocationsList().clearSelection();
00188 calculateLocalsFor(ln);
00189 setSelectedByProgram = false;
00190
00191 listModel = (DefaultListModel) getLocationsList().getModel();
00192 removeLocationFrom(location2, listModel);
00193 return;
00194 }
00195 }
00196 currentCriterion.add(location);
00197 DefaultListModel listModel = null;
00198
00199 SlicePoint sp = (SlicePoint) location;
00200 LocationNodeInCriterionViewer ln = null;
00201
00202
00203 listModel = (DefaultListModel) getStatementsList().getModel();
00204 if (!statementsListContains(listModel, locationAnnotation))
00205 ln = new StatementNodeInCriterionViewer(sp.getSootMethod(), locationAnnotation, sp, locationArray);
00206 if (ln == null)
00207 return;
00208 listModel.addElement(ln);
00209 setSelectedByProgram = true;
00210 getStatementsList().setSelectedValue(ln, true);
00211 getLocationsList().clearSelection();
00212
00213 setSelectedByProgram = false;
00214 }
00215
00216
00217
00218
00219
00220 void addVarToCriterion(Object var) {
00221 if (!dependFrame.getBackwardSliceToolBarButton().isEnabled())
00222 dependFrame.getBackwardSliceToolBarButton().setEnabled(true);
00223 if (currentCriterion.contains(var)) {
00224 System.out.println("the variable has been in the current criterion");
00225 return;
00226 }
00227 currentCriterion.add(var);
00228 DefaultListModel listModel = (DefaultListModel) getVarsList().getModel();
00229 listModel.addElement(var);
00230 }
00231
00232
00233
00234
00235
00236
00237 private Vector buildCriterionForCurrentNode(Object currentNode) {
00238 Vector returnCriterion = null;
00239 if (currentNode instanceof StmtTreeNode) {
00240 StmtTreeNode stn = (StmtTreeNode) currentNode;
00241 Annotation currentStmtAnnotation = stn.currentStmtAnnotation;
00242 if ((currentStmtAnnotation instanceof MethodDeclarationAnnotation) || (currentStmtAnnotation instanceof ConstructorDeclarationAnnotation))
00243 return null;
00244 returnCriterion = new Vector();
00245 Annotation currentMda = stn.currentMethodDeclarationAnnotation;
00246 SootMethod sm = ((MethodDeclarationAnnotation) currentMda).getSootMethod();
00247 SootClass sc = stn.currentSootClass;
00248 Stmt stmts[] = currentStmtAnnotation.getStatements();
00249 for (int i = 0; i < stmts.length; i++) {
00250 Stmt stmt = stmts[i];
00251 int sind = SlicePoint.getStmtIndex(sm, stmt);
00252 SliceStatement sliceStmt = new SliceStatement(sc, sm, stmt, sind);
00253 returnCriterion.addElement(sliceStmt);
00254 }
00255 }
00256 return returnCriterion;
00257 }
00258 private Vector buildLocalListFor(Annotation annotation, SootMethod sm) {
00259 Vector localList = new Vector();
00260 String className = null;
00261 SootClass sc = null;
00262 Object leftAnnotation = CompilationManager.getAnnotationManager().getMethodAnnotationContainingAnnotation(annotation);
00263 sc = sm.getDeclaringClass();
00264 className = sc.getName().trim();
00265 Hashtable table = annotation.getDeclaredLocalVariables();
00266 for (Enumeration e = table.keys(); e.hasMoreElements();) {
00267 String name = (String) e.nextElement();
00268 Local local = (Local) table.get(name);
00269 if (local.getType() instanceof ca.mcgill.sable.soot.ArrayType) {
00270 } else
00271 if (local.getType() instanceof RefType) {
00272 SliceLocal sl = new SliceLocal(sc, sm, local);
00273 localList.addElement(sl);
00274 } else {
00275 SliceLocal sl = new SliceLocal(sc, sm, local);
00276 localList.addElement(sl);
00277 }
00278 }
00279 return localList;
00280 }
00281
00282
00283
00284
00285
00286 private void calculateLocalsFor(LocationNodeInCriterionViewer locationNode) {
00287 Vector locals = buildLocalListFor(locationNode.stmtAnnotation, locationNode.sootMethod);
00288 DefaultListModel listModel = (DefaultListModel) getLocationVarsList().getModel();
00289 listModel.removeAllElements();
00290 for (Enumeration e = locals.elements(); e.hasMoreElements();)
00291 listModel.addElement(e.nextElement());
00292 }
00293
00294
00295
00296 SlicePoint calculateSlicePoint(Object userObjectInMethodTree) {
00297 if (!(userObjectInMethodTree instanceof Annotation))
00298 return null;
00299 SlicePoint sp = null;
00300 Annotation a = (Annotation) userObjectInMethodTree;
00301 Annotation leftAnnotation = CompilationManager.getAnnotationManager().getMethodAnnotationContainingAnnotation(a);
00302 if (leftAnnotation instanceof ConstructorDeclarationAnnotation) {
00303 ConstructorDeclarationAnnotation ann = (ConstructorDeclarationAnnotation) leftAnnotation;
00304 SootMethod sm = ann.getSootMethod();
00305 SootClass sc = sm.getDeclaringClass();
00306 Stmt stmts[] = a.getStatements();
00307 Stmt stmt = stmts[0];
00308 int sind = SlicePoint.getStmtIndex(sm, stmts[0]);
00309 sp = new SlicePoint(sc, sm, stmt, sind);
00310
00311 } else
00312 if (leftAnnotation instanceof MethodDeclarationAnnotation) {
00313 MethodDeclarationAnnotation ann = (MethodDeclarationAnnotation) leftAnnotation;
00314 SootMethod sm = ann.getSootMethod();
00315 SootClass sc = sm.getDeclaringClass();
00316 Stmt stmts[] = a.getStatements();
00317 Stmt stmt = stmts[0];
00318 int sind = SlicePoint.getStmtIndex(sm, stmts[0]);
00319 sp = new SlicePoint(sc, sm, stmt, sind);
00320
00321 }
00322 return sp;
00323 }
00324
00325
00326
00327 SlicePoint[] calculateSliceStatements(Object userObjectInMethodTree) {
00328 if (!(userObjectInMethodTree instanceof Annotation))
00329 return null;
00330 SlicePoint[] sp = null;
00331 Annotation a = (Annotation) userObjectInMethodTree;
00332 Annotation leftAnnotation = CompilationManager.getAnnotationManager().getMethodAnnotationContainingAnnotation(a);
00333 if (leftAnnotation instanceof ConstructorDeclarationAnnotation) {
00334 ConstructorDeclarationAnnotation ann = (ConstructorDeclarationAnnotation) leftAnnotation;
00335 SootMethod sm = ann.getSootMethod();
00336 SootClass sc = sm.getDeclaringClass();
00337 Stmt stmts[] = a.getStatements();
00338 sp = new SlicePoint[stmts.length];
00339 for (int i = 0; i < stmts.length; i++) {
00340 Stmt stmt = stmts[i];
00341 int sind = SlicePoint.getStmtIndex(sm, stmt);
00342 sp[i] = new SliceStatement(sc, sm, stmt, sind);
00343 }
00344
00345 } else
00346 if (leftAnnotation instanceof MethodDeclarationAnnotation) {
00347 MethodDeclarationAnnotation ann = (MethodDeclarationAnnotation) leftAnnotation;
00348 SootMethod sm = ann.getSootMethod();
00349 SootClass sc = sm.getDeclaringClass();
00350 Stmt stmts[] = a.getStatements();
00351 sp = new SlicePoint[stmts.length];
00352 for (int i = 0; i < stmts.length; i++) {
00353 Stmt stmt = stmts[i];
00354 int sind = SlicePoint.getStmtIndex(sm, stmts[i]);
00355 sp[i] = new SliceStatement(sc, sm, stmt, sind);
00356 }
00357
00358 }
00359 return sp;
00360 }
00361
00362
00363
00364
00365 private void connEtoC1() {
00366 try {
00367
00368
00369 this.removeStatementButton_ActionEvents();
00370
00371
00372 } catch (java.lang.Throwable ivjExc) {
00373
00374
00375 handleException(ivjExc);
00376 }
00377 }
00378
00379
00380
00381
00382 private void connEtoC2() {
00383 try {
00384
00385
00386 this.removeLocationButton_ActionEvents();
00387
00388
00389 } catch (java.lang.Throwable ivjExc) {
00390
00391
00392 handleException(ivjExc);
00393 }
00394 }
00395
00396
00397
00398
00399 private void connEtoC3() {
00400 try {
00401
00402
00403 this.removeVarsButton_ActionEvents();
00404
00405
00406 } catch (java.lang.Throwable ivjExc) {
00407
00408
00409 handleException(ivjExc);
00410 }
00411 }
00412
00413
00414
00415
00416 private void connEtoC4() {
00417 try {
00418
00419 if (!setSelectedByProgram)
00420
00421 this.locationsList_ListSelectionEvents();
00422
00423
00424 } catch (java.lang.Throwable ivjExc) {
00425
00426
00427 handleException(ivjExc);
00428 }
00429 }
00430
00431
00432
00433
00434 private void connEtoC5() {
00435 try {
00436
00437 if (!setSelectedByProgram)
00438
00439 this.statementsList_ListSelectionEvents();
00440
00441
00442 } catch (java.lang.Throwable ivjExc) {
00443
00444
00445 handleException(ivjExc);
00446 }
00447 }
00448
00449
00450
00451
00452
00453 private void connEtoC6(java.awt.event.MouseEvent arg1) {
00454 try {
00455
00456
00457 this.statementsList_MouseClicked(arg1);
00458
00459
00460 } catch (java.lang.Throwable ivjExc) {
00461
00462
00463 handleException(ivjExc);
00464 }
00465 }
00466
00467
00468
00469
00470
00471 private void connEtoC7(java.awt.event.MouseEvent arg1) {
00472 try {
00473
00474
00475 this.locationsList_MouseClicked(arg1);
00476
00477
00478 } catch (java.lang.Throwable ivjExc) {
00479
00480
00481 handleException(ivjExc);
00482 }
00483 }
00484
00485
00486
00487
00488 private void connEtoC8() {
00489 try {
00490
00491 if (!setSelectedByProgram)
00492
00493 this.varsList_ListSelectionEvents();
00494
00495
00496 } catch (java.lang.Throwable ivjExc) {
00497
00498
00499 handleException(ivjExc);
00500 }
00501 }
00502
00503
00504
00505
00506 private void connEtoC9() {
00507 try {
00508
00509 if (!setSelectedByProgram)
00510
00511 this.locationVarsList_ListSelectionEvents();
00512
00513
00514 } catch (java.lang.Throwable ivjExc) {
00515
00516
00517 handleException(ivjExc);
00518 }
00519 }
00520
00521
00522
00523
00524
00525 private javax.swing.JLabel getLocationsLabel() {
00526 if (ivjLocationsLabel == null) {
00527 try {
00528 ivjLocationsLabel = new javax.swing.JLabel();
00529 ivjLocationsLabel.setName("LocationsLabel");
00530 ivjLocationsLabel.setText("Control Slice");
00531 ivjLocationsLabel.setForeground(java.awt.Color.black);
00532 ivjLocationsLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
00533
00534
00535 } catch (java.lang.Throwable ivjExc) {
00536
00537
00538 handleException(ivjExc);
00539 }
00540 }
00541 return ivjLocationsLabel;
00542 }
00543
00544
00545
00546
00547
00548 private DroppableLocationsList getLocationsList() {
00549 if (ivjLocationsList == null) {
00550 try {
00551 ivjLocationsList = new edu.ksu.cis.bandera.pdgslicer.dependency.DroppableLocationsList();
00552 ivjLocationsList.setName("LocationsList");
00553 ivjLocationsList.setBounds(0, 0, 160, 120);
00554
00555 ivjLocationsList.setCriterionViewer(this);
00556
00557 } catch (java.lang.Throwable ivjExc) {
00558
00559
00560 handleException(ivjExc);
00561 }
00562 }
00563 return ivjLocationsList;
00564 }
00565
00566
00567
00568
00569
00570 private javax.swing.JPanel getLocationsPanel() {
00571 if (ivjLocationsPanel == null) {
00572 try {
00573 ivjLocationsPanel = new javax.swing.JPanel();
00574 ivjLocationsPanel.setName("LocationsPanel");
00575 ivjLocationsPanel.setLayout(new java.awt.BorderLayout());
00576 getLocationsPanel().add(getLocationsLabel(), "North");
00577 getLocationsPanel().add(getRemoveLocationButton(), "South");
00578 getLocationsPanel().add(getLocationsVarsSplitPane(), "Center");
00579
00580
00581 } catch (java.lang.Throwable ivjExc) {
00582
00583
00584 handleException(ivjExc);
00585 }
00586 }
00587 return ivjLocationsPanel;
00588 }
00589
00590
00591
00592
00593
00594 private javax.swing.JScrollPane getLocationsScrollPane() {
00595 if (ivjLocationsScrollPane == null) {
00596 try {
00597 ivjLocationsScrollPane = new javax.swing.JScrollPane();
00598 ivjLocationsScrollPane.setName("LocationsScrollPane");
00599 getLocationsScrollPane().setViewportView(getLocationsList());
00600
00601
00602 } catch (java.lang.Throwable ivjExc) {
00603
00604
00605 handleException(ivjExc);
00606 }
00607 }
00608 return ivjLocationsScrollPane;
00609 }
00610
00611
00612
00613
00614
00615 public javax.swing.JSplitPane getLocationsVarsSplitPane() {
00616 if (ivjLocationsVarsSplitPane == null) {
00617 try {
00618 ivjLocationsVarsSplitPane = new javax.swing.JSplitPane(javax.swing.JSplitPane.HORIZONTAL_SPLIT);
00619 ivjLocationsVarsSplitPane.setName("LocationsVarsSplitPane");
00620 ivjLocationsVarsSplitPane.setDividerSize(1);
00621 ivjLocationsVarsSplitPane.setDividerLocation(40);
00622 getLocationsVarsSplitPane().add(getLocationsScrollPane(), "left");
00623 getLocationsVarsSplitPane().add(getLocationVarsScrollPane(), "right");
00624
00625 ivjLocationsVarsSplitPane.setDividerLocation(80);
00626
00627 } catch (java.lang.Throwable ivjExc) {
00628
00629
00630 handleException(ivjExc);
00631 }
00632 }
00633 return ivjLocationsVarsSplitPane;
00634 }
00635
00636
00637
00638
00639
00640 private DraggableVariablesList getLocationVarsList() {
00641 if (ivjLocationVarsList == null) {
00642 try {
00643 ivjLocationVarsList = new edu.ksu.cis.bandera.pdgslicer.dependency.DraggableVariablesList();
00644 ivjLocationVarsList.setName("LocationVarsList");
00645 ivjLocationVarsList.setBounds(0, 0, 160, 120);
00646
00647
00648 } catch (java.lang.Throwable ivjExc) {
00649
00650
00651 handleException(ivjExc);
00652 }
00653 }
00654 return ivjLocationVarsList;
00655 }
00656
00657
00658
00659
00660
00661 private javax.swing.JScrollPane getLocationVarsScrollPane() {
00662 if (ivjLocationVarsScrollPane == null) {
00663 try {
00664 ivjLocationVarsScrollPane = new javax.swing.JScrollPane();
00665 ivjLocationVarsScrollPane.setName("LocationVarsScrollPane");
00666 getLocationVarsScrollPane().setViewportView(getLocationVarsList());
00667
00668
00669 } catch (java.lang.Throwable ivjExc) {
00670
00671
00672 handleException(ivjExc);
00673 }
00674 }
00675 return ivjLocationVarsScrollPane;
00676 }
00677
00678
00679
00680
00681
00682 public javax.swing.JSplitPane getPointVarSplitPane() {
00683 if (ivjPointVarSplitPane == null) {
00684 try {
00685 ivjPointVarSplitPane = new javax.swing.JSplitPane(javax.swing.JSplitPane.HORIZONTAL_SPLIT);
00686 ivjPointVarSplitPane.setName("PointVarSplitPane");
00687 ivjPointVarSplitPane.setDividerSize(2);
00688 ivjPointVarSplitPane.setDividerLocation(200);
00689 getPointVarSplitPane().add(getStmtControlSplitPane(), "left");
00690 getPointVarSplitPane().add(getVarsPanel(), "right");
00691
00692
00693
00694 } catch (java.lang.Throwable ivjExc) {
00695
00696
00697 handleException(ivjExc);
00698 }
00699 }
00700 return ivjPointVarSplitPane;
00701 }
00702
00703
00704
00705
00706
00707 private javax.swing.JButton getRemoveLocationButton() {
00708 if (ivjRemoveLocationButton == null) {
00709 try {
00710 ivjRemoveLocationButton = new javax.swing.JButton();
00711 ivjRemoveLocationButton.setName("RemoveLocationButton");
00712 ivjRemoveLocationButton.setText("Remove Control Point");
00713
00714
00715 } catch (java.lang.Throwable ivjExc) {
00716
00717
00718 handleException(ivjExc);
00719 }
00720 }
00721 return ivjRemoveLocationButton;
00722 }
00723
00724
00725
00726
00727
00728 private javax.swing.JButton getRemoveStatementButton() {
00729 if (ivjRemoveStatementButton == null) {
00730 try {
00731 ivjRemoveStatementButton = new javax.swing.JButton();
00732 ivjRemoveStatementButton.setName("RemoveStatementButton");
00733 ivjRemoveStatementButton.setText("Remove Statement");
00734
00735
00736 } catch (java.lang.Throwable ivjExc) {
00737
00738
00739 handleException(ivjExc);
00740 }
00741 }
00742 return ivjRemoveStatementButton;
00743 }
00744
00745
00746
00747
00748
00749 private javax.swing.JButton getRemoveVarsButton() {
00750 if (ivjRemoveVarsButton == null) {
00751 try {
00752 ivjRemoveVarsButton = new javax.swing.JButton();
00753 ivjRemoveVarsButton.setName("RemoveVarsButton");
00754 ivjRemoveVarsButton.setText("Remove Variable");
00755
00756
00757 } catch (java.lang.Throwable ivjExc) {
00758
00759
00760 handleException(ivjExc);
00761 }
00762 }
00763 return ivjRemoveVarsButton;
00764 }
00765
00766
00767
00768
00769 Vector getSliceInterests() {
00770 SliceInterestEnv sliceInterestEnv = new SliceInterestEnv();
00771 sliceInterestEnv.setCriterionViewer(this);
00772 sliceInterestEnv.setDependFrame(this.dependFrame);
00773 return sliceInterestEnv.getSliceInterests();
00774 }
00775
00776
00777
00778
00779
00780 private javax.swing.JLabel getStatementLabel() {
00781 if (ivjStatementLabel == null) {
00782 try {
00783 ivjStatementLabel = new javax.swing.JLabel();
00784 ivjStatementLabel.setName("StatementLabel");
00785 ivjStatementLabel.setText("Statement Slice");
00786 ivjStatementLabel.setForeground(java.awt.Color.black);
00787 ivjStatementLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
00788
00789
00790 } catch (java.lang.Throwable ivjExc) {
00791
00792
00793 handleException(ivjExc);
00794 }
00795 }
00796 return ivjStatementLabel;
00797 }
00798
00799
00800
00801
00802
00803 private javax.swing.JPanel getStatementPanel() {
00804 if (ivjStatementPanel == null) {
00805 try {
00806 ivjStatementPanel = new javax.swing.JPanel();
00807 ivjStatementPanel.setName("StatementPanel");
00808 ivjStatementPanel.setLayout(new java.awt.BorderLayout());
00809 getStatementPanel().add(getStatementLabel(), "North");
00810 getStatementPanel().add(getRemoveStatementButton(), "South");
00811 getStatementPanel().add(getStatementScrollPane(), "Center");
00812
00813
00814 } catch (java.lang.Throwable ivjExc) {
00815
00816
00817 handleException(ivjExc);
00818 }
00819 }
00820 return ivjStatementPanel;
00821 }
00822
00823
00824
00825
00826
00827 private javax.swing.JScrollPane getStatementScrollPane() {
00828 if (ivjStatementScrollPane == null) {
00829 try {
00830 ivjStatementScrollPane = new javax.swing.JScrollPane();
00831 ivjStatementScrollPane.setName("StatementScrollPane");
00832 getStatementScrollPane().setViewportView(getStatementsList());
00833
00834
00835 } catch (java.lang.Throwable ivjExc) {
00836
00837
00838 handleException(ivjExc);
00839 }
00840 }
00841 return ivjStatementScrollPane;
00842 }
00843
00844
00845
00846
00847
00848 public DroppableStatementsList getStatementsList() {
00849 if (ivjStatementsList == null) {
00850 try {
00851 ivjStatementsList = new edu.ksu.cis.bandera.pdgslicer.dependency.DroppableStatementsList();
00852 ivjStatementsList.setName("StatementsList");
00853 ivjStatementsList.setBounds(0, 0, 160, 120);
00854
00855 ivjStatementsList.setCriterionViewer(this);
00856
00857 } catch (java.lang.Throwable ivjExc) {
00858
00859
00860 handleException(ivjExc);
00861 }
00862 }
00863 return ivjStatementsList;
00864 }
00865
00866
00867
00868
00869
00870 public javax.swing.JSplitPane getStmtControlSplitPane() {
00871 if (ivjStmtControlSplitPane == null) {
00872 try {
00873 ivjStmtControlSplitPane = new javax.swing.JSplitPane(javax.swing.JSplitPane.HORIZONTAL_SPLIT);
00874 ivjStmtControlSplitPane.setName("StmtControlSplitPane");
00875 ivjStmtControlSplitPane.setDividerSize(2);
00876 ivjStmtControlSplitPane.setDividerLocation(240);
00877 getStmtControlSplitPane().add(getStatementPanel(), "left");
00878 getStmtControlSplitPane().add(getLocationsPanel(), "right");
00879
00880
00881 } catch (java.lang.Throwable ivjExc) {
00882
00883
00884 handleException(ivjExc);
00885 }
00886 }
00887 return ivjStmtControlSplitPane;
00888 }
00889
00890
00891
00892
00893
00894
00895 private StmtTreeNode getStmtTreeNodeFromLocationNode(LocationNodeInCriterionViewer ln) {
00896 SootClass sc = ln.sootMethod.getDeclaringClass();
00897 Annotation mda = CompilationManager.getAnnotationManager().getAnnotation(sc, ln.sootMethod);
00898 Annotation stmtAnn = ln.stmtAnnotation;
00899 return new StmtTreeNode(sc, mda, stmtAnn);
00900 }
00901
00902
00903
00904
00905
00906 private javax.swing.JLabel getVarsLabel() {
00907 if (ivjVarsLabel == null) {
00908 try {
00909 ivjVarsLabel = new javax.swing.JLabel();
00910 ivjVarsLabel.setName("VarsLabel");
00911 ivjVarsLabel.setText("Variable Slice");
00912 ivjVarsLabel.setForeground(java.awt.Color.black);
00913 ivjVarsLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
00914
00915
00916 } catch (java.lang.Throwable ivjExc) {
00917
00918
00919 handleException(ivjExc);
00920 }
00921 }
00922 return ivjVarsLabel;
00923 }
00924
00925
00926
00927
00928
00929 private DroppableVariablesList getVarsList() {
00930 if (ivjVarsList == null) {
00931 try {
00932 ivjVarsList = new edu.ksu.cis.bandera.pdgslicer.dependency.DroppableVariablesList();
00933 ivjVarsList.setName("VarsList");
00934 ivjVarsList.setBounds(0, 0, 160, 120);
00935
00936 ivjVarsList.setCriterionViewer(this);
00937
00938 } catch (java.lang.Throwable ivjExc) {
00939
00940
00941 handleException(ivjExc);
00942 }
00943 }
00944 return ivjVarsList;
00945 }
00946
00947
00948
00949
00950
00951 private javax.swing.JPanel getVarsPanel() {
00952 if (ivjVarsPanel == null) {
00953 try {
00954 ivjVarsPanel = new javax.swing.JPanel();
00955 ivjVarsPanel.setName("VarsPanel");
00956 ivjVarsPanel.setLayout(new java.awt.BorderLayout());
00957 getVarsPanel().add(getVarsLabel(), "North");
00958 getVarsPanel().add(getRemoveVarsButton(), "South");
00959 getVarsPanel().add(getVarsScrollPane(), "Center");
00960
00961
00962 } catch (java.lang.Throwable ivjExc) {
00963
00964
00965 handleException(ivjExc);
00966 }
00967 }
00968 return ivjVarsPanel;
00969 }
00970
00971
00972
00973
00974
00975 private javax.swing.JScrollPane getVarsScrollPane() {
00976 if (ivjVarsScrollPane == null) {
00977 try {
00978 ivjVarsScrollPane = new javax.swing.JScrollPane();
00979 ivjVarsScrollPane.setName("VarsScrollPane");
00980 getVarsScrollPane().setViewportView(getVarsList());
00981
00982
00983 } catch (java.lang.Throwable ivjExc) {
00984
00985
00986 handleException(ivjExc);
00987 }
00988 }
00989 return ivjVarsScrollPane;
00990 }
00991
00992
00993
00994
00995 private void handleException(java.lang.Throwable exception) {
00996
00997
00998
00999
01000 }
01001
01002
01003
01004
01005
01006 private void initConnections() throws java.lang.Exception {
01007
01008
01009 getRemoveStatementButton().addActionListener(ivjEventHandler);
01010 getRemoveLocationButton().addActionListener(ivjEventHandler);
01011 getRemoveVarsButton().addActionListener(ivjEventHandler);
01012 getLocationsList().addListSelectionListener(ivjEventHandler);
01013 getStatementsList().addListSelectionListener(ivjEventHandler);
01014 getStatementsList().addMouseListener(ivjEventHandler);
01015 getLocationsList().addMouseListener(ivjEventHandler);
01016 getVarsList().addListSelectionListener(ivjEventHandler);
01017 getLocationVarsList().addListSelectionListener(ivjEventHandler);
01018 }
01019
01020
01021
01022
01023 private void initialize() {
01024 try {
01025
01026
01027 setName("CriterionViewer");
01028 setLayout(new java.awt.BorderLayout());
01029 setSize(766, 367);
01030 add(getPointVarSplitPane(), "Center");
01031 initConnections();
01032 } catch (java.lang.Throwable ivjExc) {
01033 handleException(ivjExc);
01034 }
01035
01036
01037
01038 }
01039
01040
01041
01042 public void locationsList_ListSelectionEvents() {
01043 Object selectedValue = getLocationsList().getSelectedValue();
01044 if (selectedValue instanceof LocationNodeInCriterionViewer) {
01045 setSelectedByProgram = true;
01046 getStatementsList().clearSelection();
01047 getLocationVarsList().clearSelection();
01048 getVarsList().clearSelection();
01049 setSelectedByProgram = false;
01050 LocationNodeInCriterionViewer locationNode = (LocationNodeInCriterionViewer) selectedValue;
01051 calculateLocalsFor(locationNode);
01052 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(selectedValue);
01053 } else
01054 System.out.println("selected value in the location list should be LocationNodeInCriterionViewer");
01055 return;
01056 }
01057
01058
01059
01060 public void locationsList_MouseClicked(java.awt.event.MouseEvent mouseEvent) {
01061 int selIndex = getLocationsList().locationToIndex(mouseEvent.getPoint());
01062 if (selIndex != -1) {
01063 if (mouseEvent.getClickCount() == 1) {
01064
01065
01066 } else
01067 if (mouseEvent.getClickCount() == 2) {
01068
01069
01070 LocationNodeInCriterionViewer selectedStmt = (LocationNodeInCriterionViewer) getLocationsList().getSelectedValue();
01071 if (selectedStmt == null)
01072 return;
01073 StmtTreeNode selectedNode = getStmtTreeNodeFromLocationNode(selectedStmt);
01074 dependFrame.addSelectedNodeToDependFrame(selectedNode);
01075
01076 }
01077 }
01078 return;
01079 }
01080
01081
01082
01083 public void locationVarsList_ListSelectionEvents() {
01084 Object selectedValue = getLocationVarsList().getSelectedValue();
01085 if (selectedValue instanceof SliceVariable) {
01086 setSelectedByProgram = true;
01087 getStatementsList().clearSelection();
01088 getLocationsList().clearSelection();
01089 getVarsList().clearSelection();
01090 setSelectedByProgram = false;
01091 if (selectedValue instanceof SliceField) {
01092 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(selectedValue);
01093 } else
01094 if (selectedValue instanceof SliceLocal) {
01095 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(selectedValue);
01096 }
01097 } else
01098 System.out.println("selected value in the location variables list should be SliceVariable");
01099 return;
01100 }
01101
01102
01103
01104
01105 public static void main(java.lang.String[] args) {
01106 try {
01107 JFrame frame = new javax.swing.JFrame();
01108 CriterionViewer aCriterionViewer;
01109 aCriterionViewer = new CriterionViewer();
01110 frame.setContentPane(aCriterionViewer);
01111 frame.setSize(aCriterionViewer.getSize());
01112 frame.addWindowListener(new java.awt.event.WindowAdapter() {
01113 public void windowClosing(java.awt.event.WindowEvent e) {
01114 System.exit(0);
01115 };
01116 });
01117 frame.setVisible(true);
01118 } catch (Throwable exception) {
01119 System.err.println("Exception occurred in main() of javax.swing.JPanel");
01120 exception.printStackTrace(System.out);
01121 }
01122 }
01123
01124
01125
01126 public void removeLocationButton_ActionEvents() {
01127 LocationNodeInCriterionViewer ln = (LocationNodeInCriterionViewer) getLocationsList().getSelectedValue();
01128 currentCriterion.remove(ln.slicePoint);
01129
01130 DefaultListModel listModel = (DefaultListModel) getLocationsList().getModel();
01131 listModel.removeElement(getLocationsList().getSelectedValue());
01132 if (listModel.isEmpty()) {
01133 DefaultListModel varListModel = (DefaultListModel) getLocationVarsList().getModel();
01134 varListModel.removeAllElements();
01135 }
01136 return;
01137 }
01138
01139
01140
01141
01142
01143 private void removeLocationFrom(Object location, DefaultListModel listModel) {
01144 for (Enumeration en = listModel.elements(); en.hasMoreElements();) {
01145 LocationNodeInCriterionViewer ln = (LocationNodeInCriterionViewer) en.nextElement();
01146 if (location.equals(ln.slicePoint)) {
01147 listModel.removeElement(ln);
01148 return;
01149 }
01150 }
01151 }
01152
01153
01154
01155 public void removeStatementButton_ActionEvents() {
01156 StatementNodeInCriterionViewer ln = (StatementNodeInCriterionViewer) getStatementsList().getSelectedValue();
01157 for (int i = 0; i < ln.locationArray.length; i++)
01158 currentCriterion.remove(ln.locationArray[i]);
01159 DefaultListModel listModel = (DefaultListModel) getStatementsList().getModel();
01160 listModel.removeElement(getStatementsList().getSelectedValue());
01161 return;
01162 }
01163
01164
01165
01166 public void removeVarsButton_ActionEvents() {
01167 currentCriterion.remove(getVarsList().getSelectedValue());
01168
01169
01170 DefaultListModel listModel = (DefaultListModel) getVarsList().getModel();
01171 listModel.removeElement(getVarsList().getSelectedValue());
01172 return;
01173 }
01174 void runSlicerWithCurrentCriterion() {
01175
01176
01177 if (currentCriterion.isEmpty()) {
01178
01179 runningCriterion = buildCriterionForCurrentNode(dependFrame.currentNode);
01180 } else
01181 runningCriterion = (Vector) currentCriterion.clone();
01182 if ((runningCriterion == null) || runningCriterion.isEmpty()) {
01183 System.out.println("The current criterion is null or empty");
01184 return;
01185 }
01186 if (runningCriterion.containsAll(lastTimeRunningCriterion) && lastTimeRunningCriterion.containsAll(runningCriterion)) {
01187 System.out.println("The current criterion is the same as the last one");
01188 return;
01189 }
01190
01191 boolean emptyCriterion = dependFrame.slicer.preProcessing(runningCriterion);
01192 dependFrame.slicer.slicing();
01193 dependFrame.slicer.postProcessingOnAnnotation();
01194
01195 CodeBrowserPane codeBrowserPane = dependFrame.getCodeBrowserPane();
01196 codeBrowserPane.setPostProcessValues();
01197 codeBrowserPane.repaintTrees();
01198
01199 lastTimeRunningCriterion = runningCriterion;
01200 }
01201
01202
01203
01204
01205
01206 void setDependFrame(Dependencies dp) {
01207 dependFrame = dp;
01208 }
01209
01210
01211
01212 void showCriterionInViewer(Vector sliceInterests) {
01213
01214 DefaultListModel listModel = (DefaultListModel) this.getVarsList().getModel();
01215 listModel.removeAllElements();
01216 listModel = (DefaultListModel) this.getLocationsList().getModel();
01217 listModel.removeAllElements();
01218 listModel = (DefaultListModel) this.getStatementsList().getModel();
01219 listModel.removeAllElements();
01220 for (Enumeration e = sliceInterests.elements(); e.hasMoreElements();) {
01221 SliceInterest si = (SliceInterest) e.nextElement();
01222 if ((si instanceof SliceStatement) || (si instanceof SlicePoint)) {
01223 boolean isStatementNode;
01224 if (si instanceof SliceStatement)
01225 isStatementNode = true;
01226 else
01227 isStatementNode = false;
01228 SlicePoint sp = (SlicePoint) si;
01229 SootClass sootClass = sp.getSootClass();
01230 SootMethod sootMethod = sp.getSootMethod();
01231 Stmt stmt = sp.getStmt();
01232 Annotation locationAnnotation = null;
01233 try {
01234 locationAnnotation = CompilationManager.getAnnotationManager().getContainingAnnotation(sootClass, sootMethod, stmt);
01235 } catch (AnnotationException ae) {
01236
01237 }
01238 if (locationAnnotation != null) {
01239 if (!isStatementNode)
01240 addLocationToCriterion(si, locationAnnotation);
01241 else {
01242
01243 }
01244 } else {
01245 addVarToCriterion(si);
01246 }
01247 }
01248 }
01249 }
01250
01251
01252
01253 public void statementsList_ListSelectionEvents() {
01254 Object selectedValue = getStatementsList().getSelectedValue();
01255 if (selectedValue instanceof LocationNodeInCriterionViewer) {
01256 setSelectedByProgram = true;
01257 getLocationsList().clearSelection();
01258 getLocationVarsList().clearSelection();
01259 getVarsList().clearSelection();
01260 setSelectedByProgram = false;
01261 LocationNodeInCriterionViewer locationNode = (LocationNodeInCriterionViewer) selectedValue;
01262 calculateLocalsFor(locationNode);
01263 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(selectedValue);
01264 } else
01265 System.out.println("selected value in the location list should be LocationNodeInCriterionViewer");
01266 return;
01267 }
01268
01269
01270
01271 public void statementsList_MouseClicked(java.awt.event.MouseEvent mouseEvent) {
01272 int selIndex = getStatementsList().locationToIndex(mouseEvent.getPoint());
01273 if (selIndex != -1) {
01274 if (mouseEvent.getClickCount() == 1) {
01275
01276
01277 } else
01278 if (mouseEvent.getClickCount() == 2) {
01279
01280
01281 LocationNodeInCriterionViewer selectedStmt = (LocationNodeInCriterionViewer) getStatementsList().getSelectedValue();
01282 if (selectedStmt == null)
01283 return;
01284 StmtTreeNode selectedNode = getStmtTreeNodeFromLocationNode(selectedStmt);
01285 dependFrame.addSelectedNodeToDependFrame(selectedNode);
01286
01287 }
01288 }
01289 return;
01290 }
01291
01292
01293
01294
01295
01296
01297
01298 private boolean statementsListContains(DefaultListModel listModel, Annotation annotation) {
01299 for (int i = 0; i < listModel.getSize(); i++) {
01300 Object element = listModel.elementAt(i);
01301 LocationNodeInCriterionViewer node = (LocationNodeInCriterionViewer) element;
01302 if (node.stmtAnnotation.equals(annotation))
01303 return true;
01304 }
01305 return false;
01306 }
01307
01308
01309
01310 public void varsList_ListSelectionEvents() {
01311 Object selectedValue = getVarsList().getSelectedValue();
01312 if (selectedValue instanceof SliceVariable) {
01313 setSelectedByProgram = true;
01314 getStatementsList().clearSelection();
01315 getLocationsList().clearSelection();
01316 getLocationVarsList().clearSelection();
01317 setSelectedByProgram = false;
01318 if (selectedValue instanceof SliceField) {
01319 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(selectedValue);
01320 } else
01321 if (selectedValue instanceof SliceLocal) {
01322 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(selectedValue);
01323 }
01324 } else
01325 System.out.println("selected value in the variables list should be SliceVariable");
01326 return;
01327 }
01328 }