From 4035a174b2a080841df5cf07bf97fa2ce0978c1d Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 13 Feb 2006 15:37:17 +0000 Subject: [PATCH] optimization: use bit twiddling rather than Sets for manipulating the list of Pointcut.couldMatchKinds - (saves a few percent when building shadows in my tests...) --- weaver/src/org/aspectj/weaver/Shadow.java | 99 +++++++++++++------ .../aspectj/weaver/bcel/BcelClassWeaver.java | 17 +++- .../org/aspectj/weaver/bcel/BcelWeaver.java | 12 +-- ...ointcutDesignatorHandlerBasedPointcut.java | 5 +- .../aspectj/weaver/patterns/AndPointcut.java | 10 +- .../weaver/patterns/AnnotationPointcut.java | 5 +- .../patterns/ArgsAnnotationPointcut.java | 5 +- .../aspectj/weaver/patterns/ArgsPointcut.java | 5 +- .../weaver/patterns/CflowPointcut.java | 7 +- .../patterns/ConcreteCflowPointcut.java | 5 +- .../weaver/patterns/HandlerPointcut.java | 9 +- .../aspectj/weaver/patterns/IfPointcut.java | 10 +- .../weaver/patterns/KindedPointcut.java | 9 +- .../aspectj/weaver/patterns/NotPointcut.java | 5 +- .../aspectj/weaver/patterns/OrPointcut.java | 9 +- .../org/aspectj/weaver/patterns/PerCflow.java | 7 +- .../aspectj/weaver/patterns/PerFromSuper.java | 5 +- .../aspectj/weaver/patterns/PerObject.java | 27 ++--- .../aspectj/weaver/patterns/PerSingleton.java | 7 +- .../weaver/patterns/PerTypeWithin.java | 11 +-- .../org/aspectj/weaver/patterns/Pointcut.java | 13 ++- .../PointcutEvaluationExpenseComparator.java | 2 +- .../weaver/patterns/PointcutRewriter.java | 4 +- .../weaver/patterns/ReferencePointcut.java | 5 +- .../ThisOrTargetAnnotationPointcut.java | 23 +++-- .../weaver/patterns/ThisOrTargetPointcut.java | 23 +++-- .../patterns/WithinAnnotationPointcut.java | 5 +- .../WithinCodeAnnotationPointcut.java | 12 +-- .../weaver/patterns/WithinPointcut.java | 5 +- .../weaver/patterns/WithincodePointcut.java | 15 ++- .../weaver/patterns/PointcutRewriterTest.java | 84 ++++++++-------- 31 files changed, 240 insertions(+), 220 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/Shadow.java b/weaver/src/org/aspectj/weaver/Shadow.java index ab652b24c..2436a6c0e 100644 --- a/weaver/src/org/aspectj/weaver/Shadow.java +++ b/weaver/src/org/aspectj/weaver/Shadow.java @@ -16,7 +16,6 @@ package org.aspectj.weaver; import java.io.DataInputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -258,29 +257,55 @@ public abstract class Shadow { public static final Kind Initialization = new Kind(JoinPoint.INITIALIZATION, 10, false); public static final Kind ExceptionHandler = new Kind(JoinPoint.EXCEPTION_HANDLER, 11, true); + // Bits here are 1<<(Kind.getKey()) - and unfortunately keys didn't start at zero so bits here start at 2 + public static final int MethodCallBit = 0x002; + public static final int ConstructorCallBit = 0x004; + public static final int MethodExecutionBit = 0x008; + public static final int ConstructorExecutionBit = 0x010; + public static final int FieldGetBit = 0x020; + public static final int FieldSetBit = 0x040; + public static final int StaticInitializationBit = 0x080; + public static final int PreInitializationBit = 0x100; + public static final int AdviceExecutionBit = 0x200; + public static final int InitializationBit = 0x400; + public static final int ExceptionHandlerBit = 0x800; + public static final int MAX_SHADOW_KIND = 11; public static final Kind[] SHADOW_KINDS = new Kind[] { MethodCall, ConstructorCall, MethodExecution, ConstructorExecution, FieldGet, FieldSet, StaticInitialization, PreInitialization, AdviceExecution, Initialization, ExceptionHandler, }; - - public static final Set ALL_SHADOW_KINDS; + + public static final int ALL_SHADOW_KINDS_BITS; + public static final int NO_SHADOW_KINDS_BITS; + static { - HashSet aSet = new HashSet(); - for (int i = 0; i < SHADOW_KINDS.length; i++) { - aSet.add(SHADOW_KINDS[i]); - } - ALL_SHADOW_KINDS = Collections.unmodifiableSet(aSet); + ALL_SHADOW_KINDS_BITS = 0xffe; + NO_SHADOW_KINDS_BITS = 0x000; } + + /** + * Return count of how many bits set in the supplied parameter. + */ + public static int howMany(int i) { + int count = 0; + for (int j = 0; j 0) + if (left.couldMatchKinds()!=Shadow.NO_SHADOW_KINDS_BITS) validateSingleBranch(left, userPointcut, numFormals, names, leftBindings); } if (right instanceof OrPointcut) { Pointcut[] newLeftBindings = new Pointcut[numFormals]; validateOrBranch((OrPointcut)right,userPointcut,numFormals,names,newLeftBindings,rightBindings); } else { - if (right.couldMatchKinds().size() > 0) + if (right.couldMatchKinds()!=Shadow.NO_SHADOW_KINDS_BITS) validateSingleBranch(right, userPointcut, numFormals, names, rightBindings); } - Set kindsInCommon = left.couldMatchKinds(); - kindsInCommon.retainAll(right.couldMatchKinds()); - if (!kindsInCommon.isEmpty() && couldEverMatchSameJoinPoints(left,right)) { + int kindsInCommon = left.couldMatchKinds() & right.couldMatchKinds(); + if (kindsInCommon!=Shadow.NO_SHADOW_KINDS_BITS && couldEverMatchSameJoinPoints(left,right)) { // we know that every branch binds every formal, so there is no ambiguity // if each branch binds it in exactly the same way... List ambiguousNames = new ArrayList(); diff --git a/weaver/src/org/aspectj/weaver/internal/tools/PointcutDesignatorHandlerBasedPointcut.java b/weaver/src/org/aspectj/weaver/internal/tools/PointcutDesignatorHandlerBasedPointcut.java index 3934f56c9..824e52192 100644 --- a/weaver/src/org/aspectj/weaver/internal/tools/PointcutDesignatorHandlerBasedPointcut.java +++ b/weaver/src/org/aspectj/weaver/internal/tools/PointcutDesignatorHandlerBasedPointcut.java @@ -14,7 +14,6 @@ package org.aspectj.weaver.internal.tools; import java.io.DataOutputStream; import java.io.IOException; import java.util.Map; -import java.util.Set; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.IntMap; @@ -74,8 +73,8 @@ public class PointcutDesignatorHandlerBasedPointcut extends Pointcut{ /* (non-Javadoc) * @see org.aspectj.weaver.patterns.Pointcut#couldMatchKinds() */ - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } /* (non-Javadoc) diff --git a/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java b/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java index 0aa55e115..88810c288 100644 --- a/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java @@ -15,9 +15,7 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.ISourceContext; @@ -30,7 +28,7 @@ import org.aspectj.weaver.ast.Test; public class AndPointcut extends Pointcut { Pointcut left, right; // exposed for testing - private Set couldMatchKinds; + private int couldMatchKinds; public AndPointcut(Pointcut left, Pointcut right) { super(); @@ -38,12 +36,10 @@ public class AndPointcut extends Pointcut { this.right = right; this.pointcutKind = AND; setLocation(left.getSourceContext(), left.getStart(), right.getEnd()); - couldMatchKinds = new HashSet(); - couldMatchKinds.addAll(left.couldMatchKinds()); - couldMatchKinds.retainAll(right.couldMatchKinds()); + couldMatchKinds = left.couldMatchKinds() & right.couldMatchKinds(); } - public Set couldMatchKinds() { + public int couldMatchKinds() { return couldMatchKinds; } diff --git a/weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java index f01b9240e..883f93fb6 100644 --- a/weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java @@ -17,7 +17,6 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.MessageUtil; import org.aspectj.util.FuzzyBoolean; @@ -84,8 +83,8 @@ public class AnnotationPointcut extends NameBindingPointcut { return annotationTypePattern; } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } public Pointcut parameterizeWith(Map typeVariableMap) { diff --git a/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java index aec5585df..41d7416e6 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java @@ -15,7 +15,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.ISourceLocation; @@ -57,8 +56,8 @@ public class ArgsAnnotationPointcut extends NameBindingPointcut { return arguments; } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; // empty args() matches jps with no args + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; // empty args() matches jps with no args } public Pointcut parameterizeWith(Map typeVariableMap) { diff --git a/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java index 04581891b..18b624c11 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.ISourceLocation; @@ -65,8 +64,8 @@ public class ArgsPointcut extends NameBindingPointcut { return ret; } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; // empty args() matches jps with no args + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; // empty args() matches jps with no args } public FuzzyBoolean fastMatch(FastMatchInfo type) { diff --git a/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java b/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java index 4eea612fd..b1f3a8ef0 100644 --- a/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java @@ -23,7 +23,6 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.IMessage; import org.aspectj.util.FileUtil; @@ -34,8 +33,8 @@ import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.IntMap; import org.aspectj.weaver.Member; import org.aspectj.weaver.NameMangler; -import org.aspectj.weaver.ResolvedMemberImpl; import org.aspectj.weaver.ResolvedMember; +import org.aspectj.weaver.ResolvedMemberImpl; import org.aspectj.weaver.ResolvedPointcutDefinition; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.Shadow; @@ -79,8 +78,8 @@ public class CflowPointcut extends Pointcut { return isBelow; } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } // enh 76055 diff --git a/weaver/src/org/aspectj/weaver/patterns/ConcreteCflowPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ConcreteCflowPointcut.java index d86578be8..3a91e5486 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ConcreteCflowPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ConcreteCflowPointcut.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.IntMap; @@ -46,8 +45,8 @@ public class ConcreteCflowPointcut extends Pointcut { this.pointcutKind = CFLOW; } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } public FuzzyBoolean fastMatch(FastMatchInfo type) { diff --git a/weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java b/weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java index a92eaa007..0d9e56377 100644 --- a/weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java @@ -15,9 +15,7 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.MessageUtil; import org.aspectj.util.FuzzyBoolean; @@ -40,17 +38,14 @@ import org.aspectj.weaver.ast.Test; public class HandlerPointcut extends Pointcut { TypePattern exceptionType; - private static final Set MATCH_KINDS = new HashSet(); - static { - MATCH_KINDS.add(Shadow.ExceptionHandler); - } + private static final int MATCH_KINDS = Shadow.ExceptionHandler.bit; public HandlerPointcut(TypePattern exceptionType) { this.exceptionType = exceptionType; this.pointcutKind = HANDLER; } - public Set couldMatchKinds() { + public int couldMatchKinds() { return MATCH_KINDS; } diff --git a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java index 9b8d5b6af..bcb5bf3a9 100644 --- a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java @@ -15,11 +15,9 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.IMessage; import org.aspectj.lang.JoinPoint; @@ -73,8 +71,8 @@ public class IfPointcut extends Pointcut { this.extraParameterFlags = -1;//allows to keep track of the @Aj style } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } public FuzzyBoolean fastMatch(FastMatchInfo type) { @@ -393,8 +391,8 @@ public class IfPointcut extends Pointcut { this.pointcutKind = Pointcut.IF_FALSE; } - public Set couldMatchKinds() { - return Collections.EMPTY_SET; + public int couldMatchKinds() { + return Shadow.NO_SHADOW_KINDS_BITS; } public boolean alwaysFalse() { diff --git a/weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java b/weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java index 25c25740c..0c3dffe0d 100644 --- a/weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java @@ -15,9 +15,7 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.MessageUtil; @@ -40,7 +38,7 @@ import org.aspectj.weaver.ast.Test; public class KindedPointcut extends Pointcut { Shadow.Kind kind; private SignaturePattern signature; - private Set matchKinds; + private int matchKinds; private ShadowMunger munger = null; // only set after concretization @@ -50,8 +48,7 @@ public class KindedPointcut extends Pointcut { this.kind = kind; this.signature = signature; this.pointcutKind = KINDED; - this.matchKinds = new HashSet(); - matchKinds.add(kind); + this.matchKinds = kind.bit; } public KindedPointcut( Shadow.Kind kind, @@ -68,7 +65,7 @@ public class KindedPointcut extends Pointcut { /* (non-Javadoc) * @see org.aspectj.weaver.patterns.Pointcut#couldMatchKinds() */ - public Set couldMatchKinds() { + public int couldMatchKinds() { return matchKinds; } diff --git a/weaver/src/org/aspectj/weaver/patterns/NotPointcut.java b/weaver/src/org/aspectj/weaver/patterns/NotPointcut.java index 9f70b73f9..972657f93 100644 --- a/weaver/src/org/aspectj/weaver/patterns/NotPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/NotPointcut.java @@ -16,7 +16,6 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; import java.util.Map; -import java.util.Set; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.ISourceContext; @@ -39,8 +38,8 @@ public class NotPointcut extends Pointcut { setLocation(pointcut.getSourceContext(), startPos, pointcut.getEnd()); } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } public Pointcut getNegatedPointcut() { return body; } diff --git a/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java b/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java index 76774e613..5a564ec9c 100644 --- a/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java @@ -15,9 +15,7 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.ISourceContext; @@ -29,7 +27,7 @@ import org.aspectj.weaver.ast.Test; public class OrPointcut extends Pointcut { Pointcut left, right; - private Set couldMatchKinds; + private int couldMatchKinds; public OrPointcut(Pointcut left, Pointcut right) { super(); @@ -37,11 +35,10 @@ public class OrPointcut extends Pointcut { this.right = right; setLocation(left.getSourceContext(), left.getStart(), right.getEnd()); this.pointcutKind = OR; - this.couldMatchKinds = new HashSet(left.couldMatchKinds()); - this.couldMatchKinds.addAll(right.couldMatchKinds()); + this.couldMatchKinds = left.couldMatchKinds() | right.couldMatchKinds(); } - public Set couldMatchKinds() { + public int couldMatchKinds() { return couldMatchKinds; } diff --git a/weaver/src/org/aspectj/weaver/patterns/PerCflow.java b/weaver/src/org/aspectj/weaver/patterns/PerCflow.java index dd63f3d51..ee5517048 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PerCflow.java +++ b/weaver/src/org/aspectj/weaver/patterns/PerCflow.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.Advice; @@ -35,9 +34,9 @@ import org.aspectj.weaver.Shadow; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.VersionedDataInputStream; import org.aspectj.weaver.World; -import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; import org.aspectj.weaver.ast.Expr; import org.aspectj.weaver.ast.Test; +import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; public class PerCflow extends PerClause { private boolean isBelow; @@ -54,8 +53,8 @@ public class PerCflow extends PerClause { return visitor.visit(this,data); } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } public FuzzyBoolean fastMatch(FastMatchInfo type) { diff --git a/weaver/src/org/aspectj/weaver/patterns/PerFromSuper.java b/weaver/src/org/aspectj/weaver/patterns/PerFromSuper.java index 02335285e..822345216 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PerFromSuper.java +++ b/weaver/src/org/aspectj/weaver/patterns/PerFromSuper.java @@ -16,7 +16,6 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.MessageUtil; import org.aspectj.util.FuzzyBoolean; @@ -38,8 +37,8 @@ public class PerFromSuper extends PerClause { return visitor.visit(this,data); } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } public FuzzyBoolean fastMatch(FastMatchInfo type) { diff --git a/weaver/src/org/aspectj/weaver/patterns/PerObject.java b/weaver/src/org/aspectj/weaver/patterns/PerObject.java index b29fee3fc..64f2ea2f7 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PerObject.java +++ b/weaver/src/org/aspectj/weaver/patterns/PerObject.java @@ -15,37 +15,40 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; -import java.util.HashSet; -import java.util.Iterator; import java.util.Map; -import java.util.Set; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.Advice; import org.aspectj.weaver.AjcMemberMaker; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.PerObjectInterfaceTypeMunger; -import org.aspectj.weaver.ResolvedTypeMunger; import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.ResolvedTypeMunger; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.VersionedDataInputStream; import org.aspectj.weaver.World; -import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; import org.aspectj.weaver.ast.Expr; import org.aspectj.weaver.ast.Test; import org.aspectj.weaver.ast.Var; +import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; public class PerObject extends PerClause { private boolean isThis; private Pointcut entry; - private static final Set thisKindSet = new HashSet(Shadow.ALL_SHADOW_KINDS); - private static final Set targetKindSet = new HashSet(Shadow.ALL_SHADOW_KINDS); + + private static final int thisKindSet; + private static final int targetKindSet; + static { - for (Iterator iter = Shadow.ALL_SHADOW_KINDS.iterator(); iter.hasNext();) { - Shadow.Kind kind = (Shadow.Kind) iter.next(); - if (kind.neverHasThis()) thisKindSet.remove(kind); - if (kind.neverHasTarget()) targetKindSet.remove(kind); + int thisFlags = Shadow.ALL_SHADOW_KINDS_BITS; + int targFlags = Shadow.ALL_SHADOW_KINDS_BITS; + for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) { + Shadow.Kind kind = Shadow.SHADOW_KINDS[i]; + if (kind.neverHasThis()) thisFlags-=kind.bit; + if (kind.neverHasTarget()) targFlags-=kind.bit; } + thisKindSet = thisFlags; + targetKindSet=targFlags; } public PerObject(Pointcut entry, boolean isThis) { @@ -57,7 +60,7 @@ public class PerObject extends PerClause { return visitor.visit(this,data); } - public Set couldMatchKinds() { + public int couldMatchKinds() { return isThis ? thisKindSet : targetKindSet; } diff --git a/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java b/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java index f8155ed70..addf03925 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java +++ b/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java @@ -16,7 +16,6 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; import java.util.Map; -import java.util.Set; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.AjcMemberMaker; @@ -24,10 +23,10 @@ import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.VersionedDataInputStream; -import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; import org.aspectj.weaver.ast.Expr; import org.aspectj.weaver.ast.Literal; import org.aspectj.weaver.ast.Test; +import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; public class PerSingleton extends PerClause { public PerSingleton() { @@ -37,8 +36,8 @@ public class PerSingleton extends PerClause { return visitor.visit(this,data); } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } public FuzzyBoolean fastMatch(FastMatchInfo type) { diff --git a/weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java b/weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java index 0f8d2a327..0c8a5096e 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java +++ b/weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java @@ -14,9 +14,7 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.ISourceLocation; @@ -26,17 +24,16 @@ import org.aspectj.weaver.Advice; import org.aspectj.weaver.AjcMemberMaker; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.Member; -//import org.aspectj.weaver.PerTypeWithinTargetTypeMunger; import org.aspectj.weaver.PerTypeWithinTargetTypeMunger; -import org.aspectj.weaver.ResolvedTypeMunger; import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.ResolvedTypeMunger; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.VersionedDataInputStream; import org.aspectj.weaver.World; -import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; import org.aspectj.weaver.ast.Expr; import org.aspectj.weaver.ast.Literal; import org.aspectj.weaver.ast.Test; +import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; // PTWIMPL Represents a parsed pertypewithin() @@ -45,7 +42,7 @@ public class PerTypeWithin extends PerClause { private TypePattern typePattern; // Any shadow could be considered within a pertypewithin() type pattern - private static final Set kindSet = new HashSet(Shadow.ALL_SHADOW_KINDS); + private static final int kindSet = Shadow.ALL_SHADOW_KINDS_BITS; public TypePattern getTypePattern() { return typePattern; @@ -59,7 +56,7 @@ public class PerTypeWithin extends PerClause { return visitor.visit(this,data); } - public Set couldMatchKinds() { + public int couldMatchKinds() { return kindSet; } diff --git a/weaver/src/org/aspectj/weaver/patterns/Pointcut.java b/weaver/src/org/aspectj/weaver/patterns/Pointcut.java index 4fdf124ba..f0fd775c2 100644 --- a/weaver/src/org/aspectj/weaver/patterns/Pointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/Pointcut.java @@ -15,9 +15,7 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; -import java.util.Collections; import java.util.Map; -import java.util.Set; import org.aspectj.util.FuzzyBoolean; import org.aspectj.util.TypeSafeEnum; @@ -121,9 +119,10 @@ public abstract class Pointcut extends PatternNode { public abstract FuzzyBoolean fastMatch(FastMatchInfo info); /** - * The set of ShadowKinds that this Pointcut could possibly match + * The set of ShadowKinds that this Pointcut could possibly match - + * an int whose bits are set according to the Kinds specified in Shadow.java */ - public abstract /*Enum*/Set/**/ couldMatchKinds(); + public abstract int couldMatchKinds(); public String[] getTypeVariablesInScope() { return typeVariablesInScope; @@ -141,7 +140,7 @@ public abstract class Pointcut extends PatternNode { if (shadow.shadowId == lastMatchedShadowId) return lastMatchedShadowResult; FuzzyBoolean ret; // this next test will prevent a lot of un-needed matching going on.... - if (couldMatchKinds().contains(shadow.getKind())) { + if (shadow.getKind().isSet(couldMatchKinds())) { ret = matchInternal(shadow); } else { ret = FuzzyBoolean.NO; @@ -326,8 +325,8 @@ public abstract class Pointcut extends PatternNode { return Literal.FALSE; // can only get here if an earlier error occurred } - public Set couldMatchKinds() { - return Collections.EMPTY_SET; + public int couldMatchKinds() { + return Shadow.NO_SHADOW_KINDS_BITS; } public FuzzyBoolean fastMatch(FastMatchInfo type) { diff --git a/weaver/src/org/aspectj/weaver/patterns/PointcutEvaluationExpenseComparator.java b/weaver/src/org/aspectj/weaver/patterns/PointcutEvaluationExpenseComparator.java index 578670031..2c2d7c0e6 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PointcutEvaluationExpenseComparator.java +++ b/weaver/src/org/aspectj/weaver/patterns/PointcutEvaluationExpenseComparator.java @@ -75,7 +75,7 @@ public class PointcutEvaluationExpenseComparator implements Comparator { // a higher score means a more expensive evaluation private int getScore(Pointcut p) { - if (p.couldMatchKinds().isEmpty()) return MATCHES_NOTHING; + if (p.couldMatchKinds()==Shadow.NO_SHADOW_KINDS_BITS) return MATCHES_NOTHING; if (p instanceof WithinPointcut) return WITHIN; if (p instanceof WithinAnnotationPointcut) return ATWITHIN; if (p instanceof KindedPointcut) { diff --git a/weaver/src/org/aspectj/weaver/patterns/PointcutRewriter.java b/weaver/src/org/aspectj/weaver/patterns/PointcutRewriter.java index 2d70942bf..8b08b041a 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PointcutRewriter.java +++ b/weaver/src/org/aspectj/weaver/patterns/PointcutRewriter.java @@ -307,9 +307,9 @@ public class PointcutRewriter { if (((IfPointcut)element).alwaysFalse()) return Pointcut.makeMatchesNothing(element.state); } // If it can't match anything, the whole AND can't match anything - if (element.couldMatchKinds().isEmpty()) return element; + if (element.couldMatchKinds()==Shadow.NO_SHADOW_KINDS_BITS) return element; } - if (apc.couldMatchKinds().isEmpty()) return Pointcut.makeMatchesNothing(apc.state); + if (apc.couldMatchKinds()==Shadow.NO_SHADOW_KINDS_BITS) return Pointcut.makeMatchesNothing(apc.state); // write out with cheapest on left Iterator iter = nodes.iterator(); Pointcut result = (Pointcut) iter.next(); diff --git a/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java b/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java index bb2c6ba61..4110eec92 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.MessageUtil; @@ -67,8 +66,8 @@ public class ReferencePointcut extends Pointcut { this.pointcutKind = REFERENCE; } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } diff --git a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java index fc9493c5b..8f1cb3c31 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java @@ -13,11 +13,8 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.MessageUtil; @@ -47,14 +44,20 @@ public class ThisOrTargetAnnotationPointcut extends NameBindingPointcut { private ExactAnnotationTypePattern annotationTypePattern; private ShadowMunger munger; private String declarationText; - private static final Set thisKindSet = new HashSet(Shadow.ALL_SHADOW_KINDS); - private static final Set targetKindSet = new HashSet(Shadow.ALL_SHADOW_KINDS); + + private static final int thisKindSet; + private static final int targetKindSet; + static { - for (Iterator iter = Shadow.ALL_SHADOW_KINDS.iterator(); iter.hasNext();) { - Shadow.Kind kind = (Shadow.Kind) iter.next(); - if (kind.neverHasThis()) thisKindSet.remove(kind); - if (kind.neverHasTarget()) targetKindSet.remove(kind); + int thisFlags = Shadow.ALL_SHADOW_KINDS_BITS; + int targFlags = Shadow.ALL_SHADOW_KINDS_BITS; + for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) { + Shadow.Kind kind = Shadow.SHADOW_KINDS[i]; + if (kind.neverHasThis()) thisFlags-=kind.bit; + if (kind.neverHasTarget()) targFlags-=kind.bit; } + thisKindSet = thisFlags; + targetKindSet=targFlags; } /** @@ -77,7 +80,7 @@ public class ThisOrTargetAnnotationPointcut extends NameBindingPointcut { return annotationTypePattern; } - public Set couldMatchKinds() { + public int couldMatchKinds() { return isThis ? thisKindSet : targetKindSet; } diff --git a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java index 862000825..c50577323 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java @@ -17,11 +17,8 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.MessageUtil; @@ -56,16 +53,22 @@ public class ThisOrTargetPointcut extends NameBindingPointcut { private TypePattern type; private String declarationText; - private static final Set thisKindSet = new HashSet(Shadow.ALL_SHADOW_KINDS); - private static final Set targetKindSet = new HashSet(Shadow.ALL_SHADOW_KINDS); + private static final int thisKindSet; + private static final int targetKindSet; + static { - for (Iterator iter = Shadow.ALL_SHADOW_KINDS.iterator(); iter.hasNext();) { - Shadow.Kind kind = (Shadow.Kind) iter.next(); - if (kind.neverHasThis()) thisKindSet.remove(kind); - if (kind.neverHasTarget()) targetKindSet.remove(kind); + int thisFlags = Shadow.ALL_SHADOW_KINDS_BITS; + int targFlags = Shadow.ALL_SHADOW_KINDS_BITS; + for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) { + Shadow.Kind kind = Shadow.SHADOW_KINDS[i]; + if (kind.neverHasThis()) thisFlags-=kind.bit; + if (kind.neverHasTarget()) targFlags-=kind.bit; } + thisKindSet = thisFlags; + targetKindSet=targFlags; } + public boolean isBinding() { return (type instanceof BindingTypePattern); } @@ -89,7 +92,7 @@ public class ThisOrTargetPointcut extends NameBindingPointcut { return ret; } - public Set couldMatchKinds() { + public int couldMatchKinds() { return isThis ? thisKindSet : targetKindSet; } diff --git a/weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java index 5996464d7..f2c5d8a88 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java @@ -15,7 +15,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.MessageUtil; @@ -65,8 +64,8 @@ public class WithinAnnotationPointcut extends NameBindingPointcut { return annotationTypePattern; } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } public Pointcut parameterizeWith(Map typeVariableMap) { diff --git a/weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java index 7022d2cee..cb0295c06 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java @@ -13,10 +13,8 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.MessageUtil; import org.aspectj.util.FuzzyBoolean; @@ -48,13 +46,15 @@ public class WithinCodeAnnotationPointcut extends NameBindingPointcut { private ExactAnnotationTypePattern annotationTypePattern; private ShadowMunger munger = null; // only set after concretization private String declarationText; - private static final Set matchedShadowKinds = new HashSet(); + + private static final int matchedShadowKinds; static { - matchedShadowKinds.addAll(Shadow.ALL_SHADOW_KINDS); + int flags = Shadow.ALL_SHADOW_KINDS_BITS; for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) { if (Shadow.SHADOW_KINDS[i].isEnclosingKind()) - matchedShadowKinds.remove(Shadow.SHADOW_KINDS[i]); + flags -= Shadow.SHADOW_KINDS[i].bit; } + matchedShadowKinds=flags; } public WithinCodeAnnotationPointcut(ExactAnnotationTypePattern type) { @@ -74,7 +74,7 @@ public class WithinCodeAnnotationPointcut extends NameBindingPointcut { return annotationTypePattern; } - public Set couldMatchKinds() { + public int couldMatchKinds() { return matchedShadowKinds; } diff --git a/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java b/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java index 5e893256a..3b213be0a 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java @@ -16,7 +16,6 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.MessageUtil; @@ -52,8 +51,8 @@ public class WithinPointcut extends Pointcut { return FuzzyBoolean.NO; } - public Set couldMatchKinds() { - return Shadow.ALL_SHADOW_KINDS; + public int couldMatchKinds() { + return Shadow.ALL_SHADOW_KINDS_BITS; } public Pointcut parameterizeWith(Map typeVariableMap) { diff --git a/weaver/src/org/aspectj/weaver/patterns/WithincodePointcut.java b/weaver/src/org/aspectj/weaver/patterns/WithincodePointcut.java index 88315200a..b3fcf03cb 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WithincodePointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/WithincodePointcut.java @@ -15,9 +15,7 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import org.aspectj.bridge.MessageUtil; import org.aspectj.util.FuzzyBoolean; @@ -32,16 +30,17 @@ import org.aspectj.weaver.ast.Test; public class WithincodePointcut extends Pointcut { private SignaturePattern signature; - private static final Set matchedShadowKinds = new HashSet(); + private static final int matchedShadowKinds; static { - matchedShadowKinds.addAll(Shadow.ALL_SHADOW_KINDS); + int flags = Shadow.ALL_SHADOW_KINDS_BITS; for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) { if (Shadow.SHADOW_KINDS[i].isEnclosingKind()) - matchedShadowKinds.remove(Shadow.SHADOW_KINDS[i]); + flags -= Shadow.SHADOW_KINDS[i].bit; } // these next two are needed for inlining of field initializers - matchedShadowKinds.add(Shadow.ConstructorExecution); - matchedShadowKinds.add(Shadow.Initialization); + flags|=Shadow.ConstructorExecution.bit; + flags|=Shadow.Initialization.bit; + matchedShadowKinds = flags; } public WithincodePointcut(SignaturePattern signature) { @@ -53,7 +52,7 @@ public class WithincodePointcut extends Pointcut { return signature; } - public Set couldMatchKinds() { + public int couldMatchKinds() { return matchedShadowKinds; } diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/PointcutRewriterTest.java b/weaver/testsrc/org/aspectj/weaver/patterns/PointcutRewriterTest.java index 84a32ddb1..3684e9d86 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/PointcutRewriterTest.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/PointcutRewriterTest.java @@ -212,73 +212,73 @@ public class PointcutRewriterTest extends TestCase { public void testDetermineKindSetOfAnd() { Pointcut oneKind = getPointcut("execution(* foo(..)) && this(Boo)"); AndPointcut rewritten = (AndPointcut) prw.rewrite(oneKind); - assertEquals("Only one kind",1,rewritten.couldMatchKinds().size()); - assertTrue("It's Shadow.MethodExecution",rewritten.couldMatchKinds().contains(Shadow.MethodExecution)); + assertEquals("Only one kind",1,Shadow.howMany(rewritten.couldMatchKinds())); + assertTrue("It's Shadow.MethodExecution",Shadow.MethodExecution.isSet(rewritten.couldMatchKinds())); } public void testKindSetOfExecution() { Pointcut p = getPointcut("execution(* foo(..))"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.MethodExecution",p.couldMatchKinds().contains(Shadow.MethodExecution)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.MethodExecution",Shadow.MethodExecution.isSet(p.couldMatchKinds())); p = getPointcut("execution(new(..))"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.ConstructorExecution",p.couldMatchKinds().contains(Shadow.ConstructorExecution)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.ConstructorExecution",Shadow.ConstructorExecution.isSet(p.couldMatchKinds())); } public void testKindSetOfCall() { Pointcut p = getPointcut("call(* foo(..))"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.MethodCall",p.couldMatchKinds().contains(Shadow.MethodCall)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.MethodCall",Shadow.MethodCall.isSet(p.couldMatchKinds())); p = getPointcut("call(new(..))"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.ConstructorCall",p.couldMatchKinds().contains(Shadow.ConstructorCall)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.ConstructorCall",Shadow.ConstructorCall.isSet(p.couldMatchKinds())); } public void testKindSetOfAdviceExecution() { Pointcut p = getPointcut("adviceexecution()"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.AdviceExecution",p.couldMatchKinds().contains(Shadow.AdviceExecution)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.AdviceExecution",Shadow.AdviceExecution.isSet(p.couldMatchKinds())); } public void testKindSetOfGet() { Pointcut p = getPointcut("get(* *)"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.FieldGet",p.couldMatchKinds().contains(Shadow.FieldGet)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.FieldGet",Shadow.FieldGet.isSet(p.couldMatchKinds())); } public void testKindSetOfSet() { Pointcut p = getPointcut("set(* *)"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.FieldSet",p.couldMatchKinds().contains(Shadow.FieldSet)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.FieldSet",Shadow.FieldSet.isSet(p.couldMatchKinds())); } public void testKindSetOfHandler() { Pointcut p = getPointcut("handler(*)"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.ExceptionHandler",p.couldMatchKinds().contains(Shadow.ExceptionHandler)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.ExceptionHandler",Shadow.ExceptionHandler.isSet(p.couldMatchKinds())); } public void testKindSetOfInitialization() { Pointcut p = getPointcut("initialization(new (..))"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.Initialization",p.couldMatchKinds().contains(Shadow.Initialization)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.Initialization",Shadow.Initialization.isSet(p.couldMatchKinds())); } public void testKindSetOfPreInitialization() { Pointcut p = getPointcut("preinitialization(new (..))"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.PreInitialization",p.couldMatchKinds().contains(Shadow.PreInitialization)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.PreInitialization",Shadow.PreInitialization.isSet(p.couldMatchKinds())); } public void testKindSetOfStaticInitialization() { Pointcut p = getPointcut("staticinitialization(*)"); - assertEquals("Only one kind",1,p.couldMatchKinds().size()); - assertTrue("It's Shadow.StaticInitialization",p.couldMatchKinds().contains(Shadow.StaticInitialization)); + assertEquals("Only one kind",1,Shadow.howMany(p.couldMatchKinds())); + assertTrue("It's Shadow.StaticInitialization",Shadow.StaticInitialization.isSet(p.couldMatchKinds())); } public void testKindSetOfThis() { Pointcut p = getPointcut("this(Foo)"); - Set matches = p.couldMatchKinds(); + Set matches = Shadow.toSet(p.couldMatchKinds()); for (Iterator iter = matches.iterator(); iter.hasNext();) { Shadow.Kind kind = (Shadow.Kind) iter.next(); assertFalse("No kinds that don't have a this",kind.neverHasThis()); @@ -290,7 +290,7 @@ public class PointcutRewriterTest extends TestCase { } // + @ p = getPointcut("@this(Foo)"); - matches = p.couldMatchKinds(); + matches = Shadow.toSet(p.couldMatchKinds()); for (Iterator iter = matches.iterator(); iter.hasNext();) { Shadow.Kind kind = (Shadow.Kind) iter.next(); assertFalse("No kinds that don't have a this",kind.neverHasThis()); @@ -304,7 +304,7 @@ public class PointcutRewriterTest extends TestCase { public void testKindSetOfTarget() { Pointcut p = getPointcut("target(Foo)"); - Set matches = p.couldMatchKinds(); + Set matches = Shadow.toSet(p.couldMatchKinds()); for (Iterator iter = matches.iterator(); iter.hasNext();) { Shadow.Kind kind = (Shadow.Kind) iter.next(); assertFalse("No kinds that don't have a target",kind.neverHasTarget()); @@ -316,7 +316,7 @@ public class PointcutRewriterTest extends TestCase { } // + @ p = getPointcut("@target(Foo)"); - matches = p.couldMatchKinds(); + matches = Shadow.toSet(p.couldMatchKinds()); for (Iterator iter = matches.iterator(); iter.hasNext();) { Shadow.Kind kind = (Shadow.Kind) iter.next(); assertFalse("No kinds that don't have a target",kind.neverHasTarget()); @@ -330,28 +330,28 @@ public class PointcutRewriterTest extends TestCase { public void testKindSetOfArgs() { Pointcut p = getPointcut("args(..)"); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); // + @ p = getPointcut("@args(..)"); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); } public void testKindSetOfAnnotation() { Pointcut p = getPointcut("@annotation(Foo)"); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); } public void testKindSetOfWithin() { Pointcut p = getPointcut("within(*)"); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); // + @ p = getPointcut("@within(Foo)"); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); } public void testKindSetOfWithinCode() { Pointcut p = getPointcut("withincode(* foo(..))"); - Set matches = p.couldMatchKinds(); + Set matches = Shadow.toSet(p.couldMatchKinds()); for (Iterator iter = matches.iterator(); iter.hasNext();) { Shadow.Kind kind = (Shadow.Kind) iter.next(); assertFalse("No kinds that are themselves enclosing", @@ -366,7 +366,7 @@ public class PointcutRewriterTest extends TestCase { assertTrue("Need init for inlined field inits",matches.contains(Shadow.Initialization)); // + @ p = getPointcut("@withincode(Foo)"); - matches = p.couldMatchKinds(); + matches = Shadow.toSet(p.couldMatchKinds()); for (Iterator iter = matches.iterator(); iter.hasNext();) { Shadow.Kind kind = (Shadow.Kind) iter.next(); assertFalse("No kinds that are themselves enclosing",kind.isEnclosingKind()); @@ -380,29 +380,29 @@ public class PointcutRewriterTest extends TestCase { public void testKindSetOfIf() { Pointcut p = new IfPointcut(null,0); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); p = IfPointcut.makeIfTruePointcut(Pointcut.CONCRETE); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); p = IfPointcut.makeIfFalsePointcut(Pointcut.CONCRETE); - assertTrue("Nothing",p.couldMatchKinds().isEmpty()); + assertTrue("Nothing",p.couldMatchKinds()==Shadow.NO_SHADOW_KINDS_BITS); } public void testKindSetOfCflow() { Pointcut p = getPointcut("cflow(this(Foo))"); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); // [below] p = getPointcut("cflowbelow(this(Foo))"); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); } public void testKindSetInNegation() { Pointcut p = getPointcut("!execution(new(..))"); - assertTrue("All kinds",p.couldMatchKinds().containsAll(Shadow.ALL_SHADOW_KINDS)); + assertTrue("All kinds",p.couldMatchKinds()==Shadow.ALL_SHADOW_KINDS_BITS); } public void testKindSetOfOr() { Pointcut p = getPointcut("execution(new(..)) || get(* *)"); - Set matches = p.couldMatchKinds(); + Set matches = Shadow.toSet(p.couldMatchKinds()); assertEquals("2 kinds",2,matches.size()); assertTrue("ConstructorExecution",matches.contains(Shadow.ConstructorExecution)); assertTrue("FieldGet",matches.contains(Shadow.FieldGet)); -- 2.39.5