From 28e19ed8c76602615a323722942ff10c2012c262 Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Tue, 29 Jan 2019 12:35:36 +0300 Subject: [PATCH] 191: Uast: `AlternativesRenderLogTest` introduced --- .../testData/ClassAnnotation.altlog.txt.191 | 56 ++++++++++++++++++ .../testData/InnerClasses.altlog.txt.191 | 37 ++++++++++++ .../testData/LocalDeclarations.altlog.txt.191 | 47 +++++++++++++++ ...meterPropertyWithAnnotation.altlog.txt.191 | 59 +++++++++++++++++++ .../tests/AlternativesRenderLogTest.kt.191 | 59 +++++++++++++++++++ 5 files changed, 258 insertions(+) create mode 100644 plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt.191 create mode 100644 plugins/uast-kotlin/testData/InnerClasses.altlog.txt.191 create mode 100644 plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt.191 create mode 100644 plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt.191 create mode 100644 plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt.191 diff --git a/plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt.191 b/plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt.191 new file mode 100644 index 00000000000..d39b7977da0 --- /dev/null +++ b/plugins/uast-kotlin/testData/ClassAnnotation.altlog.txt.191 @@ -0,0 +1,56 @@ +[1]:[UFile (package = )] + [1]:[UClass (name = A)] + [1]:[UAnnotation (fqName = null)] + [1]:[[!] UnknownKotlinExpression (CONSTRUCTOR_CALLEE)] + [1]:[UTypeReferenceExpression (name = )] + [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))] diff --git a/plugins/uast-kotlin/testData/InnerClasses.altlog.txt.191 b/plugins/uast-kotlin/testData/InnerClasses.altlog.txt.191 new file mode 100644 index 00000000000..9552409772b --- /dev/null +++ b/plugins/uast-kotlin/testData/InnerClasses.altlog.txt.191 @@ -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))] diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt.191 b/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt.191 new file mode 100644 index 00000000000..99fd07b78fa --- /dev/null +++ b/plugins/uast-kotlin/testData/LocalDeclarations.altlog.txt.191 @@ -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))] diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt.191 b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt.191 new file mode 100644 index 00000000000..8e8944d919c --- /dev/null +++ b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.altlog.txt.191 @@ -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))] diff --git a/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt.191 b/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt.191 new file mode 100644 index 00000000000..b886b72f314 --- /dev/null +++ b/plugins/uast-kotlin/tests/AlternativesRenderLogTest.kt.191 @@ -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) + +}