Skip to content

Commit e562c69

Browse files
author
Chris
committed
Updates for issue #29
1 parent 66226e6 commit e562c69

5 files changed

Lines changed: 39 additions & 24 deletions

File tree

dataTool/src/dataTool/AnnotationManager.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ public AnnotationManager(AbstractDecoratedTextEditor anEditor) {
6868
sourceViewer.addPainter(painter);
6969
selectionChanged((ITextSelection) painter.getSelection());
7070
}
71-
71+
72+
/**
73+
* Handles updating the annotations and searching when user clicks a variable
74+
* @param selection: current text selected
75+
*/
7276
public void selectionChanged(ITextSelection selection) {
7377
painter.removeAllAnnotations();
7478
try {
@@ -122,9 +126,11 @@ else if(dn.getStartPosition() > sourceViewer.getBottomIndexEndOffset()) {
122126
if(searchUp != null) {
123127
textUp.addAll(searchUp);
124128
((EditorBreadcrumb)upBreadcrumb).setSearchMethod(call.getCurrentMethod(one.getStartPosition()));
129+
((EditorBreadcrumb)upBreadcrumb).setSearchIndex(one.getParameterIndex());
125130
}
126131
if(searchDown != null) {
127132
textDown.addAll(searchDown);
133+
((EditorBreadcrumb)downBreadcrumb).setSearchIndex(one.getParameterIndex());
128134
}
129135
upBreadcrumb.setText(textUp);
130136
downBreadcrumb.setText(textDown);
@@ -180,7 +186,7 @@ private ASTNode meet(ASTNode from, ASTNode to) {
180186
private boolean isAlreadyAnnotated(int start, int end) {
181187

182188
Position headPosition = painter.getPosition(highlightAnnotation);
183-
189+
184190
if (headPosition != null)
185191
return headPosition.getOffset() == start && headPosition.getOffset() + headPosition.getLength() == end;
186192

@@ -227,7 +233,7 @@ private void addAnnotationsAt(int statementStart, int length, boolean isHighligh
227233

228234
public void removeAnnotations() {
229235
try {
230-
if (highlightAnnotation != null) {
236+
if (highlightAnnotation != null || linkAnnotation != null) {
231237
painter.removeAllAnnotations();
232238
}
233239
} catch (Exception ignore) {

dataTool/src/dataTool/DataCallHierarchy.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ else if (direction.equals(Finder.DOWN)) {
9696
if( node.getInvocationMethod() != null ) {
9797
Set<IMethod> searchDown = new HashSet<IMethod>();
9898
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-
}
10699
results = searchDown;
107100
}
108101
}

dataTool/src/dataTool/Visitor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,17 @@ public boolean visit(MethodInvocation mi) {
194194
}
195195
List<Expression> args = mi.arguments();
196196
Method methodInvocation = new Method( mi.getName());
197-
198197
List<DataNode> nodeArgs = new ArrayList<DataNode>();
198+
int i = -1;
199199
for( Expression e : args ) {
200200
if( e.getNodeType() == ASTNode.SIMPLE_NAME ) {
201+
i++;
201202
SimpleName n = (SimpleName) e;
202203
addedNode = getNodeFromName(n);
203204
// TODO shouldn't need a check here
204205
if( addedNode != null ) {
205206
addedNode.setInvocationMethod(methodInvocation);
207+
addedNode.setParameterIndex(i);
206208
nodeArgs.add( addedNode );
207209
}
208210
} else {

dataTool/src/dataTool/annotations/LinkAnnotation.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.eclipse.ui.PartInitException;
2424
import org.eclipse.ui.texteditor.AbstractTextEditor;
2525
import org.eclipse.ui.texteditor.ITextEditor;
26+
import org.eclipse.jdt.core.IJavaElement;
27+
import org.eclipse.jdt.core.ILocalVariable;
2628
import org.eclipse.jdt.core.IMethod;
2729
import org.eclipse.jdt.core.JavaModelException;
2830
import org.eclipse.jdt.core.dom.AST;
@@ -51,7 +53,7 @@ public class LinkAnnotation extends Annotation implements ISelfDrawingAnnotation
5153
public static Set<IMethod> searchResultsDown;
5254
public String searchMethod = "";
5355
private IEditorPart editor = null;
54-
private boolean load = true;
56+
private static boolean load = true;
5557

5658
public static final String INVALID = "Method not in scope of project.";
5759

@@ -90,8 +92,14 @@ public void mouseUp(MouseEvent arg0) {
9092
im = (IMethod) o;
9193
if(im.getElementName().equals(linkNode.getInvocationMethod().getName().getIdentifier())) {
9294
try {
93-
JavaUI.openInEditor(im, true, true);
94-
load = true;
95+
if(im.getParameters().length > 0) {
96+
editor = JavaUI.openInEditor(im.getParameters()[linkNode.getParameterIndex()], true, true);
97+
load = true;
98+
}
99+
else {
100+
JavaUI.openInEditor(im, true, true);
101+
load = true;
102+
}
95103
} catch (PartInitException | JavaModelException e) {
96104
// Auto-generated catch block
97105
e.printStackTrace();
@@ -104,13 +112,20 @@ else if(linkNode.getDeclarationMethod() != null) {
104112
search = searchResultsUp.toArray();
105113
im = (IMethod)search[0];
106114
searchMethod = linkNode.getDeclarationMethod().getName().getIdentifier();
107-
editor = JavaUI.openInEditor(im, true, true);
108-
if(editor != null) {
109-
String code = JDTUtils.getCUSource((AbstractTextEditor) editor);
110-
lineSearch(code.toCharArray(), im);
111-
goToLine(editor);
115+
if(im.getParameters().length > 0) {
116+
editor = JavaUI.openInEditor(im.getParameters()[linkNode.getParameterIndex()], true, true);
112117
load = true;
113118
}
119+
else {
120+
editor = JavaUI.openInEditor(im, true, true);
121+
if(editor != null) {
122+
String code = JDTUtils.getCUSource((AbstractTextEditor) editor);
123+
lineSearch(code.toCharArray(), im);
124+
goToLine(editor);
125+
load = true;
126+
}
127+
}
128+
114129
} catch (Exception e) {
115130
// Auto-generated catch block
116131
e.printStackTrace();
@@ -138,12 +153,13 @@ public boolean visit(MethodInvocation m) {
138153
}
139154
return true;
140155
}
141-
public boolean visit(ClassInstanceCreation c) {
156+
//TODO if we need it
157+
/*public boolean visit(ClassInstanceCreation c) {
142158
if(c.getType().toString().equals(searchMethod)) {
143159
searchResult = c;
144160
}
145161
return true;
146-
}
162+
}*/
147163
});
148164
return true;
149165
}
@@ -163,6 +179,7 @@ private static void goToLine(IEditorPart editorPart) {
163179
ITextEditor editor = (ITextEditor) editorPart;
164180
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
165181
if (document != null && searchResult != null) {
182+
//searchResult.
166183
editor.selectAndReveal(searchResult.getStartPosition(), searchResult.getLength());
167184
}
168185
}

dataTool/src/dataTool/annotations/ProgramNavigationPainter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public class ProgramNavigationPainter extends AnnotationPainter {
6060
private Set<ISelectionChangedListener> listeners = new HashSet<ISelectionChangedListener>();
6161
private SourceViewer viewer;
6262
private Map<ISelfDrawingAnnotation, Position> anns = new HashMap<ISelfDrawingAnnotation, Position>();
63-
private Map<ISelfDrawingAnnotation, Position> linkAnns = new HashMap<ISelfDrawingAnnotation, Position>();
6463
private boolean isActive = false;
6564
private boolean painted = false;
6665

@@ -151,9 +150,7 @@ public void removeAnnotation(ISelfDrawingAnnotation ann) {
151150

152151
public void removeAllAnnotations() {
153152
Collection<Position> positions = new ArrayList<Position>(anns.values());
154-
positions.addAll(linkAnns.values());
155153
anns.clear();
156-
linkAnns.clear();
157154
fireAnnotationChangedEvent(positions);
158155
}
159156

0 commit comments

Comments
 (0)