Skip to content

Commit 2dc71a2

Browse files
author
Chris
committed
Latest version of navigation plugin
1 parent 7916c64 commit 2dc71a2

File tree

8 files changed

+240
-129
lines changed

8 files changed

+240
-129
lines changed

dataTool/src/dataTool/AnnotationManager.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void selectionChanged(ITextSelection selection) {
7676
Finder finder = Finder.getInstance();
7777
if(one != null) {
7878
addAnnotation(one);
79-
currentSearch = one.getKey();
79+
currentSearch = one.getBinding();
8080
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
8181
IEditorPart activeEditor = activePage.getActiveEditor();
8282
JavaEditor j = (JavaEditor) activeEditor;
@@ -95,15 +95,18 @@ public void selectionChanged(ITextSelection selection) {
9595
if((finder.upSearch(one) != null || finder.downSearch(one) != null || one.getInvocationMethod() != null) && currentSearch != null) {
9696
searchUp = call.searchProject(one, Finder.UP);
9797
searchDown = call.searchProject(one, Finder.DOWN);
98+
if(one.isParameterSelected(selection.getOffset())) {
99+
linkAnnotation.searchResultsDown = searchDown;
100+
linkAnnotation.searchResultsUp = searchUp;
101+
linkAnnotation.setDataNode(one);
102+
addLinkAnnotation(one);
103+
}
98104
}
99105

100106
//Adds all occurrences of data node off screen
101-
linkAnnotation.searchResultsDown = searchDown;
102-
linkAnnotation.searchResultsUp = searchUp;
103-
linkAnnotation.setDataNode(one);
104107
ArrayList<Object> textUp = new ArrayList<Object>();
105108
ArrayList<Object> textDown = new ArrayList<Object>();
106-
for(DataNode dn: finder.getOccurrences(one.getPosition())) {
109+
for(DataNode dn: finder.getOccurrences(one.getValue(), new Position(one.getStartPosition(), one.getLength()))) {
107110
int[] offScreen = new int[3];
108111
int line = sourceViewer.widgetLineOfWidgetOffset(dn.getStartPosition())+1;
109112
offScreen[0] = line;
@@ -115,22 +118,12 @@ public void selectionChanged(ITextSelection selection) {
115118
else if(dn.getStartPosition() > sourceViewer.getBottomIndexEndOffset()) {
116119
textDown.add(offScreen);
117120
}
118-
if(dn.getDeclarationMethod() != null) {
119-
linkAnnotation.draw(null, sourceViewer.getTextWidget(),
120-
dn.getDeclarationMethod().getName().getStartPosition(), dn.getDeclarationMethod().getName().getLength());
121-
}
122-
if(dn.getInvocationMethod() != null) {
123-
linkAnnotation.draw(null, sourceViewer.getTextWidget(), dn.getInvocationMethod().getName().getStartPosition(),
124-
dn.getInvocationMethod().getName().getLength());
125-
}
126121
}
127122
if(searchUp != null) {
128123
textUp.addAll(searchUp);
129-
((EditorBreadcrumb)upBreadcrumb).setSearchIndex(one.getParameterIndex());
130124
((EditorBreadcrumb)upBreadcrumb).setSearchMethod(call.getCurrentMethod(one.getStartPosition()));
131125
}
132126
if(searchDown != null) {
133-
((EditorBreadcrumb)downBreadcrumb).setSearchIndex(one.getParameterIndex());
134127
textDown.addAll(searchDown);
135128
}
136129
upBreadcrumb.setText(textUp);

dataTool/src/dataTool/DataCallHierarchy.java

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

109
import org.eclipse.core.resources.IFile;
1110
import org.eclipse.core.resources.IFolder;
@@ -79,8 +78,7 @@ public DataCallHierarchy() {
7978
* @throws JavaModelException
8079
*/
8180
public Set<IMethod> searchProject(DataNode node, String direction) throws JavaModelException {
82-
Set<IMethod> results = new HashSet<IMethod>();
83-
//inClass = false;
81+
Set<IMethod> results = null;
8482
if (direction.equals(Finder.UP)) {
8583
Method up = node.getDeclarationMethod();
8684
if(up != null) {
@@ -89,22 +87,26 @@ public Set<IMethod> searchProject(DataNode node, String direction) throws JavaMo
8987
}
9088
else if (direction.equals(Finder.DOWN)) {
9189
ArrayList<String> down = new ArrayList<String>();
92-
Set<IMethod> searchDown = new HashSet<IMethod>();
93-
for(DataNode dn: Finder.getInstance().getOccurrences(node.getPosition())) {
90+
for(DataNode dn: Finder.getInstance().getOccurrences(node.getValue(), new Position(node.getStartPosition(),node.getLength()))) {
9491
if(dn.getInvocationMethod() != null) {
9592
down.add(dn.getInvocationMethod().getName().getIdentifier());
96-
searchDown.addAll(search(dn, dn.getInvocationMethod(), Finder.DOWN));
9793
}
9894
}
99-
for(IMethod s: searchDown) {
100-
if(down.contains(s.getElementName())) {
101-
results.add(s);
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;
102107
}
103108
}
104109
}
105-
if(results.isEmpty()) {
106-
return null;
107-
}
108110
return results;
109111
}
110112
/**
@@ -151,11 +153,15 @@ public Set<IMethod> search(DataNode node, Method methodName, String direction) t
151153
methods = callGen.getCallersOf(m);
152154
}
153155
else {
154-
Set<IMethod> temp = callGen.getCalleesOf(m);
155-
for(IMethod i: temp) {
156-
methods.add(i);
157-
}
158-
methods.add(m);
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+
}
159165
}
160166
return methods;
161167
}
@@ -176,7 +182,7 @@ private IMethod findMethod(IType type, String methodName) throws JavaModelExcept
176182
{
177183
IMethod imethod = methods[i];
178184
if (imethod.getElementName().equals(methodName)) {
179-
//inClass = true;
185+
inClass = true;
180186
theMethod = imethod;
181187
}
182188
}

dataTool/src/dataTool/DataNode.java

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
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;
129

1310
/**
1411
* DataNode class that creates objects for the data we find and want to highlight.
@@ -25,44 +22,71 @@ public class DataNode implements Comparable {
2522
final public static String FOR_VAR = "variableFor";
2623
final public static String VAR = "variable";
2724

25+
private String binding;
2826
private String key;
29-
private String name;
30-
private int startPosition;
27+
private String value;
28+
private int index;
3129
private int length;
3230
private int parameterIndex;
3331
private SimpleName sn;
3432
private String type;
33+
private String signature;
3534
private Method declarationMethod;
3635
private Method invocationMethod;
37-
private Position position;
36+
private boolean isHighlighted;
3837

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+
3958
public DataNode( SimpleName sn ) {
4059
this.sn = sn;
41-
name = sn.getFullyQualifiedName();
42-
startPosition = sn.getStartPosition();
43-
length = name.length();
44-
position = new Position( startPosition, length );
60+
value = sn.getFullyQualifiedName();
61+
index = sn.getStartPosition();
62+
length = value.length();
63+
isHighlighted = false;
4564
parameterIndex = -1;
4665
this.key = sn.resolveBinding().getKey();
66+
this.binding = sn.resolveBinding().toString();
4767
}
4868
public void setStartPosition( int i ) {
49-
startPosition = i;
69+
index = i;
5070
}
5171

5272
/**
5373
* Gets the value of the data
5474
* @returns variable name
5575
*/
5676
public String getValue() {
57-
return this.name;
77+
return this.value;
78+
}
79+
80+
public String getBinding() {
81+
return binding;
5882
}
5983

6084
/**
6185
* Gets the start position of current data in the source code
6286
* @returns variable start position
6387
*/
6488
public int getStartPosition() {
65-
return this.startPosition;
89+
return this.index;
6690
}
6791

6892
/**
@@ -91,13 +115,16 @@ public Method getInvocationMethod() {
91115
public void setInvocationMethod( Method m ) {
92116
invocationMethod = m;
93117
}
118+
public String getSignature() {
119+
return this.signature;
120+
}
94121
/**
95122
* Checks to see if current node is a parameter, only want to display box when actual
96123
* param is selected
97124
* @returns true if node is a parameter, else false
98125
*/
99126
public boolean isParameterSelected(int pos) {
100-
if(pos < startPosition || pos > startPosition+length) {
127+
if(pos < index || pos > index+length) {
101128
return false;
102129
}
103130
return true;
@@ -110,14 +137,11 @@ public int compareTo(Object o) {
110137
if( o == null || !( o instanceof DataNode ) ) {
111138
return 1;
112139
}
113-
return startPosition - ((DataNode)o).getStartPosition();
140+
return index - ((DataNode)o).getStartPosition();
114141
}
115142
@Override
116143
public String toString() {
117-
return key;
118-
}
119-
public Position getPosition() {
120-
return position;
144+
return binding;
121145
}
122146

123-
}
147+
}

0 commit comments

Comments
 (0)