Skip to content

Commit f04d415

Browse files
author
Chris
committed
Latest version of the tool with new user interface for issue #8. This version does not work yet.
1 parent 20a1e62 commit f04d415

17 files changed

Lines changed: 343 additions & 236 deletions

dataTool/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
99
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
1010
<classpathentry kind="src" path="src_tests"/>
11+
<classpathentry kind="lib" path="C:/Users/Chris/Documents/Classes/NC State/research/org.eclipse.ui.articles.views/views.jar"/>
1112
<classpathentry kind="output" path="bin"/>
1213
</classpath>

dataTool/META-INF/MANIFEST.MF

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Require-Bundle: org.eclipse.ui,
1717
org.eclipse.core.resources,
1818
org.eclipse.ui.workbench,
1919
org.eclipse.equinox.registry,
20-
org.eclipse.jdt.ui
20+
org.eclipse.jdt.ui,
21+
org.eclipse.ui.ide;bundle-version="3.11.0",
22+
org.eclipse.ui.ide.application;bundle-version="1.1.0",
23+
org.eclipse.text
2124
Eclipse-LazyStart: true
2225
Import-Package: org.eclipse.jdt.internal.ui.search

dataTool/plugin.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
icon="icons/data.gif"
1818
id="dataTool.action1"
1919
label="Find EOS"
20-
style="toggle"
20+
style="menu"
2121
toolbarPath="TempGroup"
2222
tooltip="Highlights flow of data within your code"/>
2323
</actionSet>
2424
</extension>
2525
<extension
2626
point="org.eclipse.ui.commands">
2727
</extension>
28-
2928
</plugin>

dataTool/src/dataTool/DataCallHierarchy.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package dataTool;
22

33
import java.util.ArrayList;
4+
import java.util.HashMap;
45
import java.util.HashSet;
56

7+
import org.eclipse.core.resources.IFile;
68
import org.eclipse.core.resources.IFolder;
79
import org.eclipse.core.resources.IProject;
810
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -47,11 +49,19 @@ public class DataCallHierarchy {
4749
private String className;
4850
private String location;
4951
private ICompilationUnit cUnit;
52+
private HashMap<String, ArrayList<DataLink>> results;
53+
54+
public String goTo = null;
55+
public int goToOffset;
5056

5157
public DataCallHierarchy() {
5258

5359
}
5460

61+
public void setGoTo(int offset) {
62+
goToOffset = offset;
63+
}
64+
5565
public HashSet<IMethod> getCalls(IMethod m) {
5666
Finder f = Finder.getInstance();
5767
if(f instanceof UpFinder) {
@@ -123,11 +133,17 @@ private IMethod getIMethodFromMethodWrapper(MethodWrapper m) {
123133
* @returns String of next method name
124134
* @throws CoreException
125135
*/
126-
public ArrayList<DataLink> searchProject(String method) throws CoreException {
127-
ArrayList<DataLink> results = new ArrayList<DataLink>();
136+
public HashMap<String, ArrayList<DataLink>> searchProject(String method) throws CoreException {
137+
results = new HashMap<String, ArrayList<DataLink>>();
128138
String projectName = EnableNavigationAction.project;
129139
String path = EnableNavigationAction.path;
130-
String projectPath = path.substring(path.indexOf("/src/")+5,path.lastIndexOf("/")).replace("/", ".");
140+
String projectPath;
141+
if(path.contains("/src/")) {
142+
projectPath = path.substring(path.indexOf("/src/")+5,path.lastIndexOf("/")).replace("/", ".");
143+
}
144+
else {
145+
projectPath = path;
146+
}
131147
String projectFile = EnableNavigationAction.file;
132148
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
133149
IProject project = root.getProject(projectName);
@@ -139,46 +155,27 @@ public ArrayList<DataLink> searchProject(String method) throws CoreException {
139155
cUnit = frag.getCompilationUnit(projectFile);
140156
IType type = cUnit.getType(projectFile.replace(".java", ""));
141157
HashSet<IMethod> calls = null;
158+
ArrayList<DataLink> links = new ArrayList<DataLink>();
142159
for(IMethod im: type.getMethods()){
143160
if(im.getElementName().equals(method)) {
144161
calls = getCalls(im);
145162
for(IMethod mem: calls) {
146-
//results += mem.getElementName() + "\n";
147-
results.add(new DataLink(mem.getElementName(), mem.toString()));
163+
links.add(new DataLink(mem, mem.getElementName(), mem.getPath().toString()));
148164
searchMatch = mem.toString();
149165
}
150166
}
151167
}
168+
results.put(Finder.UP, links);
152169
if(calls == null) {
153-
results.add(processRootDirectory(method));
170+
results.put(Finder.DOWN, processRootDirectory(method));
154171
}
155172
return results;
156173
}
157174

158-
/**
159-
* Function to parse the output from the search function above
160-
* @param s: String of search results
161-
*/
162-
private void parseSearchResults(String s) {
163-
System.out.println(s);
164-
method = s.substring(s.indexOf(" ")+1,s.indexOf("("));
165-
parameters = s.substring(s.indexOf("("),s.indexOf(")")+1);
166-
String temp[] = s.substring(s.indexOf("[")).split("\\[in ");
167-
String tempLoc = "";
168-
for(int i = 1; i < temp.length; i++) {
169-
String str = temp[i].trim().replace("[Working copy] ","").replace("]","");
170-
if(i==1) {
171-
className = str;
172-
continue;
173-
}
174-
tempLoc = str+"."+tempLoc;
175-
}
176-
location = tempLoc.substring(0,tempLoc.length()-1);
177-
}
178-
179-
private DataLink processRootDirectory(String method) throws JavaModelException,CoreException {
175+
private ArrayList<DataLink> processRootDirectory(String method) throws JavaModelException,CoreException {
180176
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
181177
IProject[] projects = root.getProjects();
178+
ArrayList<DataLink> links = new ArrayList<DataLink>();
182179

183180
// process each project
184181
for (IProject project : projects) {
@@ -199,7 +196,7 @@ private DataLink processRootDirectory(String method) throws JavaModelException,C
199196
for (IMethod imethod : methods) {
200197
if(imethod.getElementName().equals(method)) {
201198
searchMatch = method.toString();
202-
return new DataLink(imethod.getElementName(), imethod.toString());
199+
links.add(new DataLink(imethod, imethod.getElementName(),imethod.getPath().toString()));
203200
}
204201
}
205202
}
@@ -209,6 +206,10 @@ private DataLink processRootDirectory(String method) throws JavaModelException,C
209206
}
210207

211208
}
212-
return new DataLink(DataLink.INVALID, DataLink.INVALID_DESC);
209+
if(links.isEmpty())
210+
{
211+
links.add(new DataLink(null, DataLink.INVALID, DataLink.INVALID_DESC));
212+
}
213+
return links;
213214
}
214215
}

dataTool/src/dataTool/DataNode.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,23 @@ public String getType() {
100100
* @returns string method
101101
*/
102102
public String getMethod() {
103-
if(isParameter()) {
103+
if(isParameter(index)) {
104104
return this.method;
105105
}
106106
return null;
107107
}
108108

109109
/**
110-
* Checks to see if current node is a parameter or used as one. Used in call hierarchy search
111-
* for entire project.
110+
* Checks to see if current node is a parameter, only want to display box when actual
111+
* param is selected
112112
* @returns true if node is a parameter, else false
113113
*/
114-
public boolean isParameter() {
114+
public boolean isParameter(int pos) {
115115
Finder f = Finder.getInstance();
116-
if(f.getFlowDirection().equals(Finder.UP)) {
117-
return type.equals(PARAM_UP);
116+
if(pos < index || pos > index+length) {
117+
return false;
118118
}
119-
else if(f.getFlowDirection().equals(Finder.DOWN)) {
120-
return type.equals(PARAM_DOWN);
121-
}
122-
return false;
119+
return (type.equals(PARAM_UP) || (type.equals(PARAM_DOWN)));
123120
}
124121

125122
}

dataTool/src/dataTool/DownFinder.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,4 @@ public boolean isUp(String var, int start) {
154154
}
155155
return false;
156156
}
157-
158-
public static String searchProjectDown(String project, String method) {
159-
//TODO
160-
/*
161-
* http://stackoverflow.com/questions/13980726/using-search-engine-to-implement-call-hierarchy-getting-all-the-methods-that-in
162-
*/
163-
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
164-
IProject iProject= root.getProject(project);
165-
return "";
166-
}
167157
}

dataTool/src/dataTool/EnableNavigationAction.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package dataTool;
2+
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.jface.action.IAction;
34
import org.eclipse.jface.viewers.ISelection;
45
import org.eclipse.ui.IEditorPart;
@@ -8,6 +9,8 @@
89
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
910
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
1011

12+
import dataTool.ui.NavigationBox;
13+
1114
/**
1215
* An action that enables the statement helper
1316
*
@@ -46,8 +49,9 @@ private void enable(IEditorPart activeEditor) {
4649
project = path[0];
4750
file = activeEditor.getTitle();
4851
this.path = activeEditor.getEditorInput().toString().replace("org.eclipse.ui.part.FileEditorInput(", "").replace(")","");
49-
if(page.getActiveEditor()!=null)
52+
if(page.getActiveEditor()!=null) {
5053
annotationManager = new AnnotationManager((AbstractDecoratedTextEditor)activeEditor);
54+
}
5155
}
5256

5357
public void init(IWorkbenchWindow window) {
@@ -91,6 +95,10 @@ public void run(IAction action) {
9195
}
9296
}
9397

98+
public boolean isEnabled() {
99+
return isEnabled;
100+
}
101+
94102
public void selectionChanged(IAction action, ISelection selection) {
95103
//do nothing
96104
}

dataTool/src/dataTool/Finder.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,34 @@ public class Finder {
1919
private static String findDirection = UP; //default direction is up
2020
private static Finder currentFinder;
2121
private static Color currentColor;
22+
private String goToName = null;
23+
private int goToOffset = -1;
2224

2325
public Finder () {
2426
//Do nothing
2527
}
2628

27-
public Finder (String s) {
28-
if (s.equals(UP) || s.equals(DOWN))
29-
setFlowDirection(s);
29+
public void setGoToIndex(int offset) {
30+
System.out.println(offset + " off");
31+
goToOffset = offset;
32+
}
33+
34+
public void setGoToFunc(String name) {
35+
goToName = name;
36+
}
37+
38+
public int getGoToIndex() {
39+
if(goToOffset > 0) {
40+
return goToOffset;
41+
}
42+
return -1;
43+
}
44+
45+
public String getGoToFunc() {
46+
if(goToName != null) {
47+
return goToName;
48+
}
49+
return null;
3050
}
3151

3252
public ArrayList<DataNode> getOccurrences(String data) {
@@ -45,7 +65,7 @@ else if(findDirection.equals(DOWN)) {
4565
* Controls which flow the tool will navigate to show data flow
4666
* @param s: Direction for flow display, required to be UP or DOWN
4767
*/
48-
public void setFlowDirection(String s) {
68+
/*public void setFlowDirection(String s) {
4969
if(s.equals(UP)) {
5070
findDirection = s;
5171
currentFinder = UpFinder.getInstance();
@@ -60,7 +80,7 @@ else if(s.equals(DOWN)) {
6080
//something went very wrong...
6181
findDirection = null;
6282
}
63-
}
83+
}*/
6484

6585
/**
6686
* Function to return the current direction of the flow navigation.

dataTool/src/dataTool/Visitor.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public static void parseData() {
115115
char[] code = source.toCharArray();
116116
upFinder = UpFinder.getInstance();
117117
downFinder = DownFinder.getInstance();
118+
Finder finder = Finder.getInstance();
118119
ASTParser parser = ASTParser.newParser(AST.JLS3);
119120
parser.setSource(code);
120121
parser.setKind(ASTParser.K_COMPILATION_UNIT);
@@ -131,13 +132,12 @@ public boolean visit(VariableDeclarationFragment vdf) {
131132
return true;
132133
}
133134

134-
public boolean visit(ConstructorInvocation ci) {
135-
System.out.println(ci.toString());
136-
return true;
137-
}
138135
public boolean visit(MethodDeclaration md) {
139136
if (!seenMethod.contains(md.getName())) {
140137
seenMethod.add(md.getName());
138+
if(md.getName().getIdentifier().equals(finder.getGoToFunc())) {
139+
finder.setGoToIndex(md.getStartPosition());
140+
}
141141
String param = "";
142142
String[] array = new String[md.parameters().size()];
143143
int i = 0;
@@ -147,7 +147,6 @@ public boolean visit(MethodDeclaration md) {
147147
param = ((SingleVariableDeclaration) o).getName().getIdentifier();
148148
data.add(param);
149149
upFinder.add(param, (SingleVariableDeclaration) o, DataNode.PARAM_UP);
150-
findOccurrences(param);
151150
}
152151

153152
md.accept(new ASTVisitor() {
@@ -214,6 +213,9 @@ public boolean visit(TryStatement ts) {
214213

215214
public boolean visit(MethodInvocation mi) {
216215
List<ASTNode> args = mi.arguments();
216+
if(finder.getFlowDirection().equals(Finder.UP) && mi.getName().getIdentifier().equals(finder.getGoToFunc())) {
217+
finder.setGoToIndex(mi.getStartPosition());
218+
}
217219
for(ASTNode arg: args) {
218220
if(data.contains(arg.toString())) {
219221
downFinder.add(arg.toString(), arg.getStartPosition(), DataNode.PARAM_DOWN, mi.getName().getIdentifier());

0 commit comments

Comments
 (0)