191: Uast: AlternativesRenderLogTest introduced

This commit is contained in:
Nicolay Mitropolsky
2019-01-29 12:35:36 +03:00
parent 8ad06314f0
commit 28e19ed8c7
5 changed files with 258 additions and 0 deletions
@@ -0,0 +1,56 @@
[1]:[UFile (package = )]
[1]:[UClass (name = A)]
[1]:[UAnnotation (fqName = null)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = <ErrorType>)]
[1]:[USimpleNameReferenceExpression (identifier = Test)]
[1]:[UIdentifier (Identifier (Test))]
[1]:[UIdentifier (Identifier (A))]
[1]:[UClass (name = MyAnnotation)]
[1]:[UIdentifier (Identifier (MyAnnotation))]
[1]:[UDeclarationsExpression]
[1]:[UDeclarationsExpression]
[1]:[UAnnotationMethod (name = text)]
[1]:[UIdentifier (Identifier (text))]
[1]:[UTypeReferenceExpression (name = java.lang.String)]
[1]:[USimpleNameReferenceExpression (identifier = String)]
[1]:[UIdentifier (Identifier (String))]
[1]:[UClass (name = B)]
[1]:[UAnnotation (fqName = MyAnnotation)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation)]
[1]:[UIdentifier (Identifier (MyAnnotation))]
[1]:[ULiteralExpression (value = "class")]
[1]:[ULiteralExpression (value = "class")]
[1]:[UIdentifier (Identifier (B))]
[1]:[UExpressionList (class_body)]
[1]:[UClass (name = InB)]
[1]:[UAnnotation (fqName = MyAnnotation)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation)]
[1]:[UIdentifier (Identifier (MyAnnotation))]
[1]:[ULiteralExpression (value = "inB class")]
[1]:[ULiteralExpression (value = "inB class")]
[1]:[UIdentifier (Identifier (InB))]
[1]:[UExpressionList (class_body)]
[1]:[UClass (name = Companion)]
[1]:[UAnnotation (fqName = MyAnnotation)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation)]
[1]:[UIdentifier (Identifier (MyAnnotation))]
[1]:[ULiteralExpression (value = "companion")]
[1]:[ULiteralExpression (value = "companion")]
[1]:[UIdentifier (Identifier (object))]
[1]:[UExpressionList (class_body)]
[1]:[UClass (name = Obj)]
[1]:[UAnnotation (fqName = MyAnnotation)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation)]
[1]:[UIdentifier (Identifier (MyAnnotation))]
[1]:[ULiteralExpression (value = "object")]
[1]:[ULiteralExpression (value = "object")]
[1]:[UIdentifier (Identifier (Obj))]
@@ -0,0 +1,37 @@
[1]:[UFile (package = )]
[1]:[UClass (name = Foo)]
[1]:[UIdentifier (Identifier (Foo))]
[1]:[UExpressionList (class_body)]
[2]:[UClass (name = Bar), UAnnotationMethod (name = Bar)]
[1]:[UIdentifier (Identifier (Bar))]
[1]:[UAnnotationMethod (name = Bar)]
[1]:[UDeclarationsExpression]
[3]:[UParameter (name = a), UField (name = a), UAnnotationMethod (name = getA)]
[1]:[UIdentifier (Identifier (a))]
[1]:[UTypeReferenceExpression (name = int)]
[1]:[USimpleNameReferenceExpression (identifier = Int)]
[1]:[UIdentifier (Identifier (Int))]
[3]:[UParameter (name = b), UField (name = b), UAnnotationMethod (name = getB)]
[1]:[UIdentifier (Identifier (b))]
[1]:[UTypeReferenceExpression (name = int)]
[1]:[USimpleNameReferenceExpression (identifier = Int)]
[1]:[UIdentifier (Identifier (Int))]
[1]:[UExpressionList (class_body)]
[1]:[UAnnotationMethod (name = getAPlusB)]
[1]:[UIdentifier (Identifier (getAPlusB))]
[1]:[UDeclarationsExpression]
[1]:[UBinaryExpression (operator = +)]
[1]:[USimpleNameReferenceExpression (identifier = a)]
[1]:[UIdentifier (Identifier (a))]
[1]:[USimpleNameReferenceExpression (identifier = +)]
[1]:[UIdentifier (Identifier (+))]
[1]:[USimpleNameReferenceExpression (identifier = b)]
[1]:[UIdentifier (Identifier (b))]
[1]:[UClass (name = Baz)]
[1]:[UIdentifier (Identifier (Baz))]
[1]:[UExpressionList (class_body)]
[1]:[UAnnotationMethod (name = doNothing)]
[1]:[UIdentifier (Identifier (doNothing))]
[1]:[UDeclarationsExpression]
[1]:[USimpleNameReferenceExpression (identifier = Unit)]
[1]:[UIdentifier (Identifier (Unit))]
@@ -0,0 +1,47 @@
[1]:[UFile (package = )]
[1]:[UAnnotationMethod (name = foo)]
[1]:[UIdentifier (Identifier (foo))]
[1]:[UDeclarationsExpression]
[1]:[UTypeReferenceExpression (name = boolean)]
[1]:[USimpleNameReferenceExpression (identifier = Boolean)]
[1]:[UIdentifier (Identifier (Boolean))]
[1]:[UBlockExpression]
[1]:[UClass (name = Local)]
[1]:[UIdentifier (Identifier (Local))]
[1]:[ULambdaExpression]
[1]:[UIdentifier (Identifier (bar))]
[1]:[UDeclarationsExpression]
[1]:[UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))]
[1]:[USimpleNameReferenceExpression (identifier = Local)]
[1]:[UIdentifier (Identifier (Local))]
[1]:[ULocalVariable (name = baz)]
[1]:[UIdentifier (Identifier (baz))]
[1]:[ULambdaExpression]
[1]:[UDeclarationsExpression]
[1]:[UBlockExpression]
[1]:[UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))]
[1]:[USimpleNameReferenceExpression (identifier = Local)]
[1]:[UIdentifier (Identifier (Local))]
[1]:[ULambdaExpression]
[1]:[UTypeReferenceExpression (name = int)]
[1]:[USimpleNameReferenceExpression (identifier = Int)]
[1]:[UIdentifier (Identifier (Int))]
[1]:[UIdentifier (Identifier (someLocalFun))]
[1]:[UDeclarationsExpression]
[1]:[UIdentifier (Identifier (text))]
[1]:[UTypeReferenceExpression (name = java.lang.String)]
[1]:[USimpleNameReferenceExpression (identifier = String)]
[1]:[UIdentifier (Identifier (String))]
[1]:[ULiteralExpression (value = 42)]
[1]:[UClass (name = LocalObject)]
[1]:[UIdentifier (Identifier (LocalObject))]
[1]:[UReturnExpression]
[1]:[UBinaryExpression (operator = ==)]
[1]:[UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))]
[1]:[USimpleNameReferenceExpression (identifier = bar)]
[1]:[UIdentifier (Identifier (bar))]
[1]:[USimpleNameReferenceExpression (identifier = ==)]
[1]:[UIdentifier (Identifier (==))]
[1]:[UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))]
[1]:[USimpleNameReferenceExpression (identifier = Local)]
[1]:[UIdentifier (Identifier (Local))]
@@ -0,0 +1,59 @@
[1]:[UFile (package = )]
[1]:[UClass (name = MyAnnotation)]
[1]:[UIdentifier (Identifier (MyAnnotation))]
[1]:[UClass (name = MyAnnotation2)]
[1]:[UIdentifier (Identifier (MyAnnotation2))]
[1]:[UClass (name = MyAnnotation3)]
[1]:[UIdentifier (Identifier (MyAnnotation3))]
[1]:[UClass (name = MyAnnotation4)]
[1]:[UIdentifier (Identifier (MyAnnotation4))]
[1]:[UClass (name = MyAnnotation5)]
[1]:[UIdentifier (Identifier (MyAnnotation5))]
[2]:[UClass (name = Test1), UAnnotationMethod (name = Test1)]
[1]:[UIdentifier (Identifier (Test1))]
[1]:[UAnnotationMethod (name = Test1)]
[1]:[UDeclarationsExpression]
[4]:[UParameter (name = bar), UField (name = bar), UAnnotationMethod (name = getBar), UAnnotationMethod (name = setBar)]
[1]:[UAnnotation (fqName = MyAnnotation)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation)]
[1]:[UIdentifier (Identifier (MyAnnotation))]
[1]:[UIdentifier (Identifier (bar))]
[1]:[UTypeReferenceExpression (name = int)]
[1]:[USimpleNameReferenceExpression (identifier = Int)]
[1]:[UIdentifier (Identifier (Int))]
[2]:[UClass (name = Test2), UAnnotationMethod (name = Test2)]
[1]:[UIdentifier (Identifier (Test2))]
[1]:[UAnnotationMethod (name = Test2)]
[1]:[UDeclarationsExpression]
[4]:[UParameter (name = bar), UField (name = bar), UAnnotationMethod (name = getBar), UAnnotationMethod (name = setBar)]
[1]:[UAnnotation (fqName = MyAnnotation)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation)]
[1]:[UIdentifier (Identifier (MyAnnotation))]
[1]:[UAnnotation (fqName = MyAnnotation2)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation2)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation2)]
[1]:[UIdentifier (Identifier (MyAnnotation2))]
[1]:[UAnnotation (fqName = MyAnnotation3)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation3)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation3)]
[1]:[UIdentifier (Identifier (MyAnnotation3))]
[1]:[UAnnotation (fqName = MyAnnotation4)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation4)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation4)]
[1]:[UIdentifier (Identifier (MyAnnotation4))]
[1]:[UAnnotation (fqName = MyAnnotation5)]
[1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)]
[1]:[UTypeReferenceExpression (name = MyAnnotation5)]
[1]:[USimpleNameReferenceExpression (identifier = MyAnnotation5)]
[1]:[UIdentifier (Identifier (MyAnnotation5))]
[1]:[UIdentifier (Identifier (bar))]
[1]:[UTypeReferenceExpression (name = int)]
[1]:[USimpleNameReferenceExpression (identifier = Int)]
[1]:[UIdentifier (Identifier (Int))]
@@ -0,0 +1,59 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.uast.test.kotlin
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.uast.DEFAULT_TYPES_LIST
import org.jetbrains.uast.UFile
import org.jetbrains.uast.UastLanguagePlugin
import org.jetbrains.uast.test.env.kotlin.assertEqualsToFile
import java.io.File
class AlternativesRenderLogTest : AbstractKotlinUastTest() {
fun testClassAnnotation() = doTest("ClassAnnotation")
fun testInnerClasses() = doTest("InnerClasses")
fun testLocalDeclarations() = doTest("LocalDeclarations")
fun testParameterPropertyWithAnnotation() = doTest("ParameterPropertyWithAnnotation")
override fun check(testName: String, file: UFile) {
val valuesFile = getTestFile(testName, "altlog.txt")
assertEqualsToFile("alternatives conversion result", valuesFile, file.asMultiplesTargetConversionResult())
}
private fun UFile.asMultiplesTargetConversionResult(): String {
val plugin = UastLanguagePlugin.byLanguage(KotlinLanguage.INSTANCE)!!
val builder = StringBuilder()
var level = 0
(this.psi as KtFile).accept(object : PsiElementVisitor() {
override fun visitElement(element: PsiElement) {
val uElement = plugin.convertToAlternatives(element, DEFAULT_TYPES_LIST).toList()
if (uElement.any()) {
builder.append(" ".repeat(level))
builder.append("[${uElement.size}]:")
builder.append(uElement.joinToString(", ", "[", "]") { it.asLogString() })
builder.appendln()
}
if (uElement.any()) level++
element.acceptChildren(this)
if (uElement.any()) level--
}
})
return builder.toString()
}
private fun getTestFile(testName: String, ext: String) =
File(File(AbstractKotlinUastTest.TEST_KOTLIN_MODEL_DIR, testName).canonicalPath + '.' + ext)
}