summaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoracolyer <acolyer>2004-07-28 15:13:09 +0000
committeracolyer <acolyer>2004-07-28 15:13:09 +0000
commit10c6de6fbc8a0b9eb07801f4ac19bea8304a9cb3 (patch)
treeb44260eba290558bdc43afb7e968b60990e96bd0 /weaver
parent573741c8081c6b6b45921cafaae39f37eede2302 (diff)
downloadaspectj-10c6de6fbc8a0b9eb07801f4ac19bea8304a9cb3.tar.gz
aspectj-10c6de6fbc8a0b9eb07801f4ac19bea8304a9cb3.zip
fix for Bugzilla Bug 48990
Special case if(false) to not require a dynamic test
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/IfPointcut.java136
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/Pointcut.java7
2 files changed, 142 insertions, 1 deletions
diff --git a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java
index e770509b3..43f11ec28 100644
--- a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import org.aspectj.bridge.IMessage;
+import org.aspectj.lang.JoinPoint;
import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.Advice;
import org.aspectj.weaver.ISourceContext;
@@ -204,4 +205,139 @@ public class IfPointcut extends Pointcut {
return ret;
}
+// public static Pointcut MatchesNothing = new MatchesNothingPointcut();
+// ??? there could possibly be some good optimizations to be done at this point
+ public static IfPointcut makeIfFalsePointcut(State state) {
+ IfPointcut ret = new IfFalsePointcut();
+ ret.state = state;
+ return ret;
+ }
+
+ private static class IfFalsePointcut extends IfPointcut {
+
+ public IfFalsePointcut() {
+ super(null,0);
+ }
+
+ public Test findResidue(Shadow shadow, ExposedState state) {
+ return Literal.FALSE; // can only get here if an earlier error occurred
+ }
+
+ public FuzzyBoolean fastMatch(FastMatchInfo type) {
+ return FuzzyBoolean.NO;
+ }
+
+ public FuzzyBoolean match(Shadow shadow) {
+ return FuzzyBoolean.NO;
+ }
+
+ public FuzzyBoolean match(JoinPoint.StaticPart jpsp) {
+ return FuzzyBoolean.NO;
+ }
+
+ public void resolveBindings(IScope scope, Bindings bindings) {
+ }
+
+ public void resolveBindingsFromRTTI() {
+ }
+
+ public void postRead(ResolvedTypeX enclosingType) {
+ }
+
+ public Pointcut concretize1(
+ ResolvedTypeX inAspect,
+ IntMap bindings) {
+ if (isDeclare(bindings.getEnclosingAdvice())) {
+ // Enforce rule about which designators are supported in declare
+ inAspect.getWorld().showMessage(IMessage.ERROR,
+ "if() pointcut designator cannot be used in declare statement",
+ bindings.getEnclosingAdvice().getSourceLocation(),
+ null);
+ return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
+ }
+ return makeIfFalsePointcut(state);
+ }
+
+
+ public void write(DataOutputStream s) throws IOException {
+ s.writeByte(Pointcut.IF_FALSE);
+ }
+
+ public int hashCode() {
+ int result = 17;
+ return result;
+ }
+
+ public String toString() {
+ return "if(false)";
+ }
+ }
+
+ public static IfPointcut makeIfTruePointcut(State state) {
+ IfPointcut ret = new IfTruePointcut();
+ ret.state = state;
+ return ret;
+ }
+
+ private static class IfTruePointcut extends IfPointcut {
+
+ public IfTruePointcut() {
+ super(null,0);
+ }
+
+ public Test findResidue(Shadow shadow, ExposedState state) {
+ return Literal.TRUE; // can only get here if an earlier error occurred
+ }
+
+ public FuzzyBoolean fastMatch(FastMatchInfo type) {
+ return FuzzyBoolean.YES;
+ }
+
+ public FuzzyBoolean match(Shadow shadow) {
+ return FuzzyBoolean.YES;
+ }
+
+ public FuzzyBoolean match(JoinPoint.StaticPart jpsp) {
+ return FuzzyBoolean.YES;
+ }
+
+ public void resolveBindings(IScope scope, Bindings bindings) {
+ }
+
+ public void resolveBindingsFromRTTI() {
+ }
+
+ public void postRead(ResolvedTypeX enclosingType) {
+ }
+
+ public Pointcut concretize1(
+ ResolvedTypeX inAspect,
+ IntMap bindings) {
+ if (isDeclare(bindings.getEnclosingAdvice())) {
+ // Enforce rule about which designators are supported in declare
+ inAspect.getWorld().showMessage(IMessage.ERROR,
+ "if() pointcut designator cannot be used in declare statement",
+ bindings.getEnclosingAdvice().getSourceLocation(),
+ null);
+ return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
+ }
+ return makeIfTruePointcut(state);
+ }
+
+
+ public void write(DataOutputStream s) throws IOException {
+ s.writeByte(IF_TRUE);
+ }
+
+ public int hashCode() {
+ int result = 37;
+ return result;
+ }
+
+ public String toString() {
+ return "if(true)";
+ }
+ }
+
}
+
diff --git a/weaver/src/org/aspectj/weaver/patterns/Pointcut.java b/weaver/src/org/aspectj/weaver/patterns/Pointcut.java
index 466363135..31afd6039 100644
--- a/weaver/src/org/aspectj/weaver/patterns/Pointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/Pointcut.java
@@ -103,6 +103,8 @@ public abstract class Pointcut extends PatternNode {
public static final byte CFLOW = 10;
public static final byte WITHINCODE = 12;
public static final byte HANDLER = 13;
+ public static final byte IF_TRUE = 14;
+ public static final byte IF_FALSE = 15;
public static final byte NONE = 20;
@@ -217,6 +219,8 @@ public abstract class Pointcut extends PatternNode {
case CFLOW: ret = CflowPointcut.read(s, context); break;
case WITHINCODE: ret = WithincodePointcut.read(s, context); break;
case HANDLER: ret = HandlerPointcut.read(s, context); break;
+ case IF_TRUE: ret = IfPointcut.makeIfTruePointcut(RESOLVED); break;
+ case IF_FALSE: ret = IfPointcut.makeIfFalsePointcut(RESOLVED); break;
case NONE: ret = makeMatchesNothing(RESOLVED); break;
default:
@@ -283,7 +287,8 @@ public abstract class Pointcut extends PatternNode {
ret.state = state;
return ret;
}
-
+
+
public void assertState(State state) {
if (this.state != state) {
throw new BCException("expected state: " + state + " got: " + this.state);