Browse Source

255555: pattern parser allowing for parentheses around declare anno signatures; cope with weaving broken code.

tags/V1_6_3rc1
aclement 15 years ago
parent
commit
89d94f1b41

+ 22
- 31
org.aspectj.matcher/src/org/aspectj/weaver/patterns/DeclareAnnotation.java View File

@@ -101,8 +101,7 @@ public class DeclareAnnotation extends Declare {
ret.append("declare @");
ret.append(kind);
ret.append(" : ");
ret.append(typePattern != null ? typePattern.toString() : sigPattern
.toString());
ret.append(typePattern != null ? typePattern.toString() : sigPattern.toString());
ret.append(" : ");
ret.append(annotationString);
return ret.toString();
@@ -124,13 +123,11 @@ public class DeclareAnnotation extends Declare {
} else if (kind == AT_CONSTRUCTOR) {
msg = WeaverMessages.DECLARE_ATCONS_ONLY_SUPPORTED_AT_JAVA5_LEVEL;
}
scope.message(MessageUtil.error(WeaverMessages.format(msg),
getSourceLocation()));
scope.message(MessageUtil.error(WeaverMessages.format(msg), getSourceLocation()));
return;
}
if (typePattern != null) {
typePattern = typePattern.resolveBindings(scope, Bindings.NONE,
false, false);
typePattern = typePattern.resolveBindings(scope, Bindings.NONE, false, false);
}
if (sigPattern != null) {
sigPattern = sigPattern.resolveBindings(scope, Bindings.NONE);
@@ -141,11 +138,9 @@ public class DeclareAnnotation extends Declare {
public Declare parameterizeWith(Map typeVariableBindingMap, World w) {
DeclareAnnotation ret;
if (this.kind == AT_TYPE) {
ret = new DeclareAnnotation(kind, this.typePattern
.parameterizeWith(typeVariableBindingMap, w));
ret = new DeclareAnnotation(kind, this.typePattern.parameterizeWith(typeVariableBindingMap, w));
} else {
ret = new DeclareAnnotation(kind, this.sigPattern.parameterizeWith(
typeVariableBindingMap, w));
ret = new DeclareAnnotation(kind, this.sigPattern.parameterizeWith(typeVariableBindingMap, w));
}
ret.annotationMethod = this.annotationMethod;
ret.annotationString = this.annotationString;
@@ -203,8 +198,7 @@ public class DeclareAnnotation extends Declare {
/*
* (non-Javadoc)
*
* @see
* org.aspectj.weaver.patterns.PatternNode#write(java.io.DataOutputStream)
* @see org.aspectj.weaver.patterns.PatternNode#write(java.io.DataOutputStream)
*/
public void write(DataOutputStream s) throws IOException {
s.writeByte(Declare.ANNOTATION);
@@ -218,8 +212,7 @@ public class DeclareAnnotation extends Declare {
writeLocation(s);
}

public static Declare read(VersionedDataInputStream s,
ISourceContext context) throws IOException {
public static Declare read(VersionedDataInputStream s, ISourceContext context) throws IOException {
DeclareAnnotation ret = null;
int kind = s.readInt();
String annotationString = s.readUTF();
@@ -275,10 +268,8 @@ public class DeclareAnnotation extends Declare {
public boolean matches(ResolvedType typeX) {
if (!typePattern.matchesStatically(typeX))
return false;
if (typeX.getWorld().getLint().typeNotExposedToWeaver.isEnabled()
&& !typeX.isExposedToWeaver()) {
typeX.getWorld().getLint().typeNotExposedToWeaver.signal(typeX
.getName(), getSourceLocation());
if (typeX.getWorld().getLint().typeNotExposedToWeaver.isEnabled() && !typeX.isExposedToWeaver()) {
typeX.getWorld().getLint().typeNotExposedToWeaver.signal(typeX.getName(), getSourceLocation());
}
return true;
}
@@ -304,9 +295,8 @@ public class DeclareAnnotation extends Declare {
}

/**
* The annotation specified in the declare @type is stored against a simple
* method of the form "ajc$declare_<NN>", this method finds that method and
* retrieves the annotation
* The annotation specified in the declare @type is stored against a simple method of the form "ajc$declare_<NN>", this method
* finds that method and retrieves the annotation
*/
private void ensureAnnotationDiscovered() {
if (annotation != null)
@@ -314,7 +304,12 @@ public class DeclareAnnotation extends Declare {
for (Iterator iter = containingAspect.getMethods(); iter.hasNext();) {
ResolvedMember member = (ResolvedMember) iter.next();
if (member.getName().equals(annotationMethod)) {
annotation = member.getAnnotations()[0];
AnnotationAJ[] annos = member.getAnnotations();
if (annos == null) {
// if weaving broken code, this can happen
return;
}
annotation = annos[0];
}
}
}
@@ -332,8 +327,7 @@ public class DeclareAnnotation extends Declare {
return typePattern.isStarAnnotation();
if (sigPattern != null)
return sigPattern.isStarAnnotation();
throw new RuntimeException("Impossible! what kind of deca is this: "
+ this);
throw new RuntimeException("Impossible! what kind of deca is this: " + this);
}

public Kind getKind() {
@@ -381,9 +375,8 @@ public class DeclareAnnotation extends Declare {
}

/**
* Return true if this declare annotation could ever match something in the
* specified type - only really able to make intelligent decision if a type
* was specified in the sig/type pattern signature.
* Return true if this declare annotation could ever match something in the specified type - only really able to make
* intelligent decision if a type was specified in the sig/type pattern signature.
*/
public boolean couldEverMatch(ResolvedType type) {
// Haven't implemented variant for typePattern (doesn't seem worth it!)
@@ -393,14 +386,12 @@ public class DeclareAnnotation extends Declare {
// in all types exposed to the weaver! So look out for bugs here and
// we can update the test as appropriate.
if (sigPattern != null)
return sigPattern.getDeclaringType().matches(type,
TypePattern.STATIC).maybeTrue();
return sigPattern.getDeclaringType().matches(type, TypePattern.STATIC).maybeTrue();
return true;
}

/**
* Provide a name suffix so that we can tell the different declare
* annotations forms apart in the AjProblemReporter
* Provide a name suffix so that we can tell the different declare annotations forms apart in the AjProblemReporter
*/
public String getNameSuffix() {
return getKind().toString();

+ 81
- 69
org.aspectj.matcher/src/org/aspectj/weaver/patterns/DeclarePrecedence.java View File

@@ -10,7 +10,6 @@
* PARC initial implementation
* ******************************************************************/


package org.aspectj.weaver.patterns;

import java.io.DataOutputStream;
@@ -27,26 +26,25 @@ import org.aspectj.weaver.World;

public class DeclarePrecedence extends Declare {
private TypePatternList patterns;

public DeclarePrecedence(List patterns) {
this(new TypePatternList(patterns));
}
private DeclarePrecedence(TypePatternList patterns) {
this.patterns = patterns;
}
public Object accept(PatternNodeVisitor visitor, Object data) {
return visitor.visit(this,data);
return visitor.visit(this, data);
}
public Declare parameterizeWith(Map typeVariableBindingMap,World w) {
DeclarePrecedence ret = new DeclarePrecedence(this.patterns.parameterizeWith(typeVariableBindingMap,w));
public Declare parameterizeWith(Map typeVariableBindingMap, World w) {
DeclarePrecedence ret = new DeclarePrecedence(this.patterns.parameterizeWith(typeVariableBindingMap, w));
ret.copyLocationFrom(this);
return ret;
}
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("declare precedence: ");
@@ -54,67 +52,76 @@ public class DeclarePrecedence extends Declare {
buf.append(";");
return buf.toString();
}
public boolean equals(Object other) {
if (!(other instanceof DeclarePrecedence)) return false;
DeclarePrecedence o = (DeclarePrecedence)other;

public boolean equals(Object other) {
if (!(other instanceof DeclarePrecedence))
return false;
DeclarePrecedence o = (DeclarePrecedence) other;
return o.patterns.equals(patterns);
}
public int hashCode() {
return patterns.hashCode();
}

public int hashCode() {
return patterns.hashCode();
}

public void write(DataOutputStream s) throws IOException {
s.writeByte(Declare.DOMINATES);
patterns.write(s);
writeLocation(s);
}
public static Declare read(VersionedDataInputStream s, ISourceContext context) throws IOException {
Declare ret = new DeclarePrecedence(TypePatternList.read(s, context));
ret.readLocation(context, s);
return ret;
}
public void resolve(IScope scope) {
patterns = patterns.resolveBindings(scope, Bindings.NONE, false, false);
boolean seenStar = false;
for (int i=0; i < patterns.size(); i++) {
TypePattern pi = patterns.get(i);
if (pi.isStar()) {
if (seenStar) {
scope.getWorld().showMessage(IMessage.ERROR,
WeaverMessages.format(WeaverMessages.TWO_STARS_IN_PRECEDENCE),
pi.getSourceLocation(), null);
}
seenStar = true;
continue;
}
ResolvedType exactType = pi.getExactType().resolve(scope.getWorld());
if (exactType.isMissing()) continue;
// Cannot do a dec prec specifying a non-aspect types unless suffixed with a '+'
if (!exactType.isAspect() && !pi.isIncludeSubtypes() && !exactType.isTypeVariableReference()) {
scope.getWorld().showMessage(IMessage.ERROR,
WeaverMessages.format(WeaverMessages.CLASSES_IN_PRECEDENCE,exactType.getName()),
pi.getSourceLocation(),null);
}
for (int j=0; j < patterns.size(); j++) {
if (j == i) continue;
TypePattern pj = patterns.get(j);
if (pj.isStar()) continue;
if (pj.matchesStatically(exactType)) {
scope.getWorld().showMessage(IMessage.ERROR,
WeaverMessages.format(WeaverMessages.TWO_PATTERN_MATCHES_IN_PRECEDENCE,exactType.getName()),

boolean underResolution = false;

public void resolve(IScope scope) {
// if (underResolution) {
// return;
// }
// underResolution = true;
patterns = patterns.resolveBindings(scope, Bindings.NONE, false, false);
boolean seenStar = false;

for (int i = 0; i < patterns.size(); i++) {
TypePattern pi = patterns.get(i);
if (pi.isStar()) {
if (seenStar) {
scope.getWorld().showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.TWO_STARS_IN_PRECEDENCE),
pi.getSourceLocation(), null);
}
seenStar = true;
continue;
}
ResolvedType exactType = pi.getExactType().resolve(scope.getWorld());
if (exactType.isMissing())
continue;

// Cannot do a dec prec specifying a non-aspect types unless suffixed with a '+'
if (!exactType.isAspect() && !pi.isIncludeSubtypes() && !exactType.isTypeVariableReference()) {
scope.getWorld().showMessage(IMessage.ERROR,
WeaverMessages.format(WeaverMessages.CLASSES_IN_PRECEDENCE, exactType.getName()), pi.getSourceLocation(),
null);
}

for (int j = 0; j < patterns.size(); j++) {
if (j == i)
continue;
TypePattern pj = patterns.get(j);
if (pj.isStar())
continue;
if (pj.matchesStatically(exactType)) {
scope.getWorld().showMessage(IMessage.ERROR,
WeaverMessages.format(WeaverMessages.TWO_PATTERN_MATCHES_IN_PRECEDENCE, exactType.getName()),
pi.getSourceLocation(), pj.getSourceLocation());
}
}
}
}
}
}
// underResolution = false;
}
}

public TypePatternList getPatterns() {
return patterns;
@@ -123,14 +130,14 @@ public class DeclarePrecedence extends Declare {
private int matchingIndex(ResolvedType a) {
int knownMatch = -1;
int starMatch = -1;
for (int i=0, len=patterns.size(); i < len; i++) {
for (int i = 0, len = patterns.size(); i < len; i++) {
TypePattern p = patterns.get(i);
if (p.isStar()) {
starMatch = i;
} else if (p.matchesStatically(a)) {
if (knownMatch != -1) {
a.getWorld().showMessage(IMessage.ERROR,
WeaverMessages.format(WeaverMessages.MULTIPLE_MATCHES_IN_PRECEDENCE,a,patterns.get(knownMatch),p),
WeaverMessages.format(WeaverMessages.MULTIPLE_MATCHES_IN_PRECEDENCE, a, patterns.get(knownMatch), p),
patterns.get(knownMatch).getSourceLocation(), p.getSourceLocation());
return -1;
} else {
@@ -138,24 +145,29 @@ public class DeclarePrecedence extends Declare {
}
}
}
if (knownMatch == -1) return starMatch;
else return knownMatch;
if (knownMatch == -1)
return starMatch;
else
return knownMatch;
}

public int compare(ResolvedType aspect1, ResolvedType aspect2) {
int index1 = matchingIndex(aspect1);
int index2 = matchingIndex(aspect2);
//System.out.println("a1: " + aspect1 + ", " + aspect2 + " = " + index1 + ", " + index2);
if (index1 == -1 || index2 == -1) return 0;
if (index1 == index2) return 0;
else if (index1 > index2) return -1;
else return +1;

// System.out.println("a1: " + aspect1 + ", " + aspect2 + " = " + index1 + ", " + index2);

if (index1 == -1 || index2 == -1)
return 0;

if (index1 == index2)
return 0;
else if (index1 > index2)
return -1;
else
return +1;
}
public boolean isAdviceLike() {
return false;
}

+ 516
- 496
org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java
File diff suppressed because it is too large
View File


Loading…
Cancel
Save