KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > crosscuts > BuildAdvicePlannersPass


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;
26
27 import org.aspectj.compiler.crosscuts.ast.*;
28 import org.aspectj.compiler.crosscuts.joinpoints.*;
29
30 import org.aspectj.compiler.base.ast.*;
31 import org.aspectj.compiler.base.*;
32 import org.aspectj.util.CollectionUtil;
33
34 import java.util.*;
35
36 public class BuildAdvicePlannersPass extends AbstractCompilerPass {
37
38     public BuildAdvicePlannersPass(JavaCompiler compiler) {
39         super(compiler);
40     }
41
42     public String JavaDoc getDisplayName() {
43         return "building advice planners";
44     }
45
46     public void transform(TypeDec td) {
47         if (td instanceof AspectDec) {
48             initializeAspect((AspectDec)td);
49         }
50         
51         // also do this on all inner types
52
final int N = td.getBody().size();
53         for (int i = 0; i < N; i++) {
54             Dec dec = td.getBody().get(i);
55             if (dec instanceof TypeDec) transform( (TypeDec)dec );
56         }
57     }
58     
59     public void initializeAspect(final AspectDec aspectDec) {
60         //??? I don't think this loses anything
61
if (aspectDec.isAbstract()) return;
62         
63         getCompiler().enterNode(aspectDec);
64         
65         PerClause perClause = aspectDec.getPerClause();
66         if (perClause != null) {
67             JpPlanner planner = perClause.makeInitializerPlanner(
68                     new PlanData(aspectDec, null));
69             if (planner != null) getWorld().addJpPlanner(planner);
70         }
71         
72         Collection jpPlannerMakerList = aspectDec.getJpPlannerMakers();
73         
74         getCompiler().showMessage(" initializing advice in " +
75                                   aspectDec.toShortString());
76         
77         for(Iterator i = jpPlannerMakerList.iterator(); i.hasNext(); ) {
78             JpPlannerMaker jpPlannerMaker = (JpPlannerMaker)i.next();
79             JpPlanner planner =
80                 jpPlannerMaker.makePlanner(new PlanData(aspectDec, jpPlannerMaker));
81             if (planner != null) {
82                 getWorld().addJpPlanner(planner);
83                 getCompiler().showMessage(" " + jpPlannerMaker.toShortString());
84             }
85         }
86
87         for (Iterator i = aspectDec.getExtraPlanners().values().iterator();
88              i.hasNext(); )
89         {
90             getWorld().addJpPlanner((JpPlanner)i.next());
91         }
92
93         // System.out.println(" jpp: " + joinPointPlanners);
94
getCompiler().exitNode(aspectDec);
95     }
96
97 }
98
99
Popular Tags