Browse Source

support for isNested, and use of that property when splitting names in WildTypePattern

tags/V1_5_0RC1
acolyer 18 years ago
parent
commit
99a8e76485

+ 4
- 0
weaver/src/org/aspectj/weaver/BoundedReferenceType.java View File

@@ -181,6 +181,10 @@ public class BoundedReferenceType extends ReferenceType {
return resolvedTypeX.isAnonymous();
}
public boolean isNested() {
return resolvedTypeX.isNested();
}
public String getRetentionPolicy() {
return resolvedTypeX.getRetentionPolicy();
}

+ 4
- 0
weaver/src/org/aspectj/weaver/ReferenceType.java View File

@@ -166,6 +166,10 @@ public class ReferenceType extends ResolvedType {
return delegate.isAnonymous();
}
public boolean isNested() {
return delegate.isNested();
}
public String getRetentionPolicy() {
return delegate.getRetentionPolicy();
}

+ 1
- 0
weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java View File

@@ -38,6 +38,7 @@ public interface ReferenceTypeDelegate {
public boolean isClass();
public boolean isGeneric();
public boolean isAnonymous();
public boolean isNested();
public boolean isExposedToWeaver();
public boolean hasAnnotation(UnresolvedType ofType);

+ 5
- 1
weaver/src/org/aspectj/weaver/ResolvedType.java View File

@@ -54,7 +54,7 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
}

// ---- things that don't require a world
/**
* Returns an iterator through ResolvedType objects representing all the direct
* supertypes of this type. That is, through the superclass, if any, and
@@ -620,6 +620,10 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
return false;
}
public boolean isNested() {
return false;
}
/**
* Note: Only overridden by Name subtype
*/

+ 4
- 0
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java View File

@@ -409,6 +409,10 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
return javaClass.isAnonymous();
}
public boolean isNested() {
return javaClass.isNested();
}
public void addAnnotation(AnnotationX annotation) {
damaged = true;
// Add it to the set of annotations

+ 21
- 11
weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java View File

@@ -200,12 +200,15 @@ public class WildTypePattern extends TypePattern {
}
//XXX inefficient implementation
public static char[][] splitNames(String s) {
// we don't know whether $ characters are from nested types, or were
// part of the declared type name (generated code often uses $s in type
// names). More work required on our part to get this right...
public static char[][] splitNames(String s, boolean convertDollar) {
List ret = new ArrayList();
int startIndex = 0;
while (true) {
int breakIndex = s.indexOf('.', startIndex); // what about /
if (breakIndex == -1) breakIndex = s.indexOf('$', startIndex); // we treat $ like . here
if (convertDollar && (breakIndex == -1)) breakIndex = s.indexOf('$', startIndex); // we treat $ like . here
if (breakIndex == -1) break;
char[] name = s.substring(startIndex, breakIndex).toCharArray();
ret.add(name);
@@ -230,7 +233,7 @@ public class WildTypePattern extends TypePattern {
// Ensure the annotation pattern is resolved
annotationPattern.resolve(type.getWorld());
return matchesExactlyByName(targetTypeName,type.isAnonymous()) &&
return matchesExactlyByName(targetTypeName,type.isAnonymous(),type.isNested()) &&
matchesParameters(type,STATIC) &&
matchesBounds(type,STATIC) &&
annotationPattern.matches(annotatedType).alwaysTrue();
@@ -288,7 +291,7 @@ public class WildTypePattern extends TypePattern {
* @param targetTypeName
* @return
*/
private boolean matchesExactlyByName(String targetTypeName, boolean isAnonymous) {
private boolean matchesExactlyByName(String targetTypeName, boolean isAnonymous, boolean isNested) {
// we deal with parameter matching separately...
if (targetTypeName.indexOf('<') != -1) {
targetTypeName = targetTypeName.substring(0,targetTypeName.indexOf('<'));
@@ -299,7 +302,7 @@ public class WildTypePattern extends TypePattern {
}
//XXX hack
if (knownMatches == null && importedPrefixes == null) {
return innerMatchesExactly(targetTypeName,isAnonymous);
return innerMatchesExactly(targetTypeName,isAnonymous, isNested);
}
if (isNamePatternStar()) {
@@ -334,7 +337,7 @@ public class WildTypePattern extends TypePattern {
String knownPrefix = knownMatches[i] + "$";
if (targetTypeName.startsWith(knownPrefix)) {
int pos = lastIndexOfDotOrDollar(knownMatches[i]);
if (innerMatchesExactly(targetTypeName.substring(pos+1),isAnonymous)) {
if (innerMatchesExactly(targetTypeName.substring(pos+1),isAnonymous,isNested)) {
return true;
}
}
@@ -349,13 +352,13 @@ public class WildTypePattern extends TypePattern {
//System.err.println("prefix match? " + prefix + " to " + targetTypeName);
if (targetTypeName.startsWith(prefix)) {
if (innerMatchesExactly(targetTypeName.substring(prefix.length()),isAnonymous)) {
if (innerMatchesExactly(targetTypeName.substring(prefix.length()),isAnonymous,isNested)) {
return true;
}
}
}
return innerMatchesExactly(targetTypeName,isAnonymous);
return innerMatchesExactly(targetTypeName,isAnonymous,isNested);
}

private int lastIndexOfDotOrDollar(String string) {
@@ -365,9 +368,9 @@ public class WildTypePattern extends TypePattern {
}

private boolean innerMatchesExactly(String targetTypeName, boolean isAnonymous) {
private boolean innerMatchesExactly(String targetTypeName, boolean isAnonymous, boolean isNested) {
//??? doing this everytime is not very efficient
char[][] names = splitNames(targetTypeName);
char[][] names = splitNames(targetTypeName,isNested);

return innerMatchesExactly(names, isAnonymous);
}
@@ -980,9 +983,16 @@ public class WildTypePattern extends TypePattern {
List ret = new ArrayList();
for (int i=0, len=possibleMatches.length; i < len; i++) {
char[][] names = splitNames(possibleMatches[i]); //??? not most efficient
char[][] names = splitNames(possibleMatches[i],true); //??? not most efficient
if (namePatterns[0].matches(names[names.length-1])) {
ret.add(possibleMatches[i]);
continue;
}
if (possibleMatches[i].indexOf("$") != -1) {
names = splitNames(possibleMatches[i],false); //??? not most efficient
if (namePatterns[0].matches(names[names.length-1])) {
ret.add(possibleMatches[i]);
}
}
}
return (String[])ret.toArray(new String[ret.size()]);

+ 5
- 0
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java View File

@@ -156,6 +156,11 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
public boolean isAnonymous() {
return false;
}
public boolean isNested() {
boolean member = this.myClass.isMemberClass();
return member;
}

/* (non-Javadoc)
* @see org.aspectj.weaver.ReferenceTypeDelegate#isExposedToWeaver()

Loading…
Cancel
Save