From 54285d328f1aa46b376e10e6b77d304290ff8b08 Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Thu, 28 Nov 2019 12:49:05 +0300 Subject: [PATCH] Uast: `KotlinIDERenderLogTest` for running UAST tests with ULC In case of result difference the `-ide`-suffixed testdata is used. Actually the difference in results is more likely to be a bug but currently we are fixating at least some behaviour to protect from unexpected regressions in Ultra Light Classes. `object Local` were removed because there is no local objects in actual Kotlin syntax --- .../uast/kotlin/KotlinAbstractUElement.kt | 8 +- .../uast/kotlin/KotlinUastLanguagePlugin.kt | 10 +- .../testData/Anonymous.log-ide.txt | 59 +++++++ .../testData/ConstructorDelegate.log-ide.txt | 49 ++++++ .../ConstructorDelegate.render-ide.txt | 26 +++ .../testData/Constructors.log-ide.txt | 161 +++++++++++++++++ .../testData/Constructors.render-ide.txt | 81 +++++++++ .../DestructuringDeclaration.log-ide.txt | 49 ++++++ .../DestructuringDeclaration.render-ide.txt | 10 ++ .../testData/EnumValueMembers.log-ide.txt | 19 ++ .../testData/EnumValueMembers.render-ide.txt | 12 ++ .../testData/LambdaReturn.log-ide.txt | 140 +++++++++++++++ .../testData/LambdaReturn.render-ide.txt | 44 +++++ .../testData/LocalDeclarations.altlog.txt | 2 - .../LocalDeclarations.identifiers.txt | 1 - .../uast-kotlin/testData/LocalDeclarations.kt | 2 - .../testData/LocalDeclarations.log-ide.txt | 38 ++++ .../testData/LocalDeclarations.log.txt | 5 - .../testData/LocalDeclarations.render-ide.txt | 17 ++ .../testData/LocalDeclarations.render.txt | 4 - .../testData/LocalDeclarations.types.txt | 5 - .../testData/LocalDeclarations.values.txt | 5 - ...arameterPropertyWithAnnotation.log-ide.txt | 31 ++++ ...meterPropertyWithAnnotation.render-ide.txt | 30 ++++ .../testData/ParametersDisorder.kt | 2 +- .../testData/ParametersDisorder.log-ide.txt | 163 ++++++++++++++++++ .../testData/ParametersDisorder.render.txt | 3 +- .../testData/PropertyInitializer.log-ide.txt | 14 ++ .../PropertyInitializer.render-ide.txt | 9 + ...opertyInitializerWithoutSetter.log-ide.txt | 12 ++ ...rtyInitializerWithoutSetter.render-ide.txt | 7 + .../PropertyWithAnnotation.log-ide.txt | 25 +++ .../PropertyWithAnnotation.render-ide.txt | 18 ++ .../testData/SimpleScript.log-ide.txt | 52 ++++++ .../testData/SimpleScript.render-ide.txt | 26 +++ .../testData/SuperCalls.identifiers.txt | 2 - plugins/uast-kotlin/testData/SuperCalls.kt | 4 +- .../testData/SuperCalls.log-ide.txt | 100 +++++++++++ .../uast-kotlin/testData/SuperCalls.log.txt | 9 - .../testData/SuperCalls.refNames.txt | 1 - .../testData/SuperCalls.render.txt | 4 +- .../uast-kotlin/testData/Suspend.log-ide.txt | 30 ++++ .../testData/Suspend.render-ide.txt | 17 ++ .../UnexpectedContainerException.log-ide.txt | 40 +++++ .../testData/WhenAndDestructing.log-ide.txt | 45 +++++ .../WhenAndDestructing.render-ide.txt | 21 +++ .../tests/AbstractKotlinIdentifiersTest.kt | 2 +- .../tests/AbstractKotlinRenderLogTest.kt | 5 +- .../AbstractKotlinResolveEverythingTest.kt | 2 +- ...ctKotlinUastLightCodeInsightFixtureTest.kt | 45 +++++ .../tests/AbstractKotlinUastTest.kt | 27 +-- .../tests/AbstractKotlinValuesTest.kt | 2 +- .../tests/AlternativesRenderLogTest.kt | 2 +- .../tests/KotlinIDERenderLogTest.kt | 158 +++++++++++++++++ .../uast-kotlin/tests/KotlinUastApiTest.kt | 2 - .../tests/MultiplesRequiredTypesTest.kt | 2 +- .../tests/SimpleKotlinRenderLogTest.kt | 21 ++- 57 files changed, 1602 insertions(+), 78 deletions(-) create mode 100644 plugins/uast-kotlin/testData/Anonymous.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/ConstructorDelegate.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/ConstructorDelegate.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/Constructors.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/Constructors.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/DestructuringDeclaration.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/DestructuringDeclaration.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/EnumValueMembers.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/EnumValueMembers.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/LambdaReturn.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/LambdaReturn.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/LocalDeclarations.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/LocalDeclarations.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/ParametersDisorder.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/PropertyInitializer.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/PropertyInitializer.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/PropertyWithAnnotation.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/PropertyWithAnnotation.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/SimpleScript.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/SimpleScript.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/SuperCalls.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/Suspend.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/Suspend.render-ide.txt create mode 100644 plugins/uast-kotlin/testData/UnexpectedContainerException.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/WhenAndDestructing.log-ide.txt create mode 100644 plugins/uast-kotlin/testData/WhenAndDestructing.render-ide.txt create mode 100644 plugins/uast-kotlin/tests/AbstractKotlinUastLightCodeInsightFixtureTest.kt create mode 100644 plugins/uast-kotlin/tests/KotlinIDERenderLogTest.kt 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 e60fb51dcc9..5f03a513dc4 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt @@ -19,7 +19,7 @@ package org.jetbrains.uast.kotlin import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod import org.jetbrains.kotlin.asJava.LightClassUtil -import org.jetbrains.kotlin.asJava.classes.KtLightClassForLocalDeclaration +import org.jetbrains.kotlin.asJava.elements.KtLightElement import org.jetbrains.kotlin.asJava.elements.KtLightMethod import org.jetbrains.kotlin.asJava.toLightGetter import org.jetbrains.kotlin.asJava.toLightSetter @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.isPropertyParameter import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf +import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.jetbrains.uast.* import org.jetbrains.uast.kotlin.expressions.KotlinLocalFunctionULambdaExpression import org.jetbrains.uast.kotlin.expressions.KotlinUElvisExpression @@ -61,9 +62,10 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : Kotl } - if (psi is KtLightClassForLocalDeclaration) { - val originParent = psi.kotlinOrigin.parent + if (psi is KtLightElement<*, *> && sourcePsi.safeAs()?.isLocal == true) { + val originParent = psi.kotlinOrigin?.parent parent = when (originParent) { + null -> parent is KtClassBody -> originParent.parent else -> originParent } 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 81ac5beb144..96f3dba346c 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt @@ -21,6 +21,7 @@ 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.PsiEnumConstant import com.intellij.psi.PsiFile import com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.annotations.TestOnly @@ -450,7 +451,7 @@ internal object KotlinConverter { private fun convertEnumEntry(original: KtEnumEntry, givenParent: UElement?): UElement? { return LightClassUtil.getLightClassBackingField(original)?.let { psiField -> - if (psiField is KtLightFieldImpl.KtLightEnumConstant) { + if (psiField is KtLightField && psiField is PsiEnumConstant) { KotlinUEnumConstant(psiField, psiField.kotlinOrigin, givenParent) } else { null @@ -489,8 +490,11 @@ internal object KotlinConverter { } else -> el { KotlinUClass.create(original, givenParent) } } - is KtLightFieldImpl.KtLightEnumConstant -> el(buildKtOpt(original.kotlinOrigin, ::KotlinUEnumConstant)) - is KtLightField -> el(buildKtOpt(original.kotlinOrigin, ::KotlinUField)) + is KtLightField -> + if (original is PsiEnumConstant) + el(buildKtOpt(original.kotlinOrigin, ::KotlinUEnumConstant)) + else + el(buildKtOpt(original.kotlinOrigin, ::KotlinUField)) is KtLightParameter -> el(buildKtOpt(original.kotlinOrigin, ::KotlinUParameter)) is UastKotlinPsiParameter -> el(buildKt(original.ktParameter, ::KotlinUParameter)) is UastKotlinPsiVariable -> el(buildKt(original.ktElement, ::KotlinUVariable)) diff --git a/plugins/uast-kotlin/testData/Anonymous.log-ide.txt b/plugins/uast-kotlin/testData/Anonymous.log-ide.txt new file mode 100644 index 00000000000..7ce1b45a9d3 --- /dev/null +++ b/plugins/uast-kotlin/testData/Anonymous.log-ide.txt @@ -0,0 +1,59 @@ +UFile (package = ) + UImportStatement (isOnDemand = false) + UImportStatement (isOnDemand = false) + UClass (name = AnonymousKt) + UMethod (name = foo) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = runnable) + UObjectLiteralExpression + UClass (name = null) + UMethod (name = run) + UBlockExpression + UMethod (name = ) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = runnable) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (run)) + USimpleNameReferenceExpression (identifier = run, resolvesTo = null) + UDeclarationsExpression + ULocalVariable (name = runnable2) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (Runnable)) + USimpleNameReferenceExpression (identifier = Runnable, resolvesTo = Runnable) + ULambdaExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = runnable2) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (run)) + USimpleNameReferenceExpression (identifier = run, resolvesTo = null) + UDeclarationsExpression + ULocalVariable (name = closeableRunnable) + UObjectLiteralExpression + UClass (name = null) + UMethod (name = close) + UBlockExpression + UMethod (name = run) + UBlockExpression + UMethod (name = ) + UDeclarationsExpression + ULocalVariable (name = runnableIs) + UObjectLiteralExpression + UClass (name = null) + UMethod (name = read) + UBlockExpression + UReturnExpression + ULiteralExpression (value = 0) + UMethod (name = run) + UBlockExpression + UMethod (name = ) + UMethod (name = withErr) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = runnable) + UObjectLiteralExpression + UClass (name = ) diff --git a/plugins/uast-kotlin/testData/ConstructorDelegate.log-ide.txt b/plugins/uast-kotlin/testData/ConstructorDelegate.log-ide.txt new file mode 100644 index 00000000000..2d91310ba21 --- /dev/null +++ b/plugins/uast-kotlin/testData/ConstructorDelegate.log-ide.txt @@ -0,0 +1,49 @@ +UFile (package = ) + UClass (name = ConstructorDelegateKt) + UMethod (name = createBase) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (BaseImpl)) + USimpleNameReferenceExpression (identifier = , resolvesTo = BaseImpl) + USimpleNameReferenceExpression (identifier = i) + UClass (name = Base) + UMethod (name = print) + UClass (name = BaseImpl) + UField (name = x) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = print) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (print)) + USimpleNameReferenceExpression (identifier = print, resolvesTo = null) + USimpleNameReferenceExpression (identifier = x) + UMethod (name = getX) + UMethod (name = BaseImpl) + UParameter (name = x) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UClass (name = Derived) + UExpressionList (super_delegation) + UTypeReferenceExpression (name = Base) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (createBase)) + USimpleNameReferenceExpression (identifier = createBase, resolvesTo = null) + ULiteralExpression (value = 10) + UExpressionList (super_delegation) + UTypeReferenceExpression (name = java.lang.CharSequence) + ULiteralExpression (value = "abc") + UMethod (name = Derived) + UParameter (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = print) + UMethod (name = getLength) + UMethod (name = get) + UParameter (name = index) + UAnnotation (fqName = null) + UMethod (name = subSequence) + UParameter (name = startIndex) + UAnnotation (fqName = null) + UParameter (name = endIndex) + UAnnotation (fqName = null) diff --git a/plugins/uast-kotlin/testData/ConstructorDelegate.render-ide.txt b/plugins/uast-kotlin/testData/ConstructorDelegate.render-ide.txt new file mode 100644 index 00000000000..345e16e2fc1 --- /dev/null +++ b/plugins/uast-kotlin/testData/ConstructorDelegate.render-ide.txt @@ -0,0 +1,26 @@ +public final class ConstructorDelegateKt { + public static final fun createBase(@org.jetbrains.annotations.NotNull i: int) : Base { + return (i) + } +} + +public abstract interface Base { + public abstract fun print() : void = UastEmptyExpression +} + +public final class BaseImpl : Base { + @org.jetbrains.annotations.NotNull private final var x: int + public fun print() : void { + print(x) + } + public final fun getX() : int = UastEmptyExpression + public fun BaseImpl(@org.jetbrains.annotations.NotNull x: int) = UastEmptyExpression +} + +public final class Derived : Base, java.lang.CharSequence { + public fun Derived(@org.jetbrains.annotations.NotNull b: Base) = UastEmptyExpression + public fun print() : void = UastEmptyExpression + public fun getLength() : int = UastEmptyExpression + public fun get(@null index: int) : char = UastEmptyExpression + public fun subSequence(@null startIndex: int, @null endIndex: int) : java.lang.CharSequence = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/Constructors.log-ide.txt b/plugins/uast-kotlin/testData/Constructors.log-ide.txt new file mode 100644 index 00000000000..fb2909007fb --- /dev/null +++ b/plugins/uast-kotlin/testData/Constructors.log-ide.txt @@ -0,0 +1,161 @@ +UFile (package = ) + UClass (name = A) + UField (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = getStr) + UMethod (name = A) + UParameter (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = A) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (this)) + USimpleNameReferenceExpression (identifier = , resolvesTo = A) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = i) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString, resolvesTo = null) + UClass (name = AWithInit) + UField (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = getStr) + UMethod (name = AWithInit) + UParameter (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + UMethod (name = AWithInit) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (this)) + USimpleNameReferenceExpression (identifier = , resolvesTo = AWithInit) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = i) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString, resolvesTo = null) + UClass (name = AWith2Init) + UField (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = getStr) + UMethod (name = AWith2Init) + UParameter (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + ULiteralExpression (value = 1) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + ULiteralExpression (value = 2) + UMethod (name = AWith2Init) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (this)) + USimpleNameReferenceExpression (identifier = , resolvesTo = AWith2Init) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = i) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString, resolvesTo = null) + UClass (name = AOnlyInit) + UMethod (name = AOnlyInit) + UBlockExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + ULiteralExpression (value = 1) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + ULiteralExpression (value = 2) + UClass (name = AWithSecondary) + UField (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = getA) + UMethod (name = setA) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = AWithSecondary) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier ()) + USimpleNameReferenceExpression (identifier = , resolvesTo = Object) + UBinaryExpression (operator = =) + USimpleNameReferenceExpression (identifier = a) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = i) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString, resolvesTo = null) + UMethod (name = AWithSecondary) + UParameter (name = s) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier ()) + USimpleNameReferenceExpression (identifier = , resolvesTo = Object) + UBinaryExpression (operator = =) + USimpleNameReferenceExpression (identifier = a) + USimpleNameReferenceExpression (identifier = s) + UClass (name = AWithSecondaryInit) + UField (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = getA) + UMethod (name = setA) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = AWithSecondaryInit) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier ()) + USimpleNameReferenceExpression (identifier = , resolvesTo = Object) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + UBinaryExpression (operator = =) + USimpleNameReferenceExpression (identifier = a) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = i) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString, resolvesTo = null) + UMethod (name = AWithSecondaryInit) + UParameter (name = s) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier ()) + USimpleNameReferenceExpression (identifier = , resolvesTo = Object) + UBinaryExpression (operator = =) + USimpleNameReferenceExpression (identifier = a) + USimpleNameReferenceExpression (identifier = s) + UDeclarationsExpression + ULocalVariable (name = local) + USimpleNameReferenceExpression (identifier = s) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = local) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString, resolvesTo = null) \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/Constructors.render-ide.txt b/plugins/uast-kotlin/testData/Constructors.render-ide.txt new file mode 100644 index 00000000000..62bb3df0075 --- /dev/null +++ b/plugins/uast-kotlin/testData/Constructors.render-ide.txt @@ -0,0 +1,81 @@ +public final class A { + @org.jetbrains.annotations.NotNull private final var str: java.lang.String + public final fun getStr() : java.lang.String = UastEmptyExpression + public fun A(@org.jetbrains.annotations.NotNull str: java.lang.String) = UastEmptyExpression + public fun A(@org.jetbrains.annotations.NotNull i: int) { + (i.toString()) + } +} + +public final class AWithInit { + @org.jetbrains.annotations.NotNull private final var str: java.lang.String + public final fun getStr() : java.lang.String = UastEmptyExpression + public fun AWithInit(@org.jetbrains.annotations.NotNull str: java.lang.String) { + { + println() + } + } + public fun AWithInit(@org.jetbrains.annotations.NotNull i: int) { + (i.toString()) + } +} + +public final class AWith2Init { + @org.jetbrains.annotations.NotNull private final var str: java.lang.String + public final fun getStr() : java.lang.String = UastEmptyExpression + public fun AWith2Init(@org.jetbrains.annotations.NotNull str: java.lang.String) { + { + println(1) + } + { + println(2) + } + } + public fun AWith2Init(@org.jetbrains.annotations.NotNull i: int) { + (i.toString()) + } +} + +public final class AOnlyInit { + public fun AOnlyInit() { + { + println(1) + } + { + println(2) + } + } +} + +public final class AWithSecondary { + @org.jetbrains.annotations.NotNull public var a: java.lang.String + public final fun getA() : java.lang.String = UastEmptyExpression + public final fun setA(@org.jetbrains.annotations.NotNull a: java.lang.String) : void = UastEmptyExpression + public fun AWithSecondary(@org.jetbrains.annotations.NotNull i: int) { + () + a = i.toString() + } + public fun AWithSecondary(@org.jetbrains.annotations.NotNull s: java.lang.String) { + () + a = s + } +} + +public final class AWithSecondaryInit { + @org.jetbrains.annotations.NotNull public var a: java.lang.String + public final fun getA() : java.lang.String = UastEmptyExpression + public final fun setA(@org.jetbrains.annotations.NotNull a: java.lang.String) : void = UastEmptyExpression + public fun AWithSecondaryInit(@org.jetbrains.annotations.NotNull i: int) { + () + { + println() + } + a = i.toString() + } + public fun AWithSecondaryInit(@org.jetbrains.annotations.NotNull s: java.lang.String) { + () + a = s + var local: java.lang.String = s + local.toString() + } +} diff --git a/plugins/uast-kotlin/testData/DestructuringDeclaration.log-ide.txt b/plugins/uast-kotlin/testData/DestructuringDeclaration.log-ide.txt new file mode 100644 index 00000000000..77771a8dd73 --- /dev/null +++ b/plugins/uast-kotlin/testData/DestructuringDeclaration.log-ide.txt @@ -0,0 +1,49 @@ +UFile (package = ) + UClass (name = DestructuringDeclarationKt) + UMethod (name = foo) + UParameter (name = data) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = var268d41a5) + UAnnotation (fqName = null) + UBinaryExpression (operator = ) + ULiteralExpression (value = "foo") + ULiteralExpression (value = 1) + ULocalVariable (name = a) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var268d41a5) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component1)) + USimpleNameReferenceExpression (identifier = , resolvesTo = null) + ULocalVariable (name = b) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var268d41a5) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component2)) + USimpleNameReferenceExpression (identifier = , resolvesTo = null) + UDeclarationsExpression + ULocalVariable (name = var465978a0) + UAnnotation (fqName = null) + UAnnotation (fqName = kotlin.Suppress) + UNamedExpression (name = names) + ULiteralExpression (value = "UNCHECKED_CAST") + UBinaryExpressionWithType + USimpleNameReferenceExpression (identifier = data) + UTypeReferenceExpression (name = kotlin.Pair) + ULocalVariable (name = k) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var465978a0) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component1)) + USimpleNameReferenceExpression (identifier = , resolvesTo = null) + ULocalVariable (name = v) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var465978a0) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component2)) + USimpleNameReferenceExpression (identifier = , resolvesTo = null) diff --git a/plugins/uast-kotlin/testData/DestructuringDeclaration.render-ide.txt b/plugins/uast-kotlin/testData/DestructuringDeclaration.render-ide.txt new file mode 100644 index 00000000000..03647158190 --- /dev/null +++ b/plugins/uast-kotlin/testData/DestructuringDeclaration.render-ide.txt @@ -0,0 +1,10 @@ +public final class DestructuringDeclarationKt { + public static final fun foo(@org.jetbrains.annotations.NotNull data: java.lang.Object) : void { + @null var var268d41a5: = "foo" 1 + @null var a: java.lang.String = var268d41a5.() + @null var b: int = var268d41a5.() + @null @kotlin.Suppress(names = "UNCHECKED_CAST") var var465978a0: = data as kotlin.Pair + @null var k: java.lang.String = var465978a0.() + @null var v: java.lang.String = var465978a0.() + } +} diff --git a/plugins/uast-kotlin/testData/EnumValueMembers.log-ide.txt b/plugins/uast-kotlin/testData/EnumValueMembers.log-ide.txt new file mode 100644 index 00000000000..bd07a46ab5d --- /dev/null +++ b/plugins/uast-kotlin/testData/EnumValueMembers.log-ide.txt @@ -0,0 +1,19 @@ +UFile (package = ) + UClass (name = Style) + UField (name = value) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UEnumConstant (name = SHEET) + UAnnotation (fqName = null) + USimpleNameReferenceExpression (identifier = Style) + ULiteralExpression (value = "foo") + UClass (name = SHEET) + UMethod (name = getExitAnimation) + UBlockExpression + UReturnExpression + ULiteralExpression (value = "bar") + UMethod (name = SHEET) + UMethod (name = getExitAnimation) + UMethod (name = getValue) + UMethod (name = Style) + UParameter (name = value) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) diff --git a/plugins/uast-kotlin/testData/EnumValueMembers.render-ide.txt b/plugins/uast-kotlin/testData/EnumValueMembers.render-ide.txt new file mode 100644 index 00000000000..0b9be77a0f3 --- /dev/null +++ b/plugins/uast-kotlin/testData/EnumValueMembers.render-ide.txt @@ -0,0 +1,12 @@ +public enum Style { + @org.jetbrains.annotations.NotNull private final var value: java.lang.String + @null SHEET("foo") { + public fun getExitAnimation() : java.lang.String { + return "bar" + } + fun SHEET() = UastEmptyExpression + } + public abstract fun getExitAnimation() : java.lang.String = UastEmptyExpression + public final fun getValue() : java.lang.String = UastEmptyExpression + private fun Style(@org.jetbrains.annotations.NotNull value: java.lang.String) = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/LambdaReturn.log-ide.txt b/plugins/uast-kotlin/testData/LambdaReturn.log-ide.txt new file mode 100644 index 00000000000..4feec660772 --- /dev/null +++ b/plugins/uast-kotlin/testData/LambdaReturn.log-ide.txt @@ -0,0 +1,140 @@ +UFile (package = org.jetbrains.uast.kotlin) + UClass (name = LambdaReturnKt) + UMethod (name = foo) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = lam1) + ULambdaExpression + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = b) + ULiteralExpression (value = 1) + UReturnExpression + UBinaryExpression (operator = +) + USimpleNameReferenceExpression (identifier = a) + USimpleNameReferenceExpression (identifier = b) + UDeclarationsExpression + ULocalVariable (name = lam2) + ULambdaExpression + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = c) + ULiteralExpression (value = 1) + UReturnExpression + UIfExpression + UBinaryExpression (operator = >) + USimpleNameReferenceExpression (identifier = a) + ULiteralExpression (value = 0) + UBinaryExpression (operator = +) + USimpleNameReferenceExpression (identifier = a) + USimpleNameReferenceExpression (identifier = c) + UBinaryExpression (operator = -) + USimpleNameReferenceExpression (identifier = a) + USimpleNameReferenceExpression (identifier = c) + UDeclarationsExpression + ULocalVariable (name = lam3) + ULabeledExpression (label = lbd) + ULambdaExpression + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = d) + ULiteralExpression (value = 1) + UReturnExpression + UBinaryExpression (operator = +) + USimpleNameReferenceExpression (identifier = a) + USimpleNameReferenceExpression (identifier = d) + UDeclarationsExpression + ULocalVariable (name = lam4) + ULambdaExpression + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UIfExpression + UBinaryExpression (operator = <) + USimpleNameReferenceExpression (identifier = a) + ULiteralExpression (value = 5) + UReturnExpression + ULiteralExpression (value = "5") + UIfExpression + UBinaryExpression (operator = >) + USimpleNameReferenceExpression (identifier = a) + ULiteralExpression (value = 0) + UReturnExpression + ULiteralExpression (value = "1") + UReturnExpression + ULiteralExpression (value = "2") + UDeclarationsExpression + ULocalVariable (name = lam5) + ULambdaExpression + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + UBinaryExpression (operator = +) + ULiteralExpression (value = "a") + USimpleNameReferenceExpression (identifier = a) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (bar)) + USimpleNameReferenceExpression (identifier = bar, resolvesTo = null) + ULambdaExpression + UBlockExpression + UIfExpression + UBinaryExpression (operator = >) + USimpleNameReferenceExpression (identifier = it) + ULiteralExpression (value = 5) + UReturnExpression + UDeclarationsExpression + ULocalVariable (name = b) + ULiteralExpression (value = 1) + UReturnExpression + UBinaryExpression (operator = +) + USimpleNameReferenceExpression (identifier = it) + USimpleNameReferenceExpression (identifier = b) + UDeclarationsExpression + ULocalVariable (name = x) + ULambdaExpression + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = vardbcd0724) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (listOf)) + USimpleNameReferenceExpression (identifier = listOf, resolvesTo = null) + ULiteralExpression (value = 1) + ULiteralExpression (value = 2) + ULocalVariable (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = vardbcd0724) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component1)) + USimpleNameReferenceExpression (identifier = , resolvesTo = null) + ULocalVariable (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = vardbcd0724) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component2)) + USimpleNameReferenceExpression (identifier = , resolvesTo = null) + UDeclarationsExpression + ULocalVariable (name = y) + ULambdaExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (listOf)) + USimpleNameReferenceExpression (identifier = listOf, resolvesTo = null) + ULiteralExpression (value = 1) + UMethod (name = bar) + UParameter (name = lmbd) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (lmbd)) + USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null) + ULiteralExpression (value = 1) diff --git a/plugins/uast-kotlin/testData/LambdaReturn.render-ide.txt b/plugins/uast-kotlin/testData/LambdaReturn.render-ide.txt new file mode 100644 index 00000000000..6c03aa8df48 --- /dev/null +++ b/plugins/uast-kotlin/testData/LambdaReturn.render-ide.txt @@ -0,0 +1,44 @@ +package org.jetbrains.uast.kotlin + +public final class LambdaReturnKt { + public static final fun foo() : void { + var lam1: kotlin.jvm.functions.Function1 = { @org.jetbrains.annotations.NotNull var a: int -> + + var b: int = 1 + return a + b + } + var lam2: kotlin.jvm.functions.Function1 = { @org.jetbrains.annotations.NotNull var a: int -> + + var c: int = 1 + return if (a > 0) a + c else a - c + } + var lam3: kotlin.jvm.functions.Function1 = lbd@ { @org.jetbrains.annotations.NotNull var a: int -> + + var d: int = 1 + return a + d + } + var lam4: kotlin.jvm.functions.Function1 = fun (@org.jetbrains.annotations.NotNull var a: int) { + if (a < 5) return "5" + if (a > 0) return "1" else return "2" + } + var lam5: kotlin.jvm.functions.Function1 = fun (@org.jetbrains.annotations.NotNull var a: int) { + return "a" + a + } + bar({ + if (it > 5) return + var b: int = 1 + return it + b + }) + var x: kotlin.jvm.functions.Function0 = { + @org.jetbrains.annotations.NotNull var vardbcd0724: = listOf(1, 2) + @org.jetbrains.annotations.NotNull var a: int = vardbcd0724.() + @org.jetbrains.annotations.NotNull var b: int = vardbcd0724.() + } + var y: kotlin.jvm.functions.Function0 = { + listOf(1) + } + } + private static final fun bar(@org.jetbrains.annotations.NotNull lmbd: kotlin.jvm.functions.Function1) : void { + invoke(1) + } +} diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt b/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt index 8795145472e..4e49963457a 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt @@ -33,8 +33,6 @@ [1]:[USimpleNameReferenceExpression (identifier = String)] [1]:[UIdentifier (Identifier (String))] [1]:[ULiteralExpression (value = 42)] - [1]:[UClass (name = LocalObject)] - [1]:[UIdentifier (Identifier (LocalObject))] [1]:[UReturnExpression] [1]:[UBinaryExpression (operator = ==)] [1]:[UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))] diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.identifiers.txt b/plugins/uast-kotlin/testData/LocalDeclarations.identifiers.txt index e7659615439..225753ccb59 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.identifiers.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.identifiers.txt @@ -9,7 +9,6 @@ Boolean -> USimpleNameReferenceExpression (identifier = Boolean) someLocalFun -> ULambdaExpression text -> [!] UnknownKotlinExpression (VALUE_PARAMETER) String -> USimpleNameReferenceExpression (identifier = String) - LocalObject -> UClass (name = LocalObject) bar -> UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) == -> USimpleNameReferenceExpression (identifier = ==) Local -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.kt b/plugins/uast-kotlin/testData/LocalDeclarations.kt index 26a267e7d8d..ff45265e296 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.kt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.kt @@ -8,7 +8,5 @@ fun foo(): Boolean { fun Int.someLocalFun(text: String) = 42 - object LocalObject - return bar() == Local() } \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.log-ide.txt b/plugins/uast-kotlin/testData/LocalDeclarations.log-ide.txt new file mode 100644 index 00000000000..090b85d49d6 --- /dev/null +++ b/plugins/uast-kotlin/testData/LocalDeclarations.log-ide.txt @@ -0,0 +1,38 @@ +UFile (package = ) + UClass (name = LocalDeclarationsKt) + UMethod (name = foo) + UBlockExpression + UDeclarationsExpression + UClass (name = Local) + UMethod (name = Local) + UDeclarationsExpression + UVariable (name = bar) + ULambdaExpression + UBlockExpression + UReturnExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (Local)) + USimpleNameReferenceExpression (identifier = , resolvesTo = Local) + UDeclarationsExpression + ULocalVariable (name = baz) + ULambdaExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (Local)) + USimpleNameReferenceExpression (identifier = , resolvesTo = Local) + UDeclarationsExpression + UVariable (name = someLocalFun) + ULambdaExpression + UParameter (name = text) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + ULiteralExpression (value = 42) + UReturnExpression + UBinaryExpression (operator = ==) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (bar)) + USimpleNameReferenceExpression (identifier = bar, resolvesTo = null) + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (Local)) + USimpleNameReferenceExpression (identifier = , resolvesTo = Local) \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.log.txt b/plugins/uast-kotlin/testData/LocalDeclarations.log.txt index 631ce793b8a..04a28d2ea30 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.log.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.log.txt @@ -28,11 +28,6 @@ UFile (package = ) UBlockExpression UReturnExpression ULiteralExpression (value = 42) - UDeclarationsExpression - UClass (name = LocalObject) - UField (name = INSTANCE) - UAnnotation (fqName = null) - UMethod (name = LocalDeclarationsKt$foo$LocalObject) UReturnExpression UBinaryExpression (operator = ==) UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.render-ide.txt b/plugins/uast-kotlin/testData/LocalDeclarations.render-ide.txt new file mode 100644 index 00000000000..d3d9c9d6c92 --- /dev/null +++ b/plugins/uast-kotlin/testData/LocalDeclarations.render-ide.txt @@ -0,0 +1,17 @@ +public final class LocalDeclarationsKt { + public static final fun foo() : boolean { + public static final class Local { + public fun Local() = UastEmptyExpression + } + var bar: = fun () { + return () + } + var baz: kotlin.jvm.functions.Function0 = fun () { + () + } + var someLocalFun: kotlin.jvm.functions.Function2 = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) { + return 42 + } + return bar() == () + } +} diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.render.txt b/plugins/uast-kotlin/testData/LocalDeclarations.render.txt index 0805df0ce43..87f9fa57e78 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.render.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.render.txt @@ -12,10 +12,6 @@ public final class LocalDeclarationsKt { var someLocalFun: kotlin.jvm.functions.Function2 = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) { return 42 } - public static final class LocalObject { - @null public static final var INSTANCE: LocalDeclarationsKt.foo.LocalObject - private fun LocalDeclarationsKt$foo$LocalObject() = UastEmptyExpression - } return bar() == () } } diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.types.txt b/plugins/uast-kotlin/testData/LocalDeclarations.types.txt index dbe1b3a2584..878f06ea5f5 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.types.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.types.txt @@ -28,11 +28,6 @@ UFile (package = ) [public final class LocalDeclarationsKt {...] UBlockExpression [{...}] UReturnExpression [return 42] ULiteralExpression (value = 42) [42] : PsiType:int - UDeclarationsExpression [public static final class LocalObject {...}] - UClass (name = LocalObject) [public static final class LocalObject {...}] - UField (name = INSTANCE) [@null public static final var INSTANCE: LocalDeclarationsKt.foo.LocalObject] - UAnnotation (fqName = null) [@null] - UMethod (name = LocalDeclarationsKt$foo$LocalObject) [private fun LocalDeclarationsKt$foo$LocalObject() = UastEmptyExpression] UReturnExpression [return bar() == ()] : PsiType:Void UBinaryExpression (operator = ==) [bar() == ()] : PsiType:boolean UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [bar()] : PsiType: diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.values.txt b/plugins/uast-kotlin/testData/LocalDeclarations.values.txt index eae5032907f..791501900cd 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.values.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.values.txt @@ -28,11 +28,6 @@ UFile (package = ) [public final class LocalDeclarationsKt {...] UBlockExpression [{...}] = Nothing UReturnExpression [return 42] = Undetermined ULiteralExpression (value = 42) [42] = 42 - UDeclarationsExpression [public static final class LocalObject {...}] = Undetermined - UClass (name = LocalObject) [public static final class LocalObject {...}] - UField (name = INSTANCE) [@null public static final var INSTANCE: LocalDeclarationsKt.foo.LocalObject] - UAnnotation (fqName = null) [@null] - UMethod (name = LocalDeclarationsKt$foo$LocalObject) [private fun LocalDeclarationsKt$foo$LocalObject() = UastEmptyExpression] UReturnExpression [return bar() == ()] = Nothing UBinaryExpression (operator = ==) [bar() == ()] = Undetermined UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [bar()] = external bar()() diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log-ide.txt b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log-ide.txt new file mode 100644 index 00000000000..648242ea2da --- /dev/null +++ b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log-ide.txt @@ -0,0 +1,31 @@ +UFile (package = ) + UClass (name = MyAnnotation) + UClass (name = MyAnnotation2) + UClass (name = MyAnnotation3) + UClass (name = MyAnnotation4) + UClass (name = MyAnnotation5) + UClass (name = Test1) + UField (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = getBar) + UMethod (name = setBar) + UParameter (name = bar) + UAnnotation (fqName = null) + UMethod (name = Test1) + UParameter (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UAnnotation (fqName = MyAnnotation) + UClass (name = Test2) + UField (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UAnnotation (fqName = MyAnnotation5) + UMethod (name = getBar) + UAnnotation (fqName = MyAnnotation) + UMethod (name = setBar) + UAnnotation (fqName = MyAnnotation2) + UParameter (name = bar) + UAnnotation (fqName = MyAnnotation3) + UAnnotation (fqName = null) + UMethod (name = Test2) + UParameter (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render-ide.txt b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render-ide.txt new file mode 100644 index 00000000000..b87a33358c6 --- /dev/null +++ b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render-ide.txt @@ -0,0 +1,30 @@ +public abstract annotation MyAnnotation { +} + +public abstract annotation MyAnnotation2 { +} + +public abstract annotation MyAnnotation3 { +} + +public abstract annotation MyAnnotation4 { +} + +public abstract annotation MyAnnotation5 { +} + +public final class Test1 { + @org.jetbrains.annotations.NotNull private var bar: int + public final fun getBar() : int = UastEmptyExpression + public final fun setBar(@null bar: int) : void = UastEmptyExpression + public fun Test1(@org.jetbrains.annotations.NotNull @MyAnnotation bar: int) = UastEmptyExpression +} + +public final class Test2 { + @org.jetbrains.annotations.NotNull @MyAnnotation5 private var bar: int + @MyAnnotation + public final fun getBar() : int = UastEmptyExpression + @MyAnnotation2 + public final fun setBar(@MyAnnotation3 @null bar: int) : void = UastEmptyExpression + public fun Test2(@org.jetbrains.annotations.NotNull bar: int) = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/ParametersDisorder.kt b/plugins/uast-kotlin/testData/ParametersDisorder.kt index c6a067ac19a..157a78223f5 100644 --- a/plugins/uast-kotlin/testData/ParametersDisorder.kt +++ b/plugins/uast-kotlin/testData/ParametersDisorder.kt @@ -31,5 +31,5 @@ open class Parent(a: String, b: Int) fun objectLiteral() { - object : Parent(b = 1, a = "foo") + object : Parent(b = 1, a = "foo") { } } \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/ParametersDisorder.log-ide.txt b/plugins/uast-kotlin/testData/ParametersDisorder.log-ide.txt new file mode 100644 index 00000000000..41b9a91c725 --- /dev/null +++ b/plugins/uast-kotlin/testData/ParametersDisorder.log-ide.txt @@ -0,0 +1,163 @@ +UFile (package = ) + UClass (name = ParametersDisorderKt) + UMethod (name = global) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UMethod (name = withDefault) + UParameter (name = c) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = 1) + UParameter (name = d) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = "aaa") + UBlockExpression + UMethod (name = withReceiver) + UParameter (name = $this$withReceiver) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UMethod (name = call) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (global)) + USimpleNameReferenceExpression (identifier = global, resolvesTo = null) + ULiteralExpression (value = 2.2) + ULiteralExpression (value = 2) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (withDefault)) + USimpleNameReferenceExpression (identifier = withDefault, resolvesTo = null) + ULiteralExpression (value = "bbb") + UQualifiedReferenceExpression + ULiteralExpression (value = "abc") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (withReceiver)) + USimpleNameReferenceExpression (identifier = withReceiver, resolvesTo = null) + ULiteralExpression (value = 1) + ULiteralExpression (value = 1.2) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = Math) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (atan2)) + USimpleNameReferenceExpression (identifier = atan2, resolvesTo = null) + ULiteralExpression (value = 1.3) + ULiteralExpression (value = 3.4) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (unresolvedMethod)) + USimpleNameReferenceExpression (identifier = , resolvesTo = null) + ULiteralExpression (value = "param1") + ULiteralExpression (value = "param2") + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = java) + USimpleNameReferenceExpression (identifier = lang) + USimpleNameReferenceExpression (identifier = String) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 4)) + UIdentifier (Identifier (format)) + USimpleNameReferenceExpression (identifier = format, resolvesTo = null) + ULiteralExpression (value = "%i %i %i") + ULiteralExpression (value = 1) + ULiteralExpression (value = 2) + ULiteralExpression (value = 3) + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = java) + USimpleNameReferenceExpression (identifier = lang) + USimpleNameReferenceExpression (identifier = String) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (format)) + USimpleNameReferenceExpression (identifier = format, resolvesTo = null) + ULiteralExpression (value = "%i %i %i") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 3)) + UIdentifier (Identifier (arrayOf)) + USimpleNameReferenceExpression (identifier = arrayOf, resolvesTo = null) + ULiteralExpression (value = 1) + ULiteralExpression (value = 2) + ULiteralExpression (value = 3) + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = java) + USimpleNameReferenceExpression (identifier = lang) + USimpleNameReferenceExpression (identifier = String) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 3)) + UIdentifier (Identifier (format)) + USimpleNameReferenceExpression (identifier = format, resolvesTo = null) + ULiteralExpression (value = "%i %i %i") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 3)) + UIdentifier (Identifier (arrayOf)) + USimpleNameReferenceExpression (identifier = arrayOf, resolvesTo = null) + ULiteralExpression (value = 1) + ULiteralExpression (value = 2) + ULiteralExpression (value = 3) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 3)) + UIdentifier (Identifier (arrayOf)) + USimpleNameReferenceExpression (identifier = arrayOf, resolvesTo = null) + ULiteralExpression (value = 4) + ULiteralExpression (value = 5) + ULiteralExpression (value = 6) + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = java) + USimpleNameReferenceExpression (identifier = lang) + USimpleNameReferenceExpression (identifier = String) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (format)) + USimpleNameReferenceExpression (identifier = format, resolvesTo = null) + ULiteralExpression (value = "%i %i %i") + UQualifiedReferenceExpression + UQualifiedReferenceExpression + ULiteralExpression (value = "") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (chunked)) + USimpleNameReferenceExpression (identifier = chunked, resolvesTo = null) + ULiteralExpression (value = 2) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toTypedArray)) + USimpleNameReferenceExpression (identifier = toTypedArray, resolvesTo = null) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (with)) + USimpleNameReferenceExpression (identifier = with, resolvesTo = null) + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = , resolvesTo = A) + ULambdaExpression + UBlockExpression + UQualifiedReferenceExpression + ULiteralExpression (value = "def") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (with2Receivers)) + USimpleNameReferenceExpression (identifier = with2Receivers, resolvesTo = null) + ULiteralExpression (value = 8) + ULiteralExpression (value = 7.0) + UMethod (name = objectLiteral) + UBlockExpression + UObjectLiteralExpression + ULiteralExpression (value = 1) + ULiteralExpression (value = "foo") + UClass (name = null) + UMethod (name = ) + UClass (name = A) + UMethod (name = with2Receivers) + UParameter (name = $this$with2Receivers) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UMethod (name = A) + UClass (name = Parent) + UMethod (name = Parent) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) diff --git a/plugins/uast-kotlin/testData/ParametersDisorder.render.txt b/plugins/uast-kotlin/testData/ParametersDisorder.render.txt index d8f87681ae9..dde115c8dec 100644 --- a/plugins/uast-kotlin/testData/ParametersDisorder.render.txt +++ b/plugins/uast-kotlin/testData/ParametersDisorder.render.txt @@ -20,8 +20,7 @@ public final class ParametersDisorderKt { }) } public static final fun objectLiteral() : void { - anonymous object : Parent(b = 1, a = "foo") - + anonymous object : Parent(b = 1, a = "foo") { } } } diff --git a/plugins/uast-kotlin/testData/PropertyInitializer.log-ide.txt b/plugins/uast-kotlin/testData/PropertyInitializer.log-ide.txt new file mode 100644 index 00000000000..cea445422b1 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializer.log-ide.txt @@ -0,0 +1,14 @@ +UFile (package = ) + UClass (name = TestPropertyInitializer) + UMethod (name = getWithSetter) + UBlockExpression + UReturnExpression + USimpleNameReferenceExpression (identifier = field) + UMethod (name = setWithSetter) + UParameter (name = p) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UBinaryExpression (operator = =) + USimpleNameReferenceExpression (identifier = field) + USimpleNameReferenceExpression (identifier = p) + UMethod (name = TestPropertyInitializer) diff --git a/plugins/uast-kotlin/testData/PropertyInitializer.render-ide.txt b/plugins/uast-kotlin/testData/PropertyInitializer.render-ide.txt new file mode 100644 index 00000000000..e30a2a39770 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializer.render-ide.txt @@ -0,0 +1,9 @@ +public final class TestPropertyInitializer { + public final fun getWithSetter() : java.lang.String { + return field + } + public final fun setWithSetter(@org.jetbrains.annotations.NotNull p: java.lang.String) : void { + field = p + } + public fun TestPropertyInitializer() = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log-ide.txt b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log-ide.txt new file mode 100644 index 00000000000..7eaac7d90ec --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log-ide.txt @@ -0,0 +1,12 @@ +UFile (package = ) + UClass (name = PropertyInitializerWithoutSetterKt) + UField (name = withoutSetter) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = "/sdcard") + UMethod (name = getWithoutSetter) + UBlockExpression + UReturnExpression + USimpleNameReferenceExpression (identifier = field) + UMethod (name = setWithoutSetter) + UParameter (name = withoutSetter) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.render-ide.txt b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.render-ide.txt new file mode 100644 index 00000000000..5cf1fa4a062 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.render-ide.txt @@ -0,0 +1,7 @@ +public final class PropertyInitializerWithoutSetterKt { + @org.jetbrains.annotations.NotNull private static var withoutSetter: java.lang.String = "/sdcard" + public static final fun getWithoutSetter() : java.lang.String { + return field + } + public static final fun setWithoutSetter(@org.jetbrains.annotations.NotNull withoutSetter: java.lang.String) : void = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/PropertyWithAnnotation.log-ide.txt b/plugins/uast-kotlin/testData/PropertyWithAnnotation.log-ide.txt new file mode 100644 index 00000000000..edd43f0c533 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyWithAnnotation.log-ide.txt @@ -0,0 +1,25 @@ +UFile (package = ) + UClass (name = PropertyWithAnnotationKt) + UField (name = prop1) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UAnnotation (fqName = TestAnnotation) + ULiteralExpression (value = 0) + UMethod (name = getProp1) + UMethod (name = getProp2) + UAnnotation (fqName = TestAnnotation) + UBlockExpression + UReturnExpression + ULiteralExpression (value = 0) + UMethod (name = getProp3) + UBlockExpression + UReturnExpression + ULiteralExpression (value = 0) + UMethod (name = setProp3) + UAnnotation (fqName = TestAnnotation) + UParameter (name = value) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UBinaryExpression (operator = =) + USimpleNameReferenceExpression (identifier = field) + USimpleNameReferenceExpression (identifier = value) + UClass (name = TestAnnotation) diff --git a/plugins/uast-kotlin/testData/PropertyWithAnnotation.render-ide.txt b/plugins/uast-kotlin/testData/PropertyWithAnnotation.render-ide.txt new file mode 100644 index 00000000000..6aa6bd3cbb2 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyWithAnnotation.render-ide.txt @@ -0,0 +1,18 @@ +public final class PropertyWithAnnotationKt { + @org.jetbrains.annotations.NotNull @TestAnnotation private static final var prop1: int = 0 + public static final fun getProp1() : int = UastEmptyExpression + @TestAnnotation + public static final fun getProp2() : int { + return 0 + } + public static final fun getProp3() : int { + return 0 + } + @TestAnnotation + public static final fun setProp3(@org.jetbrains.annotations.NotNull value: int) : void { + field = value + } +} + +public abstract annotation TestAnnotation { +} diff --git a/plugins/uast-kotlin/testData/SimpleScript.log-ide.txt b/plugins/uast-kotlin/testData/SimpleScript.log-ide.txt new file mode 100644 index 00000000000..bda60ca5df6 --- /dev/null +++ b/plugins/uast-kotlin/testData/SimpleScript.log-ide.txt @@ -0,0 +1,52 @@ +UFile (package = ) + UClass (name = SimpleScript) + UMethod (name = getBarOrNull) + UParameter (name = flag) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + UIfExpression + USimpleNameReferenceExpression (identifier = flag) + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (Bar)) + USimpleNameReferenceExpression (identifier = , resolvesTo = Bar) + ULiteralExpression (value = 42) + ULiteralExpression (value = null) + UMethod (name = main) + UParameter (name = strings) + UAnnotation (fqName = null) + UMethod (name = SimpleScript) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + ULiteralExpression (value = "Hello World!") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (getBarOrNull)) + USimpleNameReferenceExpression (identifier = getBarOrNull, resolvesTo = null) + ULiteralExpression (value = true) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + ULiteralExpression (value = "Goodbye World!") + UClass (name = Bar) + UField (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = 0) + UField (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = getB) + UMethod (name = getAPlusB) + UBlockExpression + UReturnExpression + UBinaryExpression (operator = +) + USimpleNameReferenceExpression (identifier = a) + USimpleNameReferenceExpression (identifier = b) + UMethod (name = getA) + UMethod (name = Bar) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UClass (name = Baz) + UMethod (name = doSomething) + UBlockExpression + UMethod (name = Baz) diff --git a/plugins/uast-kotlin/testData/SimpleScript.render-ide.txt b/plugins/uast-kotlin/testData/SimpleScript.render-ide.txt new file mode 100644 index 00000000000..69a53c8143e --- /dev/null +++ b/plugins/uast-kotlin/testData/SimpleScript.render-ide.txt @@ -0,0 +1,26 @@ +public class SimpleScript { + public final fun getBarOrNull(@org.jetbrains.annotations.NotNull flag: boolean) : SimpleScript.Bar { + return if (flag) (42) else null + } + public static final fun main(@null strings: java.lang.String[]) : void = UastEmptyExpression + public fun SimpleScript() { + println("Hello World!") + getBarOrNull(true) + println("Goodbye World!") + } + public static final class Bar { + @org.jetbrains.annotations.NotNull private final var b: int = 0 + @org.jetbrains.annotations.NotNull private final var a: int + public final fun getB() : int = UastEmptyExpression + public final fun getAPlusB() : int { + return a + b + } + public final fun getA() : int = UastEmptyExpression + public fun Bar(@org.jetbrains.annotations.NotNull a: int) = UastEmptyExpression + public static final class Baz { + public final fun doSomething() : void { + } + public fun Baz() = UastEmptyExpression + } + } +} diff --git a/plugins/uast-kotlin/testData/SuperCalls.identifiers.txt b/plugins/uast-kotlin/testData/SuperCalls.identifiers.txt index 475efe8c383..6a41fa53569 100644 --- a/plugins/uast-kotlin/testData/SuperCalls.identifiers.txt +++ b/plugins/uast-kotlin/testData/SuperCalls.identifiers.txt @@ -43,8 +43,6 @@ bar -> UMethod (name = bar) cons -> UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) object -> UClass (name = null) A -> UObjectLiteralExpression -innerObject -> UClass (name = innerObject) -A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) InnerClass -> UClass (name = InnerClass) A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) cons -> UMethod (name = cons) diff --git a/plugins/uast-kotlin/testData/SuperCalls.kt b/plugins/uast-kotlin/testData/SuperCalls.kt index 7ec534caf35..764bbaf009b 100644 --- a/plugins/uast-kotlin/testData/SuperCalls.kt +++ b/plugins/uast-kotlin/testData/SuperCalls.kt @@ -24,11 +24,9 @@ object O : A("text") val anon = object : A("textForAnon") { fun bar() { - cons(object : A("inner literal")) + cons(object : A("inner literal") { }) } - object innerObject : A("inner object") - inner class InnerClass : A("inner class") } diff --git a/plugins/uast-kotlin/testData/SuperCalls.log-ide.txt b/plugins/uast-kotlin/testData/SuperCalls.log-ide.txt new file mode 100644 index 00000000000..e55664a2f9a --- /dev/null +++ b/plugins/uast-kotlin/testData/SuperCalls.log-ide.txt @@ -0,0 +1,100 @@ +UFile (package = ) + UClass (name = SuperCallsKt) + UField (name = anon) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UObjectLiteralExpression + ULiteralExpression (value = "textForAnon") + UClass (name = null) + UMethod (name = bar) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (cons)) + USimpleNameReferenceExpression (identifier = cons, resolvesTo = null) + UObjectLiteralExpression + ULiteralExpression (value = "inner literal") + UClass (name = null) + UMethod (name = ) + UMethod (name = ) + UClass (name = InnerClass) + UMethod (name = InnerClass) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = , resolvesTo = A) + ULiteralExpression (value = "inner class") + UMethod (name = getAnon) + UMethod (name = cons) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UClass (name = A) + UField (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = foo) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UMethod (name = getStr) + UMethod (name = A) + UParameter (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UMethod (name = A) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (this)) + USimpleNameReferenceExpression (identifier = , resolvesTo = A) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = i) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString, resolvesTo = null) + UClass (name = B) + UMethod (name = B) + UParameter (name = param) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = , resolvesTo = A) + USimpleNameReferenceExpression (identifier = param) + UClass (name = C) + UMethod (name = foo) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UQualifiedReferenceExpression + USuperExpression (label = null) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (foo)) + USimpleNameReferenceExpression (identifier = foo, resolvesTo = null) + USimpleNameReferenceExpression (identifier = a) + UMethod (name = C) + UParameter (name = p) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (super)) + USimpleNameReferenceExpression (identifier = , resolvesTo = A) + USimpleNameReferenceExpression (identifier = p) + UMethod (name = C) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (super)) + USimpleNameReferenceExpression (identifier = , resolvesTo = A) + USimpleNameReferenceExpression (identifier = i) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println, resolvesTo = null) + UClass (name = O) + UField (name = INSTANCE) + UAnnotation (fqName = null) + UMethod (name = O) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = , resolvesTo = A) + ULiteralExpression (value = "text") diff --git a/plugins/uast-kotlin/testData/SuperCalls.log.txt b/plugins/uast-kotlin/testData/SuperCalls.log.txt index 4a9f10afe0c..5cdd4558f78 100644 --- a/plugins/uast-kotlin/testData/SuperCalls.log.txt +++ b/plugins/uast-kotlin/testData/SuperCalls.log.txt @@ -15,15 +15,6 @@ UFile (package = ) UClass (name = null) UMethod (name = SuperCallsKt$anon$1$bar$1) UMethod (name = SuperCallsKt$anon$1) - UClass (name = innerObject) - UField (name = INSTANCE) - UAnnotation (fqName = org.jetbrains.annotations.NotNull) - UMethod (name = innerObject) - UBlockExpression - UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) - UIdentifier (Identifier (A)) - USimpleNameReferenceExpression (identifier = , resolvesTo = A) - ULiteralExpression (value = "inner object") UClass (name = InnerClass) UMethod (name = InnerClass) UBlockExpression diff --git a/plugins/uast-kotlin/testData/SuperCalls.refNames.txt b/plugins/uast-kotlin/testData/SuperCalls.refNames.txt index 6b91e0eaf63..e7d112f48e0 100644 --- a/plugins/uast-kotlin/testData/SuperCalls.refNames.txt +++ b/plugins/uast-kotlin/testData/SuperCalls.refNames.txt @@ -24,5 +24,4 @@ cons -> UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) A -> USimpleNameReferenceExpression (identifier = A) from KtObjectLiteralExpression A -> UObjectLiteralExpression from KtNameReferenceExpression A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) from KtNameReferenceExpression -A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) from KtNameReferenceExpression A -> USimpleNameReferenceExpression (identifier = A) from KtNameReferenceExpression diff --git a/plugins/uast-kotlin/testData/SuperCalls.render.txt b/plugins/uast-kotlin/testData/SuperCalls.render.txt index 874e70453b2..3cadc676fd8 100644 --- a/plugins/uast-kotlin/testData/SuperCalls.render.txt +++ b/plugins/uast-kotlin/testData/SuperCalls.render.txt @@ -1,11 +1,9 @@ public final class SuperCallsKt { @org.jetbrains.annotations.NotNull private static final var anon: A = anonymous object : A("textForAnon") { fun bar() { - cons(object : A("inner literal")) + cons(object : A("inner literal") { }) } - object innerObject : A("inner object") - inner class InnerClass : A("inner class") } public static final fun getAnon() : A = UastEmptyExpression diff --git a/plugins/uast-kotlin/testData/Suspend.log-ide.txt b/plugins/uast-kotlin/testData/Suspend.log-ide.txt new file mode 100644 index 00000000000..7efb0bebd40 --- /dev/null +++ b/plugins/uast-kotlin/testData/Suspend.log-ide.txt @@ -0,0 +1,30 @@ +UFile (package = test.pkg) + UClass (name = SuspendKt) + UMethod (name = top) + UParameter (name = $completion) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + UQualifiedReferenceExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (Context)) + USimpleNameReferenceExpression (identifier = , resolvesTo = Context) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (inner)) + USimpleNameReferenceExpression (identifier = inner, resolvesTo = null) + UClass (name = Context) + UMethod (name = inner) + UParameter (name = $completion) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (suspendPrivate)) + USimpleNameReferenceExpression (identifier = suspendPrivate, resolvesTo = null) + UMethod (name = Context) + UMethod (name = suspendPrivate) + UBlockExpression + UReturnExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (inner)) + USimpleNameReferenceExpression (identifier = inner, resolvesTo = null) \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/Suspend.render-ide.txt b/plugins/uast-kotlin/testData/Suspend.render-ide.txt new file mode 100644 index 00000000000..6c4d4265fb0 --- /dev/null +++ b/plugins/uast-kotlin/testData/Suspend.render-ide.txt @@ -0,0 +1,17 @@ +package test.pkg + +public final class SuspendKt { + public static final fun top(@org.jetbrains.annotations.NotNull $completion: kotlin.coroutines.Continuation) : java.lang.Object { + return ().inner() + } +} + +public final class Context { + public final fun inner(@org.jetbrains.annotations.NotNull $completion: kotlin.coroutines.Continuation) : java.lang.Object { + return suspendPrivate() + } + public fun Context() = UastEmptyExpression + fun suspendPrivate() : int { + return inner() + } +} diff --git a/plugins/uast-kotlin/testData/UnexpectedContainerException.log-ide.txt b/plugins/uast-kotlin/testData/UnexpectedContainerException.log-ide.txt new file mode 100644 index 00000000000..29df09cd201 --- /dev/null +++ b/plugins/uast-kotlin/testData/UnexpectedContainerException.log-ide.txt @@ -0,0 +1,40 @@ +UFile (package = ) + UClass (name = Callback) + UMethod (name = onError) + UParameter (name = throwable) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UClass (name = Model) + UMethod (name = crashMe) + UParameter (name = clazz) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = factory) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UThrowExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (UnsupportedOperationException)) + USimpleNameReferenceExpression (identifier = , resolvesTo = UnsupportedOperationException) + UMethod (name = Model) + UBlockExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (crashMe)) + USimpleNameReferenceExpression (identifier = crashMe, resolvesTo = null) + UQualifiedReferenceExpression + UClassLiteralExpression + USimpleNameReferenceExpression (identifier = java) + ULambdaExpression + UBlockExpression + UReturnExpression + UObjectLiteralExpression + UClass (name = null) + UMethod (name = onError) + UParameter (name = throwable) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UThrowExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (UnsupportedOperationException)) + USimpleNameReferenceExpression (identifier = , resolvesTo = UnsupportedOperationException) + ULiteralExpression (value = "") + UMethod (name = ) diff --git a/plugins/uast-kotlin/testData/WhenAndDestructing.log-ide.txt b/plugins/uast-kotlin/testData/WhenAndDestructing.log-ide.txt new file mode 100644 index 00000000000..061131ed262 --- /dev/null +++ b/plugins/uast-kotlin/testData/WhenAndDestructing.log-ide.txt @@ -0,0 +1,45 @@ +UFile (package = ) + UClass (name = WhenAndDestructingKt) + UMethod (name = getElementsAdditionalResolve) + UParameter (name = string) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = arr) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (listOf)) + USimpleNameReferenceExpression (identifier = listOf, resolvesTo = null) + ULiteralExpression (value = "1") + ULiteralExpression (value = "2") + USwitchExpression + USimpleNameReferenceExpression (identifier = string) + UExpressionList (when) + USwitchClauseExpressionWithBody + ULiteralExpression (value = "aaaa") + UExpressionList (when_entry) + UReturnExpression + ULiteralExpression (value = "bindingContext") + UBreakExpression (label = null) + USwitchClauseExpressionWithBody + UExpressionList (when_entry) + UDeclarationsExpression + ULocalVariable (name = var837f1e82) + UAnnotation (fqName = null) + USimpleNameReferenceExpression (identifier = arr) + ULocalVariable (name = bindingContext) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var837f1e82) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component1)) + USimpleNameReferenceExpression (identifier = , resolvesTo = null) + ULocalVariable (name = statementFilter) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var837f1e82) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component2)) + USimpleNameReferenceExpression (identifier = , resolvesTo = null) + UReturnExpression + USimpleNameReferenceExpression (identifier = bindingContext) + UBreakExpression (label = null) diff --git a/plugins/uast-kotlin/testData/WhenAndDestructing.render-ide.txt b/plugins/uast-kotlin/testData/WhenAndDestructing.render-ide.txt new file mode 100644 index 00000000000..f3e37e879f8 --- /dev/null +++ b/plugins/uast-kotlin/testData/WhenAndDestructing.render-ide.txt @@ -0,0 +1,21 @@ +public final class WhenAndDestructingKt { + public static final fun getElementsAdditionalResolve(@org.jetbrains.annotations.NotNull string: java.lang.String) : java.lang.String { + var arr: java.util.List = listOf("1", "2") + switch (string) { + "aaaa" -> { + return "bindingContext" + break + } + + -> { + @null var var837f1e82: = arr + @null var bindingContext: java.lang.String = var837f1e82.() + @null var statementFilter: java.lang.String = var837f1e82.() + return bindingContext + break + } + + } + + } +} diff --git a/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt index 7ad8eaf5956..dddfe20241f 100644 --- a/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt +++ b/plugins/uast-kotlin/tests/AbstractKotlinIdentifiersTest.kt @@ -13,7 +13,7 @@ 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) + File(File(TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) override fun getIdentifiersFile(testName: String): File = getTestFile(testName, "identifiers.txt") diff --git a/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt index 7a6834b31cb..59fe076da5e 100644 --- a/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt @@ -8,6 +8,7 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.util.PairProcessor import com.intellij.util.ref.DebugReflectionUtil import junit.framework.TestCase +import junit.framework.TestCase.* import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.psi.KtElement @@ -26,9 +27,9 @@ import org.junit.Assert import java.io.File import java.util.* -abstract class AbstractKotlinRenderLogTest : AbstractKotlinUastTest(), RenderLogTestBase { +interface AbstractKotlinRenderLogTest : RenderLogTestBase { override fun getTestFile(testName: String, ext: String) = - File(File(TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) + File(File(TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) override fun check(testName: String, file: UFile) { check(testName, file, true) diff --git a/plugins/uast-kotlin/tests/AbstractKotlinResolveEverythingTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinResolveEverythingTest.kt index 55431abed95..42cb7740d79 100644 --- a/plugins/uast-kotlin/tests/AbstractKotlinResolveEverythingTest.kt +++ b/plugins/uast-kotlin/tests/AbstractKotlinResolveEverythingTest.kt @@ -19,7 +19,7 @@ import java.io.File abstract class AbstractKotlinResolveEverythingTest : AbstractKotlinUastTest() { private fun getTestFile(testName: String, ext: String) = - File(File(AbstractKotlinUastTest.TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) + File(File(TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) private fun UFile.resolvableWithTargets() = object : IndentedPrintingVisitor(KtBlockExpression::class) { diff --git a/plugins/uast-kotlin/tests/AbstractKotlinUastLightCodeInsightFixtureTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinUastLightCodeInsightFixtureTest.kt new file mode 100644 index 00000000000..d209116a5fd --- /dev/null +++ b/plugins/uast-kotlin/tests/AbstractKotlinUastLightCodeInsightFixtureTest.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.uast.test.kotlin + +import com.intellij.openapi.util.registry.Registry +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.openapi.vfs.VirtualFileManager +import com.intellij.testFramework.LightProjectDescriptor +import com.intellij.util.io.URLUtil +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor +import org.jetbrains.uast.UFile +import org.jetbrains.uast.UastFacade +import java.io.File + +abstract class AbstractKotlinUastLightCodeInsightFixtureTest : KotlinLightCodeInsightFixtureTestCase() { + + override fun getProjectDescriptor(): LightProjectDescriptor = + KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_FULL_JDK + + override fun setUp() { + super.setUp() + Registry.get("kotlin.uast.multiresolve.enabled").setValue(true, testRootDisposable) + } + + fun getVirtualFile(testName: String): VirtualFile { + val testFile = TEST_KOTLIN_MODEL_DIR.listFiles { pathname -> pathname.nameWithoutExtension == testName }.first() + val vfs = VirtualFileManager.getInstance().getFileSystem(URLUtil.FILE_PROTOCOL) + return vfs.findFileByPath(testFile.canonicalPath)!! + } + + abstract fun check(testName: String, file: UFile) + + fun doTest(testName: String, checkCallback: (String, UFile) -> Unit = { testName, file -> check(testName, file) }) { + val virtualFile = getVirtualFile(testName) + + val psiFile = myFixture.configureByText(virtualFile.name, File(virtualFile.canonicalPath!!).readText()) + val uFile = UastFacade.convertElementWithParent(psiFile, null) ?: error("Can't get UFile for $testName") + checkCallback(testName, uFile as UFile) + } + +} \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/AbstractKotlinUastTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinUastTest.kt index b39549f1f47..1519e51062e 100644 --- a/plugins/uast-kotlin/tests/AbstractKotlinUastTest.kt +++ b/plugins/uast-kotlin/tests/AbstractKotlinUastTest.kt @@ -38,9 +38,6 @@ import org.jetbrains.uast.test.env.kotlin.AbstractUastTest import java.io.File abstract class AbstractKotlinUastTest : AbstractUastTest() { - protected companion object { - val TEST_KOTLIN_MODEL_DIR = File("plugins/uast-kotlin/testData") - } private lateinit var compilerConfiguration: CompilerConfiguration private var kotlinCoreEnvironment: KotlinCoreEnvironment? = null @@ -58,7 +55,7 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() { val environment = kotlinCoreEnvironment!! TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( - project, environment.getSourceFiles(), trace, compilerConfiguration, environment::createPackagePartProvider + project, environment.getSourceFiles(), trace, compilerConfiguration, environment::createPackagePartProvider ) val vfs = VirtualFileManager.getInstance().getFileSystem(URLUtil.FILE_PROTOCOL) @@ -94,13 +91,14 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() { private fun initializeKotlinEnvironment() { val area = Extensions.getRootArea() area.getExtensionPoint(UastLanguagePlugin.extensionPointName) - .registerExtension(KotlinUastLanguagePlugin()) + .registerExtension(KotlinUastLanguagePlugin()) area.getExtensionPoint(UEvaluatorExtension.EXTENSION_POINT_NAME) - .registerExtension(KotlinEvaluatorExtension()) + .registerExtension(KotlinEvaluatorExtension()) project.registerService( KotlinUastResolveProviderService::class.java, - CliKotlinUastResolveProviderService::class.java) + CliKotlinUastResolveProviderService::class.java + ) } override fun createEnvironment(source: File): AbstractCoreEnvironment { @@ -115,7 +113,8 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() { this.kotlinCoreEnvironment = kotlinCoreEnvironment AnalysisHandlerExtension.registerExtension( - kotlinCoreEnvironment.project, UastAnalysisHandlerExtension()) + kotlinCoreEnvironment.project, UastAnalysisHandlerExtension() + ) return KotlinCoreEnvironmentWrapper(kotlinCoreEnvironment, parentDisposable, appWasNull) } @@ -140,9 +139,11 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() { } } - private class KotlinCoreEnvironmentWrapper(val environment: KotlinCoreEnvironment, - val parentDisposable: Disposable, - val appWasNull: Boolean) : AbstractCoreEnvironment() { + private class KotlinCoreEnvironmentWrapper( + val environment: KotlinCoreEnvironment, + val parentDisposable: Disposable, + val appWasNull: Boolean + ) : AbstractCoreEnvironment() { override fun addJavaSourceRoot(root: File) { TODO("not implemented") } @@ -161,4 +162,6 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() { } } } -} \ No newline at end of file +} + +val TEST_KOTLIN_MODEL_DIR = File("plugins/uast-kotlin/testData") \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/AbstractKotlinValuesTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinValuesTest.kt index bf84a1080bb..77aaef7a319 100644 --- a/plugins/uast-kotlin/tests/AbstractKotlinValuesTest.kt +++ b/plugins/uast-kotlin/tests/AbstractKotlinValuesTest.kt @@ -6,7 +6,7 @@ import java.io.File abstract class AbstractKotlinValuesTest : AbstractKotlinUastTest(), ValuesTestBase { private fun getTestFile(testName: String, ext: String) = - File(File(AbstractKotlinUastTest.TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) + File(File(TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) override fun getValuesFile(testName: String) = getTestFile(testName, "values.txt") } \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt b/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt index 6fef659492d..bd6d033aba8 100644 --- a/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt @@ -54,6 +54,6 @@ class AlternativesRenderLogTest : AbstractKotlinUastTest() { } private fun getTestFile(testName: String, ext: String) = - File(File(AbstractKotlinUastTest.TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) + File(File(TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) } diff --git a/plugins/uast-kotlin/tests/KotlinIDERenderLogTest.kt b/plugins/uast-kotlin/tests/KotlinIDERenderLogTest.kt new file mode 100644 index 00000000000..72c85ce4c4b --- /dev/null +++ b/plugins/uast-kotlin/tests/KotlinIDERenderLogTest.kt @@ -0,0 +1,158 @@ +package org.jetbrains.uast.test.kotlin + +import org.jetbrains.uast.UFile +import org.junit.Ignore +import org.junit.Test +import java.io.File + +class KotlinIDERenderLogTest : AbstractKotlinUastLightCodeInsightFixtureTest(), AbstractKotlinRenderLogTest { + + override fun getTestFile(testName: String, ext: String): File { + if (ext.endsWith(".txt")) { + val testFile = super.getTestFile(testName, ext.removeSuffix(".txt") + "-ide.txt") + if (testFile.exists()) return testFile + } + return super.getTestFile(testName, ext) + } + + override fun check(testName: String, file: UFile) = super.check(testName, file) + + + @Test + fun testLocalDeclarations() = doTest("LocalDeclarations") + + @Test + fun testSimple() = doTest("Simple") + + @Test + fun testWhenIs() = doTest("WhenIs") + + @Test + fun testDefaultImpls() = doTest("DefaultImpls") + + @Test + fun testBitwise() = doTest("Bitwise") + + @Test + fun testElvis() = doTest("Elvis") + + @Test + fun testPropertyAccessors() = doTest("PropertyAccessors") + + @Test + fun testPropertyInitializer() = doTest("PropertyInitializer") + + @Test + fun testPropertyInitializerWithoutSetter() = doTest("PropertyInitializerWithoutSetter") + + @Test + fun testAnnotationParameters() = doTest("AnnotationParameters") + + @Test + fun testEnumValueMembers() = doTest("EnumValueMembers") + + @Test + fun testStringTemplate() = doTest("StringTemplate") + + @Test + fun testStringTemplateComplex() = doTest("StringTemplateComplex") + + @Test + fun testStringTemplateComplexForUInjectionHost() = withForceUInjectionHostValue { + doTest("StringTemplateComplexForUInjectionHost") + } + + @Test + fun testQualifiedConstructorCall() = doTest("QualifiedConstructorCall") + + @Test + fun testPropertyDelegate() = doTest("PropertyDelegate") + + @Test + fun testLocalVariableWithAnnotation() = doTest("LocalVariableWithAnnotation") + + @Test + fun testPropertyWithAnnotation() = doTest("PropertyWithAnnotation") + + @Test + fun testIfStatement() = doTest("IfStatement") + + @Test + fun testInnerClasses() = doTest("InnerClasses") + + @Test + @Ignore // there is a descriptor leak probably, unignore when fixed + fun ingoretestSimpleScript() = doTest("SimpleScript") { testName, file -> check(testName, file, false) } + + @Test + fun testDestructuringDeclaration() = doTest("DestructuringDeclaration") + + @Test + fun testDefaultParameterValues() = doTest("DefaultParameterValues") + + @Test + fun testParameterPropertyWithAnnotation() = doTest("ParameterPropertyWithAnnotation") + + @Test + fun testParametersWithDefaultValues() = doTest("ParametersWithDefaultValues") + + @Test + fun testUnexpectedContainer() = doTest("UnexpectedContainerException") + + @Test + fun testWhenStringLiteral() = doTest("WhenStringLiteral") + + @Test + fun testWhenAndDestructing() = doTest("WhenAndDestructing") { testName, file -> check(testName, file, false) } + + @Test + fun testSuperCalls() = doTest("SuperCalls") + + @Test + fun testConstructors() = doTest("Constructors") + + @Test + fun testClassAnnotation() = doTest("ClassAnnotation") + + @Test + fun testReceiverFun() = doTest("ReceiverFun") + + @Test + fun testAnonymous() = doTest("Anonymous") + + @Test + fun testAnnotationComplex() = doTest("AnnotationComplex") + + @Test + fun testParametersDisorder() = doTest("ParametersDisorder") { testName, file -> + // disabled due to inconsistent parents for 2-receivers call (KT-22344) + check(testName, file, false) + } + + @Test + fun testLambdas() = doTest("Lambdas") + + @Test + fun testTypeReferences() = doTest("TypeReferences") + + @Test + fun testDelegate() = doTest("Delegate") + + @Test + fun testConstructorDelegate() = doTest("ConstructorDelegate") { testName, file -> + // Igor Yakovlev told that delegation is a little bit broken in ULC and not expected to be fixed + check(testName, file, false) + } + + @Test + fun testLambdaReturn() = doTest("LambdaReturn") + + @Test + fun testReified() = doTest("Reified") + + @Test + fun testSuspend() = doTest("Suspend") + + @Test + fun testDeprecatedHidden() = doTest("DeprecatedHidden") +} diff --git a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt index cc38f027399..9bf59abc635 100644 --- a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt +++ b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt @@ -290,7 +290,6 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { doTest("SuperCalls") { _, file -> file.checkUastSuperTypes("B", listOf("A")) file.checkUastSuperTypes("O", listOf("A")) - file.checkUastSuperTypes("innerObject ", listOf("A")) file.checkUastSuperTypes("InnerClass", listOf("A")) file.checkUastSuperTypes("object : A(\"textForAnon\")", listOf("A")) } @@ -427,7 +426,6 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { ) assertArguments(listOf("\"%i %i %i\"", "\"\".chunked(2).toTypedArray()"), "format(\"%i %i %i\", *\"\".chunked(2).toTypedArray())") assertArguments(listOf("\"def\"", "8", "7.0"), "with2Receivers(8, 7.0F)") - assertArguments(listOf("\"foo\"", "1"), "object : Parent(b = 1, a = \"foo\")\n") } @Test diff --git a/plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt b/plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt index d4a0af59d24..45a9351ec7e 100644 --- a/plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt +++ b/plugins/uast-kotlin/tests/MultiplesRequiredTypesTest.kt @@ -48,6 +48,6 @@ class MultiplesRequiredTypesTest : AbstractKotlinUastTest() { } private fun getTestFile(testName: String, ext: String) = - File(File(AbstractKotlinUastTest.TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) + File(File(TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) } diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt index ed7443e3cac..d6140c554ba 100644 --- a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt @@ -1,18 +1,27 @@ package org.jetbrains.uast.test.kotlin +import org.jetbrains.uast.UFile import org.jetbrains.uast.kotlin.KotlinConverter import org.junit.Test -class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { - @Test fun testLocalDeclarations() = doTest("LocalDeclarations") +class SimpleKotlinRenderLogTest : AbstractKotlinUastTest(), AbstractKotlinRenderLogTest { - @Test fun testSimple() = doTest("Simple") + override fun check(testName: String, file: UFile) = super.check(testName, file) - @Test fun testWhenIs() = doTest("WhenIs") + @Test + fun testLocalDeclarations() = doTest("LocalDeclarations") - @Test fun testDefaultImpls() = doTest("DefaultImpls") + @Test + fun testSimple() = doTest("Simple") - @Test fun testBitwise() = doTest("Bitwise") + @Test + fun testWhenIs() = doTest("WhenIs") + + @Test + fun testDefaultImpls() = doTest("DefaultImpls") + + @Test + fun testBitwise() = doTest("Bitwise") @Test fun testElvis() = doTest("Elvis")