Skip to content

Commit 7916c64

Browse files
author
Chris
committed
Fix for issue found in down search. Still having problems with down links
1 parent 298ccb4 commit 7916c64

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

dataTool/src/dataTool/AnnotationManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void selectionChanged(ITextSelection selection) {
100100
//Adds all occurrences of data node off screen
101101
linkAnnotation.searchResultsDown = searchDown;
102102
linkAnnotation.searchResultsUp = searchUp;
103-
103+
linkAnnotation.setDataNode(one);
104104
ArrayList<Object> textUp = new ArrayList<Object>();
105105
ArrayList<Object> textDown = new ArrayList<Object>();
106106
for(DataNode dn: finder.getOccurrences(one.getPosition())) {
@@ -116,12 +116,10 @@ else if(dn.getStartPosition() > sourceViewer.getBottomIndexEndOffset()) {
116116
textDown.add(offScreen);
117117
}
118118
if(dn.getDeclarationMethod() != null) {
119-
linkAnnotation.setDataNode(dn);
120119
linkAnnotation.draw(null, sourceViewer.getTextWidget(),
121120
dn.getDeclarationMethod().getName().getStartPosition(), dn.getDeclarationMethod().getName().getLength());
122121
}
123122
if(dn.getInvocationMethod() != null) {
124-
linkAnnotation.setDataNode(dn);
125123
linkAnnotation.draw(null, sourceViewer.getTextWidget(), dn.getInvocationMethod().getName().getStartPosition(),
126124
dn.getInvocationMethod().getName().getLength());
127125
}

dataTool/src/dataTool/DataCallHierarchy.java

Lines changed: 17 additions & 21 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,24 +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>();
92+
Set<IMethod> searchDown = new HashSet<IMethod>();
9093
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-
for(IMethod i: temp) {
100-
if(down.contains(i.getElementName())) {
101-
searchDown.add(i);
102-
}
103-
}
104-
results = searchDown;
99+
for(IMethod s: searchDown) {
100+
if(down.contains(s.getElementName())) {
101+
results.add(s);
105102
}
106103
}
107104
}
105+
if(results.isEmpty()) {
106+
return null;
107+
}
108108
return results;
109109
}
110110
/**
@@ -151,15 +151,11 @@ public Set<IMethod> search(DataNode node, Method methodName, String direction) t
151151
methods = callGen.getCallersOf(m);
152152
}
153153
else {
154-
if(!inClass) {
155-
Set<IMethod> temp = callGen.getCalleesOf(m);
156-
for(IMethod i: temp) {
157-
methods.add(i);
158-
}
159-
}
160-
else {
161-
methods.add(m);
162-
}
154+
Set<IMethod> temp = callGen.getCalleesOf(m);
155+
for(IMethod i: temp) {
156+
methods.add(i);
157+
}
158+
methods.add(m);
163159
}
164160
return methods;
165161
}
@@ -180,7 +176,7 @@ private IMethod findMethod(IType type, String methodName) throws JavaModelExcept
180176
{
181177
IMethod imethod = methods[i];
182178
if (imethod.getElementName().equals(methodName)) {
183-
inClass = true;
179+
//inClass = true;
184180
theMethod = imethod;
185181
}
186182
}

dataTool/src/dataTool/annotations/LinkAnnotation.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
public class LinkAnnotation extends Annotation implements ISelfDrawingAnnotation {
4848

4949
private DataNode linkNode;
50+
private static DataNode previousNode = null;
5051
private static ASTNode searchResult;
5152
public static Set<IMethod> searchResultsUp;
5253
public static Set<IMethod> searchResultsDown;
@@ -60,7 +61,7 @@ public class LinkAnnotation extends Annotation implements ISelfDrawingAnnotation
6061
* Function to add link annotations to methods of parameters
6162
*/
6263
public void draw(GC gc, StyledText textWidget, int offset, int length) {
63-
StyleRange style = new StyleRange();
64+
final StyleRange style = new StyleRange();
6465
style.start = offset;
6566
style.length = length;
6667
style.underline = true;
@@ -80,6 +81,11 @@ public void mouseDown(MouseEvent arg0) {
8081

8182
@Override
8283
public void mouseUp(MouseEvent arg0) {
84+
if(linkNode == previousNode) {
85+
//Occasionally click registers twice and messes up direction the link
86+
return;
87+
}
88+
previousNode = linkNode;
8389
int click = textWidget.getOffsetAtLocation(new Point(arg0.x,arg0.y));
8490
if(click >= style.start && click <= style.start+style.length && load){
8591
load = false;
@@ -106,7 +112,7 @@ public void mouseUp(MouseEvent arg0) {
106112
}
107113
}
108114
}
109-
else if(linkNode.getDeclarationMethod() != null) {
115+
else if(linkNode.getDeclarationMethod() != null && searchResultsUp != null) {
110116
try {
111117
search = searchResultsUp.toArray();
112118
im = (IMethod)search[0];

0 commit comments

Comments
 (0)