1414import org .eclipse .jdt .core .dom .MethodDeclaration ;
1515import org .eclipse .jdt .core .dom .SimpleName ;
1616import org .eclipse .jdt .internal .ui .javaeditor .JavaEditor ;
17- import org .eclipse .jdt .internal .ui .javaeditor .ShowDataInBreadcrumbAction ;
17+ import org .eclipse .jdt .internal .ui .javaeditor .JavaEditorBreadcrumb ;
18+ import org .eclipse .jdt .internal .ui .javaeditor .breadcrumb .EditorBreadcrumb ;
1819import org .eclipse .jdt .internal .ui .javaeditor .breadcrumb .IBreadcrumb ;
1920import org .eclipse .jface .action .Action ;
2021import org .eclipse .jface .text .ITextSelection ;
3132import dataTool .annotations .LinkAnnotation ;
3233import dataTool .annotations .ProgramNavigationPainter ;
3334import dataTool .annotations .SuggestedSelectionAnnotation ;
35+ import dataTool .ui .ShowDataInBreadcrumbAction ;
3436import edu .pdx .cs .multiview .jdt .util .JDTUtils ;
3537import edu .pdx .cs .multiview .jface .annotation .AnnTransaction ;
3638import edu .pdx .cs .multiview .jface .annotation .AnnotationPainter ;
@@ -44,7 +46,8 @@ public class AnnotationManager implements ISelectionChangedListener {
4446 private SourceViewer sourceViewer ;
4547 private ProgramNavigationPainter painter ;
4648 private static boolean isActive = false ;
47- private IBreadcrumb dataBreadcrumb ;
49+ private IBreadcrumb upBreadcrumb ;
50+ private IBreadcrumb downBreadcrumb ;
4851
4952 // the visitor for the editor
5053 private Visitor visitor ;
@@ -65,59 +68,74 @@ public AnnotationManager(AbstractDecoratedTextEditor anEditor) {
6568 painter = new ProgramNavigationPainter (sourceViewer );
6669 painter .addSelectionChangedListener (this );
6770 sourceViewer .addPainter (painter );
68- //isActive = false;
6971 selectionChanged ((ITextSelection ) painter .getSelection ());
7072 }
7173
7274 public void selectionChanged (ITextSelection selection ) {
75+ System .out .println ("selectionChanged" );
7376 painter .removeAllAnnotations ();
7477 try {
7578 DataNode one = getNode (selection .getOffset ());
76- System .out .println (one );
7779 Finder finder = Finder .getInstance ();
7880 if (one != null ) {
7981 addAnnotation (one );
80- currentSearch = one .getValue ();
81- System .out .println (isActive +" isActive" );
82+ currentSearch = one .getBinding ();
8283 IWorkbenchPage activePage = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage ();
8384 IEditorPart activeEditor = activePage .getActiveEditor ();
84- System .out .println (activeEditor .getTitle ()+" tidal" );
8585 JavaEditor j = (JavaEditor ) activeEditor ;
86- dataBreadcrumb = j .getBreadcrumb ();
86+ upBreadcrumb = j .getBreadcrumb ();
87+ downBreadcrumb = j .getBreadcrumb2 ();
88+ System .out .println (isActive + " is active" );
89+ System .out .println (upBreadcrumb .isActive ());
90+ System .out .println (downBreadcrumb .isActive ());
91+ System .out .println (j .areBreadcrumbsActive ());
8792 if (!isActive ) {
8893 isActive = true ;
8994 ShowDataInBreadcrumbAction crumbs = new ShowDataInBreadcrumbAction (j , activePage );
9095 crumbs .run ();
9196 }
97+ upBreadcrumb .setText (null );
98+ downBreadcrumb .setText (null );
9299 DataCallHierarchy call = new DataCallHierarchy ();
93100 Set <IMethod > searchUp = null ;
94- //Set<IMethod> searchDown = null;
95- //System.out.println(one.getBinding()+" "+one.getDeclarationMethod() +" "+one.getInvocationMethod());
96- if ((finder .upSearch (one ) != null || finder .downSearch (one ) != null ) && currentSearch != null ) {
101+ Set <IMethod > searchDown = null ;
102+ if ((finder .upSearch (one ) != null || finder .downSearch (one ) != null || one .getInvocationMethod () != null ) && currentSearch != null ) {
97103 searchUp = call .searchProject (one , Finder .UP );
98- //searchDown = call.searchProject(one, Finder.DOWN);
99- //System.out.println("search "+one.getValue()+" "+searchUp+" "+one.getDeclarationMethod());
104+ searchDown = call .searchProject (one , Finder .DOWN );
100105 if (one .isParameterSelected (selection .getOffset ())) {
101- // linkAnnotation.searchResultsDown = searchDown;
106+ linkAnnotation .searchResultsDown = searchDown ;
102107 linkAnnotation .searchResultsUp = searchUp ;
103108 linkAnnotation .setDataNode (one );
104109 addLinkAnnotation (one );
105110 }
106111 }
107112 Set <String > test = new HashSet <String >();
108113 test .add (one .getValue ());
109- dataBreadcrumb .setText (searchUp );
110114 //Adds all occurrences of data node off screen
115+ ArrayList <Object > textUp = new ArrayList <Object >();
116+ ArrayList <Object > textDown = new ArrayList <Object >();
111117 for (DataNode dn : finder .getOccurrences (one .getValue (), new Position (one .getStartPosition (), one .getLength ()))) {
118+ int [] offScreen = new int [3 ];
119+ int line = sourceViewer .widgetLineOfWidgetOffset (dn .getStartPosition ())+1 ;
120+ offScreen [0 ] = line ;
121+ offScreen [1 ] = dn .getStartPosition ();
122+ offScreen [2 ] = dn .getLength ();
112123 if (dn .getStartPosition () < sourceViewer .getTopIndexStartOffset ()) {
113- int line = sourceViewer .widgetLineOfWidgetOffset (dn .getStartPosition ())+1 ;
114- //NavigationUpBox.getInstance().addOffScreen(dn, line);
124+ textUp .add (offScreen );
115125 }
116126 else if (dn .getStartPosition () > sourceViewer .getBottomIndexEndOffset ()) {
117- int line = sourceViewer .widgetLineOfWidgetOffset (dn .getStartPosition ())+1 ;
118- //NavigationDownBox.getInstance().addOffScreen(dn, line);
127+ textDown .add (offScreen );
119128 }
120129 }
130+ if (searchUp != null ) {
131+ textUp .addAll (searchUp );
132+ ((EditorBreadcrumb )upBreadcrumb ).setSearchMethod (call .getCurrentMethod (one .getStartPosition ()));
133+ }
134+ if (searchDown != null ) {
135+ textDown .addAll (searchDown );
136+ }
137+ upBreadcrumb .setText (textUp );
138+ downBreadcrumb .setText (textDown );
121139 }
122140 else {
123141 removeAnnotations ();
@@ -127,30 +145,6 @@ else if(dn.getStartPosition() > sourceViewer.getBottomIndexEndOffset()) {
127145 removeAnnotations ();
128146 }
129147 }
130-
131- /**
132- * Function that returns the method the current node is located in
133- * @param node: Current node selected by the user
134- * @returns String method name
135- */
136- private String getMethod (DataNode one ) {
137-
138- //TODO Function that could come in handy later to get current method mouse is clicked in
139- /*ASTNode temp = one.;
140- while(!(temp instanceof MethodDeclaration) && temp != null) {
141- temp = temp.getParent();
142- }
143- if(temp == null) {
144- return null;
145- }
146- return ((MethodDeclaration) temp).getName().getIdentifier();*/
147- //System.out.println(one.getValue()+" get "+one.getMethod().getName());
148- //System.out.println(one.getBinding());
149- //if(one.getMethod() != null) {
150- //return one.getMethod().getName().toString();
151- //}
152- return null ;
153- }
154148
155149 private void addAnnotation (DataNode node ) {
156150 int start = node .getStartPosition ();
@@ -162,11 +156,11 @@ private void addAnnotation(DataNode node) {
162156
163157 private void addLinkAnnotation (DataNode node ) {
164158 SimpleName method ;
165- if (node .getDeclarationMethod () != null ) {
166- method = node .getDeclarationMethod ().getName ();
159+ if (node .getInvocationMethod () != null ) {
160+ method = node .getInvocationMethod ().getName ();
167161 }
168162 else {
169- method = node .getInvocationMethod ().getName ();
163+ method = node .getDeclarationMethod ().getName ();
170164 }
171165 int start = method .getStartPosition ();
172166 int end = method .getStartPosition () + method .getLength ();
@@ -242,7 +236,6 @@ private void addAnnotationsAt(int statementStart, int length, boolean isHighligh
242236 public void removeAnnotations () {
243237 try {
244238 if (highlightAnnotation != null ) {
245- // painter.removeAnnotation(highlightAnnotation);
246239 painter .removeAllAnnotations ();
247240 }
248241 } catch (Exception ignore ) {
@@ -251,13 +244,10 @@ public void removeAnnotations() {
251244
252245 public void dispose () {
253246 painter .dispose ();
254- //dataBreadcrumb.dispose();
255- //isActive = false;
256247 currentSearch = null ;
257248 }
258249
259250 public void selectionChanged (SelectionChangedEvent event ) {
260- painter .removeAllAnnotations ();
261251 selectionChanged ((ITextSelection ) event .getSelection ());
262252 }
263253}
0 commit comments