Update UAST to 1.0.10; move uast-kotlin tests to Kotlin project

This commit is contained in:
Dmitry Jemerov
2017-02-06 19:52:52 +01:00
parent cfe159181d
commit 5dc178460e
62 changed files with 865 additions and 53 deletions
+2
View File
@@ -3,11 +3,13 @@
<CLASSES>
<root url="jar://$PROJECT_DIR$/dependencies/uast-common.jar!/" />
<root url="jar://$PROJECT_DIR$/dependencies/uast-java.jar!/" />
<root url="jar://$PROJECT_DIR$/dependencies/uast-tests.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$PROJECT_DIR$/dependencies/uast-common-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/dependencies/uast-java-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/dependencies/uast-tests-sources.jar!/" />
</SOURCES>
</library>
</component>
+1 -2
View File
@@ -124,8 +124,7 @@
<extensionPoints>
<extensionPoint qualifiedName="org.jetbrains.uast.uastLanguagePlugin"
interface="org.jetbrains.uast.UastLanguagePlugin"
area="IDEA_PROJECT"/>
interface="org.jetbrains.uast.UastLanguagePlugin"/>
</extensionPoints>
<extensions defaultExtensionNs="org.jetbrains.uast">
@@ -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
@@ -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
}
@@ -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
}
+5
View File
@@ -0,0 +1,5 @@
annotation class IntRange(val from: Long, val to: Long)
@IntRange(from = 10, to = 0)
fun foo(): Int = 5
@@ -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)
@@ -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
}
+4
View File
@@ -0,0 +1,4 @@
fun foo(): String {
val s: String? = "Not Null"
return s!!
}
+10
View File
@@ -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")
+6
View File
@@ -0,0 +1,6 @@
interface Foo {
fun bar() = "Hello!"
}
class Baz : Foo
+6
View File
@@ -0,0 +1,6 @@
UFile (package = )
UClass (name = Foo)
UAnnotationMethod (name = bar)
ULiteralExpression (value = "Hello!")
UClass (name = Baz)
UAnnotationMethod (name = Baz)
+7
View File
@@ -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
}
+6
View File
@@ -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")
}
+37
View File
@@ -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")
+12
View File
@@ -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: <ErrorType> = elvis {
var varc4aef1e3: <ErrorType> = foo("Lorem ipsum")
if (varc4aef1e3 != null) varc4aef1e3 else foo("dolor sit amet")
}
if (var243c4e1a != null) var243c4e1a else foo("consectetuer adipiscing elit")
}
}
}
+8
View File
@@ -0,0 +1,8 @@
enum class Style(val value: String) {
SHEET("foo") {
override val exitAnimation: String
get() = "bar"
};
abstract val exitAnimation: String
}
+15
View File
@@ -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)
@@ -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
}
+5
View File
@@ -0,0 +1,5 @@
fun foo(): Boolean {
val x = 1
val y = 10
return x in 0..5 && y !in 4..9
}
+22
View File
@@ -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: <ErrorType> = 1] = Undetermined
ULocalVariable (name = x) [var x: <ErrorType> = 1]
ULiteralExpression (value = 1) [1] = 1
UDeclarationsExpression [var y: <ErrorType> = 10] = Undetermined
ULocalVariable (name = y) [var y: <ErrorType> = 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
+10
View File
@@ -0,0 +1,10 @@
fun foo(): Boolean {
class Local
fun bar() = Local()
val baz = fun() {
Local()
}
return bar() == Local()
}
+28
View File
@@ -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 = <init>)
UDeclarationsExpression
ULocalVariable (name = baz)
ULambdaExpression
UBlockExpression
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))
UIdentifier (Identifier (Local))
USimpleNameReferenceExpression (identifier = <init>)
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 = <init>)
@@ -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: <ErrorType> = fun () {
<init>()
}
var baz: <ErrorType> = fun () {
<init>()
}
return bar() == <init>()
}
}
@@ -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: <ErrorType> = fun () {...}]
UVariable (name = bar) [var bar: <ErrorType> = fun () {...}]
ULambdaExpression [fun () {...}]
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [<init>()] : PsiType:<ErrorType>
UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] : PsiType:<ErrorType>
UDeclarationsExpression [var baz: <ErrorType> = fun () {...}]
ULocalVariable (name = baz) [var baz: <ErrorType> = fun () {...}]
ULambdaExpression [fun () {...}]
UBlockExpression [{...}] : PsiType:<ErrorType>
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [<init>()] : PsiType:<ErrorType>
UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] : PsiType:<ErrorType>
UReturnExpression [return bar() == <init>()] : PsiType:Void
UBinaryExpression (operator = ==) [bar() == <init>()] : PsiType:boolean
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [bar()] : PsiType:<ErrorType>
UIdentifier (Identifier (bar)) [UIdentifier (Identifier (bar))]
USimpleNameReferenceExpression (identifier = bar) [bar] : PsiType:<ErrorType>
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [<init>()] : PsiType:<ErrorType>
UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] : PsiType:<ErrorType>
@@ -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: <ErrorType> = fun () {...}] = Undetermined
UVariable (name = bar) [var bar: <ErrorType> = fun () {...}]
ULambdaExpression [fun () {...}] = Undetermined
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [<init>()] = external <init>()()
UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] = external <init>()
UDeclarationsExpression [var baz: <ErrorType> = fun () {...}] = Undetermined
ULocalVariable (name = baz) [var baz: <ErrorType> = fun () {...}]
ULambdaExpression [fun () {...}] = Undetermined
UBlockExpression [{...}] = external <init>()()
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [<init>()] = external <init>()()
UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] = external <init>()
UReturnExpression [return bar() == <init>()] = Nothing
UBinaryExpression (operator = ==) [bar() == <init>()] = 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)) [<init>()] = external <init>()()
UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] = external <init>()
+9
View File
@@ -0,0 +1,9 @@
class Foo {
fun bar() {
}
}
val x = Foo::bar
// REF:Foo::bar
// RESULT:KtLightAnnotationMethod:bar
+12
View File
@@ -0,0 +1,12 @@
class PropertyTest {
var stringRepresentation: String
get() = this.toString()
set(value) {
setDataFromString(value)
}
fun setDataFromString(data: String) {
}
}
+21
View File
@@ -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)
@@ -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
}
+8
View File
@@ -0,0 +1,8 @@
class TestPropertyInitializer {
var withSetter = "/sdcard"
get() = field
set(p) {
field = p
}
}
@@ -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)
@@ -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
}
@@ -0,0 +1,3 @@
var withoutSetter = "/sdcard"
get() = field
@@ -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)
@@ -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
}
@@ -0,0 +1,9 @@
package A.B.C
internal class Foo
internal class Bar {
fun getFoo(): Foo {
return A.B.C.Foo()
}
}
@@ -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 = <init>)
UAnnotationMethod (name = Bar)
@@ -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.<init>()
}
public fun Bar() = UastEmptyExpression
}
+7
View File
@@ -0,0 +1,7 @@
class Simple {
fun method() {
println("Hello, world!")
}
val property: String = "Mary"
}
+13
View File
@@ -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)
+8
View File
@@ -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
}
+13
View File
@@ -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]
+5
View File
@@ -0,0 +1,5 @@
val foo = "lorem"
val bar = "ipsum"
val baz = "dolor"
val foobarbaz = "$foo $bar $baz"
+23
View File
@@ -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)
+10
View File
@@ -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
}
@@ -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 <T : Any> crashMe(clazz: Class<T>, factory: () -> T) {
throw UnsupportedOperationException()
}
}
@@ -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<T>, factory: kotlin.jvm.functions.Function0<? extends T>) : void {...}]
UParameter (name = clazz) [var clazz: java.lang.Class<T>]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UParameter (name = factory) [var factory: kotlin.jvm.functions.Function0<? extends T>]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UBlockExpression [{...}] : PsiType:Void
UThrowExpression [throw <init>()] : PsiType:Void
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [<init>()] : PsiType:UnsupportedOperationException
UIdentifier (Identifier (UnsupportedOperationException)) [UIdentifier (Identifier (UnsupportedOperationException))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] : 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<Callback>
UClassLiteralExpression [Callback] : PsiType:KClass<Callback>
USimpleNameReferenceExpression (identifier = java) [java] : PsiType:Class<Callback>
ULambdaExpression [{ ...}] : PsiType:<ErrorType>
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 <init>("")] : PsiType:Void
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) [<init>("")] : PsiType:UnsupportedOperationException
UIdentifier (Identifier (UnsupportedOperationException)) [UIdentifier (Identifier (UnsupportedOperationException))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] : PsiType:UnsupportedOperationException
ULiteralExpression (value = "") [""] : PsiType:String
UAnnotationMethod (name = Model$1$1) [fun Model$1$1() = UastEmptyExpression]
+4
View File
@@ -0,0 +1,4 @@
fun foo(bar: Any) = when(bar) {
is String -> bar
!is String -> "<error>"
}
+22
View File
@@ -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 = "<error>")
UBreakExpression (label = null)
+15
View File
@@ -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 -> {
"<error>"
break
}
}
}
@@ -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)
}
@@ -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")
}
@@ -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<String>(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)
}
}
}
@@ -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")
}
@@ -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<UAnnotation>("@IntRange(from = 10, to = 0)")
assertEquals(annotation.findAttributeValue("from")?.expression?.evaluate(), 10)
assertEquals(annotation.findAttributeValue("to")?.expression?.evaluate(), 0)
}
}
}
@@ -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")
}
@@ -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")
}
@@ -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")
}
@@ -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")
}
+6 -1
View File
@@ -4,7 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -15,5 +15,10 @@
<orderEntry type="module" module-name="light-classes" />
<orderEntry type="module" module-name="util.runtime" />
<orderEntry type="library" name="uast-java" level="project" />
<orderEntry type="module" module-name="cli" scope="TEST" />
<orderEntry type="module" module-name="util" scope="TEST" />
<orderEntry type="library" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="module" module-name="idea-android" scope="TEST" />
<orderEntry type="module" module-name="tests-common" scope="TEST" />
</component>
</module>
+2 -1
View File
@@ -31,7 +31,7 @@
<os family="windows"/>
</condition>
<property name="uast.version" value="1.0.9"/>
<property name="uast.version" value="1.0.10"/>
<property name="generators" value="${basedir}/generators"/>
@@ -237,6 +237,7 @@
<property name="uast.server" value="http://dl.bintray.com/kotlin/uast"/>
<get-maven-library prefix="org/jetbrains/uast" lib="uast-common" version="${uast.version}" target.jar.name.base="uast-common" server="${uast.server}"/>
<get-maven-library prefix="org/jetbrains/uast" lib="uast-java" version="${uast.version}" target.jar.name.base="uast-java" server="${uast.server}"/>
<get-maven-library prefix="org/jetbrains/uast" lib="uast-tests" version="${uast.version}" target.jar.name.base="uast-tests" server="${uast.server}"/>
<!-- Closure Compiler -->
<!-- A download url taken from http://code.google.com/p/closure-compiler/wiki/BinaryDownloads -->