]> source.dussan.org Git - aspectj.git/commitdiff
updated for DeclareError and DeclareWarning
authoracolyer <acolyer>
Fri, 29 Apr 2005 20:19:21 +0000 (20:19 +0000)
committeracolyer <acolyer>
Fri, 29 Apr 2005 20:19:21 +0000 (20:19 +0000)
aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareEoW.java [new file with mode: 0644]
aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareSoft.java [new file with mode: 0644]
aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java
aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java [new file with mode: 0644]
aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareError.java [new file with mode: 0644]
aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareWarning.java [new file with mode: 0644]
aspectj5rt/java5-src/org/aspectj/lang/reflect/AjType.java
aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java
aspectj5rt/testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java

diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareEoW.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareEoW.java
new file mode 100644 (file)
index 0000000..e349d60
--- /dev/null
@@ -0,0 +1,31 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: 
+ *   Adrian Colyer                     Initial implementation
+ * ******************************************************************/
+package org.aspectj.internal.lang.annotation;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+
+/**
+ * @author colyer
+ * Marker annotation for declare soft declarations
+ * ajc prefix used to indicate that this annotation is *internal*
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface ajcDeclareEoW {
+       String message();
+       String pointcut();
+       boolean isError();
+}
diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareSoft.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareSoft.java
new file mode 100644 (file)
index 0000000..3a90051
--- /dev/null
@@ -0,0 +1,30 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: 
+ *   Adrian Colyer                     Initial implementation
+ * ******************************************************************/
+package org.aspectj.internal.lang.annotation;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+
+/**
+ * @author colyer
+ * Marker annotation for declare soft declarations
+ * ajc prefix used to indicate that this annotation is *internal*
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface ajcDeclareSoft {
+       Class exceptionType();
+       String pointcut();
+}
index 09db33898e99b33d99b6ee3db5a578c2a890b34d..13b177f5ff180c4b2be1f99d86bfc1db332d0e68 100644 (file)
@@ -15,6 +15,7 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
@@ -23,6 +24,7 @@ import java.util.EnumSet;
 import java.util.List;
 import java.util.Set;
 
+import org.aspectj.internal.lang.annotation.ajcDeclareEoW;
 import org.aspectj.internal.lang.annotation.ajcPrivileged;
 import org.aspectj.lang.annotation.After;
 import org.aspectj.lang.annotation.AfterReturning;
@@ -30,6 +32,8 @@ import org.aspectj.lang.annotation.AfterThrowing;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.DeclareError;
+import org.aspectj.lang.annotation.DeclareWarning;
 import org.aspectj.lang.reflect.Advice;
 import org.aspectj.lang.reflect.AdviceType;
 import org.aspectj.lang.reflect.AjType;
@@ -255,8 +259,12 @@ public class AjTypeImpl<T> implements AjType {
        public Field[] getDeclaredFields() {
                Field[] fields = clazz.getDeclaredFields();
                List<Field> filteredFields = new ArrayList<Field>();
-               for (Field field : fields)
-                       if (!field.getName().startsWith(ajcMagic)) filteredFields.add(field);
+               for (Field field : fields) 
+                       if (!field.getName().startsWith(ajcMagic) 
+                               && !field.isAnnotationPresent(DeclareWarning.class)
+                               && !field.isAnnotationPresent(DeclareError.class)) {
+                               filteredFields.add(field);
+                       }
                Field[] ret = new Field[filteredFields.size()];
                filteredFields.toArray(ret);
                return ret;
@@ -278,7 +286,11 @@ public class AjTypeImpl<T> implements AjType {
                Field[] fields = clazz.getFields();
                List<Field> filteredFields = new ArrayList<Field>();
                for (Field field : fields)
-                       if (!field.getName().startsWith(ajcMagic)) filteredFields.add(field);
+                       if (!field.getName().startsWith(ajcMagic) 
+                                       && !field.isAnnotationPresent(DeclareWarning.class)
+                                       && !field.isAnnotationPresent(DeclareError.class)) {
+                                       filteredFields.add(field);
+                               }
                Field[] ret = new Field[filteredFields.size()];
                filteredFields.toArray(ret);
                return ret;
@@ -631,15 +643,47 @@ public class AjTypeImpl<T> implements AjType {
        /* (non-Javadoc)
         * @see org.aspectj.lang.reflect.AjType#getDeclareErrorOrWarnings()
         */
-       public DeclareErrorOrWarning getDeclareErrorOrWarnings() {
-               // TODO Auto-generated method stub
-               return null;
+       public DeclareErrorOrWarning[] getDeclareErrorOrWarnings() {
+               List<DeclareErrorOrWarning> deows = new ArrayList<DeclareErrorOrWarning>();
+               for (Field field : clazz.getDeclaredFields()) {
+                       try {
+                               if (field.isAnnotationPresent(DeclareWarning.class)) {
+                                        DeclareWarning dw = field.getAnnotation(DeclareWarning.class);
+                                        if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
+                                                String message = (String) field.get(null);
+                                                DeclareErrorOrWarningImpl deow = new DeclareErrorOrWarningImpl(dw.value(),message,false);
+                                                deows.add(deow);
+                                        } 
+                               } else if (field.isAnnotationPresent(DeclareError.class)) {
+                                        DeclareError de = field.getAnnotation(DeclareError.class);
+                                        if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
+                                                String message = (String) field.get(null);
+                                                DeclareErrorOrWarningImpl deow = new DeclareErrorOrWarningImpl(de.value(),message,true);
+                                                deows.add(deow);
+                                        }                              
+                               }
+                       } catch (IllegalArgumentException e) {
+                               // just move on to the next field
+                       } catch (IllegalAccessException e) {
+                               // just move on to the next field
+                       }
+               }
+               for (Method method : clazz.getDeclaredMethods()) {
+                       if (method.isAnnotationPresent(ajcDeclareEoW.class)) {
+                               ajcDeclareEoW deowAnn = method.getAnnotation(ajcDeclareEoW.class);
+                               DeclareErrorOrWarning deow = new DeclareErrorOrWarningImpl(deowAnn.pointcut(),deowAnn.message(),deowAnn.isError());
+                               deows.add(deow);
+                       }
+               }
+               DeclareErrorOrWarning[] ret = new DeclareErrorOrWarning[deows.size()];
+               deows.toArray(ret);
+               return ret;
        }
 
        /* (non-Javadoc)
         * @see org.aspectj.lang.reflect.AjType#getDeclareParents()
         */
-       public DeclareParents getDeclareParents() {
+       public DeclareParents[] getDeclareParents() {
                // TODO Auto-generated method stub
                return null;
        }
@@ -647,15 +691,14 @@ public class AjTypeImpl<T> implements AjType {
        /* (non-Javadoc)
         * @see org.aspectj.lang.reflect.AjType#getDeclareSofts()
         */
-       public DeclareSoft getDeclareSofts() {
-               // TODO Auto-generated method stub
+       public DeclareSoft[] getDeclareSofts() {
                return null;
        }
 
        /* (non-Javadoc)
         * @see org.aspectj.lang.reflect.AjType#getDeclareAnnotations()
         */
-       public DeclareAnnotation getDeclareAnnotations() {
+       public DeclareAnnotation[] getDeclareAnnotations() {
                // TODO Auto-generated method stub
                return null;
        }
@@ -663,7 +706,7 @@ public class AjTypeImpl<T> implements AjType {
        /* (non-Javadoc)
         * @see org.aspectj.lang.reflect.AjType#getDeclarePrecedence()
         */
-       public DeclarePrecedence getDeclarePrecedence() {
+       public DeclarePrecedence[] getDeclarePrecedence() {
                // TODO Auto-generated method stub
                return null;
        }
diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java
new file mode 100644 (file)
index 0000000..826b36c
--- /dev/null
@@ -0,0 +1,53 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: 
+ *   Adrian Colyer                     Initial implementation
+ * ******************************************************************/
+package org.aspectj.internal.lang.reflect;
+
+import org.aspectj.lang.reflect.DeclareErrorOrWarning;
+
+/**
+ * @author colyer
+ *
+ */
+public class DeclareErrorOrWarningImpl implements DeclareErrorOrWarning {
+
+       private String pc;
+       private String msg;
+       private boolean isError;
+       
+       public DeclareErrorOrWarningImpl(String pointcut, String message, boolean isError) {
+               this.pc = pointcut;
+               this.msg = message;
+               this.isError = isError;
+       }
+       
+       /* (non-Javadoc)
+        * @see org.aspectj.lang.reflect.DeclareErrorOrWarning#getPointcutExpression()
+        */
+       public String getPointcutExpression() {
+               return pc;
+       }
+
+       /* (non-Javadoc)
+        * @see org.aspectj.lang.reflect.DeclareErrorOrWarning#getMessage()
+        */
+       public String getMessage() {
+               return msg;
+       }
+
+       /* (non-Javadoc)
+        * @see org.aspectj.lang.reflect.DeclareErrorOrWarning#isError()
+        */
+       public boolean isError() {
+               return isError;
+       }
+
+}
diff --git a/aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareError.java b/aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareError.java
new file mode 100644 (file)
index 0000000..803118d
--- /dev/null
@@ -0,0 +1,31 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: 
+ *   Adrian Colyer                     Initial implementation
+ * ******************************************************************/
+package org.aspectj.lang.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author colyer
+ * Annotation for declare error...
+ * 
+ * usage:
+ * @DeclareError("somePcut()")
+ * private static final String "a message";
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface DeclareError {
+       String value();
+}
diff --git a/aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareWarning.java b/aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareWarning.java
new file mode 100644 (file)
index 0000000..ba3d11e
--- /dev/null
@@ -0,0 +1,31 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: 
+ *   Adrian Colyer                     Initial implementation
+ * ******************************************************************/
+package org.aspectj.lang.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author colyer
+ * Annotation for declare warning...
+ * 
+ * usage:
+ * @DeclareWarning("somePcut()")
+ * private static final String "a message";
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface DeclareWarning {
+       String value();
+}
index 19a30aa487b1962f88407ba61501326a3223e04c..a468653d7005464678cdae73641808f5be4c4840 100644 (file)
@@ -143,15 +143,15 @@ public interface AjType<T> extends Type {
                
        // declare statements
        
-       public DeclareErrorOrWarning getDeclareErrorOrWarnings();
+       public DeclareErrorOrWarning[] getDeclareErrorOrWarnings();
        
-       public DeclareParents getDeclareParents();
+       public DeclareParents[] getDeclareParents();
        
-       public DeclareSoft getDeclareSofts();
+       public DeclareSoft[] getDeclareSofts();
        
-       public DeclareAnnotation getDeclareAnnotations();
+       public DeclareAnnotation[] getDeclareAnnotations();
        
-       public DeclarePrecedence getDeclarePrecedence();
+       public DeclarePrecedence[] getDeclarePrecedence();
        
        // misc
        
index f62608b302800275abacf977dca7cad2ea91abad..4fa4783f038aa299eacaf63f912e19b7cbf0d5d7 100644 (file)
@@ -16,5 +16,8 @@ package org.aspectj.lang.reflect;
  *
  */
 public interface DeclareErrorOrWarning {
-
+       String getPointcutExpression();
+       String getMessage();
+       boolean isError();
+       
 }
index 89e65be4a57fa25d70f704bc2a21ceb1c278d903..1ecd34516f76357e222c4f008530dac6d8947495 100644 (file)
@@ -8,14 +8,15 @@
  *  
  * Contributors: 
  *     Adrian Colyer       initial implementation 
- * ******************************************************************/package org.aspectj.internal.lang.reflect;
-
+ * ******************************************************************/
+package org.aspectj.internal.lang.reflect;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
 import junit.framework.TestCase;
 
+import org.aspectj.internal.lang.annotation.ajcDeclareEoW;
 import org.aspectj.internal.lang.annotation.ajcPrivileged;
 import org.aspectj.lang.annotation.AdviceName;
 import org.aspectj.lang.annotation.After;
@@ -24,10 +25,13 @@ import org.aspectj.lang.annotation.AfterThrowing;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.DeclareError;
+import org.aspectj.lang.annotation.DeclareWarning;
 import org.aspectj.lang.reflect.Advice;
 import org.aspectj.lang.reflect.AdviceType;
 import org.aspectj.lang.reflect.AjType;
 import org.aspectj.lang.reflect.AjTypeSystem;
+import org.aspectj.lang.reflect.DeclareErrorOrWarning;
 import org.aspectj.lang.reflect.NoSuchAdviceException;
 import org.aspectj.lang.reflect.NoSuchPointcutException;
 import org.aspectj.lang.reflect.PerClause;
@@ -288,6 +292,28 @@ public class AjTypeTestsWithAspects extends TestCase {
                assertTrue(AjTypeSystem.getAjType(SimplePrivilegedAspect.MemberAspect.class).isMemberAspect());
 
        }
+       
+       public void testGetDeclareEoWarnings() {
+               DeclareErrorOrWarning[] deows = sa.getDeclareErrorOrWarnings();
+               assertEquals(4,deows.length);
+               boolean foundCodeWarning = false;
+               boolean foundCodeError = false;
+               boolean foundAnnWarning = false;
+               boolean foundAnnError = false;
+               for (DeclareErrorOrWarning deow : deows) {
+                       if (deow.isError()) {
+                               if (deow.getMessage().equals("dont call this method code")) foundCodeError = true;
+                               if (deow.getMessage().equals("dont call this method ann")) foundAnnError = true;
+                               assertEquals("call(* DontDoIt.*(..))",deow.getPointcutExpression());
+                       } else {
+                               if (deow.getMessage().equals("dont call this method code")) foundCodeWarning = true;
+                               if (deow.getMessage().equals("dont call this method ann")) foundAnnWarning = true;
+                               assertEquals("call(* DontDoIt.*(..))",deow.getPointcutExpression());                            
+                       }
+               }
+               assertTrue(foundCodeWarning && foundAnnWarning && foundCodeError && foundAnnError);
+       }
+       
 }
 
 
@@ -352,6 +378,21 @@ class SimpleAspect {
   @org.aspectj.lang.annotation.Pointcut("call(* SimpleAspect.*(..))")
   private void ajc$pointcut$$simpleAspectCall$123(SimpleAspect target) {};
   
+  // decw, ann style
+  @DeclareWarning("call(* DontDoIt.*(..))")
+  public static final String dontDoIt = "dont call this method ann";
+  
+  // decw, code style
+  @ajcDeclareEoW(pointcut="call(* DontDoIt.*(..))",message="dont call this method code",isError=false)
+  private void ajc$declare_eow$123() {}
+
+  // dec., ann style
+  @DeclareError("call(* DontDoIt.*(..))")
+  public static final String dontDoItISaid = "dont call this method ann";
+  
+  // decw, code style
+  @ajcDeclareEoW(pointcut="call(* DontDoIt.*(..))",message="dont call this method code",isError=true)
+  private void ajc$declare_eow$124() {}
 }
 
 @Aspect