From 8b6fbd3ae387e8746cd24184e747d3f8acef3dc2 Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 17 Jan 2006 13:34:44 +0000 Subject: [PATCH] testcode for 123695 --- tests/bugs151/pr123695/InjectName.java | 7 +++ tests/bugs151/pr123695/Main.java | 32 ++++++++++ tests/bugs151/pr123695/MarkMyMethods.java | 7 +++ .../bugs151/pr123695/MarkMyMethodsAspect.java | 60 +++++++++++++++++++ tests/bugs151/pr123695/NameAspect.java | 18 ++++++ tests/bugs151/pr123695/Named.java | 5 ++ tests/bugs151/pr123695/Read.java | 7 +++ tests/bugs151/pr123695/Write.java | 7 +++ 8 files changed, 143 insertions(+) create mode 100644 tests/bugs151/pr123695/InjectName.java create mode 100644 tests/bugs151/pr123695/Main.java create mode 100644 tests/bugs151/pr123695/MarkMyMethods.java create mode 100644 tests/bugs151/pr123695/MarkMyMethodsAspect.java create mode 100644 tests/bugs151/pr123695/NameAspect.java create mode 100644 tests/bugs151/pr123695/Named.java create mode 100644 tests/bugs151/pr123695/Read.java create mode 100644 tests/bugs151/pr123695/Write.java diff --git a/tests/bugs151/pr123695/InjectName.java b/tests/bugs151/pr123695/InjectName.java new file mode 100644 index 000000000..e1cfec5b3 --- /dev/null +++ b/tests/bugs151/pr123695/InjectName.java @@ -0,0 +1,7 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +public @interface InjectName { + +} diff --git a/tests/bugs151/pr123695/Main.java b/tests/bugs151/pr123695/Main.java new file mode 100644 index 000000000..f70f2d674 --- /dev/null +++ b/tests/bugs151/pr123695/Main.java @@ -0,0 +1,32 @@ +import java.io.Serializable; +@InjectName +@MarkMyMethods +public class Main { + + public String name; + + public Main() { + name = "jack"; + } + + public String testMethod() { + return "Test"; + } + + protected String testMethodProtected() { + return "Blah!"; + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Main m = new Main(); + Class[] cls = Main.class.getInterfaces(); + for(Class cl:cls) { + System.out.println("Interface : " + cl.getCanonicalName()); + } + } + +} diff --git a/tests/bugs151/pr123695/MarkMyMethods.java b/tests/bugs151/pr123695/MarkMyMethods.java new file mode 100644 index 000000000..22536d9db --- /dev/null +++ b/tests/bugs151/pr123695/MarkMyMethods.java @@ -0,0 +1,7 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +public @interface MarkMyMethods { + +} diff --git a/tests/bugs151/pr123695/MarkMyMethodsAspect.java b/tests/bugs151/pr123695/MarkMyMethodsAspect.java new file mode 100644 index 000000000..3d6a57422 --- /dev/null +++ b/tests/bugs151/pr123695/MarkMyMethodsAspect.java @@ -0,0 +1,60 @@ + + +public aspect MarkMyMethodsAspect { + + /* All methods not marked with @Read nor @Write are marked with @Write + * + * When @MarkMyMethods is present on a Type, all public methods of + * that type must either be marked with @Read or @Write. If neither of + * @Read or @Write is present on such a method, the method is automatically + * annotated with the default marker, i.e. @Write + * + * ******************************************************* + * BUG + * internal null pointer exception with the first part + * of the declare statement. + * ******************************************************* + * + */ + declare @method : !@(Write || Read) public !static * (@MarkMyMethods *).*(..) : @Write; + + // This one works + //declare @method : !@(Read) public !static * (@MarkMyMethods *).*(..) : @Write; + // This one too + //declare @method : !@(Write) public !static * (@MarkMyMethods *).*(..) : @Write; + + + /* Cannot have @Read or @Write methods without @MarkMyMethods + * + * When @Read or @Write is present on a method, the enclosing type must + * have the @AccessClassified annotation. + */ + declare error : execution(@Read public * !@MarkMyMethods *.*(..)) : + "Cannot have public @Read methods inside non @AccessClassified types."; + declare error : execution(@Write public * !@MarkMyMethods *.*(..)) : + "Cannot have public @Write methods inside non @AccessClassified types."; + + /* Cannot have a method marked with both @Read and @Write + * + * What would be necessary is to have an annotation that can take + * a parameter to identify which type of access is needed that would prevent + * the user from having the 2 at the same time e.g. @Access(READ). Unfortunately, + * AspectJ 1.5 can currently only work with marker annotations and ignores + * parameter annotations. + */ + declare error : readMethod() && writeMethod() : + "Cannot have both @Read and @Write on the same method."; + + /* + * public @Read methods inside @MarkMyMethods types + */ + public pointcut readMethod() : + execution(@Read public !static * @MarkMyMethods *.*(..)); + + /* + * public @Write methods inside @MarkMyMethods types + */ + public pointcut writeMethod() : + execution(@Write public !static * @MarkMyMethods *.*(..)); + +} diff --git a/tests/bugs151/pr123695/NameAspect.java b/tests/bugs151/pr123695/NameAspect.java new file mode 100644 index 000000000..2e4f77f34 --- /dev/null +++ b/tests/bugs151/pr123695/NameAspect.java @@ -0,0 +1,18 @@ + +public aspect NameAspect { + + + declare parents: @InjectName * implements Named; + + /* + * The injection of that method interferes with the declare + * statements in MarkMyMethodsAspect + */ + public String Named.getName() { return name; } + private String Named.name; + + after(Named newinstance) : execution(Named+.new(..)) && target(newinstance) { + System.out.println("A new name was created"); + newinstance.name = "TikaTikaSlimShady"; + } +} diff --git a/tests/bugs151/pr123695/Named.java b/tests/bugs151/pr123695/Named.java new file mode 100644 index 000000000..59b5464f2 --- /dev/null +++ b/tests/bugs151/pr123695/Named.java @@ -0,0 +1,5 @@ + +public interface Named { + public String getName(); + +} diff --git a/tests/bugs151/pr123695/Read.java b/tests/bugs151/pr123695/Read.java new file mode 100644 index 000000000..b874d7851 --- /dev/null +++ b/tests/bugs151/pr123695/Read.java @@ -0,0 +1,7 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +public @interface Read { + +} diff --git a/tests/bugs151/pr123695/Write.java b/tests/bugs151/pr123695/Write.java new file mode 100644 index 000000000..1acdc9a0a --- /dev/null +++ b/tests/bugs151/pr123695/Write.java @@ -0,0 +1,7 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +public @interface Write { + +} -- 2.39.5