Skip to content

Commit 5dc1784

Browse files
committed
Update UAST to 1.0.10; move uast-kotlin tests to Kotlin project
1 parent cfe1591 commit 5dc1784

File tree

62 files changed

+865
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+865
-53
lines changed

.idea/libraries/uast_java.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

idea/src/META-INF/android-lint.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@
124124

125125
<extensionPoints>
126126
<extensionPoint qualifiedName="org.jetbrains.uast.uastLanguagePlugin"
127-
interface="org.jetbrains.uast.UastLanguagePlugin"
128-
area="IDEA_PROJECT"/>
127+
interface="org.jetbrains.uast.UastLanguagePlugin"/>
129128
</extensionPoints>
130129

131130
<extensions defaultExtensionNs="org.jetbrains.uast">

plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
package org.jetbrains.uast.kotlin
1818

1919
import com.intellij.lang.Language
20-
import com.intellij.openapi.project.Project
21-
import com.intellij.psi.*
20+
import com.intellij.psi.PsiElement
21+
import com.intellij.psi.PsiFile
22+
import com.intellij.psi.PsiVariable
2223
import com.intellij.psi.impl.source.tree.LeafPsiElement
2324
import com.intellij.psi.util.PsiTreeUtil
2425
import org.jetbrains.kotlin.asJava.LightClassUtil
@@ -48,10 +49,10 @@ interface KotlinUastBindingContextProviderService {
4849
fun getTypeMapper(element: KtElement): KotlinTypeMapper?
4950
}
5051

51-
class KotlinUastLanguagePlugin(override val project: Project) : UastLanguagePlugin {
52+
class KotlinUastLanguagePlugin : UastLanguagePlugin {
5253
override val priority = 10
5354

54-
private val javaPlugin by lz { UastLanguagePlugin.getInstances(project).first { it is JavaUastLanguagePlugin } }
55+
private val javaPlugin by lz { UastLanguagePlugin.getInstances().first { it is JavaUastLanguagePlugin } }
5556

5657
override val language: Language
5758
get() = KotlinLanguage.INSTANCE

plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/evaluation/KotlinEvaluatorExtension.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.jetbrains.uast.kotlin.evaluation
22

33
import org.jetbrains.kotlin.idea.KotlinLanguage
4-
import org.jetbrains.uast.UastBinaryOperator
4+
import org.jetbrains.uast.UBinaryExpression
55
import org.jetbrains.uast.UastPostfixOperator
66
import org.jetbrains.uast.evaluation.UEvaluationInfo
77
import org.jetbrains.uast.evaluation.UEvaluationState
@@ -16,8 +16,8 @@ class KotlinEvaluatorExtension : UEvaluatorExtension {
1616
override fun toString() = "$from..$to"
1717
}
1818

19-
private class UClosedRangeConstant(override val value: Range) : UAbstractConstant() {
20-
constructor(from: UValue, to: UValue): this(Range(from, to))
19+
private class UClosedRangeConstant(override val value: Range, override val source: UBinaryExpression?) : UAbstractConstant() {
20+
constructor(from: UValue, to: UValue, source: UBinaryExpression): this(Range(from, to), source)
2121
}
2222

2323
override val language: KotlinLanguage = KotlinLanguage.INSTANCE
@@ -43,15 +43,15 @@ class KotlinEvaluatorExtension : UEvaluatorExtension {
4343
}
4444

4545
override fun evaluateBinary(
46-
operator: UastBinaryOperator,
46+
binaryExpression: UBinaryExpression,
4747
leftValue: UValue,
4848
rightValue: UValue,
4949
state: UEvaluationState
5050
): UEvaluationInfo {
51-
return when (operator) {
51+
return when (binaryExpression.operator) {
5252
KotlinBinaryOperators.IN -> rightValue.contains(leftValue)
5353
KotlinBinaryOperators.NOT_IN -> !rightValue.contains(leftValue)
54-
KotlinBinaryOperators.RANGE_TO -> UClosedRangeConstant(leftValue, rightValue)
54+
KotlinBinaryOperators.RANGE_TO -> UClosedRangeConstant(leftValue, rightValue, binaryExpression)
5555
else -> UUndeterminedValue
5656
} to state
5757
}

plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUBinaryExpression.kt

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
annotation class IntRange(val from: Long, val to: Long)
3+
4+
@IntRange(from = 10, to = 0)
5+
fun foo(): Int = 5
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
UFile (package = )
2+
UClass (name = AnnotationParametersKt)
3+
UAnnotationMethod (name = foo)
4+
UAnnotation (fqName = IntRange)
5+
UNamedExpression (name = from)
6+
ULiteralExpression (value = 10)
7+
UNamedExpression (name = to)
8+
ULiteralExpression (value = 0)
9+
ULiteralExpression (value = 5)
10+
UClass (name = IntRange)
11+
UAnnotation (fqName = java.lang.annotation.Retention)
12+
UNamedExpression (name = )
13+
UQualifiedReferenceExpression
14+
UQualifiedReferenceExpression
15+
UQualifiedReferenceExpression
16+
UQualifiedReferenceExpression
17+
USimpleNameReferenceExpression (identifier = java)
18+
USimpleNameReferenceExpression (identifier = lang)
19+
USimpleNameReferenceExpression (identifier = annotation)
20+
USimpleNameReferenceExpression (identifier = RetentionPolicy)
21+
USimpleNameReferenceExpression (identifier = RUNTIME)
22+
UAnnotationMethod (name = from)
23+
UAnnotationMethod (name = to)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public final class AnnotationParametersKt {
2+
@IntRange(from = 10, to = 0)
3+
public static final fun foo() : int = 5
4+
}
5+
6+
public abstract annotation IntRange {
7+
public abstract fun from() : long = UastEmptyExpression
8+
public abstract fun to() : long = UastEmptyExpression
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fun foo(): String {
2+
val s: String? = "Not Null"
3+
return s!!
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
UFile (package = ) [public final class AssertionKt {...]
2+
UClass (name = AssertionKt) [public final class AssertionKt {...}]
3+
UAnnotationMethod (name = foo) [public static final fun foo() : java.lang.String {...}]
4+
UBlockExpression [{...}] = Nothing
5+
UDeclarationsExpression [var s: java.lang.String = "Not Null"] = Undetermined
6+
ULocalVariable (name = s) [var s: java.lang.String = "Not Null"]
7+
ULiteralExpression (value = "Not Null") ["Not Null"] = "Not Null"
8+
UReturnExpression [return s!!] = Nothing
9+
UPostfixExpression (operator = !!) [s!!] = (var s = "Not Null")
10+
USimpleNameReferenceExpression (identifier = s) [s] = (var s = "Not Null")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
interface Foo {
3+
fun bar() = "Hello!"
4+
}
5+
6+
class Baz : Foo
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
UFile (package = )
2+
UClass (name = Foo)
3+
UAnnotationMethod (name = bar)
4+
ULiteralExpression (value = "Hello!")
5+
UClass (name = Baz)
6+
UAnnotationMethod (name = Baz)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public abstract interface Foo {
2+
public abstract fun bar() : java.lang.String = "Hello!"
3+
}
4+
5+
public final class Baz : Foo {
6+
public fun Baz() = UastEmptyExpression
7+
}

plugins/uast-kotlin/testData/Elvis.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
fun foo(bar: String): Any? = null
3+
4+
fun baz(): Any? {
5+
return foo("Lorem ipsum") ?: foo("dolor sit amet") ?: foo("consectetuer adipiscing elit")
6+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
UFile (package = )
2+
UClass (name = ElvisKt)
3+
UAnnotationMethod (name = foo)
4+
UParameter (name = bar)
5+
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
6+
ULiteralExpression (value = null)
7+
UAnnotationMethod (name = baz)
8+
UBlockExpression
9+
UReturnExpression
10+
UExpressionList (elvis)
11+
UDeclarationsExpression
12+
ULocalVariable (name = var243c4e1a)
13+
UExpressionList (elvis)
14+
UDeclarationsExpression
15+
ULocalVariable (name = varc4aef1e3)
16+
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
17+
UIdentifier (Identifier (foo))
18+
USimpleNameReferenceExpression (identifier = foo)
19+
ULiteralExpression (value = "Lorem ipsum")
20+
UIfExpression
21+
UBinaryExpression (operator = !=)
22+
USimpleNameReferenceExpression (identifier = varc4aef1e3)
23+
ULiteralExpression (value = null)
24+
USimpleNameReferenceExpression (identifier = varc4aef1e3)
25+
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
26+
UIdentifier (Identifier (foo))
27+
USimpleNameReferenceExpression (identifier = foo)
28+
ULiteralExpression (value = "dolor sit amet")
29+
UIfExpression
30+
UBinaryExpression (operator = !=)
31+
USimpleNameReferenceExpression (identifier = var243c4e1a)
32+
ULiteralExpression (value = null)
33+
USimpleNameReferenceExpression (identifier = var243c4e1a)
34+
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
35+
UIdentifier (Identifier (foo))
36+
USimpleNameReferenceExpression (identifier = foo)
37+
ULiteralExpression (value = "consectetuer adipiscing elit")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public final class ElvisKt {
2+
public static final fun foo(bar: java.lang.String) : java.lang.Object = null
3+
public static final fun baz() : java.lang.Object {
4+
return elvis {
5+
var var243c4e1a: <ErrorType> = elvis {
6+
var varc4aef1e3: <ErrorType> = foo("Lorem ipsum")
7+
if (varc4aef1e3 != null) varc4aef1e3 else foo("dolor sit amet")
8+
}
9+
if (var243c4e1a != null) var243c4e1a else foo("consectetuer adipiscing elit")
10+
}
11+
}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
enum class Style(val value: String) {
2+
SHEET("foo") {
3+
override val exitAnimation: String
4+
get() = "bar"
5+
};
6+
7+
abstract val exitAnimation: String
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
UFile (package = )
2+
UClass (name = Style)
3+
UEnumConstant (name = SHEET)
4+
USimpleNameReferenceExpression (identifier = Style)
5+
UClass (name = null)
6+
UAnnotationMethod (name = getExitAnimation)
7+
ULiteralExpression (value = "bar")
8+
UAnnotationMethod (name = SHEET)
9+
UField (name = value)
10+
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
11+
UAnnotationMethod (name = getExitAnimation)
12+
UAnnotationMethod (name = getValue)
13+
UAnnotationMethod (name = Style)
14+
UParameter (name = value)
15+
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public enum Style {
2+
SHEET {
3+
public fun getExitAnimation() : java.lang.String = "bar"
4+
fun SHEET() = UastEmptyExpression
5+
}
6+
private final var value: java.lang.String
7+
public abstract fun getExitAnimation() : java.lang.String = UastEmptyExpression
8+
public final fun getValue() : java.lang.String = UastEmptyExpression
9+
protected fun Style(value: java.lang.String) = UastEmptyExpression
10+
}

plugins/uast-kotlin/testData/In.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fun foo(): Boolean {
2+
val x = 1
3+
val y = 10
4+
return x in 0..5 && y !in 4..9
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
UFile (package = ) [public final class InKt {...]
2+
UClass (name = InKt) [public final class InKt {...}]
3+
UAnnotationMethod (name = foo) [public static final fun foo() : boolean {...}]
4+
UBlockExpression [{...}] = Nothing
5+
UDeclarationsExpression [var x: <ErrorType> = 1] = Undetermined
6+
ULocalVariable (name = x) [var x: <ErrorType> = 1]
7+
ULiteralExpression (value = 1) [1] = 1
8+
UDeclarationsExpression [var y: <ErrorType> = 10] = Undetermined
9+
ULocalVariable (name = y) [var y: <ErrorType> = 10]
10+
ULiteralExpression (value = 10) [10] = 10
11+
UReturnExpression [return x in 0 .. 5 && y !in 4 .. 9] = Nothing
12+
UBinaryExpression (operator = &&) [x in 0 .. 5 && y !in 4 .. 9] = true (depending on: (var x = 1), (var y = 10))
13+
UBinaryExpression (operator = in) [x in 0 .. 5] = true (depending on: (var x = 1))
14+
USimpleNameReferenceExpression (identifier = x) [x] = (var x = 1)
15+
UBinaryExpression (operator = ..) [0 .. 5] = 0..5
16+
ULiteralExpression (value = 0) [0] = 0
17+
ULiteralExpression (value = 5) [5] = 5
18+
UBinaryExpression (operator = !in) [y !in 4 .. 9] = true (depending on: (var y = 10))
19+
USimpleNameReferenceExpression (identifier = y) [y] = (var y = 10)
20+
UBinaryExpression (operator = ..) [4 .. 9] = 4..9
21+
ULiteralExpression (value = 4) [4] = 4
22+
ULiteralExpression (value = 9) [9] = 9
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fun foo(): Boolean {
2+
class Local
3+
fun bar() = Local()
4+
5+
val baz = fun() {
6+
Local()
7+
}
8+
9+
return bar() == Local()
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
UFile (package = )
2+
UClass (name = LocalDeclarationsKt)
3+
UAnnotationMethod (name = foo)
4+
UBlockExpression
5+
UDeclarationsExpression
6+
UClass (name = Local)
7+
UAnnotationMethod (name = LocalDeclarationsKt$foo$Local)
8+
UDeclarationsExpression
9+
UVariable (name = bar)
10+
ULambdaExpression
11+
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))
12+
UIdentifier (Identifier (Local))
13+
USimpleNameReferenceExpression (identifier = <init>)
14+
UDeclarationsExpression
15+
ULocalVariable (name = baz)
16+
ULambdaExpression
17+
UBlockExpression
18+
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))
19+
UIdentifier (Identifier (Local))
20+
USimpleNameReferenceExpression (identifier = <init>)
21+
UReturnExpression
22+
UBinaryExpression (operator = ==)
23+
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
24+
UIdentifier (Identifier (bar))
25+
USimpleNameReferenceExpression (identifier = bar)
26+
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))
27+
UIdentifier (Identifier (Local))
28+
USimpleNameReferenceExpression (identifier = <init>)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public final class LocalDeclarationsKt {
2+
public static final fun foo() : boolean {
3+
public static final class Local {
4+
public fun LocalDeclarationsKt$foo$Local() = UastEmptyExpression
5+
}
6+
var bar: <ErrorType> = fun () {
7+
<init>()
8+
}
9+
var baz: <ErrorType> = fun () {
10+
<init>()
11+
}
12+
return bar() == <init>()
13+
}
14+
}

0 commit comments

Comments
 (0)