KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > ui > StructureSearchManager


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

25  
26 package org.aspectj.ajde.ui;
27
28 import java.util.*;
29 import org.aspectj.ajde.*;
30 import org.aspectj.ajde.ui.internal.*;
31 import org.aspectj.asm.*;
32 import org.aspectj.asm.associations.*;
33
34 /**
35  * @author Mik Kersten
36  */

37 public class StructureSearchManager {
38
39     /**
40      * @param pattern case-sensitive substring of node name
41      *
42      * @return null if a corresponding node was not found
43      */

44     public List findMatches(
45         String JavaDoc pattern,
46         ProgramElementNode.Kind kind) {
47         
48         List matches = new ArrayList();
49         StructureModel model = Ajde.getDefault().getStructureModelManager().getStructureModel();
50         if (model.equals(StructureModel.NO_STRUCTURE)) {
51             return null;
52         } else {
53             return findMatchesHelper((ProgramElementNode)model.getRoot(), pattern, kind, matches);
54         }
55     }
56     
57     
58     private List findMatchesHelper(
59         ProgramElementNode node,
60         String JavaDoc pattern,
61         ProgramElementNode.Kind kind,
62         List matches) {
63             
64         if (node != null && node.getName().indexOf(pattern) != -1) {
65             if (kind == null || node.getProgramElementKind().equals(kind)) {
66                 matches.add(node);
67             }
68         }
69         
70         for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
71             StructureNode nextNode = (StructureNode)it.next();
72             if (nextNode instanceof ProgramElementNode) {
73                 findMatchesHelper(
74                     (ProgramElementNode)nextNode,
75                     pattern,
76                     kind,
77                     matches);
78             }
79         }
80          
81         return matches;
82     }
83 }
Popular Tags