KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > debug > TreeNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.java.debug;
20
21 import com.sun.source.tree.AnnotationTree;
22 import com.sun.source.tree.ArrayAccessTree;
23 import com.sun.source.tree.ArrayTypeTree;
24 import com.sun.source.tree.AssertTree;
25 import com.sun.source.tree.AssignmentTree;
26 import com.sun.source.tree.BinaryTree;
27 import com.sun.source.tree.BlockTree;
28 import com.sun.source.tree.BreakTree;
29 import com.sun.source.tree.CaseTree;
30 import com.sun.source.tree.CatchTree;
31 import com.sun.source.tree.ClassTree;
32 import com.sun.source.tree.CompilationUnitTree;
33 import com.sun.source.tree.CompoundAssignmentTree;
34 import com.sun.source.tree.ConditionalExpressionTree;
35 import com.sun.source.tree.ContinueTree;
36 import com.sun.source.tree.DoWhileLoopTree;
37 import com.sun.source.tree.EmptyStatementTree;
38 import com.sun.source.tree.EnhancedForLoopTree;
39 import com.sun.source.tree.ErroneousTree;
40 import com.sun.source.tree.ExpressionStatementTree;
41 import com.sun.source.tree.ForLoopTree;
42 import com.sun.source.tree.IdentifierTree;
43 import com.sun.source.tree.IfTree;
44 import com.sun.source.tree.ImportTree;
45 import com.sun.source.tree.InstanceOfTree;
46 import com.sun.source.tree.LabeledStatementTree;
47 import com.sun.source.tree.LiteralTree;
48 import com.sun.source.tree.MemberSelectTree;
49 import com.sun.source.tree.MethodTree;
50 import com.sun.source.tree.MethodInvocationTree;
51 import com.sun.source.tree.ModifiersTree;
52 import com.sun.source.tree.NewArrayTree;
53 import com.sun.source.tree.NewClassTree;
54 import com.sun.source.tree.ParameterizedTypeTree;
55 import com.sun.source.tree.ParenthesizedTree;
56 import com.sun.source.tree.PrimitiveTypeTree;
57 import com.sun.source.tree.ReturnTree;
58 import com.sun.source.tree.SwitchTree;
59 import com.sun.source.tree.SynchronizedTree;
60 import com.sun.source.tree.ThrowTree;
61 import com.sun.source.tree.TryTree;
62 import com.sun.source.tree.TypeCastTree;
63 import com.sun.source.tree.TypeParameterTree;
64 import com.sun.source.tree.UnaryTree;
65 import com.sun.source.tree.VariableTree;
66 import com.sun.source.tree.WhileLoopTree;
67 import com.sun.source.tree.WildcardTree;
68 import com.sun.source.util.TreePath;
69 import com.sun.source.util.TreePathScanner;
70 import java.awt.Color JavaDoc;
71 import java.util.ArrayList JavaDoc;
72 import java.util.Collections JavaDoc;
73 import java.util.List JavaDoc;
74 import javax.lang.model.element.Element;
75 import javax.lang.model.type.TypeMirror;
76 import org.netbeans.api.java.source.CompilationInfo;
77 import org.netbeans.editor.Coloring;
78 import org.netbeans.modules.editor.highlights.spi.Highlight;
79 import org.openide.nodes.AbstractNode;
80 import org.openide.nodes.Children;
81 import org.openide.nodes.Node;
82 import org.openide.util.NbBundle;
83
84 /**
85  *
86  * @author Jan Lahoda
87  */

88 public class TreeNode extends AbstractNode implements Highlight {
89     
90     static final Coloring HIGHLIGHT = new Coloring(null, null, new Color JavaDoc(224, 224, 224));
91
92     private TreePath tree;
93     private CompilationInfo info;
94     private boolean synthetic;
95     
96     public static Node getTree(CompilationInfo info, TreePath tree) {
97         List JavaDoc<Node> result = new ArrayList JavaDoc<Node>();
98         
99         new FindChildrenTreeVisitor(info).scan(tree, result);
100         
101         return result.get(0);
102     }
103
104     /** Creates a new instance of TreeNode */
105     public TreeNode(CompilationInfo info, TreePath tree, List JavaDoc<Node> nodes) {
106         super(nodes.isEmpty() ? Children.LEAF: new NodeChilren(nodes));
107         this.tree = tree;
108         this.info = info;
109         this.synthetic = info.getTreeUtilities().isSynthetic(tree);
110         setDisplayName(tree.getLeaf().getKind().toString() + ":" + tree.getLeaf().toString()); //NOI18N
111
setIconBaseWithExtension("org/netbeans/modules/java/debug/resources/tree.png"); //NOI18N
112
}
113
114     @Override JavaDoc
115     public String JavaDoc getHtmlDisplayName() {
116         if (synthetic) {
117             return "<html><font color='#808080'>" + translate(getDisplayName()); //NOI18N
118
}
119         
120         return null;
121     }
122             
123     private static String JavaDoc[] c = new String JavaDoc[] {"&", "<", ">", "\""}; // NOI18N
124
private static String JavaDoc[] tags = new String JavaDoc[] {"&amp;", "&lt;", "&gt;", "&quot;"}; // NOI18N
125

126     private String JavaDoc translate(String JavaDoc input) {
127         for (int cntr = 0; cntr < c.length; cntr++) {
128             input = input.replaceAll(c[cntr], tags[cntr]);
129         }
130         
131         return input;
132     }
133     
134     public int getStart() {
135         return (int)info.getTrees().getSourcePositions().getStartPosition(tree.getCompilationUnit(), tree.getLeaf());
136     }
137
138     public int getEnd() {
139         return (int)info.getTrees().getSourcePositions().getEndPosition(tree.getCompilationUnit(), tree.getLeaf());
140     }
141
142     public Coloring getColoring() {
143         return HIGHLIGHT;
144     }
145     
146     private static final class NodeChilren extends Children.Keys {
147         
148         public NodeChilren(List JavaDoc<Node> nodes) {
149             setKeys(nodes);
150         }
151         
152         protected Node[] createNodes(Object JavaDoc key) {
153             return new Node[] {(Node) key};
154         }
155         
156     }
157     
158     private static class FindChildrenTreeVisitor extends TreePathScanner<Void JavaDoc, List JavaDoc<Node>> {
159         
160         private CompilationInfo info;
161         
162         public FindChildrenTreeVisitor(CompilationInfo info) {
163             this.info = info;
164         }
165         
166         @Override JavaDoc
167         public Void JavaDoc visitAnnotation(AnnotationTree tree, List JavaDoc<Node> d) {
168             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
169             
170             //???
171
addCorrespondingElement(below);
172             addCorrespondingType(below);
173             addCorrespondingComments(below);
174             
175             super.visitAnnotation(tree, below);
176             
177             d.add(new TreeNode(info, getCurrentPath(), below));
178             return null;
179         }
180
181         @Override JavaDoc
182         public Void JavaDoc visitMethodInvocation(MethodInvocationTree tree, List JavaDoc<Node> d) {
183             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
184             
185             addCorrespondingElement(below);
186             addCorrespondingType(below);
187             addCorrespondingComments(below);
188             
189             super.visitMethodInvocation(tree, below);
190             
191             d.add(new TreeNode(info, getCurrentPath(), below));
192             return null;
193         }
194
195         @Override JavaDoc
196         public Void JavaDoc visitAssert(AssertTree tree, List JavaDoc<Node> d) {
197             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
198             
199             addCorrespondingType(below);
200             addCorrespondingComments(below);
201             super.visitAssert(tree, below);
202             
203             d.add(new TreeNode(info, getCurrentPath(), below));
204             return null;
205         }
206
207         @Override JavaDoc
208         public Void JavaDoc visitAssignment(AssignmentTree tree, List JavaDoc<Node> d) {
209             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
210             
211             addCorrespondingType(below);
212             addCorrespondingComments(below);
213             super.visitAssignment(tree, below);
214             
215             d.add(new TreeNode(info, getCurrentPath(), below));
216             return null;
217         }
218
219         @Override JavaDoc
220         public Void JavaDoc visitCompoundAssignment(CompoundAssignmentTree tree, List JavaDoc<Node> d) {
221             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
222             
223             addCorrespondingType(below);
224             addCorrespondingComments(below);
225             super.visitCompoundAssignment(tree, below);
226             
227             d.add(new TreeNode(info, getCurrentPath(), below));
228             return null;
229         }
230
231         @Override JavaDoc
232         public Void JavaDoc visitBinary(BinaryTree tree, List JavaDoc<Node> d) {
233             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
234             
235             addCorrespondingType(below);
236             addCorrespondingComments(below);
237             super.visitBinary(tree, below);
238             
239             d.add(new TreeNode(info, getCurrentPath(), below));
240             return null;
241         }
242
243         @Override JavaDoc
244         public Void JavaDoc visitBlock(BlockTree tree, List JavaDoc<Node> d) {
245             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
246             
247             addCorrespondingType(below);
248             addCorrespondingComments(below);
249             super.visitBlock(tree, below);
250             
251             d.add(new TreeNode(info, getCurrentPath(), below));
252             return null;
253         }
254
255         @Override JavaDoc
256         public Void JavaDoc visitBreak(BreakTree tree, List JavaDoc<Node> d) {
257             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
258             
259             addCorrespondingType(below);
260             addCorrespondingComments(below);
261             super.visitBreak(tree, below);
262             
263             d.add(new TreeNode(info, getCurrentPath(), below));
264             return null;
265         }
266
267         @Override JavaDoc
268         public Void JavaDoc visitCase(CaseTree tree, List JavaDoc<Node> d) {
269             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
270             
271             addCorrespondingType(below);
272             addCorrespondingComments(below);
273             super.visitCase(tree, below);
274             
275             d.add(new TreeNode(info, getCurrentPath(), below));
276             return null;
277         }
278
279         @Override JavaDoc
280         public Void JavaDoc visitCatch(CatchTree tree, List JavaDoc<Node> d) {
281             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
282             
283             addCorrespondingType(below);
284             addCorrespondingComments(below);
285             super.visitCatch(tree, below);
286             
287             d.add(new TreeNode(info, getCurrentPath(), below));
288             return null;
289         }
290
291         @Override JavaDoc
292         public Void JavaDoc visitClass(ClassTree tree, List JavaDoc<Node> d) {
293             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
294             
295             addCorrespondingElement(below);
296             addCorrespondingType(below);
297             addCorrespondingComments(below);
298             
299             super.visitClass(tree, below);
300             
301             d.add(new TreeNode(info, getCurrentPath(), below));
302             return null;
303         }
304
305         @Override JavaDoc
306         public Void JavaDoc visitConditionalExpression(ConditionalExpressionTree tree, List JavaDoc<Node> d) {
307             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
308             
309             addCorrespondingType(below);
310             addCorrespondingComments(below);
311             super.visitConditionalExpression(tree, below);
312             
313             d.add(new TreeNode(info, getCurrentPath(), below));
314             return null;
315         }
316
317         @Override JavaDoc
318         public Void JavaDoc visitContinue(ContinueTree tree, List JavaDoc<Node> d) {
319             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
320             
321             addCorrespondingType(below);
322             addCorrespondingComments(below);
323             super.visitContinue(tree, below);
324             
325             d.add(new TreeNode(info, getCurrentPath(), below));
326             return null;
327         }
328
329         @Override JavaDoc
330         public Void JavaDoc visitDoWhileLoop(DoWhileLoopTree tree, List JavaDoc<Node> d) {
331             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
332             
333             addCorrespondingType(below);
334             addCorrespondingComments(below);
335             super.visitDoWhileLoop(tree, below);
336             
337             d.add(new TreeNode(info, getCurrentPath(), below));
338             return null;
339         }
340
341         @Override JavaDoc
342         public Void JavaDoc visitErroneous(ErroneousTree tree, List JavaDoc<Node> d) {
343             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
344             
345             addCorrespondingType(below);
346             addCorrespondingComments(below);
347             scan(((com.sun.tools.javac.tree.JCTree.JCErroneous)tree).errs, below);
348             
349             d.add(new TreeNode(info, getCurrentPath(), below));
350             return null;
351         }
352
353         @Override JavaDoc
354         public Void JavaDoc visitExpressionStatement(ExpressionStatementTree tree, List JavaDoc<Node> d) {
355             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
356             
357             addCorrespondingType(below);
358             addCorrespondingComments(below);
359             super.visitExpressionStatement(tree, below);
360             
361             d.add(new TreeNode(info, getCurrentPath(), below));
362             return null;
363         }
364
365         @Override JavaDoc
366         public Void JavaDoc visitEnhancedForLoop(EnhancedForLoopTree tree, List JavaDoc<Node> d) {
367             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
368             
369             addCorrespondingType(below);
370             addCorrespondingComments(below);
371             super.visitEnhancedForLoop(tree, below);
372             
373             d.add(new TreeNode(info, getCurrentPath(), below));
374             return null;
375         }
376
377         @Override JavaDoc
378         public Void JavaDoc visitForLoop(ForLoopTree tree, List JavaDoc<Node> d) {
379             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
380             
381             addCorrespondingType(below);
382             addCorrespondingComments(below);
383             super.visitForLoop(tree, below);
384             
385             d.add(new TreeNode(info, getCurrentPath(), below));
386             return null;
387         }
388
389         @Override JavaDoc
390         public Void JavaDoc visitIdentifier(IdentifierTree tree, List JavaDoc<Node> d) {
391             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
392             
393             addCorrespondingElement(below);
394             addCorrespondingType(below);
395             addCorrespondingComments(below);
396             
397             super.visitIdentifier(tree, below);
398             
399             d.add(new TreeNode(info, getCurrentPath(), below));
400             return null;
401         }
402
403         @Override JavaDoc
404         public Void JavaDoc visitIf(IfTree tree, List JavaDoc<Node> d) {
405             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
406             
407             addCorrespondingType(below);
408             addCorrespondingComments(below);
409             super.visitIf(tree, below);
410             
411             d.add(new TreeNode(info, getCurrentPath(), below));
412             return null;
413         }
414
415         @Override JavaDoc
416         public Void JavaDoc visitImport(ImportTree tree, List JavaDoc<Node> d) {
417             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
418             
419             addCorrespondingType(below);
420             addCorrespondingComments(below);
421             super.visitImport(tree, below);
422             
423             d.add(new TreeNode(info, getCurrentPath(), below));
424             return null;
425         }
426
427         @Override JavaDoc
428         public Void JavaDoc visitArrayAccess(ArrayAccessTree tree, List JavaDoc<Node> d) {
429             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
430             
431             addCorrespondingType(below);
432             addCorrespondingComments(below);
433             super.visitArrayAccess(tree, below);
434             
435             d.add(new TreeNode(info, getCurrentPath(), below));
436             return null;
437         }
438
439         @Override JavaDoc
440         public Void JavaDoc visitLabeledStatement(LabeledStatementTree tree, List JavaDoc<Node> d) {
441             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
442             
443             addCorrespondingType(below);
444             addCorrespondingComments(below);
445             super.visitLabeledStatement(tree, below);
446             
447             d.add(new TreeNode(info, getCurrentPath(), below));
448             return null;
449         }
450
451         @Override JavaDoc
452         public Void JavaDoc visitLiteral(LiteralTree tree, List JavaDoc<Node> d) {
453             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
454             
455             addCorrespondingType(below);
456             addCorrespondingComments(below);
457             super.visitLiteral(tree, below);
458             
459             d.add(new TreeNode(info, getCurrentPath(), below));
460             return null;
461         }
462
463         @Override JavaDoc
464         public Void JavaDoc visitMethod(MethodTree tree, List JavaDoc<Node> d) {
465             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
466             
467             addCorrespondingElement(below);
468             addCorrespondingType(below);
469             addCorrespondingComments(below);
470             
471             super.visitMethod(tree, below);
472             
473             d.add(new TreeNode(info, getCurrentPath(), below));
474             return null;
475         }
476
477         @Override JavaDoc
478         public Void JavaDoc visitModifiers(ModifiersTree tree, List JavaDoc<Node> d) {
479             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
480             
481             addCorrespondingType(below);
482             addCorrespondingComments(below);
483             super.visitModifiers(tree, below);
484             
485             d.add(new TreeNode(info, getCurrentPath(), below));
486             return null;
487         }
488
489         @Override JavaDoc
490         public Void JavaDoc visitNewArray(NewArrayTree tree, List JavaDoc<Node> d) {
491             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
492             
493             addCorrespondingElement(below);
494             addCorrespondingType(below);
495             addCorrespondingComments(below);
496             
497             super.visitNewArray(tree, below);
498             
499             d.add(new TreeNode(info, getCurrentPath(), below));
500             return null;
501         }
502
503         @Override JavaDoc
504         public Void JavaDoc visitNewClass(NewClassTree tree, List JavaDoc<Node> d) {
505             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
506             
507             addCorrespondingElement(below);
508             addCorrespondingType(below);
509             addCorrespondingComments(below);
510             
511             super.visitNewClass(tree, below);
512             
513             d.add(new TreeNode(info, getCurrentPath(), below));
514             return null;
515         }
516
517         @Override JavaDoc
518         public Void JavaDoc visitParenthesized(ParenthesizedTree tree, List JavaDoc<Node> d) {
519             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
520             
521             addCorrespondingType(below);
522             addCorrespondingComments(below);
523             super.visitParenthesized(tree, below);
524             
525             d.add(new TreeNode(info, getCurrentPath(), below));
526             return null;
527         }
528
529         @Override JavaDoc
530         public Void JavaDoc visitReturn(ReturnTree tree, List JavaDoc<Node> d) {
531             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
532             
533             addCorrespondingType(below);
534             addCorrespondingComments(below);
535             super.visitReturn(tree, below);
536             
537             d.add(new TreeNode(info, getCurrentPath(), below));
538             return null;
539         }
540
541         @Override JavaDoc
542         public Void JavaDoc visitMemberSelect(MemberSelectTree tree, List JavaDoc<Node> d) {
543             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
544             
545             addCorrespondingElement(below);
546             addCorrespondingType(below);
547             addCorrespondingComments(below);
548             
549             super.visitMemberSelect(tree, below);
550             
551             d.add(new TreeNode(info, getCurrentPath(), below));
552             return null;
553         }
554
555         @Override JavaDoc
556         public Void JavaDoc visitEmptyStatement(EmptyStatementTree tree, List JavaDoc<Node> d) {
557             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
558             
559             addCorrespondingType(below);
560             addCorrespondingComments(below);
561             super.visitEmptyStatement(tree, below);
562             
563             d.add(new TreeNode(info, getCurrentPath(), below));
564             return null;
565         }
566
567         @Override JavaDoc
568         public Void JavaDoc visitSwitch(SwitchTree tree, List JavaDoc<Node> d) {
569             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
570             
571             addCorrespondingType(below);
572             addCorrespondingComments(below);
573             super.visitSwitch(tree, below);
574             
575             d.add(new TreeNode(info, getCurrentPath(), below));
576             return null;
577         }
578
579         @Override JavaDoc
580         public Void JavaDoc visitSynchronized(SynchronizedTree tree, List JavaDoc<Node> d) {
581             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
582             
583             addCorrespondingType(below);
584             addCorrespondingComments(below);
585             super.visitSynchronized(tree, below);
586             
587             d.add(new TreeNode(info, getCurrentPath(), below));
588             return null;
589         }
590
591         @Override JavaDoc
592         public Void JavaDoc visitThrow(ThrowTree tree, List JavaDoc<Node> d) {
593             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
594             
595             addCorrespondingType(below);
596             addCorrespondingComments(below);
597             super.visitThrow(tree, below);
598             
599             d.add(new TreeNode(info, getCurrentPath(), below));
600             return null;
601         }
602
603         @Override JavaDoc
604         public Void JavaDoc visitCompilationUnit(CompilationUnitTree tree, List JavaDoc<Node> d) {
605             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
606             
607             addCorrespondingElement(below);
608             addCorrespondingType(below);
609             addCorrespondingComments(below);
610             
611             super.visitCompilationUnit(tree, below);
612             
613             d.add(new TreeNode(info, getCurrentPath(), below));
614             return null;
615         }
616
617         @Override JavaDoc
618         public Void JavaDoc visitTry(TryTree tree, List JavaDoc<Node> d) {
619             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
620             
621             addCorrespondingType(below);
622             addCorrespondingComments(below);
623             super.visitTry(tree, below);
624             
625             d.add(new TreeNode(info, getCurrentPath(), below));
626             return null;
627         }
628
629         @Override JavaDoc
630         public Void JavaDoc visitParameterizedType(ParameterizedTypeTree tree, List JavaDoc<Node> d) {
631             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
632             
633             addCorrespondingElement(below);
634             addCorrespondingType(below);
635             addCorrespondingComments(below);
636             
637             super.visitParameterizedType(tree, below);
638             
639             d.add(new TreeNode(info, getCurrentPath(), below));
640             return null;
641         }
642
643         @Override JavaDoc
644         public Void JavaDoc visitArrayType(ArrayTypeTree tree, List JavaDoc<Node> d) {
645             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
646             
647             addCorrespondingElement(below);
648             addCorrespondingType(below);
649             addCorrespondingComments(below);
650             
651             super.visitArrayType(tree, below);
652             
653             d.add(new TreeNode(info, getCurrentPath(), below));
654             return null;
655         }
656
657         @Override JavaDoc
658         public Void JavaDoc visitTypeCast(TypeCastTree tree, List JavaDoc<Node> d) {
659             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
660             
661             addCorrespondingType(below);
662             addCorrespondingComments(below);
663             super.visitTypeCast(tree, below);
664             
665             d.add(new TreeNode(info, getCurrentPath(), below));
666             return null;
667         }
668
669         @Override JavaDoc
670         public Void JavaDoc visitPrimitiveType(PrimitiveTypeTree tree, List JavaDoc<Node> d) {
671             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
672             
673             addCorrespondingType(below);
674             addCorrespondingComments(below);
675             super.visitPrimitiveType(tree, below);
676             
677             d.add(new TreeNode(info, getCurrentPath(), below));
678             return null;
679         }
680
681         @Override JavaDoc
682         public Void JavaDoc visitTypeParameter(TypeParameterTree tree, List JavaDoc<Node> d) {
683             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
684             
685             addCorrespondingElement(below);
686             addCorrespondingType(below);
687             addCorrespondingComments(below);
688             
689             super.visitTypeParameter(tree, below);
690             
691             d.add(new TreeNode(info, getCurrentPath(), below));
692             return null;
693         }
694
695         @Override JavaDoc
696         public Void JavaDoc visitInstanceOf(InstanceOfTree tree, List JavaDoc<Node> d) {
697             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
698             
699             addCorrespondingType(below);
700             addCorrespondingComments(below);
701             super.visitInstanceOf(tree, below);
702             
703             d.add(new TreeNode(info, getCurrentPath(), below));
704             return null;
705         }
706
707         @Override JavaDoc
708         public Void JavaDoc visitUnary(UnaryTree tree, List JavaDoc<Node> d) {
709             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
710             
711             addCorrespondingType(below);
712             addCorrespondingComments(below);
713             super.visitUnary(tree, below);
714             
715             d.add(new TreeNode(info, getCurrentPath(), below));
716             return null;
717         }
718
719         @Override JavaDoc
720         public Void JavaDoc visitVariable(VariableTree tree, List JavaDoc<Node> d) {
721             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
722             
723             addCorrespondingElement(below);
724             addCorrespondingType(below);
725             addCorrespondingComments(below);
726             
727             super.visitVariable(tree, below);
728             
729             d.add(new TreeNode(info, getCurrentPath(), below));
730             return null;
731         }
732
733         @Override JavaDoc
734         public Void JavaDoc visitWhileLoop(WhileLoopTree tree, List JavaDoc<Node> d) {
735             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
736             
737             addCorrespondingType(below);
738             addCorrespondingComments(below);
739             super.visitWhileLoop(tree, below);
740             
741             d.add(new TreeNode(info, getCurrentPath(), below));
742             return null;
743         }
744
745         @Override JavaDoc
746         public Void JavaDoc visitWildcard(WildcardTree tree, List JavaDoc<Node> d) {
747             List JavaDoc<Node> below = new ArrayList JavaDoc<Node>();
748             
749             addCorrespondingType(below);
750             addCorrespondingComments(below);
751             super.visitWildcard(tree, below);
752             
753             d.add(new TreeNode(info, getCurrentPath(), below));
754             return null;
755         }
756         
757         private void addCorrespondingElement(List JavaDoc<Node> below) {
758             Element el = info.getTrees().getElement(getCurrentPath());
759             
760             if (el != null) {
761                 below.add(new ElementNode(info, el, Collections.EMPTY_LIST));
762             } else {
763                 below.add(new NotFoundElementNode(NbBundle.getMessage(TreeNode.class, "Cannot_Resolve_Element")));
764             }
765         }
766
767         private void addCorrespondingType(List JavaDoc<Node> below) {
768             TypeMirror tm = info.getTrees().getTypeMirror(getCurrentPath());
769             
770             if (tm != null) {
771                 below.add(new TypeNode(tm));
772             } else {
773                 below.add(new NotFoundTypeNode(NbBundle.getMessage(TreeNode.class, "Cannot_Resolve_Type")));
774             }
775         }
776         
777         private void addCorrespondingComments(List JavaDoc<Node> below) {
778             below.add(new CommentsNode(NbBundle.getMessage(TreeNode.class, "NM_Preceding_Comments"), info.getTreeUtilities().getComments(getCurrentPath().getLeaf(), true)));
779             below.add(new CommentsNode(NbBundle.getMessage(TreeNode.class, "NM_Trailing_Comments"), info.getTreeUtilities().getComments(getCurrentPath().getLeaf(), false)));
780         }
781     }
782     
783     private static class NotFoundElementNode extends AbstractNode {
784         
785         public NotFoundElementNode(String JavaDoc name) {
786             super(Children.LEAF);
787             setName(name);
788             setDisplayName(name);
789             setIconBaseWithExtension("org/netbeans/modules/java/debug/resources/element.png"); //NOI18N
790
}
791         
792     }
793     
794     private static class TypeNode extends AbstractNode {
795         
796         public TypeNode(TypeMirror type) {
797             super(Children.LEAF);
798             setDisplayName(type.getKind().toString() + ":" + type.toString()); //NOI18N
799
setIconBaseWithExtension("org/netbeans/modules/java/debug/resources/type.png"); //NOI18N
800
}
801         
802     }
803     
804     private static class NotFoundTypeNode extends AbstractNode {
805         
806         public NotFoundTypeNode(String JavaDoc name) {
807             super(Children.LEAF);
808             setName(name);
809             setDisplayName(name);
810             setIconBaseWithExtension("org/netbeans/modules/java/debug/resources/type.png"); //NOI18N
811
}
812         
813     }
814 }
815
Popular Tags