public ISourceContext getSourceContext() {
return new ISourceContext() {
+ @Override
public ISourceLocation makeSourceLocation(IHasPosition position) {
return null;
}
+ @Override
public ISourceLocation makeSourceLocation(int line, int offset) {
return null;
}
+ @Override
public int getOffset() {
return 0;
}
+ @Override
public void tidy() {
}
return isAssignableFrom(other);
}
}
-
+
/*
* (non-Javadoc)
*
*
* @see org.aspectj.weaver.AnnotatedElement#hasAnnotation(org.aspectj.weaver.UnresolvedType)
*/
+ @Override
public boolean hasAnnotation(UnresolvedType ofType) {
raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_ANNOTATION);
return false;
this.testPointcut = testPointcut;
}
+ @Override
public boolean equals(Object other) {
if (!(other instanceof PerTypeWithinTargetTypeMunger)) {
return false;
private volatile int hashCode = 0;
+ @Override
public int hashCode() {
if (hashCode == 0) {
int result = 17;
return hashCode;
}
+ @Override
public void write(CompressingDataOutputStream s) throws IOException {
throw new RuntimeException("shouldn't be serialized");
}
// This is a lexical within() so if you say PerTypeWithin(Test) and matchType is an
// inner type (e.g. Test$NestedType) then it should match successfully
// Does not match if the target is an interface
+ @Override
public boolean matches(ResolvedType matchType, ResolvedType aspectType) {
- return isWithinType(matchType).alwaysTrue() && !matchType.isInterface();
+ return isWithinType(matchType).alwaysTrue() && !matchType.isInterface() && (matchType.canBeSeenBy(aspectType) || aspectType.isPrivilegedAspect());
}
private FuzzyBoolean isWithinType(ResolvedType type) {
}
return FuzzyBoolean.NO;
}
-
+
}
private static int TypeHierarchyCompleteBit = 0x0010;
private static int GroovyObjectInitialized = 0x0020;
private static int IsGroovyObject = 0x0040;
+ private static int IsPrivilegedBitInitialized = 0x0080;
+ private static int IsPrivilegedAspect = 0x0100;
protected ResolvedType(String signature, World world) {
super(signature);
this.world = world;
}
+ @Override
public int getSize() {
return 1;
}
public abstract int getModifiers();
+ public boolean canBeSeenBy(ResolvedType from) {
+ int targetMods = getModifiers();
+ if (Modifier.isPublic(targetMods)) {
+ return true;
+ }
+ if (Modifier.isPrivate(targetMods)) {
+ return false;
+ }
+ // isProtected() or isDefault()
+ return getPackageName().equals(from.getPackageName());
+ }
+
// return true if this resolved type couldn't be found (but we know it's name maybe)
public boolean isMissing() {
return false;
}
}
+ @Override
public ResolvedType[] getAnnotationTypes() {
return EMPTY_RESOLVED_TYPE_ARRAY;
}
+ @Override
public AnnotationAJ getAnnotationOfType(UnresolvedType ofType) {
return null;
}
public Iterator<ResolvedMember> getFields() {
final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
+ @Override
public Iterator<ResolvedType> get(ResolvedType o) {
return dupFilter.filter(o.getDirectSupertypes());
}
* An Iterators.Getter that returns an iterator over all methods declared on some resolved type.
*/
private static class MethodGetter implements Iterators.Getter<ResolvedType, ResolvedMember> {
+ @Override
public Iterator<ResolvedMember> get(ResolvedType type) {
return Iterators.array(type.getDeclaredMethods());
}
* An Iterators.Getter that returns an iterator over all pointcuts declared on some resolved type.
*/
private static class PointcutGetter implements Iterators.Getter<ResolvedType, ResolvedMember> {
+ @Override
public Iterator<ResolvedMember> get(ResolvedType o) {
return Iterators.array(o.getDeclaredPointcuts());
}
// Getter that returns all declared methods for a type through an iterator - including intertype declarations
private static class MethodGetterIncludingItds implements Iterators.Getter<ResolvedType, ResolvedMember> {
+ @Override
public Iterator<ResolvedMember> get(ResolvedType type) {
ResolvedMember[] methods = type.getDeclaredMethods();
if (type.interTypeMungers != null) {
* An Iterators.Getter that returns an iterator over all fields declared on some resolved type.
*/
private static class FieldGetter implements Iterators.Getter<ResolvedType, ResolvedMember> {
+ @Override
public Iterator<ResolvedMember> get(ResolvedType type) {
return Iterators.array(type.getDeclaredFields());
}
final Iterators.Getter<ResolvedType, ResolvedType> interfaceGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
List<String> alreadySeen = new ArrayList<String>(); // Strings are signatures (ResolvedType.getSignature())
+ @Override
public Iterator<ResolvedType> get(ResolvedType type) {
ResolvedType[] interfaces = type.getDeclaredInterfaces();
final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
// same order as fields
Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
+ @Override
public Iterator<ResolvedType> get(ResolvedType o) {
return dupFilter.filter(o.getDirectSupertypes());
}
// ret.addAll(getDeclares());
final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
+ @Override
public Iterator<ResolvedType> get(ResolvedType o) {
return dupFilter.filter((o).getDirectSupertypes());
}
List<ShadowMunger> acc = new ArrayList<ShadowMunger>();
final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
+ @Override
public Iterator<ResolvedType> get(ResolvedType o) {
return dupFilter.filter((o).getDirectSupertypes());
}
public final int getSize() {
return size;
}
-
+
@Override
public final int getModifiers() {
return Modifier.PUBLIC | Modifier.FINAL;
return true;
}
+ @Override
public boolean hasAnnotation(UnresolvedType ofType) {
return false;
}
return true;
}
+ @Override
public boolean hasAnnotation(UnresolvedType ofType) {
return false;
}
this.wantGenerics = genericsAware;
}
+ @Override
public boolean hasNext() {
return curr != null;
}
+ @Override
public ResolvedType next() {
ResolvedType ret = curr;
if (!wantGenerics && ret.isParameterizedOrGenericType()) {
return ret;
}
+ @Override
public void remove() {
throw new UnsupportedOperationException();
}
this.delegate = Iterators.one(interfaceType);
}
+ @Override
public boolean hasNext() {
if (delegate == null || !delegate.hasNext()) {
// either we set it up or we have run out, is there anything else to look at?
toPersue.add(ret);
}
+ @Override
public ResolvedType next() {
ResolvedType next = delegate.next();
// BUG should check for generics and erase?
return next;
}
+ @Override
public void remove() {
throw new UnsupportedOperationException();
}
}
return (bits & IsGroovyObject) != 0;
}
+
+ public boolean isPrivilegedAspect() {
+ if ((bits & IsPrivilegedBitInitialized) == 0) {
+ AnnotationAJ privilegedAnnotation = getAnnotationOfType(UnresolvedType.AJC_PRIVILEGED);
+ if (privilegedAnnotation != null) {
+ bits |= IsPrivilegedAspect;
+ }
+ // TODO do we need to reset this bit if the annotations are set again ?
+ bits |= IsPrivilegedBitInitialized;
+ }
+ return (bits & IsPrivilegedAspect) != 0;
+ }
}
public static final UnresolvedType[] ARRAY_WITH_JUST_OBJECT = new UnresolvedType[] { OBJECT };
public static final UnresolvedType JOINPOINT_STATICPART = forSignature("Lorg/aspectj/lang/JoinPoint$StaticPart;");
public static final UnresolvedType JOINPOINT_ENCLOSINGSTATICPART = forSignature("Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart;");
+ public static final UnresolvedType AJC_PRIVILEGED = forSignature("Lorg/aspectj/internal/lang/annotation/ajcPrivileged;");
public static final UnresolvedType BOOLEAN = forPrimitiveType("Z");
public static final UnresolvedType BYTE = forPrimitiveType("B");
private final String type;
}
+ @Override
public TypeVariable getTypeVariableNamed(String name) {
TypeVariable[] vars = getTypeVariables();
if (vars == null || vars.length == 0) {
return null;
}
+ @Override
public String toTraceString() {
return getClass().getName() + "[" + getName() + "]";
}
typePattern = p;
}
+ @Override
public Object accept(PatternNodeVisitor visitor, Object data) {
return visitor.visit(this, data);
}
+ @Override
public int couldMatchKinds() {
return kindSet;
}
+ @Override
public Pointcut parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
PerTypeWithin ret = new PerTypeWithin(typePattern.parameterizeWith(typeVariableMap, w));
ret.copyLocationFrom(this);
}
// -----
+ @Override
public FuzzyBoolean fastMatch(FastMatchInfo info) {
if (typePattern.annotationPattern instanceof AnyAnnotationTypePattern) {
return isWithinType(info.getType());
return FuzzyBoolean.MAYBE;
}
+ @Override
protected FuzzyBoolean matchInternal(Shadow shadow) {
ResolvedType enclosingType = shadow.getIWorld().resolve(shadow.getEnclosingType(), true);
if (enclosingType.isMissing()) {
if (enclosingType.isInterface()) {
return FuzzyBoolean.NO;
}
+ if (!(enclosingType.canBeSeenBy(inAspect) || inAspect.isPrivilegedAspect())) {
+ return FuzzyBoolean.NO;
+ }
typePattern.resolve(shadow.getIWorld());
return isWithinType(enclosingType);
}
+ @Override
public void resolveBindings(IScope scope, Bindings bindings) {
typePattern = typePattern.resolveBindings(scope, bindings, false, false);
}
+ @Override
protected Test findResidueInternal(Shadow shadow, ExposedState state) {
// Member ptwField =
// AjcMemberMaker.perTypeWithinField(shadow.getEnclosingType
return match(shadow).alwaysTrue() ? Literal.TRUE : Literal.FALSE;
}
+ @Override
public PerClause concretize(ResolvedType inAspect) {
PerTypeWithin ret = new PerTypeWithin(typePattern);
ret.copyLocationFrom(this);
Pointcut staticInitStar = new KindedPointcut(Shadow.StaticInitialization, sigpat);
Pointcut withinTp = new WithinPointcut(typePattern);
Pointcut andPcut = new AndPointcut(staticInitStar, withinTp);
- // We want the pointcut to be 'staticinitialization(*) &&
- // within(<typepattern>' -
+ // We want the pointcut to be:
+ // 'staticinitialization(*) && within(<typepattern>)' -
// we *cannot* shortcut this to staticinitialization(<typepattern>)
- // because it
- // doesnt mean the same thing.
+ // because it doesnt mean the same thing.
- // This munger will initialize the aspect instance field in the matched
- // type
+ // This munger will initialize the aspect instance field in the matched type
inAspect.crosscuttingMembers.addConcreteShadowMunger(Advice.makePerTypeWithinEntry(world, andPcut, inAspect));
}
+ @Override
public void write(CompressingDataOutputStream s) throws IOException {
PERTYPEWITHIN.write(s);
typePattern.write(s);
return ret;
}
+ @Override
public PerClause.Kind getKind() {
return PERTYPEWITHIN;
}
+ @Override
public String toString() {
return "pertypewithin(" + typePattern + ")";
}
+ @Override
public String toDeclarationString() {
return toString();
}
return FuzzyBoolean.NO;
}
+ @Override
public boolean equals(Object other) {
if (!(other instanceof PerTypeWithin)) {
return false;
&& ((pc.typePattern == null) ? (typePattern == null) : pc.typePattern.equals(typePattern));
}
+ @Override
public int hashCode() {
int result = 17;
result = 37 * result + ((inAspect == null) ? 0 : inAspect.hashCode());
import org.aspectj.systemtest.ajc190.AllTestsAspectJ190;
import org.aspectj.systemtest.ajc191.AllTestsAspectJ191;
+import org.aspectj.systemtest.ajc192.AllTestsAspectJ192;
import junit.framework.Test;
import junit.framework.TestSuite;
// $JUnit-BEGIN$
suite.addTest(AllTestsAspectJ190.suite());
suite.addTest(AllTestsAspectJ191.suite());
+ suite.addTest(AllTestsAspectJ192.suite());
suite.addTest(AllTests18.suite());
// $JUnit-END$
return suite;
return getThisJoinPointStaticPartBcelVar(false);
}
+ @Override
public BcelVar getThisAspectInstanceVar(ResolvedType aspectType) {
return new AspectInstanceVar(aspectType);
}
* Causes the aspect instance to be *set* for later retrievable through localAspectof()/aspectOf()
*/
public void weavePerTypeWithinAspectInitialization(final BcelAdvice munger, UnresolvedType t) {
-
- if (t.resolve(world).isInterface()) {
- return; // Don't initialize statics in
+ ResolvedType tResolved = t.resolve(world);
+ if (tResolved.isInterface()) {
+ return; // Don't initialize statics in interfaces
+ }
+ ResolvedType aspectRT = munger.getConcreteAspect();
+ BcelWorld.getBcelObjectType(aspectRT);
+
+ // Although matched, if the visibility rules prevent the aspect from seeing this type, don't
+ // insert any code (easier to do it here than try to affect the matching logic, unfortunately)
+ if (!(tResolved.canBeSeenBy(aspectRT) || aspectRT.isPrivilegedAspect())) {
+ return;
}
+
final InstructionFactory fact = getFactory();
InstructionList entryInstructions = new InstructionList();
InstructionList entrySuccessInstructions = new InstructionList();
- BcelWorld.getBcelObjectType(munger.getConcreteAspect());
String aspectname = munger.getConcreteAspect().getName();
String ptwField = NameMangler.perTypeWithinFieldForTarget(munger.getConcreteAspect());
// e.g ajc$com_blah_SecurityAspect$ptwAspectInstance
FieldGen fg = makeFieldGen(gen, AjcMemberMaker.perTypeWithinField(gen.getType(), aspectType));
gen.addField(fg, getSourceLocation());
-
+ if (!gen.getType().canBeSeenBy(aspectType) && aspectType.isPrivilegedAspect()) {
+ gen.forcePublic();
+ }
// Add an accessor for this new field, the
// ajc$<aspectname>$localAspectOf() method
// e.g.