1 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 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 addExprTest(Expr newExprTest) { 59 dynamicTest = intersectTests(this.dynamicTest, newExprTest); 60 } 61 62 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 test = dynamicTest; 139 return test; 146 } 147 148 149 public boolean hasTest() { 150 return dynamicTest != null || calledInstanceTest != null || 151 enclosingInstanceTest != null; 152 } 153 154 } 165 166 | Popular Tags |