KickJava   Java API By Example, From Geeks To Geeks.

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


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
25 import org.aspectj.ajdoc.AdviceDoc;
26 import org.aspectj.ajdoc.AspectDoc;
27 import org.aspectj.ajdoc.ClassDoc;
28 import org.aspectj.ajdoc.ExecutableMemberDoc;
29 import org.aspectj.compiler.base.ast.CodeDec;
30 import org.aspectj.compiler.base.ast.FormalDec;
31 import org.aspectj.compiler.base.ast.NameType;
32 import org.aspectj.compiler.base.ast.TypeDec;
33 import org.aspectj.compiler.crosscuts.ast.AdviceDec;
34 import org.aspectj.compiler.crosscuts.ast.AfterReturningAdviceDec;
35 import org.aspectj.compiler.crosscuts.ast.AfterThrowingAdviceDec;
36 import org.aspectj.compiler.crosscuts.ast.AroundAdviceDec;
37
38 import com.sun.javadoc.Type;
39
40 import java.util.ArrayList JavaDoc;
41 import java.util.Collection JavaDoc;
42 import java.util.Collections JavaDoc;
43 import java.util.Iterator JavaDoc;
44 import java.util.List JavaDoc;
45 import java.util.Set JavaDoc;
46
47 public class AdviceDocImpl extends CodeDocImpl implements AdviceDoc {
48
49     /** Crosscuts this advice affects. */
50     private final Collection JavaDoc crosscuts;
51
52     /**
53      * Constructrs an AdviceDoc with the containing ClassDoc
54      * and underlying AdviceDec.
55      *
56      * @param containingClass containing ClassDoc.
57      * @param adviceDec underlying AdviceDec.
58      */

59      public AdviceDocImpl(ClassDoc containingClass, AdviceDec adviceDec) {
60         super(containingClass, adviceDec);
61         crosscuts = createCrosscuts();
62     }
63
64     /**
65      * Returns the underlying Dec -- an AdviceDec.
66      *
67      * @return the underlying Dec -- an AdviceDec.
68      */

69     protected AdviceDec adviceDec() {
70         return (AdviceDec)codeDec();
71     }
72
73     /**
74      * Return the ExecutableMemberDocs this advice crosscuts.
75      *
76      * @return an array of ExecutableMemberDocs representing
77      * the members this advice crosscuts.
78      */

79     public com.sun.javadoc.ExecutableMemberDoc[] crosscuts() {
80         return (ExecutableMemberDoc[])crosscuts.toArray
81             (new ExecutableMemberDoc[crosscuts.size()]);
82     }
83
84     /**
85      * Returns <code>null</code>, because advice can't override
86      * other advice.
87      *
88      * @return <code>null</code>, because advice can't override
89      * other advice.
90      */

91     public AspectDoc overriddenAspect() {
92         return null;
93     }
94
95     /**
96      * Returns the return type of the advice -- it may be null.
97      *
98      * @return the return type of the advice -- it may be null.
99      */

100     public com.sun.javadoc.Type returnType() {
101         if (adviceDec() instanceof AroundAdviceDec) {
102             return TypeImpl.getInstance(adviceDec().getReturnType());
103         } else {
104             return null;
105         }
106     }
107
108     /**
109      * Returns <code>true</code>.
110      *
111      * @return <code>true</code>.
112      */

113     public boolean isAdvice() {
114         return true;
115     }
116
117     /**
118      * Returns <code>true</code> if this advice is <code>abstract</code>.
119      *
120      * @return <code>true</code> if this advice is <code>abstract</code>.
121      */

122     public boolean isAbstract() {
123         return adviceDec().isAbstract();
124     }
125
126     
127     /**
128      * Returns <code>true</code> if this is <code>throwing</code> advice.
129      *
130      * @return <code>true</code> if this is <code>throwing</code> advice.
131      */

132     public boolean isThrowing() {
133         return adviceDec() instanceof AfterThrowingAdviceDec;
134     }
135
136     /**
137      * Returns <code>true</code> if this is <code>returning</code> advice.
138      *
139      * @return <code>true</code> if this is <code>returning</code> advice.
140      */

141     public boolean isReturning() {
142         return adviceDec() instanceof AfterReturningAdviceDec;
143     }
144
145     /**
146      * Returns the extra formal type that's the optional type
147      * to <code>after returning</code> or <code>after throwing</code>
148      * advice.
149      *
150      * @return an instance of Type that represents the the extra formal type
151      * that's the optional type to <code>after returning</code> or
152      * <code>after throwing</code> advice.
153      */

154     public Type extraType() {
155         FormalDec fd = adviceDec().getExtraFormal();
156         if (fd != null) {
157             return TypeImpl.getInstance(fd.getType());
158         }
159         return null;
160     }
161
162
163     /**
164      * Returns a Collection of CodeDocImpl representing the
165      * crosscuts the underlying TypeDec declares.
166      *
167      * @return a Collection of CodeDocImpl representing the
168      * crosscuts the underlying TypeDec declares.
169      */

170     private Collection JavaDoc createCrosscuts() {
171         Set JavaDoc affects = ajc().getCorrespondences().getAffects(adviceDec());
172         if (affects.size() < 1) return Collections.EMPTY_LIST;
173         List JavaDoc list = new ArrayList JavaDoc();
174         for (Iterator JavaDoc i = affects.iterator(); i.hasNext();) {
175             Object JavaDoc o = i.next();
176             if (o instanceof CodeDec) {
177                 CodeDec cdec = (CodeDec)o;
178                 TypeDec owner = ((NameType)cdec.getDeclaringType()).getTypeDec();
179                 ClassDocImpl cd = ClassDocImpl.getInstance(owner);
180                 CodeDocImpl cdoc = cd.docForDec(cdec);
181                 if (cdoc != null) { // todo: silent introduced members
182
list.add(cdoc);
183                 }
184             }
185         }
186         return list;
187     }
188
189     /**
190      * Returns the simple name of this advice. Need to override
191      * this so we don't print afterThrowing or afterReturning.
192      *
193      * @return one of after, before, around.
194      */

195     public String JavaDoc name() {
196         if (isThrowing() || isReturning()) return "after";
197         return super.name();
198     }
199 }
200
Popular Tags