Some more instrumentation, and playing around with chopping (chops when double-click...
[eclipsethinslicer.git] / Svelte / src / edu / berkeley / cs / bodik / svelte / plugin / SliceEnvironment.java
blob9052e8db411672991875f6b7465c5b3a2ef9a4af
1 package edu.berkeley.cs.bodik.svelte.plugin;
3 import org.eclipse.core.resources.IFile;
4 import org.eclipse.core.resources.IProject;
5 import org.eclipse.jdt.core.IJavaProject;
7 import com.ibm.wala.ipa.callgraph.CallGraph;
8 import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
9 import com.ibm.wala.ipa.slicer.Statement;
10 import com.ibm.wala.util.graph.Graph;
12 import edu.berkeley.cs.bodik.svelte.Slice;
13 import edu.berkeley.cs.bodik.svelte.Slicing;
14 import edu.berkeley.cs.bodik.svelte.cislicer.CISDG;
15 import edu.berkeley.cs.bodik.svelte.cislicer.CISlicer;
17 /**
18 * For lack of a better name...
19 * Encapsulates the a calculated slice, including the environment. This includes project, seed file, and calculated
20 * slice data, such as an SDG. The idea is that we slice once, but later various views and things need to do things
21 * with the slice. This data can be set in two stages:
23 * 1) create a new object via the constructor, passing in project and seed file
24 * 2) after we create the slice, set the callGraph, pointerAnalysis, and seed and slice variables. Except for slice these can also be done before slicing.
26 * With the data here we can do various things such as find files related to the slice thru that project.
29 * TODO: listeners to recalculate views, etc. on update.
31 * @author evan
34 public class SliceEnvironment {
36 private boolean useShrike;
38 private IProject project;
39 private IJavaProject javaProject;
41 private int slicingType; // as defined by constants in Slicing
43 private IFile seedFile;
44 private int seedLine; // could be more specific...
46 private CallGraph callGraph;
47 private PointerAnalysis pointerAnalysis;
49 private Slice seed;
50 private Slice slice;
52 private CISlicer cislicer; // only for CI slicing
54 int depth;
56 private Graph<Statement> csDepGraph;
58 private Graph<Statement> depGraph;
60 public SliceEnvironment(IJavaProject javaProject,
61 int slicingType, IFile seedFile, int seedLine, boolean useShrike, int depth) {
62 super();
63 this.project = project;
64 this.javaProject = javaProject;
65 this.slicingType = slicingType;
66 this.seedFile = seedFile;
67 this.seedLine = seedLine;
68 this.useShrike = useShrike;
69 this.depth = depth;
72 public void setSliceData(CallGraph callGraph, PointerAnalysis pointerAnalysis, Slice seed, Slice slice, CISlicer cislicer, Graph<Statement> csDepGraph) {
73 this.callGraph = callGraph;
74 this.pointerAnalysis = pointerAnalysis;
75 this.seed = seed;
76 this.slice = slice;
77 this.cislicer = cislicer;
78 this.csDepGraph = csDepGraph;
80 revertToOriginalDepGraph();
83 public void revertToOriginalDepGraph() {
84 if ( slicingType == Slicing.CI_THIN_SLICE )
85 depGraph = cislicer.getDepGraph();
86 else
87 depGraph = csDepGraph;
90 public Graph<Statement> getDepGraph() {
91 return depGraph;
94 public Graph<Statement> getCSDepGraph() {
95 return csDepGraph;
97 public IProject getProject() {
98 return project;
100 public IJavaProject getJavaProject() {
101 return javaProject;
103 public int getSlicingType() {
104 return slicingType;
106 public int getDepth() {
107 return depth;
109 public IFile getSeedFile() {
110 return seedFile;
112 public int getSeedLine() {
113 return seedLine;
115 public CallGraph getCallGraph() {
116 return callGraph;
118 public PointerAnalysis getPointerAnalysis() {
119 return pointerAnalysis;
121 public Slice getSeed() {
122 return seed;
124 public Slice getSlice() {
125 return slice;
128 public CISlicer getCISlicer() {
129 return cislicer;
131 public boolean getUseShrike() {
132 return useShrike;
136 static SliceEnvironment current = null;
137 public static SliceEnvironment getCurrent() {
138 return current;
140 public static void setCurrent(SliceEnvironment se) {
141 current = se;
142 // should probably run GC here, since statements, a call graph, etc. will probably be made unreachable
144 public static void setCurrentSliceData(CallGraph callGraph, PointerAnalysis pointerAnalysis, Slice seed, Slice slice, CISlicer cislicer, Graph<Statement> csDepGraph) {
145 if ( current != null )
146 current.setSliceData(callGraph, pointerAnalysis, seed, slice, cislicer, csDepGraph);
149 public static boolean hasCurrentCI() {
150 return current != null && current.cislicer != null;
152 public static boolean hasCurrent() {
153 return current != null;
156 public void setDepGraph(Graph<Statement> newDepGraph) {
157 depGraph = newDepGraph;
158 // seed = new Slice(((CachedSlice)newDepGraph).seeds);
159 // shoiuld really change seed, but we have to change it back remember!