diff --git a/.bunch b/.bunch index 22ac050a9a3..6028c56b0f1 100644 --- a/.bunch +++ b/.bunch @@ -1,9 +1,9 @@ -183 -182 -181_182 -as32_181_182 -as33_182 -as34 -as35_191 191 -192_191 +192 +183 +182_183 +181_182_183 +as32_181_182_183 +as33_182_183 +as34_183 +as35 diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt index a6d2a7575f0..ebb3b448c7c 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt @@ -51,7 +51,11 @@ class MockExternalAnnotationsManager : ExternalAnnotationsManager() { throw UnsupportedOperationException("not implemented") } - override fun hasAnnotationRootsForFile(file: VirtualFile): Boolean { - throw UnsupportedOperationException("not implemented") - } + override fun hasAnnotationRootsForFile(file: VirtualFile): Boolean = false + + override fun findDefaultConstructorExternalAnnotations(aClass: PsiClass, annotationFQN: String): List = emptyList() + + override fun findDefaultConstructorExternalAnnotations(aClass: PsiClass): List = emptyList() + + override fun findExternalAnnotations(listOwner: PsiModifierListOwner, annotationFQN: String): List = emptyList() } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt.191 b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt.183 similarity index 84% rename from compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt.191 rename to compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt.183 index ebb3b448c7c..a6d2a7575f0 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt.191 +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/MockExternalAnnotationsManager.kt.183 @@ -51,11 +51,7 @@ class MockExternalAnnotationsManager : ExternalAnnotationsManager() { throw UnsupportedOperationException("not implemented") } - override fun hasAnnotationRootsForFile(file: VirtualFile): Boolean = false - - override fun findDefaultConstructorExternalAnnotations(aClass: PsiClass, annotationFQN: String): List = emptyList() - - override fun findDefaultConstructorExternalAnnotations(aClass: PsiClass): List = emptyList() - - override fun findExternalAnnotations(listOwner: PsiModifierListOwner, annotationFQN: String): List = emptyList() + override fun hasAnnotationRootsForFile(file: VirtualFile): Boolean { + throw UnsupportedOperationException("not implemented") + } } diff --git a/compiler/compiler.pro b/compiler/compiler.pro index 765db257657..c8589f42d1d 100644 --- a/compiler/compiler.pro +++ b/compiler/compiler.pro @@ -16,6 +16,7 @@ messages/**) -dontnote ** -dontwarn com.intellij.util.ui.IsRetina* +-dontwarn com.intellij.util.ui.UIUtilities -dontwarn com.intellij.util.RetinaImage* -dontwarn apple.awt.* -dontwarn dk.brics.automaton.* @@ -201,7 +202,6 @@ messages/**) -keep class org.jetbrains.org.objectweb.asm.tree.FieldNode { *; } -keep class org.jetbrains.org.objectweb.asm.tree.ParameterNode { *; } -keep class org.jetbrains.org.objectweb.asm.tree.TypeAnnotationNode { *; } --keep class org.jetbrains.org.objectweb.asm.tree.InsnList { *; } -keep class org.jetbrains.org.objectweb.asm.signature.SignatureReader { *; } -keep class org.jetbrains.org.objectweb.asm.signature.SignatureVisitor { *; } diff --git a/compiler/compiler.pro.191 b/compiler/compiler.pro.183 similarity index 99% rename from compiler/compiler.pro.191 rename to compiler/compiler.pro.183 index c8589f42d1d..765db257657 100644 --- a/compiler/compiler.pro.191 +++ b/compiler/compiler.pro.183 @@ -16,7 +16,6 @@ messages/**) -dontnote ** -dontwarn com.intellij.util.ui.IsRetina* --dontwarn com.intellij.util.ui.UIUtilities -dontwarn com.intellij.util.RetinaImage* -dontwarn apple.awt.* -dontwarn dk.brics.automaton.* @@ -202,6 +201,7 @@ messages/**) -keep class org.jetbrains.org.objectweb.asm.tree.FieldNode { *; } -keep class org.jetbrains.org.objectweb.asm.tree.ParameterNode { *; } -keep class org.jetbrains.org.objectweb.asm.tree.TypeAnnotationNode { *; } +-keep class org.jetbrains.org.objectweb.asm.tree.InsnList { *; } -keep class org.jetbrains.org.objectweb.asm.signature.SignatureReader { *; } -keep class org.jetbrains.org.objectweb.asm.signature.SignatureVisitor { *; } diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt old mode 100755 new mode 100644 index a45a8a76d34..5ee58a570e6 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -19,16 +19,7 @@ package org.jetbrains.kotlin.generators.tests import org.jetbrains.kotlin.AbstractDataFlowValueRenderingTest import org.jetbrains.kotlin.addImport.AbstractAddImportTest import org.jetbrains.kotlin.allopen.AbstractBytecodeListingTestForAllOpen -import org.jetbrains.kotlin.android.* -import org.jetbrains.kotlin.android.annotator.AbstractAndroidGutterIconTest -import org.jetbrains.kotlin.android.configure.AbstractConfigureProjectTest -import org.jetbrains.kotlin.android.folding.AbstractAndroidResourceFoldingTest -import org.jetbrains.kotlin.android.intention.AbstractAndroidIntentionTest -import org.jetbrains.kotlin.android.intention.AbstractAndroidResourceIntentionTest -import org.jetbrains.kotlin.android.lint.AbstractKotlinLintTest import org.jetbrains.kotlin.android.parcel.AbstractParcelBytecodeListingTest -import org.jetbrains.kotlin.android.quickfix.AbstractAndroidLintQuickfixTest -import org.jetbrains.kotlin.android.quickfix.AbstractAndroidQuickFixMultiFileTest import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidBoxTest import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidBytecodeShapeTest import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidSyntheticPropertyDescriptorTest @@ -150,15 +141,13 @@ import org.jetbrains.kotlin.jps.build.* import org.jetbrains.kotlin.jps.build.dependeciestxt.actualizeMppJpsIncTestCaseDirs import org.jetbrains.kotlin.jps.incremental.AbstractJsProtoComparisonTest import org.jetbrains.kotlin.jps.incremental.AbstractJvmProtoComparisonTest +import org.jetbrains.kotlin.kapt.cli.test.AbstractArgumentParsingTest +import org.jetbrains.kotlin.kapt.cli.test.AbstractKaptToolIntegrationTest import org.jetbrains.kotlin.jvm.abi.AbstractCompareJvmAbiTest import org.jetbrains.kotlin.jvm.abi.AbstractCompileAgainstJvmAbiTest import org.jetbrains.kotlin.jvm.abi.AbstractJvmAbiContentTest -import org.jetbrains.kotlin.kapt.cli.test.AbstractArgumentParsingTest -import org.jetbrains.kotlin.kapt.cli.test.AbstractKaptToolIntegrationTest import org.jetbrains.kotlin.kapt3.test.AbstractClassFileToSourceStubConverterTest import org.jetbrains.kotlin.kapt3.test.AbstractKotlinKaptContextTest -import org.jetbrains.kotlin.nj2k.AbstractNewJavaToKotlinConverterSingleFileTest -import org.jetbrains.kotlin.nj2k.AbstractNullabilityAnalysisTest import org.jetbrains.kotlin.noarg.AbstractBlackBoxCodegenTestForNoArg import org.jetbrains.kotlin.noarg.AbstractBytecodeListingTestForNoArg import org.jetbrains.kotlin.psi.patternMatching.AbstractPsiUnifierTest @@ -654,10 +643,6 @@ fun main(args: Array) { model("debugger/tinyApp/src/evaluate/multipleBreakpoints", testMethod = "doMultipleBreakpointsTest") } - testClass { - model("debugger/tinyApp/src/asyncStackTrace") - } - testClass { model("debugger/fileRanking") } @@ -967,14 +952,8 @@ fun main(args: Array) { } } - testGroup("nj2k/tests", "nj2k/testData/") { - testClass { - model("nullabilityAnalysis") - } - } - testGroup("jps-plugin/jps-tests/test", "jps-plugin/testData") { - testClass { + testClass { model("incremental/multiModule/common", extension = null, excludeParentDirs = true) model("incremental/multiModule/jvm", extension = null, excludeParentDirs = true) model("incremental/multiModule/multiplatform/custom", extension = null, excludeParentDirs = true) @@ -1142,7 +1121,7 @@ fun main(args: Array) { model("script", extension = "kts") } } - +/* testGroup("plugins/android-extensions/android-extensions-idea/tests", "plugins/android-extensions/android-extensions-idea/testData") { testClass { model("android/completion", recursive = false, extension = null) @@ -1215,4 +1194,5 @@ fun main(args: Array) { model("android/gutterIcon") } } +*/ } diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.191 b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 old mode 100755 new mode 100644 similarity index 98% rename from generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.191 rename to generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 index 5ee58a570e6..a45a8a76d34 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.191 +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 @@ -19,7 +19,16 @@ package org.jetbrains.kotlin.generators.tests import org.jetbrains.kotlin.AbstractDataFlowValueRenderingTest import org.jetbrains.kotlin.addImport.AbstractAddImportTest import org.jetbrains.kotlin.allopen.AbstractBytecodeListingTestForAllOpen +import org.jetbrains.kotlin.android.* +import org.jetbrains.kotlin.android.annotator.AbstractAndroidGutterIconTest +import org.jetbrains.kotlin.android.configure.AbstractConfigureProjectTest +import org.jetbrains.kotlin.android.folding.AbstractAndroidResourceFoldingTest +import org.jetbrains.kotlin.android.intention.AbstractAndroidIntentionTest +import org.jetbrains.kotlin.android.intention.AbstractAndroidResourceIntentionTest +import org.jetbrains.kotlin.android.lint.AbstractKotlinLintTest import org.jetbrains.kotlin.android.parcel.AbstractParcelBytecodeListingTest +import org.jetbrains.kotlin.android.quickfix.AbstractAndroidLintQuickfixTest +import org.jetbrains.kotlin.android.quickfix.AbstractAndroidQuickFixMultiFileTest import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidBoxTest import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidBytecodeShapeTest import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidSyntheticPropertyDescriptorTest @@ -141,13 +150,15 @@ import org.jetbrains.kotlin.jps.build.* import org.jetbrains.kotlin.jps.build.dependeciestxt.actualizeMppJpsIncTestCaseDirs import org.jetbrains.kotlin.jps.incremental.AbstractJsProtoComparisonTest import org.jetbrains.kotlin.jps.incremental.AbstractJvmProtoComparisonTest -import org.jetbrains.kotlin.kapt.cli.test.AbstractArgumentParsingTest -import org.jetbrains.kotlin.kapt.cli.test.AbstractKaptToolIntegrationTest import org.jetbrains.kotlin.jvm.abi.AbstractCompareJvmAbiTest import org.jetbrains.kotlin.jvm.abi.AbstractCompileAgainstJvmAbiTest import org.jetbrains.kotlin.jvm.abi.AbstractJvmAbiContentTest +import org.jetbrains.kotlin.kapt.cli.test.AbstractArgumentParsingTest +import org.jetbrains.kotlin.kapt.cli.test.AbstractKaptToolIntegrationTest import org.jetbrains.kotlin.kapt3.test.AbstractClassFileToSourceStubConverterTest import org.jetbrains.kotlin.kapt3.test.AbstractKotlinKaptContextTest +import org.jetbrains.kotlin.nj2k.AbstractNewJavaToKotlinConverterSingleFileTest +import org.jetbrains.kotlin.nj2k.AbstractNullabilityAnalysisTest import org.jetbrains.kotlin.noarg.AbstractBlackBoxCodegenTestForNoArg import org.jetbrains.kotlin.noarg.AbstractBytecodeListingTestForNoArg import org.jetbrains.kotlin.psi.patternMatching.AbstractPsiUnifierTest @@ -643,6 +654,10 @@ fun main(args: Array) { model("debugger/tinyApp/src/evaluate/multipleBreakpoints", testMethod = "doMultipleBreakpointsTest") } + testClass { + model("debugger/tinyApp/src/asyncStackTrace") + } + testClass { model("debugger/fileRanking") } @@ -952,8 +967,14 @@ fun main(args: Array) { } } + testGroup("nj2k/tests", "nj2k/testData/") { + testClass { + model("nullabilityAnalysis") + } + } + testGroup("jps-plugin/jps-tests/test", "jps-plugin/testData") { - testClass { + testClass { model("incremental/multiModule/common", extension = null, excludeParentDirs = true) model("incremental/multiModule/jvm", extension = null, excludeParentDirs = true) model("incremental/multiModule/multiplatform/custom", extension = null, excludeParentDirs = true) @@ -1121,7 +1142,7 @@ fun main(args: Array) { model("script", extension = "kts") } } -/* + testGroup("plugins/android-extensions/android-extensions-idea/tests", "plugins/android-extensions/android-extensions-idea/testData") { testClass { model("android/completion", recursive = false, extension = null) @@ -1194,5 +1215,4 @@ fun main(args: Array) { model("android/gutterIcon") } } -*/ } diff --git a/gradle/versions.properties b/gradle/versions.properties index fd0f1443e05..cc2075076c7 100644 --- a/gradle/versions.properties +++ b/gradle/versions.properties @@ -1,6 +1,7 @@ -versions.intellijSdk=183.5153.4 +versions.intellijSdk=191.6707.61 versions.androidBuildTools=r23.0.1 versions.idea.NodeJS=181.3494.12 +versions.jar.asm-all=7.0.1 versions.jar.guava=25.1-jre versions.jar.groovy-all=2.4.15 versions.jar.lombok-ast=0.2.3 @@ -10,6 +11,5 @@ versions.jar.streamex=0.6.7 versions.jar.gson=2.8.5 versions.jar.oro=2.0.8 versions.jar.picocontainer=1.2 -versions.jar.asm-all=7.0 ignore.jar.snappy-in-java=true versions.gradle-api=4.5.1 diff --git a/gradle/versions.properties.191 b/gradle/versions.properties.183 similarity index 86% rename from gradle/versions.properties.191 rename to gradle/versions.properties.183 index cc2075076c7..fd0f1443e05 100644 --- a/gradle/versions.properties.191 +++ b/gradle/versions.properties.183 @@ -1,7 +1,6 @@ -versions.intellijSdk=191.6707.61 +versions.intellijSdk=183.5153.4 versions.androidBuildTools=r23.0.1 versions.idea.NodeJS=181.3494.12 -versions.jar.asm-all=7.0.1 versions.jar.guava=25.1-jre versions.jar.groovy-all=2.4.15 versions.jar.lombok-ast=0.2.3 @@ -11,5 +10,6 @@ versions.jar.streamex=0.6.7 versions.jar.gson=2.8.5 versions.jar.oro=2.0.8 versions.jar.picocontainer=1.2 +versions.jar.asm-all=7.0 ignore.jar.snappy-in-java=true versions.gradle-api=4.5.1 diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt index 4e712eb4fe7..fab56a53b79 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt @@ -1,17 +1,90 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + package org.jetbrains.kotlin.idea.caches.project +import com.intellij.openapi.module.Module +import com.intellij.openapi.module.ModuleUtilCore import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Key import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.idea.LIBRARY_KEY +import org.jetbrains.kotlin.idea.MODULE_ROOT_TYPE_KEY +import org.jetbrains.kotlin.idea.SDK_KEY +import org.jetbrains.kotlin.idea.caches.project.UserDataModuleContainer.ForPsiElement +import org.jetbrains.kotlin.idea.caches.project.UserDataModuleContainer.ForVirtualFile +import org.jetbrains.kotlin.idea.core.getSourceType +import org.jetbrains.kotlin.utils.addIfNotNull + +// This file declares non-exported API for overriding module info with user-data -// NO-OP implementation, full implementation only for AS3.3, AS3.4 +private sealed class UserDataModuleContainer { + abstract fun getUserData(key: Key): T? + abstract fun getModule(): Module? + + data class ForVirtualFile(val virtualFile: VirtualFile, val project: Project) : UserDataModuleContainer() { + override fun getUserData(key: Key): T? = virtualFile.getUserData(key) + override fun getModule(): Module? = ModuleUtilCore.findModuleForFile(virtualFile, project) + } + + data class ForPsiElement(val psiElement: PsiElement) : UserDataModuleContainer() { + override fun getUserData(key: Key): T? { + return psiElement.getUserData(key) + ?: psiElement.containingFile?.getUserData(key) + ?: psiElement.containingFile?.originalFile?.virtualFile?.getUserData(key) + } + + override fun getModule(): Module? = ModuleUtilCore.findModuleForPsiElement(psiElement) + } +} + + +private fun collectModuleInfoByUserData( + project: Project, + container: UserDataModuleContainer +): List { + fun forModule(): ModuleSourceInfo? { + val rootType = container.getUserData(MODULE_ROOT_TYPE_KEY) ?: return null + val module = container.getModule() ?: return null + + return when (rootType.getSourceType()) { + null -> null + SourceType.PRODUCTION -> module.productionSourceInfo() + SourceType.TEST -> module.testSourceInfo() + } + } + + val result = mutableListOf() + result.addIfNotNull(forModule()) + + val library = container.getUserData(LIBRARY_KEY) + if (library != null) { + result.addAll(createLibraryInfo(project, library)) + } + + val sdk = container.getUserData(SDK_KEY) + if (sdk != null) { + result.add(SdkInfo(project, sdk)) + } + + return result +} + fun collectModuleInfoByUserData( project: Project, virtualFile: VirtualFile -): List = emptyList() +): List = collectModuleInfoByUserData(project, ForVirtualFile(virtualFile, project)) fun collectModuleInfoByUserData( psiElement: PsiElement -): List = emptyList() +): List = collectModuleInfoByUserData(psiElement.project, ForPsiElement(psiElement)) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt.183 b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt.183 new file mode 100644 index 00000000000..4e712eb4fe7 --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt.183 @@ -0,0 +1,17 @@ +package org.jetbrains.kotlin.idea.caches.project + +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.PsiElement + + +// NO-OP implementation, full implementation only for AS3.3, AS3.4 + +fun collectModuleInfoByUserData( + project: Project, + virtualFile: VirtualFile +): List = emptyList() + +fun collectModuleInfoByUserData( + psiElement: PsiElement +): List = emptyList() diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt.191 b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt.191 deleted file mode 100644 index fab56a53b79..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/userDataModuleInfoUtil.kt.191 +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.idea.caches.project - -import com.intellij.openapi.module.Module -import com.intellij.openapi.module.ModuleUtilCore -import com.intellij.openapi.project.Project -import com.intellij.openapi.util.Key -import com.intellij.openapi.vfs.VirtualFile -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.idea.LIBRARY_KEY -import org.jetbrains.kotlin.idea.MODULE_ROOT_TYPE_KEY -import org.jetbrains.kotlin.idea.SDK_KEY -import org.jetbrains.kotlin.idea.caches.project.UserDataModuleContainer.ForPsiElement -import org.jetbrains.kotlin.idea.caches.project.UserDataModuleContainer.ForVirtualFile -import org.jetbrains.kotlin.idea.core.getSourceType -import org.jetbrains.kotlin.utils.addIfNotNull - -// This file declares non-exported API for overriding module info with user-data - - -private sealed class UserDataModuleContainer { - abstract fun getUserData(key: Key): T? - abstract fun getModule(): Module? - - data class ForVirtualFile(val virtualFile: VirtualFile, val project: Project) : UserDataModuleContainer() { - override fun getUserData(key: Key): T? = virtualFile.getUserData(key) - override fun getModule(): Module? = ModuleUtilCore.findModuleForFile(virtualFile, project) - } - - data class ForPsiElement(val psiElement: PsiElement) : UserDataModuleContainer() { - override fun getUserData(key: Key): T? { - return psiElement.getUserData(key) - ?: psiElement.containingFile?.getUserData(key) - ?: psiElement.containingFile?.originalFile?.virtualFile?.getUserData(key) - } - - override fun getModule(): Module? = ModuleUtilCore.findModuleForPsiElement(psiElement) - } -} - - -private fun collectModuleInfoByUserData( - project: Project, - container: UserDataModuleContainer -): List { - fun forModule(): ModuleSourceInfo? { - val rootType = container.getUserData(MODULE_ROOT_TYPE_KEY) ?: return null - val module = container.getModule() ?: return null - - return when (rootType.getSourceType()) { - null -> null - SourceType.PRODUCTION -> module.productionSourceInfo() - SourceType.TEST -> module.testSourceInfo() - } - } - - val result = mutableListOf() - result.addIfNotNull(forModule()) - - val library = container.getUserData(LIBRARY_KEY) - if (library != null) { - result.addAll(createLibraryInfo(project, library)) - } - - val sdk = container.getUserData(SDK_KEY) - if (sdk != null) { - result.add(SdkInfo(project, sdk)) - } - - return result -} - - -fun collectModuleInfoByUserData( - project: Project, - virtualFile: VirtualFile -): List = collectModuleInfoByUserData(project, ForVirtualFile(virtualFile, project)) - -fun collectModuleInfoByUserData( - psiElement: PsiElement -): List = collectModuleInfoByUserData(psiElement.project, ForPsiElement(psiElement)) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/userDataModuleInfo.kt.191 b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/userDataModuleInfo.kt similarity index 100% rename from idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/userDataModuleInfo.kt.191 rename to idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/userDataModuleInfo.kt diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinRootType.kt.191 b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/userDataModuleInfo.kt.183 similarity index 100% rename from idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinRootType.kt.191 rename to idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/userDataModuleInfo.kt.183 diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt index 8a2c7e8a191..12626aef688 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt @@ -15,22 +15,21 @@ */ package org.jetbrains.kotlin.idea.run +import com.intellij.execution.Location import com.intellij.execution.actions.ConfigurationContext -import com.intellij.execution.actions.RunConfigurationProducer -import com.intellij.execution.junit.PatternConfigurationProducer +import com.intellij.execution.actions.ConfigurationFromContext import com.intellij.ide.plugins.PluginManager import com.intellij.openapi.extensions.PluginId.getId import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration -import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil import com.intellij.openapi.util.Ref import com.intellij.openapi.util.component1 import com.intellij.openapi.util.component2 import com.intellij.psi.PsiClass import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod +import org.jetbrains.kotlin.idea.caches.project.isMPPModule import org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer import org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer -import org.jetbrains.plugins.gradle.util.GradleConstants private val IS_JUNIT_ENABLED by lazy { isPluginEnabled("JUnit") } private val IS_TESTNG_ENABLED by lazy { isPluginEnabled("TestNG-J") } @@ -69,61 +68,35 @@ class KotlinTestClassGradleConfigurationProducer : TestClassGradleConfigurationP sourceElement: Ref ): Boolean { if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false + context.module?.asJvmModule() ?: return false - val contextLocation = context.location ?: return false - val module = context.module?.asJvmModule() ?: return false + return super.doSetupConfigurationFromContext(configuration, context, sourceElement) + } - if (RunConfigurationProducer.getInstance(PatternConfigurationProducer::class.java).isMultipleElementsSelected(context)) { - return false + override fun getPsiClassForLocation(contextLocation: Location<*>): PsiClass? { + val leaf = contextLocation.psiElement ?: return null + return getTestClass(leaf) + } + + override fun getPsiMethodForLocation(contextLocation: Location<*>): PsiMethod? { + val leaf = contextLocation.psiElement ?: return null + return getTestMethod(leaf) + } + + override fun onFirstRun(fromContext: ConfigurationFromContext, context: ConfigurationContext, performRunnable: Runnable) { + if (context.location?.module?.isMPPModule == true) { + // TODO: remove hack when IDEA has new API + performRunnable.run() + } else { + super.onFirstRun(fromContext, context, performRunnable) } - val leaf = context.location?.psiElement ?: return false - val testClass = getTestClass(leaf) ?: return false - sourceElement.set(testClass) - - if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) return false - - val projectPath = resolveProjectPath(module) ?: return false - - val tasksToRun = getTasksToRun(module) - if (tasksToRun.isEmpty()) return false - - configuration.settings.externalProjectPath = projectPath - configuration.settings.taskNames = tasksToRun - configuration.settings.scriptParameters = String.format("--tests \"%s\"", testClass.qualifiedName) - configuration.name = testClass.name ?: "unknown" - - JavaRunConfigurationExtensionManagerUtil.getInstance().extendCreatedConfiguration(configuration, contextLocation) - return true } override fun doIsConfigurationFromContext(configuration: ExternalSystemRunConfiguration, context: ConfigurationContext): Boolean { if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false + context.module?.asJvmModule() ?: return false - val leaf = context.location?.psiElement ?: return false - val module = context.module?.asJvmModule() ?: return false - - if (RunConfigurationProducer.getInstance(PatternConfigurationProducer::class.java).isMultipleElementsSelected(context)) { - return false - } - - if (getTestMethod(leaf) != null) return false - - val testClass = getTestClass(leaf) - if (testClass == null || testClass.qualifiedName == null) return false - - - val projectPath = resolveProjectPath(module) ?: return false - if (projectPath != configuration.settings.externalProjectPath) { - return false - } - if (!configuration.settings.taskNames.containsAll(getTasksToRun(module))) return false - - val scriptParameters = configuration.settings.scriptParameters + ' ' - val i = scriptParameters.indexOf("--tests ") - if (i == -1) return false - - val str = scriptParameters.substringAfter("--tests ").trim() + ' ' - return str.startsWith("\"" + testClass.qualifiedName + "\"" + ' ') && !str.contains("--tests") + return super.doIsConfigurationFromContext(configuration, context) } } @@ -134,88 +107,29 @@ class KotlinTestMethodGradleConfigurationProducer : TestMethodGradleConfiguratio sourceElement: Ref ): Boolean { if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false - - val contextLocation = context.location ?: return false context.module?.asJvmModule() ?: return false - if (RunConfigurationProducer.getInstance(PatternConfigurationProducer::class.java).isMultipleElementsSelected(context)) { - return false + return super.doSetupConfigurationFromContext(configuration, context, sourceElement) + } + + override fun getPsiMethodForLocation(contextLocation: Location<*>): PsiMethod? { + val leaf = contextLocation.psiElement ?: return null + return getTestMethod(leaf) + } + + override fun onFirstRun(fromContext: ConfigurationFromContext, context: ConfigurationContext, performRunnable: Runnable) { + if (context.location?.module?.isMPPModule == true) { + // TODO: remove hack when IDEA has new API + performRunnable.run() + } else { + super.onFirstRun(fromContext, context, performRunnable) } - - val psiMethod = getTestMethod(contextLocation.psiElement) ?: return false - sourceElement.set(psiMethod) - - val containingClass = psiMethod.containingClass ?: return false - - - if (!applyTestMethodConfiguration(configuration, context, psiMethod, containingClass)) return false - - JavaRunConfigurationExtensionManagerUtil.getInstance().extendCreatedConfiguration(configuration, contextLocation) - return true } override fun doIsConfigurationFromContext(configuration: ExternalSystemRunConfiguration, context: ConfigurationContext): Boolean { if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false + context.module?.asJvmModule() ?: return false - if (RunConfigurationProducer.getInstance(PatternConfigurationProducer::class.java).isMultipleElementsSelected(context)) { - return false - } - - val contextLocation = context.location ?: return false - val module = context.module?.asJvmModule() ?: return false - - val psiMethod = getTestMethod(contextLocation.psiElement) ?: return false - - val containingClass = psiMethod.containingClass ?: return false - - - val projectPath = resolveProjectPath(module) ?: return false - - if (projectPath != configuration.settings.externalProjectPath) { - return false - } - if (!configuration.settings.taskNames.containsAll(getTasksToRun(module))) return false - - val scriptParameters = configuration.settings.scriptParameters + ' ' - val testFilter = createTestFilter(containingClass, psiMethod) - return scriptParameters.contains(testFilter!!) - } - - private fun applyTestMethodConfiguration( - configuration: ExternalSystemRunConfiguration, - context: ConfigurationContext, - psiMethod: PsiMethod, - vararg containingClasses: PsiClass - ): Boolean { - val module = context.module ?: return false - - if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) return false - - val projectPath = resolveProjectPath(module) ?: return false - - val tasksToRun = getTasksToRun(module) - if (tasksToRun.isEmpty()) return false - - configuration.settings.externalProjectPath = projectPath - configuration.settings.taskNames = tasksToRun - - val params = containingClasses.joinToString("") { aClass -> createTestFilter(aClass, psiMethod) ?: "" } - - configuration.settings.scriptParameters = params.trim() - configuration.name = (if (containingClasses.size == 1) containingClasses[0].name + "." else "") + psiMethod.name - return true - } - - companion object { - - private fun createTestFilter(aClass: PsiClass, psiMethod: PsiMethod): String? { - return createTestFilter(aClass.qualifiedName, psiMethod.name) - } - - fun createTestFilter(aClass: String?, method: String?): String? { - if (aClass == null) return null - val testFilterPattern = aClass + if (method == null) "" else '.' + method - return "--tests \"$testFilterPattern\" " - } + return super.doIsConfigurationFromContext(configuration, context) } } diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt.183 b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt.183 new file mode 100644 index 00000000000..8a2c7e8a191 --- /dev/null +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt.183 @@ -0,0 +1,221 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.kotlin.idea.run + +import com.intellij.execution.actions.ConfigurationContext +import com.intellij.execution.actions.RunConfigurationProducer +import com.intellij.execution.junit.PatternConfigurationProducer +import com.intellij.ide.plugins.PluginManager +import com.intellij.openapi.extensions.PluginId.getId +import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration +import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil +import com.intellij.openapi.util.Ref +import com.intellij.openapi.util.component1 +import com.intellij.openapi.util.component2 +import com.intellij.psi.PsiClass +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiMethod +import org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer +import org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer +import org.jetbrains.plugins.gradle.util.GradleConstants + +private val IS_JUNIT_ENABLED by lazy { isPluginEnabled("JUnit") } +private val IS_TESTNG_ENABLED by lazy { isPluginEnabled("TestNG-J") } +private val IS_TEST_FRAMEWORK_PLUGIN_ENABLED by lazy { IS_JUNIT_ENABLED || IS_TESTNG_ENABLED } + +private fun isPluginEnabled(id: String): Boolean { + return PluginManager.isPluginInstalled(getId(id)) && id !in PluginManager.getDisabledPlugins() +} + +private fun getTestClass(leaf: PsiElement): PsiClass? { + if (IS_JUNIT_ENABLED) { + KotlinJUnitRunConfigurationProducer.getTestClass(leaf)?.let { return it } + } + if (IS_TESTNG_ENABLED) { + KotlinTestNgConfigurationProducer.getTestClassAndMethod(leaf)?.let { (testClass, testMethod) -> + return if (testMethod == null) testClass else null + } + } + return null +} + +private fun getTestMethod(leaf: PsiElement): PsiMethod? { + if (IS_JUNIT_ENABLED) { + KotlinJUnitRunConfigurationProducer.getTestMethod(leaf)?.let { return it } + } + if (IS_TESTNG_ENABLED) { + KotlinTestNgConfigurationProducer.getTestClassAndMethod(leaf)?.second?.let { return it } + } + return null +} + +class KotlinTestClassGradleConfigurationProducer : TestClassGradleConfigurationProducer() { + override fun doSetupConfigurationFromContext( + configuration: ExternalSystemRunConfiguration, + context: ConfigurationContext, + sourceElement: Ref + ): Boolean { + if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false + + val contextLocation = context.location ?: return false + val module = context.module?.asJvmModule() ?: return false + + if (RunConfigurationProducer.getInstance(PatternConfigurationProducer::class.java).isMultipleElementsSelected(context)) { + return false + } + val leaf = context.location?.psiElement ?: return false + val testClass = getTestClass(leaf) ?: return false + sourceElement.set(testClass) + + if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) return false + + val projectPath = resolveProjectPath(module) ?: return false + + val tasksToRun = getTasksToRun(module) + if (tasksToRun.isEmpty()) return false + + configuration.settings.externalProjectPath = projectPath + configuration.settings.taskNames = tasksToRun + configuration.settings.scriptParameters = String.format("--tests \"%s\"", testClass.qualifiedName) + configuration.name = testClass.name ?: "unknown" + + JavaRunConfigurationExtensionManagerUtil.getInstance().extendCreatedConfiguration(configuration, contextLocation) + return true + } + + override fun doIsConfigurationFromContext(configuration: ExternalSystemRunConfiguration, context: ConfigurationContext): Boolean { + if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false + + val leaf = context.location?.psiElement ?: return false + val module = context.module?.asJvmModule() ?: return false + + if (RunConfigurationProducer.getInstance(PatternConfigurationProducer::class.java).isMultipleElementsSelected(context)) { + return false + } + + if (getTestMethod(leaf) != null) return false + + val testClass = getTestClass(leaf) + if (testClass == null || testClass.qualifiedName == null) return false + + + val projectPath = resolveProjectPath(module) ?: return false + if (projectPath != configuration.settings.externalProjectPath) { + return false + } + if (!configuration.settings.taskNames.containsAll(getTasksToRun(module))) return false + + val scriptParameters = configuration.settings.scriptParameters + ' ' + val i = scriptParameters.indexOf("--tests ") + if (i == -1) return false + + val str = scriptParameters.substringAfter("--tests ").trim() + ' ' + return str.startsWith("\"" + testClass.qualifiedName + "\"" + ' ') && !str.contains("--tests") + } +} + +class KotlinTestMethodGradleConfigurationProducer : TestMethodGradleConfigurationProducer() { + override fun doSetupConfigurationFromContext( + configuration: ExternalSystemRunConfiguration, + context: ConfigurationContext, + sourceElement: Ref + ): Boolean { + if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false + + val contextLocation = context.location ?: return false + context.module?.asJvmModule() ?: return false + + if (RunConfigurationProducer.getInstance(PatternConfigurationProducer::class.java).isMultipleElementsSelected(context)) { + return false + } + + val psiMethod = getTestMethod(contextLocation.psiElement) ?: return false + sourceElement.set(psiMethod) + + val containingClass = psiMethod.containingClass ?: return false + + + if (!applyTestMethodConfiguration(configuration, context, psiMethod, containingClass)) return false + + JavaRunConfigurationExtensionManagerUtil.getInstance().extendCreatedConfiguration(configuration, contextLocation) + return true + } + + override fun doIsConfigurationFromContext(configuration: ExternalSystemRunConfiguration, context: ConfigurationContext): Boolean { + if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false + + if (RunConfigurationProducer.getInstance(PatternConfigurationProducer::class.java).isMultipleElementsSelected(context)) { + return false + } + + val contextLocation = context.location ?: return false + val module = context.module?.asJvmModule() ?: return false + + val psiMethod = getTestMethod(contextLocation.psiElement) ?: return false + + val containingClass = psiMethod.containingClass ?: return false + + + val projectPath = resolveProjectPath(module) ?: return false + + if (projectPath != configuration.settings.externalProjectPath) { + return false + } + if (!configuration.settings.taskNames.containsAll(getTasksToRun(module))) return false + + val scriptParameters = configuration.settings.scriptParameters + ' ' + val testFilter = createTestFilter(containingClass, psiMethod) + return scriptParameters.contains(testFilter!!) + } + + private fun applyTestMethodConfiguration( + configuration: ExternalSystemRunConfiguration, + context: ConfigurationContext, + psiMethod: PsiMethod, + vararg containingClasses: PsiClass + ): Boolean { + val module = context.module ?: return false + + if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) return false + + val projectPath = resolveProjectPath(module) ?: return false + + val tasksToRun = getTasksToRun(module) + if (tasksToRun.isEmpty()) return false + + configuration.settings.externalProjectPath = projectPath + configuration.settings.taskNames = tasksToRun + + val params = containingClasses.joinToString("") { aClass -> createTestFilter(aClass, psiMethod) ?: "" } + + configuration.settings.scriptParameters = params.trim() + configuration.name = (if (containingClasses.size == 1) containingClasses[0].name + "." else "") + psiMethod.name + return true + } + + companion object { + + private fun createTestFilter(aClass: PsiClass, psiMethod: PsiMethod): String? { + return createTestFilter(aClass.qualifiedName, psiMethod.name) + } + + fun createTestFilter(aClass: String?, method: String?): String? { + if (aClass == null) return null + val testFilterPattern = aClass + if (method == null) "" else '.' + method + return "--tests \"$testFilterPattern\" " + } + } +} diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt.191 b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt.191 deleted file mode 100644 index 12626aef688..00000000000 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinGradleTestRunConfigurationProducer.kt.191 +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.kotlin.idea.run - -import com.intellij.execution.Location -import com.intellij.execution.actions.ConfigurationContext -import com.intellij.execution.actions.ConfigurationFromContext -import com.intellij.ide.plugins.PluginManager -import com.intellij.openapi.extensions.PluginId.getId -import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration -import com.intellij.openapi.util.Ref -import com.intellij.openapi.util.component1 -import com.intellij.openapi.util.component2 -import com.intellij.psi.PsiClass -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiMethod -import org.jetbrains.kotlin.idea.caches.project.isMPPModule -import org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer -import org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer - -private val IS_JUNIT_ENABLED by lazy { isPluginEnabled("JUnit") } -private val IS_TESTNG_ENABLED by lazy { isPluginEnabled("TestNG-J") } -private val IS_TEST_FRAMEWORK_PLUGIN_ENABLED by lazy { IS_JUNIT_ENABLED || IS_TESTNG_ENABLED } - -private fun isPluginEnabled(id: String): Boolean { - return PluginManager.isPluginInstalled(getId(id)) && id !in PluginManager.getDisabledPlugins() -} - -private fun getTestClass(leaf: PsiElement): PsiClass? { - if (IS_JUNIT_ENABLED) { - KotlinJUnitRunConfigurationProducer.getTestClass(leaf)?.let { return it } - } - if (IS_TESTNG_ENABLED) { - KotlinTestNgConfigurationProducer.getTestClassAndMethod(leaf)?.let { (testClass, testMethod) -> - return if (testMethod == null) testClass else null - } - } - return null -} - -private fun getTestMethod(leaf: PsiElement): PsiMethod? { - if (IS_JUNIT_ENABLED) { - KotlinJUnitRunConfigurationProducer.getTestMethod(leaf)?.let { return it } - } - if (IS_TESTNG_ENABLED) { - KotlinTestNgConfigurationProducer.getTestClassAndMethod(leaf)?.second?.let { return it } - } - return null -} - -class KotlinTestClassGradleConfigurationProducer : TestClassGradleConfigurationProducer() { - override fun doSetupConfigurationFromContext( - configuration: ExternalSystemRunConfiguration, - context: ConfigurationContext, - sourceElement: Ref - ): Boolean { - if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false - context.module?.asJvmModule() ?: return false - - return super.doSetupConfigurationFromContext(configuration, context, sourceElement) - } - - override fun getPsiClassForLocation(contextLocation: Location<*>): PsiClass? { - val leaf = contextLocation.psiElement ?: return null - return getTestClass(leaf) - } - - override fun getPsiMethodForLocation(contextLocation: Location<*>): PsiMethod? { - val leaf = contextLocation.psiElement ?: return null - return getTestMethod(leaf) - } - - override fun onFirstRun(fromContext: ConfigurationFromContext, context: ConfigurationContext, performRunnable: Runnable) { - if (context.location?.module?.isMPPModule == true) { - // TODO: remove hack when IDEA has new API - performRunnable.run() - } else { - super.onFirstRun(fromContext, context, performRunnable) - } - } - - override fun doIsConfigurationFromContext(configuration: ExternalSystemRunConfiguration, context: ConfigurationContext): Boolean { - if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false - context.module?.asJvmModule() ?: return false - - return super.doIsConfigurationFromContext(configuration, context) - } -} - -class KotlinTestMethodGradleConfigurationProducer : TestMethodGradleConfigurationProducer() { - override fun doSetupConfigurationFromContext( - configuration: ExternalSystemRunConfiguration, - context: ConfigurationContext, - sourceElement: Ref - ): Boolean { - if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false - context.module?.asJvmModule() ?: return false - - return super.doSetupConfigurationFromContext(configuration, context, sourceElement) - } - - override fun getPsiMethodForLocation(contextLocation: Location<*>): PsiMethod? { - val leaf = contextLocation.psiElement ?: return null - return getTestMethod(leaf) - } - - override fun onFirstRun(fromContext: ConfigurationFromContext, context: ConfigurationContext, performRunnable: Runnable) { - if (context.location?.module?.isMPPModule == true) { - // TODO: remove hack when IDEA has new API - performRunnable.run() - } else { - super.onFirstRun(fromContext, context, performRunnable) - } - } - - override fun doIsConfigurationFromContext(configuration: ExternalSystemRunConfiguration, context: ConfigurationContext): Boolean { - if (!IS_TEST_FRAMEWORK_PLUGIN_ENABLED) return false - context.module?.asJvmModule() ?: return false - - return super.doIsConfigurationFromContext(configuration, context) - } -} diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinMPPGradleTestTasksProvider.kt.191 b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinMPPGradleTestTasksProvider.kt similarity index 100% rename from idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinMPPGradleTestTasksProvider.kt.191 rename to idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinMPPGradleTestTasksProvider.kt diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinMPPGradleTestTasksProvider.kt.183 b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/run/KotlinMPPGradleTestTasksProvider.kt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java index 2b1009ce461..a8c717e781a 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java @@ -31,6 +31,7 @@ import org.gradle.tooling.model.DomainObjectSet; import org.gradle.tooling.model.idea.IdeaModule; import org.gradle.util.GradleVersion; import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.ClassSetProjectImportExtraModelProvider; import org.jetbrains.plugins.gradle.model.ExternalProject; import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper; @@ -140,7 +141,7 @@ public abstract class AbstractModelBuilderTest { try { ProjectImportAction projectImportAction = new ProjectImportAction(false); - projectImportAction.addExtraProjectModelClasses(getModels()); + projectImportAction.addProjectImportExtraModelProvider(new ClassSetProjectImportExtraModelProvider(getModels())); BuildActionExecuter buildActionExecutor = connection.action(projectImportAction); File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses()); assertNotNull(initScript); diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.191 b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.183 similarity index 97% rename from idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.191 rename to idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.183 index a8c717e781a..2b1009ce461 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.191 +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.183 @@ -31,7 +31,6 @@ import org.gradle.tooling.model.DomainObjectSet; import org.gradle.tooling.model.idea.IdeaModule; import org.gradle.util.GradleVersion; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.gradle.model.ClassSetProjectImportExtraModelProvider; import org.jetbrains.plugins.gradle.model.ExternalProject; import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper; @@ -141,7 +140,7 @@ public abstract class AbstractModelBuilderTest { try { ProjectImportAction projectImportAction = new ProjectImportAction(false); - projectImportAction.addProjectImportExtraModelProvider(new ClassSetProjectImportExtraModelProvider(getModels())); + projectImportAction.addExtraProjectModelClasses(getModels()); BuildActionExecuter buildActionExecutor = connection.action(projectImportAction); File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses()); assertNotNull(initScript); diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt index 1ebd0ae647e..8ca9dea92fc 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt @@ -11,18 +11,15 @@ import org.jetbrains.jps.model.java.JavaResourceRootType import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.module.JpsModuleSourceRootType -sealed class KotlinResourceRootType(val isTest: Boolean) : JpsElementTypeBase(), - JpsModuleSourceRootType, KotlinRootType { +sealed class KotlinResourceRootType() : JpsElementTypeBase(), + JpsModuleSourceRootType { override fun createDefaultProperties() = JpsJavaExtensionService.getInstance().createResourceRootProperties("", false) - - override fun isTestRoot() = isTest - - override fun isForTests() = isTest - - override fun equals(other: Any?) = if (super.equals(other)) true else isSameRootType(this, other) } -object ResourceKotlinRootType : KotlinResourceRootType(false) -object TestResourceKotlinRootType : KotlinResourceRootType(true) \ No newline at end of file +object ResourceKotlinRootType : KotlinResourceRootType() + +object TestResourceKotlinRootType : KotlinResourceRootType() { + override fun isForTests() = true +} \ No newline at end of file diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt.191 b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt.183 similarity index 56% rename from idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt.191 rename to idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt.183 index 8ca9dea92fc..1ebd0ae647e 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt.191 +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt.183 @@ -11,15 +11,18 @@ import org.jetbrains.jps.model.java.JavaResourceRootType import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.module.JpsModuleSourceRootType -sealed class KotlinResourceRootType() : JpsElementTypeBase(), - JpsModuleSourceRootType { +sealed class KotlinResourceRootType(val isTest: Boolean) : JpsElementTypeBase(), + JpsModuleSourceRootType, KotlinRootType { override fun createDefaultProperties() = JpsJavaExtensionService.getInstance().createResourceRootProperties("", false) + + override fun isTestRoot() = isTest + + override fun isForTests() = isTest + + override fun equals(other: Any?) = if (super.equals(other)) true else isSameRootType(this, other) } -object ResourceKotlinRootType : KotlinResourceRootType() - -object TestResourceKotlinRootType : KotlinResourceRootType() { - override fun isForTests() = true -} \ No newline at end of file +object ResourceKotlinRootType : KotlinResourceRootType(false) +object TestResourceKotlinRootType : KotlinResourceRootType(true) \ No newline at end of file diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinRootType.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinRootType.kt.183 similarity index 100% rename from idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinRootType.kt rename to idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinRootType.kt.183 diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt index f517867f2c3..834e7921dbe 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt @@ -11,21 +11,16 @@ import org.jetbrains.jps.model.java.JavaSourceRootType import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.module.JpsModuleSourceRootType -sealed class KotlinSourceRootType(val isTest: Boolean) : JpsElementTypeBase(), JpsModuleSourceRootType, KotlinRootType { - +sealed class KotlinSourceRootType() : JpsElementTypeBase(), JpsModuleSourceRootType { override fun createDefaultProperties() = JpsJavaExtensionService.getInstance().createSourceRootProperties("") - - override fun isTestRoot() = isTest - - override fun isForTests() = isTest - - override fun equals(other: Any?) = if (super.equals(other)) true else isSameRootType(this, other) } -object SourceKotlinRootType : KotlinSourceRootType(false) +object SourceKotlinRootType : KotlinSourceRootType() -object TestSourceKotlinRootType : KotlinSourceRootType(true) +object TestSourceKotlinRootType : KotlinSourceRootType() { + override fun isForTests() = true +} val ALL_KOTLIN_SOURCE_ROOT_TYPES = setOf(SourceKotlinRootType, TestSourceKotlinRootType) diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt.191 b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt.183 similarity index 59% rename from idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt.191 rename to idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt.183 index 834e7921dbe..f517867f2c3 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt.191 +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt.183 @@ -11,16 +11,21 @@ import org.jetbrains.jps.model.java.JavaSourceRootType import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.module.JpsModuleSourceRootType -sealed class KotlinSourceRootType() : JpsElementTypeBase(), JpsModuleSourceRootType { +sealed class KotlinSourceRootType(val isTest: Boolean) : JpsElementTypeBase(), JpsModuleSourceRootType, KotlinRootType { + override fun createDefaultProperties() = JpsJavaExtensionService.getInstance().createSourceRootProperties("") + + override fun isTestRoot() = isTest + + override fun isForTests() = isTest + + override fun equals(other: Any?) = if (super.equals(other)) true else isSameRootType(this, other) } -object SourceKotlinRootType : KotlinSourceRootType() +object SourceKotlinRootType : KotlinSourceRootType(false) -object TestSourceKotlinRootType : KotlinSourceRootType() { - override fun isForTests() = true -} +object TestSourceKotlinRootType : KotlinSourceRootType(true) val ALL_KOTLIN_SOURCE_ROOT_TYPES = setOf(SourceKotlinRootType, TestSourceKotlinRootType) diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt index e3bf65762a1..680a143ce6e 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.idea.maven -import com.intellij.openapi.util.AsyncResult +import org.jetbrains.concurrency.AsyncPromise import org.jetbrains.idea.maven.model.MavenArtifact import org.jetbrains.idea.maven.project.MavenProject import org.jetbrains.idea.maven.project.MavenProjectsManager @@ -17,5 +17,5 @@ fun scheduleArtifactsDownloading( toBeDownloaded: List ) { //true, false, AsyncResult() - projectsManager.scheduleArtifactsDownloading(projects, toBeDownloaded, true, false, AsyncResult()) + projectsManager.scheduleArtifactsDownloading(projects, toBeDownloaded, true, false, AsyncPromise()) } \ No newline at end of file diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt.191 b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt.183 similarity index 88% rename from idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt.191 rename to idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt.183 index 680a143ce6e..e3bf65762a1 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt.191 +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArtifactsDownloadScheduler.kt.183 @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.idea.maven -import org.jetbrains.concurrency.AsyncPromise +import com.intellij.openapi.util.AsyncResult import org.jetbrains.idea.maven.model.MavenArtifact import org.jetbrains.idea.maven.project.MavenProject import org.jetbrains.idea.maven.project.MavenProjectsManager @@ -17,5 +17,5 @@ fun scheduleArtifactsDownloading( toBeDownloaded: List ) { //true, false, AsyncResult() - projectsManager.scheduleArtifactsDownloading(projects, toBeDownloaded, true, false, AsyncPromise()) + projectsManager.scheduleArtifactsDownloading(projects, toBeDownloaded, true, false, AsyncResult()) } \ No newline at end of file diff --git a/idea/resources/META-INF/extensions/ide.xml b/idea/resources/META-INF/extensions/ide.xml index 7d934071cb9..071a973f0bc 100644 --- a/idea/resources/META-INF/extensions/ide.xml +++ b/idea/resources/META-INF/extensions/ide.xml @@ -7,14 +7,6 @@ interface="org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension" area="IDEA_PROJECT"/> - - - - @@ -94,12 +86,12 @@ - + + description="Use new Java to Kotlin Converter (experimental)" + defaultValue="false" + restartRequired="false"/> diff --git a/idea/resources/META-INF/extensions/ide.xml.191 b/idea/resources/META-INF/extensions/ide.xml.183 similarity index 90% rename from idea/resources/META-INF/extensions/ide.xml.191 rename to idea/resources/META-INF/extensions/ide.xml.183 index 071a973f0bc..7d934071cb9 100644 --- a/idea/resources/META-INF/extensions/ide.xml.191 +++ b/idea/resources/META-INF/extensions/ide.xml.183 @@ -7,6 +7,14 @@ interface="org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension" area="IDEA_PROJECT"/> + + + + @@ -86,12 +94,12 @@ - + + description="Use new Java to Kotlin Converter (experimental)" + defaultValue="false" + restartRequired="false"/> diff --git a/idea/resources/META-INF/gradle-java.xml b/idea/resources/META-INF/gradle-java.xml index 5b229499905..6ee0d5464e5 100644 --- a/idea/resources/META-INF/gradle-java.xml +++ b/idea/resources/META-INF/gradle-java.xml @@ -20,9 +20,10 @@ + - + diff --git a/idea/resources/META-INF/gradle-java.xml.191 b/idea/resources/META-INF/gradle-java.xml.183 similarity index 96% rename from idea/resources/META-INF/gradle-java.xml.191 rename to idea/resources/META-INF/gradle-java.xml.183 index 6ee0d5464e5..5b229499905 100644 --- a/idea/resources/META-INF/gradle-java.xml.191 +++ b/idea/resources/META-INF/gradle-java.xml.183 @@ -20,10 +20,9 @@ - - + diff --git a/idea/resources/META-INF/gradle.xml b/idea/resources/META-INF/gradle.xml index 61f86b55ece..a06b6441aa2 100644 --- a/idea/resources/META-INF/gradle.xml +++ b/idea/resources/META-INF/gradle.xml @@ -14,6 +14,7 @@ + diff --git a/idea/resources/META-INF/gradle.xml.191 b/idea/resources/META-INF/gradle.xml.183 similarity index 93% rename from idea/resources/META-INF/gradle.xml.191 rename to idea/resources/META-INF/gradle.xml.183 index a06b6441aa2..61f86b55ece 100644 --- a/idea/resources/META-INF/gradle.xml.191 +++ b/idea/resources/META-INF/gradle.xml.183 @@ -14,7 +14,6 @@ - diff --git a/idea/resources/META-INF/jvm.xml b/idea/resources/META-INF/jvm.xml index d5c501d1cd4..b21476dcad2 100644 --- a/idea/resources/META-INF/jvm.xml +++ b/idea/resources/META-INF/jvm.xml @@ -166,6 +166,11 @@ description="Whether to use multi resolve for UAST in Kotlin provided by `Call.resolveCandidates`, otherwise PsiPolyVariantReference-based multiResolve will be performed" defaultValue="true" restartRequired="false"/> + + diff --git a/idea/resources/META-INF/jvm.xml.191 b/idea/resources/META-INF/jvm.xml.183 similarity index 98% rename from idea/resources/META-INF/jvm.xml.191 rename to idea/resources/META-INF/jvm.xml.183 index b21476dcad2..d5c501d1cd4 100644 --- a/idea/resources/META-INF/jvm.xml.191 +++ b/idea/resources/META-INF/jvm.xml.183 @@ -166,11 +166,6 @@ description="Whether to use multi resolve for UAST in Kotlin provided by `Call.resolveCandidates`, otherwise PsiPolyVariantReference-based multiResolve will be performed" defaultValue="true" restartRequired="false"/> - - diff --git a/idea/resources/META-INF/plugin.xml b/idea/resources/META-INF/plugin.xml index 46a859286ca..82a7ec95bef 100644 --- a/idea/resources/META-INF/plugin.xml +++ b/idea/resources/META-INF/plugin.xml @@ -13,7 +13,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. @snapshot@ JetBrains - + com.intellij.modules.platform @@ -26,7 +26,6 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. org.intellij.groovy org.jetbrains.idea.maven TestNG-J - org.jetbrains.android Coverage com.intellij.java-i18n org.jetbrains.java.decompiler @@ -70,7 +69,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. - + + + + + + + + + diff --git a/idea/resources/META-INF/plugin.xml.191 b/idea/resources/META-INF/plugin.xml.183 similarity index 81% rename from idea/resources/META-INF/plugin.xml.191 rename to idea/resources/META-INF/plugin.xml.183 index 82a7ec95bef..46a859286ca 100644 --- a/idea/resources/META-INF/plugin.xml.191 +++ b/idea/resources/META-INF/plugin.xml.183 @@ -13,7 +13,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. @snapshot@ JetBrains - + com.intellij.modules.platform @@ -26,6 +26,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. org.intellij.groovy org.jetbrains.idea.maven TestNG-J + org.jetbrains.android Coverage com.intellij.java-i18n org.jetbrains.java.decompiler @@ -69,15 +70,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. - + - - - - - - - - diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt index e8f7a4362dd..00ea1bd6ad6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt @@ -64,6 +64,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext import org.jetbrains.kotlin.psi.psiUtil.isAncestor import org.jetbrains.kotlin.utils.ifEmpty import org.jetbrains.kotlin.utils.keysToMap +import java.lang.AssertionError import java.util.* interface Mover : (KtNamedDeclaration, KtElement) -> KtNamedDeclaration { @@ -202,12 +203,8 @@ class MoveKotlinDeclarationsProcessor( fun collectUsages(kotlinToLightElements: Map>, result: MutableCollection) { kotlinToLightElements.values.flatten().flatMapTo(result) { lightElement -> val searchScope = getSearchScope(lightElement) ?: return@flatMapTo emptyList() - - val newFqName = StringUtil.getQualifiedName(newContainerName, lightElement.name) - val newFqNameForKt = StringUtil.getQualifiedName( - newContainerName, - lightElement.namedUnwrappedElement?.name?: lightElement.name - ) + val elementName = lightElement.name ?: return@flatMapTo emptyList() + val newFqName = StringUtil.getQualifiedName(newContainerName, elementName) val foundReferences = HashSet() val results = ReferencesSearch @@ -235,19 +232,6 @@ class MoveKotlinDeclarationsProcessor( if (handler !is MoveKotlinClassHandler) handler.preprocessUsages(results) } - results - .filter { it is NonCodeUsageInfo && it.file is KtFile } - .forEach { - val newText = NonCodeUsageInfo::class.java.getField("newText") - // A 'newText' is marked as final initially, but here we need to change it to prevent - // light-class names in kotlin files. - val oldAccessibility = newText.isAccessible - newText.isAccessible = true - newText.set(it, newFqNameForKt) - // Restore initial accessibility of 'newText' field. - newText.isAccessible = oldAccessibility - } - results } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt.191 b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt.183 similarity index 94% rename from idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt.191 rename to idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt.183 index 00ea1bd6ad6..e8f7a4362dd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt.191 +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt.183 @@ -64,7 +64,6 @@ import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext import org.jetbrains.kotlin.psi.psiUtil.isAncestor import org.jetbrains.kotlin.utils.ifEmpty import org.jetbrains.kotlin.utils.keysToMap -import java.lang.AssertionError import java.util.* interface Mover : (KtNamedDeclaration, KtElement) -> KtNamedDeclaration { @@ -203,8 +202,12 @@ class MoveKotlinDeclarationsProcessor( fun collectUsages(kotlinToLightElements: Map>, result: MutableCollection) { kotlinToLightElements.values.flatten().flatMapTo(result) { lightElement -> val searchScope = getSearchScope(lightElement) ?: return@flatMapTo emptyList() - val elementName = lightElement.name ?: return@flatMapTo emptyList() - val newFqName = StringUtil.getQualifiedName(newContainerName, elementName) + + val newFqName = StringUtil.getQualifiedName(newContainerName, lightElement.name) + val newFqNameForKt = StringUtil.getQualifiedName( + newContainerName, + lightElement.namedUnwrappedElement?.name?: lightElement.name + ) val foundReferences = HashSet() val results = ReferencesSearch @@ -232,6 +235,19 @@ class MoveKotlinDeclarationsProcessor( if (handler !is MoveKotlinClassHandler) handler.preprocessUsages(results) } + results + .filter { it is NonCodeUsageInfo && it.file is KtFile } + .forEach { + val newText = NonCodeUsageInfo::class.java.getField("newText") + // A 'newText' is marked as final initially, but here we need to change it to prevent + // light-class names in kotlin files. + val oldAccessibility = newText.isAccessible + newText.isAccessible = true + newText.set(it, newFqNameForKt) + // Restore initial accessibility of 'newText' field. + newText.isAccessible = oldAccessibility + } + results } } diff --git a/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt b/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt index 21391929097..00e2f45d215 100644 --- a/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt +++ b/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt @@ -100,7 +100,7 @@ class KotlinTargetElementEvaluator : TargetElementEvaluatorEx, TargetElementUtil val calleeExpression = refExpression?.getParentOfTypeAndBranch { calleeExpression } if (calleeExpression != null) { (ref.resolve() as? KtConstructor<*>)?.let { - return if (flags and JavaTargetElementEvaluator.NEW_AS_CONSTRUCTOR != 0) it else it.containingClassOrObject + return if (flags and JavaTargetElementEvaluator().additionalReferenceSearchFlags != 0) it else it.containingClassOrObject } } diff --git a/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt.191 b/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt.183 similarity index 97% rename from idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt.191 rename to idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt.183 index 00e2f45d215..21391929097 100644 --- a/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt.191 +++ b/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTargetElementEvaluator.kt.183 @@ -100,7 +100,7 @@ class KotlinTargetElementEvaluator : TargetElementEvaluatorEx, TargetElementUtil val calleeExpression = refExpression?.getParentOfTypeAndBranch { calleeExpression } if (calleeExpression != null) { (ref.resolve() as? KtConstructor<*>)?.let { - return if (flags and JavaTargetElementEvaluator().additionalReferenceSearchFlags != 0) it else it.containingClassOrObject + return if (flags and JavaTargetElementEvaluator.NEW_AS_CONSTRUCTOR != 0) it else it.containingClassOrObject } } diff --git a/idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt b/idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt index c8c17e6d69d..1ea61f65829 100644 --- a/idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt +++ b/idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt @@ -8,4 +8,4 @@ package org.jetbrains.kotlin.idea.slicer.compat import com.intellij.psi.PsiElement // BUNCH: 183 -internal typealias PsiElement_N183_NN191 = PsiElement? \ No newline at end of file +internal typealias PsiElement_N183_NN191 = PsiElement \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt.191 b/idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt.183 similarity index 82% rename from idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt.191 rename to idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt.183 index 1ea61f65829..c8c17e6d69d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt.191 +++ b/idea/src/org/jetbrains/kotlin/idea/slicer/compat/nullability.kt.183 @@ -8,4 +8,4 @@ package org.jetbrains.kotlin.idea.slicer.compat import com.intellij.psi.PsiElement // BUNCH: 183 -internal typealias PsiElement_N183_NN191 = PsiElement \ No newline at end of file +internal typealias PsiElement_N183_NN191 = PsiElement? \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt b/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt index 986601b4ec1..1ecad01fac6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt +++ b/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt @@ -1,14 +1,21 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.statistics +import com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogger +import com.intellij.internal.statistic.eventLog.FeatureUsageData +import org.jetbrains.kotlin.idea.KotlinPluginUtil + + open class KotlinStatisticsTrigger { companion object { - public fun trigger(trigger: KotlinEventTrigger, event: String) { - // Not whitelisted for 183 + private val context = FeatureUsageData().addData("plugin_version", KotlinPluginUtil.getPluginVersion()) + + fun trigger(trigger: KotlinEventTrigger, event: String) { + FUCounterUsageLogger.getInstance().logEvent(trigger.GROUP_ID, event, context) } } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt.183 b/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt.183 new file mode 100644 index 00000000000..986601b4ec1 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt.183 @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.statistics + +open class KotlinStatisticsTrigger { + companion object { + public fun trigger(trigger: KotlinEventTrigger, event: String) { + // Not whitelisted for 183 + } + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt.191 b/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt.191 deleted file mode 100644 index 1ecad01fac6..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/statistics/ProjectScopeStatsReporters.kt.191 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.idea.statistics - -import com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogger -import com.intellij.internal.statistic.eventLog.FeatureUsageData -import org.jetbrains.kotlin.idea.KotlinPluginUtil - - -open class KotlinStatisticsTrigger { - companion object { - private val context = FeatureUsageData().addData("plugin_version", KotlinPluginUtil.getPluginVersion()) - - fun trigger(trigger: KotlinEventTrigger, event: String) { - FUCounterUsageLogger.getInstance().logEvent(trigger.GROUP_ID, event, context) - } - } -} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt b/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt index 6a45e2e5567..e76e28a907c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt @@ -5,8 +5,11 @@ package org.jetbrains.kotlin.idea.highlighter +import com.intellij.testFramework.ExpectedHighlightingData + // Idea 191 has an additional check for duplicate highlighting // BUNCH: 183 fun expectedDuplicatedHighlighting(runnable: Runnable) { - runnable.run() + @Suppress("DEPRECATION") + ExpectedHighlightingData.expectedDuplicatedHighlighting(runnable) } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.191 b/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.183 similarity index 68% rename from idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.191 rename to idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.183 index e76e28a907c..6a45e2e5567 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.191 +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.183 @@ -5,11 +5,8 @@ package org.jetbrains.kotlin.idea.highlighter -import com.intellij.testFramework.ExpectedHighlightingData - // Idea 191 has an additional check for duplicate highlighting // BUNCH: 183 fun expectedDuplicatedHighlighting(runnable: Runnable) { - @Suppress("DEPRECATION") - ExpectedHighlightingData.expectedDuplicatedHighlighting(runnable) + runnable.run() } \ No newline at end of file diff --git a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt index d099fa2d4f8..7e734004783 100644 --- a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt +++ b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt @@ -8,7 +8,7 @@ package org.jetbrains.kotlin.android.model.impl import com.android.builder.model.SourceProvider import com.android.tools.idea.gradle.project.GradleProjectInfo import com.android.tools.idea.gradle.project.model.AndroidModuleModel -import com.android.tools.idea.res.AppResourceRepository +import com.android.tools.idea.res.ResourceRepositoryManager import com.intellij.openapi.module.Module import com.intellij.openapi.vfs.VirtualFile import org.jetbrains.android.facet.AndroidFacet @@ -36,7 +36,7 @@ class AndroidModuleInfoProviderImpl(override val module: Module) : AndroidModule } override fun getApplicationResourceDirectories(createIfNecessary: Boolean): Collection { - return AppResourceRepository.getOrCreateInstance(module)?.resourceDirs ?: emptyList() + return ResourceRepositoryManager.getOrCreateInstance(module)?.getAppResources(createIfNecessary)?.resourceDirs ?: emptyList() } override fun getAllSourceProviders(): List { diff --git a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt.191 b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt.183 similarity index 94% rename from plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt.191 rename to plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt.183 index 7e734004783..d099fa2d4f8 100644 --- a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt.191 +++ b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/model/impl/AndroidModuleInfoProviderImpl.kt.183 @@ -8,7 +8,7 @@ package org.jetbrains.kotlin.android.model.impl import com.android.builder.model.SourceProvider import com.android.tools.idea.gradle.project.GradleProjectInfo import com.android.tools.idea.gradle.project.model.AndroidModuleModel -import com.android.tools.idea.res.ResourceRepositoryManager +import com.android.tools.idea.res.AppResourceRepository import com.intellij.openapi.module.Module import com.intellij.openapi.vfs.VirtualFile import org.jetbrains.android.facet.AndroidFacet @@ -36,7 +36,7 @@ class AndroidModuleInfoProviderImpl(override val module: Module) : AndroidModule } override fun getApplicationResourceDirectories(createIfNecessary: Boolean): Collection { - return ResourceRepositoryManager.getOrCreateInstance(module)?.getAppResources(createIfNecessary)?.resourceDirs ?: emptyList() + return AppResourceRepository.getOrCreateInstance(module)?.resourceDirs ?: emptyList() } override fun getAllSourceProviders(): List { diff --git a/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt b/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt index 1287a980a94..a2c1ecd67f5 100644 --- a/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt +++ b/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.kapt.idea -import com.android.tools.idea.gradle.project.model.AndroidModuleModel import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.externalSystem.model.DataNode import com.intellij.openapi.externalSystem.model.ProjectKeys @@ -80,8 +79,6 @@ class KaptProjectResolverExtension : AbstractProjectResolverExtension() { if (kaptModel != null && kaptModel.isEnabled) { for (sourceSet in kaptModel.sourceSets) { - populateAndroidModuleModelIfNeeded(ideModule, sourceSet) - val sourceSetDataNode = ideModule.findGradleSourceSet(sourceSet.sourceSetName) ?: continue fun addSourceSet(path: String, type: ExternalSystemSourceType) { @@ -106,42 +103,6 @@ class KaptProjectResolverExtension : AbstractProjectResolverExtension() { super.populateModuleExtraModels(gradleModule, ideModule) } - private fun populateAndroidModuleModelIfNeeded(ideModule: DataNode, sourceSet: KaptSourceSetModel) { - ideModule.findAndroidModuleModel()?.let { androidModelAny -> - // We can cast to AndroidModuleModel cause we already checked in findAndroidModuleModel() that the class exists - - val generatedKotlinSources = sourceSet.generatedKotlinSourcesDirFile ?: return - - val androidModel = androidModelAny.data as? AndroidModuleModel ?: return - val variant = androidModel.findVariantByName(sourceSet.sourceSetName) ?: return - - androidModel.registerExtraGeneratedSourceFolder(generatedKotlinSources) - - // TODO remove this when IDEA eventually migrate to the newer Android plugin - try { - variant.mainArtifact.generatedSourceFolders += generatedKotlinSources - } catch (e: Throwable) { - // There was an error being thrown here, but the code above doesn't work for the newer versions of Android Studio 3 - // (generatedSourceFolders returns a wrapped unmodifiable list), and the thrown exception breaks the import. - // The error will be moved back when I find a work-around for AS3. - } - } - } - - private fun DataNode.findAndroidModuleModel(): DataNode<*>? { - val modelClassName = "com.android.tools.idea.gradle.project.model.AndroidModuleModel" - val node = children.firstOrNull { it.key.dataType == modelClassName } ?: return null - return if (!hasClassInClasspath(modelClassName)) null else node - } - - private fun hasClassInClasspath(name: String): Boolean { - return try { - Class.forName(name) != null - } catch (thr: Throwable) { - false - } - } - private fun DataNode.findGradleSourceSet(sourceSetName: String): DataNode? { val moduleName = data.id for (child in children) { diff --git a/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt.191 b/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt.183 similarity index 79% rename from plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt.191 rename to plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt.183 index a2c1ecd67f5..1287a980a94 100644 --- a/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt.191 +++ b/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt.183 @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.kapt.idea +import com.android.tools.idea.gradle.project.model.AndroidModuleModel import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.externalSystem.model.DataNode import com.intellij.openapi.externalSystem.model.ProjectKeys @@ -79,6 +80,8 @@ class KaptProjectResolverExtension : AbstractProjectResolverExtension() { if (kaptModel != null && kaptModel.isEnabled) { for (sourceSet in kaptModel.sourceSets) { + populateAndroidModuleModelIfNeeded(ideModule, sourceSet) + val sourceSetDataNode = ideModule.findGradleSourceSet(sourceSet.sourceSetName) ?: continue fun addSourceSet(path: String, type: ExternalSystemSourceType) { @@ -103,6 +106,42 @@ class KaptProjectResolverExtension : AbstractProjectResolverExtension() { super.populateModuleExtraModels(gradleModule, ideModule) } + private fun populateAndroidModuleModelIfNeeded(ideModule: DataNode, sourceSet: KaptSourceSetModel) { + ideModule.findAndroidModuleModel()?.let { androidModelAny -> + // We can cast to AndroidModuleModel cause we already checked in findAndroidModuleModel() that the class exists + + val generatedKotlinSources = sourceSet.generatedKotlinSourcesDirFile ?: return + + val androidModel = androidModelAny.data as? AndroidModuleModel ?: return + val variant = androidModel.findVariantByName(sourceSet.sourceSetName) ?: return + + androidModel.registerExtraGeneratedSourceFolder(generatedKotlinSources) + + // TODO remove this when IDEA eventually migrate to the newer Android plugin + try { + variant.mainArtifact.generatedSourceFolders += generatedKotlinSources + } catch (e: Throwable) { + // There was an error being thrown here, but the code above doesn't work for the newer versions of Android Studio 3 + // (generatedSourceFolders returns a wrapped unmodifiable list), and the thrown exception breaks the import. + // The error will be moved back when I find a work-around for AS3. + } + } + } + + private fun DataNode.findAndroidModuleModel(): DataNode<*>? { + val modelClassName = "com.android.tools.idea.gradle.project.model.AndroidModuleModel" + val node = children.firstOrNull { it.key.dataType == modelClassName } ?: return null + return if (!hasClassInClasspath(modelClassName)) null else node + } + + private fun hasClassInClasspath(name: String): Boolean { + return try { + Class.forName(name) != null + } catch (thr: Throwable) { + false + } + } + private fun DataNode.findGradleSourceSet(sourceSetName: String): DataNode? { val moduleName = data.id for (child in children) { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt index 392872e9ce3..7af3e07f69b 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt @@ -79,10 +79,14 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl parent = parent.parent } - while (parent is KtStringTemplateEntryWithExpression || - parent is KtStringTemplateExpression && parent.entries.size == 1) { - parent = parent.parent - } + if (KotlinConverter.forceUInjectionHost) { + if (parent is KtBlockStringTemplateEntry) { + parent = parent.parent + } + } else + while (parent is KtStringTemplateEntryWithExpression || parent is KtStringTemplateExpression && parent.entries.size == 1) { + parent = parent.parent + } if (parent is KtWhenConditionWithExpression) { parent = parent.parent @@ -110,7 +114,7 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl val result = doConvertParent(this, parent) if (result == this) { - throw IllegalStateException("Loop in parent structure when converting a $psi of type ${psi?.javaClass} with parent $parent of type ${parent?.javaClass} text: [${parent?.text}]") + throw IllegalStateException("Loop in parent structure when converting a $psi of type ${psi?.javaClass} with parent $parent of type ${parent?.javaClass} text: [${parent?.text}], result = $result") } return result diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.183 similarity index 95% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.183 index 7af3e07f69b..392872e9ce3 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.183 @@ -79,14 +79,10 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl parent = parent.parent } - if (KotlinConverter.forceUInjectionHost) { - if (parent is KtBlockStringTemplateEntry) { - parent = parent.parent - } - } else - while (parent is KtStringTemplateEntryWithExpression || parent is KtStringTemplateExpression && parent.entries.size == 1) { - parent = parent.parent - } + while (parent is KtStringTemplateEntryWithExpression || + parent is KtStringTemplateExpression && parent.entries.size == 1) { + parent = parent.parent + } if (parent is KtWhenConditionWithExpression) { parent = parent.parent @@ -114,7 +110,7 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl val result = doConvertParent(this, parent) if (result == this) { - throw IllegalStateException("Loop in parent structure when converting a $psi of type ${psi?.javaClass} with parent $parent of type ${parent?.javaClass} text: [${parent?.text}], result = $result") + throw IllegalStateException("Loop in parent structure when converting a $psi of type ${psi?.javaClass} with parent $parent of type ${parent?.javaClass} text: [${parent?.text}]") } return result diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt index 9b9a2daaf54..b221083ec70 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt @@ -19,13 +19,16 @@ package org.jetbrains.uast.kotlin import com.intellij.lang.Language import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.util.Key +import com.intellij.openapi.util.registry.Registry import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.impl.source.tree.LeafPsiElement +import org.jetbrains.annotations.TestOnly import org.jetbrains.kotlin.asJava.LightClassUtil import org.jetbrains.kotlin.asJava.classes.KtLightClass import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade import org.jetbrains.kotlin.asJava.elements.* +import org.jetbrains.kotlin.asJava.findFacadeClass import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper import org.jetbrains.kotlin.config.LanguageVersionSettings @@ -39,6 +42,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.uast.* +import org.jetbrains.uast.expressions.UInjectionHost import org.jetbrains.uast.kotlin.KotlinConverter.convertDeclaration import org.jetbrains.uast.kotlin.KotlinConverter.convertDeclarationOrElement import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier @@ -75,15 +79,15 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin { override fun convertElement(element: PsiElement, parent: UElement?, requiredType: Class?): UElement? { if (!element.isJvmElement) return null - return convertDeclarationOrElement(element, parent, requiredType) + return convertDeclarationOrElement(element, parent, elementTypes(requiredType)) } override fun convertElementWithParent(element: PsiElement, requiredType: Class?): UElement? { if (!element.isJvmElement) return null - if (element is PsiFile) return convertDeclaration(element, null, requiredType) - if (element is KtLightClassForFacade) return convertDeclaration(element, null, requiredType) + if (element is PsiFile) return convertDeclaration(element, null, elementTypes(requiredType)) + if (element is KtLightClassForFacade) return convertDeclaration(element, null, elementTypes(requiredType)) - return convertDeclarationOrElement(element, null, requiredType) + return convertDeclarationOrElement(element, null, elementTypes(requiredType)) } override fun getMethodCallExpression( @@ -136,16 +140,45 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin { else -> false } } + + @Suppress("UNCHECKED_CAST") + fun convertElement(element: PsiElement, parent: UElement?, expectedTypes: Array>): T? { + if (!element.isJvmElement) return null + val nonEmptyExpectedTypes = expectedTypes.nonEmptyOr(DEFAULT_TYPES_LIST) + return (convertDeclaration(element, parent, nonEmptyExpectedTypes) + ?: KotlinConverter.convertPsiElement(element, parent, nonEmptyExpectedTypes)) as? T + } + + override fun convertElementWithParent(element: PsiElement, requiredTypes: Array>): T? { + return convertElement(element, null, requiredTypes) + } + + @Suppress("UNCHECKED_CAST") + override fun convertToAlternatives(element: PsiElement, requiredTypes: Array>): Sequence = + if (!element.isJvmElement) emptySequence() else when { + element is KtFile -> KotlinConverter.convertKtFile(element, null, requiredTypes) as Sequence + (element is KtProperty && !element.isLocal) -> + KotlinConverter.convertNonLocalProperty(element, null, requiredTypes) as Sequence + element is KtParameter -> KotlinConverter.convertParameter(element, null, requiredTypes) as Sequence + element is KtClassOrObject -> KotlinConverter.convertClassOrObject(element, null, requiredTypes) as Sequence + else -> sequenceOf(convertElementWithParent(element, requiredTypes.nonEmptyOr(DEFAULT_TYPES_LIST)) as? T).filterNotNull() + } } -internal inline fun Class?.el(f: () -> UElement?): UElement? { +internal inline fun Class<*>?.el(f: () -> UElement?): UElement? { return if (this == null || isAssignableFrom(ActualT::class.java)) f() else null } -internal inline fun Class?.expr(f: () -> UExpression?): UExpression? { - return if (this == null || isAssignableFrom(ActualT::class.java)) f() else null +internal inline fun Array>.el(f: () -> UElement?): UElement? { + return if (isAssignableFrom(ActualT::class.java)) f() else null } +internal inline fun Array>.expr(f: () -> UExpression?): UExpression? { + return if (isAssignableFrom(ActualT::class.java)) f() else null +} + +internal fun Array>.isAssignableFrom(cls: Class<*>) = any { it.isAssignableFrom(cls) } + internal object KotlinConverter { @@ -166,12 +199,13 @@ internal object KotlinConverter { internal fun convertPsiElement(element: PsiElement?, givenParent: UElement?, - requiredType: Class?): UElement? { + expectedTypes: Array> + ): UElement? { fun

build(ctor: (P, UElement?) -> UElement): () -> UElement? { return { ctor(element as P, givenParent) } } - return with (requiredType) { when (element) { + return with (expectedTypes) { when (element) { is KtParameterList -> el { val declarationsExpression = KotlinUDeclarationsExpression(givenParent) declarationsExpression.apply { @@ -184,11 +218,7 @@ internal object KotlinConverter { is KtCatchClause -> el(build(::KotlinUCatchClause)) is KtVariableDeclaration -> if (element is KtProperty && !element.isLocal) { - el { - LightClassUtil.getLightClassBackingField(element)?.let { - KotlinUField(it, element, givenParent) - } - } + convertNonLocalProperty(element, givenParent, this).firstOrNull() } else { el { @@ -196,19 +226,19 @@ internal object KotlinConverter { } } - is KtExpression -> KotlinConverter.convertExpression(element, givenParent, requiredType) - is KtLambdaArgument -> element.getLambdaExpression()?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) } + is KtExpression -> KotlinConverter.convertExpression(element, givenParent, expectedTypes) + is KtLambdaArgument -> element.getLambdaExpression()?.let { KotlinConverter.convertExpression(it, givenParent, expectedTypes) } is KtLightElementBase -> { val expression = element.kotlinOrigin when (expression) { - is KtExpression -> KotlinConverter.convertExpression(expression, givenParent, requiredType) + is KtExpression -> KotlinConverter.convertExpression(expression, givenParent, expectedTypes) else -> el { UastEmptyExpression(givenParent) } } } is KtLiteralStringTemplateEntry, is KtEscapeStringTemplateEntry -> el(build(::KotlinStringULiteralExpression)) - is KtStringTemplateEntry -> element.expression?.let { convertExpression(it, givenParent, requiredType) } ?: expr { UastEmptyExpression } + is KtStringTemplateEntry -> element.expression?.let { convertExpression(it, givenParent, expectedTypes) } ?: expr { UastEmptyExpression } is KtWhenEntry -> el(build(::KotlinUSwitchEntry)) - is KtWhenCondition -> convertWhenCondition(element, givenParent, requiredType) + is KtWhenCondition -> convertWhenCondition(element, givenParent, expectedTypes) is KtTypeReference -> el { LazyKotlinUTypeReferenceExpression(element, givenParent) } is KtConstructorDelegationCall -> el { KotlinUFunctionCallExpression(element, givenParent) } @@ -246,7 +276,8 @@ internal object KotlinConverter { internal fun convertEntry(entry: KtStringTemplateEntry, givenParent: UElement?, - requiredType: Class? = null): UExpression? { + requiredType: Array> + ): UExpression? { return with(requiredType) { if (entry is KtStringTemplateEntryWithExpression) { expr { @@ -264,9 +295,16 @@ internal object KotlinConverter { } } + var forceUInjectionHost = Registry.`is`("kotlin.uast.force.uinjectionhost", false) + @TestOnly + set(value) { + field = value + } + internal fun convertExpression(expression: KtExpression, givenParent: UElement?, - requiredType: Class? = null): UExpression? { + requiredType: Array> + ): UExpression? { fun

build(ctor: (P, UElement?) -> UExpression): () -> UExpression? { return { ctor(expression as P, givenParent) } } @@ -276,13 +314,16 @@ internal object KotlinConverter { is KtStringTemplateExpression -> { when { + forceUInjectionHost || requiredType.contains(UInjectionHost::class.java) -> + expr { KotlinStringTemplateUPolyadicExpression(expression, givenParent) } expression.entries.isEmpty() -> { expr { KotlinStringULiteralExpression(expression, givenParent, "") } } + expression.entries.size == 1 -> convertEntry(expression.entries[0], givenParent, requiredType) - else -> { - expr { KotlinStringTemplateUPolyadicExpression(expression, givenParent) } - } + + else -> + expr { KotlinStringTemplateUPolyadicExpression(expression, givenParent) } } } is KtDestructuringDeclaration -> expr { @@ -355,7 +396,7 @@ internal object KotlinConverter { internal fun convertWhenCondition(condition: KtWhenCondition, givenParent: UElement?, - requiredType: Class? = null + requiredType: Array> ): UExpression? { return with(requiredType) { when (condition) { @@ -405,7 +446,7 @@ internal object KotlinConverter { internal fun convertDeclaration( element: PsiElement, givenParent: UElement?, - requiredType: Class? + expectedTypes: Array> ): UElement? { fun

build(ctor: (P, UElement?) -> UElement): () -> UElement? = { ctor(element as P, givenParent) } @@ -416,7 +457,7 @@ internal object KotlinConverter { { ctor(element as P, ktElement, givenParent) } val original = element.originalElement - return with(requiredType) { + return with(expectedTypes) { when (original) { is KtLightMethod -> el(build(KotlinUMethod.Companion::create)) // .Companion is needed because of KT-13934 is KtLightClass -> when (original.kotlinOrigin) { @@ -434,11 +475,7 @@ internal object KotlinConverter { is KtEnumEntry -> el { convertEnumEntry(original, givenParent) } - is KtClassOrObject -> el { - original.toLightClass()?.let { lightClass -> - KotlinUClass.create(lightClass, givenParent) - } - } + is KtClassOrObject -> convertClassOrObject(original, givenParent, this).firstOrNull() is KtFunction -> if (original.isLocal) { el { @@ -447,49 +484,41 @@ internal object KotlinConverter { KotlinULambdaExpression(parent, givenParent) // your parent is the ULambdaExpression } else if (original.name.isNullOrEmpty()) { createLocalFunctionLambdaExpression(original, givenParent) - } - else { + } else { val uDeclarationsExpression = createLocalFunctionDeclaration(original, givenParent) val localFunctionVar = uDeclarationsExpression.declarations.single() as KotlinLocalFunctionUVariable localFunctionVar.uastInitializer } } - } - else { + } else { el { val lightMethod = LightClassUtil.getLightClassMethod(original) ?: return null - convertDeclaration(lightMethod, givenParent, requiredType) + convertDeclaration(lightMethod, givenParent, expectedTypes) } } is KtPropertyAccessor -> el { val lightMethod = LightClassUtil.getLightClassAccessorMethod(original) ?: return null - convertDeclaration(lightMethod, givenParent, requiredType) + convertDeclaration(lightMethod, givenParent, expectedTypes) } is KtProperty -> if (original.isLocal) { - KotlinConverter.convertPsiElement(element, givenParent, requiredType) - } - else { - convertNonLocalProperty(original, givenParent, requiredType) + KotlinConverter.convertPsiElement(element, givenParent, expectedTypes) + } else { + convertNonLocalProperty(original, givenParent, expectedTypes).firstOrNull() } - is KtParameter -> el { - val ownerFunction = original.ownerFunction as? KtFunction ?: return null - val lightMethod = LightClassUtil.getLightClassMethod(ownerFunction) ?: return null - val lightParameter = lightMethod.parameterList.parameters.find { it.name == original.name } ?: return null - KotlinUParameter(lightParameter, original, givenParent) - } + is KtParameter -> convertParameter(original, givenParent, this).firstOrNull() - is KtFile -> el { KotlinUFile(original) } + is KtFile -> convertKtFile(original, givenParent, this).firstOrNull() is FakeFileForLightClass -> el { KotlinUFile(original.navigationElement) } is KtAnnotationEntry -> el(build(::KotlinUAnnotation)) is KtCallExpression -> - if (requiredType != null && UAnnotation::class.java.isAssignableFrom(requiredType)) { + if (expectedTypes.isAssignableFrom(KotlinUNestedAnnotation::class.java) && !expectedTypes.isAssignableFrom(UCallExpression::class.java)) { el { KotlinUNestedAnnotation.tryCreate(original, givenParent) } } else null - is KtLightAnnotationForSourceEntry -> convertDeclarationOrElement(original.kotlinOrigin, givenParent, requiredType) + is KtLightAnnotationForSourceEntry -> convertDeclarationOrElement(original.kotlinOrigin, givenParent, expectedTypes) is KtDelegatedSuperTypeEntry -> el { KotlinSupertypeDelegationUExpression(original, givenParent) } @@ -499,17 +528,21 @@ internal object KotlinConverter { } - fun convertDeclarationOrElement(element: PsiElement, givenParent: UElement?, requiredType: Class?): UElement? { + fun convertDeclarationOrElement( + element: PsiElement, + givenParent: UElement?, + expectedTypes: Array> + ): UElement? { if (element is UElement) return element if (element.isValid) { element.getUserData(KOTLIN_CACHED_UELEMENT_KEY)?.get()?.let { cachedUElement -> - return if (requiredType == null || requiredType.isInstance(cachedUElement)) cachedUElement else null + return if (expectedTypes.isAssignableFrom(cachedUElement.javaClass)) cachedUElement else null } } - val uElement = convertDeclaration(element, givenParent, requiredType) - ?: KotlinConverter.convertPsiElement(element, givenParent, requiredType) + val uElement = convertDeclaration(element, givenParent, expectedTypes) + ?: KotlinConverter.convertPsiElement(element, givenParent, expectedTypes) /* if (uElement != null) { element.putUserData(KOTLIN_CACHED_UELEMENT_KEY, WeakReference(uElement)) @@ -518,27 +551,71 @@ internal object KotlinConverter { return uElement } - private fun convertNonLocalProperty( + private fun convertToPropertyAlternatives( + methods: LightClassUtil.PropertyAccessorsPsiMethods?, + givenParent: UElement? + ): Array> = if (methods != null) arrayOf( + alternative { methods.backingField?.let { KotlinUField(it, (it as? KtLightElement<*, *>)?.kotlinOrigin, givenParent) } }, + alternative { methods.getter?.let { convertDeclaration(it, givenParent, arrayOf(UMethod::class.java)) as? UMethod } }, + alternative { methods.setter?.let { convertDeclaration(it, givenParent, arrayOf(UMethod::class.java)) as? UMethod } } + ) else emptyArray() + + fun convertNonLocalProperty( property: KtProperty, givenParent: UElement?, - requiredType: Class? - ): UElement? { - val methods = LightClassUtil.getLightClassPropertyMethods(property) - return methods.backingField?.let { backingField -> - with(requiredType) { - el { KotlinUField(backingField, (backingField as? KtLightElement<*,*>)?.kotlinOrigin, givenParent) } + expectedTypes: Array> + ): Sequence = + expectedTypes.accommodate(*convertToPropertyAlternatives(LightClassUtil.getLightClassPropertyMethods(property), givenParent)) + + + fun convertParameter( + element: KtParameter, + givenParent: UElement?, + expectedTypes: Array> + ): Sequence = expectedTypes.accommodate( + alternative uParam@{ + val ownerFunction = element.ownerFunction as? KtFunction ?: return@uParam null + val lightMethod = LightClassUtil.getLightClassMethod(ownerFunction) ?: return@uParam null + val lightParameter = lightMethod.parameterList.parameters.find { it.name == element.name } ?: return@uParam null + KotlinUParameter(lightParameter, element, givenParent) + }, + *convertToPropertyAlternatives(LightClassUtil.getLightClassPropertyMethods(element), givenParent) + ) + + fun convertClassOrObject( + element: KtClassOrObject, + givenParent: UElement?, + expectedTypes: Array> + ): Sequence { + val ktLightClass = element.toLightClass() ?: return emptySequence() + val uClass = KotlinUClass.create(ktLightClass, givenParent) + return expectedTypes.accommodate( + alternative { uClass }, + alternative primaryConstructor@{ + val primaryConstructor = element.primaryConstructor ?: return@primaryConstructor null + uClass.methods.asSequence() + .filter { it.sourcePsi == primaryConstructor } + .firstOrNull() } - } ?: methods.getter?.let { getter -> - convertDeclaration(getter, givenParent, requiredType) - } + ) } + fun convertKtFile( + element: KtFile, + givenParent: UElement?, + requiredTypes: Array> + ): Sequence = requiredTypes.accommodate( + alternative { KotlinUFile(element) }, + alternative { element.findFacadeClass()?.let { KotlinUClass.create(it, givenParent) } } + ) + + internal fun convertOrEmpty(expression: KtExpression?, parent: UElement?): UExpression { - return expression?.let { convertExpression(it, parent, null) } ?: UastEmptyExpression + return expression?.let { convertExpression(it, parent, DEFAULT_EXPRESSION_TYPES_LIST) } ?: UastEmptyExpression } internal fun convertOrNull(expression: KtExpression?, parent: UElement?): UExpression? { - return if (expression != null) convertExpression(expression, parent, null) else null + return if (expression != null) convertExpression(expression, parent, DEFAULT_EXPRESSION_TYPES_LIST) else null } internal fun KtPsiFactory.createAnalyzableExpression(text: String, context: PsiElement): KtExpression = @@ -571,3 +648,22 @@ private fun convertVariablesDeclaration( } val kotlinUastPlugin get() = UastLanguagePlugin.getInstances().find { it.language == KotlinLanguage.INSTANCE } ?: KotlinUastLanguagePlugin() + +private fun expressionTypes(requiredType: Class?) = requiredType?.let { arrayOf(it) } ?: DEFAULT_EXPRESSION_TYPES_LIST + +private fun elementTypes(requiredType: Class?) = requiredType?.let { arrayOf(it) } ?: DEFAULT_TYPES_LIST + +private fun Array>.nonEmptyOr(default: Array>) = takeIf { it.isNotEmpty() } + ?: default + +private fun Array>.accommodate(vararg makers: UElementAlternative): Sequence { + val makersSeq = makers.asSequence() + return this.asSequence() + .flatMap { requiredType -> makersSeq.filter { requiredType.isAssignableFrom(it.uType) } } + .distinct() + .mapNotNull { it.make.invoke() } +} + +private inline fun alternative(noinline make: () -> U?) = UElementAlternative(U::class.java, make) + +private class UElementAlternative(val uType: Class, val make: () -> U?) \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.183 similarity index 75% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.183 index b221083ec70..9b9a2daaf54 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.183 @@ -19,16 +19,13 @@ package org.jetbrains.uast.kotlin import com.intellij.lang.Language import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.util.Key -import com.intellij.openapi.util.registry.Registry import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.impl.source.tree.LeafPsiElement -import org.jetbrains.annotations.TestOnly import org.jetbrains.kotlin.asJava.LightClassUtil import org.jetbrains.kotlin.asJava.classes.KtLightClass import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade import org.jetbrains.kotlin.asJava.elements.* -import org.jetbrains.kotlin.asJava.findFacadeClass import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper import org.jetbrains.kotlin.config.LanguageVersionSettings @@ -42,7 +39,6 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.uast.* -import org.jetbrains.uast.expressions.UInjectionHost import org.jetbrains.uast.kotlin.KotlinConverter.convertDeclaration import org.jetbrains.uast.kotlin.KotlinConverter.convertDeclarationOrElement import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier @@ -79,15 +75,15 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin { override fun convertElement(element: PsiElement, parent: UElement?, requiredType: Class?): UElement? { if (!element.isJvmElement) return null - return convertDeclarationOrElement(element, parent, elementTypes(requiredType)) + return convertDeclarationOrElement(element, parent, requiredType) } override fun convertElementWithParent(element: PsiElement, requiredType: Class?): UElement? { if (!element.isJvmElement) return null - if (element is PsiFile) return convertDeclaration(element, null, elementTypes(requiredType)) - if (element is KtLightClassForFacade) return convertDeclaration(element, null, elementTypes(requiredType)) + if (element is PsiFile) return convertDeclaration(element, null, requiredType) + if (element is KtLightClassForFacade) return convertDeclaration(element, null, requiredType) - return convertDeclarationOrElement(element, null, elementTypes(requiredType)) + return convertDeclarationOrElement(element, null, requiredType) } override fun getMethodCallExpression( @@ -140,45 +136,16 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin { else -> false } } - - @Suppress("UNCHECKED_CAST") - fun convertElement(element: PsiElement, parent: UElement?, expectedTypes: Array>): T? { - if (!element.isJvmElement) return null - val nonEmptyExpectedTypes = expectedTypes.nonEmptyOr(DEFAULT_TYPES_LIST) - return (convertDeclaration(element, parent, nonEmptyExpectedTypes) - ?: KotlinConverter.convertPsiElement(element, parent, nonEmptyExpectedTypes)) as? T - } - - override fun convertElementWithParent(element: PsiElement, requiredTypes: Array>): T? { - return convertElement(element, null, requiredTypes) - } - - @Suppress("UNCHECKED_CAST") - override fun convertToAlternatives(element: PsiElement, requiredTypes: Array>): Sequence = - if (!element.isJvmElement) emptySequence() else when { - element is KtFile -> KotlinConverter.convertKtFile(element, null, requiredTypes) as Sequence - (element is KtProperty && !element.isLocal) -> - KotlinConverter.convertNonLocalProperty(element, null, requiredTypes) as Sequence - element is KtParameter -> KotlinConverter.convertParameter(element, null, requiredTypes) as Sequence - element is KtClassOrObject -> KotlinConverter.convertClassOrObject(element, null, requiredTypes) as Sequence - else -> sequenceOf(convertElementWithParent(element, requiredTypes.nonEmptyOr(DEFAULT_TYPES_LIST)) as? T).filterNotNull() - } } -internal inline fun Class<*>?.el(f: () -> UElement?): UElement? { +internal inline fun Class?.el(f: () -> UElement?): UElement? { return if (this == null || isAssignableFrom(ActualT::class.java)) f() else null } -internal inline fun Array>.el(f: () -> UElement?): UElement? { - return if (isAssignableFrom(ActualT::class.java)) f() else null +internal inline fun Class?.expr(f: () -> UExpression?): UExpression? { + return if (this == null || isAssignableFrom(ActualT::class.java)) f() else null } -internal inline fun Array>.expr(f: () -> UExpression?): UExpression? { - return if (isAssignableFrom(ActualT::class.java)) f() else null -} - -internal fun Array>.isAssignableFrom(cls: Class<*>) = any { it.isAssignableFrom(cls) } - internal object KotlinConverter { @@ -199,13 +166,12 @@ internal object KotlinConverter { internal fun convertPsiElement(element: PsiElement?, givenParent: UElement?, - expectedTypes: Array> - ): UElement? { + requiredType: Class?): UElement? { fun

build(ctor: (P, UElement?) -> UElement): () -> UElement? { return { ctor(element as P, givenParent) } } - return with (expectedTypes) { when (element) { + return with (requiredType) { when (element) { is KtParameterList -> el { val declarationsExpression = KotlinUDeclarationsExpression(givenParent) declarationsExpression.apply { @@ -218,7 +184,11 @@ internal object KotlinConverter { is KtCatchClause -> el(build(::KotlinUCatchClause)) is KtVariableDeclaration -> if (element is KtProperty && !element.isLocal) { - convertNonLocalProperty(element, givenParent, this).firstOrNull() + el { + LightClassUtil.getLightClassBackingField(element)?.let { + KotlinUField(it, element, givenParent) + } + } } else { el { @@ -226,19 +196,19 @@ internal object KotlinConverter { } } - is KtExpression -> KotlinConverter.convertExpression(element, givenParent, expectedTypes) - is KtLambdaArgument -> element.getLambdaExpression()?.let { KotlinConverter.convertExpression(it, givenParent, expectedTypes) } + is KtExpression -> KotlinConverter.convertExpression(element, givenParent, requiredType) + is KtLambdaArgument -> element.getLambdaExpression()?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) } is KtLightElementBase -> { val expression = element.kotlinOrigin when (expression) { - is KtExpression -> KotlinConverter.convertExpression(expression, givenParent, expectedTypes) + is KtExpression -> KotlinConverter.convertExpression(expression, givenParent, requiredType) else -> el { UastEmptyExpression(givenParent) } } } is KtLiteralStringTemplateEntry, is KtEscapeStringTemplateEntry -> el(build(::KotlinStringULiteralExpression)) - is KtStringTemplateEntry -> element.expression?.let { convertExpression(it, givenParent, expectedTypes) } ?: expr { UastEmptyExpression } + is KtStringTemplateEntry -> element.expression?.let { convertExpression(it, givenParent, requiredType) } ?: expr { UastEmptyExpression } is KtWhenEntry -> el(build(::KotlinUSwitchEntry)) - is KtWhenCondition -> convertWhenCondition(element, givenParent, expectedTypes) + is KtWhenCondition -> convertWhenCondition(element, givenParent, requiredType) is KtTypeReference -> el { LazyKotlinUTypeReferenceExpression(element, givenParent) } is KtConstructorDelegationCall -> el { KotlinUFunctionCallExpression(element, givenParent) } @@ -276,8 +246,7 @@ internal object KotlinConverter { internal fun convertEntry(entry: KtStringTemplateEntry, givenParent: UElement?, - requiredType: Array> - ): UExpression? { + requiredType: Class? = null): UExpression? { return with(requiredType) { if (entry is KtStringTemplateEntryWithExpression) { expr { @@ -295,16 +264,9 @@ internal object KotlinConverter { } } - var forceUInjectionHost = Registry.`is`("kotlin.uast.force.uinjectionhost", false) - @TestOnly - set(value) { - field = value - } - internal fun convertExpression(expression: KtExpression, givenParent: UElement?, - requiredType: Array> - ): UExpression? { + requiredType: Class? = null): UExpression? { fun

build(ctor: (P, UElement?) -> UExpression): () -> UExpression? { return { ctor(expression as P, givenParent) } } @@ -314,16 +276,13 @@ internal object KotlinConverter { is KtStringTemplateExpression -> { when { - forceUInjectionHost || requiredType.contains(UInjectionHost::class.java) -> - expr { KotlinStringTemplateUPolyadicExpression(expression, givenParent) } expression.entries.isEmpty() -> { expr { KotlinStringULiteralExpression(expression, givenParent, "") } } - expression.entries.size == 1 -> convertEntry(expression.entries[0], givenParent, requiredType) - - else -> - expr { KotlinStringTemplateUPolyadicExpression(expression, givenParent) } + else -> { + expr { KotlinStringTemplateUPolyadicExpression(expression, givenParent) } + } } } is KtDestructuringDeclaration -> expr { @@ -396,7 +355,7 @@ internal object KotlinConverter { internal fun convertWhenCondition(condition: KtWhenCondition, givenParent: UElement?, - requiredType: Array> + requiredType: Class? = null ): UExpression? { return with(requiredType) { when (condition) { @@ -446,7 +405,7 @@ internal object KotlinConverter { internal fun convertDeclaration( element: PsiElement, givenParent: UElement?, - expectedTypes: Array> + requiredType: Class? ): UElement? { fun

build(ctor: (P, UElement?) -> UElement): () -> UElement? = { ctor(element as P, givenParent) } @@ -457,7 +416,7 @@ internal object KotlinConverter { { ctor(element as P, ktElement, givenParent) } val original = element.originalElement - return with(expectedTypes) { + return with(requiredType) { when (original) { is KtLightMethod -> el(build(KotlinUMethod.Companion::create)) // .Companion is needed because of KT-13934 is KtLightClass -> when (original.kotlinOrigin) { @@ -475,7 +434,11 @@ internal object KotlinConverter { is KtEnumEntry -> el { convertEnumEntry(original, givenParent) } - is KtClassOrObject -> convertClassOrObject(original, givenParent, this).firstOrNull() + is KtClassOrObject -> el { + original.toLightClass()?.let { lightClass -> + KotlinUClass.create(lightClass, givenParent) + } + } is KtFunction -> if (original.isLocal) { el { @@ -484,41 +447,49 @@ internal object KotlinConverter { KotlinULambdaExpression(parent, givenParent) // your parent is the ULambdaExpression } else if (original.name.isNullOrEmpty()) { createLocalFunctionLambdaExpression(original, givenParent) - } else { + } + else { val uDeclarationsExpression = createLocalFunctionDeclaration(original, givenParent) val localFunctionVar = uDeclarationsExpression.declarations.single() as KotlinLocalFunctionUVariable localFunctionVar.uastInitializer } } - } else { + } + else { el { val lightMethod = LightClassUtil.getLightClassMethod(original) ?: return null - convertDeclaration(lightMethod, givenParent, expectedTypes) + convertDeclaration(lightMethod, givenParent, requiredType) } } is KtPropertyAccessor -> el { val lightMethod = LightClassUtil.getLightClassAccessorMethod(original) ?: return null - convertDeclaration(lightMethod, givenParent, expectedTypes) + convertDeclaration(lightMethod, givenParent, requiredType) } is KtProperty -> if (original.isLocal) { - KotlinConverter.convertPsiElement(element, givenParent, expectedTypes) - } else { - convertNonLocalProperty(original, givenParent, expectedTypes).firstOrNull() + KotlinConverter.convertPsiElement(element, givenParent, requiredType) + } + else { + convertNonLocalProperty(original, givenParent, requiredType) } - is KtParameter -> convertParameter(original, givenParent, this).firstOrNull() + is KtParameter -> el { + val ownerFunction = original.ownerFunction as? KtFunction ?: return null + val lightMethod = LightClassUtil.getLightClassMethod(ownerFunction) ?: return null + val lightParameter = lightMethod.parameterList.parameters.find { it.name == original.name } ?: return null + KotlinUParameter(lightParameter, original, givenParent) + } - is KtFile -> convertKtFile(original, givenParent, this).firstOrNull() + is KtFile -> el { KotlinUFile(original) } is FakeFileForLightClass -> el { KotlinUFile(original.navigationElement) } is KtAnnotationEntry -> el(build(::KotlinUAnnotation)) is KtCallExpression -> - if (expectedTypes.isAssignableFrom(KotlinUNestedAnnotation::class.java) && !expectedTypes.isAssignableFrom(UCallExpression::class.java)) { + if (requiredType != null && UAnnotation::class.java.isAssignableFrom(requiredType)) { el { KotlinUNestedAnnotation.tryCreate(original, givenParent) } } else null - is KtLightAnnotationForSourceEntry -> convertDeclarationOrElement(original.kotlinOrigin, givenParent, expectedTypes) + is KtLightAnnotationForSourceEntry -> convertDeclarationOrElement(original.kotlinOrigin, givenParent, requiredType) is KtDelegatedSuperTypeEntry -> el { KotlinSupertypeDelegationUExpression(original, givenParent) } @@ -528,21 +499,17 @@ internal object KotlinConverter { } - fun convertDeclarationOrElement( - element: PsiElement, - givenParent: UElement?, - expectedTypes: Array> - ): UElement? { + fun convertDeclarationOrElement(element: PsiElement, givenParent: UElement?, requiredType: Class?): UElement? { if (element is UElement) return element if (element.isValid) { element.getUserData(KOTLIN_CACHED_UELEMENT_KEY)?.get()?.let { cachedUElement -> - return if (expectedTypes.isAssignableFrom(cachedUElement.javaClass)) cachedUElement else null + return if (requiredType == null || requiredType.isInstance(cachedUElement)) cachedUElement else null } } - val uElement = convertDeclaration(element, givenParent, expectedTypes) - ?: KotlinConverter.convertPsiElement(element, givenParent, expectedTypes) + val uElement = convertDeclaration(element, givenParent, requiredType) + ?: KotlinConverter.convertPsiElement(element, givenParent, requiredType) /* if (uElement != null) { element.putUserData(KOTLIN_CACHED_UELEMENT_KEY, WeakReference(uElement)) @@ -551,71 +518,27 @@ internal object KotlinConverter { return uElement } - private fun convertToPropertyAlternatives( - methods: LightClassUtil.PropertyAccessorsPsiMethods?, - givenParent: UElement? - ): Array> = if (methods != null) arrayOf( - alternative { methods.backingField?.let { KotlinUField(it, (it as? KtLightElement<*, *>)?.kotlinOrigin, givenParent) } }, - alternative { methods.getter?.let { convertDeclaration(it, givenParent, arrayOf(UMethod::class.java)) as? UMethod } }, - alternative { methods.setter?.let { convertDeclaration(it, givenParent, arrayOf(UMethod::class.java)) as? UMethod } } - ) else emptyArray() - - fun convertNonLocalProperty( + private fun convertNonLocalProperty( property: KtProperty, givenParent: UElement?, - expectedTypes: Array> - ): Sequence = - expectedTypes.accommodate(*convertToPropertyAlternatives(LightClassUtil.getLightClassPropertyMethods(property), givenParent)) - - - fun convertParameter( - element: KtParameter, - givenParent: UElement?, - expectedTypes: Array> - ): Sequence = expectedTypes.accommodate( - alternative uParam@{ - val ownerFunction = element.ownerFunction as? KtFunction ?: return@uParam null - val lightMethod = LightClassUtil.getLightClassMethod(ownerFunction) ?: return@uParam null - val lightParameter = lightMethod.parameterList.parameters.find { it.name == element.name } ?: return@uParam null - KotlinUParameter(lightParameter, element, givenParent) - }, - *convertToPropertyAlternatives(LightClassUtil.getLightClassPropertyMethods(element), givenParent) - ) - - fun convertClassOrObject( - element: KtClassOrObject, - givenParent: UElement?, - expectedTypes: Array> - ): Sequence { - val ktLightClass = element.toLightClass() ?: return emptySequence() - val uClass = KotlinUClass.create(ktLightClass, givenParent) - return expectedTypes.accommodate( - alternative { uClass }, - alternative primaryConstructor@{ - val primaryConstructor = element.primaryConstructor ?: return@primaryConstructor null - uClass.methods.asSequence() - .filter { it.sourcePsi == primaryConstructor } - .firstOrNull() + requiredType: Class? + ): UElement? { + val methods = LightClassUtil.getLightClassPropertyMethods(property) + return methods.backingField?.let { backingField -> + with(requiredType) { + el { KotlinUField(backingField, (backingField as? KtLightElement<*,*>)?.kotlinOrigin, givenParent) } } - ) + } ?: methods.getter?.let { getter -> + convertDeclaration(getter, givenParent, requiredType) + } } - fun convertKtFile( - element: KtFile, - givenParent: UElement?, - requiredTypes: Array> - ): Sequence = requiredTypes.accommodate( - alternative { KotlinUFile(element) }, - alternative { element.findFacadeClass()?.let { KotlinUClass.create(it, givenParent) } } - ) - - internal fun convertOrEmpty(expression: KtExpression?, parent: UElement?): UExpression { - return expression?.let { convertExpression(it, parent, DEFAULT_EXPRESSION_TYPES_LIST) } ?: UastEmptyExpression + return expression?.let { convertExpression(it, parent, null) } ?: UastEmptyExpression } internal fun convertOrNull(expression: KtExpression?, parent: UElement?): UExpression? { - return if (expression != null) convertExpression(expression, parent, DEFAULT_EXPRESSION_TYPES_LIST) else null + return if (expression != null) convertExpression(expression, parent, null) else null } internal fun KtPsiFactory.createAnalyzableExpression(text: String, context: PsiElement): KtExpression = @@ -648,22 +571,3 @@ private fun convertVariablesDeclaration( } val kotlinUastPlugin get() = UastLanguagePlugin.getInstances().find { it.language == KotlinLanguage.INSTANCE } ?: KotlinUastLanguagePlugin() - -private fun expressionTypes(requiredType: Class?) = requiredType?.let { arrayOf(it) } ?: DEFAULT_EXPRESSION_TYPES_LIST - -private fun elementTypes(requiredType: Class?) = requiredType?.let { arrayOf(it) } ?: DEFAULT_TYPES_LIST - -private fun Array>.nonEmptyOr(default: Array>) = takeIf { it.isNotEmpty() } - ?: default - -private fun Array>.accommodate(vararg makers: UElementAlternative): Sequence { - val makersSeq = makers.asSequence() - return this.asSequence() - .flatMap { requiredType -> makersSeq.filter { requiredType.isAssignableFrom(it.uType) } } - .distinct() - .mapNotNull { it.make.invoke() } -} - -private inline fun alternative(noinline make: () -> U?) = UElementAlternative(U::class.java, make) - -private class UElementAlternative(val uType: Class, val make: () -> U?) \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt index fb4487692ce..6795ae95096 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt @@ -107,7 +107,7 @@ open class KotlinUMethod( KotlinUBlockExpression.KotlinLazyUBlockExpression(this, { block -> val implicitReturn = KotlinUImplicitReturnExpression(block) val uBody = getLanguagePlugin().convertElement(bodyExpression, implicitReturn) as? UExpression - ?: return@KotlinLazyUBlockExpression emptyList() + ?: return@KotlinLazyUBlockExpression emptyList() listOf(implicitReturn.apply { returnExpression = uBody }) }) @@ -123,6 +123,12 @@ open class KotlinUMethod( override fun getOriginalElement(): PsiElement? = super.getOriginalElement() + override val returnTypeReference: UTypeReferenceExpression? by lz { + (sourcePsi as? KtCallableDeclaration)?.typeReference?.let { + LazyKotlinUTypeReferenceExpression(it, this) { javaPsi.returnType ?: UastErrorType } + } + } + override fun equals(other: Any?) = other is KotlinUMethod && psi == other.psi companion object { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt.183 similarity index 94% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt.183 index 6795ae95096..fb4487692ce 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt.183 @@ -107,7 +107,7 @@ open class KotlinUMethod( KotlinUBlockExpression.KotlinLazyUBlockExpression(this, { block -> val implicitReturn = KotlinUImplicitReturnExpression(block) val uBody = getLanguagePlugin().convertElement(bodyExpression, implicitReturn) as? UExpression - ?: return@KotlinLazyUBlockExpression emptyList() + ?: return@KotlinLazyUBlockExpression emptyList() listOf(implicitReturn.apply { returnExpression = uBody }) }) @@ -123,12 +123,6 @@ open class KotlinUMethod( override fun getOriginalElement(): PsiElement? = super.getOriginalElement() - override val returnTypeReference: UTypeReferenceExpression? by lz { - (sourcePsi as? KtCallableDeclaration)?.typeReference?.let { - LazyKotlinUTypeReferenceExpression(it, this) { javaPsi.returnType ?: UastErrorType } - } - } - override fun equals(other: Any?) = other is KotlinUMethod && psi == other.psi companion object { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt index e2642d6bd8a..36ad4408c6b 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt @@ -9,6 +9,7 @@ import org.jetbrains.uast.evaluation.UEvaluationState import org.jetbrains.uast.kotlin.KotlinBinaryOperators import org.jetbrains.uast.kotlin.KotlinPostfixOperators import org.jetbrains.uast.values.* +import org.jetbrains.uast.evaluation.to class KotlinEvaluatorExtension : AbstractEvaluatorExtension(KotlinLanguage.INSTANCE) { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt.183 similarity index 98% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt.183 index 36ad4408c6b..e2642d6bd8a 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt.183 @@ -9,7 +9,6 @@ import org.jetbrains.uast.evaluation.UEvaluationState import org.jetbrains.uast.kotlin.KotlinBinaryOperators import org.jetbrains.uast.kotlin.KotlinPostfixOperators import org.jetbrains.uast.values.* -import org.jetbrains.uast.evaluation.to class KotlinEvaluatorExtension : AbstractEvaluatorExtension(KotlinLanguage.INSTANCE) { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt index 74e3b5f4ea6..2ced5a28b57 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt @@ -67,7 +67,7 @@ private fun createElvisExpressions( override val sourcePsi: PsiElement? = null override val condition: UExpression by lz { createNotEqWithNullExpression(tempVariable, this) } override val thenExpression: UExpression? by lz { createVariableReferenceExpression(tempVariable, this) } - override val elseExpression: UExpression? by lz { KotlinConverter.convertExpression(right, this ) } + override val elseExpression: UExpression? by lz { KotlinConverter.convertExpression(right, this, DEFAULT_EXPRESSION_TYPES_LIST) } override val isTernary: Boolean = false override val annotations: List = emptyList() override val ifIdentifier: UIdentifier = KotlinUIdentifier(null, this) diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt.183 similarity index 98% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt.183 index 2ced5a28b57..74e3b5f4ea6 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/ElvisExpression.kt.183 @@ -67,7 +67,7 @@ private fun createElvisExpressions( override val sourcePsi: PsiElement? = null override val condition: UExpression by lz { createNotEqWithNullExpression(tempVariable, this) } override val thenExpression: UExpression? by lz { createVariableReferenceExpression(tempVariable, this) } - override val elseExpression: UExpression? by lz { KotlinConverter.convertExpression(right, this, DEFAULT_EXPRESSION_TYPES_LIST) } + override val elseExpression: UExpression? by lz { KotlinConverter.convertExpression(right, this ) } override val isTernary: Boolean = false override val annotations: List = emptyList() override val ifIdentifier: UIdentifier = KotlinUIdentifier(null, this) diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt index 5db5fbc72a4..65c25c8a1ed 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt @@ -16,19 +16,33 @@ package org.jetbrains.uast.kotlin +import com.intellij.psi.PsiLanguageInjectionHost import org.jetbrains.kotlin.psi.KtStringTemplateExpression -import org.jetbrains.uast.UElement -import org.jetbrains.uast.UExpression -import org.jetbrains.uast.UPolyadicExpression -import org.jetbrains.uast.UastBinaryOperator +import org.jetbrains.uast.* +import org.jetbrains.uast.expressions.UInjectionHost class KotlinStringTemplateUPolyadicExpression( - override val psi: KtStringTemplateExpression, - givenParent: UElement? + override val psi: KtStringTemplateExpression, + givenParent: UElement? ) : KotlinAbstractUExpression(givenParent), - UPolyadicExpression, - KotlinUElementWithType, - KotlinEvaluatableUElement { - override val operands: List by lz { psi.entries.map { KotlinConverter.convertEntry(it, this)!! } } + UPolyadicExpression, + KotlinUElementWithType, + KotlinEvaluatableUElement, + UInjectionHost { + override val operands: List by lz { + psi.entries.map { + KotlinConverter.convertEntry( + it, + this, + DEFAULT_EXPRESSION_TYPES_LIST + )!! + } + } override val operator = UastBinaryOperator.PLUS + + override val psiLanguageInjectionHost: PsiLanguageInjectionHost get() = psi + override val isString: Boolean get() = true + + override fun asRenderString(): String = if (operands.isEmpty()) "\"\"" else super.asRenderString() + override fun asLogString(): String = if (operands.isEmpty()) "UPolyadicExpression (value = \"\")" else super.asLogString() } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.183 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.183 new file mode 100644 index 00000000000..5db5fbc72a4 --- /dev/null +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.183 @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.uast.kotlin + +import org.jetbrains.kotlin.psi.KtStringTemplateExpression +import org.jetbrains.uast.UElement +import org.jetbrains.uast.UExpression +import org.jetbrains.uast.UPolyadicExpression +import org.jetbrains.uast.UastBinaryOperator + +class KotlinStringTemplateUPolyadicExpression( + override val psi: KtStringTemplateExpression, + givenParent: UElement? +) : KotlinAbstractUExpression(givenParent), + UPolyadicExpression, + KotlinUElementWithType, + KotlinEvaluatableUElement { + override val operands: List by lz { psi.entries.map { KotlinConverter.convertEntry(it, this)!! } } + override val operator = UastBinaryOperator.PLUS +} \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.191 deleted file mode 100644 index 65c25c8a1ed..00000000000 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.191 +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.uast.kotlin - -import com.intellij.psi.PsiLanguageInjectionHost -import org.jetbrains.kotlin.psi.KtStringTemplateExpression -import org.jetbrains.uast.* -import org.jetbrains.uast.expressions.UInjectionHost - -class KotlinStringTemplateUPolyadicExpression( - override val psi: KtStringTemplateExpression, - givenParent: UElement? -) : KotlinAbstractUExpression(givenParent), - UPolyadicExpression, - KotlinUElementWithType, - KotlinEvaluatableUElement, - UInjectionHost { - override val operands: List by lz { - psi.entries.map { - KotlinConverter.convertEntry( - it, - this, - DEFAULT_EXPRESSION_TYPES_LIST - )!! - } - } - override val operator = UastBinaryOperator.PLUS - - override val psiLanguageInjectionHost: PsiLanguageInjectionHost get() = psi - override val isString: Boolean get() = true - - override fun asRenderString(): String = if (operands.isEmpty()) "\"\"" else super.asRenderString() - override fun asLogString(): String = if (operands.isEmpty()) "UPolyadicExpression (value = \"\")" else super.asLogString() -} \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt index 6dedf972075..2f2b06ce476 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt @@ -20,10 +20,7 @@ import com.intellij.psi.PsiNamedElement import com.intellij.psi.ResolveResult import org.jetbrains.kotlin.psi.KtCallableReferenceExpression import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS -import org.jetbrains.uast.UCallableReferenceExpression -import org.jetbrains.uast.UElement -import org.jetbrains.uast.UExpression -import org.jetbrains.uast.UMultiResolvable +import org.jetbrains.uast.* import org.jetbrains.uast.kotlin.internal.getResolveResultVariants class KotlinUCallableReferenceExpression( @@ -34,7 +31,7 @@ class KotlinUCallableReferenceExpression( get() { if (qualifierType != null) return null val receiverExpression = psi.receiverExpression ?: return null - return KotlinConverter.convertExpression(receiverExpression, this) + return KotlinConverter.convertExpression(receiverExpression, this, DEFAULT_EXPRESSION_TYPES_LIST) } override val qualifierType by lz { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt.183 similarity index 91% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt.183 index 2f2b06ce476..6dedf972075 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCallableReferenceExpression.kt.183 @@ -20,7 +20,10 @@ import com.intellij.psi.PsiNamedElement import com.intellij.psi.ResolveResult import org.jetbrains.kotlin.psi.KtCallableReferenceExpression import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS -import org.jetbrains.uast.* +import org.jetbrains.uast.UCallableReferenceExpression +import org.jetbrains.uast.UElement +import org.jetbrains.uast.UExpression +import org.jetbrains.uast.UMultiResolvable import org.jetbrains.uast.kotlin.internal.getResolveResultVariants class KotlinUCallableReferenceExpression( @@ -31,7 +34,7 @@ class KotlinUCallableReferenceExpression( get() { if (qualifierType != null) return null val receiverExpression = psi.receiverExpression ?: return null - return KotlinConverter.convertExpression(receiverExpression, this, DEFAULT_EXPRESSION_TYPES_LIST) + return KotlinConverter.convertExpression(receiverExpression, this) } override val qualifierType by lz { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt index 28125ec5b28..748ea720f53 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt @@ -18,6 +18,7 @@ package org.jetbrains.uast.kotlin import org.jetbrains.kotlin.psi.KtClassLiteralExpression import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS +import org.jetbrains.uast.DEFAULT_EXPRESSION_TYPES_LIST import org.jetbrains.uast.UClassLiteralExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.UExpression @@ -35,6 +36,6 @@ class KotlinUClassLiteralExpression( get() { if (type != null) return null val receiverExpression = psi.receiverExpression ?: return null - return KotlinConverter.convertExpression(receiverExpression, this) + return KotlinConverter.convertExpression(receiverExpression, this, DEFAULT_EXPRESSION_TYPES_LIST) } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt.183 similarity index 93% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt.183 index 748ea720f53..28125ec5b28 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUClassLiteralExpression.kt.183 @@ -18,7 +18,6 @@ package org.jetbrains.uast.kotlin import org.jetbrains.kotlin.psi.KtClassLiteralExpression import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS -import org.jetbrains.uast.DEFAULT_EXPRESSION_TYPES_LIST import org.jetbrains.uast.UClassLiteralExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.UExpression @@ -36,6 +35,6 @@ class KotlinUClassLiteralExpression( get() { if (type != null) return null val receiverExpression = psi.receiverExpression ?: return null - return KotlinConverter.convertExpression(receiverExpression, this, DEFAULT_EXPRESSION_TYPES_LIST) + return KotlinConverter.convertExpression(receiverExpression, this) } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt index 3a0b23a12bb..c06035e6ee1 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.KtObjectLiteralExpression import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.uast.* +import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve class KotlinUObjectLiteralExpression( @@ -82,7 +83,10 @@ class KotlinUObjectLiteralExpression( get() = identifier override val identifier: String - get() = psi.name ?: "" + get() = psi.name ?: referenceNameElement.sourcePsi?.text ?: "" + + override val referenceNameElement: UElement + get() = KotlinUIdentifier(psi.typeReference?.nameElement, this) } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt.183 similarity index 92% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt.183 index c06035e6ee1..3a0b23a12bb 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUObjectLiteralExpression.kt.183 @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.psi.KtObjectLiteralExpression import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.uast.* -import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier import org.jetbrains.uast.kotlin.internal.DelegatedMultiResolve class KotlinUObjectLiteralExpression( @@ -83,10 +82,7 @@ class KotlinUObjectLiteralExpression( get() = identifier override val identifier: String - get() = psi.name ?: referenceNameElement.sourcePsi?.text ?: "" - - override val referenceNameElement: UElement - get() = KotlinUIdentifier(psi.typeReference?.nameElement, this) + get() = psi.name ?: "" } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt index eb90d47c3ec..5c060f991c8 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt @@ -18,6 +18,7 @@ package org.jetbrains.uast.kotlin import com.intellij.psi.PsiNamedElement import org.jetbrains.kotlin.psi.KtDotQualifiedExpression +import org.jetbrains.uast.UCallExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.UQualifiedReferenceExpression import org.jetbrains.uast.UastQualifiedExpressionAccessType @@ -36,4 +37,10 @@ class KotlinUQualifiedReferenceExpression( override val resolvedName: String? get() = (resolve() as? PsiNamedElement)?.name + + override val referenceNameElement: UElement? + get() = when (val selector = selector) { + is UCallExpression -> selector.methodIdentifier + else -> super.referenceNameElement + } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt.183 similarity index 86% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt.183 index 5c060f991c8..eb90d47c3ec 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUQualifiedReferenceExpression.kt.183 @@ -18,7 +18,6 @@ package org.jetbrains.uast.kotlin import com.intellij.psi.PsiNamedElement import org.jetbrains.kotlin.psi.KtDotQualifiedExpression -import org.jetbrains.uast.UCallExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.UQualifiedReferenceExpression import org.jetbrains.uast.UastQualifiedExpressionAccessType @@ -37,10 +36,4 @@ class KotlinUQualifiedReferenceExpression( override val resolvedName: String? get() = (resolve() as? PsiNamedElement)?.name - - override val referenceNameElement: UElement? - get() = when (val selector = selector) { - is UCallExpression -> selector.methodIdentifier - else -> super.referenceNameElement - } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt index bcdfcb5a982..d621cfd0aa5 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt @@ -71,6 +71,8 @@ open class KotlinUSimpleReferenceExpression( visitor.afterVisitSimpleNameReferenceExpression(this) } + override val referenceNameElement: UElement? by lz { psi.getIdentifier()?.toUElement() } + private fun visitAccessorCalls(visitor: UastVisitor) { // Visit Kotlin get-set synthetic Java property calls as function calls val bindingContext = psi.analyze() diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt.183 similarity index 99% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt.183 index d621cfd0aa5..bcdfcb5a982 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt.183 @@ -71,8 +71,6 @@ open class KotlinUSimpleReferenceExpression( visitor.afterVisitSimpleNameReferenceExpression(this) } - override val referenceNameElement: UElement? by lz { psi.getIdentifier()?.toUElement() } - private fun visitAccessorCalls(visitor: UastVisitor) { // Visit Kotlin get-set synthetic Java property calls as function calls val bindingContext = psi.analyze() diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt index 52052a319ed..99a7fe36f64 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt @@ -54,7 +54,7 @@ class KotlinUSwitchEntry( givenParent: UElement? ) : KotlinAbstractUExpression(givenParent), USwitchClauseExpressionWithBody { override val caseValues by lz { - psi.conditions.map { KotlinConverter.convertWhenCondition(it, this) ?: UastEmptyExpression } + psi.conditions.map { KotlinConverter.convertWhenCondition(it, this, DEFAULT_EXPRESSION_TYPES_LIST) ?: UastEmptyExpression } } override val body: UExpressionList by lz { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt.183 similarity index 98% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt.183 index 99a7fe36f64..52052a319ed 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSwitchExpression.kt.183 @@ -54,7 +54,7 @@ class KotlinUSwitchEntry( givenParent: UElement? ) : KotlinAbstractUExpression(givenParent), USwitchClauseExpressionWithBody { override val caseValues by lz { - psi.conditions.map { KotlinConverter.convertWhenCondition(it, this, DEFAULT_EXPRESSION_TYPES_LIST) ?: UastEmptyExpression } + psi.conditions.map { KotlinConverter.convertWhenCondition(it, this) ?: UastEmptyExpression } } override val body: UExpressionList by lz { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt index db9c6cedd83..548d9520778 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt @@ -17,10 +17,7 @@ package org.jetbrains.uast.kotlin import org.jetbrains.kotlin.psi.KtTryExpression -import org.jetbrains.uast.UElement -import org.jetbrains.uast.UIdentifier -import org.jetbrains.uast.UTryExpression -import org.jetbrains.uast.UVariable +import org.jetbrains.uast.* import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier class KotlinUTryExpression( @@ -29,7 +26,15 @@ class KotlinUTryExpression( ) : KotlinAbstractUExpression(givenParent), UTryExpression, KotlinUElementWithType { override val tryClause by lz { KotlinConverter.convertOrEmpty(psi.tryBlock, this) } override val catchClauses by lz { psi.catchClauses.map { KotlinUCatchClause(it, this) } } - override val finallyClause by lz { psi.finallyBlock?.finalExpression?.let { KotlinConverter.convertExpression(it, this) } } + override val finallyClause by lz { + psi.finallyBlock?.finalExpression?.let { + KotlinConverter.convertExpression( + it, + this, + DEFAULT_EXPRESSION_TYPES_LIST + ) + } + } override val resourceVariables: List get() = emptyList() diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt.183 similarity index 83% rename from plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt.191 rename to plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt.183 index 548d9520778..db9c6cedd83 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt.191 +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTryExpression.kt.183 @@ -17,7 +17,10 @@ package org.jetbrains.uast.kotlin import org.jetbrains.kotlin.psi.KtTryExpression -import org.jetbrains.uast.* +import org.jetbrains.uast.UElement +import org.jetbrains.uast.UIdentifier +import org.jetbrains.uast.UTryExpression +import org.jetbrains.uast.UVariable import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier class KotlinUTryExpression( @@ -26,15 +29,7 @@ class KotlinUTryExpression( ) : KotlinAbstractUExpression(givenParent), UTryExpression, KotlinUElementWithType { override val tryClause by lz { KotlinConverter.convertOrEmpty(psi.tryBlock, this) } override val catchClauses by lz { psi.catchClauses.map { KotlinUCatchClause(it, this) } } - override val finallyClause by lz { - psi.finallyBlock?.finalExpression?.let { - KotlinConverter.convertExpression( - it, - this, - DEFAULT_EXPRESSION_TYPES_LIST - ) - } - } + override val finallyClause by lz { psi.finallyBlock?.finalExpression?.let { KotlinConverter.convertExpression(it, this) } } override val resourceVariables: List get() = emptyList() diff --git a/plugins/uast-kotlin/testData/Anonymous.refNames.txt.191 b/plugins/uast-kotlin/testData/Anonymous.refNames.txt similarity index 100% rename from plugins/uast-kotlin/testData/Anonymous.refNames.txt.191 rename to plugins/uast-kotlin/testData/Anonymous.refNames.txt diff --git a/plugins/uast-kotlin/testData/Anonymous.refNames.txt.183 b/plugins/uast-kotlin/testData/Anonymous.refNames.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/Assertion.values.txt.191 b/plugins/uast-kotlin/testData/Assertion.values.txt.183 similarity index 100% rename from plugins/uast-kotlin/testData/Assertion.values.txt.191 rename to plugins/uast-kotlin/testData/Assertion.values.txt.183 diff --git a/plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt.191 b/plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt similarity index 100% rename from plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt.191 rename to plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt diff --git a/plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt.183 b/plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt b/plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt index b26c4c639f6..991b620ac1d 100644 --- a/plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt +++ b/plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt @@ -1,7 +1,7 @@ Test -> UAnnotation (fqName = null) A -> UClass (name = A) MyAnnotation -> UClass (name = MyAnnotation) -text -> [!] UnknownKotlinExpression (VALUE_PARAMETER) +text -> UAnnotationMethod (name = text) String -> USimpleNameReferenceExpression (identifier = String) MyAnnotation -> UAnnotation (fqName = MyAnnotation) B -> UClass (name = B) diff --git a/plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt.191 b/plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt.183 similarity index 90% rename from plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt.191 rename to plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt.183 index 991b620ac1d..b26c4c639f6 100644 --- a/plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt.191 +++ b/plugins/uast-kotlin/testData/ClassAnnotation.identifiers.txt.183 @@ -1,7 +1,7 @@ Test -> UAnnotation (fqName = null) A -> UClass (name = A) MyAnnotation -> UClass (name = MyAnnotation) -text -> UAnnotationMethod (name = text) +text -> [!] UnknownKotlinExpression (VALUE_PARAMETER) String -> USimpleNameReferenceExpression (identifier = String) MyAnnotation -> UAnnotation (fqName = MyAnnotation) B -> UClass (name = B) diff --git a/plugins/uast-kotlin/testData/ClassAnnotation.refNames.txt.191 b/plugins/uast-kotlin/testData/ClassAnnotation.refNames.txt similarity index 100% rename from plugins/uast-kotlin/testData/ClassAnnotation.refNames.txt.191 rename to plugins/uast-kotlin/testData/ClassAnnotation.refNames.txt diff --git a/plugins/uast-kotlin/testData/ClassAnnotation.refNames.txt.183 b/plugins/uast-kotlin/testData/ClassAnnotation.refNames.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/Constructors.refNames.txt.191 b/plugins/uast-kotlin/testData/Constructors.refNames.txt similarity index 100% rename from plugins/uast-kotlin/testData/Constructors.refNames.txt.191 rename to plugins/uast-kotlin/testData/Constructors.refNames.txt diff --git a/plugins/uast-kotlin/testData/Constructors.refNames.txt.183 b/plugins/uast-kotlin/testData/Constructors.refNames.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/InnerClasses.altlog.txt.191 b/plugins/uast-kotlin/testData/InnerClasses.altlog.txt similarity index 100% rename from plugins/uast-kotlin/testData/InnerClasses.altlog.txt.191 rename to plugins/uast-kotlin/testData/InnerClasses.altlog.txt diff --git a/plugins/uast-kotlin/testData/InnerClasses.altlog.txt.183 b/plugins/uast-kotlin/testData/InnerClasses.altlog.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/InnerClasses.splog.txt.191 b/plugins/uast-kotlin/testData/InnerClasses.splog.txt similarity index 100% rename from plugins/uast-kotlin/testData/InnerClasses.splog.txt.191 rename to plugins/uast-kotlin/testData/InnerClasses.splog.txt diff --git a/plugins/uast-kotlin/testData/InnerClasses.splog.txt.183 b/plugins/uast-kotlin/testData/InnerClasses.splog.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt.191 b/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt similarity index 100% rename from plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt.191 rename to plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt.183 b/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.refNames.txt.191 b/plugins/uast-kotlin/testData/LocalDeclarations.refNames.txt similarity index 100% rename from plugins/uast-kotlin/testData/LocalDeclarations.refNames.txt.191 rename to plugins/uast-kotlin/testData/LocalDeclarations.refNames.txt diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.refNames.txt.183 b/plugins/uast-kotlin/testData/LocalDeclarations.refNames.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/ManyAlternatives.kt.191 b/plugins/uast-kotlin/testData/ManyAlternatives.kt similarity index 100% rename from plugins/uast-kotlin/testData/ManyAlternatives.kt.191 rename to plugins/uast-kotlin/testData/ManyAlternatives.kt diff --git a/plugins/uast-kotlin/testData/ManyAlternatives.kt.183 b/plugins/uast-kotlin/testData/ManyAlternatives.kt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt.191 b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt similarity index 100% rename from plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt.191 rename to plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt.183 b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/SimpleAnnotated.refNames.txt.191 b/plugins/uast-kotlin/testData/SimpleAnnotated.refNames.txt similarity index 100% rename from plugins/uast-kotlin/testData/SimpleAnnotated.refNames.txt.191 rename to plugins/uast-kotlin/testData/SimpleAnnotated.refNames.txt diff --git a/plugins/uast-kotlin/testData/SimpleAnnotated.refNames.txt.183 b/plugins/uast-kotlin/testData/SimpleAnnotated.refNames.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.kt.191 b/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.kt similarity index 100% rename from plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.kt.191 rename to plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.kt diff --git a/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.kt.183 b/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.kt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.log.txt.191 b/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.log.txt similarity index 100% rename from plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.log.txt.191 rename to plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.log.txt diff --git a/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.log.txt.183 b/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.log.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.render.txt.191 b/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.render.txt similarity index 100% rename from plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.render.txt.191 rename to plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.render.txt diff --git a/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.render.txt.183 b/plugins/uast-kotlin/testData/StringTemplateComplexForUInjectionHost.render.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/testData/SuperCalls.refNames.txt.191 b/plugins/uast-kotlin/testData/SuperCalls.refNames.txt similarity index 100% rename from plugins/uast-kotlin/testData/SuperCalls.refNames.txt.191 rename to plugins/uast-kotlin/testData/SuperCalls.refNames.txt diff --git a/plugins/uast-kotlin/testData/SuperCalls.refNames.txt.183 b/plugins/uast-kotlin/testData/SuperCalls.refNames.txt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt index ff2b42742d8..0262154ebf6 100644 --- a/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt +++ b/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt @@ -1,7 +1,12 @@ package org.jetbrains.uast.test.kotlin +import com.intellij.psi.PsiElement +import org.jetbrains.uast.* +import org.jetbrains.uast.test.common.UElementToParentMap import org.jetbrains.uast.test.common.kotlin.IdentifiersTestBase +import org.jetbrains.uast.test.env.assertEqualsToFile import java.io.File +import kotlin.test.assertNotNull abstract class AbstractKotlinIdentifiersTest : AbstractKotlinUastTest(), IdentifiersTestBase { @@ -11,5 +16,21 @@ abstract class AbstractKotlinIdentifiersTest : AbstractKotlinUastTest(), Identif override fun getIdentifiersFile(testName: String): File = getTestFile(testName, "identifiers.txt") + override fun check(testName: String, file: UFile) { + super.check(testName, file) + assertEqualsToFile("refNames", getTestFile(testName, "refNames.txt"), file.asRefNames()) + } +} -} \ No newline at end of file +private fun refNameRetriever(psiElement: PsiElement): UElement? = + when (val uElement = psiElement.toUElementOfExpectedTypes(UCallExpression::class.java, UReferenceExpression::class.java)) { + is UReferenceExpression -> uElement.referenceNameElement + is UCallExpression -> uElement.classReference?.referenceNameElement + else -> null + }?.also { + assertNotNull(it.sourcePsi, "referenceNameElement should have physical source, origin = $psiElement") + } + +fun UFile.asRefNames() = object : UElementToParentMap(::refNameRetriever) { + override fun renderSource(element: PsiElement): String = element.javaClass.simpleName +}.visitUFileAndGetResult(this) \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt.183 b/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt.183 new file mode 100644 index 00000000000..ff2b42742d8 --- /dev/null +++ b/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt.183 @@ -0,0 +1,15 @@ +package org.jetbrains.uast.test.kotlin + +import org.jetbrains.uast.test.common.kotlin.IdentifiersTestBase +import java.io.File + + +abstract class AbstractKotlinIdentifiersTest : AbstractKotlinUastTest(), IdentifiersTestBase { + + private fun getTestFile(testName: String, ext: String) = + File(File(AbstractKotlinUastTest.TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) + + override fun getIdentifiersFile(testName: String): File = getTestFile(testName, "identifiers.txt") + + +} \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt.191 b/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt.191 deleted file mode 100644 index 0262154ebf6..00000000000 --- a/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt.191 +++ /dev/null @@ -1,36 +0,0 @@ -package org.jetbrains.uast.test.kotlin - -import com.intellij.psi.PsiElement -import org.jetbrains.uast.* -import org.jetbrains.uast.test.common.UElementToParentMap -import org.jetbrains.uast.test.common.kotlin.IdentifiersTestBase -import org.jetbrains.uast.test.env.assertEqualsToFile -import java.io.File -import kotlin.test.assertNotNull - - -abstract class AbstractKotlinIdentifiersTest : AbstractKotlinUastTest(), IdentifiersTestBase { - - private fun getTestFile(testName: String, ext: String) = - File(File(AbstractKotlinUastTest.TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) - - override fun getIdentifiersFile(testName: String): File = getTestFile(testName, "identifiers.txt") - - override fun check(testName: String, file: UFile) { - super.check(testName, file) - assertEqualsToFile("refNames", getTestFile(testName, "refNames.txt"), file.asRefNames()) - } -} - -private fun refNameRetriever(psiElement: PsiElement): UElement? = - when (val uElement = psiElement.toUElementOfExpectedTypes(UCallExpression::class.java, UReferenceExpression::class.java)) { - is UReferenceExpression -> uElement.referenceNameElement - is UCallExpression -> uElement.classReference?.referenceNameElement - else -> null - }?.also { - assertNotNull(it.sourcePsi, "referenceNameElement should have physical source, origin = $psiElement") - } - -fun UFile.asRefNames() = object : UElementToParentMap(::refNameRetriever) { - override fun renderSource(element: PsiElement): String = element.javaClass.simpleName -}.visitUFileAndGetResult(this) \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt.191 b/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt similarity index 100% rename from plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt.191 rename to plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt diff --git a/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt.183 b/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/tests/KotlinUastAlternativesTest.kt.191 b/plugins/uast-kotlin/tests/KotlinUastAlternativesTest.kt similarity index 100% rename from plugins/uast-kotlin/tests/KotlinUastAlternativesTest.kt.191 rename to plugins/uast-kotlin/tests/KotlinUastAlternativesTest.kt diff --git a/plugins/uast-kotlin/tests/KotlinUastAlternativesTest.kt.183 b/plugins/uast-kotlin/tests/KotlinUastAlternativesTest.kt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt index 3d374de7a1b..8d328472a12 100644 --- a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt +++ b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.assertedCast import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.sure import org.jetbrains.uast.* +import org.jetbrains.uast.expressions.UInjectionHost import org.jetbrains.uast.kotlin.KotlinUastLanguagePlugin import org.jetbrains.uast.test.env.kotlin.findElementByText import org.jetbrains.uast.test.env.kotlin.findElementByTextFromPsi @@ -216,21 +217,21 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { fun testWhenStringLiteral() { doTest("WhenStringLiteral") { _, file -> - file.findElementByTextFromPsi("abc").let { literalExpression -> + file.findElementByTextFromPsi("\"abc\"").let { literalExpression -> val psi = literalExpression.psi!! - Assert.assertTrue(psi is KtLiteralStringTemplateEntry) + Assert.assertTrue(psi is KtStringTemplateExpression) UsefulTestCase.assertInstanceOf(literalExpression.uastParent, USwitchClauseExpressionWithBody::class.java) } - file.findElementByTextFromPsi("def").let { literalExpression -> + file.findElementByTextFromPsi("\"def\"").let { literalExpression -> val psi = literalExpression.psi!! - Assert.assertTrue(psi is KtLiteralStringTemplateEntry) + Assert.assertTrue(psi is KtStringTemplateExpression) UsefulTestCase.assertInstanceOf(literalExpression.uastParent, USwitchClauseExpressionWithBody::class.java) } - file.findElementByTextFromPsi("def1").let { literalExpression -> + file.findElementByTextFromPsi("\"def1\"").let { literalExpression -> val psi = literalExpression.psi!! - Assert.assertTrue(psi is KtLiteralStringTemplateEntry) + Assert.assertTrue(psi is KtStringTemplateExpression) UsefulTestCase.assertInstanceOf(literalExpression.uastParent, UBlockExpression::class.java) } @@ -549,6 +550,21 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { } } + @Test + fun testMethodReturnTypeReference() { + doTest("Elvis") { _, file -> + assertEquals( + "UTypeReferenceExpression (name = java.lang.String)", + file.findElementByTextFromPsi("fun foo(bar: String): String? = null").returnTypeReference?.asLogString() + ) + assertEquals( + null, + file.findElementByTextFromPsi("fun bar() = 42").returnTypeReference?.asLogString() + ) + + } + } + @Test fun testVariablesTypeReferences() { doTest("TypeReferences") { _, file -> diff --git a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt.191 b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt.183 similarity index 96% rename from plugins/uast-kotlin/tests/KotlinUastApiTest.kt.191 rename to plugins/uast-kotlin/tests/KotlinUastApiTest.kt.183 index 8d328472a12..3d374de7a1b 100644 --- a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt.191 +++ b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt.183 @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.assertedCast import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.sure import org.jetbrains.uast.* -import org.jetbrains.uast.expressions.UInjectionHost import org.jetbrains.uast.kotlin.KotlinUastLanguagePlugin import org.jetbrains.uast.test.env.kotlin.findElementByText import org.jetbrains.uast.test.env.kotlin.findElementByTextFromPsi @@ -217,21 +216,21 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { fun testWhenStringLiteral() { doTest("WhenStringLiteral") { _, file -> - file.findElementByTextFromPsi("\"abc\"").let { literalExpression -> + file.findElementByTextFromPsi("abc").let { literalExpression -> val psi = literalExpression.psi!! - Assert.assertTrue(psi is KtStringTemplateExpression) + Assert.assertTrue(psi is KtLiteralStringTemplateEntry) UsefulTestCase.assertInstanceOf(literalExpression.uastParent, USwitchClauseExpressionWithBody::class.java) } - file.findElementByTextFromPsi("\"def\"").let { literalExpression -> + file.findElementByTextFromPsi("def").let { literalExpression -> val psi = literalExpression.psi!! - Assert.assertTrue(psi is KtStringTemplateExpression) + Assert.assertTrue(psi is KtLiteralStringTemplateEntry) UsefulTestCase.assertInstanceOf(literalExpression.uastParent, USwitchClauseExpressionWithBody::class.java) } - file.findElementByTextFromPsi("\"def1\"").let { literalExpression -> + file.findElementByTextFromPsi("def1").let { literalExpression -> val psi = literalExpression.psi!! - Assert.assertTrue(psi is KtStringTemplateExpression) + Assert.assertTrue(psi is KtLiteralStringTemplateEntry) UsefulTestCase.assertInstanceOf(literalExpression.uastParent, UBlockExpression::class.java) } @@ -550,21 +549,6 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { } } - @Test - fun testMethodReturnTypeReference() { - doTest("Elvis") { _, file -> - assertEquals( - "UTypeReferenceExpression (name = java.lang.String)", - file.findElementByTextFromPsi("fun foo(bar: String): String? = null").returnTypeReference?.asLogString() - ) - assertEquals( - null, - file.findElementByTextFromPsi("fun bar() = 42").returnTypeReference?.asLogString() - ) - - } - } - @Test fun testVariablesTypeReferences() { doTest("TypeReferences") { _, file -> diff --git a/plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt b/plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt index a2729463164..ec2cb86b56b 100644 --- a/plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt +++ b/plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt @@ -9,7 +9,7 @@ import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.util.Disposer -import com.intellij.patterns.uast.literalExpression +import com.intellij.patterns.uast.injectionHostUExpression import com.intellij.psi.* import com.intellij.psi.impl.source.resolve.reference.PsiReferenceContributorEP import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry @@ -35,7 +35,7 @@ class KotlinUastReferencesTest : KotlinLightCodeInsightFixtureTestCase() { fun `test original getter is visible when reference is under renaming`() { registerReferenceProviders(testRootDisposable) { - registerUastReferenceProvider(literalExpression(), uastLiteralReferenceProvider { _, psiLanguageInjectionHost -> + registerUastReferenceProvider(injectionHostUExpression(), uastInjectionHostReferenceProvider { _, psiLanguageInjectionHost -> arrayOf(GetterReference("KotlinBean", psiLanguageInjectionHost)) }) } diff --git a/plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt.191 b/plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt.183 similarity index 95% rename from plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt.191 rename to plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt.183 index ec2cb86b56b..a2729463164 100644 --- a/plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt.191 +++ b/plugins/uast-kotlin/tests/KotlinUastReferencesTest.kt.183 @@ -9,7 +9,7 @@ import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.util.Disposer -import com.intellij.patterns.uast.injectionHostUExpression +import com.intellij.patterns.uast.literalExpression import com.intellij.psi.* import com.intellij.psi.impl.source.resolve.reference.PsiReferenceContributorEP import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry @@ -35,7 +35,7 @@ class KotlinUastReferencesTest : KotlinLightCodeInsightFixtureTestCase() { fun `test original getter is visible when reference is under renaming`() { registerReferenceProviders(testRootDisposable) { - registerUastReferenceProvider(injectionHostUExpression(), uastInjectionHostReferenceProvider { _, psiLanguageInjectionHost -> + registerUastReferenceProvider(literalExpression(), uastLiteralReferenceProvider { _, psiLanguageInjectionHost -> arrayOf(GetterReference("KotlinBean", psiLanguageInjectionHost)) }) } diff --git a/plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt.191 b/plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt similarity index 100% rename from plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt.191 rename to plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt diff --git a/plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt.183 b/plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt.183 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt index 6a7e6f453da..4e27b5cee53 100644 --- a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt @@ -1,5 +1,6 @@ package org.jetbrains.uast.test.kotlin +import org.jetbrains.uast.kotlin.KotlinConverter import org.junit.Test class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @@ -27,6 +28,11 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @Test fun testStringTemplateComplex() = doTest("StringTemplateComplex") + @Test + fun testStringTemplateComplexForUInjectionHost() = withForceUInjectionHostValue { + doTest("StringTemplateComplexForUInjectionHost") + } + @Test fun testQualifiedConstructorCall() = doTest("QualifiedConstructorCall") @Test fun testPropertyDelegate() = doTest("PropertyDelegate") @@ -94,3 +100,13 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @Test fun testConstructorDelegate() = doTest("ConstructorDelegate") } + +fun withForceUInjectionHostValue(call: () -> Unit) { + val prev = KotlinConverter.forceUInjectionHost + KotlinConverter.forceUInjectionHost = true + try { + call.invoke() + } finally { + KotlinConverter.forceUInjectionHost = prev + } +} \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.191 b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.183 similarity index 86% rename from plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.191 rename to plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.183 index 4e27b5cee53..6a7e6f453da 100644 --- a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.191 +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt.183 @@ -1,6 +1,5 @@ package org.jetbrains.uast.test.kotlin -import org.jetbrains.uast.kotlin.KotlinConverter import org.junit.Test class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @@ -28,11 +27,6 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @Test fun testStringTemplateComplex() = doTest("StringTemplateComplex") - @Test - fun testStringTemplateComplexForUInjectionHost() = withForceUInjectionHostValue { - doTest("StringTemplateComplexForUInjectionHost") - } - @Test fun testQualifiedConstructorCall() = doTest("QualifiedConstructorCall") @Test fun testPropertyDelegate() = doTest("PropertyDelegate") @@ -100,13 +94,3 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @Test fun testConstructorDelegate() = doTest("ConstructorDelegate") } - -fun withForceUInjectionHostValue(call: () -> Unit) { - val prev = KotlinConverter.forceUInjectionHost - KotlinConverter.forceUInjectionHost = true - try { - call.invoke() - } finally { - KotlinConverter.forceUInjectionHost = prev - } -} \ No newline at end of file