summaryrefslogtreecommitdiffstats
path: root/aspectj5rt
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-04-29 20:19:21 +0000
committeracolyer <acolyer>2005-04-29 20:19:21 +0000
commita6291f59f0bd11e85b5018bb68d9d6e61ece43ec (patch)
treeacfcaa135e42e8a7b1ab39848a61eae0c20769a3 /aspectj5rt
parent28a5bce27afc1b25460d6fe3273ae2e0272dd53e (diff)
downloadaspectj-a6291f59f0bd11e85b5018bb68d9d6e61ece43ec.tar.gz
aspectj-a6291f59f0bd11e85b5018bb68d9d6e61ece43ec.zip
updated for DeclareError and DeclareWarning
Diffstat (limited to 'aspectj5rt')
-rw-r--r--aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareEoW.java31
-rw-r--r--aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareSoft.java30
-rw-r--r--aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java65
-rw-r--r--aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java53
-rw-r--r--aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareError.java31
-rw-r--r--aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareWarning.java31
-rw-r--r--aspectj5rt/java5-src/org/aspectj/lang/reflect/AjType.java10
-rw-r--r--aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java5
-rw-r--r--aspectj5rt/testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java45
9 files changed, 282 insertions, 19 deletions
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
index 000000000..e349d603e
--- /dev/null
+++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareEoW.java
@@ -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
index 000000000..3a9005146
--- /dev/null
+++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareSoft.java
@@ -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();
+}
diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java
index 09db33898..13b177f5f 100644
--- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java
+++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java
@@ -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
index 000000000..826b36c19
--- /dev/null
+++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java
@@ -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
index 000000000..803118de1
--- /dev/null
+++ b/aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareError.java
@@ -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
index 000000000..ba3d11eb7
--- /dev/null
+++ b/aspectj5rt/java5-src/org/aspectj/lang/annotation/DeclareWarning.java
@@ -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();
+}
diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/AjType.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/AjType.java
index 19a30aa48..a468653d7 100644
--- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/AjType.java
+++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/AjType.java
@@ -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
diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java
index f62608b30..4fa4783f0 100644
--- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java
+++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java
@@ -16,5 +16,8 @@ package org.aspectj.lang.reflect;
*
*/
public interface DeclareErrorOrWarning {
-
+ String getPointcutExpression();
+ String getMessage();
+ boolean isError();
+
}
diff --git a/aspectj5rt/testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java b/aspectj5rt/testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java
index 89e65be4a..1ecd34516 100644
--- a/aspectj5rt/testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java
+++ b/aspectj5rt/testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java
@@ -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