Cleanup in libraries and tools: use property access syntax.

This commit is contained in:
Ilya Gorbunov
2016-01-13 21:00:36 +03:00
parent 19a4f65fd1
commit 57dcbe0aea
22 changed files with 197 additions and 197 deletions
@@ -95,7 +95,7 @@ public abstract class AnnotationProcessorWrapper(
return
}
val annotationsFilePath = processingEnv.getOptions().get(KAPT_ANNOTATION_OPTION)
val annotationsFilePath = processingEnv.options[KAPT_ANNOTATION_OPTION]
val annotationsFile = if (annotationsFilePath != null) File(annotationsFilePath) else null
kotlinAnnotationsProvider = if (annotationsFile != null && annotationsFile.exists()) {
FileKotlinAnnotationProvider(annotationsFile)
@@ -108,13 +108,13 @@ public abstract class AnnotationProcessorWrapper(
}
override fun getSupportedAnnotationTypes(): MutableSet<String> {
val supportedAnnotations = processor.getSupportedAnnotationTypes().toMutableSet()
val supportedAnnotations = processor.supportedAnnotationTypes.toMutableSet()
supportedAnnotations.add("__gen.KotlinAptAnnotation")
return supportedAnnotations
}
override fun getSupportedSourceVersion(): SourceVersion? {
return processor.getSupportedSourceVersion()
return processor.supportedSourceVersion
}
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
@@ -127,13 +127,13 @@ public abstract class AnnotationProcessorWrapper(
}
override fun getSupportedOptions(): MutableSet<String> {
val supportedOptions = processor.getSupportedOptions().toHashSet()
val supportedOptions = processor.supportedOptions.toHashSet()
supportedOptions.add(KAPT_ANNOTATION_OPTION)
return supportedOptions
}
private fun ProcessingEnvironment.err(message: String) {
getMessager().printMessage(Diagnostic.Kind.ERROR, message)
messager.printMessage(Diagnostic.Kind.ERROR, message)
}
}
@@ -17,18 +17,18 @@ internal class RoundEnvironmentWrapper(
) : RoundEnvironment {
override fun getRootElements(): MutableSet<out Element>? {
return parent.getRootElements()
return parent.rootElements
}
override fun getElementsAnnotatedWith(a: TypeElement): MutableSet<out Element>? {
val elements = parent.getElementsAnnotatedWith(a).toHashSet()
elements.addAll(resolveKotlinElements(a.getQualifiedName().toString()))
elements.addAll(resolveKotlinElements(a.qualifiedName.toString()))
return elements
}
override fun getElementsAnnotatedWith(a: Class<out Annotation>): MutableSet<out Element>? {
val elements = parent.getElementsAnnotatedWith(a).toHashSet()
elements.addAll(resolveKotlinElements(a.getName()))
elements.addAll(resolveKotlinElements(a.name))
return elements
}
@@ -37,24 +37,24 @@ internal class RoundEnvironmentWrapper(
override fun errorRaised() = parent.errorRaised()
private fun TypeElement.filterEnclosedElements(kind: ElementKind, name: String): List<Element> {
return getEnclosedElements().filter { it.getKind() == kind && it.getSimpleName().toString() == name }
return enclosedElements.filter { it.kind == kind && it.simpleName.toString() == name }
}
private fun TypeElement.filterEnclosedElements(kind: ElementKind): List<Element> {
return getEnclosedElements().filter { it.getKind() == kind }
return enclosedElements.filter { it.kind == kind }
}
private fun Element.hasAnnotation(annotationFqName: String): Boolean {
return getAnnotationMirrors().any { annotationFqName == it.getAnnotationType().asElement().toString() }
return annotationMirrors.any { annotationFqName == it.annotationType.asElement().toString() }
}
private fun TypeElement.hasInheritedAnnotation(annotationFqName: String): Boolean {
if (hasAnnotation(annotationFqName)) return true
val superclassMirror = getSuperclass()
val superclassMirror = superclass
if (superclassMirror is NoType) return false
val superClass = processingEnv.getTypeUtils().asElement(superclassMirror)
val superClass = processingEnv.typeUtils.asElement(superclassMirror)
if (superClass !is TypeElement) return false
return superClass.hasInheritedAnnotation(annotationFqName)
@@ -65,7 +65,7 @@ internal class RoundEnvironmentWrapper(
val descriptors = kotlinAnnotationsProvider.annotatedKotlinElements.get(annotationFqName) ?: setOf()
val descriptorsWithKotlin = descriptors.fold(hashSetOf<Element>()) { set, descriptor ->
val clazz = processingEnv.getElementUtils().getTypeElement(descriptor.classFqName) ?: return@fold set
val clazz = processingEnv.elementUtils.getTypeElement(descriptor.classFqName) ?: return@fold set
when (descriptor) {
is AnnotatedClassDescriptor -> set.add(clazz)
is AnnotatedConstructorDescriptor -> {
@@ -85,12 +85,12 @@ internal class RoundEnvironmentWrapper(
}
if (kotlinAnnotationsProvider.supportInheritedAnnotations) {
val isInherited = processingEnv.getElementUtils().getTypeElement(annotationFqName)
?.hasAnnotation(Inherited::class.java.getCanonicalName()) ?: false
val isInherited = processingEnv.elementUtils.getTypeElement(annotationFqName)
?.hasAnnotation(Inherited::class.java.canonicalName) ?: false
if (isInherited) {
kotlinAnnotationsProvider.kotlinClasses.forEach { classFqName ->
val clazz = processingEnv.getElementUtils().getTypeElement(classFqName) ?: return@forEach
val clazz = processingEnv.elementUtils.getTypeElement(classFqName) ?: return@forEach
if (clazz.hasInheritedAnnotation(annotationFqName)) {
descriptorsWithKotlin.add(clazz)
}
@@ -54,7 +54,7 @@ public class AnnotationListParseTest {
val annotationsFile = File(resourcesRootFile, "$testName/annotations.txt")
val expectedFile = File(resourcesRootFile, "$testName/parsed.txt")
assertTrue(annotationsFile.getAbsolutePath() + " does not exist.", annotationsFile.exists())
assertTrue(annotationsFile.absolutePath + " does not exist.", annotationsFile.exists())
val annotationProvider = FileKotlinAnnotationProvider(annotationsFile)
val parsedAnnotations = annotationProvider.annotatedKotlinElements