Kapt: Minor, refactor JeAnnotationMirror:getElementValues()
(cherry picked from commit 649b938)
This commit is contained in:
committed by
Yan Zhulanow
parent
23b343bb03
commit
cd09f2bcb8
+6
-14
@@ -33,27 +33,19 @@ class JeAnnotationMirror(val psi: PsiAnnotation) : AnnotationMirror {
|
|||||||
return JeDeclaredType(PsiTypesUtil.getClassType(psiClass), psiClass)
|
return JeDeclaredType(PsiTypesUtil.getClassType(psiClass), psiClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getElementValues(): Map<out ExecutableElement, AnnotationValue> {
|
override fun getElementValues(): Map<out ExecutableElement, AnnotationValue> = getElementValues(false)
|
||||||
val annotationClass = resolveAnnotationClass() ?: return emptyMap()
|
|
||||||
|
|
||||||
return mutableMapOf<ExecutableElement, AnnotationValue>().apply {
|
fun getAllElementValues(): Map<out ExecutableElement, AnnotationValue> = getElementValues(true)
|
||||||
for (attribute in psi.parameterList.attributes) {
|
|
||||||
val attributeValue = attribute.value ?: continue
|
|
||||||
val method = annotationClass.methods.firstOrNull {
|
|
||||||
it is PsiAnnotationMethod && it.name == attribute.name
|
|
||||||
} ?: return emptyMap()
|
|
||||||
put(JeMethodExecutableElement(method), JeAnnotationValue(attributeValue))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getAllElementValues(): Map<out ExecutableElement, AnnotationValue> {
|
private fun getElementValues(withDefaults: Boolean): Map<out ExecutableElement, AnnotationValue> {
|
||||||
val annotationClass = resolveAnnotationClass() ?: return emptyMap()
|
val annotationClass = resolveAnnotationClass() ?: return emptyMap()
|
||||||
|
|
||||||
return mutableMapOf<ExecutableElement, AnnotationValue>().apply {
|
return mutableMapOf<ExecutableElement, AnnotationValue>().apply {
|
||||||
for (method in annotationClass.methods) {
|
for (method in annotationClass.methods) {
|
||||||
method as? PsiAnnotationMethod ?: continue
|
method as? PsiAnnotationMethod ?: continue
|
||||||
val attributeValue = psi.findAttributeValue(method.name) ?: method.defaultValue ?: continue
|
val attributeValue = psi.findDeclaredAttributeValue(method.name)
|
||||||
|
?: (if (withDefaults) method.defaultValue else null)
|
||||||
|
?: continue
|
||||||
put(JeMethodExecutableElement(method), JeAnnotationValue(attributeValue))
|
put(JeMethodExecutableElement(method), JeAnnotationValue(attributeValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user