diff --git a/.idea/libraries/uast_java.xml b/.idea/libraries/uast_java.xml index 703d240e89c..177fec82f29 100644 --- a/.idea/libraries/uast_java.xml +++ b/.idea/libraries/uast_java.xml @@ -3,11 +3,13 @@ + + \ No newline at end of file diff --git a/idea/src/META-INF/android-lint.xml b/idea/src/META-INF/android-lint.xml index 4c41551d09a..3d760b9b393 100644 --- a/idea/src/META-INF/android-lint.xml +++ b/idea/src/META-INF/android-lint.xml @@ -124,8 +124,7 @@ + interface="org.jetbrains.uast.UastLanguagePlugin"/> 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 d97ea53a6ef..e3d77df8a45 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt @@ -17,8 +17,9 @@ package org.jetbrains.uast.kotlin import com.intellij.lang.Language -import com.intellij.openapi.project.Project -import com.intellij.psi.* +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.intellij.psi.PsiVariable import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.asJava.LightClassUtil @@ -48,10 +49,10 @@ interface KotlinUastBindingContextProviderService { fun getTypeMapper(element: KtElement): KotlinTypeMapper? } -class KotlinUastLanguagePlugin(override val project: Project) : UastLanguagePlugin { +class KotlinUastLanguagePlugin : UastLanguagePlugin { override val priority = 10 - private val javaPlugin by lz { UastLanguagePlugin.getInstances(project).first { it is JavaUastLanguagePlugin } } + private val javaPlugin by lz { UastLanguagePlugin.getInstances().first { it is JavaUastLanguagePlugin } } override val language: Language get() = KotlinLanguage.INSTANCE diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt index 38003243e55..d9eb8b7e62f 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt @@ -1,7 +1,7 @@ package org.jetbrains.uast.kotlin.evaluation import org.jetbrains.kotlin.idea.KotlinLanguage -import org.jetbrains.uast.UastBinaryOperator +import org.jetbrains.uast.UBinaryExpression import org.jetbrains.uast.UastPostfixOperator import org.jetbrains.uast.evaluation.UEvaluationInfo import org.jetbrains.uast.evaluation.UEvaluationState @@ -16,8 +16,8 @@ class KotlinEvaluatorExtension : UEvaluatorExtension { override fun toString() = "$from..$to" } - private class UClosedRangeConstant(override val value: Range) : UAbstractConstant() { - constructor(from: UValue, to: UValue): this(Range(from, to)) + private class UClosedRangeConstant(override val value: Range, override val source: UBinaryExpression?) : UAbstractConstant() { + constructor(from: UValue, to: UValue, source: UBinaryExpression): this(Range(from, to), source) } override val language: KotlinLanguage = KotlinLanguage.INSTANCE @@ -43,15 +43,15 @@ class KotlinEvaluatorExtension : UEvaluatorExtension { } override fun evaluateBinary( - operator: UastBinaryOperator, + binaryExpression: UBinaryExpression, leftValue: UValue, rightValue: UValue, state: UEvaluationState ): UEvaluationInfo { - return when (operator) { + return when (binaryExpression.operator) { KotlinBinaryOperators.IN -> rightValue.contains(leftValue) KotlinBinaryOperators.NOT_IN -> !rightValue.contains(leftValue) - KotlinBinaryOperators.RANGE_TO -> UClosedRangeConstant(leftValue, rightValue) + KotlinBinaryOperators.RANGE_TO -> UClosedRangeConstant(leftValue, rightValue, binaryExpression) else -> UUndeterminedValue } to state } diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUBinaryExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUBinaryExpression.kt deleted file mode 100644 index 841186f4455..00000000000 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUBinaryExpression.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.uast.kotlin - -import org.jetbrains.kotlin.psi.KtStringTemplateExpression -import org.jetbrains.uast.* -import org.jetbrains.uast.psi.PsiElementBacked - -class KotlinStringTemplateUBinaryExpression( - override val psi: KtStringTemplateExpression, - override val containingElement: UElement? -) : KotlinAbstractUExpression(), UBinaryExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { - override lateinit var leftOperand: UExpression - internal set - - override lateinit var rightOperand: UExpression - internal set - - override val operator = UastBinaryOperator.PLUS - - override val operatorIdentifier: UIdentifier? - get() = null - - override fun resolveOperator() = null -} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/AnnotationParameters.kt b/plugins/uast-kotlin/testData/AnnotationParameters.kt new file mode 100644 index 00000000000..1b9e57b5bbc --- /dev/null +++ b/plugins/uast-kotlin/testData/AnnotationParameters.kt @@ -0,0 +1,5 @@ + +annotation class IntRange(val from: Long, val to: Long) + +@IntRange(from = 10, to = 0) +fun foo(): Int = 5 \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/AnnotationParameters.log.txt b/plugins/uast-kotlin/testData/AnnotationParameters.log.txt new file mode 100644 index 00000000000..65b8f9cf997 --- /dev/null +++ b/plugins/uast-kotlin/testData/AnnotationParameters.log.txt @@ -0,0 +1,23 @@ +UFile (package = ) + UClass (name = AnnotationParametersKt) + UAnnotationMethod (name = foo) + UAnnotation (fqName = IntRange) + UNamedExpression (name = from) + ULiteralExpression (value = 10) + UNamedExpression (name = to) + ULiteralExpression (value = 0) + ULiteralExpression (value = 5) + UClass (name = IntRange) + UAnnotation (fqName = java.lang.annotation.Retention) + UNamedExpression (name = ) + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = java) + USimpleNameReferenceExpression (identifier = lang) + USimpleNameReferenceExpression (identifier = annotation) + USimpleNameReferenceExpression (identifier = RetentionPolicy) + USimpleNameReferenceExpression (identifier = RUNTIME) + UAnnotationMethod (name = from) + UAnnotationMethod (name = to) diff --git a/plugins/uast-kotlin/testData/AnnotationParameters.render.txt b/plugins/uast-kotlin/testData/AnnotationParameters.render.txt new file mode 100644 index 00000000000..4803ace7f95 --- /dev/null +++ b/plugins/uast-kotlin/testData/AnnotationParameters.render.txt @@ -0,0 +1,9 @@ +public final class AnnotationParametersKt { + @IntRange(from = 10, to = 0) + public static final fun foo() : int = 5 +} + +public abstract annotation IntRange { + public abstract fun from() : long = UastEmptyExpression + public abstract fun to() : long = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/Assertion.kt b/plugins/uast-kotlin/testData/Assertion.kt new file mode 100644 index 00000000000..245dda65115 --- /dev/null +++ b/plugins/uast-kotlin/testData/Assertion.kt @@ -0,0 +1,4 @@ +fun foo(): String { + val s: String? = "Not Null" + return s!! +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/Assertion.values.txt b/plugins/uast-kotlin/testData/Assertion.values.txt new file mode 100644 index 00000000000..d51e11b7116 --- /dev/null +++ b/plugins/uast-kotlin/testData/Assertion.values.txt @@ -0,0 +1,10 @@ +UFile (package = ) [public final class AssertionKt {...] + UClass (name = AssertionKt) [public final class AssertionKt {...}] + UAnnotationMethod (name = foo) [public static final fun foo() : java.lang.String {...}] + UBlockExpression [{...}] = Nothing + UDeclarationsExpression [var s: java.lang.String = "Not Null"] = Undetermined + ULocalVariable (name = s) [var s: java.lang.String = "Not Null"] + ULiteralExpression (value = "Not Null") ["Not Null"] = "Not Null" + UReturnExpression [return s!!] = Nothing + UPostfixExpression (operator = !!) [s!!] = (var s = "Not Null") + USimpleNameReferenceExpression (identifier = s) [s] = (var s = "Not Null") diff --git a/plugins/uast-kotlin/testData/DefaultImpls.kt b/plugins/uast-kotlin/testData/DefaultImpls.kt new file mode 100644 index 00000000000..836eeff2f8c --- /dev/null +++ b/plugins/uast-kotlin/testData/DefaultImpls.kt @@ -0,0 +1,6 @@ + +interface Foo { + fun bar() = "Hello!" +} + +class Baz : Foo \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/DefaultImpls.log.txt b/plugins/uast-kotlin/testData/DefaultImpls.log.txt new file mode 100644 index 00000000000..2392c297aab --- /dev/null +++ b/plugins/uast-kotlin/testData/DefaultImpls.log.txt @@ -0,0 +1,6 @@ +UFile (package = ) + UClass (name = Foo) + UAnnotationMethod (name = bar) + ULiteralExpression (value = "Hello!") + UClass (name = Baz) + UAnnotationMethod (name = Baz) diff --git a/plugins/uast-kotlin/testData/DefaultImpls.render.txt b/plugins/uast-kotlin/testData/DefaultImpls.render.txt new file mode 100644 index 00000000000..1e912f7b081 --- /dev/null +++ b/plugins/uast-kotlin/testData/DefaultImpls.render.txt @@ -0,0 +1,7 @@ +public abstract interface Foo { + public abstract fun bar() : java.lang.String = "Hello!" +} + +public final class Baz : Foo { + public fun Baz() = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/Elvis.kt b/plugins/uast-kotlin/testData/Elvis.kt new file mode 100644 index 00000000000..c2e32cefc8a --- /dev/null +++ b/plugins/uast-kotlin/testData/Elvis.kt @@ -0,0 +1,6 @@ + +fun foo(bar: String): Any? = null + +fun baz(): Any? { + return foo("Lorem ipsum") ?: foo("dolor sit amet") ?: foo("consectetuer adipiscing elit") +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/Elvis.log.txt b/plugins/uast-kotlin/testData/Elvis.log.txt new file mode 100644 index 00000000000..59e5fb4442e --- /dev/null +++ b/plugins/uast-kotlin/testData/Elvis.log.txt @@ -0,0 +1,37 @@ +UFile (package = ) + UClass (name = ElvisKt) + UAnnotationMethod (name = foo) + UParameter (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = null) + UAnnotationMethod (name = baz) + UBlockExpression + UReturnExpression + UExpressionList (elvis) + UDeclarationsExpression + ULocalVariable (name = var243c4e1a) + UExpressionList (elvis) + UDeclarationsExpression + ULocalVariable (name = varc4aef1e3) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (foo)) + USimpleNameReferenceExpression (identifier = foo) + ULiteralExpression (value = "Lorem ipsum") + UIfExpression + UBinaryExpression (operator = !=) + USimpleNameReferenceExpression (identifier = varc4aef1e3) + ULiteralExpression (value = null) + USimpleNameReferenceExpression (identifier = varc4aef1e3) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (foo)) + USimpleNameReferenceExpression (identifier = foo) + ULiteralExpression (value = "dolor sit amet") + UIfExpression + UBinaryExpression (operator = !=) + USimpleNameReferenceExpression (identifier = var243c4e1a) + ULiteralExpression (value = null) + USimpleNameReferenceExpression (identifier = var243c4e1a) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (foo)) + USimpleNameReferenceExpression (identifier = foo) + ULiteralExpression (value = "consectetuer adipiscing elit") diff --git a/plugins/uast-kotlin/testData/Elvis.render.txt b/plugins/uast-kotlin/testData/Elvis.render.txt new file mode 100644 index 00000000000..466d2c1385e --- /dev/null +++ b/plugins/uast-kotlin/testData/Elvis.render.txt @@ -0,0 +1,12 @@ +public final class ElvisKt { + public static final fun foo(bar: java.lang.String) : java.lang.Object = null + public static final fun baz() : java.lang.Object { + return elvis { + var var243c4e1a: = elvis { + var varc4aef1e3: = foo("Lorem ipsum") + if (varc4aef1e3 != null) varc4aef1e3 else foo("dolor sit amet") + } + if (var243c4e1a != null) var243c4e1a else foo("consectetuer adipiscing elit") + } + } +} diff --git a/plugins/uast-kotlin/testData/EnumValueMembers.kt b/plugins/uast-kotlin/testData/EnumValueMembers.kt new file mode 100644 index 00000000000..6611ec2e9fa --- /dev/null +++ b/plugins/uast-kotlin/testData/EnumValueMembers.kt @@ -0,0 +1,8 @@ +enum class Style(val value: String) { + SHEET("foo") { + override val exitAnimation: String + get() = "bar" + }; + + abstract val exitAnimation: String +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/EnumValueMembers.log.txt b/plugins/uast-kotlin/testData/EnumValueMembers.log.txt new file mode 100644 index 00000000000..ae7d9e2e759 --- /dev/null +++ b/plugins/uast-kotlin/testData/EnumValueMembers.log.txt @@ -0,0 +1,15 @@ +UFile (package = ) + UClass (name = Style) + UEnumConstant (name = SHEET) + USimpleNameReferenceExpression (identifier = Style) + UClass (name = null) + UAnnotationMethod (name = getExitAnimation) + ULiteralExpression (value = "bar") + UAnnotationMethod (name = SHEET) + UField (name = value) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UAnnotationMethod (name = getExitAnimation) + UAnnotationMethod (name = getValue) + UAnnotationMethod (name = Style) + UParameter (name = value) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) diff --git a/plugins/uast-kotlin/testData/EnumValueMembers.render.txt b/plugins/uast-kotlin/testData/EnumValueMembers.render.txt new file mode 100644 index 00000000000..a4325db460b --- /dev/null +++ b/plugins/uast-kotlin/testData/EnumValueMembers.render.txt @@ -0,0 +1,10 @@ +public enum Style { + SHEET { + public fun getExitAnimation() : java.lang.String = "bar" + fun SHEET() = UastEmptyExpression + } + private final var value: java.lang.String + public abstract fun getExitAnimation() : java.lang.String = UastEmptyExpression + public final fun getValue() : java.lang.String = UastEmptyExpression + protected fun Style(value: java.lang.String) = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/In.kt b/plugins/uast-kotlin/testData/In.kt new file mode 100644 index 00000000000..d7a5641b705 --- /dev/null +++ b/plugins/uast-kotlin/testData/In.kt @@ -0,0 +1,5 @@ +fun foo(): Boolean { + val x = 1 + val y = 10 + return x in 0..5 && y !in 4..9 +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/In.values.txt b/plugins/uast-kotlin/testData/In.values.txt new file mode 100644 index 00000000000..65f9a0a752a --- /dev/null +++ b/plugins/uast-kotlin/testData/In.values.txt @@ -0,0 +1,22 @@ +UFile (package = ) [public final class InKt {...] + UClass (name = InKt) [public final class InKt {...}] + UAnnotationMethod (name = foo) [public static final fun foo() : boolean {...}] + UBlockExpression [{...}] = Nothing + UDeclarationsExpression [var x: = 1] = Undetermined + ULocalVariable (name = x) [var x: = 1] + ULiteralExpression (value = 1) [1] = 1 + UDeclarationsExpression [var y: = 10] = Undetermined + ULocalVariable (name = y) [var y: = 10] + ULiteralExpression (value = 10) [10] = 10 + UReturnExpression [return x in 0 .. 5 && y !in 4 .. 9] = Nothing + UBinaryExpression (operator = &&) [x in 0 .. 5 && y !in 4 .. 9] = true (depending on: (var x = 1), (var y = 10)) + UBinaryExpression (operator = in) [x in 0 .. 5] = true (depending on: (var x = 1)) + USimpleNameReferenceExpression (identifier = x) [x] = (var x = 1) + UBinaryExpression (operator = ..) [0 .. 5] = 0..5 + ULiteralExpression (value = 0) [0] = 0 + ULiteralExpression (value = 5) [5] = 5 + UBinaryExpression (operator = !in) [y !in 4 .. 9] = true (depending on: (var y = 10)) + USimpleNameReferenceExpression (identifier = y) [y] = (var y = 10) + UBinaryExpression (operator = ..) [4 .. 9] = 4..9 + ULiteralExpression (value = 4) [4] = 4 + ULiteralExpression (value = 9) [9] = 9 diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.kt b/plugins/uast-kotlin/testData/LocalDeclarations.kt new file mode 100644 index 00000000000..8b4531f0209 --- /dev/null +++ b/plugins/uast-kotlin/testData/LocalDeclarations.kt @@ -0,0 +1,10 @@ +fun foo(): Boolean { + class Local + fun bar() = Local() + + val baz = fun() { + Local() + } + + return bar() == 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 new file mode 100644 index 00000000000..87775b574ab --- /dev/null +++ b/plugins/uast-kotlin/testData/LocalDeclarations.log.txt @@ -0,0 +1,28 @@ +UFile (package = ) + UClass (name = LocalDeclarationsKt) + UAnnotationMethod (name = foo) + UBlockExpression + UDeclarationsExpression + UClass (name = Local) + UAnnotationMethod (name = LocalDeclarationsKt$foo$Local) + UDeclarationsExpression + UVariable (name = bar) + ULambdaExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (Local)) + USimpleNameReferenceExpression (identifier = ) + UDeclarationsExpression + ULocalVariable (name = baz) + ULambdaExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (Local)) + USimpleNameReferenceExpression (identifier = ) + UReturnExpression + UBinaryExpression (operator = ==) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (bar)) + USimpleNameReferenceExpression (identifier = bar) + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (Local)) + USimpleNameReferenceExpression (identifier = ) diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.render.txt b/plugins/uast-kotlin/testData/LocalDeclarations.render.txt new file mode 100644 index 00000000000..e7e1c8e6be2 --- /dev/null +++ b/plugins/uast-kotlin/testData/LocalDeclarations.render.txt @@ -0,0 +1,14 @@ +public final class LocalDeclarationsKt { + public static final fun foo() : boolean { + public static final class Local { + public fun LocalDeclarationsKt$foo$Local() = UastEmptyExpression + } + var bar: = fun () { + () + } + var baz: = fun () { + () + } + return bar() == () + } +} diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.types.txt b/plugins/uast-kotlin/testData/LocalDeclarations.types.txt new file mode 100644 index 00000000000..631652d4a77 --- /dev/null +++ b/plugins/uast-kotlin/testData/LocalDeclarations.types.txt @@ -0,0 +1,28 @@ +UFile (package = ) [public final class LocalDeclarationsKt {...] + UClass (name = LocalDeclarationsKt) [public final class LocalDeclarationsKt {...}] + UAnnotationMethod (name = foo) [public static final fun foo() : boolean {...}] + UBlockExpression [{...}] : PsiType:Void + UDeclarationsExpression [public static final class Local {...}] + UClass (name = Local) [public static final class Local {...}] + UAnnotationMethod (name = LocalDeclarationsKt$foo$Local) [public fun LocalDeclarationsKt$foo$Local() = UastEmptyExpression] + UDeclarationsExpression [var bar: = fun () {...}] + UVariable (name = bar) [var bar: = fun () {...}] + ULambdaExpression [fun () {...}] + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [()] : PsiType: + UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))] + USimpleNameReferenceExpression (identifier = ) [] : PsiType: + UDeclarationsExpression [var baz: = fun () {...}] + ULocalVariable (name = baz) [var baz: = fun () {...}] + ULambdaExpression [fun () {...}] + UBlockExpression [{...}] : PsiType: + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [()] : PsiType: + UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))] + USimpleNameReferenceExpression (identifier = ) [] : PsiType: + UReturnExpression [return bar() == ()] : PsiType:Void + UBinaryExpression (operator = ==) [bar() == ()] : PsiType:boolean + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [bar()] : PsiType: + UIdentifier (Identifier (bar)) [UIdentifier (Identifier (bar))] + USimpleNameReferenceExpression (identifier = bar) [bar] : PsiType: + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [()] : PsiType: + UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))] + USimpleNameReferenceExpression (identifier = ) [] : PsiType: diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.values.txt b/plugins/uast-kotlin/testData/LocalDeclarations.values.txt new file mode 100644 index 00000000000..f7cc9eaac37 --- /dev/null +++ b/plugins/uast-kotlin/testData/LocalDeclarations.values.txt @@ -0,0 +1,28 @@ +UFile (package = ) [public final class LocalDeclarationsKt {...] + UClass (name = LocalDeclarationsKt) [public final class LocalDeclarationsKt {...}] + UAnnotationMethod (name = foo) [public static final fun foo() : boolean {...}] + UBlockExpression [{...}] = Nothing + UDeclarationsExpression [public static final class Local {...}] = Undetermined + UClass (name = Local) [public static final class Local {...}] + UAnnotationMethod (name = LocalDeclarationsKt$foo$Local) [public fun LocalDeclarationsKt$foo$Local() = UastEmptyExpression] + UDeclarationsExpression [var bar: = fun () {...}] = Undetermined + UVariable (name = bar) [var bar: = fun () {...}] + ULambdaExpression [fun () {...}] = Undetermined + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [()] = external ()() + UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))] + USimpleNameReferenceExpression (identifier = ) [] = external () + UDeclarationsExpression [var baz: = fun () {...}] = Undetermined + ULocalVariable (name = baz) [var baz: = fun () {...}] + ULambdaExpression [fun () {...}] = Undetermined + UBlockExpression [{...}] = external ()() + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [()] = external ()() + UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))] + USimpleNameReferenceExpression (identifier = ) [] = external () + UReturnExpression [return bar() == ()] = Nothing + UBinaryExpression (operator = ==) [bar() == ()] = Undetermined + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [bar()] = external bar()() + UIdentifier (Identifier (bar)) [UIdentifier (Identifier (bar))] + USimpleNameReferenceExpression (identifier = bar) [bar] = external bar() + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [()] = external ()() + UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))] + USimpleNameReferenceExpression (identifier = ) [] = external () diff --git a/plugins/uast-kotlin/testData/MethodReference.kt b/plugins/uast-kotlin/testData/MethodReference.kt new file mode 100644 index 00000000000..a927015d46c --- /dev/null +++ b/plugins/uast-kotlin/testData/MethodReference.kt @@ -0,0 +1,9 @@ +class Foo { + fun bar() { + } +} + +val x = Foo::bar + +// REF:Foo::bar +// RESULT:KtLightAnnotationMethod:bar diff --git a/plugins/uast-kotlin/testData/PropertyAccessors.kt b/plugins/uast-kotlin/testData/PropertyAccessors.kt new file mode 100644 index 00000000000..2a1e86dc2d8 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyAccessors.kt @@ -0,0 +1,12 @@ + +class PropertyTest { + var stringRepresentation: String + get() = this.toString() + set(value) { + setDataFromString(value) + } + + fun setDataFromString(data: String) { + + } +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/PropertyAccessors.log.txt b/plugins/uast-kotlin/testData/PropertyAccessors.log.txt new file mode 100644 index 00000000000..3b0a96a66bc --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyAccessors.log.txt @@ -0,0 +1,21 @@ +UFile (package = ) + UClass (name = PropertyTest) + UAnnotationMethod (name = getStringRepresentation) + UQualifiedReferenceExpression + UThisExpression (label = null) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString) + UAnnotationMethod (name = setStringRepresentation) + UParameter (name = value) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (setDataFromString)) + USimpleNameReferenceExpression (identifier = setDataFromString) + USimpleNameReferenceExpression (identifier = value) + UAnnotationMethod (name = setDataFromString) + UParameter (name = data) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UAnnotationMethod (name = PropertyTest) diff --git a/plugins/uast-kotlin/testData/PropertyAccessors.render.txt b/plugins/uast-kotlin/testData/PropertyAccessors.render.txt new file mode 100644 index 00000000000..91e56d20bb0 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyAccessors.render.txt @@ -0,0 +1,9 @@ +public final class PropertyTest { + public final fun getStringRepresentation() : java.lang.String = this.toString() + public final fun setStringRepresentation(value: java.lang.String) : void { + setDataFromString(value) + } + public final fun setDataFromString(data: java.lang.String) : void { + } + public fun PropertyTest() = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/PropertyInitializer.kt b/plugins/uast-kotlin/testData/PropertyInitializer.kt new file mode 100644 index 00000000000..8169ab4dafc --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializer.kt @@ -0,0 +1,8 @@ + +class TestPropertyInitializer { + var withSetter = "/sdcard" + get() = field + set(p) { + field = p + } +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/PropertyInitializer.log.txt b/plugins/uast-kotlin/testData/PropertyInitializer.log.txt new file mode 100644 index 00000000000..93453f9b40f --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializer.log.txt @@ -0,0 +1,15 @@ +UFile (package = ) + UClass (name = TestPropertyInitializer) + UField (name = withSetter) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = "/sdcard") + UAnnotationMethod (name = getWithSetter) + USimpleNameReferenceExpression (identifier = field) + UAnnotationMethod (name = setWithSetter) + UParameter (name = p) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UBinaryExpression (operator = =) + USimpleNameReferenceExpression (identifier = field) + USimpleNameReferenceExpression (identifier = p) + UAnnotationMethod (name = TestPropertyInitializer) diff --git a/plugins/uast-kotlin/testData/PropertyInitializer.render.txt b/plugins/uast-kotlin/testData/PropertyInitializer.render.txt new file mode 100644 index 00000000000..7d34908b700 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializer.render.txt @@ -0,0 +1,8 @@ +public final class TestPropertyInitializer { + private var withSetter: java.lang.String = "/sdcard" + public final fun getWithSetter() : java.lang.String = field + public final fun setWithSetter(p: java.lang.String) : void { + field = p + } + public fun TestPropertyInitializer() = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.kt b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.kt new file mode 100644 index 00000000000..aac1a6bbd4b --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.kt @@ -0,0 +1,3 @@ + +var withoutSetter = "/sdcard" + get() = field \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log.txt b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log.txt new file mode 100644 index 00000000000..0d13d6ea800 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log.txt @@ -0,0 +1,10 @@ +UFile (package = ) + UClass (name = PropertyInitializerWithoutSetterKt) + UField (name = withoutSetter) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = "/sdcard") + UAnnotationMethod (name = getWithoutSetter) + USimpleNameReferenceExpression (identifier = field) + UAnnotationMethod (name = setWithoutSetter) + UParameter (name = p) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) diff --git a/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.render.txt b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.render.txt new file mode 100644 index 00000000000..9a5b0de74c5 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.render.txt @@ -0,0 +1,5 @@ +public final class PropertyInitializerWithoutSetterKt { + private static var withoutSetter: java.lang.String = "/sdcard" + public static final fun getWithoutSetter() : java.lang.String = field + public static final fun setWithoutSetter(p: java.lang.String) : void = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/QualifiedConstructorCall.kt b/plugins/uast-kotlin/testData/QualifiedConstructorCall.kt new file mode 100644 index 00000000000..362a4f3e308 --- /dev/null +++ b/plugins/uast-kotlin/testData/QualifiedConstructorCall.kt @@ -0,0 +1,9 @@ +package A.B.C + +internal class Foo + +internal class Bar { + fun getFoo(): Foo { + return A.B.C.Foo() + } +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/QualifiedConstructorCall.log.txt b/plugins/uast-kotlin/testData/QualifiedConstructorCall.log.txt new file mode 100644 index 00000000000..7fad3df7e0a --- /dev/null +++ b/plugins/uast-kotlin/testData/QualifiedConstructorCall.log.txt @@ -0,0 +1,17 @@ +UFile (package = A.B.C) + UClass (name = Foo) + UAnnotationMethod (name = Foo) + UClass (name = Bar) + UAnnotationMethod (name = getFoo) + UBlockExpression + UReturnExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = A) + USimpleNameReferenceExpression (identifier = B) + USimpleNameReferenceExpression (identifier = C) + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (Foo)) + USimpleNameReferenceExpression (identifier = ) + UAnnotationMethod (name = Bar) diff --git a/plugins/uast-kotlin/testData/QualifiedConstructorCall.render.txt b/plugins/uast-kotlin/testData/QualifiedConstructorCall.render.txt new file mode 100644 index 00000000000..9c004977b1e --- /dev/null +++ b/plugins/uast-kotlin/testData/QualifiedConstructorCall.render.txt @@ -0,0 +1,12 @@ +package A.B.C + +public final class Foo { + public fun Foo() = UastEmptyExpression +} + +public final class Bar { + public final fun getFoo() : A.B.C.Foo { + return A.B.C.() + } + public fun Bar() = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/Simple.kt b/plugins/uast-kotlin/testData/Simple.kt new file mode 100644 index 00000000000..5f1c82104c2 --- /dev/null +++ b/plugins/uast-kotlin/testData/Simple.kt @@ -0,0 +1,7 @@ +class Simple { + fun method() { + println("Hello, world!") + } + + val property: String = "Mary" +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/Simple.log.txt b/plugins/uast-kotlin/testData/Simple.log.txt new file mode 100644 index 00000000000..283fb878d8d --- /dev/null +++ b/plugins/uast-kotlin/testData/Simple.log.txt @@ -0,0 +1,13 @@ +UFile (package = ) + UClass (name = Simple) + UField (name = property) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = "Mary") + UAnnotationMethod (name = method) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println) + ULiteralExpression (value = "Hello, world!") + UAnnotationMethod (name = getProperty) + UAnnotationMethod (name = Simple) diff --git a/plugins/uast-kotlin/testData/Simple.render.txt b/plugins/uast-kotlin/testData/Simple.render.txt new file mode 100644 index 00000000000..b354c83cca5 --- /dev/null +++ b/plugins/uast-kotlin/testData/Simple.render.txt @@ -0,0 +1,8 @@ +public final class Simple { + private final var property: java.lang.String = "Mary" + public final fun method() : void { + println("Hello, world!") + } + public final fun getProperty() : java.lang.String = UastEmptyExpression + public fun Simple() = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/Simple.values.txt b/plugins/uast-kotlin/testData/Simple.values.txt new file mode 100644 index 00000000000..19c3476a4b2 --- /dev/null +++ b/plugins/uast-kotlin/testData/Simple.values.txt @@ -0,0 +1,13 @@ +UFile (package = ) [public final class Simple {...] + UClass (name = Simple) [public final class Simple {...}] + UField (name = property) [private final var property: java.lang.String = "Mary"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + ULiteralExpression (value = "Mary") ["Mary"] = "Mary" + UAnnotationMethod (name = method) [public final fun method() : void {...}] + UBlockExpression [{...}] = external println("Hello, world!")("Hello, world!") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [println("Hello, world!")] = external println("Hello, world!")("Hello, world!") + UIdentifier (Identifier (println)) [UIdentifier (Identifier (println))] + USimpleNameReferenceExpression (identifier = println) [println] = external println() + ULiteralExpression (value = "Hello, world!") ["Hello, world!"] = "Hello, world!" + UAnnotationMethod (name = getProperty) [public final fun getProperty() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = Simple) [public fun Simple() = UastEmptyExpression] diff --git a/plugins/uast-kotlin/testData/StringTemplate.kt b/plugins/uast-kotlin/testData/StringTemplate.kt new file mode 100644 index 00000000000..b7775ff5aa7 --- /dev/null +++ b/plugins/uast-kotlin/testData/StringTemplate.kt @@ -0,0 +1,5 @@ +val foo = "lorem" +val bar = "ipsum" +val baz = "dolor" + +val foobarbaz = "$foo $bar $baz" \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/StringTemplate.log.txt b/plugins/uast-kotlin/testData/StringTemplate.log.txt new file mode 100644 index 00000000000..e38047dc442 --- /dev/null +++ b/plugins/uast-kotlin/testData/StringTemplate.log.txt @@ -0,0 +1,23 @@ +UFile (package = ) + UClass (name = StringTemplateKt) + UField (name = foo) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = "lorem") + UField (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = "ipsum") + UField (name = baz) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = "dolor") + UField (name = foobarbaz) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + USimpleNameReferenceExpression (identifier = foo) + ULiteralExpression (value = " ") + USimpleNameReferenceExpression (identifier = bar) + ULiteralExpression (value = " ") + USimpleNameReferenceExpression (identifier = baz) + UAnnotationMethod (name = getFoo) + UAnnotationMethod (name = getBar) + UAnnotationMethod (name = getBaz) + UAnnotationMethod (name = getFoobarbaz) diff --git a/plugins/uast-kotlin/testData/StringTemplate.render.txt b/plugins/uast-kotlin/testData/StringTemplate.render.txt new file mode 100644 index 00000000000..2d56a3954b6 --- /dev/null +++ b/plugins/uast-kotlin/testData/StringTemplate.render.txt @@ -0,0 +1,10 @@ +public final class StringTemplateKt { + private static final var foo: java.lang.String = "lorem" + private static final var bar: java.lang.String = "ipsum" + private static final var baz: java.lang.String = "dolor" + private static final var foobarbaz: java.lang.String = foo + " " + bar + " " + baz + public static final fun getFoo() : java.lang.String = UastEmptyExpression + public static final fun getBar() : java.lang.String = UastEmptyExpression + public static final fun getBaz() : java.lang.String = UastEmptyExpression + public static final fun getFoobarbaz() : java.lang.String = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/UnexpectedContainerException.kt b/plugins/uast-kotlin/testData/UnexpectedContainerException.kt new file mode 100644 index 00000000000..73783d48455 --- /dev/null +++ b/plugins/uast-kotlin/testData/UnexpectedContainerException.kt @@ -0,0 +1,19 @@ +interface Callback { + fun onError(throwable: Throwable) +} + +class Model { + init { + crashMe(Callback::class.java) { + object : Callback { + override fun onError(throwable: Throwable) { + throw UnsupportedOperationException("") + } + } + } + } + + fun crashMe(clazz: Class, factory: () -> T) { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/UnexpectedContainerException.types.txt b/plugins/uast-kotlin/testData/UnexpectedContainerException.types.txt new file mode 100644 index 00000000000..3844346145d --- /dev/null +++ b/plugins/uast-kotlin/testData/UnexpectedContainerException.types.txt @@ -0,0 +1,39 @@ +UFile (package = ) [public abstract interface Callback {...] + UClass (name = Callback) [public abstract interface Callback {...}] + UAnnotationMethod (name = onError) [public abstract fun onError(throwable: java.lang.Throwable) : void = UastEmptyExpression] + UParameter (name = throwable) [var throwable: java.lang.Throwable] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UClass (name = Model) [public final class Model {...}] + UAnnotationMethod (name = crashMe) [public final fun crashMe(clazz: java.lang.Class, factory: kotlin.jvm.functions.Function0) : void {...}] + UParameter (name = clazz) [var clazz: java.lang.Class] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UParameter (name = factory) [var factory: kotlin.jvm.functions.Function0] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UBlockExpression [{...}] : PsiType:Void + UThrowExpression [throw ()] : PsiType:Void + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [()] : PsiType:UnsupportedOperationException + UIdentifier (Identifier (UnsupportedOperationException)) [UIdentifier (Identifier (UnsupportedOperationException))] + USimpleNameReferenceExpression (identifier = ) [] : PsiType:UnsupportedOperationException + UMethod (name = Model) [public fun Model() {...}] + UBlockExpression [{...}] + UBlockExpression [{...}] : PsiType:Unit + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) [crashMe(Callback.java, { ...})] : PsiType:Unit + UIdentifier (Identifier (crashMe)) [UIdentifier (Identifier (crashMe))] + USimpleNameReferenceExpression (identifier = crashMe) [crashMe] : PsiType:Unit + UQualifiedReferenceExpression [Callback.java] : PsiType:Class + UClassLiteralExpression [Callback] : PsiType:KClass + USimpleNameReferenceExpression (identifier = java) [java] : PsiType:Class + ULambdaExpression [{ ...}] : PsiType: + UBlockExpression [{...}] + UObjectLiteralExpression [anonymous object : Callback {... }] : PsiType:Callback + UClass (name = null) [final class null {...}] + UAnnotationMethod (name = onError) [public fun onError(throwable: java.lang.Throwable) : void {...}] + UParameter (name = throwable) [var throwable: java.lang.Throwable] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UBlockExpression [{...}] : PsiType:Void + UThrowExpression [throw ("")] : PsiType:Void + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) [("")] : PsiType:UnsupportedOperationException + UIdentifier (Identifier (UnsupportedOperationException)) [UIdentifier (Identifier (UnsupportedOperationException))] + USimpleNameReferenceExpression (identifier = ) [] : PsiType:UnsupportedOperationException + ULiteralExpression (value = "") [""] : PsiType:String + UAnnotationMethod (name = Model$1$1) [fun Model$1$1() = UastEmptyExpression] diff --git a/plugins/uast-kotlin/testData/WhenIs.kt b/plugins/uast-kotlin/testData/WhenIs.kt new file mode 100644 index 00000000000..26b8065b8b7 --- /dev/null +++ b/plugins/uast-kotlin/testData/WhenIs.kt @@ -0,0 +1,4 @@ +fun foo(bar: Any) = when(bar) { + is String -> bar + !is String -> "" +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/WhenIs.log.txt b/plugins/uast-kotlin/testData/WhenIs.log.txt new file mode 100644 index 00000000000..56d1ab7caee --- /dev/null +++ b/plugins/uast-kotlin/testData/WhenIs.log.txt @@ -0,0 +1,22 @@ +UFile (package = ) + UClass (name = WhenIsKt) + UAnnotationMethod (name = foo) + UParameter (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + USwitchExpression + USimpleNameReferenceExpression (identifier = bar) + UExpressionList (when) + USwitchClauseExpressionWithBody + UBinaryExpressionWithType + USimpleNameReferenceExpression (identifier = it) + UTypeReferenceExpression (name = java.lang.String) + UExpressionList (when_entry) + USimpleNameReferenceExpression (identifier = bar) + UBreakExpression (label = null) + USwitchClauseExpressionWithBody + UBinaryExpressionWithType + USimpleNameReferenceExpression (identifier = it) + UTypeReferenceExpression (name = java.lang.String) + UExpressionList (when_entry) + ULiteralExpression (value = "") + UBreakExpression (label = null) diff --git a/plugins/uast-kotlin/testData/WhenIs.render.txt b/plugins/uast-kotlin/testData/WhenIs.render.txt new file mode 100644 index 00000000000..63513a3aac2 --- /dev/null +++ b/plugins/uast-kotlin/testData/WhenIs.render.txt @@ -0,0 +1,15 @@ +public final class WhenIsKt { + public static final fun foo(bar: java.lang.Object) : java.lang.String = switch (bar) { + it is java.lang.String -> { + bar + break + } + + it !is java.lang.String -> { + "" + break + } + + } + +} diff --git a/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt new file mode 100644 index 00000000000..bb2fbe17632 --- /dev/null +++ b/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt @@ -0,0 +1,9 @@ +package org.jetbrains.uast.test.kotlin + +import org.jetbrains.uast.test.common.RenderLogTestBase +import java.io.File + +abstract class AbstractKotlinRenderLogTest : AbstractKotlinUastTest(), RenderLogTestBase { + override fun getTestFile(testName: String, ext: String) = + File(File(TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) +} \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/AbstractKotlinTypesTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinTypesTest.kt new file mode 100644 index 00000000000..f77a0066f96 --- /dev/null +++ b/plugins/uast-kotlin/tests/AbstractKotlinTypesTest.kt @@ -0,0 +1,12 @@ +package org.jetbrains.uast.test.kotlin + +import org.jetbrains.uast.test.common.TypesTestBase +import java.io.File + +abstract class AbstractKotlinTypesTest : AbstractKotlinUastTest(), TypesTestBase { + + private fun getTestFile(testName: String, ext: String) = + File(File(TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext) + + override fun getTypesFile(testName: String) = getTestFile(testName, "types.txt") +} \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/AbstractKotlinUastTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinUastTest.kt new file mode 100644 index 00000000000..991d0531c31 --- /dev/null +++ b/plugins/uast-kotlin/tests/AbstractKotlinUastTest.kt @@ -0,0 +1,115 @@ +package org.jetbrains.uast.test.kotlin + +import com.intellij.mock.MockProject +import com.intellij.openapi.Disposable +import com.intellij.openapi.util.Disposer +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.openapi.vfs.VirtualFileManager +import com.intellij.util.io.URLUtil +import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys +import org.jetbrains.kotlin.cli.common.messages.MessageRenderer +import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector +import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles +import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot +import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots +import org.jetbrains.kotlin.config.CommonConfigurationKeys +import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.config.addKotlinSourceRoot +import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM +import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension +import org.jetbrains.kotlin.utils.PathUtil +import org.jetbrains.uast.kotlin.internal.UastAnalysisHandlerExtension +import org.jetbrains.uast.test.env.AbstractCoreEnvironment +import org.jetbrains.uast.test.env.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 + + override fun getVirtualFile(testName: String): VirtualFile { + val projectDir = TEST_KOTLIN_MODEL_DIR + val testFile = File(TEST_KOTLIN_MODEL_DIR, testName.substringBefore('/') + ".kt") + + super.initializeEnvironment(testFile) + + val trace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace() + + val kotlinCoreEnvironment = kotlinCoreEnvironment!! + + TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( + project, + kotlinCoreEnvironment.getSourceFiles(), + trace, + compilerConfiguration, + { scope -> JvmPackagePartProvider(kotlinCoreEnvironment, scope) } + ) + + val vfs = VirtualFileManager.getInstance().getFileSystem(URLUtil.FILE_PROTOCOL) + + val ideaProject = project + ideaProject.baseDir = vfs.findFileByPath(projectDir.canonicalPath) + + return vfs.findFileByPath(testFile.canonicalPath)!! + } + + override fun createEnvironment(source: File): AbstractCoreEnvironment { + compilerConfiguration = createKotlinCompilerConfiguration(source) + val parentDisposable = Disposer.newDisposable() + val kotlinCoreEnvironment = KotlinCoreEnvironment.createForTests( + parentDisposable, + compilerConfiguration, + EnvironmentConfigFiles.JVM_CONFIG_FILES) + + this.kotlinCoreEnvironment = kotlinCoreEnvironment + + AnalysisHandlerExtension.registerExtension( + kotlinCoreEnvironment.project, UastAnalysisHandlerExtension()) + + return KotlinCoreEnvironmentWrapper(kotlinCoreEnvironment, parentDisposable) + } + + override fun tearDown() { + kotlinCoreEnvironment = null + super.tearDown() + } + + private fun createKotlinCompilerConfiguration(sourceFile: File): CompilerConfiguration { + val configuration = CompilerConfiguration() + configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRoots()) + + val kotlinLibsDir = File("dist/kotlinc/lib") + configuration.addJvmClasspathRoot(File(kotlinLibsDir, "kotlin-runtime.jar")) + configuration.addJvmClasspathRoot(File(kotlinLibsDir, "kotlin-reflect.jar")) + + configuration.addKotlinSourceRoot(sourceFile.canonicalPath) + + val messageCollector = PrintingMessageCollector(System.err, MessageRenderer.PLAIN_RELATIVE_PATHS, true) + configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector) + + configuration.put(CommonConfigurationKeys.MODULE_NAME, "test-module") + + return configuration + } + + private class KotlinCoreEnvironmentWrapper(val environment: KotlinCoreEnvironment, + val parentDisposable: Disposable) : AbstractCoreEnvironment() { + override fun addJavaSourceRoot(root: File) { + TODO("not implemented") + } + + override val project: MockProject + get() = environment.project as MockProject + + override fun dispose() { + Disposer.dispose(parentDisposable) + } + } +} \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/AbstractKotlinValuesTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinValuesTest.kt new file mode 100644 index 00000000000..34cd3c32985 --- /dev/null +++ b/plugins/uast-kotlin/tests/AbstractKotlinValuesTest.kt @@ -0,0 +1,12 @@ +package org.jetbrains.uast.test.kotlin + +import org.jetbrains.uast.test.common.ValuesTestBase +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) + + override fun getValuesFile(testName: String) = getTestFile(testName, "values.txt") +} \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt new file mode 100644 index 00000000000..44029d4eca0 --- /dev/null +++ b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt @@ -0,0 +1,21 @@ +package org.jetbrains.uast.test.kotlin + +import org.jetbrains.uast.UAnnotation +import org.jetbrains.uast.UFile +import org.jetbrains.uast.test.env.findElementByText +import org.junit.Test + + +class KotlinUastApiTest : AbstractKotlinUastTest() { + override fun check(testName: String, file: UFile) { + } + + @Test fun testAnnotationParameters() { + doTest("AnnotationParameters") { name, file -> + val annotation = file.findElementByText("@IntRange(from = 10, to = 0)") + assertEquals(annotation.findAttributeValue("from")?.expression?.evaluate(), 10) + assertEquals(annotation.findAttributeValue("to")?.expression?.evaluate(), 0) + } + } +} + diff --git a/plugins/uast-kotlin/tests/KotlinUastResolveTest.kt b/plugins/uast-kotlin/tests/KotlinUastResolveTest.kt new file mode 100644 index 00000000000..db7289e999d --- /dev/null +++ b/plugins/uast-kotlin/tests/KotlinUastResolveTest.kt @@ -0,0 +1,13 @@ +package org.jetbrains.uast.test.kotlin + +import org.jetbrains.uast.UFile +import org.jetbrains.uast.test.common.ResolveTestBase +import org.junit.Test + +class KotlinUastResolveTest : AbstractKotlinUastTest(), ResolveTestBase { + override fun check(testName: String, file: UFile) { + super.check(testName, file) + } + + @Test fun testMethodReference() = doTest("MethodReference") +} diff --git a/plugins/uast-kotlin/tests/KotlinUastTypesTest.kt b/plugins/uast-kotlin/tests/KotlinUastTypesTest.kt new file mode 100644 index 00000000000..4f3dbd13be3 --- /dev/null +++ b/plugins/uast-kotlin/tests/KotlinUastTypesTest.kt @@ -0,0 +1,9 @@ +package org.jetbrains.uast.test.kotlin + +import org.junit.Test + +class KotlinUastTypesTest : AbstractKotlinTypesTest() { + @Test fun testLocalDeclarations() = doTest("LocalDeclarations") + + @Test fun testUnexpectedContainerException() = doTest("UnexpectedContainerException") +} \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/KotlinUastValuesTest.kt b/plugins/uast-kotlin/tests/KotlinUastValuesTest.kt new file mode 100644 index 00000000000..d4dcbbac620 --- /dev/null +++ b/plugins/uast-kotlin/tests/KotlinUastValuesTest.kt @@ -0,0 +1,14 @@ +package org.jetbrains.uast.test.kotlin + +import org.junit.Test + +class KotlinUastValuesTest : AbstractKotlinValuesTest() { + + @Test fun testAssertion() = doTest("Assertion") + + @Test fun testIn() = doTest("In") + + @Test fun testLocalDeclarations() = doTest("LocalDeclarations") + + @Test fun testSimple() = doTest("Simple") +} \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt new file mode 100644 index 00000000000..c5fa6d9434a --- /dev/null +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt @@ -0,0 +1,29 @@ +package org.jetbrains.uast.test.kotlin + +import org.junit.Test + +class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { + @Test fun testLocalDeclarations() = doTest("LocalDeclarations") + + @Test fun testSimple() = doTest("Simple") + + @Test fun testWhenIs() = doTest("WhenIs") + + @Test fun testDefaultImpls() = doTest("DefaultImpls") + + @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 testQualifiedConstructorCall() = doTest("QualifiedConstructorCall") +} \ No newline at end of file diff --git a/plugins/uast-kotlin/uast-kotlin.iml b/plugins/uast-kotlin/uast-kotlin.iml index 6bcdce22838..bb738923d66 100644 --- a/plugins/uast-kotlin/uast-kotlin.iml +++ b/plugins/uast-kotlin/uast-kotlin.iml @@ -4,7 +4,7 @@ - + @@ -15,5 +15,10 @@ + + + + + \ No newline at end of file diff --git a/update_dependencies.xml b/update_dependencies.xml index 1109adc33a3..764248aec4e 100644 --- a/update_dependencies.xml +++ b/update_dependencies.xml @@ -31,7 +31,7 @@ - + @@ -237,6 +237,7 @@ +