Переглянути джерело

Add support for getParameterAnnotations() from the CtBehaviour.


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@246 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
adrian 18 роки тому
джерело
коміт
7bb1f60c5b

+ 17
- 0
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.
*/

+ 42
- 0
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;

Завантаження…
Відмінити
Зберегти