KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > java > source > query > Finder


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.java.source.query;
21
22 import org.netbeans.api.java.source.query.SearchEntry;
23 import org.netbeans.api.java.source.query.Query;
24 import org.netbeans.api.java.source.query.SearchResult;
25
26 import com.sun.source.tree.Tree;
27 import javax.lang.model.element.Element;
28
29 /**
30  * Tree node scanner that generates a SearchResult.
31  */

32 public class Finder extends NodeScanner<Void JavaDoc,Object JavaDoc> {
33     private SearchResult results;
34
35     public SearchResult find(Tree root) {
36         if (model == null)
37             attach(env);
38         results.clear();
39     if(root!=null) root.accept(this, null);
40     return results;
41     }
42     
43     public Finder(String JavaDoc title, Query owner) {
44         env = owner.getEnvironment();
45         results = new SearchResult(null, title);
46         results.attach(env);
47     }
48     
49     protected final void add(Tree t) {
50         add(t, null, 0);
51     }
52     
53     protected final void add(Tree t, String JavaDoc msg) {
54     add(t, msg, 0);
55     }
56     
57     protected final void add(Tree t, String JavaDoc msg, int flags) {
58     add(currentSym, t, msg, flags);
59     }
60     
61     protected final void add(Element e, Tree t, String JavaDoc msg, int flags) {
62     results.add(new SearchEntry(null, e, t, model.getPos(t), msg, flags));
63     }
64 }
65
Popular Tags