KickJava   Java API By Example, From Geeks To Geeks.

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


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.ajdoc.ClassDoc;
25 import org.aspectj.ajdoc.IntroducedDoc;
26 import org.aspectj.ajdoc.MemberDoc;
27 import org.aspectj.compiler.base.ast.ConstructorDec;
28 import org.aspectj.compiler.base.ast.Dec;
29 import org.aspectj.compiler.base.ast.FieldDec;
30 import org.aspectj.compiler.base.ast.MethodDec;
31 import org.aspectj.compiler.base.ast.TypeDec;
32 import org.aspectj.compiler.crosscuts.ast.GenTypeName;
33 import org.aspectj.compiler.crosscuts.ast.IntroducedDec;
34
35 import java.util.Iterator JavaDoc;
36 import java.util.Set JavaDoc;
37
38 public class IntroducedDocImpl extends IntroductionDocImpl implements IntroducedDoc {
39
40     /** The introduction to which we delegate. */
41     private final IntroducedDec introducedDec;
42
43     /** The member this introduction introduced. */
44     private final MemberDocImpl member;
45
46     public IntroducedDocImpl(com.sun.javadoc.ClassDoc containingClass,
47                              IntroducedDec introducedDec) {
48         super(containingClass);
49         this.introducedDec = introducedDec; // used by findMember
50
(member = findMember()).setIntroduced(this);
51         createTargets();
52     }
53
54     protected Dec dec() {
55         return introducedDec;
56     }
57
58     protected void createTargets() {
59         /*
60          * HACK:
61          * Because the compiler doesn't resolve the types
62          * of introductions, yet, we have to set the introduced
63          * doc (member) with the appropriate fields, whether it's a
64          * - field
65          * - method
66          * - constructor
67          */

68         Set JavaDoc affects = ajc().getCorrespondences().getAffects(introducedDec);
69         if (affects.size() < 1) return;
70     nextType:
71         for (Iterator JavaDoc it = affects.iterator(); it.hasNext();) {
72             Object JavaDoc o = it.next();
73             if (o instanceof TypeDec) {
74                 TypeDec owner = (TypeDec)o;
75                 ClassDoc cd = ClassDocImpl.getInstance(owner);
76                 com.sun.javadoc.FieldDoc[] fs = cd.fields();
77                 for (int i = 0; i < fs.length; i++) {
78                     if (member.weakEquals(fs[i])) { // XXX weakEquals is unimplemented
79
((FieldDocImpl)fs[i]).setIntroduced(this);
80                         addTarget(cd);
81                         ((FieldDocImpl)member).setType(((FieldDocImpl)fs[i]).
82                                                        fieldDec().getType());
83                         // why fixup only fields?
84
continue nextType;
85                     }
86                 }
87                 com.sun.javadoc.MethodDoc[] ms = cd.methods();
88                 for (int i = 0; i < ms.length; i++) {
89                     if (member.weakEquals(ms[i])) {
90                         ((MethodDocImpl)ms[i]).setIntroduced(this);
91                         addTarget(cd);
92                         ((MethodDocImpl)member).setType(((MethodDocImpl)ms[i]).
93                                                         codeDec().getResultTypeD().
94                                                         getType());
95                         ((ExecutableMemberDocImpl)member).
96                             makeParameters(((MethodDocImpl)ms[i]).
97                                            codeDec().getFormals());
98                         continue nextType;
99                     }
100                 }
101                 com.sun.javadoc.ConstructorDoc[] cs = cd.constructors();
102                 for (int i = 0; i < cs.length; i++) {
103                     if (member.weakEquals(cs[i])) {
104                         ((ConstructorDocImpl)cs[i]).setIntroduced(this);
105                         addTarget(cd);
106                         ((ExecutableMemberDocImpl)member).
107                             makeParameters(((ConstructorDocImpl)cs[i]).
108                                            codeDec().getFormals());
109                         continue nextType;
110                     }
111                 }
112             }
113         }
114     }
115
116     public MemberDoc member() {
117         return member;
118     }
119
120     /**
121      * Returns the name of the member introduction.
122      *
123      * @return the name.
124      */

125     public String JavaDoc name() { // XXX unused?
126
Dec indec = introducedDec.getDec();
127         if (indec != null) {
128             return "" + indec.getId(); // XXX
129
} else {
130             return "";
131         }
132     }
133     
134     private MemberDocImpl findMember() {
135         Dec dec = introducedDec.getDec();
136         // fix applied all, though bug was only in methods and constructors
137
// verified working in all, including fields
138
dec.setSourceLocation(introducedDec.getSourceLocation()); // PR790, 712
139
//TODO: a little hacky now
140
if (dec instanceof FieldDec) {
141             return new FieldDocImpl(containingClass(),
142                                       (FieldDec)dec);
143
144         } else if (dec instanceof ConstructorDec) {
145             return new ConstructorDocImpl(containingClass(),
146                                           (ConstructorDec)dec);
147         } else if (dec instanceof MethodDec) {
148             return new MethodDocImpl(containingClass(),
149                                      (MethodDec)dec);
150         } else {
151             return null;
152         }
153         // should print type pattern for type of introduced member,
154
// but it messes up source/target associations
155
// GenTypeName gtn = introducedDec.getTargets();
156
// if (null != gtn) {
157
// name = gtn.toShortString() + name;
158
// }
159
}
160  
161      /**
162       * Returns the toString() of the member.
163       *
164       * @return the toString() of the member.
165       */

166      public String JavaDoc toString() {
167          return member.toString();
168      }
169 }
170
Popular Tags