KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > tools > ajdoc > FilteredDecList


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

22 package org.aspectj.tools.ajdoc;
23
24 import org.aspectj.compiler.base.ast.ConstructorDec;
25 import org.aspectj.compiler.base.ast.Dec;
26 import org.aspectj.compiler.base.ast.FieldDec;
27 import org.aspectj.compiler.base.ast.MethodDec;
28 import org.aspectj.compiler.base.ast.Type;
29 import org.aspectj.compiler.base.ast.TypeDec;
30 import org.aspectj.compiler.crosscuts.ast.PointcutDec;
31
32 import java.util.ArrayList JavaDoc;
33
34 /**
35 * Factory collection with Type-specific "add" methods which
36 * checks if ..Dec should be included and if so constructs and adds.
37 * A Dec should be included if AccessChecker.canAccess({Dec variants})
38 * and the type is the same (if type is specified).
39 * This consolidates construction of DocImpl for classes and class members.
40 */

41 public class FilteredDecList extends ArrayList JavaDoc {
42     final protected AccessChecker filter ;
43     final protected ClassDocImpl classDocImpl ;
44     final protected Type declaringType ;
45
46     /**
47      * Create a declaration list enforced by a filter and
48      * optionally a ClassDocImpl. If the ClassDocImpl is not null,
49      * then you cannot add members outside its type; if it is null,
50      * attempting to add members has undefined results. (You may
51      * still create ClassDoc.)
52      * @param filter the AccessChecker used to test for inclusion
53      * (use AccessChecker.PUBLIC if null)
54      * @param type the classDocImpl used to construct added members
55      * and ensure they are declared in this type
56      * (ignore test if null)
57      */

58     FilteredDecList(AccessChecker filter, ClassDocImpl classDocImpl) {
59         this.filter = (null != filter ? filter
60                        : AccessChecker.PUBLIC);
61         this.classDocImpl = classDocImpl;
62         TypeDec td = (null == classDocImpl? null
63                               : classDocImpl.typeDec());
64         this.declaringType = (null == td? null : td.getType());
65     }
66
67     /**
68      * Check for match with our type (if set)
69      * @param dec the Dec to get the incoming declaring type from
70      * @return true unless our type is set and does not equals dec declaring type
71      */

72     protected final boolean sameType(Dec dec) {
73         Type other = (null == dec ? null : dec.getDeclaringType());
74         boolean result = ((null != dec)
75                           && ((declaringType == null)
76                               || declaringType.equals(other))) ;
77         /*
78           System.err.println("sameType("+dec+") " + declaringType
79           + " ?= " + other);
80           if (!result) {
81           System.err.println("false FilteredDecList.sameType(" + dec
82           + ") us " + declaringType);
83           }
84         */

85         return result;
86     }
87
88     /**
89      * Implements policy on incoming TypeDec.
90      * @param dec the TypeDec to check
91      * @throws IllegalArgumentException if null == dec
92      */

93     protected void checkDec(Dec dec) {
94         if (null == dec) throw new IllegalArgumentException JavaDoc("null dec");
95     }
96
97     /**
98      * Construct and add inner class from dec
99      * if outer is included and dec should be included.
100      * @param outer the ClassDocImpl which encloses this dec
101      * @param dec the TypeDec for the inner class to add to this list, enclosed by outer
102      * @return false if dec is null or true if added
103      * @throws IllegalArgumentException if outer is null or dec is null
104      */

105     public boolean add(ClassDocImpl outer, TypeDec dec) {
106         checkDec(dec);
107         if (null == outer) throw new IllegalArgumentException JavaDoc("null outer");
108         if ((filter.canAccess(outer.typeDec()) && filter.canAccess(dec))) {
109             ClassDocImpl doc = ClassDocImpl.getInstance(outer, dec);
110             if (null != doc) {
111                 doc.setIncluded(true);
112                 return add((Object JavaDoc) doc);
113             }
114         }
115         denied(outer, dec);
116         return false;
117     }
118             
119     /**
120      * Add ClassDocImpl if dec should be included
121      * and ClassDocImpl.getInstance(..) returns something.
122      * Also sets the included property to true;
123      * @param dec the TypeDec for the class to add
124      * @return false if dec is null or true if added
125      * @throws IllegalArgumentException if outer is null or dec is null
126      */

127     public boolean add(TypeDec dec) {
128         checkDec(dec);
129         if (filter.canAccess(dec)) {
130             ClassDocImpl doc = ClassDocImpl.getInstance(dec);
131             if (null != doc) {
132                 doc.setIncluded(true);
133                 return add((Object JavaDoc) doc);
134             }
135         }
136         denied(dec);
137         return false;
138     }
139
140     /**
141      * Add MethodDocImpl to this list if dec should be included
142      * @param dec the MethodDoc for the method to add
143      * @return true if added
144      * @throws IllegalArgumentException if dec is null
145      */

146     public boolean add(MethodDec dec) {
147         checkDec(dec);
148         if (sameType(dec) && filter.canAccess(dec)) {
149             return add((Object JavaDoc) new MethodDocImpl(classDocImpl, dec));
150         }
151         denied(dec);
152         return false;
153     }
154
155     /**
156      * Add ConstructorDocImpl to this list if dec should be included
157      * @param dec the ConstructorDoc for the constructor to add
158      * @return true if added
159      * @throws IllegalArgumentException if dec is null
160      */

161     public boolean add(ConstructorDec dec) {
162         checkDec(dec);
163         if (sameType(dec) && filter.canAccess(dec)) {
164             return add((Object JavaDoc) new ConstructorDocImpl(classDocImpl, dec));
165         }
166         denied(dec);
167         return false;
168     }
169
170     /**
171      * Add FieldDocImpl to this list if dec should be included
172      * @param dec the FieldDoc for the field to add
173      * @return true if added
174      * @throws IllegalArgumentException if dec is null
175      */

176     public boolean add(FieldDec dec) {
177         checkDec(dec);
178         if (sameType(dec) && filter.canAccess(dec)) {
179             return add((Object JavaDoc) new FieldDocImpl(classDocImpl, dec));
180         }
181         denied(dec);
182         return false;
183     }
184
185     /**
186      * Add PointcutDocImpl to this list if dec should be included
187      * @param dec the PointcutDoc for the pointcut to add
188      * @return true if added
189      * @throws IllegalArgumentException if dec is null
190      */

191     public boolean add(PointcutDec dec) {
192         checkDec(dec);
193         if (sameType(dec) && filter.canAccess(dec)) {
194             return add((Object JavaDoc) new PointcutDocImpl(classDocImpl, dec));
195         }
196         denied(dec);
197         return false;
198     }
199
200     /**
201      * Called when some dec and outer is denied addition.
202      * Currently does nothing.
203      * @param outer the ClassDocImpl which encloses this dec
204      * @param dec the TypeDec for the inner class to add to this list, enclosed by outer
205      */

206     protected void denied(ClassDocImpl outer, TypeDec dec) {
207         // System.err.println(this + " denied " + o + " with " + p);
208
}
209
210     /**
211      * signalled when some dec is denied addition.
212      * Currently does nothing.
213      * @param dec the Dec denied addition
214      */

215     protected void denied(Dec dec) {
216         // System.err.println(this + " denied " + o);
217
}
218 } // class FilteredDecList
219

220
Popular Tags