Skip to content

Commit 99999ef

Browse files
author
Chris
committed
Fixed bug with editor links
1 parent 855d1af commit 99999ef

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

dataTool/src/dataTool/Visitor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public boolean visit( SimpleName sn ) {
177177
addedNode = getNodeFromName(sn);
178178
if( addedNode != null ) {
179179
for( DataNode dn : params ) {
180-
if( addedNode.getKey().equals(dn.getKey() ) ) {
180+
if( addedNode.getKey().equals(dn.getKey() )) {
181181
addedNode.setDeclarationMethod(methodDeclaration);
182182
addedNode.setParameterIndex(dn.getParameterIndex());
183183
}
@@ -202,7 +202,8 @@ public boolean visit(MethodInvocation mi) {
202202
SimpleName n = (SimpleName) e;
203203
addedNode = getNodeFromName(n);
204204
// TODO shouldn't need a check here
205-
if( addedNode != null ) {
205+
if( addedNode != null) {
206+
addedNode.setDeclarationMethod(null);
206207
addedNode.setInvocationMethod(methodInvocation);
207208
addedNode.setParameterIndex(i);
208209
nodeArgs.add( addedNode );

dataTool/src/dataTool/annotations/LinkAnnotation.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.eclipse.jdt.core.dom.CompilationUnit;
3636
import org.eclipse.jdt.core.dom.MethodDeclaration;
3737
import org.eclipse.jdt.core.dom.MethodInvocation;
38+
import org.eclipse.jdt.core.dom.SimpleName;
3839
import org.eclipse.jdt.ui.JavaUI;
3940

4041
import dataTool.DataCallHierarchy;
@@ -51,7 +52,7 @@ public class LinkAnnotation extends Annotation implements ISelfDrawingAnnotation
5152
private static ASTNode searchResult;
5253
public static Set<IMethod> searchResultsUp;
5354
public static Set<IMethod> searchResultsDown;
54-
public IMethod searchMethod = null;
55+
public String searchMethod = null;
5556
private IEditorPart editor = null;
5657
private boolean load = true;
5758

@@ -84,6 +85,8 @@ public void mouseDown(MouseEvent arg0) {
8485
public void mouseUp(MouseEvent arg0) {
8586
int click = textWidget.getOffsetAtLocation(new Point(arg0.x,arg0.y));
8687
if(click >= style.start && click <= style.start+style.length && load){
88+
load = false;
89+
boolean up = false;
8790
if(linkNode == null) {
8891
return;
8992
}
@@ -140,30 +143,34 @@ else if(linkNode.getDeclarationMethod() != null) {
140143
}
141144
}*/
142145
IMethod i = null;
143-
for(IMethod im: search) {
144-
if(linkNode.getInvocationMethod() != null) {
146+
if(linkNode.getInvocationMethod() != null && linkNode.getDeclarationMethod() == null) {
147+
for(IMethod im: search) {
145148
if (im.getElementName().equals(linkNode.getInvocationMethod().getName().getIdentifier())) {
146149
i = im;
147150
break;
148151
}
149152
}
150153

151154
}
152-
if (i == null) {
153-
if(linkNode.getDeclarationMethod() != null && searchResultsUp != null) {
154-
i = search.get(0);
155+
if (i == null || linkNode.getDeclarationMethod() != null) {
156+
if(searchResultsUp != null) {
157+
i = (IMethod) searchResultsUp.toArray()[0];
158+
searchMethod = linkNode.getDeclarationMethod().getName().getIdentifier();
159+
up = true;
155160
}
156-
else {
161+
else if (i == null){
157162
return;
158163
}
159164
}
160165
IEditorPart editor = null;
161166
try {
162-
if(i.getParameters().length > 0 && linkNode.getParameterIndex() >= 0) {
167+
if(i.getParameters().length > 0 && linkNode.getParameterIndex() >= 0 && !up) {
163168
editor = JavaUI.openInEditor(i.getParameters()[linkNode.getParameterIndex()], true, true);
169+
load = true;
164170
}
165171
else {
166172
editor = JavaUI.openInEditor(i, true, true);
173+
load = true;
167174
if(searchMethod != null && editor != null) {
168175
String code = ((AbstractTextEditor)editor).getDocumentProvider().getDocument(editor.getEditorInput()).get();
169176
lineSearch(code.toCharArray(), i);
@@ -194,7 +201,7 @@ public boolean visit(MethodDeclaration md) {
194201
public boolean visit(MethodInvocation m) {
195202
if(method.getElementName().equals(methodName)) {
196203
if(m.getName().getIdentifier().equals(searchMethod)) {
197-
searchResult = m;
204+
searchResult = (SimpleName) m.arguments().get(linkNode.getParameterIndex());
198205
}
199206
}
200207
return true;
@@ -246,7 +253,7 @@ public void setDataNode(DataNode node) {
246253
}
247254

248255
public void setSearchMethod(IMethod currentMethod) {
249-
searchMethod = currentMethod;
256+
searchMethod = currentMethod.getElementName();
250257
}
251258

252259
}

0 commit comments

Comments
 (0)