diff options
author | aclement <aclement> | 2005-11-30 17:23:35 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-11-30 17:23:35 +0000 |
commit | 2c8190702e95baf0489e384767c816f30d870c86 (patch) | |
tree | 7b1d55dd1a67a1c078b1c9c16f3aa3b649d74982 /weaver | |
parent | fcb16b97f4c2ca11e3f02b5e2b396932764b010d (diff) | |
download | aspectj-2c8190702e95baf0489e384767c816f30d870c86.tar.gz aspectj-2c8190702e95baf0489e384767c816f30d870c86.zip |
implementation of new xlint: pr111667
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/org/aspectj/weaver/Lint.java | 3 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/Shadow.java | 60 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/World.java | 7 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/XlintDefault.properties | 2 |
4 files changed, 72 insertions, 0 deletions
diff --git a/weaver/src/org/aspectj/weaver/Lint.java b/weaver/src/org/aspectj/weaver/Lint.java index 5380ecfdf..92dc373c5 100644 --- a/weaver/src/org/aspectj/weaver/Lint.java +++ b/weaver/src/org/aspectj/weaver/Lint.java @@ -108,6 +108,9 @@ public class Lint { public final Kind aspectExcludedByConfiguration = new Kind("aspectExcludedByConfiguration","aspect {0} exluded for class loader {1}"); + public final Kind unorderedAdviceAtShadow = + new Kind("unorderedAdviceAtShadow","at this shadow {0} no precedence is specified between advice applying from aspect {1} and aspect {2}"); + // there are a lot of messages in the cant find type family - I'm defining an umbrella lint warning that // allows a user to control their severity (for e.g. ltw or binary weaving) public final Kind cantFindType = diff --git a/weaver/src/org/aspectj/weaver/Shadow.java b/weaver/src/org/aspectj/weaver/Shadow.java index 5de7a60ef..4dc7a9703 100644 --- a/weaver/src/org/aspectj/weaver/Shadow.java +++ b/weaver/src/org/aspectj/weaver/Shadow.java @@ -406,7 +406,12 @@ public abstract class Shadow { } private void sortMungers() { + List sorted = PartialOrder.sort(mungers); + + // Bunch of code to work out whether to report xlints for advice that isn't ordered at this Joinpoint + possiblyReportUnorderedAdvice(sorted); + if (sorted == null) { // this means that we have circular dependencies for (Iterator i = mungers.iterator(); i.hasNext(); ) { @@ -418,6 +423,61 @@ public abstract class Shadow { } mungers = sorted; } + + // not quite optimal... but the xlint is ignore by default + private void possiblyReportUnorderedAdvice(List sorted) { + if (sorted!=null && getIWorld().getLint().unorderedAdviceAtShadow.isEnabled() && mungers.size()>1) { + + // Stores a set of strings of the form 'aspect1:aspect2' which indicates there is no + // precedence specified between the two aspects at this shadow. + Set clashingAspects = new HashSet(); + int max = mungers.size(); + + // Compare every pair of advice mungers + for (int i = max-1; i >=0; i--) { + for (int j=0; j<i; j++) { + Object a = mungers.get(i); + Object b = mungers.get(j); + + // Make sure they are the right type + if (a instanceof BcelAdvice && b instanceof BcelAdvice) { + BcelAdvice adviceA = (BcelAdvice)a; + BcelAdvice adviceB = (BcelAdvice)b; + if (!adviceA.concreteAspect.equals(adviceB.concreteAspect)) { + AdviceKind adviceKindA = adviceA.getKind(); + AdviceKind adviceKindB = adviceB.getKind(); + + // make sure they are the nice ones (<6) and not any synthetic advice ones we + // create to support other features of the language. + if (adviceKindA.getKey()<(byte)6 && adviceKindB.getKey()<(byte)6 && + adviceKindA.getPrecedence() == adviceKindB.getPrecedence()) { + + // Ask the world if it knows about precedence between these + Integer order = getIWorld().getPrecedenceIfAny( + adviceA.concreteAspect, + adviceB.concreteAspect); + + if (order!=null && + order.equals(new Integer(0))) { + String key = adviceA.getDeclaringAspect()+":"+adviceB.getDeclaringAspect(); + String possibleExistingKey = adviceB.getDeclaringAspect()+":"+adviceA.getDeclaringAspect(); + if (!clashingAspects.contains(possibleExistingKey)) clashingAspects.add(key); + } + } + } + } + } + } + for (Iterator iter = clashingAspects.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + String aspect1 = element.substring(0,element.indexOf(":")); + String aspect2 = element.substring(element.indexOf(":")+1); + getIWorld().getLint().unorderedAdviceAtShadow.signal( + new String[]{this.toString(),aspect1,aspect2}, + this.getSourceLocation(),null); + } + } + } /** Prepare the shadow for implementation. After this is done, the shadow * should be in such a position that each munger simply needs to be implemented. diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index 5101d7641..b353a7241 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -498,6 +498,9 @@ public abstract class World implements Dump.INode { public int compareByPrecedence(ResolvedType aspect1, ResolvedType aspect2) { return precedenceCalculator.compareByPrecedence(aspect1, aspect2); } + public Integer getPrecedenceIfAny(ResolvedType aspect1, ResolvedType aspect2) { + return precedenceCalculator.getPrecedenceIfAny(aspect1, aspect2); + } /** * compares by precedence with the additional rule that a super-aspect is @@ -811,6 +814,10 @@ public abstract class World implements Dump.INode { } } + public Integer getPrecedenceIfAny(ResolvedType aspect1,ResolvedType aspect2) { + return (Integer)cachedResults.get(new PrecedenceCacheKey(aspect1,aspect2)); + } + public int compareByPrecedenceAndHierarchy(ResolvedType firstAspect, ResolvedType secondAspect) { if (firstAspect.equals(secondAspect)) return 0; diff --git a/weaver/src/org/aspectj/weaver/XlintDefault.properties b/weaver/src/org/aspectj/weaver/XlintDefault.properties index 2e0f7baac..2fc6d25d2 100644 --- a/weaver/src/org/aspectj/weaver/XlintDefault.properties +++ b/weaver/src/org/aspectj/weaver/XlintDefault.properties @@ -37,3 +37,5 @@ unmatchedTargetKind = warning cantFindType = error cantFindTypeAffectingJPMatch = warning + +unorderedAdviceAtShadow=ignore |