From 7bb1f60c5b48f2ef8c481fd00e61763bc9e02f19 Mon Sep 17 00:00:00 2001 From: adrian Date: Wed, 15 Feb 2006 18:12:27 +0000 Subject: [PATCH] Add support for getParameterAnnotations() from the CtBehaviour. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@246 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/CtBehavior.java | 17 ++++++++++++ src/main/javassist/CtClassType.java | 42 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/main/javassist/CtBehavior.java b/src/main/javassist/CtBehavior.java index 71047844..5eaa1e58 100644 --- a/src/main/javassist/CtBehavior.java +++ b/src/main/javassist/CtBehavior.java @@ -152,6 +152,23 @@ public abstract class CtBehavior extends CtMember { ainfo, ainfo2); } + /** + * Returns the parameter annotations associated with this method or constructor. + * + * @return an array of annotation-type objects. + * @see CtMember#getAnnotations() + * @since 3.1 + */ + public Object[][] getParameterAnnotations() throws ClassNotFoundException { + MethodInfo mi = getMethodInfo2(); + ParameterAnnotationsAttribute ainfo = (ParameterAnnotationsAttribute) + mi.getAttribute(ParameterAnnotationsAttribute.invisibleTag); + ParameterAnnotationsAttribute ainfo2 = (ParameterAnnotationsAttribute) + mi.getAttribute(ParameterAnnotationsAttribute.visibleTag); + return CtClassType.toAnnotationType(getDeclaringClass().getClassPool(), + ainfo, ainfo2); + } + /** * Obtains parameter types of this method/constructor. */ diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java index 04500c2d..dbb19340 100644 --- a/src/main/javassist/CtClassType.java +++ b/src/main/javassist/CtClassType.java @@ -43,6 +43,7 @@ import javassist.bytecode.EnclosingMethodAttribute; import javassist.bytecode.FieldInfo; import javassist.bytecode.InnerClassesAttribute; import javassist.bytecode.MethodInfo; +import javassist.bytecode.ParameterAnnotationsAttribute; import javassist.bytecode.annotation.Annotation; import javassist.compiler.AccessorMaker; import javassist.compiler.CompileError; @@ -420,6 +421,47 @@ class CtClassType extends CtClass { return result; } + static Object[][] toAnnotationType(ClassPool cp, ParameterAnnotationsAttribute a1, + ParameterAnnotationsAttribute a2) throws ClassNotFoundException { + int numParameters = 0; + if (a1 != null) + numParameters = a1.numParameters(); + else + numParameters = a2.numParameters(); + + Object[][] result = new Object[numParameters][]; + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + for (int i = 0; i < numParameters; i++) { + Annotation[] anno1, anno2; + int size1, size2; + + if (a1 == null) { + anno1 = null; + size1 = 0; + } + else { + anno1 = a1.getAnnotations()[i]; + size1 = anno1.length; + } + + if (a2 == null) { + anno2 = null; + size2 = 0; + } + else { + anno2 = a2.getAnnotations()[i]; + size2 = anno2.length; + } + result[i] = new Object[size1 + size2]; + for (int j = 0; j < size1; ++j) + result[i][j] = anno1[j].toAnnotationType(cl, cp); + for (int j = 0; j < size2; ++j) + result[i][j + size1] = anno2[j].toAnnotationType(cl, cp); + } + + return result; + } + public boolean subclassOf(CtClass superclass) { if (superclass == null) return false; -- 2.39.5