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
;
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.
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
;
52 private CISlicer cislicer
; // only for CI slicing
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
) {
63 this.project
= project
;
64 this.javaProject
= javaProject
;
65 this.slicingType
= slicingType
;
66 this.seedFile
= seedFile
;
67 this.seedLine
= seedLine
;
68 this.useShrike
= useShrike
;
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
;
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();
87 depGraph
= csDepGraph
;
90 public Graph
<Statement
> getDepGraph() {
94 public Graph
<Statement
> getCSDepGraph() {
97 public IProject
getProject() {
100 public IJavaProject
getJavaProject() {
103 public int getSlicingType() {
106 public int getDepth() {
109 public IFile
getSeedFile() {
112 public int getSeedLine() {
115 public CallGraph
getCallGraph() {
118 public PointerAnalysis
getPointerAnalysis() {
119 return pointerAnalysis
;
121 public Slice
getSeed() {
124 public Slice
getSlice() {
128 public CISlicer
getCISlicer() {
131 public boolean getUseShrike() {
136 static SliceEnvironment current
= null;
137 public static SliceEnvironment
getCurrent() {
140 public static void setCurrent(SliceEnvironment 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!