aboutsummaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authorjhugunin <jhugunin>2002-12-20 22:49:11 +0000
committerjhugunin <jhugunin>2002-12-20 22:49:11 +0000
commit2c8295af23b94a7eaff57abf206f52abdc1dd02e (patch)
treef7030f3b5e06a565d67024546778e34e65b96c9b /weaver
parent9081949c3aca2636eab2598b57ddbda16563dcee (diff)
downloadaspectj-2c8295af23b94a7eaff57abf206f52abdc1dd02e.tar.gz
aspectj-2c8295af23b94a7eaff57abf206f52abdc1dd02e.zip
fixed rules for overriding/inheriting pointcuts
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/ResolvedTypeX.java103
-rw-r--r--weaver/testdata/dummyAspect.jarbin589 -> 589 bytes
-rw-r--r--weaver/testdata/megatrace.jarbin4858 -> 4858 bytes
-rw-r--r--weaver/testdata/megatraceNoweave.jarbin2649 -> 2649 bytes
-rw-r--r--weaver/testdata/tracing.jarbin2213 -> 2213 bytes
-rw-r--r--weaver/testsrc/org/aspectj/weaver/bcel/IdWeaveTestCase.java54
6 files changed, 119 insertions, 38 deletions
diff --git a/weaver/src/org/aspectj/weaver/ResolvedTypeX.java b/weaver/src/org/aspectj/weaver/ResolvedTypeX.java
index c0de08a5b..2fa0da533 100644
--- a/weaver/src/org/aspectj/weaver/ResolvedTypeX.java
+++ b/weaver/src/org/aspectj/weaver/ResolvedTypeX.java
@@ -248,6 +248,8 @@ public abstract class ResolvedTypeX extends TypeX {
if (m1.getKind() == Member.FIELD) {
return m1.getDeclaringType().equals(m2.getDeclaringType());
+ } else if (m1.getKind() == Member.POINTCUT) {
+ return true;
}
TypeX[] p1 = m1.getParameterTypes();
@@ -841,11 +843,11 @@ public abstract class ResolvedTypeX extends TypeX {
//System.err.println(" compare: " + c);
if (c < 0) {
// the existing munger dominates the new munger
- checkLegalOverride(existingMunger.getSignature(), munger.getSignature());
+ checkLegalOverride(munger.getSignature(), existingMunger.getSignature());
return;
} else if (c > 0) {
// the new munger dominates the existing one
- checkLegalOverride(munger.getSignature(), existingMunger.getSignature());
+ checkLegalOverride(existingMunger.getSignature(), munger.getSignature());
i.remove();
break;
} else {
@@ -875,10 +877,12 @@ public abstract class ResolvedTypeX extends TypeX {
int c = compareMemberPrecedence(sig, existingMember);
//System.err.println(" c: " + c);
if (c < 0) {
- checkLegalOverride(existingMember, munger.getSignature());
+ // existingMember dominates munger
+ checkLegalOverride(munger.getSignature(), existingMember);
return false;
} else if (c > 0) {
- checkLegalOverride(munger.getSignature(), existingMember);
+ // munger dominates existingMember
+ checkLegalOverride(existingMember, munger.getSignature());
//interTypeMungers.add(munger);
//??? might need list of these overridden abstracts
continue;
@@ -900,14 +904,27 @@ public abstract class ResolvedTypeX extends TypeX {
}
public boolean checkLegalOverride(ResolvedMember parent, ResolvedMember child) {
+ //System.err.println("check: " + child.getDeclaringType() + " overrides " + parent.getDeclaringType());
if (!parent.getReturnType().equals(child.getReturnType())) {
world.showMessage(IMessage.ERROR,
"can't override " + parent +
" with " + child + " return types don't match",
child.getSourceLocation(), parent.getSourceLocation());
return false;
- }
- if (isMoreVisible(child.getModifiers(), parent.getModifiers())) {
+ }
+ if (parent.getKind() == Member.POINTCUT) {
+ TypeX[] pTypes = parent.getParameterTypes();
+ TypeX[] cTypes = child.getParameterTypes();
+ if (!Arrays.equals(pTypes, cTypes)) {
+ world.showMessage(IMessage.ERROR,
+ "can't override " + parent +
+ " with " + child + " parameter types don't match",
+ child.getSourceLocation(), parent.getSourceLocation());
+ return false;
+ }
+ }
+ //System.err.println("check: " + child.getModifiers() + " more visible " + parent.getModifiers());
+ if (isMoreVisible(parent.getModifiers(), child.getModifiers())) {
world.showMessage(IMessage.ERROR,
"can't override " + parent +
" with " + child + " visibility is reduced",
@@ -939,13 +956,16 @@ public abstract class ResolvedTypeX extends TypeX {
public static boolean isMoreVisible(int m1, int m2) {
- if (Modifier.isPublic(m1)) return !Modifier.isPublic(m2);
- else if (Modifier.isPrivate(m1)) return false;
- else if (Modifier.isProtected(m1)) return !(Modifier.isPublic(m2) || Modifier.isProtected(m2));
- else return Modifier.isPrivate(m1);
+ if (Modifier.isPrivate(m1)) return false;
+ if (isPackage(m1)) return Modifier.isPrivate(m2);
+ if (Modifier.isProtected(m1)) return /* private package */ (Modifier.isPrivate(m2) || isPackage(m2));
+ if (Modifier.isPublic(m1)) return /* private package protected */ ! Modifier.isPublic(m2);
+ throw new RuntimeException("bad modifier: " + m1);
}
-
+ private static boolean isPackage(int i) {
+ return (0 == (i & (Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED)));
+ }
private void interTypeConflictError(
ConcreteTypeMunger m1,
@@ -995,4 +1015,65 @@ public abstract class ResolvedTypeX extends TypeX {
}
return true;
}
+
+ public List getExposedPointcuts() {
+ List ret = new ArrayList();
+ if (getSuperclass() != null) ret.addAll(getSuperclass().getExposedPointcuts());
+
+
+
+ for (Iterator i = Arrays.asList(getDeclaredInterfaces()).iterator(); i.hasNext(); ) {
+ ResolvedTypeX t = (ResolvedTypeX)i.next();
+ addPointcutsResolvingConflicts(ret, Arrays.asList(t.getDeclaredPointcuts()), false);
+ }
+ addPointcutsResolvingConflicts(ret, Arrays.asList(getDeclaredPointcuts()), true);
+ for (Iterator i = ret.iterator(); i.hasNext(); ) {
+ ResolvedPointcutDefinition inherited = (ResolvedPointcutDefinition)i.next();
+ if (inherited.isAbstract()) {
+ if (!this.isAbstract()) {
+ getWorld().showMessage(IMessage.ERROR,
+ "inherited abstract pointcut " + inherited +
+ " is not made concrete in " + this.getName(),
+ inherited.getSourceLocation(), this.getSourceLocation());
+ }
+ }
+ }
+
+
+ return ret;
+ }
+
+ private void addPointcutsResolvingConflicts(List acc, List added, boolean isOverriding) {
+ for (Iterator i = added.iterator(); i.hasNext();) {
+ ResolvedPointcutDefinition toAdd =
+ (ResolvedPointcutDefinition) i.next();
+ for (Iterator j = acc.iterator(); j.hasNext();) {
+ ResolvedPointcutDefinition existing =
+ (ResolvedPointcutDefinition) j.next();
+ if (existing == toAdd) continue;
+ if (!isVisible(existing.getModifiers(),
+ existing.getDeclaringType().resolve(getWorld()),
+ this)) {
+ continue;
+ }
+ if (conflictingSignature(existing, toAdd)) {
+ if (isOverriding) {
+ checkLegalOverride(existing, toAdd);
+ j.remove();
+ } else {
+ getWorld().showMessage(
+ IMessage.ERROR,
+ "conflicting inherited pointcuts in "
+ + this.getName() + toAdd.getSignature(),
+ existing.getSourceLocation(),
+ toAdd.getSourceLocation());
+ j.remove();
+ }
+ }
+ }
+ acc.add(toAdd);
+ }
+ }
+
+ public ISourceLocation getSourceLocation() { return null; }
}
diff --git a/weaver/testdata/dummyAspect.jar b/weaver/testdata/dummyAspect.jar
index 0e1e98aa8..5cadbea53 100644
--- a/weaver/testdata/dummyAspect.jar
+++ b/weaver/testdata/dummyAspect.jar
Binary files differ
diff --git a/weaver/testdata/megatrace.jar b/weaver/testdata/megatrace.jar
index 5fc8d9db7..e227960cc 100644
--- a/weaver/testdata/megatrace.jar
+++ b/weaver/testdata/megatrace.jar
Binary files differ
diff --git a/weaver/testdata/megatraceNoweave.jar b/weaver/testdata/megatraceNoweave.jar
index 25ad74a97..86df6e86d 100644
--- a/weaver/testdata/megatraceNoweave.jar
+++ b/weaver/testdata/megatraceNoweave.jar
Binary files differ
diff --git a/weaver/testdata/tracing.jar b/weaver/testdata/tracing.jar
index 6618effc7..ed778dde5 100644
--- a/weaver/testdata/tracing.jar
+++ b/weaver/testdata/tracing.jar
Binary files differ
diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/IdWeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/IdWeaveTestCase.java
index 031bf1c8d..6372b386d 100644
--- a/weaver/testsrc/org/aspectj/weaver/bcel/IdWeaveTestCase.java
+++ b/weaver/testsrc/org/aspectj/weaver/bcel/IdWeaveTestCase.java
@@ -76,32 +76,32 @@ public class IdWeaveTestCase extends WeaveTestCase {
}
// this test requires that Trace has been unzipped and placed in the correct place
- public void testTraceId() throws IOException {
- String saveClassDir = classDir;
- try {
- classDir = "testdata/dummyAspect.jar";
-
-
-
- final List l = new ArrayList();
- BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
- public void implementOn(Shadow shadow) {
- l.add(shadow);
- }
- };
- boolean tempRunTests = runTests;
- runTests = false;
- weaveTest(new String[] {"DummyAspect"}, "Id", p);
- runTests = tempRunTests;
-
- checkShadowSet(l, new String[] {
- "constructor-execution(void DummyAspect.<init>())",
- // XXX waiting on parser stuff
- //"advice-execution(void DummyAspect.ajc_before_1(java.lang.Object))",
- });
- } finally {
- classDir = saveClassDir;
- }
- }
+// public void testTraceId() throws IOException {
+// String saveClassDir = classDir;
+// try {
+// classDir = "testdata/dummyAspect.jar";
+//
+//
+//
+// final List l = new ArrayList();
+// BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
+// public void implementOn(Shadow shadow) {
+// l.add(shadow);
+// }
+// };
+// boolean tempRunTests = runTests;
+// runTests = false;
+// weaveTest(new String[] {"DummyAspect"}, "Id", p);
+// runTests = tempRunTests;
+//
+// checkShadowSet(l, new String[] {
+// "constructor-execution(void DummyAspect.<init>())",
+// // XXX waiting on parser stuff
+// //"advice-execution(void DummyAspect.ajc_before_1(java.lang.Object))",
+// });
+// } finally {
+// classDir = saveClassDir;
+// }
+// }
}