[jboss-cvs] JBossAS SVN: r70259 - in projects/aop/trunk/aop/src: main/org/jboss/aop/annotation and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Feb 29 05:48:20 EST 2008
Author: stalep
Date: 2008-02-29 05:48:20 -0500 (Fri, 29 Feb 2008)
New Revision: 70259
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationElement.java
projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/PortableAnnotationElement.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotatedcflow/Annotation.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationc/AnnotationTester.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Annotation.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/jdk15base/traceable.java
Log:
[JBAOP-532] Added a new strategy for aop. From now on we will not parse invisible annotations by default. To include invisible annotations their package has to be added as a param to org.aop.include.annotations.
This change will greatly speed up annotation parsing.
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java 2008-02-29 10:28:47 UTC (rev 70258)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java 2008-02-29 10:48:20 UTC (rev 70259)
@@ -28,6 +28,7 @@
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -184,7 +185,9 @@
//Keeps track of if we need to convert references etc for a given class. Domains for scoped classloaders will have their own version of this
protected static InterceptionMarkers interceptionMarkers = new InterceptionMarkers();
-
+
+ /** A set of annotation names that will be ignored even tough they have been included. */
+ protected List<String> includeInvisibleAnnotations = Collections .emptyList();
// Static -------------------------------------------------------
protected static AspectManager manager;
@@ -281,6 +284,8 @@
manager.exclude = new ArrayList();
manager.include = new ArrayList();
manager.ignore = new ArrayList();
+ manager.includeInvisibleAnnotations = new ArrayList<String>();
+
AOPClassPoolRepository.getInstance().setAspectManager(manager);
@@ -321,6 +326,12 @@
}
manager.setIgnore(list);
}
+ String invisibleAnnotations = System.getProperty("jboss.aop.invisible.annotations", null);
+ if(invisibleAnnotations != null)
+ {
+ for(String inc : invisibleAnnotations.split(","))
+ manager.includeInvisibleAnnotations.add(inc.trim());
+ }
String instrument = System.getProperty("jboss.aop.instrumentor", null);
InstrumentorFactory.initialise(instrument);
@@ -2636,5 +2647,10 @@
}
}
}
+
+ public List<String> getIncludedInvisibleAnnotations()
+ {
+ return includeInvisibleAnnotations;
+ }
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationElement.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationElement.java 2008-02-29 10:28:47 UTC (rev 70258)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationElement.java 2008-02-29 10:48:20 UTC (rev 70259)
@@ -21,6 +21,7 @@
*/
package org.jboss.aop.annotation;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -167,10 +168,58 @@
}
}
- public static Object[] getVisibleAnnotations(Class clazz) throws Exception
+ public static boolean isVisibleAnnotationPresent(Class clazz, String annotation)
{
if (System.getSecurityManager() == null)
{
+ return AnnotationElementAction.NON_PRIVILEGED.isVisibleAnnotationPresent(clazz, annotation);
+ }
+ else
+ {
+ return AnnotationElementAction.PRIVILEGED.isVisibleAnnotationPresent(clazz, annotation);
+ }
+ }
+
+ public static boolean isVisibleAnnotationPresent(Method m, String annotation)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return AnnotationElementAction.NON_PRIVILEGED.isVisibleAnnotationPresent(m, annotation);
+ }
+ else
+ {
+ return AnnotationElementAction.PRIVILEGED.isVisibleAnnotationPresent(m, annotation);
+ }
+ }
+
+ public static boolean isVisibleAnnotationPresent(Field f, String annotation)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return AnnotationElementAction.NON_PRIVILEGED.isVisibleAnnotationPresent(f, annotation);
+ }
+ else
+ {
+ return AnnotationElementAction.PRIVILEGED.isVisibleAnnotationPresent(f, annotation);
+ }
+ }
+
+ public static boolean isVisibleAnnotationPresent(Constructor con, String annotation)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return AnnotationElementAction.NON_PRIVILEGED.isVisibleAnnotationPresent(con, annotation);
+ }
+ else
+ {
+ return AnnotationElementAction.PRIVILEGED.isVisibleAnnotationPresent(con, annotation);
+ }
+ }
+
+ public static Annotation[] getVisibleAnnotations(Class clazz) throws Exception
+ {
+ if (System.getSecurityManager() == null)
+ {
return AnnotationElementAction.NON_PRIVILEGED.getVisibleAnnotations(clazz);
}
else
@@ -179,7 +228,7 @@
}
}
- public static Object[] getVisibleAnnotations(Method m) throws Exception
+ public static Annotation[] getVisibleAnnotations(Method m) throws Exception
{
if (System.getSecurityManager() == null)
{
@@ -191,7 +240,7 @@
}
}
- public static Object[] getVisibleAnnotations(Field f) throws Exception
+ public static Annotation[] getVisibleAnnotations(Field f) throws Exception
{
if (System.getSecurityManager() == null)
{
@@ -203,7 +252,7 @@
}
}
- public static Object[] getVisibleAnnotations(Constructor c) throws Exception
+ public static Annotation[] getVisibleAnnotations(Constructor c) throws Exception
{
if (System.getSecurityManager() == null)
{
@@ -218,14 +267,22 @@
private interface AnnotationElementAction
{
- Object getVisibleAnnotation(Method method, Class annotation);
+ Annotation getVisibleAnnotation(Method method, Class annotation);
- Object getVisibleAnnotation(Constructor con, Class annotation);
+ Annotation getVisibleAnnotation(Constructor con, Class annotation);
- Object getVisibleAnnotation(Field field, Class annotation);
+ Annotation getVisibleAnnotation(Field field, Class annotation);
- Object getVisibleAnnotation(Class clazz, Class annotation);
+ Annotation getVisibleAnnotation(Class clazz, Class annotation);
+
+ Annotation getVisibleAnnotation(Method method, String annotation);
+ Annotation getVisibleAnnotation(Constructor con, String annotation);
+
+ Annotation getVisibleAnnotation(Field field, String annotation);
+
+ Annotation getVisibleAnnotation(Class clazz, String annotation);
+
boolean isVisibleAnnotationPresent(Class clazz, Class annotation);
boolean isVisibleAnnotationPresent(Method m, Class annotation);
@@ -233,37 +290,84 @@
boolean isVisibleAnnotationPresent(Field f, Class annotation);
boolean isVisibleAnnotationPresent(Constructor con, Class annotation);
+
+ boolean isVisibleAnnotationPresent(Class clazz, String annotation);
- Object[] getVisibleAnnotations(Class clazz) throws Exception;
+ boolean isVisibleAnnotationPresent(Method m, String annotation);
- Object[] getVisibleAnnotations(Method m) throws Exception;
+ boolean isVisibleAnnotationPresent(Field f, String annotation);
+
+ boolean isVisibleAnnotationPresent(Constructor con, String annotation);
+
+ Annotation[] getVisibleAnnotations(Class clazz) throws Exception;
+
+ Annotation[] getVisibleAnnotations(Method m) throws Exception;
- Object[] getVisibleAnnotations(Field f) throws Exception;
+ Annotation[] getVisibleAnnotations(Field f) throws Exception;
- Object[] getVisibleAnnotations(Constructor c) throws Exception;
+ Annotation[] getVisibleAnnotations(Constructor c) throws Exception;
AnnotationElementAction NON_PRIVILEGED = new AnnotationElementAction()
{
- public Object getVisibleAnnotation(Method method, Class annotation)
+ public Annotation getVisibleAnnotation(Method method, Class annotation)
{
return method.getAnnotation(annotation);
}
- public Object getVisibleAnnotation(Constructor con, Class annotation)
+ public Annotation getVisibleAnnotation(Constructor con, Class annotation)
{
return con.getAnnotation(annotation);
}
- public Object getVisibleAnnotation(Field field, Class annotation)
+ public Annotation getVisibleAnnotation(Field field, Class annotation)
{
return field.getAnnotation(annotation);
}
- public Object getVisibleAnnotation(Class clazz, Class annotation)
+ public Annotation getVisibleAnnotation(Class clazz, Class annotation)
{
return clazz.getAnnotation(annotation);
}
+ public Annotation getVisibleAnnotation(Method method, String annotation)
+ {
+ for(Annotation a : getVisibleAnnotations(method))
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return a;
+ }
+ return null;
+ }
+ public Annotation getVisibleAnnotation(Constructor con, String annotation)
+ {
+ for(Annotation a : getVisibleAnnotations(con))
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return a;
+ }
+ return null;
+ }
+
+ public Annotation getVisibleAnnotation(Field field, String annotation)
+ {
+ for(Annotation a : getVisibleAnnotations(field))
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return a;
+ }
+ return null;
+ }
+
+ public Annotation getVisibleAnnotation(Class clazz, String annotation)
+ {
+ for(Annotation a : getVisibleAnnotations(clazz))
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return a;
+ }
+ return null;
+ }
+
public boolean isVisibleAnnotationPresent(Class clazz, Class annotation)
{
return clazz.isAnnotationPresent(annotation);
@@ -283,23 +387,63 @@
{
return con.isAnnotationPresent(annotation);
}
+
+ public boolean isVisibleAnnotationPresent(Class clazz, String annotation)
+ {
+ for(Annotation a : getVisibleAnnotations(clazz))
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return true;
+ }
+ return false;
+ }
- public Object[] getVisibleAnnotations(Class clazz) throws Exception
+ public boolean isVisibleAnnotationPresent(Method m, String annotation)
{
+ for(Annotation a : getVisibleAnnotations(m))
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isVisibleAnnotationPresent(Field f, String annotation)
+ {
+ for(Annotation a : getVisibleAnnotations(f))
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isVisibleAnnotationPresent(Constructor con, String annotation)
+ {
+ for(Annotation a : getVisibleAnnotations(con))
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return true;
+ }
+ return false;
+ }
+
+ public Annotation[] getVisibleAnnotations(Class clazz)
+ {
return clazz.getAnnotations();
}
- public Object[] getVisibleAnnotations(Method m) throws Exception
+ public Annotation[] getVisibleAnnotations(Method m)
{
return m.getAnnotations();
}
- public Object[] getVisibleAnnotations(Field f) throws Exception
+ public Annotation[] getVisibleAnnotations(Field f)
{
return f.getAnnotations();
}
- public Object[] getVisibleAnnotations(Constructor c) throws Exception
+ public Annotation[] getVisibleAnnotations(Constructor c)
{
return c.getAnnotations();
}
@@ -308,50 +452,110 @@
AnnotationElementAction PRIVILEGED = new AnnotationElementAction()
{
- public Object getVisibleAnnotation(final Method method, final Class annotation)
+ public Annotation getVisibleAnnotation(final Method method, final Class annotation)
{
- return AccessController.doPrivileged(new PrivilegedAction(){
- public Object run()
+ return AccessController.doPrivileged(new PrivilegedAction<Annotation>(){
+ public Annotation run()
{
return method.getAnnotation(annotation);
}
});
}
- public Object getVisibleAnnotation(final Constructor con, final Class annotation)
+ public Annotation getVisibleAnnotation(final Constructor con, final Class annotation)
{
- return AccessController.doPrivileged(new PrivilegedAction(){
- public Object run()
+ return AccessController.doPrivileged(new PrivilegedAction<Annotation>(){
+ public Annotation run()
{
return con.getAnnotation(annotation);
}
});
}
- public Object getVisibleAnnotation(final Field field, final Class annotation)
+ public Annotation getVisibleAnnotation(final Field field, final Class annotation)
{
- return AccessController.doPrivileged(new PrivilegedAction(){
- public Object run()
+ return AccessController.doPrivileged(new PrivilegedAction<Annotation>(){
+ public Annotation run()
{
return field.getAnnotation(annotation);
}
});
}
- public Object getVisibleAnnotation(final Class clazz, final Class annotation)
+ public Annotation getVisibleAnnotation(final Class clazz, final Class annotation)
{
- return AccessController.doPrivileged(new PrivilegedAction(){
- public Object run()
+ return AccessController.doPrivileged(new PrivilegedAction<Annotation>(){
+ public Annotation run()
{
return clazz.getAnnotation(annotation);
}
});
}
+ public Annotation getVisibleAnnotation(final Method method, final String annotation)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<Annotation>(){
+ public Annotation run()
+ {
+ for(Annotation a : method.getAnnotations())
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return a;
+ }
+ return null;
+ }
+ });
+ }
+
+ public Annotation getVisibleAnnotation(final Constructor con, final String annotation)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<Annotation>(){
+ public Annotation run()
+ {
+ for(Annotation a : con.getAnnotations())
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return a;
+ }
+ return null;
+ }
+ });
+ }
+
+ public Annotation getVisibleAnnotation(final Field field, final String annotation)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<Annotation>(){
+ public Annotation run()
+ {
+ for(Annotation a : field.getAnnotations())
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return a;
+ }
+ return null;
+ }
+ });
+ }
+
+ public Annotation getVisibleAnnotation(final Class clazz, final String annotation)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<Annotation>(){
+ public Annotation run()
+ {
+ for(Annotation a : clazz.getAnnotations())
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return a;
+ }
+ return null;
+ }
+ });
+ }
+
public boolean isVisibleAnnotationPresent(final Class clazz, final Class annotation)
{
- Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction(){
- public Object run()
+ Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
+ public Boolean run()
{
return clazz.isAnnotationPresent(annotation) ? Boolean.TRUE : Boolean.FALSE;
}
@@ -362,8 +566,8 @@
public boolean isVisibleAnnotationPresent(final Method m, final Class annotation)
{
- Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction(){
- public Object run()
+ Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
+ public Boolean run()
{
return m.isAnnotationPresent(annotation) ? Boolean.TRUE : Boolean.FALSE;
}
@@ -374,8 +578,8 @@
public boolean isVisibleAnnotationPresent(final Field f, final Class annotation)
{
- Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction(){
- public Object run()
+ Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
+ public Boolean run()
{
return f.isAnnotationPresent(annotation) ? Boolean.TRUE : Boolean.FALSE;
}
@@ -385,8 +589,8 @@
public boolean isVisibleAnnotationPresent(final Constructor con, final Class annotation)
{
- Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction(){
- public Object run()
+ Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
+ public Boolean run()
{
return con.isAnnotationPresent(annotation) ? Boolean.TRUE : Boolean.FALSE;
}
@@ -394,13 +598,80 @@
return present;
}
- public Object[] getVisibleAnnotations(final Class clazz) throws Exception
+
+ public boolean isVisibleAnnotationPresent(final Class clazz, final String annotation)
{
+ Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
+ public Boolean run()
+ {
+ for(Annotation a : clazz.getAnnotations())
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ }
+ });
+
+ return present.booleanValue();
+ }
+
+ public boolean isVisibleAnnotationPresent(final Method m, final String annotation)
+ {
+ Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
+ public Boolean run()
+ {
+ for(Annotation a : m.getAnnotations())
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ }
+ });
+
+ return present.booleanValue();
+ }
+
+ public boolean isVisibleAnnotationPresent(final Field f, final String annotation)
+ {
+ Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
+ public Boolean run()
+ {
+ for(Annotation a : f.getAnnotations())
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ }
+ });
+ return present;
+ }
+
+ public boolean isVisibleAnnotationPresent(final Constructor con, final String annotation)
+ {
+ Boolean present = (Boolean)AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
+ public Boolean run()
+ {
+ for(Annotation a : con.getAnnotations())
+ {
+ if(a.annotationType().getName().equals(annotation))
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ }
+ });
+ return present;
+ }
+
+ public Annotation[] getVisibleAnnotations(final Class clazz) throws Exception
+ {
try
{
- return (Object[])AccessController.doPrivileged(new PrivilegedExceptionAction()
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Annotation[]>()
{
- public Object run() throws Exception
+ public Annotation[] run() throws Exception
{
return clazz.getAnnotations();
}
@@ -412,12 +683,12 @@
}
}
- public Object[] getVisibleAnnotations(final Method m) throws Exception
+ public Annotation[] getVisibleAnnotations(final Method m) throws Exception
{
try
{
- return (Object[])AccessController.doPrivileged(new PrivilegedExceptionAction(){
- public Object run() throws Exception
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Annotation[]>(){
+ public Annotation[] run() throws Exception
{
return m.getAnnotations();
}
@@ -429,12 +700,12 @@
}
}
- public Object[] getVisibleAnnotations(final Field f) throws Exception
+ public Annotation[] getVisibleAnnotations(final Field f) throws Exception
{
try
{
- return (Object[])AccessController.doPrivileged(new PrivilegedExceptionAction(){
- public Object run() throws Exception
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Annotation[]>(){
+ public Annotation[] run() throws Exception
{
return f.getAnnotations();
}
@@ -446,12 +717,12 @@
}
}
- public Object[] getVisibleAnnotations(final Constructor c) throws Exception
+ public Annotation[] getVisibleAnnotations(final Constructor c) throws Exception
{
try
{
- return (Object[])AccessController.doPrivileged(new PrivilegedExceptionAction(){
- public Object run() throws Exception
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Annotation[]>(){
+ public Annotation[] run() throws Exception
{
return c.getAnnotations();
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/PortableAnnotationElement.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/PortableAnnotationElement.java 2008-02-29 10:28:47 UTC (rev 70258)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/PortableAnnotationElement.java 2008-02-29 10:48:20 UTC (rev 70259)
@@ -34,8 +34,10 @@
import org.jboss.aop.AspectManager;
import org.jboss.annotation.factory.javassist.AnnotationProxy;
+import org.jboss.ant.taskdefs.server.StartServerTask;
import org.jboss.aop.util.ReflectToJavassist;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -63,8 +65,13 @@
{
return false;
}
- CtField ctMethod = ReflectToJavassist.fieldToJavassist(field);
- return AnnotationElement.isInvisibleAnnotationPresent(ctMethod, annotation);
+ if(includeInvisibleAnnotation(annotation))
+ {
+ CtField ctMethod = ReflectToJavassist.fieldToJavassist(field);
+ return AnnotationElement.isInvisibleAnnotationPresent(ctMethod, annotation);
+ }
+ else
+ return false;
}
public static boolean isInvisibleAnnotationPresent(CtField field, String annotation)
@@ -73,12 +80,17 @@
{
return false;
}
- FieldInfo mi = field.getFieldInfo2();
+ if(includeInvisibleAnnotation(annotation))
+ {
+ FieldInfo mi = field.getFieldInfo2();
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible == null) return false;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible == null) return false;
- return invisible.getAnnotation(annotation) != null;
+ return invisible.getAnnotation(annotation) != null;
+ }
+ else
+ return false;
}
public static boolean isVisibleAnnotationPresent(CtField field, String annotation)
@@ -109,13 +121,17 @@
if (visible.getAnnotation(annotation) != null) return true;
}
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible != null)
+ if(includeInvisibleAnnotation(annotation))
{
- if (invisible.getAnnotation(annotation) != null) return true;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible != null)
+ {
+ if (invisible.getAnnotation(annotation) != null) return true;
+ }
+ return false;
}
-
- return false;
+ else
+ return false;
}
public static boolean isInvisibleAnnotationPresent(Method method, String annotation) throws Exception
@@ -124,16 +140,20 @@
{
return false;
}
- CtMethod ctMethod = ReflectToJavassist.methodToJavassist(method);
- if (ctMethod == null) return false;
- MethodInfo mi = ctMethod.getMethodInfo2();
+ if(includeInvisibleAnnotation(annotation))
+ {
+ CtMethod ctMethod = ReflectToJavassist.methodToJavassist(method);
+ if (ctMethod == null) return false;
+ MethodInfo mi = ctMethod.getMethodInfo2();
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible == null) return false;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible == null) return false;
-
- return invisible.getAnnotation(annotation) != null;
+ return invisible.getAnnotation(annotation) != null;
+ }
+ else
+ return false;
}
public static boolean isAnyAnnotationPresent(Field field, String annotation) throws Exception
@@ -142,8 +162,15 @@
{
return false;
}
- CtField ctField = ReflectToJavassist.fieldToJavassist(field);
- return AnnotationElement.isAnyAnnotationPresent(ctField, annotation);
+ if(AnnotationElement.isVisibleAnnotationPresent(field, annotation))
+ return true;
+ if(includeInvisibleAnnotation(annotation))
+ {
+ CtField ctField = ReflectToJavassist.fieldToJavassist(field);
+ return AnnotationElement.isAnyAnnotationPresent(ctField, annotation);
+ }
+ else
+ return false;
}
@@ -153,11 +180,17 @@
{
return false;
}
- CtMethod ctMethod = ReflectToJavassist.methodToJavassist(method);
- if (ctMethod == null) return false;
- boolean present = AnnotationElement.isAnyAnnotationPresent(ctMethod, annotation);
- return present;
-
+ if(AnnotationElement.isVisibleAnnotationPresent(method, annotation))
+ return true;
+ if(includeInvisibleAnnotation(annotation))
+ {
+ CtMethod ctMethod = ReflectToJavassist.methodToJavassist(method);
+ if (ctMethod == null) return false;
+ boolean present = AnnotationElement.isAnyAnnotationPresent(ctMethod, annotation);
+ return present;
+ }
+ else
+ return false;
}
public static boolean isAnyAnnotationPresent(CtMethod ctMethod, String annotation)
@@ -174,13 +207,18 @@
if (visible.getAnnotation(annotation) != null) return true;
}
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible != null)
+ if(includeInvisibleAnnotation(annotation))
{
- if (invisible.getAnnotation(annotation) != null) return true;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible != null)
+ {
+ if (invisible.getAnnotation(annotation) != null) return true;
+ }
+ return false;
}
-
- return false;
+ else
+ return false;
+
}
public static boolean isInvisibleAnnotationPresent(Constructor con, String annotation) throws Exception
@@ -189,8 +227,13 @@
{
return false;
}
- CtConstructor ctMethod = ReflectToJavassist.constructorToJavassist(con);
- return AnnotationElement.isInvisibleAnnotationPresent(ctMethod, annotation);
+ if(includeInvisibleAnnotation(annotation))
+ {
+ CtConstructor ctMethod = ReflectToJavassist.constructorToJavassist(con);
+ return AnnotationElement.isInvisibleAnnotationPresent(ctMethod, annotation);
+ }
+ else
+ return false;
}
public static boolean isInvisibleAnnotationPresent(CtConstructor ctMethod, String annotation)
@@ -199,12 +242,17 @@
{
return false;
}
- MethodInfo mi = ctMethod.getMethodInfo2();
+ if(includeInvisibleAnnotation(annotation))
+ {
+ MethodInfo mi = ctMethod.getMethodInfo2();
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible == null) return false;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible == null) return false;
- return invisible.getAnnotation(annotation) != null;
+ return invisible.getAnnotation(annotation) != null;
+ }
+ else
+ return false;
}
public static boolean isVisibleAnnotationPresent(CtConstructor ctMethod, String annotation)
@@ -228,8 +276,15 @@
{
return false;
}
- CtConstructor ctMethod = ReflectToJavassist.constructorToJavassist(con);
- return AnnotationElement.isAnyAnnotationPresent(ctMethod, annotation);
+ if(AnnotationElement.isVisibleAnnotationPresent(con, annotation))
+ return true;
+ if(includeInvisibleAnnotation(annotation))
+ {
+ CtConstructor ctMethod = ReflectToJavassist.constructorToJavassist(con);
+ return AnnotationElement.isAnyAnnotationPresent(ctMethod, annotation);
+ }
+ else
+ return false;
}
public static boolean isAnyAnnotationPresent(CtConstructor ctMethod, String annotation)
@@ -246,13 +301,17 @@
if (visible.getAnnotation(annotation) != null) return true;
}
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible != null)
+ if(includeInvisibleAnnotation(annotation))
{
- if (invisible.getAnnotation(annotation) != null) return true;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible != null)
+ {
+ if (invisible.getAnnotation(annotation) != null) return true;
+ }
+ return false;
}
-
- return false;
+ else
+ return false;
}
public static boolean isInvisibleAnnotationPresent(Class clazz, String annotation) throws Exception
@@ -261,13 +320,18 @@
{
return false;
}
- if (clazz == Void.TYPE) return false;
- ClassFile cf = AnnotationElement.getClassFile(clazz);
+ if(includeInvisibleAnnotation(annotation))
+ {
+ if (clazz == Void.TYPE) return false;
+ ClassFile cf = AnnotationElement.getClassFile(clazz);
- AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible == null) return false;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible == null) return false;
- return invisible.getAnnotation(annotation) != null;
+ return invisible.getAnnotation(annotation) != null;
+ }
+ else
+ return false;
}
public static boolean isAnyAnnotationPresent(CtClass clazz, String annotation) throws Exception
@@ -292,16 +356,22 @@
AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
if (visible != null)
{
- if (visible.getAnnotation(annotation) != null) return true;
+ if (visible.getAnnotation(annotation) != null)
+ return true;
}
- AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible != null)
+ if(includeInvisibleAnnotation(annotation))
{
- if (invisible.getAnnotation(annotation) != null) return true;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible != null)
+ {
+ if (invisible.getAnnotation(annotation) != null) return true;
+ }
+ return false;
}
-
- return false;
+ else
+ return false;
+
}
catch (RuntimeException e)
{
@@ -317,20 +387,28 @@
return false;
}
if (clazz == Void.TYPE) return false;
- ClassFile cf = AnnotationElement.getClassFile(clazz);
- AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
- if (visible != null)
- {
- if (visible.getAnnotation(annotation) != null) return true;
- }
+ if(AnnotationElement.isVisibleAnnotationPresent(clazz, annotation))
+ return true;
+
+// ClassFile cf = AnnotationElement.getClassFile(clazz);
+// AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
+// if (visible != null)
+// {
+// if (visible.getAnnotation(annotation) != null) return true;
+// }
- AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible != null)
+ if(includeInvisibleAnnotation(annotation))
{
- if (invisible.getAnnotation(annotation) != null) return true;
+ ClassFile cf = AnnotationElement.getClassFile(clazz);
+ AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible != null)
+ {
+ if (invisible.getAnnotation(annotation) != null) return true;
+ }
+ return false;
}
-
- return false;
+ else
+ return false;
}
protected static ClassFile getClassFile(Class clazz) throws NotFoundException
@@ -355,24 +433,30 @@
{
return false;
}
- try
+
+ if(includeInvisibleAnnotation(annotation))
{
- CtMethod ctMethod = ReflectToJavassist.methodToJavassist(method);
- if (ctMethod == null)
+ try
{
- return null;
- }
- MethodInfo mi = ctMethod.getMethodInfo2();
+ CtMethod ctMethod = ReflectToJavassist.methodToJavassist(method);
+ if (ctMethod == null)
+ {
+ return null;
+ }
+ MethodInfo mi = ctMethod.getMethodInfo2();
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible == null) return null;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible == null) return null;
- return create(invisible, annotation);
+ return create(invisible, annotation);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
+ }
}
- catch (Exception e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
+ else
+ return false;
}
public static Object getInvisibleAnnotation(Constructor con, Class annotation)
@@ -381,21 +465,26 @@
{
return false;
}
- try
+ if(includeInvisibleAnnotation(annotation))
{
- CtConstructor ctMethod = ReflectToJavassist.constructorToJavassist(con);
- MethodInfo mi = ctMethod.getMethodInfo2();
+ try
+ {
+ CtConstructor ctMethod = ReflectToJavassist.constructorToJavassist(con);
+ MethodInfo mi = ctMethod.getMethodInfo2();
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible == null) return null;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible == null) return null;
- return create(invisible, annotation);
+ return create(invisible, annotation);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
+ }
}
- catch (Exception e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
+ else
+ return false;
}
public static Object getInvisibleAnnotation(Field field, Class annotation)
@@ -454,7 +543,10 @@
{
Object rtn = AnnotationElement.getVisibleAnnotation(method, annotation);
if (rtn != null) return rtn;
- return getInvisibleAnnotation(method, annotation);
+ if(includeInvisibleAnnotation(annotation))
+ return getInvisibleAnnotation(method, annotation);
+ else
+ return null;
}
/**
@@ -468,14 +560,20 @@
{
Object rtn = AnnotationElement.getVisibleAnnotation(con, annotation);
if (rtn != null) return rtn;
- return getInvisibleAnnotation(con, annotation);
+ if(includeInvisibleAnnotation(annotation))
+ return getInvisibleAnnotation(con, annotation);
+ else
+ return null;
}
public static Object getAnyAnnotation(Field field, Class annotation)
{
Object rtn = AnnotationElement.getVisibleAnnotation(field, annotation);
if (rtn != null) return rtn;
- return getInvisibleAnnotation(field, annotation);
+ if(includeInvisibleAnnotation(annotation))
+ return getInvisibleAnnotation(field, annotation);
+ else
+ return null;
}
public static Object getAnyAnnotation(Class clazz, Class annotation)
@@ -483,148 +581,106 @@
if (clazz == Void.TYPE) return null;
Object rtn = AnnotationElement.getVisibleAnnotation(clazz, annotation);
if (rtn != null) return rtn;
- return getInvisibleAnnotation(clazz, annotation);
+ if(includeInvisibleAnnotation(annotation))
+ return getInvisibleAnnotation(clazz, annotation);
+ else
+ return null;
}
public static boolean isAnyAnnotationPresent(Field field, Class annotation) throws Exception
{
- if (AnnotationElement.isVisibleAnnotationPresent(field, annotation)) return true;
+ if (AnnotationElement.isVisibleAnnotationPresent(field, annotation))
+ return true;
if (closingDownManager)
{
return false;
}
- CtField ctMethod = ReflectToJavassist.fieldToJavassist(field);
- return isInvisibleAnnotationPresent(ctMethod, annotation.getName());
+ if(includeInvisibleAnnotation(annotation))
+ {
+ CtField ctMethod = ReflectToJavassist.fieldToJavassist(field);
+ return isInvisibleAnnotationPresent(ctMethod, annotation.getName());
+ }
+ else
+ return false;
}
public static boolean isAnyAnnotationPresent(Class clazz, Class annotation) throws Exception
{
if (clazz == Void.TYPE) return false;
- if (AnnotationElement.isVisibleAnnotationPresent(clazz, annotation)) return true;
+ if (AnnotationElement.isVisibleAnnotationPresent(clazz, annotation))
+ return true;
if (closingDownManager)
{
return false;
}
- ClassFile cf = getClassFile(clazz);
+ if(includeInvisibleAnnotation(annotation))
+ {
+ ClassFile cf = getClassFile(clazz);
- AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible == null) return false;
+ AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible == null) return false;
- return invisible.getAnnotation(annotation.getName()) != null;
+ return invisible.getAnnotation(annotation.getName()) != null;
+ }
+ else
+ return false;
}
public static boolean isAnyAnnotationPresent(Constructor con, Class annotation) throws Exception
{
- if (AnnotationElement.isVisibleAnnotationPresent(con, annotation)) return true;
+ if (AnnotationElement.isVisibleAnnotationPresent(con, annotation))
+ return true;
if (closingDownManager)
{
return false;
}
- CtConstructor ctMethod = ReflectToJavassist.constructorToJavassist(con);
- return isVisibleAnnotationPresent(ctMethod, annotation.getName());
- }
-
- public static boolean isAnyAnnotationPresent(Method method, Class annotation) throws Exception
- {
- if (AnnotationElement.isVisibleAnnotationPresent(method, annotation)) return true;
- if (closingDownManager)
+ if(includeInvisibleAnnotation(annotation))
{
+ CtConstructor ctMethod = ReflectToJavassist.constructorToJavassist(con);
+ return isVisibleAnnotationPresent(ctMethod, annotation.getName());
+ }
+ else
return false;
- }
- CtMethod ctMethod = ReflectToJavassist.methodToJavassist(method);
- if (ctMethod == null) return false;
- MethodInfo mi = ctMethod.getMethodInfo2();
-
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible == null) return false;
-
- return invisible.getAnnotation(annotation.getName()) != null;
}
- public static boolean isVisibleAnnotationPresent(Field field, String annotation) throws Exception
+ public static boolean isAnyAnnotationPresent(Method method, Class annotation) throws Exception
{
+ if (AnnotationElement.isVisibleAnnotationPresent(method, annotation))
+ return true;
if (closingDownManager)
{
return false;
}
- CtField ctMethod = ReflectToJavassist.fieldToJavassist(field);
- return isVisibleAnnotationPresent(ctMethod, annotation);
- }
-
- public static boolean isVisibleAnnotationPresent(Class clazz, String annotation) throws Exception
- {
- if (closingDownManager)
+ if(includeInvisibleAnnotation(annotation))
{
- return false;
- }
- if (clazz == Void.TYPE) return false;
+ CtMethod ctMethod = ReflectToJavassist.methodToJavassist(method);
+ if (ctMethod == null) return false;
+ MethodInfo mi = ctMethod.getMethodInfo2();
- ClassFile cf = getClassFile(clazz);
+ AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ if (invisible == null) return false;
- AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
- if (visible == null) return false;
-
- return visible.getAnnotation(annotation) != null;
- }
-
- public static boolean isVisibleAnnotationPresent(Constructor con, String annotation) throws Exception
- {
- if (closingDownManager)
- {
- return false;
+ return invisible.getAnnotation(annotation.getName()) != null;
}
- CtConstructor ctMethod = ReflectToJavassist.constructorToJavassist(con);
- return isVisibleAnnotationPresent(ctMethod, annotation);
- }
-
- public static boolean isVisibleAnnotationPresent(Method method, String annotation) throws Exception
- {
- if (closingDownManager)
- {
+ else
return false;
- }
- CtMethod ctMethod = ReflectToJavassist.methodToJavassist(method);
- if (ctMethod == null) return false;
- MethodInfo mi = ctMethod.getMethodInfo2();
-
-
- AnnotationsAttribute visible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.visibleTag);
- if (visible == null) return false;
-
- return visible.getAnnotation(annotation) != null;
}
-
- public static Object[] getVisibleAnnotations(Class clazz) throws Exception
+
+ protected static boolean includeInvisibleAnnotation(Class annotation)
{
- return AnnotationElement.getVisibleAnnotations(clazz);
+ return includeInvisibleAnnotation(annotation.getPackage().getName());
}
-
- public static Object[] getVisibleAnnotations(Method m) throws Exception
- {
- return AnnotationElement.getVisibleAnnotations(m);
- }
-
- public static Object[] getVisibleAnnotations(Field f) throws Exception
- {
- return AnnotationElement.getVisibleAnnotations(f);
- }
- public static Object[] getVisibleAnnotations(Constructor c) throws Exception
+ protected static boolean includeInvisibleAnnotation(String annotation)
{
- return AnnotationElement.getVisibleAnnotations(c);
- }
-
- public static Class getAnnotationType(Object o)
- {
- Class proxy = o.getClass();
- if (Proxy.isProxyClass(proxy))
+ for(String includedAnnotation : AspectManager.instance().getIncludedInvisibleAnnotations())
{
- Class[] interfaces = proxy.getInterfaces();
- if (interfaces.length == 1)
+ if(includedAnnotation.equals("*") || includedAnnotation.startsWith(annotation))
{
- return interfaces[0];
+// System.err.println("IGNORING ANNOTATION: "+annotation);
+ return true;
}
}
- return null;
+ return false;
}
}
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotatedcflow/Annotation.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotatedcflow/Annotation.java 2008-02-29 10:28:47 UTC (rev 70258)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotatedcflow/Annotation.java 2008-02-29 10:48:20 UTC (rev 70259)
@@ -21,11 +21,14 @@
*/
package org.jboss.test.aop.annotatedcflow;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;;
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision$
*/
+ at Retention(RetentionPolicy.RUNTIME)
public @interface Annotation
{
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationc/AnnotationTester.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationc/AnnotationTester.java 2008-02-29 10:28:47 UTC (rev 70258)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationc/AnnotationTester.java 2008-02-29 10:48:20 UTC (rev 70259)
@@ -119,7 +119,7 @@
complex c = null;
try
{
- Object[] annotations = PortableAnnotationElement.getVisibleAnnotations(BytecodePOJO.class);
+ Object[] annotations = AnnotationElement.getVisibleAnnotations(BytecodePOJO.class);
for (int i = 0 ; i < annotations.length ; i++)
{
if (complex.class.isAssignableFrom(annotations[i].getClass()))
@@ -207,7 +207,7 @@
try
{
- Object[] annotations = PortableAnnotationElement.getVisibleAnnotations(con);
+ Object[] annotations = AnnotationElement.getVisibleAnnotations(con);
for (int i = 0 ; i < annotations.length ; i++)
{
if (complex.class.isAssignableFrom(annotations[i].getClass()))
@@ -292,7 +292,7 @@
try
{
- Object[] annotations = PortableAnnotationElement.getVisibleAnnotations(con);
+ Object[] annotations = AnnotationElement.getVisibleAnnotations(con);
for (int i = 0 ; i < annotations.length ; i++)
{
if (complex.class.isAssignableFrom(annotations[i].getClass()))
@@ -417,7 +417,7 @@
try
{
- Object[] annotations = PortableAnnotationElement.getVisibleAnnotations(con);
+ Object[] annotations = AnnotationElement.getVisibleAnnotations(con);
for (int i = 0 ; i < annotations.length ; i++)
{
if (complex.class.isAssignableFrom(annotations[i].getClass()))
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Annotation.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Annotation.java 2008-02-29 10:28:47 UTC (rev 70258)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Annotation.java 2008-02-29 10:48:20 UTC (rev 70259)
@@ -21,11 +21,15 @@
*/
package org.jboss.test.aop.container;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
+ at Retention(RetentionPolicy.RUNTIME)
public @interface Annotation {
}
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/jdk15base/traceable.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/jdk15base/traceable.java 2008-02-29 10:28:47 UTC (rev 70258)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/jdk15base/traceable.java 2008-02-29 10:48:20 UTC (rev 70259)
@@ -21,10 +21,14 @@
*/
package org.jboss.test.aop.jdk15base;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
+ at Retention(RetentionPolicy.RUNTIME)
public @interface traceable
{
}
More information about the jboss-cvs-commits
mailing list