use of org.apache.felix.scrplugin.annotations.ClassAnnotation in project felix by apache.
the class ClassScanner method parseAnnotation.
/**
* Parse annotation and create a description.
*/
private void parseAnnotation(final List<ScannedAnnotation> descriptions, final AnnotationNode annotation, final Object annotatedObject) {
// desc has the format 'L' + className.replace('.', '/') + ';'
final String name = annotation.desc.substring(1, annotation.desc.length() - 1).replace('/', '.');
Map<String, Object> values = null;
if (annotation.values != null) {
values = new HashMap<String, Object>();
final Iterator<?> i = annotation.values.iterator();
while (i.hasNext()) {
final Object vName = i.next();
Object value = i.next();
// convert type to class name string
if (value instanceof Type) {
value = ((Type) value).getClassName();
} else if (value instanceof List<?>) {
final List<?> objects = (List<?>) value;
if (objects.size() > 0) {
if (objects.get(0) instanceof Type) {
final String[] classNames = new String[objects.size()];
int index = 0;
for (final Object v : objects) {
classNames[index] = ((Type) v).getClassName();
index++;
}
value = classNames;
} else if (objects.get(0) instanceof AnnotationNode) {
final List<ScannedAnnotation> innerDesc = new ArrayList<ScannedAnnotation>();
for (final Object v : objects) {
parseAnnotation(innerDesc, (AnnotationNode) v, annotatedObject);
}
if (annotatedObject instanceof Method) {
value = innerDesc.toArray(new MethodAnnotation[innerDesc.size()]);
} else if (annotatedObject instanceof Field) {
value = innerDesc.toArray(new FieldAnnotation[innerDesc.size()]);
} else {
value = innerDesc.toArray(new ClassAnnotation[innerDesc.size()]);
}
} else {
value = convertToArray(objects, objects.get(0).getClass());
}
} else {
value = null;
}
}
values.put(vName.toString(), value);
}
}
final ScannedAnnotation a;
if (annotatedObject instanceof Method) {
a = new MethodAnnotation(name, values, (Method) annotatedObject);
((Method) annotatedObject).setAccessible(true);
} else if (annotatedObject instanceof Field) {
a = new FieldAnnotation(name, values, (Field) annotatedObject);
((Field) annotatedObject).setAccessible(true);
} else {
a = new ClassAnnotation(name, values);
}
descriptions.add(a);
}
Aggregations