Skip to content

Commit 1eef95c

Browse files
author
Chris
committed
More updates for UI. Up is mostly working now but still looking at down.
1 parent 3ba529e commit 1eef95c

4 files changed

Lines changed: 121 additions & 57 deletions

File tree

dataTool/src/dataTool/AnnotationManager.java

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import dataTool.annotations.LinkAnnotation;
3232
import dataTool.annotations.ProgramNavigationPainter;
3333
import dataTool.annotations.SuggestedSelectionAnnotation;
34-
import dataTool.ui.NavigationDownBox;
35-
import dataTool.ui.NavigationUpBox;
3634
import edu.pdx.cs.multiview.jdt.util.JDTUtils;
3735
import edu.pdx.cs.multiview.jface.annotation.AnnTransaction;
3836
import edu.pdx.cs.multiview.jface.annotation.AnnotationPainter;
@@ -45,7 +43,7 @@ public class AnnotationManager implements ISelectionChangedListener {
4543
private LinkAnnotation linkAnnotation = new LinkAnnotation();
4644
private SourceViewer sourceViewer;
4745
private ProgramNavigationPainter painter;
48-
private boolean isActive;
46+
private static boolean isActive = false;
4947
private IBreadcrumb dataBreadcrumb;
5048

5149
// the visitor for the editor
@@ -67,58 +65,48 @@ public AnnotationManager(AbstractDecoratedTextEditor anEditor) {
6765
painter = new ProgramNavigationPainter(sourceViewer);
6866
painter.addSelectionChangedListener(this);
6967
sourceViewer.addPainter(painter);
70-
isActive = false;
68+
//isActive = false;
7169
selectionChanged((ITextSelection) painter.getSelection());
7270
}
7371

7472
public void selectionChanged(ITextSelection selection) {
7573
painter.removeAllAnnotations();
7674
try {
7775
DataNode one = getNode(selection.getOffset());
76+
System.out.println(one);
7877
Finder finder = Finder.getInstance();
79-
// System.out.println("myData2");
80-
// System.out.println(one.getValue());
81-
// System.out.println(one.getBinding());
82-
// System.out.println(one.getSignature());
83-
// System.out.println(one.getDeclarationMethod());
84-
// System.out.println(one.getInvocationMethod());
85-
// System.out.println(one.isParameterSelected(selection.getOffset()));
86-
// System.out.println(finder.downSearch(one));
87-
// System.out.println(finder.upSearch(one));
88-
// System.out.println(finder.declarationToInvocationMapDown.entrySet());
89-
// System.out.println(finder.invocationToDeclarationMapUp.entrySet());
90-
// System.out.println(finder.map.entrySet());
9178
if(one != null) {
9279
addAnnotation(one);
9380
currentSearch = one.getValue();
81+
System.out.println(isActive+" isActive");
82+
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
83+
IEditorPart activeEditor = activePage.getActiveEditor();
84+
System.out.println(activeEditor.getTitle()+" tidal");
85+
JavaEditor j = (JavaEditor) activeEditor;
86+
dataBreadcrumb = j.getBreadcrumb();
9487
if(!isActive) {
9588
isActive = true;
96-
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
97-
IEditorPart activeEditor = activePage.getActiveEditor();
98-
JavaEditor j = (JavaEditor) activeEditor;
99-
dataBreadcrumb = j.getBreadcrumb();
10089
ShowDataInBreadcrumbAction crumbs = new ShowDataInBreadcrumbAction(j, activePage);
10190
crumbs.run();
10291
}
10392
DataCallHierarchy call = new DataCallHierarchy();
10493
Set<IMethod> searchUp = null;
105-
Set<IMethod> searchDown = null;
106-
System.out.println(one.getBinding()+" "+one.getDeclarationMethod() +" "+one.getInvocationMethod());
107-
//System.out.println(one.getBinding());
94+
//Set<IMethod> searchDown = null;
95+
//System.out.println(one.getBinding()+" "+one.getDeclarationMethod() +" "+one.getInvocationMethod());
10896
if((finder.upSearch(one) != null || finder.downSearch(one) != null) && currentSearch != null) {
10997
searchUp = call.searchProject(one, Finder.UP);
110-
searchDown = call.searchProject(one, Finder.DOWN);
111-
System.out.println("search "+one.getValue());
98+
//searchDown = call.searchProject(one, Finder.DOWN);
99+
//System.out.println("search "+one.getValue()+" "+searchUp+" "+one.getDeclarationMethod());
112100
if(one.isParameterSelected(selection.getOffset())) {
113-
linkAnnotation.searchResultsDown = searchDown;
101+
//linkAnnotation.searchResultsDown = searchDown;
114102
linkAnnotation.searchResultsUp = searchUp;
115103
linkAnnotation.setDataNode(one);
116104
addLinkAnnotation(one);
117105
}
118106
}
119107
Set<String> test = new HashSet<String>();
120108
test.add(one.getValue());
121-
//dataBreadcrumb.setText(test);
109+
dataBreadcrumb.setText(searchUp);
122110
//Adds all occurrences of data node off screen
123111
for(DataNode dn: finder.getOccurrences(one.getValue(), new Position(one.getStartPosition(), one.getLength()))) {
124112
if(dn.getStartPosition() < sourceViewer.getTopIndexStartOffset()) {
@@ -136,15 +124,6 @@ else if(dn.getStartPosition() > sourceViewer.getBottomIndexEndOffset()) {
136124
}
137125
} catch (Exception e) {
138126
Activator.logError(e);
139-
if(isActive) {
140-
try {
141-
NavigationUpBox.getInstance().setText(null);
142-
NavigationDownBox.getInstance().setText(null);
143-
} catch (Exception e1) {
144-
// Auto-generated catch block
145-
//e.printStackTrace();
146-
}
147-
}
148127
removeAnnotations();
149128
}
150129
}
@@ -154,23 +133,24 @@ else if(dn.getStartPosition() > sourceViewer.getBottomIndexEndOffset()) {
154133
* @param node: Current node selected by the user
155134
* @returns String method name
156135
*/
157-
/*private String getMethod(DataNode one) {
136+
private String getMethod(DataNode one) {
137+
158138
//TODO Function that could come in handy later to get current method mouse is clicked in
159-
ASTNode temp = one.;
139+
/*ASTNode temp = one.;
160140
while(!(temp instanceof MethodDeclaration) && temp != null) {
161141
temp = temp.getParent();
162142
}
163143
if(temp == null) {
164144
return null;
165145
}
166-
return ((MethodDeclaration) temp).getName().getIdentifier();
146+
return ((MethodDeclaration) temp).getName().getIdentifier();*/
167147
//System.out.println(one.getValue()+" get "+one.getMethod().getName());
168148
//System.out.println(one.getBinding());
169149
//if(one.getMethod() != null) {
170150
//return one.getMethod().getName().toString();
171151
//}
172-
//return null;
173-
}*/
152+
return null;
153+
}
174154

175155
private void addAnnotation(DataNode node) {
176156
int start = node.getStartPosition();
@@ -271,8 +251,8 @@ public void removeAnnotations() {
271251

272252
public void dispose() {
273253
painter.dispose();
274-
dataBreadcrumb.dispose();
275-
isActive = false;
254+
//dataBreadcrumb.dispose();
255+
//isActive = false;
276256
currentSearch = null;
277257
}
278258

dataTool/src/dataTool/DataCallHierarchy.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ public DataCallHierarchy() {
7070
*/
7171
public Set<IMethod> searchProject(DataNode node, String direction) throws JavaModelException {
7272
Set<IMethod> results = null;
73+
System.out.println(node.getDeclarationMethod()+" declaration");
7374
if (direction.equals(Finder.UP)) {
74-
ArrayList<Method> up = Finder.getInstance().upSearch(node);
75+
Method up = node.getDeclarationMethod();
7576
if(up != null) {
76-
results = search(node.getDeclarationMethod().getName().getIdentifier(), Finder.UP);
77+
results = search(up.getName().getIdentifier(), Finder.UP);
7778
}
7879
}
7980
else if (direction.equals(Finder.DOWN)) {
@@ -128,6 +129,9 @@ public Set<IMethod> search(String methodName, String direction) throws JavaModel
128129
cUnit = frag.getCompilationUnit(projectFile);
129130
IType type = cUnit.getType(projectFile.replace(".java", ""));
130131
IMethod m = findMethod(type, methodName);
132+
if(m == null){
133+
return null;
134+
}
131135
Set<IMethod> methods = new HashSet<IMethod>();
132136
if(direction.equals(Finder.UP)) {
133137
methods = callGen.getCallersOf(m);

dataTool/src/dataTool/Finder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ public TreeSet<DataNode> getOccurrences(String s, Position p) {
227227
}
228228

229229
public ArrayList<Method> upSearch( DataNode dn ) {
230+
System.out.println(dn.getDeclarationMethod());
230231
if(dn.getDeclarationMethod() != null) {
231232
String declarationMethodBinding = dn.getDeclarationMethod().getName().resolveBinding().toString();
233+
System.out.println(invocationToDeclarationMapUp.entrySet());
232234
return invocationToDeclarationMapUp.get(declarationMethodBinding);
233235
}
234236
return null;

dataTool/src/dataTool/annotations/LinkAnnotation.java

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Set;
66
import java.util.TreeSet;
77

8+
import org.eclipse.jface.text.IDocument;
89
import org.eclipse.jface.text.source.Annotation;
910
import org.eclipse.swt.SWT;
1011
import org.eclipse.swt.custom.StyleRange;
@@ -15,8 +16,20 @@
1516
import org.eclipse.swt.events.SelectionListener;
1617
import org.eclipse.swt.graphics.GC;
1718
import org.eclipse.swt.graphics.Point;
19+
import org.eclipse.ui.IEditorPart;
20+
import org.eclipse.ui.PartInitException;
21+
import org.eclipse.ui.texteditor.AbstractTextEditor;
22+
import org.eclipse.ui.texteditor.ITextEditor;
1823
import org.eclipse.jdt.core.IMethod;
1924
import org.eclipse.jdt.core.JavaModelException;
25+
import org.eclipse.jdt.core.dom.AST;
26+
import org.eclipse.jdt.core.dom.ASTNode;
27+
import org.eclipse.jdt.core.dom.ASTParser;
28+
import org.eclipse.jdt.core.dom.ASTVisitor;
29+
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
30+
import org.eclipse.jdt.core.dom.CompilationUnit;
31+
import org.eclipse.jdt.core.dom.MethodDeclaration;
32+
import org.eclipse.jdt.core.dom.MethodInvocation;
2033
import org.eclipse.jdt.ui.JavaUI;
2134

2235
import dataTool.DataCallHierarchy;
@@ -25,13 +38,16 @@
2538
import dataTool.Finder;
2639
import dataTool.ui.NavigationDownBox;
2740
import dataTool.ui.NavigationUpBox;
41+
import edu.pdx.cs.multiview.jdt.util.JDTUtils;
2842
import edu.pdx.cs.multiview.jface.annotation.ISelfDrawingAnnotation;
2943

3044
public class LinkAnnotation extends Annotation implements ISelfDrawingAnnotation {
3145

3246
private DataNode linkNode;
47+
private static ASTNode searchResult;
3348
public static Set<IMethod> searchResultsUp;
3449
public static Set<IMethod> searchResultsDown;
50+
public String searchMethod = "";
3551

3652
/**
3753
* Function to add link annotations to methods of parameters
@@ -56,20 +72,20 @@ public void mouseDown(MouseEvent arg0) {
5672
if(click >= style.start && click <= style.start+style.length){
5773
Object[] search;
5874
IMethod im;
59-
// Don't want to perform the search again, need to find a way to get results from previous search here.
75+
System.out.println("clicked");
6076
if(linkNode.getDeclarationMethod() != null) {
61-
/*try {
77+
try {
6278
search = searchResultsUp.toArray();
6379
im = (IMethod)search[0];
64-
NavigationUpBox up = NavigationUpBox.getInstance();
65-
up.searchMethod = linkNode.getDeclarationMethod();
66-
up.openLink(im);
80+
searchMethod = linkNode.getDeclarationMethod().getName().getIdentifier();
81+
openLink(im);
6782
} catch (Exception e) {
6883
// Auto-generated catch block
6984
e.printStackTrace();
70-
}*/
85+
}
7186
}
7287
else if(linkNode.getInvocationMethod() != null) {
88+
//TODO Down
7389
/*try {
7490
search = searchResultsDown.toArray();
7591
for(Object o: search) {
@@ -84,13 +100,13 @@ else if(linkNode.getInvocationMethod() != null) {
84100
e.printStackTrace();
85101
}*/
86102
}
87-
EnableNavigationAction plugin = new EnableNavigationAction();
88-
try {
89-
plugin.reset(null);
90-
} catch (JavaModelException e) {
103+
//EnableNavigationAction plugin = new EnableNavigationAction();
104+
//try {
105+
//plugin.reset(null);
106+
//} catch (JavaModelException e) {
91107
// Auto-generated catch block
92-
e.printStackTrace();
93-
}
108+
// e.printStackTrace();
109+
//}
94110
}
95111
}
96112

@@ -103,6 +119,68 @@ public void mouseUp(MouseEvent arg0) {
103119
});
104120
}
105121

122+
/**
123+
* Opens invocation of new method in the editor and clears navigation box links
124+
* @param i: IMethod to open
125+
*/
126+
public void openLink(IMethod i) {
127+
IEditorPart editor = null;
128+
try {
129+
editor = JavaUI.openInEditor(i, true, true);
130+
} catch (JavaModelException | PartInitException e) {
131+
// Auto-generated catch block
132+
e.printStackTrace();
133+
}
134+
//if(editor != null) {
135+
//String code = JDTUtils.getCUSource((AbstractTextEditor) editor);
136+
//lineSearch(code.toCharArray(), i);
137+
//goToLine(editor);
138+
//}
139+
}
140+
141+
private void lineSearch(char[] source, IMethod method) {
142+
ASTParser parser = ASTParser.newParser(AST.JLS3);
143+
parser.setSource(source);
144+
parser.setKind(ASTParser.K_COMPILATION_UNIT);
145+
final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
146+
cu.accept(new ASTVisitor(){
147+
public boolean visit(MethodDeclaration md) {
148+
String methodName = md.getName().getIdentifier();
149+
md.accept(new ASTVisitor() {
150+
public boolean visit(MethodInvocation m) {
151+
if(method.getElementName().equals(methodName)) {
152+
if(m.getName().getIdentifier().equals(searchMethod)) {
153+
searchResult = m;
154+
}
155+
}
156+
return true;
157+
}
158+
public boolean visit(ClassInstanceCreation c) {
159+
//System.out.println(" "+c.getType().toString() +" " + AnnotationManager.currentSearch);
160+
return true;
161+
}
162+
});
163+
return true;
164+
}
165+
});
166+
}
167+
/**
168+
* Opens the new class at the specific line
169+
* http://stackoverflow.com/questions/2873879/eclipe-pde-jump-to-line-x-and-highlight-it
170+
* @param editorPart: current editor
171+
* @param lineNumber: line number of method invocation
172+
*/
173+
private static void goToLine(IEditorPart editorPart) {
174+
if (!(editorPart instanceof ITextEditor)) {
175+
return;
176+
}
177+
ITextEditor editor = (ITextEditor) editorPart;
178+
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
179+
if (document != null && searchResult != null) {
180+
editor.selectAndReveal(searchResult.getStartPosition(), searchResult.getLength());
181+
}
182+
}
183+
106184
/**
107185
* Removes the link annotation from the editor
108186
* @param old: StyleRange for a link annotation to a method

0 commit comments

Comments
 (0)