Skip to content

Commit 855d1af

Browse files
author
Chris
committed
Trying to push latest version of tool to github
1 parent 2dc71a2 commit 855d1af

9 files changed

Lines changed: 190 additions & 247 deletions

File tree

dataTool/src/dataTool/AnnotationManager.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public void selectionChanged(ITextSelection selection) {
7676
Finder finder = Finder.getInstance();
7777
if(one != null) {
7878
addAnnotation(one);
79-
currentSearch = one.getBinding();
79+
currentSearch = one.getKey();
80+
linkAnnotation.setDataNode(one);
8081
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
8182
IEditorPart activeEditor = activePage.getActiveEditor();
8283
JavaEditor j = (JavaEditor) activeEditor;
@@ -98,15 +99,15 @@ public void selectionChanged(ITextSelection selection) {
9899
if(one.isParameterSelected(selection.getOffset())) {
99100
linkAnnotation.searchResultsDown = searchDown;
100101
linkAnnotation.searchResultsUp = searchUp;
101-
linkAnnotation.setDataNode(one);
102102
addLinkAnnotation(one);
103103
}
104104
}
105105

106106
//Adds all occurrences of data node off screen
107107
ArrayList<Object> textUp = new ArrayList<Object>();
108108
ArrayList<Object> textDown = new ArrayList<Object>();
109-
for(DataNode dn: finder.getOccurrences(one.getValue(), new Position(one.getStartPosition(), one.getLength()))) {
109+
for(DataNode dn: finder.getOccurrences(new Position(one.getStartPosition(), one.getLength()))) {
110+
addLinkAnnotation(dn);
110111
int[] offScreen = new int[3];
111112
int line = sourceViewer.widgetLineOfWidgetOffset(dn.getStartPosition())+1;
112113
offScreen[0] = line;
@@ -122,9 +123,12 @@ else if(dn.getStartPosition() > sourceViewer.getBottomIndexEndOffset()) {
122123
if(searchUp != null) {
123124
textUp.addAll(searchUp);
124125
((EditorBreadcrumb)upBreadcrumb).setSearchMethod(call.getCurrentMethod(one.getStartPosition()));
126+
((EditorBreadcrumb)upBreadcrumb).setSearchIndex(one.getParameterIndex());
127+
linkAnnotation.setSearchMethod(call.getCurrentMethod(one.getStartPosition()));
125128
}
126129
if(searchDown != null) {
127130
textDown.addAll(searchDown);
131+
((EditorBreadcrumb)downBreadcrumb).setSearchIndex(one.getParameterIndex());
128132
}
129133
upBreadcrumb.setText(textUp);
130134
downBreadcrumb.setText(textDown);
@@ -150,14 +154,19 @@ private void addLinkAnnotation(DataNode node) {
150154
SimpleName method;
151155
if(node.getInvocationMethod() != null) {
152156
method = node.getInvocationMethod().getName();
157+
int start = method.getStartPosition();
158+
int end = method.getStartPosition() + method.getLength();
159+
if(!isAlreadyAnnotated(start, end)) {
160+
addAnnotationsAt(start, end - start, false);
161+
}
153162
}
154-
else {
163+
if(node.getDeclarationMethod() != null) {
155164
method = node.getDeclarationMethod().getName();
156-
}
157-
int start = method.getStartPosition();
158-
int end = method.getStartPosition() + method.getLength();
159-
if(!isAlreadyAnnotated(start, end)) {
160-
addAnnotationsAt(start, end - start, false);
165+
int start = method.getStartPosition();
166+
int end = method.getStartPosition() + method.getLength();
167+
if(!isAlreadyAnnotated(start, end)) {
168+
addAnnotationsAt(start, end - start, false);
169+
}
161170
}
162171
}
163172

dataTool/src/dataTool/DataCallHierarchy.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashSet;
66
import java.util.Iterator;
77
import java.util.Set;
8+
import java.util.TreeSet;
89

910
import org.eclipse.core.resources.IFile;
1011
import org.eclipse.core.resources.IFolder;
@@ -78,7 +79,8 @@ public DataCallHierarchy() {
7879
* @throws JavaModelException
7980
*/
8081
public Set<IMethod> searchProject(DataNode node, String direction) throws JavaModelException {
81-
Set<IMethod> results = null;
82+
Set<IMethod> results = new HashSet<IMethod>();
83+
//inClass = false;
8284
if (direction.equals(Finder.UP)) {
8385
Method up = node.getDeclarationMethod();
8486
if(up != null) {
@@ -87,26 +89,22 @@ public Set<IMethod> searchProject(DataNode node, String direction) throws JavaMo
8789
}
8890
else if (direction.equals(Finder.DOWN)) {
8991
ArrayList<String> down = new ArrayList<String>();
90-
for(DataNode dn: Finder.getInstance().getOccurrences(node.getValue(), new Position(node.getStartPosition(),node.getLength()))) {
92+
Set<IMethod> searchDown = new HashSet<IMethod>();
93+
for(DataNode dn: Finder.getInstance().getOccurrences(node.getPosition())) {
9194
if(dn.getInvocationMethod() != null) {
9295
down.add(dn.getInvocationMethod().getName().getIdentifier());
96+
searchDown.addAll(search(dn, dn.getInvocationMethod(), Finder.DOWN));
9397
}
9498
}
95-
if(down != null && !down.isEmpty()) {
96-
if( node.getInvocationMethod() != null ) {
97-
Set<IMethod> searchDown = new HashSet<IMethod>();
98-
Set<IMethod> temp = search(node, node.getInvocationMethod(), Finder.DOWN);
99-
System.out.println(down);
100-
for(IMethod i: temp) {
101-
System.out.println(" "+i.getElementName());
102-
if(down.contains(i.getElementName())) {
103-
searchDown.add(i);
104-
}
105-
}
106-
results = searchDown;
99+
for(IMethod s: searchDown) {
100+
if(down.contains(s.getElementName())) {
101+
results.add(s);
107102
}
108103
}
109104
}
105+
if(results.isEmpty()) {
106+
return null;
107+
}
110108
return results;
111109
}
112110
/**
@@ -153,15 +151,11 @@ public Set<IMethod> search(DataNode node, Method methodName, String direction) t
153151
methods = callGen.getCallersOf(m);
154152
}
155153
else {
156-
if(!inClass) {
157-
Set<IMethod> temp = callGen.getCalleesOf(m);
158-
for(IMethod i: temp) {
159-
methods.add(i);
160-
}
161-
}
162-
else {
163-
methods.add(m);
164-
}
154+
Set<IMethod> temp = callGen.getCalleesOf(m);
155+
for(IMethod i: temp) {
156+
methods.add(i);
157+
}
158+
methods.add(m);
165159
}
166160
return methods;
167161
}
@@ -182,7 +176,7 @@ private IMethod findMethod(IType type, String methodName) throws JavaModelExcept
182176
{
183177
IMethod imethod = methods[i];
184178
if (imethod.getElementName().equals(methodName)) {
185-
inClass = true;
179+
//inClass = true;
186180
theMethod = imethod;
187181
}
188182
}

dataTool/src/dataTool/DataNode.java

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import org.eclipse.jdt.core.dom.SimpleName;
77
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
88
import org.eclipse.jdt.core.dom.VariableDeclaration;
9+
import org.eclipse.jface.text.Position;
10+
11+
import jdk.internal.org.objectweb.asm.tree.analysis.Value;
912

1013
/**
1114
* DataNode class that creates objects for the data we find and want to highlight.
@@ -22,71 +25,44 @@ public class DataNode implements Comparable {
2225
final public static String FOR_VAR = "variableFor";
2326
final public static String VAR = "variable";
2427

25-
private String binding;
2628
private String key;
27-
private String value;
28-
private int index;
29+
private String name;
30+
private int startPosition;
2931
private int length;
3032
private int parameterIndex;
3133
private SimpleName sn;
3234
private String type;
33-
private String signature;
3435
private Method declarationMethod;
3536
private Method invocationMethod;
36-
private boolean isHighlighted;
37+
private Position position;
3738

38-
// /**
39-
// * Constructor to create DataNodes with just values, mainly for DownFinder
40-
// * @param val= Current variable name
41-
// * @param start= start position of the current variable
42-
// */
43-
// public DataNode (String val, int start, String nodeType, Method call) {
44-
//
45-
//
46-
// value = val;
47-
// index = start;
48-
// length = val.length();
49-
// type = nodeType;
50-
// method = call;
51-
// if( method != null ) {
52-
// signature = method.getSignature() + "." + value;
53-
// } else {
54-
// signature = "null";
55-
// }
56-
// }
57-
5839
public DataNode( SimpleName sn ) {
5940
this.sn = sn;
60-
value = sn.getFullyQualifiedName();
61-
index = sn.getStartPosition();
62-
length = value.length();
63-
isHighlighted = false;
41+
name = sn.getFullyQualifiedName();
42+
startPosition = sn.getStartPosition();
43+
length = name.length();
44+
position = new Position( startPosition, length );
6445
parameterIndex = -1;
6546
this.key = sn.resolveBinding().getKey();
66-
this.binding = sn.resolveBinding().toString();
6747
}
6848
public void setStartPosition( int i ) {
69-
index = i;
49+
startPosition = i;
7050
}
7151

7252
/**
7353
* Gets the value of the data
7454
* @returns variable name
7555
*/
7656
public String getValue() {
77-
return this.value;
78-
}
79-
80-
public String getBinding() {
81-
return binding;
57+
return this.name;
8258
}
8359

8460
/**
8561
* Gets the start position of current data in the source code
8662
* @returns variable start position
8763
*/
8864
public int getStartPosition() {
89-
return this.index;
65+
return this.startPosition;
9066
}
9167

9268
/**
@@ -115,16 +91,13 @@ public Method getInvocationMethod() {
11591
public void setInvocationMethod( Method m ) {
11692
invocationMethod = m;
11793
}
118-
public String getSignature() {
119-
return this.signature;
120-
}
12194
/**
12295
* Checks to see if current node is a parameter, only want to display box when actual
12396
* param is selected
12497
* @returns true if node is a parameter, else false
12598
*/
12699
public boolean isParameterSelected(int pos) {
127-
if(pos < index || pos > index+length) {
100+
if(pos < startPosition || pos > startPosition+length) {
128101
return false;
129102
}
130103
return true;
@@ -137,11 +110,14 @@ public int compareTo(Object o) {
137110
if( o == null || !( o instanceof DataNode ) ) {
138111
return 1;
139112
}
140-
return index - ((DataNode)o).getStartPosition();
113+
return startPosition - ((DataNode)o).getStartPosition();
141114
}
142115
@Override
143116
public String toString() {
144-
return binding;
117+
return key;
118+
}
119+
public Position getPosition() {
120+
return position;
145121
}
146122

147-
}
123+
}

dataTool/src/dataTool/EnableNavigationAction.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public class EnableNavigationAction implements IWorkbenchWindowActionDelegate {
4646

4747
//whether the listener is currently enabled
4848
private boolean isEnabled = false;
49-
49+
50+
private String previous = "";
51+
5052
public void dispose() {
5153
if(annotationManager!=null)
5254
annotationManager.dispose();
@@ -75,14 +77,17 @@ public void partActivated(IWorkbenchPart arg0) {
7577
@Override
7678
public void partBroughtToTop(IWorkbenchPart arg0) {
7779
// Auto-generated method stub
78-
arg0.getSite().getPage().activate(arg0);
79-
try {
80-
dispose();
81-
isEnabled = false;
82-
reset(arg0.getSite().getPage());
83-
} catch (JavaModelException e) {
84-
// Auto-generated catch block
85-
e.printStackTrace();
80+
if(!previous.equals(arg0.getTitle())) {
81+
previous = arg0.getTitle();
82+
arg0.getSite().getPage().activate(arg0);
83+
try {
84+
dispose();
85+
isEnabled = false;
86+
reset(arg0.getSite().getPage());
87+
} catch (JavaModelException e) {
88+
// Auto-generated catch block
89+
e.printStackTrace();
90+
}
8691
}
8792
}
8893

0 commit comments

Comments
 (0)