Cleanup: fix some compiler warnings (mostly deprecations, javaClass)
This commit is contained in:
+1
-1
@@ -84,7 +84,7 @@ class AndroidSyntheticPackageFragmentDescriptor(
|
||||
override fun getContributedVariables(name: Name, location: LookupLocation) = properties().filter { it.name == name }
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(javaClass.simpleName)
|
||||
p.println(this::class.java.simpleName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ class PredefinedPackageFragmentDescriptor(
|
||||
calculatedFunctions().filter { nameFilter(it.name) && kindFilter.accepts(it) }
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(javaClass.simpleName)
|
||||
p.println(this::class.java.simpleName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ class ResourceIdentifier(val name: String, val packageName: String?) {
|
||||
// Without packageName
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
|
||||
other as ResourceIdentifier
|
||||
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ class AndroidXmlVisitor(val elementCallback: (ResourceIdentifier, String, XmlAtt
|
||||
if (idAttribute != null) {
|
||||
val idAttributeValue = idAttribute.value
|
||||
if (idAttributeValue != null) {
|
||||
val xmlType = tag?.getAttribute(AndroidConst.CLASS_ATTRIBUTE_NO_NAMESPACE)?.value ?: localName
|
||||
val xmlType = tag.getAttribute(AndroidConst.CLASS_ATTRIBUTE_NO_NAMESPACE)?.value ?: localName
|
||||
val name = androidIdToName(idAttributeValue)
|
||||
if (name != null) elementCallback(name, xmlType, idAttribute)
|
||||
}
|
||||
|
||||
+2
-2
@@ -83,7 +83,7 @@ class IDEAndroidLayoutXmlFileManager(val module: Module) : AndroidLayoutXmlFileM
|
||||
val propertyName = propertyDescriptor.name.asString()
|
||||
|
||||
val attributes = arrayListOf<PsiElement>()
|
||||
val visitor = AndroidXmlVisitor { retId, wClass, valueElement ->
|
||||
val visitor = AndroidXmlVisitor { retId, _, valueElement ->
|
||||
if (retId.name == propertyName) attributes.add(valueElement)
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class IDEAndroidLayoutXmlFileManager(val module: Module) : AndroidLayoutXmlFileM
|
||||
if (applicationPackage != null) {
|
||||
val mainVariant = mainSourceProvider.toVariant()
|
||||
|
||||
val method = try { javaClass.getMethod("getFlavorSourceProviders") } catch (e: NoSuchMethodException) { null }
|
||||
val method = try { this::class.java.getMethod("getFlavorSourceProviders") } catch (e: NoSuchMethodException) { null }
|
||||
val variants: List<AndroidVariant>? = if (method != null) {
|
||||
val sourceProviders = method.invoke(this) as List<SourceProvider>?
|
||||
sourceProviders?.map { it.toVariant() } ?: listOf()
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ abstract class AbstractAndroidGotoTest : KotlinAndroidTestCase() {
|
||||
|
||||
val targetElement = GotoDeclarationAction.findTargetElement(f.project, f.editor, f.caretOffset)!!
|
||||
|
||||
assert(targetElement is XmlAttributeValue) { "XmlAttributeValue expected, got ${targetElement.javaClass}" }
|
||||
assert(targetElement is XmlAttributeValue) { "XmlAttributeValue expected, got ${targetElement::class.java}" }
|
||||
assertEquals("@+id/${property.name}", (targetElement as XmlAttributeValue).value)
|
||||
}
|
||||
}
|
||||
@@ -62,16 +62,16 @@ class KotlinAndroidJpsPlugin : KotlinJpsCompilerArgumentsProvider {
|
||||
val module = moduleBuildTarget.module
|
||||
if (!hasAndroidJpsPlugin() || !isAndroidModuleWithoutGradle(module)) return emptyList()
|
||||
|
||||
val inJar = File(PathUtil.getJarPathForClass(javaClass)).isFile
|
||||
val inJar = File(PathUtil.getJarPathForClass(this::class.java)).isFile
|
||||
val manifestFile = getAndroidManifest(moduleBuildTarget.module)
|
||||
return if (manifestFile != null) {
|
||||
listOf(
|
||||
if (inJar) {
|
||||
val libDirectory = File(PathUtil.getJarPathForClass(javaClass)).parentFile.parentFile
|
||||
val libDirectory = File(PathUtil.getJarPathForClass(this::class.java)).parentFile.parentFile
|
||||
File(libDirectory, JAR_FILE_NAME).absolutePath
|
||||
} else {
|
||||
// We're in tests now (in out/production/android-extensions/android-extensions-jps)
|
||||
val kotlinProjectDirectory = File(PathUtil.getJarPathForClass(javaClass)).parentFile.parentFile.parentFile
|
||||
val kotlinProjectDirectory = File(PathUtil.getJarPathForClass(this::class.java)).parentFile.parentFile.parentFile
|
||||
File(kotlinProjectDirectory, "dist/kotlinc/lib/$JAR_FILE_NAME").absolutePath
|
||||
})
|
||||
}
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ abstract class AbstractGradleImportHandler : GradleProjectImportHandler {
|
||||
}?.data as? TaskData ?: return null
|
||||
|
||||
val dataStorageTaskDescription = dataStorageTaskData.description ?: return null
|
||||
val (annotationFqNamesList, classpathList) = TASK_DESCRIPTION_REGEX.matchEntire(
|
||||
val (annotationFqNamesList, _) = TASK_DESCRIPTION_REGEX.matchEntire(
|
||||
dataStorageTaskDescription)?.groupValues?.drop(1) ?: return null
|
||||
|
||||
val annotationFqNames = annotationFqNamesList.split(',')
|
||||
|
||||
+3
-3
@@ -202,7 +202,7 @@ abstract class AbstractAnnotationProcessingExtension(
|
||||
private fun KotlinProcessingEnvironment.doAnnotationProcessing(files: Collection<KtFile>): ProcessingResult {
|
||||
run initializeProcessors@ {
|
||||
processors().forEach { it.init(this) }
|
||||
log { "Initialized processors: " + processors().joinToString { it.javaClass.name } }
|
||||
log { "Initialized processors: " + processors().joinToString { it::class.java.name } }
|
||||
}
|
||||
|
||||
val firstRoundAnnotations = RoundAnnotations(
|
||||
@@ -334,7 +334,7 @@ abstract class AbstractAnnotationProcessingExtension(
|
||||
}
|
||||
|
||||
if (applicableAnnotationNames.isEmpty()) {
|
||||
log { "Skipping processor " + processor.javaClass.name + ": no relevant annotations" }
|
||||
log { "Skipping processor " + processor::class.java.name + ": no relevant annotations" }
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ abstract class AbstractAnnotationProcessingExtension(
|
||||
|
||||
log {
|
||||
val annotationNames = applicableAnnotations.joinToString { it.qualifiedName.toString() }
|
||||
"Processing with " + processor.javaClass.name + " (annotations: " + annotationNames + ")"
|
||||
"Processing with " + processor::class.java.name + " (annotations: " + annotationNames + ")"
|
||||
}
|
||||
|
||||
processor.process(applicableAnnotations, roundEnvironment)
|
||||
|
||||
+2
-2
@@ -92,7 +92,7 @@ class KotlinElements(
|
||||
override fun printElements(w: Writer, vararg elements: Element) {
|
||||
val printWriter = PrintWriter(w)
|
||||
for (element in elements) {
|
||||
printWriter.println(element.simpleName.toString() + " (" + element.javaClass.name + ")")
|
||||
printWriter.println(element.simpleName.toString() + " (" + element::class.java.name + ")")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ object Constants {
|
||||
is Int, is Boolean -> value.toString()
|
||||
else -> throw IllegalArgumentException(
|
||||
"Argument is not a primitive type or a string; it " +
|
||||
(if (value == null) "is a null value." else "has class " + value.javaClass.name) + ".")
|
||||
(if (value == null) "is a null value." else "has class " + value::class.java.name) + ".")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -267,7 +267,7 @@ class KotlinTypes(
|
||||
}
|
||||
is JeVariableElement -> substitutor.substitute(element.psi.type).toJeType(psiManager())
|
||||
is JeTypeParameterElement -> substitutor.substitute(element.psi)?.toJeType(psiManager()) ?: element.asType()
|
||||
else -> throw IllegalArgumentException("Invalid element type: ${element.javaClass.name} ($element)")
|
||||
else -> throw IllegalArgumentException("Invalid element type: ${element::class.java.name} ($element)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,6 +308,6 @@ private fun assertKindNot(typeMirror: TypeMirror, vararg kinds: TypeKind): Unit
|
||||
|
||||
private fun assertJeType(type: TypeMirror) {
|
||||
if (type !is JeTypeMirror) {
|
||||
illegalArg("Must be a subclass of JePsiType, got ${type.javaClass.name}")
|
||||
illegalArg("Must be a subclass of JePsiType, got ${type::class.java.name}")
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -59,7 +59,7 @@ class JeClassInitializerExecutableElement(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
|
||||
return psi == (other as JeClassInitializerExecutableElement).psi
|
||||
}
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ class JeMethodExecutableElement(psi: PsiMethod) : JeAbstractElement<PsiMethod>(p
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
|
||||
return psi == (other as JeMethodExecutableElement).psi
|
||||
}
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ class JePackageElement(psi: PsiPackage) : JeAbstractElement<PsiPackage>(psi), Pa
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
|
||||
return psi == (other as JePackageElement).psi
|
||||
}
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ class JeTypeElement(psi: PsiClass) : JeAbstractElement<PsiClass>(psi), TypeEleme
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
|
||||
return psi == (other as JeTypeElement).psi
|
||||
}
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ class JeTypeParameterElement(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
|
||||
return psi == (other as JeTypeParameterElement).psi
|
||||
}
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class JeVariableElement(psi: PsiVariable) : JeAbstractElement<PsiVariable>(psi),
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
|
||||
return psi == (other as JeVariableElement).psi
|
||||
}
|
||||
|
||||
+1
-1
@@ -140,7 +140,7 @@ private fun getObjectType(value: PsiAnnotationMemberValue): PsiType {
|
||||
}
|
||||
}
|
||||
|
||||
throw IllegalArgumentException("Illegal value type: ${value.javaClass}")
|
||||
throw IllegalArgumentException("Illegal value type: ${value::class.java}")
|
||||
}
|
||||
|
||||
private fun castPrimitiveValue(type: PsiType, value: Any?): Any = when (type) {
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class JeArrayType(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
other as? JeArrayType ?: return false
|
||||
|
||||
return componentType == other.componentType
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ class JeClassInitializerExecutableTypeMirror(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
other as? JeClassInitializerExecutableTypeMirror ?: return false
|
||||
return psi == other.psi
|
||||
}
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ class JeDeclaredType(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
other as? JeDeclaredType ?: return false
|
||||
|
||||
return enclosingType == other.enclosingType
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ class JeIntersectionType(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
other as? JeIntersectionType ?: return false
|
||||
|
||||
return bounds == other.bounds
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ class JeMethodExecutableTypeMirror(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
return psi == (other as? JeMethodExecutableTypeMirror)?.psi
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ class JePrimitiveType(override val psiType: PsiPrimitiveType) : JePsiType, Primi
|
||||
|
||||
override fun equals(other: Any?): Boolean{
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
return psiType == (other as? JePrimitiveType)?.psiType
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class JeTypeVariableType(
|
||||
|
||||
override fun equals(other: Any?): Boolean{
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
return psiType == (other as? JeTypeVariableType)?.psiType
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ class JeWildcardType(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
other as? JeWildcardType ?: return false
|
||||
|
||||
return superBound == other.superBound
|
||||
@@ -70,7 +70,7 @@ class JeCapturedWildcardType(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
other as? JeCapturedWildcardType ?: return false
|
||||
|
||||
return superBound == other.superBound
|
||||
|
||||
@@ -86,7 +86,7 @@ class ClasspathBasedKapt3Extension(
|
||||
if (processors.isEmpty()) {
|
||||
logger.info("No annotation processors available, aborting")
|
||||
} else {
|
||||
logger.info { "Annotation processors: " + processors.joinToString { it.javaClass.canonicalName } }
|
||||
logger.info { "Annotation processors: " + processors.joinToString { it::class.java.canonicalName } }
|
||||
}
|
||||
|
||||
return processors
|
||||
|
||||
@@ -79,7 +79,7 @@ class KaptJavaFileObject(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
|
||||
other as KaptJavaFileObject
|
||||
|
||||
|
||||
+1
-1
@@ -632,7 +632,7 @@ class ClassFileToSourceStubConverter(
|
||||
|
||||
is Type -> treeMaker.Select(treeMaker.Type(value), treeMaker.name("class"))
|
||||
is AnnotationNode -> convertAnnotation(value, packageFqName = null, filtered = false)!!
|
||||
else -> throw IllegalArgumentException("Illegal literal expression value: $value (${value.javaClass.canonicalName})")
|
||||
else -> throw IllegalArgumentException("Illegal literal expression value: $value (${value::class.java.canonicalName})")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ abstract class AbstractKotlinKapt3IntegrationTest : CodegenTestCase() {
|
||||
name: String,
|
||||
vararg supportedAnnotations: String,
|
||||
options: Map<String, String> = emptyMap()
|
||||
) = testAP(false, name, options, { set, roundEnv, env -> fail("Should not run") }, *supportedAnnotations)
|
||||
) = testAP(false, name, options, { _, _, _ -> fail("Should not run") }, *supportedAnnotations)
|
||||
|
||||
protected fun testAP(
|
||||
shouldRun: Boolean,
|
||||
|
||||
@@ -26,7 +26,7 @@ import javax.lang.model.element.ExecutableElement
|
||||
|
||||
class KotlinKapt3IntegrationTests : AbstractKotlinKapt3IntegrationTest() {
|
||||
@Test
|
||||
fun testSimple() = test("Simple", "test.MyAnnotation") { set, roundEnv, env ->
|
||||
fun testSimple() = test("Simple", "test.MyAnnotation") { set, roundEnv, _ ->
|
||||
assertEquals(1, set.size)
|
||||
val annotatedElements = roundEnv.getElementsAnnotatedWith(set.single())
|
||||
assertEquals(1, annotatedElements.size)
|
||||
@@ -63,7 +63,7 @@ class KotlinKapt3IntegrationTests : AbstractKotlinKapt3IntegrationTest() {
|
||||
}
|
||||
|
||||
private fun bindingsTest(name: String, test: (File, File, Map<String, KaptJavaFileObject>) -> Unit) {
|
||||
test(name, "test.MyAnnotation") { set, roundEnv, env ->
|
||||
test(name, "test.MyAnnotation") { _, _, _ ->
|
||||
val kaptExtension = AnalysisHandlerExtension.getInstances(myEnvironment.project).firstIsInstance<Kapt3ExtensionForTests>()
|
||||
|
||||
val stubsOutputDir = kaptExtension.stubsOutputDir
|
||||
@@ -79,14 +79,14 @@ class KotlinKapt3IntegrationTests : AbstractKotlinKapt3IntegrationTest() {
|
||||
fun testOptions() = test(
|
||||
"Simple", "test.MyAnnotation",
|
||||
options = mapOf("firstKey" to "firstValue", "secondKey" to "")
|
||||
) { set, roundEnv, env ->
|
||||
) { _, _, env ->
|
||||
val options = env.options
|
||||
assertEquals("firstValue", options["firstKey"])
|
||||
assertTrue("secondKey" in options)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOverloads() = test("Overloads", "test.MyAnnotation") { set, roundEnv, env ->
|
||||
fun testOverloads() = test("Overloads", "test.MyAnnotation") { set, roundEnv, _ ->
|
||||
assertEquals(1, set.size)
|
||||
val annotatedElements = roundEnv.getElementsAnnotatedWith(set.single())
|
||||
assertEquals(1, annotatedElements.size)
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ abstract class AbstractProcessorTest : AbstractBytecodeTextTest() {
|
||||
protected fun testShouldNotRun(
|
||||
name: String,
|
||||
vararg supportedAnnotations: String
|
||||
) = testAP(false, name, { set, roundEnv, env -> fail("Should not run") }, *supportedAnnotations)
|
||||
) = testAP(false, name, { _, _, _ -> fail("Should not run") }, *supportedAnnotations)
|
||||
|
||||
protected fun testAP(
|
||||
shouldRun: Boolean,
|
||||
|
||||
+8
-8
@@ -25,7 +25,7 @@ import javax.lang.model.element.TypeElement
|
||||
class ElementsTests : AbstractProcessorTest() {
|
||||
override val testDataDir = "plugins/annotation-processing/testData/elements"
|
||||
|
||||
fun testOverrides() = test("Overrides", "*") { set, roundEnv, env ->
|
||||
fun testOverrides() = test("Overrides", "*") { _, _, env ->
|
||||
val (parent, child, childChild) = Triple(env.findClass("Parent"), env.findClass("Child"), env.findClass("ChildOfChild"))
|
||||
|
||||
val parentA = parent.findMethod("a")
|
||||
@@ -52,7 +52,7 @@ class ElementsTests : AbstractProcessorTest() {
|
||||
childChildACharSequence.assertOverrides(childA, false)
|
||||
}
|
||||
|
||||
fun testOverrides2() = test("Overrides2", "*") { set, roundEnv, env ->
|
||||
fun testOverrides2() = test("Overrides2", "*") { _, _, env ->
|
||||
val classes = listOf(env.findClass("Intf"), env.findClass("A"), env.findClass("B"))
|
||||
val (intf, a, b) = classes.map { it.findMethod("a") }
|
||||
|
||||
@@ -66,7 +66,7 @@ class ElementsTests : AbstractProcessorTest() {
|
||||
a.assertOverrides(intf, classes[2], true)
|
||||
}
|
||||
|
||||
fun testIsFunctionalInterface() = test("IsFunctionalInterface", "*") { set, roundEnv, env ->
|
||||
fun testIsFunctionalInterface() = test("IsFunctionalInterface", "*") { _, _, env ->
|
||||
with (env.elementUtils as KotlinElements) {
|
||||
fun assertIsFunctionalInterface(fqName: String, isIntf: Boolean) {
|
||||
assertEquals(isIntf, isFunctionalInterface(env.findClass(fqName)))
|
||||
@@ -82,7 +82,7 @@ class ElementsTests : AbstractProcessorTest() {
|
||||
}
|
||||
}
|
||||
|
||||
fun testIsDeprecated() = test("IsDeprecated", "*") { set, roundEnv, env ->
|
||||
fun testIsDeprecated() = test("IsDeprecated", "*") { _, _, env ->
|
||||
with (env.elementUtils) {
|
||||
assertEquals(true, isDeprecated(env.findClass("Depr")))
|
||||
assertEquals(false, isDeprecated(env.findClass("NoDepr")))
|
||||
@@ -90,7 +90,7 @@ class ElementsTests : AbstractProcessorTest() {
|
||||
}
|
||||
}
|
||||
|
||||
fun testGetElementValuesWithDefaults() = test("GetElementValuesWithDefaults", "Anno") { set, roundEnv, env ->
|
||||
fun testGetElementValuesWithDefaults() = test("GetElementValuesWithDefaults", "Anno") { _, _, env ->
|
||||
val (a, b, c, d) = listOf(env.findClass("A"), env.findClass("B"), env.findClass("C"), env.findClass("D"))
|
||||
fun getValues(e: JeTypeElement) = env.elementUtils
|
||||
.getElementValuesWithDefaults(e.annotationMirrors.first { it.psi.qualifiedName == "Anno" })
|
||||
@@ -102,7 +102,7 @@ class ElementsTests : AbstractProcessorTest() {
|
||||
assertEquals(listOf("Mary", 20), getValues(d))
|
||||
}
|
||||
|
||||
fun testGetAllMembers() = test("GetAllMembers", "*") { set, roundEnv, env ->
|
||||
fun testGetAllMembers() = test("GetAllMembers", "*") { _, _, env ->
|
||||
val clazz = env.findClass("MyClass")
|
||||
val members = clazz.enclosedElements
|
||||
assertEquals(5, members.size) // constructor, field, getter/setter, arbitrary method
|
||||
@@ -114,7 +114,7 @@ class ElementsTests : AbstractProcessorTest() {
|
||||
allMembers.sortedBy { it.simpleName.toString() }.joinToString { it.simpleName })
|
||||
}
|
||||
|
||||
fun testGetPackageOf() = test("GetPackageOf", "*") { set, roundEnv, env ->
|
||||
fun testGetPackageOf() = test("GetPackageOf", "*") { _, _, env ->
|
||||
val e = env.elementUtils
|
||||
|
||||
val myClass = env.findClass("test.MyClass")
|
||||
@@ -130,7 +130,7 @@ class ElementsTests : AbstractProcessorTest() {
|
||||
assertEquals(3, classes.size)
|
||||
}
|
||||
|
||||
fun testGetArrayType() = test("GetPackageOf", "*") { set, roundEnv, env ->
|
||||
fun testGetArrayType() = test("GetPackageOf", "*") { _, _, env ->
|
||||
val myClass = env.findClass("test.MyClass").asType()
|
||||
val array = env.typeUtils.getArrayType(myClass)
|
||||
assert(array is JeArrayType)
|
||||
|
||||
+22
-22
@@ -38,7 +38,7 @@ annotation class ColorsAnnotation(val colors: Array<RGBColors>)
|
||||
class ProcessorTests : AbstractProcessorTest() {
|
||||
override val testDataDir = "plugins/annotation-processing/testData/processors"
|
||||
|
||||
fun testSimple() = test("Simple", "Anno") { set, roundEnv, env ->
|
||||
fun testSimple() = test("Simple", "Anno") { set, roundEnv, _ ->
|
||||
assertEquals(1, set.size)
|
||||
val annotated = roundEnv.getElementsAnnotatedWith(set.first())
|
||||
assertEquals(3, annotated.size)
|
||||
@@ -52,7 +52,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
}
|
||||
}
|
||||
|
||||
fun testSeveralAnnotations() = test("SeveralAnnotations", "Name", "Age") { set, roundEnv, env ->
|
||||
fun testSeveralAnnotations() = test("SeveralAnnotations", "Name", "Age") { set, roundEnv, _ ->
|
||||
val annos = set.toList()
|
||||
|
||||
assertEquals(2, annos.size)
|
||||
@@ -70,15 +70,15 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
}
|
||||
}
|
||||
|
||||
fun testStar() = test("Star", "*") { set, roundEnv, env ->
|
||||
fun testStar() = test("Star", "*") { set, _, _ ->
|
||||
assertEquals(true, set.any { it.qualifiedName.toString() == "Anno" })
|
||||
}
|
||||
|
||||
fun testStar2() = test("Star", "Anno", "*") { set, roundEnv, env ->
|
||||
fun testStar2() = test("Star", "Anno", "*") { set, _, _ ->
|
||||
assertEquals(true, set.any { it.qualifiedName.toString() == "Anno" })
|
||||
}
|
||||
|
||||
fun testStar3() = test("Star3", "Anno", "*") { set, roundEnv, env ->
|
||||
fun testStar3() = test("Star3", "Anno", "*") { set, _, _ ->
|
||||
assertEquals(true, set.any { it.qualifiedName.toString() == "Anno2" })
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
|
||||
fun testInheritedAnnotations() {
|
||||
val handledClasses = mutableListOf<String>()
|
||||
test("InheritedAnnotations", "Anno") { set, roundEnv, env ->
|
||||
test("InheritedAnnotations", "Anno") { set, roundEnv, _ ->
|
||||
assertEquals(1, set.size)
|
||||
val annotatedElements = roundEnv.getElementsAnnotatedWith(set.first())
|
||||
for (element in annotatedElements) {
|
||||
@@ -103,7 +103,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
assertEquals(listOf("Base", "Impl", "Intf"), handledClasses.sorted())
|
||||
}
|
||||
|
||||
fun testInheritedAnnotationsOverridden() = test("InheritedAnnotationsOverridden", "Anno") { set, roundEnv, env ->
|
||||
fun testInheritedAnnotationsOverridden() = test("InheritedAnnotationsOverridden", "Anno") { set, roundEnv, _ ->
|
||||
assertEquals(1, set.size)
|
||||
val annotatedElements = roundEnv.getElementsAnnotatedWith(set.first())
|
||||
assertEquals(2, annotatedElements.size)
|
||||
@@ -112,7 +112,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
assertEquals("Tom", implAnnotations.first().elementValues.values.first().value)
|
||||
}
|
||||
|
||||
fun testNested() = test("Nested", "Anno") { set, roundEnv, env ->
|
||||
fun testNested() = test("Nested", "Anno") { set, roundEnv, _ ->
|
||||
assertEquals(1, set.size)
|
||||
val annotatedElements = roundEnv.getElementsAnnotatedWith(set.first())
|
||||
assertEquals(1, annotatedElements.size)
|
||||
@@ -127,21 +127,21 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
assertTrue((anno2.getParam("e") as JeArrayAnnotationValue).value.first() is JeTypeAnnotationValue)
|
||||
}
|
||||
|
||||
fun testEnumArray() = test("EnumArray", "*") { set, roundEnv, env ->
|
||||
fun testEnumArray() = test("EnumArray", "*") { _, _, env ->
|
||||
val testClass = env.findClass("org.jetbrains.kotlin.annotation.processing.test.processor.Test")
|
||||
val enumAnno = testClass.getAnnotation(ColorsAnnotation::class.java)
|
||||
assertNotNull(enumAnno)
|
||||
assertEquals(listOf("BLUE", "RED"), enumAnno!!.colors.map { it.name })
|
||||
}
|
||||
|
||||
fun testStringArray() = test("StringArray", "*") { set, roundEnv, env ->
|
||||
fun testStringArray() = test("StringArray", "*") { _, _, env ->
|
||||
val testClass = env.findClass("Test")
|
||||
val suppress = testClass.getAnnotation(Suppress::class.java)
|
||||
assertNotNull(suppress)
|
||||
assertEquals(listOf("Tom", "Mary"), suppress!!.names.toList())
|
||||
}
|
||||
|
||||
fun testTypeArguments() = test("TypeArguments", "*") { set, roundEnv, env ->
|
||||
fun testTypeArguments() = test("TypeArguments", "*") { _, _, env ->
|
||||
val classA = env.findClass("A")
|
||||
val superB = classA.superclass as JeDeclaredType
|
||||
val interfaceC = classA.interfaces[0] as JeDeclaredType
|
||||
@@ -150,7 +150,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
assertTrue(interfaceC.typeArguments.size == 1)
|
||||
}
|
||||
|
||||
fun testTypeArguments2() = test("TypeArguments2", "*") { set, roundEnv, env ->
|
||||
fun testTypeArguments2() = test("TypeArguments2", "*") { _, _, env ->
|
||||
val b = env.findClass("B")
|
||||
val bSuperTypes = env.typeUtils.directSupertypes(b.asType())
|
||||
assertEquals(1, bSuperTypes.size)
|
||||
@@ -182,7 +182,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
assertEquals("I3<java.util.List<? extends java.lang.String>>", i3.toString())
|
||||
}
|
||||
|
||||
fun testErasureSimple() = test("ErasureSimple", "*") { set, roundEnv, env ->
|
||||
fun testErasureSimple() = test("ErasureSimple", "*") { _, _, env ->
|
||||
val test = env.findClass("Test")
|
||||
val int = test.findMethod("a").returnType
|
||||
val void = test.findMethod("b").returnType
|
||||
@@ -190,7 +190,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
assertEquals(void, env.typeUtils.erasure(void))
|
||||
}
|
||||
|
||||
fun testErasure2() = test("Erasure2", "*") { set, roundEnv, env ->
|
||||
fun testErasure2() = test("Erasure2", "*") { _, _, env ->
|
||||
val erasure = fun (t: JeMethodExecutableTypeMirror) = env.typeUtils.erasure(t)
|
||||
fun JeTypeElement.check(methodName: String, toString: String, transform: (JeMethodExecutableTypeMirror) -> TypeMirror = { it }) {
|
||||
val method = enclosedElements.first { it is JeMethodExecutableElement && it.simpleName.toString() == methodName }
|
||||
@@ -246,7 +246,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
.firstIsInstance<AnnotationProcessingExtensionForTests>()
|
||||
|
||||
private fun incrementalDataTest(fileName: String, @Language("TEXT") expectedText: String) {
|
||||
test(fileName, "Anno", "Anno2", "Anno3") { set, roundEnv, env -> }
|
||||
test(fileName, "Anno", "Anno2", "Anno3") { _, _, _ -> }
|
||||
val ext = getKapt2Extension()
|
||||
val incrementalDataFile = ext.incrementalDataFile
|
||||
assertNotNull(incrementalDataFile)
|
||||
@@ -254,7 +254,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
assertEquals(expectedText, text)
|
||||
}
|
||||
|
||||
fun testKotlinAnnotationDefaultValueFromBinary() = test("DefaultValueFromBinary", "*") { set, roundEnv, env ->
|
||||
fun testKotlinAnnotationDefaultValueFromBinary() = test("DefaultValueFromBinary", "*") { _, _, env ->
|
||||
fun check(expectedValue: Boolean, className: String) {
|
||||
val clazz = env.findClass(className)
|
||||
val anno = clazz.getAnnotation(JvmSuppressWildcards::class.java)!!
|
||||
@@ -266,7 +266,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
check(false, "TestFalse")
|
||||
}
|
||||
|
||||
fun testAsMemberOf() = test("AsMemberOf", "*") { set, roundEnv, env ->
|
||||
fun testAsMemberOf() = test("AsMemberOf", "*") { _, _, env ->
|
||||
val f = env.findClass("Test").findField("f")
|
||||
val fType = f.asType() as JeDeclaredType
|
||||
|
||||
@@ -290,7 +290,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
check(implM, "(java.lang.String)java.lang.String")
|
||||
}
|
||||
|
||||
fun testAsMemberOfTypeParameters() = test("AsMemberOfTypeParameters", "*") { set, roundEnv, env ->
|
||||
fun testAsMemberOfTypeParameters() = test("AsMemberOfTypeParameters", "*") { _, _, env ->
|
||||
val intf = env.findClass("Intf")
|
||||
val intfT = intf.typeParameters[0]
|
||||
val base = env.findClass("Base")
|
||||
@@ -309,7 +309,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
fun testDispose() {
|
||||
var savedEnv: ProcessingEnvironment? = null
|
||||
|
||||
test("AsMemberOf", "*") { set, roundEnv, env ->
|
||||
test("AsMemberOf", "*") { _, _, env ->
|
||||
savedEnv = env
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
test { filer }
|
||||
|
||||
fun testDisposable(name: String) {
|
||||
test { (javaClass.methods.first { it.name.startsWith("$name$") }.invoke(this) as DisposableRef<*>).invoke() }
|
||||
test { (this::class.java.methods.first { it.name.startsWith("$name$") }.invoke(this) as DisposableRef<*>).invoke() }
|
||||
}
|
||||
|
||||
testDisposable("getProject")
|
||||
@@ -342,7 +342,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
}
|
||||
}
|
||||
|
||||
fun testMapMutableMap() = test("MapMutableMap", "*") { set, roundEnv, env ->
|
||||
fun testMapMutableMap() = test("MapMutableMap", "*") { _, _, env ->
|
||||
val test = env.findClass("Test")
|
||||
fun test(name: String, expected: String) {
|
||||
assertEquals(expected, test.findMethods(name).single().parameters.single().asType().toString())
|
||||
@@ -359,7 +359,7 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
|
||||
var kotlinEnv: KotlinProcessingEnvironment? = null
|
||||
try {
|
||||
test("MapMutableMap", "*") { set, roundEnv, env ->
|
||||
test("MapMutableMap", "*") { _, _, env ->
|
||||
kotlinEnv = env as KotlinProcessingEnvironment
|
||||
throw HiThere()
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin {
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor
|
||||
if (resultingDescriptor !is FunctionDescriptor || resultingDescriptor.name.asString() != methodName) return null
|
||||
|
||||
val parent = element.parent ?: return null
|
||||
val parent = element.parent
|
||||
val parentUElement = convertElementWithParent(parent, null) ?: return null
|
||||
|
||||
val uExpression = KotlinUFunctionCallExpression(element, parentUElement, resolvedCall)
|
||||
|
||||
@@ -46,7 +46,7 @@ class UastKotlinPsiParameter(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
return ktParameter == (other as? UastKotlinPsiParameter)?.ktParameter
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class UastKotlinPsiVariable(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
if (other == null || other::class.java != this::class.java) return false
|
||||
return ktElement == (other as? UastKotlinPsiVariable)?.ktElement
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
}
|
||||
|
||||
@Test fun testAnnotationParameters() {
|
||||
doTest("AnnotationParameters") { name, file ->
|
||||
doTest("AnnotationParameters") { _, file ->
|
||||
val annotation = file.findElementByText<UAnnotation>("@IntRange(from = 10, to = 0)")
|
||||
assertEquals(annotation.findAttributeValue("from")?.evaluate(), 10)
|
||||
assertEquals(annotation.findAttributeValue("to")?.evaluate(), 0)
|
||||
@@ -23,7 +23,7 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
}
|
||||
|
||||
@Test fun testConvertStringTemplate() {
|
||||
doTest("StringTemplateInClass") { name, file ->
|
||||
doTest("StringTemplateInClass") { _, file ->
|
||||
val literalExpression = file.findElementByText<ULiteralExpression>("lorem")
|
||||
val psi = literalExpression.psi!!
|
||||
Assert.assertTrue(psi is KtLiteralStringTemplateEntry)
|
||||
|
||||
Reference in New Issue
Block a user