KickJava   Java API By Example, From Geeks To Geeks.

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


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.Dec;
25 import org.aspectj.compiler.base.ast.Modifiers;
26 import org.aspectj.compiler.base.ast.NameType;
27 import org.aspectj.compiler.base.ast.TypeDec;
28 import org.aspectj.compiler.crosscuts.AspectJCompiler;
29
30 import com.sun.javadoc.ClassDoc;
31 import com.sun.javadoc.PackageDoc;
32
33 import java.lang.reflect.Modifier JavaDoc;
34
35 public abstract class ProgramElementDocImpl
36     extends DocImpl
37     implements org.aspectj.ajdoc.ProgramElementDoc {
38
39     /** The containing ClassDoc. */
40     private final ClassDoc containingClass;
41     
42     /*
43      construction of ProgramElementDocImpl must not recursively
44      invoke construction of instances of subclass ClassDocImpl
45      or endless recursion will be possible
46     */

47     public ProgramElementDocImpl(ClassDoc containingClass) {
48         this.containingClass = containingClass;
49     }
50     
51     /**
52      * Returns the underlying Dec used for a number of methods.
53      *
54      * @return the underlying Dec used for a number of methods.
55      */

56     protected abstract Dec dec();
57
58     /**
59      * Returns the AspectJCompiler that this tree. Delegates
60      * to the underlying {@link #dec()}.
61      *
62      * @return the AspectJCompiler that compiled this tree.
63      */

64     protected final AspectJCompiler ajc() {
65         return (AspectJCompiler)dec().getCompiler();
66     }
67
68     /**
69      * Returns this's Comment.
70      *
71      * @return the Comment for this Doc.
72      */

73     public Comment getComment() {
74         if (super.getComment() == null) {
75             setComment(new Comment(this, dec().getFormalComment(), err()));
76         }
77         return super.getComment();
78     }
79    
80     /**
81      * Returns the nearest enclosing class. The returned value
82      * is <code>null</code> if this is a top-level entity.
83      *
84      * @return a ClassDoc representing the nearest
85      * enclosing class. This can be null for
86      * top-level entities.
87      */

88     public ClassDoc containingClass() {
89         return containingClass;
90     }
91
92     /**
93      * Returns the package in which this Dec was declared.
94      *
95      * @return a PackageDoc representing the package
96      * in which this Dec was declared.
97      */

98     public PackageDoc containingPackage() {
99         return PackageDocImpl.getPackageDoc(nonNullTypeDec());
100     }
101
102     /**
103      */

104     public TypeDec nonNullTypeDec() {
105         if (dec().getDeclaringType() == null) return null;
106         return ((NameType)dec().getDeclaringType()).getTypeDec();
107     }
108
109     /**
110      * An int form of this Dec's modifiers.
111      *
112      * @return an int form this Dec's modifiers.
113      * @see java.lang.reflect.Modifier
114      */

115     public int modifierSpecifier() {
116         return dec().getModifiers().getValue();
117     }
118     
119     /**
120      * Returns the modifiers as a String.
121      *
122      * @return a String representing to modifiers.
123      */

124     public String JavaDoc modifiers() {
125         return Modifier.toString(modifierSpecifier());
126     }
127
128     /**
129      * Returns <code>true</code> if this is <code>public</code>.
130      *
131      * @return <code>true</code> if this is <code>public</code>.
132      */

133     public boolean isPublic() {
134         return dec().isPublic();
135     }
136
137     /**
138      * Returns <code>true</code> if this is <code>protected</code>.
139      *
140      * @return <code>true</code> if this is <code>protected</code>.
141      */

142     public boolean isProtected() {
143         return dec().isProtected();
144     }
145
146     /**
147      * Returns <code>true</code> if this is <i>package private</i>.
148      *
149      * @return <code>true</code> if this is <i>package private</i>.
150      */

151     public boolean isPackagePrivate() {
152         Modifiers mods = dec().getModifiers();
153         // todo: consider creating Dec.isPackagePrivate()
154
// todo: consider NPE if mods null
155
return ((null != mods) && mods.isPackagePrivate());
156     }
157
158     /**
159      * Returns <code>true</code> if this is <code>private</code>.
160      *
161      * @return <code>true</code> if this is <code>private</code>.
162      */

163     public boolean isPrivate() {
164         return dec().isPrivate();
165     }
166
167     /**
168      * Returns <code>true</code> if this is <code>static</code>.
169      *
170      * @return <code>true</code> if this is <code>static</code>.
171      */

172     public boolean isStatic() {
173         return dec().isStatic();
174     }
175
176     /**
177      * Returns <code>true</code> if this is <code>final</code>.
178      *
179      * @return <code>true</code> if this is <code>final</code>.
180      */

181     public boolean isFinal() {
182         return dec().isFinal();
183     }
184
185     /**
186      * Returns the fully-qualified type name of this Dec (not member name).
187      *
188      * @return the fully-qualified name.
189      */

190     public String JavaDoc qualifiedName() {
191         return name();
192     }
193     
194     /**
195      * Returns the name -- e.g. ID.
196      *
197      * @return the name of the Dec.
198      */

199     public String JavaDoc name() {
200         return dec().getId();
201     }
202     
203 }
204
Popular Tags