1 /*******************************************************************************
2 * This program and the accompanying materials
3 * are made available under the terms of the Eclipse Public License v1.0
4 * which accompanies this distribution, and is available at
5 * http://www.eclipse.org/legal/epl-v10.html.
7 * This file is a derivative of code released by the University of
8 * California under the terms listed below.
10 * Refinement Analysis Tools is Copyright ©2007 The Regents of the
11 * University of California (Regents). Provided that this notice and
12 * the following two paragraphs are included in any distribution of
13 * Refinement Analysis Tools or its derivative work, Regents agrees
14 * not to assert any of Regents' copyright rights in Refinement
15 * Analysis Tools against recipient for recipients reproduction,
16 * preparation of derivative works, public display, public
17 * performance, distribution or sublicensing of Refinement Analysis
18 * Tools and derivative works, in source code and object code form.
19 * This agreement not to assert does not confer, by implication,
20 * estoppel, or otherwise any license or rights in any intellectual
21 * property of Regents, including, but not limited to, any patents
22 * of Regents or Regents employees.
24 * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
25 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
26 * INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
27 * AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
32 * FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
33 * WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
34 * DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
35 * IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
36 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
38 package edu
.berkeley
.cs
.bodik
.svelte
.plugin
.bfsliceview
;
40 import java
.util
.ArrayList
;
42 import org
.eclipse
.jface
.action
.Action
;
43 import org
.eclipse
.jface
.action
.IToolBarManager
;
44 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
45 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
46 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
47 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
48 import org
.eclipse
.jface
.viewers
.TreeViewer
;
49 import org
.eclipse
.swt
.SWT
;
50 import org
.eclipse
.swt
.widgets
.Composite
;
51 import org
.eclipse
.swt
.widgets
.TreeColumn
;
52 import org
.eclipse
.ui
.part
.ViewPart
;
54 import com
.ibm
.wala
.ipa
.slicer
.NormalStatement
;
55 import com
.ibm
.wala
.ipa
.slicer
.Statement
;
57 import edu
.berkeley
.cs
.bodik
.svelte
.plugin
.EclipseUtils
;
58 import edu
.berkeley
.cs
.bodik
.svelte
.plugin
.SliceEnvironment
;
59 import edu
.berkeley
.cs
.bodik
.svelte
.plugin
.SveltePlugin
;
61 public class BFSliceView
extends ViewPart
{
64 BFSliceContentProvider bfscp
;
66 public BFSliceView() {
70 public void createPartControl(Composite parent
) {
71 viewer
= new TreeViewer(parent
);
72 input
= new BFSliceInput(SliceEnvironment
.getDepGraph(), SliceEnvironment
.getSeed());
74 bfscp
= new BFSliceContentProvider();
75 viewer
.setContentProvider(bfscp
);
76 viewer
.setLabelProvider(new BFSliceLabelProvider(bfscp
));
77 viewer
.setInput(input
);
79 this.viewer
.setExpandedState(bfscp
.getElements(input
)[0], true);
81 TreeColumn column
= new TreeColumn(viewer
.getTree(), SWT
.NONE
);
83 column
.setText("Statement");
84 column
= new TreeColumn(viewer
.getTree(), SWT
.NONE
);
86 column
.setText("Function");
87 column
= new TreeColumn(viewer
.getTree(), SWT
.NONE
);
89 column
.setText("SSA Instruction");
90 viewer
.getTree().setLinesVisible(true);
91 viewer
.getTree().setHeaderVisible(true);
92 viewer
.getTree().setLinesVisible(true);
93 viewer
.getTree().setHeaderVisible(true);
96 viewer
.setExpandedState(input
.getRoot(), true);
97 ArrayList
<BFSliceStatement
> seeds
= input
.getRoot().getChildren();
98 if (seeds
.size() > 0) {
99 viewer
.setSelection(new StructuredSelection(seeds
.get(0)));
100 EclipseUtils
.gotoStatement(seeds
.get(0).getStatement());
108 private void setUpListeners() {
109 viewer
.addDoubleClickListener(new IDoubleClickListener() {
111 public void doubleClick(DoubleClickEvent event
) {
112 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
113 EclipseUtils
.gotoStatement(((BFSliceStatement
) selection
.getFirstElement())
116 // /********************** CHOP *********************/
117 // // it slices dices, minces, rinses, shreds, cuts, chops, beats, blends, frappes,
119 // SliceEnvironment.getCurrent().revertToOriginalDepGraph();
120 // CachedSlice cs = new CachedSlice(SliceEnvironment.getCurrent());
121 // cs.chop(Collections.singleton(((BFSliceStatement)selection.getFirstElement()).getStatement()));
122 // SliceEnvironment.getCurrent().setDepGraph(cs);
123 // /********************** CHOP *********************/
125 Statement s
= ((BFSliceStatement
) selection
.getFirstElement()).getStatement();
126 String methodSignature
= s
.getNode().getMethod().getSignature();
127 methodSignature
= methodSignature
.replace("/", ".");
129 if ( s
instanceof NormalStatement
) {
130 System
.out
.println("instrument:");
131 System
.out
.println(methodSignature
);
132 System
.out
.println(((NormalStatement
)s
).getInstructionIndex());
135 // /** ************** INSTRUMENTATION *************** */
138 // InstrumentationSet is = new InstrumentationSet();
139 // is.addInstrumentationPoint(((BFSliceStatement) selection.getFirstElement())
141 // for (Statement s : SliceEnvironment.getSlice())
142 // is.addInstrumentationPoint(s);
144 // ArrayList<String> filenames = new ArrayList<String>();
145 // for (String classname : is.getFullyQualifiedClassNames()) {
146 // String classfilename = EclipseJdtUtils.findClassFileForClassStripL(classname,
147 // EclipseJdtUtils.getJavaProjectFromProject(SliceEnvironment.env().getProject()));
148 // if (classfilename != null)
149 // filenames.add(classfilename);
152 // Instrumenter.instrument(filenames, "/tmp/SveltedInstrumented.jar", is);
153 // } catch (Exception e) {
154 // e.printStackTrace();
156 // /** ************** INSTRUMENTATION *************** */
158 // Statement s = ((BFSliceStatement) selection.getFirstElement()).getStatement();
159 // System.out.println("****IR****\n****IR****\n" + s.getNode().getIR());
166 public void setFocus() {
167 viewer
.getControl().setFocus();
170 public void createActions() {
172 Action followDownAction
= new Action("Follow down (Statement bad)") {
178 followDownAction
.setImageDescriptor(SveltePlugin
179 .getImageDescriptor("icons/bfsv/downxred.png"));
181 Action nextCheckAction
= new Action("Next at this level (Statement good)") {
187 nextCheckAction
.setImageDescriptor(SveltePlugin
188 .getImageDescriptor("icons/bfsv/nextcheck.png"));
190 Action nextQuestionAction
= new Action("Next at this level (Statement maybe bad)") {
196 nextQuestionAction
.setImageDescriptor(SveltePlugin
197 .getImageDescriptor("icons/bfsv/nextquestionmark.png"));
199 Action backUpAction
= new Action("Back up") {
205 backUpAction
.setImageDescriptor(SveltePlugin
.getImageDescriptor("icons/bfsv/up.png"));
207 IToolBarManager mgr
= getViewSite().getActionBars().getToolBarManager();
208 mgr
.add(followDownAction
);
209 mgr
.add(nextCheckAction
);
210 mgr
.add(nextQuestionAction
);
211 mgr
.add(backUpAction
);
214 protected void backUp() {
218 protected void nextQuestion() {
219 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
220 bfscp
.nextQuestion(selection
.getFirstElement());
223 protected void nextCheck() {
224 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
225 bfscp
.nextCheck(selection
.getFirstElement());
228 protected void followDown() {
229 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
230 bfscp
.followDown(selection
.getFirstElement());