From 56dfde04281ff283231fa820f856f26b51caa884 Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Tue, 29 Jan 2019 12:35:31 +0300 Subject: [PATCH] 191: Uast: making `KotlinStringTemplateUPolyadicExpression` implement `UInjectionHost` (KT-27283) --- .../uast/kotlin/KotlinAbstractUElement.kt.191 | 228 ++++++++ .../kotlin/KotlinUastLanguagePlugin.kt.191 | 548 ++++++++++++++++++ ...inStringTemplateUPolyadicExpression.kt.191 | 43 ++ .../testData/AnnotationParameters.log.txt.191 | 79 +++ .../testData/Assertion.values.txt.191 | 11 + .../testData/ClassAnnotation.log.txt.191 | 34 ++ .../testData/DefaultImpls.log.txt.191 | 9 + .../DestructuringDeclaration.log.txt.191 | 25 + .../uast-kotlin/testData/Elvis.log.txt.191 | 50 ++ .../testData/EnumValueMembers.log.txt.191 | 21 + .../testData/IfStatement.log.txt.191 | 14 + .../LocalVariableWithAnnotation.log.txt.191 | 10 + .../testData/ParametersDisorder.log.txt.191 | 174 ++++++ .../testData/PropertyDelegate.log.txt.191 | 35 ++ .../testData/PropertyInitializer.log.txt.191 | 18 + ...opertyInitializerWithoutSetter.log.txt.191 | 13 + .../uast-kotlin/testData/Simple.log.txt.191 | 15 + .../testData/Simple.values.txt.191 | 15 + .../testData/SimpleScript.log.txt.191 | 53 ++ .../testData/StringTemplate.log.txt.191 | 26 + .../testData/StringTemplate.types.txt.191 | 26 + .../StringTemplateComplex.log.txt.191 | 80 +++ .../StringTemplateComplex.types.txt.191 | 80 +++ .../testData/SuperCalls.log.txt.191 | 114 ++++ .../UnexpectedContainerException.log.txt.191 | 39 ++ ...UnexpectedContainerException.types.txt.191 | 39 ++ .../testData/WhenAndDestructing.log.txt.191 | 49 ++ .../uast-kotlin/testData/WhenIs.log.txt.191 | 25 + .../testData/WhenStringLiteral.log.txt.191 | 38 ++ .../tests/KotlinUastApiTest.kt.191 | 52 +- 30 files changed, 1918 insertions(+), 45 deletions(-) create mode 100644 plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.191 create mode 100644 plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.191 create mode 100644 plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.191 create mode 100644 plugins/uast-kotlin/testData/AnnotationParameters.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/Assertion.values.txt.191 create mode 100644 plugins/uast-kotlin/testData/ClassAnnotation.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/DefaultImpls.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/Elvis.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/EnumValueMembers.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/IfStatement.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/LocalVariableWithAnnotation.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/ParametersDisorder.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/PropertyDelegate.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/PropertyInitializer.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/Simple.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/Simple.values.txt.191 create mode 100644 plugins/uast-kotlin/testData/SimpleScript.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/StringTemplate.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/StringTemplate.types.txt.191 create mode 100644 plugins/uast-kotlin/testData/StringTemplateComplex.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/StringTemplateComplex.types.txt.191 create mode 100644 plugins/uast-kotlin/testData/SuperCalls.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/UnexpectedContainerException.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/UnexpectedContainerException.types.txt.191 create mode 100644 plugins/uast-kotlin/testData/WhenAndDestructing.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/WhenIs.log.txt.191 create mode 100644 plugins/uast-kotlin/testData/WhenStringLiteral.log.txt.191 diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.191 new file mode 100644 index 00000000000..2c62d83f432 --- /dev/null +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt.191 @@ -0,0 +1,228 @@ +/* + * 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 com.intellij.psi.PsiElement +import org.jetbrains.kotlin.asJava.LightClassUtil +import org.jetbrains.kotlin.asJava.classes.KtLightClassForLocalDeclaration +import org.jetbrains.kotlin.asJava.toLightGetter +import org.jetbrains.kotlin.asJava.toLightSetter +import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType +import org.jetbrains.kotlin.psi.psiUtil.isPropertyParameter +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf +import org.jetbrains.uast.* +import org.jetbrains.uast.kotlin.expressions.KotlinUElvisExpression +import org.jetbrains.uast.kotlin.internal.KotlinUElementWithComments +import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable + +abstract class KotlinAbstractUElement(private val givenParent: UElement?) : KotlinUElementWithComments, + JvmDeclarationUElementPlaceholder { + + final override val uastParent: UElement? by lz { + givenParent ?: convertParent() + } + + protected open fun convertParent(): UElement? { + val psi = psi + var parent = psi?.parent ?: psi?.containingFile + + if (psi is KtLightClassForLocalDeclaration) { + val originParent = psi.kotlinOrigin.parent + parent = when (originParent) { + is KtClassBody -> originParent.parent + else -> originParent + } + } + + if (psi is KtAnnotationEntry) { + val parentUnwrapped = KotlinConverter.unwrapElements(parent) ?: return null + val target = psi.useSiteTarget?.getAnnotationUseSiteTarget() + when (target) { + AnnotationUseSiteTarget.PROPERTY_GETTER -> + parent = (parentUnwrapped as? KtProperty)?.getter + ?: (parentUnwrapped as? KtParameter)?.toLightGetter() + ?: parent + + AnnotationUseSiteTarget.PROPERTY_SETTER -> + parent = (parentUnwrapped as? KtProperty)?.setter + ?: (parentUnwrapped as? KtParameter)?.toLightSetter() + ?: parent + AnnotationUseSiteTarget.FIELD -> + parent = (parentUnwrapped as? KtProperty) + ?: (parentUnwrapped as? KtParameter) + ?.takeIf { it.isPropertyParameter() } + ?.let(LightClassUtil::getLightClassBackingField) + ?: parent + AnnotationUseSiteTarget.SETTER_PARAMETER -> + parent = (parentUnwrapped as? KtParameter) + ?.toLightSetter()?.parameterList?.parameters?.firstOrNull() ?: parent + } + } + if (psi is UastKotlinPsiVariable && parent != null) { + parent = parent.parent + } + + if (parent is KtBlockStringTemplateEntry) { + parent = parent.parent + } + + if (parent is KtWhenConditionWithExpression) { + parent = parent.parent + } + + if (parent is KtImportList) { + parent = parent.parent + } + + if (psi is KtFunctionLiteral && parent is KtLambdaExpression) { + parent = parent.parent + } + + if (parent is KtLambdaArgument) { + parent = parent.parent + } + + if (psi is KtSuperTypeCallEntry) { + parent = parent?.parent + } + + if (parent is KtPropertyDelegate) { + parent = parent.parent + } + + val result = doConvertParent(this, parent) + if (result == this) { + throw IllegalStateException("Loop in parent structure when converting a $psi of type ${psi?.javaClass} with parent $parent of type ${parent?.javaClass} text: [${parent?.text}]") + } + + return result + } + + override fun equals(other: Any?): Boolean { + if (other !is UElement) { + return false + } + + return this.psi == other.psi + } + + override fun hashCode() = psi?.hashCode() ?: 0 +} + +fun doConvertParent(element: UElement, parent: PsiElement?): UElement? { + val parentUnwrapped = KotlinConverter.unwrapElements(parent) ?: return null + if (parent is KtValueArgument && parentUnwrapped is KtAnnotationEntry) { + return (KotlinUastLanguagePlugin().convertElementWithParent(parentUnwrapped, null) as? KotlinUAnnotation) + ?.findAttributeValueExpression(parent) + } + + if (parent is KtParameter) { + val annotationClass = findAnnotationClassFromConstructorParameter(parent) + if (annotationClass != null) { + return annotationClass.methods.find { it.name == parent.name } + } + } + + if (parent is KtClassInitializer) { + val containingClass = parent.containingClassOrObject + if (containingClass != null) { + val containingUClass = KotlinUastLanguagePlugin().convertElementWithParent(containingClass, null) as? KotlinUClass + containingUClass?.methods?.filterIsInstance()?.firstOrNull { it.isPrimary }?.let { + return it.uastBody + } + } + } + + val result = KotlinUastLanguagePlugin().convertElementWithParent(parentUnwrapped, null) + + if (result is KotlinUBlockExpression && element is UClass) { + return KotlinUDeclarationsExpression(result).apply { + declarations = listOf(element) + } + } + + if (result is UEnumConstant && element is UDeclaration) { + return result.initializingClass + } + + if (result is UCallExpression && result.uastParent is UEnumConstant) { + return result.uastParent + } + + if (result is USwitchClauseExpressionWithBody && !isInConditionBranch(element, result)) { + return result.body + } + + if (result is KotlinUDestructuringDeclarationExpression && + element.psi == (parent as KtDestructuringDeclaration).initializer) { + return result.tempVarAssignment + } + + if (result is KotlinUElvisExpression && parent is KtBinaryExpression) { + when (element.psi) { + parent.left -> return result.lhsDeclaration + parent.right -> return result.rhsIfExpression + } + } + + if (result is UMethod + && result !is KotlinConstructorUMethod // no sense to wrap super calls with `return` + && element is UExpression + && element !is UBlockExpression + && element !is UTypeReferenceExpression // when element is a type in extension methods + ) { + return KotlinUBlockExpression.KotlinLazyUBlockExpression(result, { block -> + listOf(KotlinUImplicitReturnExpression(block).apply { returnExpression = element }) + }).expressions.single() + } + + return result +} + +private fun isInConditionBranch(element: UElement, result: USwitchClauseExpressionWithBody) = + element.psi?.parentsWithSelf?.takeWhile { it !== result.psi }?.any { it is KtWhenCondition } ?: false + + +private fun findAnnotationClassFromConstructorParameter(parameter: KtParameter): UClass? { + val primaryConstructor = parameter.getStrictParentOfType() ?: return null + val containingClass = primaryConstructor.getContainingClassOrObject() + if (containingClass.isAnnotation()) { + return KotlinUastLanguagePlugin().convertElementWithParent(containingClass, null) as? UClass + } + return null +} + +abstract class KotlinAbstractUExpression(givenParent: UElement?) : + KotlinAbstractUElement(givenParent), + UExpression, + JvmDeclarationUElementPlaceholder { + + override val javaPsi: PsiElement? = null + + override val sourcePsi + get() = psi + + override val annotations: List + get() { + val annotatedExpression = psi?.parent as? KtAnnotatedExpression ?: return emptyList() + return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) } + } +} + diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.191 new file mode 100644 index 00000000000..07ea7a0808c --- /dev/null +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt.191 @@ -0,0 +1,548 @@ +/* + * Copyright 2010-2015 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 com.intellij.lang.Language +import com.intellij.openapi.components.ServiceManager +import com.intellij.openapi.util.Key +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.intellij.psi.impl.source.tree.LeafPsiElement +import org.jetbrains.kotlin.asJava.LightClassUtil +import org.jetbrains.kotlin.asJava.classes.KtLightClass +import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade +import org.jetbrains.kotlin.asJava.elements.* +import org.jetbrains.kotlin.asJava.toLightClass +import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper +import org.jetbrains.kotlin.config.LanguageVersionSettings +import org.jetbrains.kotlin.descriptors.ConstructorDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.idea.KotlinLanguage +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getParentOfType +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.uast.* +import org.jetbrains.uast.expressions.UInjectionHost +import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier +import org.jetbrains.uast.kotlin.declarations.KotlinUMethod +import org.jetbrains.uast.kotlin.expressions.* +import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter +import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable + +interface KotlinUastResolveProviderService { + fun getBindingContext(element: KtElement): BindingContext + fun getTypeMapper(element: KtElement): KotlinTypeMapper? + fun getLanguageVersionSettings(element: KtElement): LanguageVersionSettings + fun isJvmElement(psiElement: PsiElement): Boolean + fun getReferenceVariants(ktElement: KtElement, nameHint: String): Sequence +} + +var PsiElement.destructuringDeclarationInitializer: Boolean? by UserDataProperty(Key.create("kotlin.uast.destructuringDeclarationInitializer")) + +class KotlinUastLanguagePlugin : UastLanguagePlugin { + override val priority = 10 + + override val language: Language + get() = KotlinLanguage.INSTANCE + + override fun isFileSupported(fileName: String): Boolean { + return fileName.endsWith(".kt", false) || fileName.endsWith(".kts", false) + } + + private val PsiElement.isJvmElement: Boolean + get() { + val resolveProvider = ServiceManager.getService(project, KotlinUastResolveProviderService::class.java) + return resolveProvider.isJvmElement(this) + } + + override fun convertElement(element: PsiElement, parent: UElement?, requiredType: Class?): UElement? { + if (!element.isJvmElement) return null + return convertDeclarationOrElement(element, parent, requiredType) + } + + override fun convertElementWithParent(element: PsiElement, requiredType: Class?): UElement? { + if (!element.isJvmElement) return null + if (element is PsiFile) return convertDeclaration(element, null, requiredType) + if (element is KtLightClassForFacade) return convertDeclaration(element, null, requiredType) + + return convertDeclarationOrElement(element, null, requiredType) + } + + private fun convertDeclarationOrElement(element: PsiElement, givenParent: UElement?, requiredType: Class?): UElement? { + if (element is UElement) return element + + if (element.isValid) { + element.getUserData(KOTLIN_CACHED_UELEMENT_KEY)?.get()?.let { cachedUElement -> + return if (requiredType == null || requiredType.isInstance(cachedUElement)) cachedUElement else null + } + } + + val uElement = convertDeclaration(element, givenParent, requiredType) + ?: KotlinConverter.convertPsiElement(element, givenParent, requiredType) + /* + if (uElement != null) { + element.putUserData(KOTLIN_CACHED_UELEMENT_KEY, WeakReference(uElement)) + } + */ + return uElement + } + + override fun getMethodCallExpression( + element: PsiElement, + containingClassFqName: String?, + methodName: String + ): UastLanguagePlugin.ResolvedMethod? { + if (element !is KtCallExpression) return null + val resolvedCall = element.getResolvedCall(element.analyze()) ?: return null + val resultingDescriptor = resolvedCall.resultingDescriptor + if (resultingDescriptor !is FunctionDescriptor || resultingDescriptor.name.asString() != methodName) return null + + val parent = element.parent + val parentUElement = convertElementWithParent(parent, null) ?: return null + + val uExpression = KotlinUFunctionCallExpression(element, parentUElement, resolvedCall) + val method = uExpression.resolve() ?: return null + if (method.name != methodName) return null + return UastLanguagePlugin.ResolvedMethod(uExpression, method) + } + + override fun getConstructorCallExpression( + element: PsiElement, + fqName: String + ): UastLanguagePlugin.ResolvedConstructor? { + if (element !is KtCallExpression) return null + val resolvedCall = element.getResolvedCall(element.analyze()) ?: return null + val resultingDescriptor = resolvedCall.resultingDescriptor + if (resultingDescriptor !is ConstructorDescriptor + || resultingDescriptor.returnType.constructor.declarationDescriptor?.name?.asString() != fqName) { + return null + } + + val parent = KotlinConverter.unwrapElements(element.parent) ?: return null + val parentUElement = convertElementWithParent(parent, null) ?: return null + + val uExpression = KotlinUFunctionCallExpression(element, parentUElement, resolvedCall) + val method = uExpression.resolve() ?: return null + val containingClass = method.containingClass ?: return null + return UastLanguagePlugin.ResolvedConstructor(uExpression, method, containingClass) + } + + internal fun convertDeclaration(element: PsiElement, + givenParent: UElement?, + requiredType: Class?): UElement? { + fun

build(ctor: (P, UElement?) -> UElement): () -> UElement? = { ctor(element as P, givenParent) } + + fun

buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = + { ctor(element as P, ktElement, givenParent) } + + fun

buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = + { ctor(element as P, ktElement, givenParent) } + + val original = element.originalElement + return with(requiredType) { + when (original) { + is KtLightMethod -> el(build(KotlinUMethod.Companion::create)) // .Companion is needed because of KT-13934 + is KtLightClass -> when (original.kotlinOrigin) { + is KtEnumEntry -> el { + convertEnumEntry(original.kotlinOrigin as KtEnumEntry, givenParent) + } + else -> el { KotlinUClass.create(original, givenParent) } + } + is KtLightFieldImpl.KtLightEnumConstant -> el(buildKtOpt(original.kotlinOrigin, ::KotlinUEnumConstant)) + is KtLightField -> el(buildKtOpt(original.kotlinOrigin, ::KotlinUField)) + is KtLightParameter -> el(buildKtOpt(original.kotlinOrigin, ::KotlinUParameter)) + is UastKotlinPsiParameter -> el(buildKt(original.ktParameter, ::KotlinUParameter)) + is UastKotlinPsiVariable -> el(buildKt(original.ktElement, ::KotlinUVariable)) + + is KtEnumEntry -> el { + convertEnumEntry(original, givenParent) + } + is KtClassOrObject -> el { + original.toLightClass()?.let { lightClass -> + KotlinUClass.create(lightClass, givenParent) + } + } + is KtFunction -> + if (original.isLocal) { + el { + val parent = original.parent + if (parent is KtLambdaExpression) { + KotlinULambdaExpression(parent, givenParent) // your parent is the ULambdaExpression + } else if (original.name.isNullOrEmpty()) { + createLocalFunctionLambdaExpression(original, givenParent) + } + else { + val uDeclarationsExpression = createLocalFunctionDeclaration(original, givenParent) + val localFunctionVar = uDeclarationsExpression.declarations.single() as KotlinLocalFunctionUVariable + localFunctionVar.uastInitializer + } + } + } + else { + el { + val lightMethod = LightClassUtil.getLightClassMethod(original) ?: return null + convertDeclaration(lightMethod, givenParent, requiredType) + } + } + + is KtPropertyAccessor -> el { + val lightMethod = LightClassUtil.getLightClassAccessorMethod(original) ?: return null + convertDeclaration(lightMethod, givenParent, requiredType) + } + + is KtProperty -> + if (original.isLocal) { + KotlinConverter.convertPsiElement(element, givenParent, requiredType) + } + else { + convertNonLocalProperty(original, givenParent, requiredType) + } + + is KtParameter -> el { + val ownerFunction = original.ownerFunction as? KtFunction ?: return null + val lightMethod = LightClassUtil.getLightClassMethod(ownerFunction) ?: return null + val lightParameter = lightMethod.parameterList.parameters.find { it.name == original.name } ?: return null + KotlinUParameter(lightParameter, original, givenParent) + } + + is KtFile -> el { KotlinUFile(original, this@KotlinUastLanguagePlugin) } + is FakeFileForLightClass -> el { KotlinUFile(original.navigationElement, this@KotlinUastLanguagePlugin) } + is KtAnnotationEntry -> el(build(::KotlinUAnnotation)) + is KtCallExpression -> + if (requiredType != null && UAnnotation::class.java.isAssignableFrom(requiredType)) { + el { KotlinUNestedAnnotation.tryCreate(original, givenParent) } + } else null + is KtLightAnnotationForSourceEntry -> convertElement(original.kotlinOrigin, givenParent, requiredType) + else -> null + } + } + } + + private fun convertEnumEntry(original: KtEnumEntry, givenParent: UElement?): UElement? { + return LightClassUtil.getLightClassBackingField(original)?.let { psiField -> + if (psiField is KtLightFieldImpl.KtLightEnumConstant) { + KotlinUEnumConstant(psiField, psiField.kotlinOrigin, givenParent) + } + else { + null + } + } + } + + override fun isExpressionValueUsed(element: UExpression): Boolean { + return when (element) { + is KotlinUSimpleReferenceExpression.KotlinAccessorCallExpression -> element.setterValue != null + is KotlinAbstractUExpression -> { + val ktElement = element.psi as? KtElement ?: return false + ktElement.analyze()[BindingContext.USED_AS_EXPRESSION, ktElement] ?: false + } + else -> false + } + } +} + +internal inline fun Class?.el(f: () -> UElement?): UElement? { + return if (this == null || isAssignableFrom(ActualT::class.java)) f() else null +} + +internal inline fun Class?.expr(f: () -> UExpression?): UExpression? { + return if (this == null || isAssignableFrom(ActualT::class.java)) f() else null +} + +private fun convertNonLocalProperty(property: KtProperty, + givenParent: UElement?, + requiredType: Class?): UElement? { + val methods = LightClassUtil.getLightClassPropertyMethods(property) + return methods.backingField?.let { backingField -> + with(requiredType) { + el { KotlinUField(backingField, (backingField as? KtLightElement<*,*>)?.kotlinOrigin, givenParent) } + } + } ?: methods.getter?.let { getter -> + KotlinUastLanguagePlugin().convertDeclaration(getter, givenParent, requiredType) + } +} + +internal object KotlinConverter { + internal tailrec fun unwrapElements(element: PsiElement?): PsiElement? = when (element) { + is KtValueArgumentList -> unwrapElements(element.parent) + is KtValueArgument -> unwrapElements(element.parent) + is KtDeclarationModifierList -> unwrapElements(element.parent) + is KtContainerNode -> unwrapElements(element.parent) + is KtSimpleNameStringTemplateEntry -> unwrapElements(element.parent) + is KtLightParameterList -> unwrapElements(element.parent) + is KtTypeElement -> unwrapElements(element.parent) + else -> element + } + + private val identifiersTokens = + setOf(KtTokens.IDENTIFIER, KtTokens.CONSTRUCTOR_KEYWORD, KtTokens.THIS_KEYWORD, KtTokens.SUPER_KEYWORD, KtTokens.OBJECT_KEYWORD) + + internal fun convertPsiElement(element: PsiElement?, + givenParent: UElement?, + requiredType: Class?): UElement? { + fun

build(ctor: (P, UElement?) -> UElement): () -> UElement? { + return { ctor(element as P, givenParent) } + } + + return with (requiredType) { when (element) { + is KtParameterList -> el { + val declarationsExpression = KotlinUDeclarationsExpression(givenParent) + declarationsExpression.apply { + declarations = element.parameters.mapIndexed { i, p -> + KotlinUParameter(UastKotlinPsiParameter.create(p, element, declarationsExpression, i), p, this) + } + } + } + is KtClassBody -> el(build(KotlinUExpressionList.Companion::createClassBody)) + is KtCatchClause -> el(build(::KotlinUCatchClause)) + is KtVariableDeclaration -> + if (element is KtProperty && !element.isLocal) { + el { + LightClassUtil.getLightClassBackingField(element)?.let { + KotlinUField(it, element, givenParent) + } + } + } + else { + el { + convertVariablesDeclaration(element, givenParent).declarations.singleOrNull() + } + } + + is KtExpression -> KotlinConverter.convertExpression(element, givenParent, requiredType) + is KtLambdaArgument -> element.getLambdaExpression()?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) } + is KtLightElementBase -> { + val expression = element.kotlinOrigin + when (expression) { + is KtExpression -> KotlinConverter.convertExpression(expression, givenParent, requiredType) + else -> el { UastEmptyExpression(givenParent) } + } + } + is KtLiteralStringTemplateEntry, is KtEscapeStringTemplateEntry -> el(build(::KotlinStringULiteralExpression)) + is KtStringTemplateEntry -> element.expression?.let { convertExpression(it, givenParent, requiredType) } ?: expr { UastEmptyExpression } + is KtWhenEntry -> el(build(::KotlinUSwitchEntry)) + is KtWhenCondition -> convertWhenCondition(element, givenParent, requiredType) + is KtTypeReference -> el { LazyKotlinUTypeReferenceExpression(element, givenParent) } + is KtConstructorDelegationCall -> + el { KotlinUFunctionCallExpression(element, givenParent) } + is KtSuperTypeCallEntry -> + el { + (element.getParentOfType(true)?.parent as? KtObjectLiteralExpression) + ?.toUElementOfType() + ?: KotlinUFunctionCallExpression(element, givenParent) + } + is KtImportDirective -> el(build(::KotlinUImportStatement)) + else -> { + if (element is LeafPsiElement) { + if (element.elementType in identifiersTokens) + if (element.elementType != KtTokens.OBJECT_KEYWORD || element.getParentOfType(false)?.nameIdentifier == null) + el(build(::KotlinUIdentifier)) + else null + else if (element.elementType in KtTokens.OPERATIONS && element.parent is KtOperationReferenceExpression) + el(build(::KotlinUIdentifier)) + else if (element.elementType == KtTokens.LBRACKET && element.parent is KtCollectionLiteralExpression) + el { + UIdentifier( + element, + KotlinUCollectionLiteralExpression( + element.parent as KtCollectionLiteralExpression, + null + ) + ) + } + else null + } else null + } + }} + } + + + internal fun convertEntry(entry: KtStringTemplateEntry, + givenParent: UElement?, + requiredType: Class? = null): UExpression? { + return with(requiredType) { + if (entry is KtStringTemplateEntryWithExpression) { + expr { + KotlinConverter.convertOrEmpty(entry.expression, givenParent) + } + } + else { + expr { + if (entry is KtEscapeStringTemplateEntry) + KotlinStringULiteralExpression(entry, givenParent, entry.unescapedValue) + else + KotlinStringULiteralExpression(entry, givenParent) + } + } + } + } + + internal fun convertExpression(expression: KtExpression, + givenParent: UElement?, + requiredType: Class? = null): UExpression? { + fun

build(ctor: (P, UElement?) -> UExpression): () -> UExpression? { + return { ctor(expression as P, givenParent) } + } + + return with (requiredType) { when (expression) { + is KtVariableDeclaration -> expr(build(::convertVariablesDeclaration)) + + is KtStringTemplateExpression -> expr { KotlinStringTemplateUPolyadicExpression(expression, givenParent) } + is KtDestructuringDeclaration -> expr { + val declarationsExpression = KotlinUDestructuringDeclarationExpression(givenParent, expression) + declarationsExpression.apply { + val tempAssignment = KotlinULocalVariable(UastKotlinPsiVariable.create(expression, declarationsExpression), expression, declarationsExpression) + val destructuringAssignments = expression.entries.mapIndexed { i, entry -> + val psiFactory = KtPsiFactory(expression.project) + val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()", + expression.containingFile) + initializer.destructuringDeclarationInitializer = true + KotlinULocalVariable(UastKotlinPsiVariable.create(entry, tempAssignment.psi, declarationsExpression, initializer), entry, declarationsExpression) + } + declarations = listOf(tempAssignment) + destructuringAssignments + } + } + is KtLabeledExpression -> expr(build(::KotlinULabeledExpression)) + is KtClassLiteralExpression -> expr(build(::KotlinUClassLiteralExpression)) + is KtObjectLiteralExpression -> expr(build(::KotlinUObjectLiteralExpression)) + is KtDotQualifiedExpression -> expr(build(::KotlinUQualifiedReferenceExpression)) + is KtSafeQualifiedExpression -> expr(build(::KotlinUSafeQualifiedExpression)) + is KtSimpleNameExpression -> expr(build(::KotlinUSimpleReferenceExpression)) + is KtCallExpression -> expr(build(::KotlinUFunctionCallExpression)) + is KtCollectionLiteralExpression -> expr(build(::KotlinUCollectionLiteralExpression)) + is KtBinaryExpression -> { + if (expression.operationToken == KtTokens.ELVIS) { + expr(build(::createElvisExpression)) + } + else expr(build(::KotlinUBinaryExpression)) + } + is KtParenthesizedExpression -> expr(build(::KotlinUParenthesizedExpression)) + is KtPrefixExpression -> expr(build(::KotlinUPrefixExpression)) + is KtPostfixExpression -> expr(build(::KotlinUPostfixExpression)) + is KtThisExpression -> expr(build(::KotlinUThisExpression)) + is KtSuperExpression -> expr(build(::KotlinUSuperExpression)) + is KtCallableReferenceExpression -> expr(build(::KotlinUCallableReferenceExpression)) + is KtIsExpression -> expr(build(::KotlinUTypeCheckExpression)) + is KtIfExpression -> expr(build(::KotlinUIfExpression)) + is KtWhileExpression -> expr(build(::KotlinUWhileExpression)) + is KtDoWhileExpression -> expr(build(::KotlinUDoWhileExpression)) + is KtForExpression -> expr(build(::KotlinUForEachExpression)) + is KtWhenExpression -> expr(build(::KotlinUSwitchExpression)) + is KtBreakExpression -> expr(build(::KotlinUBreakExpression)) + is KtContinueExpression -> expr(build(::KotlinUContinueExpression)) + is KtReturnExpression -> expr(build(::KotlinUReturnExpression)) + is KtThrowExpression -> expr(build(::KotlinUThrowExpression)) + is KtBlockExpression -> expr(build(::KotlinUBlockExpression)) + is KtConstantExpression -> expr(build(::KotlinULiteralExpression)) + is KtTryExpression -> expr(build(::KotlinUTryExpression)) + is KtArrayAccessExpression -> expr(build(::KotlinUArrayAccessExpression)) + is KtLambdaExpression -> expr(build(::KotlinULambdaExpression)) + is KtBinaryExpressionWithTypeRHS -> expr(build(::KotlinUBinaryExpressionWithType)) + is KtClassOrObject -> expr { + expression.toLightClass()?.let { lightClass -> + KotlinUDeclarationsExpression(givenParent).apply { + declarations = listOf(KotlinUClass.create(lightClass, this)) + } + } ?: UastEmptyExpression + } + is KtFunction -> if (expression.name.isNullOrEmpty()) { + expr(build(::createLocalFunctionLambdaExpression)) + } + else { + expr(build(::createLocalFunctionDeclaration)) + } + + else -> expr(build(::UnknownKotlinExpression)) + }} + } + + internal fun convertWhenCondition(condition: KtWhenCondition, + givenParent: UElement?, + requiredType: Class? = null): UExpression? { + return with(requiredType) { + when (condition) { + is KtWhenConditionInRange -> expr { + KotlinCustomUBinaryExpression(condition, givenParent).apply { + leftOperand = KotlinStringUSimpleReferenceExpression("it", this) + operator = when { + condition.isNegated -> KotlinBinaryOperators.NOT_IN + else -> KotlinBinaryOperators.IN + } + rightOperand = KotlinConverter.convertOrEmpty(condition.rangeExpression, this) + } + } + is KtWhenConditionIsPattern -> expr { + KotlinCustomUBinaryExpressionWithType(condition, givenParent).apply { + operand = KotlinStringUSimpleReferenceExpression("it", this) + operationKind = when { + condition.isNegated -> KotlinBinaryExpressionWithTypeKinds.NEGATED_INSTANCE_CHECK + else -> UastBinaryExpressionWithTypeKind.INSTANCE_CHECK + } + val typeRef = condition.typeReference + typeReference = typeRef?.let { + LazyKotlinUTypeReferenceExpression(it, this) { typeRef.toPsiType(this, boxed = true) } + } + } + } + + is KtWhenConditionWithExpression -> + condition.expression?.let { KotlinConverter.convertExpression(it, givenParent, requiredType) } + + else -> expr { UastEmptyExpression } + } + } + } + + internal fun convertOrEmpty(expression: KtExpression?, parent: UElement?): UExpression { + return expression?.let { convertExpression(it, parent, null) } ?: UastEmptyExpression + } + + internal fun convertOrNull(expression: KtExpression?, parent: UElement?): UExpression? { + return if (expression != null) convertExpression(expression, parent, null) else null + } + + internal fun KtPsiFactory.createAnalyzableExpression(text: String, context: PsiElement): KtExpression = + createAnalyzableProperty("val x = $text", context).initializer ?: error("Failed to create expression from text: '$text'") + + internal fun KtPsiFactory.createAnalyzableProperty(text: String, context: PsiElement): KtProperty = + createAnalyzableDeclaration(text, context) + + internal fun KtPsiFactory.createAnalyzableDeclaration(text: String, context: PsiElement): TDeclaration { + val file = createAnalyzableFile("dummy.kt", text, context) + val declarations = file.declarations + assert(declarations.size == 1) { "${declarations.size} declarations in $text" } + return declarations.first() as TDeclaration + } +} + +private fun convertVariablesDeclaration( + psi: KtVariableDeclaration, + parent: UElement? +): UDeclarationsExpression { + val declarationsExpression = parent as? KotlinUDeclarationsExpression + ?: psi.parent.toUElementOfType() as? KotlinUDeclarationsExpression + ?: KotlinUDeclarationsExpression(null, parent, psi) + val parentPsiElement = parent?.psi + val variable = KotlinUAnnotatedLocalVariable( + UastKotlinPsiVariable.create(psi, parentPsiElement, declarationsExpression), psi, declarationsExpression) { annotationParent -> + psi.annotationEntries.map { KotlinUAnnotation(it, annotationParent) } + } + return declarationsExpression.apply { declarations = listOf(variable) } +} diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.191 b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.191 new file mode 100644 index 00000000000..f760d4be49c --- /dev/null +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinStringTemplateUPolyadicExpression.kt.191 @@ -0,0 +1,43 @@ +/* + * 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 com.intellij.psi.PsiLanguageInjectionHost +import org.jetbrains.kotlin.psi.KtStringTemplateExpression +import org.jetbrains.uast.UElement +import org.jetbrains.uast.UExpression +import org.jetbrains.uast.UPolyadicExpression +import org.jetbrains.uast.UastBinaryOperator +import org.jetbrains.uast.expressions.UInjectionHost + +class KotlinStringTemplateUPolyadicExpression( + override val psi: KtStringTemplateExpression, + givenParent: UElement? +) : KotlinAbstractUExpression(givenParent), + UPolyadicExpression, + KotlinUElementWithType, + KotlinEvaluatableUElement, + UInjectionHost { + override val operands: List by lz { psi.entries.map { KotlinConverter.convertEntry(it, this)!! } } + override val operator = UastBinaryOperator.PLUS + + override val psiLanguageInjectionHost: PsiLanguageInjectionHost get() = psi + override val isString: Boolean get() = true + + override fun asRenderString(): String = if (operands.isEmpty()) "\"\"" else super.asRenderString() + override fun asLogString(): String = if (operands.isEmpty()) "UPolyadicExpression (value = \"\")" else super.asLogString() +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/AnnotationParameters.log.txt.191 b/plugins/uast-kotlin/testData/AnnotationParameters.log.txt.191 new file mode 100644 index 00000000000..7fbc81db93c --- /dev/null +++ b/plugins/uast-kotlin/testData/AnnotationParameters.log.txt.191 @@ -0,0 +1,79 @@ +UFile (package = ) + UClass (name = AnnotationParametersKt) + UAnnotationMethod (name = foo) + UAnnotation (fqName = RequiresPermission) + UNamedExpression (name = anyOf) + UCallExpression (kind = UastCallKind(name='array_initializer'), argCount = 3)) + UIdentifier (Identifier (intArrayOf)) + USimpleNameReferenceExpression (identifier = intArrayOf) + ULiteralExpression (value = 1) + ULiteralExpression (value = 2) + ULiteralExpression (value = 3) + UAnnotation (fqName = IntRange) + UNamedExpression (name = from) + ULiteralExpression (value = 10) + UNamedExpression (name = to) + ULiteralExpression (value = 0) + UAnnotation (fqName = WithDefaultValue) + UAnnotation (fqName = SuppressLint) + UNamedExpression (name = value) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Lorem") + UBlockExpression + UReturnExpression + ULiteralExpression (value = 5) + UAnnotationMethod (name = bar) + UAnnotation (fqName = IntRange) + UNamedExpression (name = from) + ULiteralExpression (value = 0) + UNamedExpression (name = to) + ULiteralExpression (value = 100) + UAnnotation (fqName = SuppressLint) + UNamedExpression (name = value) + UCallExpression (kind = UastCallKind(name='array_initializer'), argCount = 3)) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Lorem") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Ipsum") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Dolor") + UBlockExpression + UReturnExpression + USimpleNameReferenceExpression (identifier = Unit) + UAnnotationMethod (name = fooWithArrLiteral) + UAnnotation (fqName = RequiresPermission) + UNamedExpression (name = anyOf) + UCallExpression (kind = UastCallKind(name='array_initializer'), argCount = 3)) + UIdentifier (Identifier ([)) + ULiteralExpression (value = 1) + ULiteralExpression (value = 2) + ULiteralExpression (value = 3) + UBlockExpression + UReturnExpression + ULiteralExpression (value = 5) + UAnnotationMethod (name = fooWithStrArrLiteral) + UAnnotation (fqName = RequiresStrPermission) + UNamedExpression (name = strs) + UCallExpression (kind = UastCallKind(name='array_initializer'), argCount = 3)) + UIdentifier (Identifier ([)) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "a") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "b") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "c") + UBlockExpression + UReturnExpression + ULiteralExpression (value = 3) + UClass (name = IntRange) + UAnnotationMethod (name = from) + UAnnotationMethod (name = to) + UClass (name = RequiresPermission) + UAnnotationMethod (name = anyOf) + UClass (name = RequiresStrPermission) + UAnnotationMethod (name = strs) + UClass (name = WithDefaultValue) + UAnnotationMethod (name = value) + ULiteralExpression (value = 42) + UClass (name = SuppressLint) + UAnnotationMethod (name = value) diff --git a/plugins/uast-kotlin/testData/Assertion.values.txt.191 b/plugins/uast-kotlin/testData/Assertion.values.txt.191 new file mode 100644 index 00000000000..fab347adb1e --- /dev/null +++ b/plugins/uast-kotlin/testData/Assertion.values.txt.191 @@ -0,0 +1,11 @@ +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"] + UPolyadicExpression (operator = +) ["Not Null"] = "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/ClassAnnotation.log.txt.191 b/plugins/uast-kotlin/testData/ClassAnnotation.log.txt.191 new file mode 100644 index 00000000000..9b5381ae7b0 --- /dev/null +++ b/plugins/uast-kotlin/testData/ClassAnnotation.log.txt.191 @@ -0,0 +1,34 @@ +UFile (package = ) + UClass (name = A) + UAnnotation (fqName = null) + UAnnotationMethod (name = A) + UClass (name = MyAnnotation) + UAnnotationMethod (name = text) + UClass (name = B) + UAnnotation (fqName = MyAnnotation) + UNamedExpression (name = text) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "class") + UField (name = Companion) + UAnnotation (fqName = null) + UAnnotationMethod (name = B) + UClass (name = InB) + UAnnotation (fqName = MyAnnotation) + UNamedExpression (name = text) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "inB class") + UAnnotationMethod (name = InB) + UClass (name = Companion) + UAnnotation (fqName = MyAnnotation) + UNamedExpression (name = text) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "companion") + UAnnotationMethod (name = Companion) + UClass (name = Obj) + UAnnotation (fqName = MyAnnotation) + UNamedExpression (name = text) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "object") + UField (name = INSTANCE) + UAnnotation (fqName = null) + UAnnotationMethod (name = Obj) diff --git a/plugins/uast-kotlin/testData/DefaultImpls.log.txt.191 b/plugins/uast-kotlin/testData/DefaultImpls.log.txt.191 new file mode 100644 index 00000000000..35284a53b46 --- /dev/null +++ b/plugins/uast-kotlin/testData/DefaultImpls.log.txt.191 @@ -0,0 +1,9 @@ +UFile (package = ) + UClass (name = Foo) + UAnnotationMethod (name = bar) + UBlockExpression + UReturnExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Hello!") + UClass (name = Baz) + UAnnotationMethod (name = Baz) diff --git a/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt.191 b/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt.191 new file mode 100644 index 00000000000..dc8c23ffccd --- /dev/null +++ b/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt.191 @@ -0,0 +1,25 @@ +UFile (package = ) + UClass (name = DestructuringDeclarationKt) + UAnnotationMethod (name = foo) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = var268d4034) + UAnnotation (fqName = null) + UBinaryExpression (operator = ) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "foo") + ULiteralExpression (value = 1) + ULocalVariable (name = a) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var268d4034) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component1)) + USimpleNameReferenceExpression (identifier = ) + ULocalVariable (name = b) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var268d4034) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component2)) + USimpleNameReferenceExpression (identifier = ) diff --git a/plugins/uast-kotlin/testData/Elvis.log.txt.191 b/plugins/uast-kotlin/testData/Elvis.log.txt.191 new file mode 100644 index 00000000000..6457169b5ac --- /dev/null +++ b/plugins/uast-kotlin/testData/Elvis.log.txt.191 @@ -0,0 +1,50 @@ +UFile (package = ) + UClass (name = ElvisKt) + UAnnotationMethod (name = foo) + UParameter (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + ULiteralExpression (value = null) + UAnnotationMethod (name = bar) + UBlockExpression + UReturnExpression + ULiteralExpression (value = 42) + UAnnotationMethod (name = baz) + UBlockExpression + UReturnExpression + UExpressionList (elvis) + UDeclarationsExpression + ULocalVariable (name = var243c51a0) + UAnnotation (fqName = null) + UExpressionList (elvis) + UDeclarationsExpression + ULocalVariable (name = varc4aef569) + UAnnotation (fqName = null) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (foo)) + USimpleNameReferenceExpression (identifier = foo) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Lorem ipsum") + UIfExpression + UBinaryExpression (operator = !=) + USimpleNameReferenceExpression (identifier = varc4aef569) + ULiteralExpression (value = null) + USimpleNameReferenceExpression (identifier = varc4aef569) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (foo)) + USimpleNameReferenceExpression (identifier = foo) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "dolor sit amet") + UIfExpression + UBinaryExpression (operator = !=) + USimpleNameReferenceExpression (identifier = var243c51a0) + ULiteralExpression (value = null) + USimpleNameReferenceExpression (identifier = var243c51a0) + UQualifiedReferenceExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (bar)) + USimpleNameReferenceExpression (identifier = bar) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString) diff --git a/plugins/uast-kotlin/testData/EnumValueMembers.log.txt.191 b/plugins/uast-kotlin/testData/EnumValueMembers.log.txt.191 new file mode 100644 index 00000000000..9bcd1da79a9 --- /dev/null +++ b/plugins/uast-kotlin/testData/EnumValueMembers.log.txt.191 @@ -0,0 +1,21 @@ +UFile (package = ) + UClass (name = Style) + UEnumConstant (name = SHEET) + UAnnotation (fqName = null) + USimpleNameReferenceExpression (identifier = Style) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "foo") + UClass (name = null) + UAnnotationMethod (name = getExitAnimation) + UBlockExpression + UReturnExpression + UPolyadicExpression (operator = +) + 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/IfStatement.log.txt.191 b/plugins/uast-kotlin/testData/IfStatement.log.txt.191 new file mode 100644 index 00000000000..fb24637db1a --- /dev/null +++ b/plugins/uast-kotlin/testData/IfStatement.log.txt.191 @@ -0,0 +1,14 @@ +UFile (package = ) + UClass (name = IfStatementKt) + UAnnotationMethod (name = foo) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = x) + UIfExpression + UBinaryExpression (operator = !=) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "abc") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "def") + ULiteralExpression (value = 1) + ULiteralExpression (value = 0) diff --git a/plugins/uast-kotlin/testData/LocalVariableWithAnnotation.log.txt.191 b/plugins/uast-kotlin/testData/LocalVariableWithAnnotation.log.txt.191 new file mode 100644 index 00000000000..f48af2b19de --- /dev/null +++ b/plugins/uast-kotlin/testData/LocalVariableWithAnnotation.log.txt.191 @@ -0,0 +1,10 @@ +UFile (package = ) + UClass (name = LocalVariableWithAnnotationKt) + UAnnotationMethod (name = foo) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = bar) + UAnnotation (fqName = TestAnnotation) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "lorem ipsum") + UClass (name = TestAnnotation) diff --git a/plugins/uast-kotlin/testData/ParametersDisorder.log.txt.191 b/plugins/uast-kotlin/testData/ParametersDisorder.log.txt.191 new file mode 100644 index 00000000000..58b160b8dcb --- /dev/null +++ b/plugins/uast-kotlin/testData/ParametersDisorder.log.txt.191 @@ -0,0 +1,174 @@ +UFile (package = ) + UClass (name = ParametersDisorderKt) + UAnnotationMethod (name = global) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UAnnotationMethod (name = withDefault) + UParameter (name = c) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = 1) + UParameter (name = d) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "aaa") + UBlockExpression + UAnnotationMethod (name = withReceiver) + UParameter (name = $receiver) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UAnnotationMethod (name = call) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (global)) + USimpleNameReferenceExpression (identifier = global) + ULiteralExpression (value = 2.2) + ULiteralExpression (value = 2) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (withDefault)) + USimpleNameReferenceExpression (identifier = withDefault) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "bbb") + UQualifiedReferenceExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "abc") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (withReceiver)) + USimpleNameReferenceExpression (identifier = withReceiver) + ULiteralExpression (value = 1) + ULiteralExpression (value = 1.2) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = Math) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (atan2)) + USimpleNameReferenceExpression (identifier = atan2) + ULiteralExpression (value = 1.3) + ULiteralExpression (value = 3.4) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (unresolvedMethod)) + USimpleNameReferenceExpression (identifier = ) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "param1") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "param2") + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = java) + USimpleNameReferenceExpression (identifier = lang) + USimpleNameReferenceExpression (identifier = String) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 4)) + UIdentifier (Identifier (format)) + USimpleNameReferenceExpression (identifier = format) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "%i %i %i") + ULiteralExpression (value = 1) + ULiteralExpression (value = 2) + ULiteralExpression (value = 3) + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = java) + USimpleNameReferenceExpression (identifier = lang) + USimpleNameReferenceExpression (identifier = String) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (format)) + USimpleNameReferenceExpression (identifier = format) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "%i %i %i") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 3)) + UIdentifier (Identifier (arrayOf)) + USimpleNameReferenceExpression (identifier = arrayOf) + ULiteralExpression (value = 1) + ULiteralExpression (value = 2) + ULiteralExpression (value = 3) + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = java) + USimpleNameReferenceExpression (identifier = lang) + USimpleNameReferenceExpression (identifier = String) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 3)) + UIdentifier (Identifier (format)) + USimpleNameReferenceExpression (identifier = format) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "%i %i %i") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 3)) + UIdentifier (Identifier (arrayOf)) + USimpleNameReferenceExpression (identifier = arrayOf) + ULiteralExpression (value = 1) + ULiteralExpression (value = 2) + ULiteralExpression (value = 3) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 3)) + UIdentifier (Identifier (arrayOf)) + USimpleNameReferenceExpression (identifier = arrayOf) + ULiteralExpression (value = 4) + ULiteralExpression (value = 5) + ULiteralExpression (value = 6) + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = java) + USimpleNameReferenceExpression (identifier = lang) + USimpleNameReferenceExpression (identifier = String) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (format)) + USimpleNameReferenceExpression (identifier = format) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "%i %i %i") + UQualifiedReferenceExpression + UQualifiedReferenceExpression + UPolyadicExpression (value = "") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (chunked)) + USimpleNameReferenceExpression (identifier = chunked) + ULiteralExpression (value = 2) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toTypedArray)) + USimpleNameReferenceExpression (identifier = toTypedArray) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (with)) + USimpleNameReferenceExpression (identifier = with) + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = ) + ULambdaExpression + UBlockExpression + UQualifiedReferenceExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "def") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (with2Receivers)) + USimpleNameReferenceExpression (identifier = with2Receivers) + ULiteralExpression (value = 8) + ULiteralExpression (value = 7.0) + UAnnotationMethod (name = objectLiteral) + UBlockExpression + UObjectLiteralExpression + ULiteralExpression (value = 1) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "foo") + UClass (name = null) + UAnnotationMethod (name = ParametersDisorderKt$objectLiteral$1) + UClass (name = A) + UAnnotationMethod (name = with2Receivers) + UParameter (name = $receiver) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UAnnotationMethod (name = A) + UClass (name = Parent) + UAnnotationMethod (name = Parent) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) diff --git a/plugins/uast-kotlin/testData/PropertyDelegate.log.txt.191 b/plugins/uast-kotlin/testData/PropertyDelegate.log.txt.191 new file mode 100644 index 00000000000..5bdbbbf46e2 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyDelegate.log.txt.191 @@ -0,0 +1,35 @@ +UFile (package = ) + UClass (name = PropertyDelegateKt) + UField (name = sdCardPath$delegate) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (lazy)) + USimpleNameReferenceExpression (identifier = lazy) + ULambdaExpression + UBlockExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "/sdcard") + UField (name = annotatedDelegate$delegate) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UAnnotation (fqName = kotlin.Suppress) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (lazy)) + USimpleNameReferenceExpression (identifier = lazy) + ULambdaExpression + UBlockExpression + UBinaryExpression (operator = +) + ULiteralExpression (value = 1) + ULiteralExpression (value = 1) + UAnnotationMethod (name = getSdCardPath) + UAnnotationMethod (name = localPropertyTest) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = sdCardPathLocal) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (lazy)) + USimpleNameReferenceExpression (identifier = lazy) + ULambdaExpression + UBlockExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "/sdcard") + UAnnotationMethod (name = getAnnotatedDelegate) diff --git a/plugins/uast-kotlin/testData/PropertyInitializer.log.txt.191 b/plugins/uast-kotlin/testData/PropertyInitializer.log.txt.191 new file mode 100644 index 00000000000..3cbeec00699 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializer.log.txt.191 @@ -0,0 +1,18 @@ +UFile (package = ) + UClass (name = TestPropertyInitializer) + UField (name = withSetter) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "/sdcard") + UAnnotationMethod (name = getWithSetter) + UBlockExpression + UReturnExpression + 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/PropertyInitializerWithoutSetter.log.txt.191 b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log.txt.191 new file mode 100644 index 00000000000..5934da70a88 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyInitializerWithoutSetter.log.txt.191 @@ -0,0 +1,13 @@ +UFile (package = ) + UClass (name = PropertyInitializerWithoutSetterKt) + UField (name = withoutSetter) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "/sdcard") + UAnnotationMethod (name = getWithoutSetter) + UBlockExpression + UReturnExpression + USimpleNameReferenceExpression (identifier = field) + UAnnotationMethod (name = setWithoutSetter) + UParameter (name = p) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) diff --git a/plugins/uast-kotlin/testData/Simple.log.txt.191 b/plugins/uast-kotlin/testData/Simple.log.txt.191 new file mode 100644 index 00000000000..2ad9c6e3273 --- /dev/null +++ b/plugins/uast-kotlin/testData/Simple.log.txt.191 @@ -0,0 +1,15 @@ +UFile (package = ) + UClass (name = Simple) + UField (name = property) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Mary") + UAnnotationMethod (name = method) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Hello, world!") + UAnnotationMethod (name = getProperty) + UAnnotationMethod (name = Simple) diff --git a/plugins/uast-kotlin/testData/Simple.values.txt.191 b/plugins/uast-kotlin/testData/Simple.values.txt.191 new file mode 100644 index 00000000000..2b28dd40b63 --- /dev/null +++ b/plugins/uast-kotlin/testData/Simple.values.txt.191 @@ -0,0 +1,15 @@ +UFile (package = ) [public final class Simple {...] + UClass (name = Simple) [public final class Simple {...}] + UField (name = property) [@org.jetbrains.annotations.NotNull private final var property: java.lang.String = "Mary"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) ["Mary"] = "Mary" + 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("Hello, world!")("Hello, world!") + UPolyadicExpression (operator = +) ["Hello, world!"] = "Hello, world!" + 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/SimpleScript.log.txt.191 b/plugins/uast-kotlin/testData/SimpleScript.log.txt.191 new file mode 100644 index 00000000000..c3129caabe9 --- /dev/null +++ b/plugins/uast-kotlin/testData/SimpleScript.log.txt.191 @@ -0,0 +1,53 @@ +UFile (package = ) + UClass (name = SimpleScript) + UAnnotationMethod (name = getBarOrNull) + UParameter (name = flag) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + UIfExpression + USimpleNameReferenceExpression (identifier = flag) + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (Bar)) + USimpleNameReferenceExpression (identifier = ) + ULiteralExpression (value = 42) + ULiteralExpression (value = null) + UAnnotationMethod (name = SimpleScript) + UParameter (name = p) + UAnnotation (fqName = null) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Hello World!") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (getBarOrNull)) + USimpleNameReferenceExpression (identifier = getBarOrNull) + ULiteralExpression (value = true) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "Goodbye World!") + UClass (name = Bar) + UField (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = 0) + UField (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UAnnotationMethod (name = getB) + UAnnotationMethod (name = getAPlusB) + UBlockExpression + UReturnExpression + UBinaryExpression (operator = +) + USimpleNameReferenceExpression (identifier = a) + USimpleNameReferenceExpression (identifier = b) + UAnnotationMethod (name = getA) + UAnnotationMethod (name = Bar) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UClass (name = Baz) + UAnnotationMethod (name = doSomething) + UBlockExpression + UAnnotationMethod (name = Baz) diff --git a/plugins/uast-kotlin/testData/StringTemplate.log.txt.191 b/plugins/uast-kotlin/testData/StringTemplate.log.txt.191 new file mode 100644 index 00000000000..0f11d97a2db --- /dev/null +++ b/plugins/uast-kotlin/testData/StringTemplate.log.txt.191 @@ -0,0 +1,26 @@ +UFile (package = ) + UClass (name = StringTemplateKt) + UField (name = foo) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "lorem") + UField (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "ipsum") + UField (name = baz) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + 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.types.txt.191 b/plugins/uast-kotlin/testData/StringTemplate.types.txt.191 new file mode 100644 index 00000000000..a45f71b0e3c --- /dev/null +++ b/plugins/uast-kotlin/testData/StringTemplate.types.txt.191 @@ -0,0 +1,26 @@ +UFile (package = ) [public final class StringTemplateKt {...] + UClass (name = StringTemplateKt) [public final class StringTemplateKt {...}] + UField (name = foo) [@org.jetbrains.annotations.NotNull private static final var foo: java.lang.String = "lorem"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) ["lorem"] : PsiType:String + ULiteralExpression (value = "lorem") ["lorem"] : PsiType:String + UField (name = bar) [@org.jetbrains.annotations.NotNull private static final var bar: java.lang.String = "ipsum"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) ["ipsum"] : PsiType:String + ULiteralExpression (value = "ipsum") ["ipsum"] : PsiType:String + UField (name = baz) [@org.jetbrains.annotations.NotNull private static final var baz: java.lang.String = "dolor"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) ["dolor"] : PsiType:String + ULiteralExpression (value = "dolor") ["dolor"] : PsiType:String + UField (name = foobarbaz) [@org.jetbrains.annotations.NotNull private static final var foobarbaz: java.lang.String = foo + " " + bar + " " + baz] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) [foo + " " + bar + " " + baz] : PsiType:String + USimpleNameReferenceExpression (identifier = foo) [foo] : PsiType:String + ULiteralExpression (value = " ") [" "] : PsiType:String + USimpleNameReferenceExpression (identifier = bar) [bar] : PsiType:String + ULiteralExpression (value = " ") [" "] : PsiType:String + USimpleNameReferenceExpression (identifier = baz) [baz] : PsiType:String + UAnnotationMethod (name = getFoo) [public static final fun getFoo() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = getBar) [public static final fun getBar() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = getBaz) [public static final fun getBaz() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = getFoobarbaz) [public static final fun getFoobarbaz() : java.lang.String = UastEmptyExpression] diff --git a/plugins/uast-kotlin/testData/StringTemplateComplex.log.txt.191 b/plugins/uast-kotlin/testData/StringTemplateComplex.log.txt.191 new file mode 100644 index 00000000000..8fef37332db --- /dev/null +++ b/plugins/uast-kotlin/testData/StringTemplateComplex.log.txt.191 @@ -0,0 +1,80 @@ +UFile (package = ) + UClass (name = StringTemplateComplexKt) + UField (name = muchRecur) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + UPolyadicExpression (operator = +) + UPolyadicExpression (operator = +) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "abc") + UField (name = case4) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "a ") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "literal") + ULiteralExpression (value = " z") + UField (name = case5) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "a ") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "literal") + ULiteralExpression (value = " ") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "literal") + ULiteralExpression (value = " z") + UField (name = literalInLiteral) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "a ") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "literal") + USimpleNameReferenceExpression (identifier = case4) + ULiteralExpression (value = " z") + UField (name = literalInLiteral2) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "a ") + UQualifiedReferenceExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "literal") + USimpleNameReferenceExpression (identifier = case4) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (repeat)) + USimpleNameReferenceExpression (identifier = repeat) + ULiteralExpression (value = 4) + ULiteralExpression (value = " z") + UAnnotationMethod (name = getMuchRecur) + UAnnotationMethod (name = getCase4) + UAnnotationMethod (name = getCase5) + UAnnotationMethod (name = getLiteralInLiteral) + UAnnotationMethod (name = getLiteralInLiteral2) + UAnnotationMethod (name = simpleForTemplate) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + ULiteralExpression (value = 0) + UBlockExpression + UReturnExpression + UPolyadicExpression (operator = +) + USimpleNameReferenceExpression (identifier = i) + UAnnotationMethod (name = foo) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println) + UPolyadicExpression (operator = +) + USimpleNameReferenceExpression (identifier = baz) + UDeclarationsExpression + ULocalVariable (name = template1) + UPolyadicExpression (operator = +) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (simpleForTemplate)) + USimpleNameReferenceExpression (identifier = simpleForTemplate) + UDeclarationsExpression + ULocalVariable (name = template2) + UPolyadicExpression (operator = +) + ULiteralExpression (value = ".") + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (simpleForTemplate)) + USimpleNameReferenceExpression (identifier = simpleForTemplate) diff --git a/plugins/uast-kotlin/testData/StringTemplateComplex.types.txt.191 b/plugins/uast-kotlin/testData/StringTemplateComplex.types.txt.191 new file mode 100644 index 00000000000..e9d477a989d --- /dev/null +++ b/plugins/uast-kotlin/testData/StringTemplateComplex.types.txt.191 @@ -0,0 +1,80 @@ +UFile (package = ) [public final class StringTemplateComplexKt {...] + UClass (name = StringTemplateComplexKt) [public final class StringTemplateComplexKt {...}] + UField (name = muchRecur) [@org.jetbrains.annotations.NotNull private static final var muchRecur: java.lang.String = "abc"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) ["abc"] : PsiType:String + UPolyadicExpression (operator = +) ["abc"] : PsiType:String + UPolyadicExpression (operator = +) ["abc"] : PsiType:String + UPolyadicExpression (operator = +) ["abc"] : PsiType:String + ULiteralExpression (value = "abc") ["abc"] : PsiType:String + UField (name = case4) [@org.jetbrains.annotations.NotNull private static final var case4: java.lang.String = "a " + "literal" + " z"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) ["a " + "literal" + " z"] : PsiType:String + ULiteralExpression (value = "a ") ["a "] : PsiType:String + UPolyadicExpression (operator = +) ["literal"] : PsiType:String + ULiteralExpression (value = "literal") ["literal"] : PsiType:String + ULiteralExpression (value = " z") [" z"] : PsiType:String + UField (name = case5) [@org.jetbrains.annotations.NotNull private static final var case5: java.lang.String = "a " + "literal" + " " + "literal" + " z"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) ["a " + "literal" + " " + "literal" + " z"] : PsiType:String + ULiteralExpression (value = "a ") ["a "] : PsiType:String + UPolyadicExpression (operator = +) ["literal"] : PsiType:String + ULiteralExpression (value = "literal") ["literal"] : PsiType:String + ULiteralExpression (value = " ") [" "] : PsiType:String + UPolyadicExpression (operator = +) ["literal"] : PsiType:String + ULiteralExpression (value = "literal") ["literal"] : PsiType:String + ULiteralExpression (value = " z") [" z"] : PsiType:String + UField (name = literalInLiteral) [@org.jetbrains.annotations.NotNull private static final var literalInLiteral: java.lang.String = "a " + "literal" + case4 + " z"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) ["a " + "literal" + case4 + " z"] : PsiType:String + ULiteralExpression (value = "a ") ["a "] : PsiType:String + UPolyadicExpression (operator = +) ["literal" + case4] : PsiType:String + ULiteralExpression (value = "literal") ["literal"] : PsiType:String + USimpleNameReferenceExpression (identifier = case4) [case4] : PsiType:String + ULiteralExpression (value = " z") [" z"] : PsiType:String + UField (name = literalInLiteral2) [@org.jetbrains.annotations.NotNull private static final var literalInLiteral2: java.lang.String = "a " + "literal" + case4.repeat(4) + " z"] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UPolyadicExpression (operator = +) ["a " + "literal" + case4.repeat(4) + " z"] : PsiType:String + ULiteralExpression (value = "a ") ["a "] : PsiType:String + UQualifiedReferenceExpression ["literal" + case4.repeat(4)] : PsiType:String + UPolyadicExpression (operator = +) ["literal" + case4] : PsiType:String + ULiteralExpression (value = "literal") ["literal"] : PsiType:String + USimpleNameReferenceExpression (identifier = case4) [case4] : PsiType:String + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [repeat(4)] : PsiType:String + UIdentifier (Identifier (repeat)) [UIdentifier (Identifier (repeat))] + USimpleNameReferenceExpression (identifier = repeat) [repeat] : PsiType:String + ULiteralExpression (value = 4) [4] : PsiType:int + ULiteralExpression (value = " z") [" z"] : PsiType:String + UAnnotationMethod (name = getMuchRecur) [public static final fun getMuchRecur() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = getCase4) [public static final fun getCase4() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = getCase5) [public static final fun getCase5() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = getLiteralInLiteral) [public static final fun getLiteralInLiteral() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = getLiteralInLiteral2) [public static final fun getLiteralInLiteral2() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = simpleForTemplate) [public static final fun simpleForTemplate(@org.jetbrains.annotations.NotNull i: int) : java.lang.String {...}] + UParameter (name = i) [@org.jetbrains.annotations.NotNull var i: int = 0] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + ULiteralExpression (value = 0) [0] : PsiType:int + UBlockExpression [{...}] + UReturnExpression [return i] + UPolyadicExpression (operator = +) [i] : PsiType:String + USimpleNameReferenceExpression (identifier = i) [i] : PsiType:int + UAnnotationMethod (name = foo) [public static final fun foo() : void {...}] + UBlockExpression [{...}] : PsiType:void + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [println(baz)] : PsiType:void + UIdentifier (Identifier (println)) [UIdentifier (Identifier (println))] + USimpleNameReferenceExpression (identifier = println) [println] : PsiType:void + UPolyadicExpression (operator = +) [baz] : PsiType:String + USimpleNameReferenceExpression (identifier = baz) [baz] + UDeclarationsExpression [var template1: java.lang.String = simpleForTemplate()] + ULocalVariable (name = template1) [var template1: java.lang.String = simpleForTemplate()] + UPolyadicExpression (operator = +) [simpleForTemplate()] : PsiType:String + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [simpleForTemplate()] : PsiType:String + UIdentifier (Identifier (simpleForTemplate)) [UIdentifier (Identifier (simpleForTemplate))] + USimpleNameReferenceExpression (identifier = simpleForTemplate) [simpleForTemplate] : PsiType:String + UDeclarationsExpression [var template2: java.lang.String = "." + simpleForTemplate()] + ULocalVariable (name = template2) [var template2: java.lang.String = "." + simpleForTemplate()] + UPolyadicExpression (operator = +) ["." + simpleForTemplate()] : PsiType:String + ULiteralExpression (value = ".") ["."] : PsiType:String + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [simpleForTemplate()] : PsiType:String + UIdentifier (Identifier (simpleForTemplate)) [UIdentifier (Identifier (simpleForTemplate))] + USimpleNameReferenceExpression (identifier = simpleForTemplate) [simpleForTemplate] : PsiType:String diff --git a/plugins/uast-kotlin/testData/SuperCalls.log.txt.191 b/plugins/uast-kotlin/testData/SuperCalls.log.txt.191 new file mode 100644 index 00000000000..abc57fa81d4 --- /dev/null +++ b/plugins/uast-kotlin/testData/SuperCalls.log.txt.191 @@ -0,0 +1,114 @@ +UFile (package = ) + UClass (name = SuperCallsKt) + UField (name = anon) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UObjectLiteralExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "textForAnon") + UClass (name = null) + UAnnotationMethod (name = bar) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (cons)) + USimpleNameReferenceExpression (identifier = cons) + UObjectLiteralExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "inner literal") + UClass (name = null) + UAnnotationMethod (name = SuperCallsKt$anon$1$bar$1) + UAnnotationMethod (name = SuperCallsKt$anon$1) + UClass (name = innerObject) + UField (name = INSTANCE) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UAnnotationMethod (name = innerObject) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = ) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "inner object") + UClass (name = InnerClass) + UAnnotationMethod (name = InnerClass) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = ) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "inner class") + UAnnotationMethod (name = getAnon) + UAnnotationMethod (name = cons) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UClass (name = A) + UField (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UAnnotationMethod (name = foo) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UAnnotationMethod (name = getStr) + UAnnotationMethod (name = A) + UParameter (name = str) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UAnnotationMethod (name = A) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (this)) + USimpleNameReferenceExpression (identifier = ) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = i) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toString)) + USimpleNameReferenceExpression (identifier = toString) + UClass (name = B) + UAnnotationMethod (name = B) + UParameter (name = param) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = ) + USimpleNameReferenceExpression (identifier = param) + UClass (name = C) + UAnnotationMethod (name = foo) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UQualifiedReferenceExpression + USuperExpression (label = null) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (foo)) + USimpleNameReferenceExpression (identifier = foo) + USimpleNameReferenceExpression (identifier = a) + UAnnotationMethod (name = C) + UParameter (name = p) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (super)) + USimpleNameReferenceExpression (identifier = ) + USimpleNameReferenceExpression (identifier = p) + UAnnotationMethod (name = C) + UParameter (name = i) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (super)) + USimpleNameReferenceExpression (identifier = ) + USimpleNameReferenceExpression (identifier = i) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println) + UClass (name = O) + UField (name = INSTANCE) + UAnnotation (fqName = null) + UAnnotationMethod (name = O) + UBlockExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = ) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "text") diff --git a/plugins/uast-kotlin/testData/UnexpectedContainerException.log.txt.191 b/plugins/uast-kotlin/testData/UnexpectedContainerException.log.txt.191 new file mode 100644 index 00000000000..fa62a1d85f8 --- /dev/null +++ b/plugins/uast-kotlin/testData/UnexpectedContainerException.log.txt.191 @@ -0,0 +1,39 @@ +UFile (package = ) + UClass (name = Callback) + UAnnotationMethod (name = onError) + UParameter (name = throwable) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UClass (name = Model) + UAnnotationMethod (name = crashMe) + UParameter (name = clazz) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UParameter (name = factory) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UThrowExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (UnsupportedOperationException)) + USimpleNameReferenceExpression (identifier = ) + UAnnotationMethod (name = Model) + UBlockExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (crashMe)) + USimpleNameReferenceExpression (identifier = crashMe) + UQualifiedReferenceExpression + UClassLiteralExpression + USimpleNameReferenceExpression (identifier = java) + ULambdaExpression + UBlockExpression + UObjectLiteralExpression + UClass (name = null) + UAnnotationMethod (name = onError) + UParameter (name = throwable) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UThrowExpression + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) + UIdentifier (Identifier (UnsupportedOperationException)) + USimpleNameReferenceExpression (identifier = ) + UPolyadicExpression (value = "") + UAnnotationMethod (name = Model$1$1) diff --git a/plugins/uast-kotlin/testData/UnexpectedContainerException.types.txt.191 b/plugins/uast-kotlin/testData/UnexpectedContainerException.types.txt.191 new file mode 100644 index 00000000000..5aced0bb76a --- /dev/null +++ b/plugins/uast-kotlin/testData/UnexpectedContainerException.types.txt.191 @@ -0,0 +1,39 @@ +UFile (package = ) [public abstract interface Callback {...] + UClass (name = Callback) [public abstract interface Callback {...}] + UAnnotationMethod (name = onError) [public abstract fun onError(@org.jetbrains.annotations.NotNull throwable: java.lang.Throwable) : void = UastEmptyExpression] + UParameter (name = throwable) [@org.jetbrains.annotations.NotNull 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(@org.jetbrains.annotations.NotNull clazz: java.lang.Class, @org.jetbrains.annotations.NotNull factory: kotlin.jvm.functions.Function0) : void {...}] + UParameter (name = clazz) [@org.jetbrains.annotations.NotNull var clazz: java.lang.Class] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UParameter (name = factory) [@org.jetbrains.annotations.NotNull 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 + UAnnotationMethod (name = Model) [public fun Model() {...}] + UBlockExpression [{...}] + UBlockExpression [{...}] : PsiType:void + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) [crashMe(Callback.java, { ...})] : PsiType:void + UIdentifier (Identifier (crashMe)) [UIdentifier (Identifier (crashMe))] + USimpleNameReferenceExpression (identifier = crashMe) [crashMe] : PsiType:void + 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 : Callback {...}] + UAnnotationMethod (name = onError) [public fun onError(@org.jetbrains.annotations.NotNull throwable: java.lang.Throwable) : void {...}] + UParameter (name = throwable) [@org.jetbrains.annotations.NotNull 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 + UPolyadicExpression (value = "") [""] : PsiType:String + UAnnotationMethod (name = Model$1$1) [fun Model$1$1() = UastEmptyExpression] diff --git a/plugins/uast-kotlin/testData/WhenAndDestructing.log.txt.191 b/plugins/uast-kotlin/testData/WhenAndDestructing.log.txt.191 new file mode 100644 index 00000000000..53e426a1acd --- /dev/null +++ b/plugins/uast-kotlin/testData/WhenAndDestructing.log.txt.191 @@ -0,0 +1,49 @@ +UFile (package = ) + UClass (name = WhenAndDestructingKt) + UAnnotationMethod (name = getElementsAdditionalResolve) + UParameter (name = string) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = arr) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) + UIdentifier (Identifier (listOf)) + USimpleNameReferenceExpression (identifier = listOf) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "1") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "2") + USwitchExpression + USimpleNameReferenceExpression (identifier = string) + UExpressionList (when) + USwitchClauseExpressionWithBody + UPolyadicExpression (operator = +) + ULiteralExpression (value = "aaaa") + UExpressionList (when_entry) + UReturnExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "bindingContext") + UBreakExpression (label = null) + USwitchClauseExpressionWithBody + UExpressionList (when_entry) + UDeclarationsExpression + ULocalVariable (name = var837f1e82) + UAnnotation (fqName = null) + USimpleNameReferenceExpression (identifier = arr) + ULocalVariable (name = bindingContext) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var837f1e82) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component1)) + USimpleNameReferenceExpression (identifier = ) + ULocalVariable (name = statementFilter) + UAnnotation (fqName = null) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var837f1e82) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component2)) + USimpleNameReferenceExpression (identifier = ) + UReturnExpression + USimpleNameReferenceExpression (identifier = bindingContext) + UBreakExpression (label = null) diff --git a/plugins/uast-kotlin/testData/WhenIs.log.txt.191 b/plugins/uast-kotlin/testData/WhenIs.log.txt.191 new file mode 100644 index 00000000000..07d3e122d9e --- /dev/null +++ b/plugins/uast-kotlin/testData/WhenIs.log.txt.191 @@ -0,0 +1,25 @@ +UFile (package = ) + UClass (name = WhenIsKt) + UAnnotationMethod (name = foo) + UParameter (name = bar) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + 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) + UPolyadicExpression (operator = +) + ULiteralExpression (value = "") + UBreakExpression (label = null) diff --git a/plugins/uast-kotlin/testData/WhenStringLiteral.log.txt.191 b/plugins/uast-kotlin/testData/WhenStringLiteral.log.txt.191 new file mode 100644 index 00000000000..67cd36776dc --- /dev/null +++ b/plugins/uast-kotlin/testData/WhenStringLiteral.log.txt.191 @@ -0,0 +1,38 @@ +UFile (package = ) + UClass (name = WhenStringLiteralKt) + UField (name = a) + UAnnotation (fqName = org.jetbrains.annotations.Nullable) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (readLine)) + USimpleNameReferenceExpression (identifier = readLine) + UField (name = b) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + USwitchExpression + USimpleNameReferenceExpression (identifier = a) + UExpressionList (when) + USwitchClauseExpressionWithBody + UPolyadicExpression (operator = +) + ULiteralExpression (value = "abc") + UExpressionList (when_entry) + ULiteralExpression (value = 1) + UBreakExpression (label = null) + USwitchClauseExpressionWithBody + UPolyadicExpression (operator = +) + ULiteralExpression (value = "def") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "ghi") + UExpressionList (when_entry) + ULiteralExpression (value = 2) + UBreakExpression (label = null) + USwitchClauseExpressionWithBody + UExpressionList (when_entry) + ULiteralExpression (value = 3) + UBreakExpression (label = null) + UAnnotationMethod (name = getA) + UAnnotationMethod (name = getB) + UAnnotationMethod (name = ) + UBlockExpression + UPolyadicExpression (operator = +) + ULiteralExpression (value = "abc1") + UPolyadicExpression (operator = +) + ULiteralExpression (value = "def1") diff --git a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt.191 b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt.191 index 2d88b3a850c..4a651f2a797 100644 --- a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt.191 +++ b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt.191 @@ -11,13 +11,13 @@ import org.jetbrains.kotlin.utils.addToStdlib.assertedCast import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.sure import org.jetbrains.uast.* +import org.jetbrains.uast.expressions.UInjectionHost import org.jetbrains.uast.kotlin.KotlinUastLanguagePlugin import org.jetbrains.uast.test.env.kotlin.findElementByText import org.jetbrains.uast.test.env.kotlin.findElementByTextFromPsi import org.jetbrains.uast.visitor.AbstractUastVisitor import org.junit.Assert import org.junit.Test -import kotlin.test.fail as kfail class KotlinUastApiTest : AbstractKotlinUastTest() { @@ -174,21 +174,21 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { fun testWhenStringLiteral() { doTest("WhenStringLiteral") { _, file -> - file.findElementByTextFromPsi("abc").let { literalExpression -> + file.findElementByTextFromPsi("\"abc\"").let { literalExpression -> val psi = literalExpression.psi!! - Assert.assertTrue(psi is KtLiteralStringTemplateEntry) + Assert.assertTrue(psi is KtStringTemplateExpression) UsefulTestCase.assertInstanceOf(literalExpression.uastParent, USwitchClauseExpressionWithBody::class.java) } - file.findElementByTextFromPsi("def").let { literalExpression -> + file.findElementByTextFromPsi("\"def\"").let { literalExpression -> val psi = literalExpression.psi!! - Assert.assertTrue(psi is KtLiteralStringTemplateEntry) + Assert.assertTrue(psi is KtStringTemplateExpression) UsefulTestCase.assertInstanceOf(literalExpression.uastParent, USwitchClauseExpressionWithBody::class.java) } - file.findElementByTextFromPsi("def1").let { literalExpression -> + file.findElementByTextFromPsi("\"def1\"").let { literalExpression -> val psi = literalExpression.psi!! - Assert.assertTrue(psi is KtLiteralStringTemplateEntry) + Assert.assertTrue(psi is KtStringTemplateExpression) UsefulTestCase.assertInstanceOf(literalExpression.uastParent, UBlockExpression::class.java) } @@ -316,44 +316,6 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { } } - @Test - fun testNestedAnnotationParameters() = doTest("AnnotationComplex") { _, file -> - - fun UFile.annotationAndParam(refText: String, check: (PsiAnnotation, String?) -> Unit) { - findElementByTextFromPsi(refText) - .let { expression -> - val (annotation: PsiAnnotation, paramname: String?) = - getContainingAnnotationEntry(expression) ?: kfail("annotation not found for '$refText' ($expression)") - check(annotation, paramname) - } - } - - file.annotationAndParam("sv1") { annotation, paramname -> - assertEquals("Annotation", annotation.qualifiedName) - assertEquals(null, paramname) - } - file.annotationAndParam("sv2") { annotation, paramname -> - assertEquals("Annotation", annotation.qualifiedName) - assertEquals(null, paramname) - } - file.annotationAndParam("sar1") { annotation, paramname -> - assertEquals("Annotation", annotation.qualifiedName) - assertEquals("strings", paramname) - } - file.annotationAndParam("sar2") { annotation, paramname -> - assertEquals("Annotation", annotation.qualifiedName) - assertEquals("strings", paramname) - } - file.annotationAndParam("[sar]1") { annotation, paramname -> - assertEquals("Annotation", annotation.qualifiedName) - assertEquals("strings", paramname) - } - file.annotationAndParam("[sar]2") { annotation, paramname -> - assertEquals("Annotation", annotation.qualifiedName) - assertEquals("strings", paramname) - } - } - @Test fun testParametersDisorder() = doTest("ParametersDisorder") { _, file ->