From 5e3e0b6a07c1a1e270786faf72e6a7a54972f821 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 22 May 2008 23:57:23 +0000 Subject: [PATCH] 227401: test and fix - use correct declaring type when building tjp so getDeclaringType() works at runtime --- tests/bugs161/pr227401/Fails.java | 42 ++++++++++++++++ tests/bugs161/pr227401/Instrumentation.java | 50 +++++++++++++++++++ tests/bugs161/pr227401/Works.java | 41 +++++++++++++++ .../systemtest/ajc161/Ajc161Tests.java | 1 + .../org/aspectj/systemtest/ajc161/ajc161.xml | 17 +++++++ 5 files changed, 151 insertions(+) create mode 100644 tests/bugs161/pr227401/Fails.java create mode 100644 tests/bugs161/pr227401/Instrumentation.java create mode 100644 tests/bugs161/pr227401/Works.java diff --git a/tests/bugs161/pr227401/Fails.java b/tests/bugs161/pr227401/Fails.java new file mode 100644 index 000000000..385c143bd --- /dev/null +++ b/tests/bugs161/pr227401/Fails.java @@ -0,0 +1,42 @@ +public class Fails { + + interface I { + static final int CONST = 56; + } + + static class A { + protected int prot; + protected String protS; + int def; + String defS; + T foo; + } + + static class B extends A implements I { + void m() { + // protected +// super.prot = 1; +// super.protS = "1"; +// System.out.println(super.protS + super.prot); + prot = 2; + protS = "2"; + System.out.println(protS + prot); + // default + super.def = 1; + super.defS = "1"; + System.out.println(defS + def); + def = 2; + defS = "2"; + foo = "todo"; + System.out.println(defS + def); +// // interface +// System.out.println(CONST); + } + } + + public static void main(String[] args) { + B b = new B(); + b.m(); + } +} + diff --git a/tests/bugs161/pr227401/Instrumentation.java b/tests/bugs161/pr227401/Instrumentation.java new file mode 100644 index 000000000..64c6ec168 --- /dev/null +++ b/tests/bugs161/pr227401/Instrumentation.java @@ -0,0 +1,50 @@ +import java.lang.reflect.Field; + +import org.aspectj.lang.reflect.*; + +public aspect Instrumentation { + pointcut nofl() : !within(Instrumentation); + + pointcut getField() : get(* *) && nofl() && !get(* System.out) ; + + after() : getField() { + final FieldSignature signature = (FieldSignature) thisJoinPointStaticPart.getSignature(); + StringBuffer jpInfo = new StringBuffer(); + jpInfo.append("getField(* ").append(signature.getName()).append(")"); + final Field field = signature.getField(); + jpInfo.append(" getField()='").append(signature.getField()).append("'"); + final Class declaringType = signature.getDeclaringType(); + jpInfo.append(" getDeclaringType()='"+declaringType).append("'"); + final Object receiver = thisJoinPoint.getTarget(); + if (receiver == null) { + jpInfo.append(" signature.getTarget() is null (only ok if static)"); + } + System.out.println(jpInfo.toString()); + } + + + +/* + pointcut setField() : set(* *) && nofl(); + + after() : setField() { + System.out.println("setField()"); + final FieldSignature signature = (FieldSignature) thisJoinPointStaticPart + .getSignature(); + final Field field = signature.getField(); + if (field == null) + System.out.println(" - field " + signature.getName() + + " is null...bug!"); + final Class declaringType = signature.getDeclaringType(); + if (declaringType == null) + System.out.println(" - declaringType for the field " + + signature.getName() + " is null...bug!"); + final Object receiver = thisJoinPoint.getTarget(); + if (receiver == null) + System.out.println(" - target (receiver) for the field " + + signature.getName() + " is null...bug!"); + } +*/ + +} + diff --git a/tests/bugs161/pr227401/Works.java b/tests/bugs161/pr227401/Works.java new file mode 100644 index 000000000..e8e31d206 --- /dev/null +++ b/tests/bugs161/pr227401/Works.java @@ -0,0 +1,41 @@ +public class Works { + + interface I { + static final int CONST = 56; + } + + static class A { + protected int prot; + protected String protS; + int def; + String defS; + String foo; + } + + static class B extends A implements I { + void m() { +// // protected +// super.prot = 1; +// super.protS = "1"; +// System.out.println(super.protS + super.prot); + prot = 2; + protS = "2"; + System.out.println(protS + prot); +// // default +// super.def = 3; +// super.defS = "3"; +// System.out.println(defS + def); +// def = 4; +// defS = "4"; +// foo = "todo"; +// System.out.println(defS + def); +// // interface +// System.out.println(CONST); + } + } + + public static void main(String[] args) { + B b = new B(); + b.m(); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc161/Ajc161Tests.java b/tests/src/org/aspectj/systemtest/ajc161/Ajc161Tests.java index a31dfb86b..6fe3c414f 100644 --- a/tests/src/org/aspectj/systemtest/ajc161/Ajc161Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc161/Ajc161Tests.java @@ -19,6 +19,7 @@ import org.aspectj.testing.XMLBasedAjcTestCase; public class Ajc161Tests extends org.aspectj.testing.XMLBasedAjcTestCase { // AspectJ1.6.1 + public void testGetFieldGenerics_pr227401() { runTest("getfield problem with generics");} public void testGenericAbstractAspects_pr231478() { runTest("generic abstract aspects"); } public void testFieldJoinpointsAndAnnotationValues_pr227993() { runTest("field jp anno value"); } public void testGenericsBoundsDecp_pr231187() { runTest("generics bounds decp"); } diff --git a/tests/src/org/aspectj/systemtest/ajc161/ajc161.xml b/tests/src/org/aspectj/systemtest/ajc161/ajc161.xml index a7768d284..de172f61f 100644 --- a/tests/src/org/aspectj/systemtest/ajc161/ajc161.xml +++ b/tests/src/org/aspectj/systemtest/ajc161/ajc161.xml @@ -3,6 +3,23 @@ + + + + + + + + + + + + + + + + + -- 2.39.5