KickJava   Java API By Example, From Geeks To Geeks.

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


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.crosscuts.ast.*;
28 import org.aspectj.compiler.base.ast.*;
29
30 import org.aspectj.compiler.base.JavaCompiler;
31
32 import java.util.*;
33
34 /**
35  */

36 public class CFlowEntryPlan extends JpPlan {
37     private CFlowPlanner cflowPlanner;
38     private JpPlan plan;
39
40     public CFlowEntryPlan(JpPlan innerPlan, CFlowPlanner cflowPlanner) {
41         super(innerPlan.joinPoint);
42
43         this.cflowPlanner = cflowPlanner;
44         plan = innerPlan;
45     }
46
47     public int getPreSortOrder() {
48         if (cflowPlanner.getIncludesRoot()) return CFLOWENTRY_ROOT;
49         else return CFLOWENTRY_NOROOT;
50     }
51
52     /**
53      * These plans are ordered based on dependencies, i.e.
54      * eachcflow(P && !cflow(P))
55      * The ordering will make sure that the plan for cflow(P) is run before the
56      * plan for the eachcflow in order to generate the correct behavior.
57      *
58      * This is the only case where plans are ordered based on internal dependencies.
59      */

60     public int compareTo(Object JavaDoc o) {
61         int ret = super.compareTo(o);
62         if (ret != 0) return ret;
63            
64         if (! (o instanceof CFlowEntryPlan) ) return 0;
65         
66         CFlowEntryPlan p = (CFlowEntryPlan)o;
67         if (cflowPlanner.getIncludesRoot() != p.cflowPlanner.getIncludesRoot()) return 0;
68      
69         // now check to see if there's a dependency
70
if (plan.dependsOn(p.cflowPlanner)) {
71             //System.out.println("depends");
72
if (p.cflowPlanner.getIncludesRoot()) return +1;
73             else return -1;
74         } else if (p.plan.dependsOn(cflowPlanner)) {
75             //System.out.println("depends");
76
if (cflowPlanner.getIncludesRoot()) return -1;
77             else return +1;
78         } else {
79             //System.out.println("no depends");
80
return 0;
81         }
82     }
83
84     
85     public void wrapJoinPoint(JoinPoint jp) {
86         jp.setStmts(wrapPushPop(jp.getStmts()));
87     }
88     
89     public Stmts wrapPushPop(Stmts stmts) {
90         return cflowPlanner.wrapPushPop(plan, stmts);
91     }
92     
93     public String JavaDoc toString() {
94         return "cflow" + super.toString();
95     }
96 }
97
Popular Tags