KickJava   Java API By Example, From Geeks To Geeks.

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


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.TypeManager;
31 import org.aspectj.compiler.base.CompilerObject;
32 import org.aspectj.compiler.base.JavaCompiler;
33
34 import java.util.*;
35
36 /**
37  */

38
39 public class DynamicPointTest extends CompilerObject {
40     public Expr dynamicTest = null;
41     public InstanceTest enclosingInstanceTest;
42     public InstanceTest calledInstanceTest;
43
44     public DynamicPointTest(JavaCompiler compiler) {
45         super(compiler);
46     }
47
48 // public void addInstanceTest(InstanceTest instanceTest, boolean useCallThis) {
49
// if (useCallThis) {
50
// calledInstanceTest =
51
// intersectInstanceTests(this.calledInstanceTest, instanceTest);
52
// } else {
53
// enclosingInstanceTest =
54
// intersectInstanceTests(this.enclosingInstanceTest, instanceTest);
55
// }
56
// }
57
//
58
public void addExprTest(Expr newExprTest) {
59         dynamicTest = intersectTests(this.dynamicTest, newExprTest);
60     }
61
62     //XXX cut-and-paste from intersect
63
public void addTest(DynamicPointTest other) {
64         dynamicTest = intersectTests(dynamicTest, other.dynamicTest);
65         calledInstanceTest = intersectInstanceTests(calledInstanceTest, other.calledInstanceTest);
66         enclosingInstanceTest = intersectInstanceTests(enclosingInstanceTest, other.enclosingInstanceTest);
67     }
68
69     public DynamicPointTest intersect(DynamicPointTest other) {
70         DynamicPointTest newTest = new DynamicPointTest(getCompiler());
71
72         newTest.dynamicTest = intersectTests(dynamicTest, other.dynamicTest);
73         newTest.calledInstanceTest = intersectInstanceTests(calledInstanceTest, other.calledInstanceTest);
74         newTest.enclosingInstanceTest = intersectInstanceTests(enclosingInstanceTest, other.enclosingInstanceTest);
75
76         return newTest;
77     }
78
79     public DynamicPointTest union(DynamicPointTest other) {
80         DynamicPointTest newTest = new DynamicPointTest(getCompiler());
81
82         newTest.dynamicTest = unionTests(dynamicTest, other.dynamicTest);
83         newTest.calledInstanceTest = unionInstanceTests(calledInstanceTest, other.calledInstanceTest);
84         newTest.enclosingInstanceTest = unionInstanceTests(enclosingInstanceTest, other.enclosingInstanceTest);
85
86         return newTest;
87     }
88
89     public DynamicPointTest complement() {
90         DynamicPointTest newTest = new DynamicPointTest(getCompiler());
91
92         newTest.dynamicTest = complementTest(dynamicTest);
93         newTest.calledInstanceTest = complementInstanceTest(calledInstanceTest);
94         newTest.enclosingInstanceTest = complementInstanceTest(enclosingInstanceTest);
95
96         return newTest;
97     }
98
99
100
101     private InstanceTest intersectInstanceTests(InstanceTest test1, InstanceTest test2) {
102         if (test1 == null) return test2;
103         if (test2 == null) return test1;
104         return test1.intersect(test2);
105     }
106
107     private Expr intersectTests(Expr test1, Expr test2) {
108         if (test1 == null) return test2;
109         if (test2 == null) return test1;
110         return getAST().makeBinop("&&", test1, test2);
111     }
112
113     private InstanceTest unionInstanceTests(InstanceTest test1, InstanceTest test2) {
114         if (test1 == null) return test2;
115         if (test2 == null) return test1;
116         return test1.union(test2);
117     }
118
119     private Expr unionTests(Expr test1, Expr test2) {
120         if (test1 == null) return test2;
121         if (test2 == null) return test1;
122         return getAST().makeBinop("||", test1, test2);
123     }
124
125     private InstanceTest complementInstanceTest(InstanceTest instanceTest) {
126         if (instanceTest == null) return null;
127         return instanceTest.complement();
128     }
129
130     private Expr complementTest(Expr test) {
131         if (test == null) return null;
132         return getAST().makeUnop("!", test);
133     }
134
135
136
137     public Expr getTestExpr() { //Expr calledThis, Expr enclosingThis) {
138
Expr test = dynamicTest;
139 // if (calledInstanceTest != null) {
140
// test = intersectTests(test, calledInstanceTest.makeExpr(calledThis));
141
// }
142
// if (enclosingInstanceTest != null) {
143
// test = intersectTests(test, enclosingInstanceTest.makeExpr(enclosingThis));
144
// }
145
return test;
146     }
147
148
149     public boolean hasTest() {
150         return dynamicTest != null || calledInstanceTest != null ||
151                     enclosingInstanceTest != null;
152     }
153
154 // public String toString() {
155
// Expr testExpr = getTestExpr(new VarExpr(getCompiler(),"calledThis"), new VarExpr(getCompiler(),"this"));
156
// String s;
157
// if (testExpr == null) {
158
// s = "null";
159
// } else {
160
// s = testExpr.toShortString();
161
// }
162
// return "DynamicPointTest(" + s + ")";
163
// }
164
}
165
166
Popular Tags