Refactoring: rename AnnotatedElementDescriptor->AnnotatedElement
This commit is contained in:
+11
-11
@@ -1,19 +1,19 @@
|
||||
package org.jetbrains.kotlin.annotation
|
||||
|
||||
sealed class AnnotatedElementDescriptor(val classFqName: String) {
|
||||
class Class(classFqName: String) : AnnotatedElementDescriptor(classFqName) {
|
||||
sealed class AnnotatedElement(val classFqName: String) {
|
||||
class Class(classFqName: String) : AnnotatedElement(classFqName) {
|
||||
override fun equals(other: Any?) = other is Class && classFqName == other.classFqName
|
||||
|
||||
override fun hashCode() = classFqName.hashCode()
|
||||
}
|
||||
|
||||
class Method(classFqName: String, val methodName: String) : AnnotatedElementDescriptor(classFqName) {
|
||||
class Method(classFqName: String, val methodName: String) : AnnotatedElement(classFqName) {
|
||||
override fun equals(other: Any?) = other is Method && methodName == other.methodName && classFqName == other.classFqName
|
||||
|
||||
override fun hashCode() = 31 * classFqName.hashCode() + methodName.hashCode()
|
||||
}
|
||||
|
||||
class Constructor(classFqName: String) : AnnotatedElementDescriptor(classFqName) {
|
||||
class Constructor(classFqName: String) : AnnotatedElement(classFqName) {
|
||||
companion object {
|
||||
const val METHOD_NAME = "<init>"
|
||||
}
|
||||
@@ -23,25 +23,25 @@ sealed class AnnotatedElementDescriptor(val classFqName: String) {
|
||||
override fun hashCode() = 31 * classFqName.hashCode() + METHOD_NAME.hashCode()
|
||||
}
|
||||
|
||||
class Field(classFqName: String, val fieldName: String) : AnnotatedElementDescriptor(classFqName) {
|
||||
class Field(classFqName: String, val fieldName: String) : AnnotatedElement(classFqName) {
|
||||
override fun equals(other: Any?) = other is Field && fieldName == other.fieldName && classFqName == other.classFqName
|
||||
|
||||
override fun hashCode() = 31 * classFqName.hashCode() + fieldName.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun AnnotationWriter.writeAnnotatedElement(annotation: String, element: AnnotatedElementDescriptor) {
|
||||
fun AnnotationWriter.writeAnnotatedElement(annotation: String, element: AnnotatedElement) {
|
||||
when (element) {
|
||||
is AnnotatedElementDescriptor.Class -> {
|
||||
is AnnotatedElement.Class -> {
|
||||
writeAnnotatedClass(annotation, element.classFqName)
|
||||
}
|
||||
is AnnotatedElementDescriptor.Constructor -> {
|
||||
writeAnnotatedMethod(annotation, element.classFqName, AnnotatedElementDescriptor.Constructor.METHOD_NAME)
|
||||
is AnnotatedElement.Constructor -> {
|
||||
writeAnnotatedMethod(annotation, element.classFqName, AnnotatedElement.Constructor.METHOD_NAME)
|
||||
}
|
||||
is AnnotatedElementDescriptor.Method -> {
|
||||
is AnnotatedElement.Method -> {
|
||||
writeAnnotatedMethod(annotation, element.classFqName, element.methodName)
|
||||
}
|
||||
is AnnotatedElementDescriptor.Field -> {
|
||||
is AnnotatedElement.Field -> {
|
||||
writeAnnotatedField(annotation, element.classFqName, element.fieldName)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -27,13 +27,13 @@ open class KotlinAnnotationProvider(annotationsReader: Reader) {
|
||||
constructor() : this(StringReader(""))
|
||||
|
||||
protected val kotlinClassesInternal = hashSetOf<String>()
|
||||
protected val annotatedKotlinElementsInternal = hashMapOf<String, MutableSet<AnnotatedElementDescriptor>>()
|
||||
protected val annotatedKotlinElementsInternal = hashMapOf<String, MutableSet<AnnotatedElement>>()
|
||||
|
||||
init {
|
||||
readAnnotations(annotationsReader)
|
||||
}
|
||||
|
||||
val annotatedKotlinElements: Map<String, Set<AnnotatedElementDescriptor>>
|
||||
val annotatedKotlinElements: Map<String, Set<AnnotatedElement>>
|
||||
get() = annotatedKotlinElementsInternal
|
||||
|
||||
val kotlinClasses: Set<String>
|
||||
@@ -84,18 +84,18 @@ open class KotlinAnnotationProvider(annotationsReader: Reader) {
|
||||
|
||||
val set = annotatedKotlinElementsInternal.getOrPut(annotationName) { HashSet() }
|
||||
set.add(when (type) {
|
||||
Notation.ANNOTATED_CLASS -> AnnotatedElementDescriptor.Class(classFqName)
|
||||
Notation.ANNOTATED_CLASS -> AnnotatedElement.Class(classFqName)
|
||||
Notation.ANNOTATED_FIELD -> {
|
||||
val name = elementName ?: throw AssertionError("Name for field must be provided")
|
||||
AnnotatedElementDescriptor.Field(classFqName, name)
|
||||
AnnotatedElement.Field(classFqName, name)
|
||||
}
|
||||
Notation.ANNOTATED_METHOD -> {
|
||||
val name = elementName ?: throw AssertionError("Name for method must be provided")
|
||||
|
||||
if (AnnotatedElementDescriptor.Constructor.METHOD_NAME == name)
|
||||
AnnotatedElementDescriptor.Constructor(classFqName)
|
||||
if (AnnotatedElement.Constructor.METHOD_NAME == name)
|
||||
AnnotatedElement.Constructor(classFqName)
|
||||
else
|
||||
AnnotatedElementDescriptor.Method(classFqName, name)
|
||||
AnnotatedElement.Method(classFqName, name)
|
||||
}
|
||||
else -> throw AssertionError("Unknown type: $type")
|
||||
})
|
||||
|
||||
+4
-4
@@ -66,16 +66,16 @@ internal class RoundEnvironmentWrapper(
|
||||
val descriptorsWithKotlin = descriptors.fold(hashSetOf<Element>()) { set, descriptor ->
|
||||
val clazz = processingEnv.elementUtils.getTypeElement(descriptor.classFqName) ?: return@fold set
|
||||
when (descriptor) {
|
||||
is AnnotatedElementDescriptor.Class -> set.add(clazz)
|
||||
is AnnotatedElementDescriptor.Constructor -> {
|
||||
is AnnotatedElement.Class -> set.add(clazz)
|
||||
is AnnotatedElement.Constructor -> {
|
||||
set.addAll(clazz.filterEnclosedElements(ElementKind.CONSTRUCTOR)
|
||||
.filter { it.hasAnnotation(annotationFqName) })
|
||||
}
|
||||
is AnnotatedElementDescriptor.Field -> {
|
||||
is AnnotatedElement.Field -> {
|
||||
set.addAll(clazz.filterEnclosedElements(ElementKind.FIELD, descriptor.fieldName)
|
||||
.filter { it.hasAnnotation(annotationFqName) })
|
||||
}
|
||||
is AnnotatedElementDescriptor.Method -> {
|
||||
is AnnotatedElement.Method -> {
|
||||
set.addAll(clazz.filterEnclosedElements(ElementKind.METHOD, descriptor.methodName)
|
||||
.filter { it.hasAnnotation(annotationFqName) })
|
||||
}
|
||||
|
||||
+7
-4
@@ -67,10 +67,13 @@ open class AnnotationListParseTest {
|
||||
for (element in it.value) {
|
||||
actualAnnotations.append(it.key).append(' ').append(element.classFqName)
|
||||
when (element) {
|
||||
is AnnotatedElementDescriptor.Method -> actualAnnotations.append(' ').append(element.methodName)
|
||||
is AnnotatedElementDescriptor.Field -> actualAnnotations.append(' ').append(element.fieldName)
|
||||
is AnnotatedElementDescriptor.Constructor -> actualAnnotations.append(" ${AnnotatedElementDescriptor.Constructor.METHOD_NAME}")
|
||||
is AnnotatedElementDescriptor.Class -> {}
|
||||
is AnnotatedElement.Method ->
|
||||
actualAnnotations.append(' ').append(element.methodName)
|
||||
is AnnotatedElement.Field ->
|
||||
actualAnnotations.append(' ').append(element.fieldName)
|
||||
is AnnotatedElement.Constructor ->
|
||||
actualAnnotations.append(" ${AnnotatedElement.Constructor.METHOD_NAME}")
|
||||
is AnnotatedElement.Class -> {}
|
||||
}
|
||||
actualAnnotations.append('\n')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user