KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > crosscuts > joinpoints > CalleeSideCallJp


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler 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  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.crosscuts.joinpoints;
26
27 import org.aspectj.compiler.base.ast.*;
28 import org.aspectj.compiler.crosscuts.ast.*;
29
30 import java.util.*;
31
32 public class CalleeSideCallJp extends CodeDecJp {
33     TypeDec typeDec;
34     public CalleeSideCallJp(TypeDec typeDec, MethodDec methodDec) {
35         super(methodDec);
36         this.typeDec = typeDec;
37     }
38
39     public Kind getKind() { return MethodCallJp.KIND; }
40     
41     public void addPlan(JpPlan plan) {
42         if (plan instanceof AdvicePlan) {
43             AdvicePlan advicePlan = (AdvicePlan)plan;
44             if (advicePlan.getAdviceDec() != null &&
45                 advicePlan.getAdviceDec().needsStaticEnclosingJoinPointFormal())
46             {
47                 getCompiler().showMessage(" skip plan on " + this + " needs enclosing join point");
48                 return;
49             }
50         }
51         plans.add(plan);
52     }
53     
54     //playing with cvs
55

56     public String JavaDoc toString() {
57         return super.toString() + "*";
58     }
59
60     public Type getBytecodeType() {
61         return getCodeDec().getBytecodeType();
62     }
63
64     public Type getDeclaringType() {
65         return getCodeDec().getDeclaringType();
66     }
67     
68     public Expr makeTargetExpr() {
69         return super.makeThisExpr();
70     }
71
72     public Type makeThisExprType() { return null; }
73     public Expr makeThisExpr() {
74         return null;
75     }
76     public Exprs makeArgsExprs() {
77         return getCodeFormals().makeExprs();
78     }
79
80     public ASTObject getSourceLocation() { return null; }
81     public ASTObject getTargetNode() { return getCodeDec(); }
82     public Type getTargetType() {
83         return null; //getRootDeclaringType(getTargetSO(), getDeclaringType());
84
}
85     
86     
87     public Set getTargetTypes() {
88         //System.out.println(this + " target types: " + getBaseMethodDec().getMatchingSignatureTypes());
89
return getBaseMethodDec().getMatchingSignatureTypes();
90     }
91         
92
93 // Type getRootDeclaringType(SemanticObject so, Type inType) {
94
// SemanticObject matchingSO = inType.findMatchingSemanticObject(so);
95
// if (matchingSO == null) return null;
96
//
97
// if (so.isStatic()) {
98
// if (matchingSO != so) return null;
99
// }
100
//
101
// //??? for fields, static methods and constructors this can probably be optimized
102
// //??? to only go up the class hierarchy ignoring interfaces
103
// for (Iterator i = inType.getDirectSuperTypes().iterator(); i.hasNext(); ) {
104
// Type ret = getRootDeclaringType(so, (Type)i.next());
105
// //!!! this doesn't handle ambiguity at all
106
// if (ret != null) return ret;
107
// }
108
//
109
// return inType;
110
// }
111

112     public boolean isSynthetic() {
113         return getCodeDec().getDeclaringType() != typeDec.getType();
114     }
115
116     public MethodDec getBaseMethodDec() {
117         if (isSynthetic()) {
118             //methodDec = getMethodDec().makeSuperCaller();
119
}
120         return (MethodDec)getCodeDec();
121     }
122     
123     public String JavaDoc getPostDispatchMethodName() {
124         return getAST().makeGeneratedName(getCodeDec().getId() + "$ajcPostCall");
125     }
126     
127     private Formals codeFormals = null;
128     public Formals getCodeFormals() {
129         if (codeFormals == null) {
130             codeFormals = (Formals)getBaseMethodDec().getFormals().copy();
131         }
132         return codeFormals;
133     }
134
135     
136     public MethodDec getPostMethodDec() {
137         if (postDispatchMethod == null) {
138             Formals formals = getBaseMethodDec().getFormals();
139             Type resultType = getBaseMethodDec().getResultType();
140             String JavaDoc id = getPostDispatchMethodName();
141             Modifiers modifiers = (Modifiers)getBaseMethodDec().getModifiers().copy();
142             postDispatchMethod =
143                 getAST().makeMethod(modifiers, resultType, id, formals, null);
144             TypeDs _throws = getBaseMethodDec().getThrows();
145             if (_throws != null) {
146                 postDispatchMethod.setThrows((TypeDs)_throws.copy());
147             }
148             postDispatchMethod.owner = getBaseMethodDec();
149             getBaseMethodDec().getBytecodeTypeDec().getBody().add(postDispatchMethod);
150         }
151         return postDispatchMethod;
152     }
153         
154     
155     MethodDec postDispatchMethod = null;
156     boolean madeInnerMethod = false;
157     public Stmts getStmts() {
158         if (!madeInnerMethod) {
159             madeInnerMethod = true;
160             CodeBody body = getBaseMethodDec().getBody();
161             Type resultType = getBaseMethodDec().getResultType();
162             
163             getBaseMethodDec().setBody(null);
164             
165             getPostMethodDec();
166             
167             getBaseMethodDec().setFormals(getCodeFormals());
168             getBaseMethodDec().setResultTypeD(resultType.makeTypeD());
169             
170
171             postDispatchMethod.setBody(body);
172             
173             Exprs args = getCodeFormals().makeExprs();
174             Expr thisExpr = makeThisExprOrType();
175             Expr callExpr = getAST().makeCall(postDispatchMethod, thisExpr, args);
176             callExpr.setSourceLocation(getTargetNode().getSourceLocation());
177             Stmt stmt = null;
178             if (resultType.isVoid()) {
179                 stmt = getAST().makeStmt(callExpr);
180             } else {
181                 stmt = getAST().makeReturn(callExpr);
182             }
183             getBaseMethodDec().setBody(getAST().makeBlock(stmt));
184         }
185         return getBaseMethodDec().getBody().getStmts();
186     }
187 }
188
Popular Tags