KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > crosscuts > ast > PerClause


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.ast;
26 import org.aspectj.compiler.base.ast.*;
27 import org.aspectj.compiler.crosscuts.joinpoints.*;
28 import org.aspectj.util.*;
29
30 import org.aspectj.compiler.base.JavaCompiler;
31
32 /**
33  * @grammar per*(...)
34  */

35
36 public abstract class PerClause extends ASTObject {
37     MethodDec aspectOfMethod;
38     MethodDec hasAspectMethod;
39     
40     private AspectDec aspectDec = null;
41     public AspectDec getAspectDec() {
42         if (aspectDec == null) {
43             aspectDec = (AspectDec)getParent();
44         }
45         return aspectDec;
46     }
47
48     TypeD getAspectTypeD() {
49         return getAspectDec().getType().makeTypeD();
50     }
51     Type getAspectType() {
52         return getAspectDec().getType();
53     }
54     
55     /**
56      * per-clauses have a unique notion of their lexically enclosing type
57      * even though they're not in the body of their declaring aspect, they
58      * need to be treated as if they were.
59      */

60     public Type getLexicalType() {
61         return getAspectType();
62     }
63
64     public Type getDeclaringType() {
65         return getAspectType();
66     }
67     
68     public abstract JpPlanner makeInnerPlanner(PlanData planData);
69     public abstract JpPlanner makeInitializerPlanner(PlanData planData);
70     
71     protected MethodDec makeAspectOfMethod(Formals formals, BlockStmt body) {
72         final AST ast = getAST();
73         Modifiers modifiers = ast.makeModifiers(Modifiers.PUBLIC | Modifiers.STATIC);
74         String JavaDoc name = "aspectOf";
75 // if (getAspectDec().isAbstract()) {
76
// name =
77
// JavaStrings.makeLegalIdentifier(name + '$' + getAspectType().getString());
78
// }
79

80         return ast.makeMethod(modifiers, getAspectType(), name, formals, body);
81     }
82     
83     protected MethodDec makeHasAspectMethod(Formals formals, BlockStmt body) {
84         final AST ast = getAST();
85         Modifiers modifiers = ast.makeModifiers(Modifiers.PUBLIC | Modifiers.STATIC);
86         String JavaDoc name = "hasAspect";
87 // if (getAspectDec().isAbstract()) {
88
// name =
89
// JavaStrings.makeLegalIdentifier(name + '$' + getAspectType().getString());
90
// }
91

92         return ast.makeMethod(modifiers, getTypeManager().booleanType, name, formals, body);
93     }
94     
95     protected abstract MethodDec makeAspectOfMethod();
96     protected abstract MethodDec makeHasAspectMethod();
97     
98     
99     public void setupAspect() {
100         TypeDec typeDec = getAspectDec();
101         if (typeDec.isAbstract()) return;
102         
103         aspectOfMethod = makeAspectOfMethod();
104         typeDec.addToBodyAndType(aspectOfMethod);
105         hasAspectMethod = makeHasAspectMethod();
106         typeDec.addToBodyAndType(hasAspectMethod);
107     }
108
109     public Expr makeAspectOfExpr(Expr fromObject) { return null; }
110     
111     //BEGIN: Generated from @child and @property
112

113     public PerClause(SourceLocation location) {
114         super(location);
115     
116     }
117     
118     
119     public String JavaDoc getDefaultDisplayName() {
120         return "PerClause()";
121     }
122     
123     //END: Generated from @child and @property
124
}
125
126
Popular Tags