/** * Parses a type definition * * @param type * @return */ protected static TypeInfo ParseType(Type type) { TypeInfo typeInfo = new TypeInfo(); typeInfo.qualifiedName = type.qualifiedTypeName(); typeInfo.dimension = type.dimension(); typeInfo.wildcard = ParseWildCard(type.asWildcardType()); typeInfo.generics = ParseGenerics(type.asParameterizedType()); return typeInfo; }
/** * Parses annotation instances from the javadoc annotation instance type * * @param annotationDocs Annotations decorated on some type * @return Serializable representation of annotations */ protected static AnnotationInstance[] ParseAnnotationInstances( AnnotationDesc[] annotationDocs, String origin) { AnnotationInstance[] annotations = null; if (annotationDocs != null && annotationDocs.length > 0) { ArrayList<AnnotationInstance> list = new ArrayList<AnnotationInstance>(); for (AnnotationDesc annot : annotationDocs) { AnnotationInstance instance = new AnnotationInstance(); AnnotationTypeDoc annotTypeInfo = null; try { annotTypeInfo = annot.annotationType(); instance.name = annot.annotationType().name(); instance.qualifiedName = annot.annotationType().qualifiedTypeName(); } catch (ClassCastException castException) { log.error("Unable to obtain type data about an annotation found on: " + origin); log.error("Add to the -cp parameter the class/jar that defines this annotation."); instance.name = null; instance.qualifiedName = null; } AnnotationDesc.ElementValuePair[] arguments = annot.elementValues(); if (arguments != null && arguments.length > 0) { ArrayList<AnnotationArgument> argumentList = new ArrayList<AnnotationArgument>(); for (AnnotationDesc.ElementValuePair pair : arguments) { AnnotationArgument annotationArgument = new AnnotationArgument(); annotationArgument.name = pair.element().name(); Type annotationArgumentType = pair.element().returnType(); annotationArgument.type = annotationArgumentType.qualifiedTypeName(); annotationArgument.isPrimitive = annotationArgumentType.isPrimitive(); annotationArgument.isArray = annotationArgumentType.dimension().length() > 0; Object objValue = pair.value().value(); if (objValue instanceof AnnotationValue[]) { AnnotationValue[] realValues = (AnnotationValue[]) objValue; String[] values = new String[realValues.length]; for (int i = 0; i < realValues.length; i++) { values[i] = realValues[i].value().toString(); } annotationArgument.value = values; } else if (objValue instanceof Number) { Number number = (Number) objValue; annotationArgument.value = new String[] {number.toString()}; } else if (objValue instanceof Character) { Character character = (Character) objValue; annotationArgument.value = new String[] {character.toString()}; } else if (objValue instanceof Boolean) { Boolean booleanValue = (Boolean) objValue; annotationArgument.value = new String[] {booleanValue.toString()}; } else if (objValue instanceof String) { String stringValue = (String) objValue; annotationArgument.value = new String[] {stringValue}; } else if (objValue instanceof FieldDoc) { FieldDoc field = (FieldDoc) objValue; annotationArgument.value = new String[] {field.name()}; } else if (objValue instanceof ClassDoc) { ClassDoc classDoc = (ClassDoc) objValue; annotationArgument.value = new String[] {classDoc.qualifiedTypeName()}; } argumentList.add(annotationArgument); } instance.arguments = argumentList.toArray(new AnnotationArgument[] {}); } list.add(instance); } annotations = list.toArray(new AnnotationInstance[] {}); } return annotations; }