[jboss-cvs] JBossAS SVN: r92231 - in projects/annotations/trunk/core: src/main/java/org/jboss/annotations/javalangreflect and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 11 12:18:08 EDT 2009
Author: jesper.pedersen
Date: 2009-08-11 12:18:07 -0400 (Tue, 11 Aug 2009)
New Revision: 92231
Added:
projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/
projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/ITest.java
projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/Test.java
projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/package.html
Modified:
projects/annotations/trunk/core/build.xml
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java
projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassTests.java
Log:
[JBANN-22] Fold annotations from interface methods
Modified: projects/annotations/trunk/core/build.xml
===================================================================
--- projects/annotations/trunk/core/build.xml 2009-08-11 14:09:54 UTC (rev 92230)
+++ projects/annotations/trunk/core/build.xml 2009-08-11 16:18:07 UTC (rev 92231)
@@ -113,6 +113,9 @@
<jar destfile="${build.core.dir}/testjars/classinterface.jar"
basedir="${build.core.dir}/test"
includes="**/common/**, **/classinterface/**"/>
+ <jar destfile="${build.core.dir}/testjars/classinterfacemethod.jar"
+ basedir="${build.core.dir}/test"
+ includes="**/common/**, **/classinterfacemethod/**"/>
<jar destfile="${build.core.dir}/testjars/classlevel.jar"
basedir="${build.core.dir}/test"
includes="**/common/**, **/classlevel/**"/>
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java 2009-08-11 14:09:54 UTC (rev 92230)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java 2009-08-11 16:18:07 UTC (rev 92231)
@@ -43,6 +43,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
@@ -228,6 +229,41 @@
result);
}
}
+
+ Method[] interfaceMethods = interfaceClass.getDeclaredMethods();
+ if (interfaceMethods != null)
+ {
+ for (Method method : interfaceMethods)
+ {
+ if (trace)
+ log.finest("Interface Method=" + method.getName());
+
+ java.lang.annotation.Annotation[] methodAnnotations = method.getDeclaredAnnotations();
+ if (methodAnnotations != null)
+ {
+ String[] parameterTypes = null;
+ Class[] parameters = method.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
+ {
+ parameterTypes = new String[parameters.length];
+ for (int i = 0; i < parameters.length; i++)
+ {
+ parameterTypes[i] = parameters[i].getName();
+
+ if (trace)
+ log.finest("Interface Parameter=" + parameters[i].getName());
+ }
+ }
+
+ for (java.lang.annotation.Annotation annotation : methodAnnotations)
+ {
+ processAnnotation(annotation, AnnotationType.METHOD,
+ clz.getName(), method.getName(), parameterTypes,
+ result);
+ }
+ }
+ }
+ }
}
}
}
@@ -357,9 +393,11 @@
String key = annotationClass.getName();
Collection<Annotation> l = map.get(key);
if (l == null)
- l = new ArrayList<Annotation>();
+ l = new HashSet<Annotation>();
- l.add(a);
+ if (!l.contains(a))
+ l.add(a);
+
map.put(key, l);
}
}
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java 2009-08-11 14:09:54 UTC (rev 92230)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java 2009-08-11 16:18:07 UTC (rev 92231)
@@ -39,6 +39,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
@@ -253,6 +254,43 @@
result);
}
}
+
+ // Interface method level annotations
+ CtMethod[] interfaceMethods = interfaceClass.getDeclaredMethods();
+ if (interfaceMethods != null)
+ {
+ for (CtMethod method : interfaceMethods)
+ {
+ if (trace)
+ log.finest("Interface Method=" + method.getName());
+
+ Object[] methodAnnotations = method.getAvailableAnnotations();
+ if (methodAnnotations != null)
+ {
+ String[] parameterTypes = null;
+ CtClass[] parameters = method.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
+ {
+ parameterTypes = new String[parameters.length];
+ for (int i = 0; i < parameters.length; i++)
+ {
+ parameterTypes[i] = parameters[i].getName();
+
+ if (trace)
+ log.finest("Interface Parameter=" + parameters[i].getName());
+ }
+ }
+
+ for (Object annotation : methodAnnotations)
+ {
+ processAnnotation(annotation,
+ AnnotationType.METHOD,
+ ctClass.getName(), method.getName(), parameterTypes,
+ result);
+ }
+ }
+ }
+ }
}
}
}
@@ -380,9 +418,11 @@
String key = annotationClass.getName();
Collection<Annotation> l = map.get(key);
if (l == null)
- l = new ArrayList<Annotation>();
+ l = new HashSet<Annotation>();
- l.add(a);
+ if (!l.contains(a))
+ l.add(a);
+
map.put(key, l);
}
}
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java 2009-08-11 14:09:54 UTC (rev 92230)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java 2009-08-11 16:18:07 UTC (rev 92231)
@@ -34,12 +34,11 @@
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.List;
+import java.util.HashSet;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -278,6 +277,43 @@
result);
}
}
+
+ // Interface method level annotations
+ CtMethod[] interfaceMethods = interfaceClass.getDeclaredMethods();
+ if (interfaceMethods != null)
+ {
+ for (CtMethod method : interfaceMethods)
+ {
+ if (trace)
+ log.finest("Interface Method=" + method.getName());
+
+ Object[] methodAnnotations = method.getAvailableAnnotations();
+ if (methodAnnotations != null)
+ {
+ String[] parameterTypes = null;
+ CtClass[] parameters = method.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
+ {
+ parameterTypes = new String[parameters.length];
+ for (int i = 0; i < parameters.length; i++)
+ {
+ parameterTypes[i] = parameters[i].getName();
+
+ if (trace)
+ log.finest("Interface Parameter=" + parameters[i].getName());
+ }
+ }
+
+ for (Object annotation : methodAnnotations)
+ {
+ processAnnotation(annotation,
+ AnnotationType.METHOD,
+ ctClass.getName(), method.getName(), parameterTypes,
+ result);
+ }
+ }
+ }
+ }
}
}
}
@@ -349,9 +385,11 @@
String key = annotationClass.getName();
Collection<Annotation> l = map.get(key);
if (l == null)
- l = new ArrayList<Annotation>();
-
- l.add(a);
+ l = new HashSet<Annotation>();
+
+ if (!l.contains(a))
+ l.add(a);
+
map.put(key, l);
}
}
Modified: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassTests.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassTests.java 2009-08-11 14:09:54 UTC (rev 92230)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassTests.java 2009-08-11 16:18:07 UTC (rev 92231)
@@ -308,4 +308,45 @@
}
}
+ /**
+ * Class interface method
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testClassInterfaceMethod() throws Throwable
+ {
+ URL archive = getURL("classinterfacemethod.jar");
+ AnnotationRepository ar = scanner.scan(new URL[] {archive});
+
+ assertNotNull(ar);
+
+ assertTrue(ar.hasAnnotation(MyAnnotation.class));
+
+ Collection<Annotation> l = ar.getAnnotation(MyAnnotation.class);
+
+ assertNotNull(l);
+ assertTrue(l.size() == 2);
+
+ for (Annotation annotation : l)
+ {
+ if ("org.jboss.annotations.test.tests.classinterfacemethod.Test".equals(annotation.getClassName()))
+ {
+ assertNotNull(annotation.getAnnotation());
+ assertTrue(annotation.getType() == AnnotationType.METHOD);
+ assertEquals("myMethod", annotation.getMemberName());
+ assertNull(annotation.getParameterTypes());
+ }
+ else if ("org.jboss.annotations.test.tests.classinterfacemethod.ITest".equals(annotation.getClassName()))
+ {
+ assertNotNull(annotation.getAnnotation());
+ assertTrue(annotation.getType() == AnnotationType.METHOD);
+ assertEquals("myMethod", annotation.getMemberName());
+ assertNull(annotation.getParameterTypes());
+ }
+ else
+ {
+ fail("Unknown annotation location");
+ }
+ }
+ }
}
Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/ITest.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/ITest.java (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/ITest.java 2009-08-11 16:18:07 UTC (rev 92231)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.annotations.test.tests.classinterfacemethod;
+
+import org.jboss.annotations.test.tests.common.MyAnnotation;
+
+/**
+ * Test
+ */
+public interface ITest
+{
+ /**
+ * My method
+ */
+ @MyAnnotation
+ public void myMethod();
+}
Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/Test.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/Test.java (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/Test.java 2009-08-11 16:18:07 UTC (rev 92231)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.annotations.test.tests.classinterfacemethod;
+
+/**
+ * Test
+ */
+public class Test implements ITest
+{
+ /**
+ * My method
+ */
+ public void myMethod()
+ {
+ }
+}
Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/package.html
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/package.html (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterfacemethod/package.html 2009-08-11 16:18:07 UTC (rev 92231)
@@ -0,0 +1,3 @@
+<body>
+A class with a class level annotation
+</body>
More information about the jboss-cvs-commits
mailing list