191: Uast: making KotlinStringTemplateUPolyadicExpression implement UInjectionHost (KT-27283)

This commit is contained in:
Nicolay Mitropolsky
2019-01-29 12:35:31 +03:00
parent 6f04deff0e
commit 56dfde0428
30 changed files with 1918 additions and 45 deletions
@@ -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<KotlinConstructorUMethod>()?.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<KtPrimaryConstructor>() ?: 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<UAnnotation>
get() {
val annotatedExpression = psi?.parent as? KtAnnotatedExpression ?: return emptyList()
return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) }
}
}
@@ -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<DeclarationDescriptor>
}
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<out UElement>?): UElement? {
if (!element.isJvmElement) return null
return convertDeclarationOrElement(element, parent, requiredType)
}
override fun convertElementWithParent(element: PsiElement, requiredType: Class<out UElement>?): 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<out UElement>?): 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<out UElement>?): UElement? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? = { ctor(element as P, givenParent) }
fun <P : PsiElement, K : KtElement> buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? =
{ ctor(element as P, ktElement, givenParent) }
fun <P : PsiElement, K : KtElement> 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<UMethod>(build(KotlinUMethod.Companion::create)) // .Companion is needed because of KT-13934
is KtLightClass -> when (original.kotlinOrigin) {
is KtEnumEntry -> el<UEnumConstant> {
convertEnumEntry(original.kotlinOrigin as KtEnumEntry, givenParent)
}
else -> el<UClass> { KotlinUClass.create(original, givenParent) }
}
is KtLightFieldImpl.KtLightEnumConstant -> el<UEnumConstant>(buildKtOpt(original.kotlinOrigin, ::KotlinUEnumConstant))
is KtLightField -> el<UField>(buildKtOpt(original.kotlinOrigin, ::KotlinUField))
is KtLightParameter -> el<UParameter>(buildKtOpt(original.kotlinOrigin, ::KotlinUParameter))
is UastKotlinPsiParameter -> el<UParameter>(buildKt(original.ktParameter, ::KotlinUParameter))
is UastKotlinPsiVariable -> el<UVariable>(buildKt(original.ktElement, ::KotlinUVariable))
is KtEnumEntry -> el<UEnumConstant> {
convertEnumEntry(original, givenParent)
}
is KtClassOrObject -> el<UClass> {
original.toLightClass()?.let { lightClass ->
KotlinUClass.create(lightClass, givenParent)
}
}
is KtFunction ->
if (original.isLocal) {
el<ULambdaExpression> {
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<UMethod> {
val lightMethod = LightClassUtil.getLightClassMethod(original) ?: return null
convertDeclaration(lightMethod, givenParent, requiredType)
}
}
is KtPropertyAccessor -> el<UMethod> {
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<UParameter> {
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<UFile> { KotlinUFile(original, this@KotlinUastLanguagePlugin) }
is FakeFileForLightClass -> el<UFile> { KotlinUFile(original.navigationElement, this@KotlinUastLanguagePlugin) }
is KtAnnotationEntry -> el<UAnnotation>(build(::KotlinUAnnotation))
is KtCallExpression ->
if (requiredType != null && UAnnotation::class.java.isAssignableFrom(requiredType)) {
el<UAnnotation> { 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 <reified ActualT : UElement> Class<out UElement>?.el(f: () -> UElement?): UElement? {
return if (this == null || isAssignableFrom(ActualT::class.java)) f() else null
}
internal inline fun <reified ActualT : UElement> Class<out UElement>?.expr(f: () -> UExpression?): UExpression? {
return if (this == null || isAssignableFrom(ActualT::class.java)) f() else null
}
private fun convertNonLocalProperty(property: KtProperty,
givenParent: UElement?,
requiredType: Class<out UElement>?): UElement? {
val methods = LightClassUtil.getLightClassPropertyMethods(property)
return methods.backingField?.let { backingField ->
with(requiredType) {
el<UField> { 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<out UElement>?): UElement? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? {
return { ctor(element as P, givenParent) }
}
return with (requiredType) { when (element) {
is KtParameterList -> el<UDeclarationsExpression> {
val declarationsExpression = KotlinUDeclarationsExpression(givenParent)
declarationsExpression.apply {
declarations = element.parameters.mapIndexed { i, p ->
KotlinUParameter(UastKotlinPsiParameter.create(p, element, declarationsExpression, i), p, this)
}
}
}
is KtClassBody -> el<UExpressionList>(build(KotlinUExpressionList.Companion::createClassBody))
is KtCatchClause -> el<UCatchClause>(build(::KotlinUCatchClause))
is KtVariableDeclaration ->
if (element is KtProperty && !element.isLocal) {
el<UField> {
LightClassUtil.getLightClassBackingField(element)?.let {
KotlinUField(it, element, givenParent)
}
}
}
else {
el<UVariable> {
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<UExpression> { UastEmptyExpression(givenParent) }
}
}
is KtLiteralStringTemplateEntry, is KtEscapeStringTemplateEntry -> el<ULiteralExpression>(build(::KotlinStringULiteralExpression))
is KtStringTemplateEntry -> element.expression?.let { convertExpression(it, givenParent, requiredType) } ?: expr<UExpression> { UastEmptyExpression }
is KtWhenEntry -> el<USwitchClauseExpressionWithBody>(build(::KotlinUSwitchEntry))
is KtWhenCondition -> convertWhenCondition(element, givenParent, requiredType)
is KtTypeReference -> el<UTypeReferenceExpression> { LazyKotlinUTypeReferenceExpression(element, givenParent) }
is KtConstructorDelegationCall ->
el<UCallExpression> { KotlinUFunctionCallExpression(element, givenParent) }
is KtSuperTypeCallEntry ->
el<UExpression> {
(element.getParentOfType<KtClassOrObject>(true)?.parent as? KtObjectLiteralExpression)
?.toUElementOfType<UExpression>()
?: KotlinUFunctionCallExpression(element, givenParent)
}
is KtImportDirective -> el<UImportStatement>(build(::KotlinUImportStatement))
else -> {
if (element is LeafPsiElement) {
if (element.elementType in identifiersTokens)
if (element.elementType != KtTokens.OBJECT_KEYWORD || element.getParentOfType<KtObjectDeclaration>(false)?.nameIdentifier == null)
el<UIdentifier>(build(::KotlinUIdentifier))
else null
else if (element.elementType in KtTokens.OPERATIONS && element.parent is KtOperationReferenceExpression)
el<UIdentifier>(build(::KotlinUIdentifier))
else if (element.elementType == KtTokens.LBRACKET && element.parent is KtCollectionLiteralExpression)
el<UIdentifier> {
UIdentifier(
element,
KotlinUCollectionLiteralExpression(
element.parent as KtCollectionLiteralExpression,
null
)
)
}
else null
} else null
}
}}
}
internal fun convertEntry(entry: KtStringTemplateEntry,
givenParent: UElement?,
requiredType: Class<out UElement>? = null): UExpression? {
return with(requiredType) {
if (entry is KtStringTemplateEntryWithExpression) {
expr<UExpression> {
KotlinConverter.convertOrEmpty(entry.expression, givenParent)
}
}
else {
expr<ULiteralExpression> {
if (entry is KtEscapeStringTemplateEntry)
KotlinStringULiteralExpression(entry, givenParent, entry.unescapedValue)
else
KotlinStringULiteralExpression(entry, givenParent)
}
}
}
}
internal fun convertExpression(expression: KtExpression,
givenParent: UElement?,
requiredType: Class<out UElement>? = null): UExpression? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UExpression): () -> UExpression? {
return { ctor(expression as P, givenParent) }
}
return with (requiredType) { when (expression) {
is KtVariableDeclaration -> expr<UDeclarationsExpression>(build(::convertVariablesDeclaration))
is KtStringTemplateExpression -> expr<UInjectionHost> { KotlinStringTemplateUPolyadicExpression(expression, givenParent) }
is KtDestructuringDeclaration -> expr<UDeclarationsExpression> {
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<ULabeledExpression>(build(::KotlinULabeledExpression))
is KtClassLiteralExpression -> expr<UClassLiteralExpression>(build(::KotlinUClassLiteralExpression))
is KtObjectLiteralExpression -> expr<UObjectLiteralExpression>(build(::KotlinUObjectLiteralExpression))
is KtDotQualifiedExpression -> expr<UQualifiedReferenceExpression>(build(::KotlinUQualifiedReferenceExpression))
is KtSafeQualifiedExpression -> expr<UQualifiedReferenceExpression>(build(::KotlinUSafeQualifiedExpression))
is KtSimpleNameExpression -> expr<USimpleNameReferenceExpression>(build(::KotlinUSimpleReferenceExpression))
is KtCallExpression -> expr<UCallExpression>(build(::KotlinUFunctionCallExpression))
is KtCollectionLiteralExpression -> expr<UCallExpression>(build(::KotlinUCollectionLiteralExpression))
is KtBinaryExpression -> {
if (expression.operationToken == KtTokens.ELVIS) {
expr<UExpressionList>(build(::createElvisExpression))
}
else expr<UBinaryExpression>(build(::KotlinUBinaryExpression))
}
is KtParenthesizedExpression -> expr<UParenthesizedExpression>(build(::KotlinUParenthesizedExpression))
is KtPrefixExpression -> expr<UPrefixExpression>(build(::KotlinUPrefixExpression))
is KtPostfixExpression -> expr<UPostfixExpression>(build(::KotlinUPostfixExpression))
is KtThisExpression -> expr<UThisExpression>(build(::KotlinUThisExpression))
is KtSuperExpression -> expr<USuperExpression>(build(::KotlinUSuperExpression))
is KtCallableReferenceExpression -> expr<UCallableReferenceExpression>(build(::KotlinUCallableReferenceExpression))
is KtIsExpression -> expr<UBinaryExpressionWithType>(build(::KotlinUTypeCheckExpression))
is KtIfExpression -> expr<UIfExpression>(build(::KotlinUIfExpression))
is KtWhileExpression -> expr<UWhileExpression>(build(::KotlinUWhileExpression))
is KtDoWhileExpression -> expr<UDoWhileExpression>(build(::KotlinUDoWhileExpression))
is KtForExpression -> expr<UForEachExpression>(build(::KotlinUForEachExpression))
is KtWhenExpression -> expr<USwitchExpression>(build(::KotlinUSwitchExpression))
is KtBreakExpression -> expr<UBreakExpression>(build(::KotlinUBreakExpression))
is KtContinueExpression -> expr<UContinueExpression>(build(::KotlinUContinueExpression))
is KtReturnExpression -> expr<UReturnExpression>(build(::KotlinUReturnExpression))
is KtThrowExpression -> expr<UThrowExpression>(build(::KotlinUThrowExpression))
is KtBlockExpression -> expr<UBlockExpression>(build(::KotlinUBlockExpression))
is KtConstantExpression -> expr<ULiteralExpression>(build(::KotlinULiteralExpression))
is KtTryExpression -> expr<UTryExpression>(build(::KotlinUTryExpression))
is KtArrayAccessExpression -> expr<UArrayAccessExpression>(build(::KotlinUArrayAccessExpression))
is KtLambdaExpression -> expr<ULambdaExpression>(build(::KotlinULambdaExpression))
is KtBinaryExpressionWithTypeRHS -> expr<UBinaryExpressionWithType>(build(::KotlinUBinaryExpressionWithType))
is KtClassOrObject -> expr<UDeclarationsExpression> {
expression.toLightClass()?.let { lightClass ->
KotlinUDeclarationsExpression(givenParent).apply {
declarations = listOf(KotlinUClass.create(lightClass, this))
}
} ?: UastEmptyExpression
}
is KtFunction -> if (expression.name.isNullOrEmpty()) {
expr<ULambdaExpression>(build(::createLocalFunctionLambdaExpression))
}
else {
expr<UDeclarationsExpression>(build(::createLocalFunctionDeclaration))
}
else -> expr<UExpression>(build(::UnknownKotlinExpression))
}}
}
internal fun convertWhenCondition(condition: KtWhenCondition,
givenParent: UElement?,
requiredType: Class<out UElement>? = null): UExpression? {
return with(requiredType) {
when (condition) {
is KtWhenConditionInRange -> expr<UBinaryExpression> {
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<UBinaryExpression> {
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<UExpression> { 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 <TDeclaration : KtDeclaration> 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<UDeclarationsExpression>() 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) }
}
@@ -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<UExpression> 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<UPolyadicExpression>.asRenderString()
override fun asLogString(): String = if (operands.isEmpty()) "UPolyadicExpression (value = \"\")" else super.asLogString()
}
@@ -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)
+11
View File
@@ -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")
@@ -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)
+9
View File
@@ -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)
@@ -0,0 +1,25 @@
UFile (package = )
UClass (name = DestructuringDeclarationKt)
UAnnotationMethod (name = foo)
UBlockExpression
UDeclarationsExpression
ULocalVariable (name = var268d4034)
UAnnotation (fqName = null)
UBinaryExpression (operator = <other>)
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 = <anonymous class>)
ULocalVariable (name = b)
UAnnotation (fqName = null)
UQualifiedReferenceExpression
USimpleNameReferenceExpression (identifier = var268d4034)
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
UIdentifier (Identifier (component2))
USimpleNameReferenceExpression (identifier = <anonymous class>)
+50
View File
@@ -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)
@@ -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)
+14
View File
@@ -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)
@@ -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)
@@ -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 = <anonymous class>)
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 = <init>)
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)
@@ -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)
@@ -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)
@@ -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)
+15
View File
@@ -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)
+15
View File
@@ -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]
+53
View File
@@ -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 = <init>)
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)
+26
View File
@@ -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)
@@ -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]
@@ -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)
@@ -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
+114
View File
@@ -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 = <init>)
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 = <init>)
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 = <init>)
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 = <init>)
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 = <init>)
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 = <init>)
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 = <init>)
UPolyadicExpression (operator = +)
ULiteralExpression (value = "text")
@@ -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 = <init>)
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 = <init>)
UPolyadicExpression (value = "")
UAnnotationMethod (name = Model$1$1)
@@ -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<T>, @org.jetbrains.annotations.NotNull factory: kotlin.jvm.functions.Function0<? extends T>) : void {...}]
UParameter (name = clazz) [@org.jetbrains.annotations.NotNull var clazz: java.lang.Class<T>]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UParameter (name = factory) [@org.jetbrains.annotations.NotNull var factory: kotlin.jvm.functions.Function0<? extends T>]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UBlockExpression [{...}] : PsiType:Void
UThrowExpression [throw <init>()] : PsiType:Void
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [<init>()] : PsiType:UnsupportedOperationException
UIdentifier (Identifier (UnsupportedOperationException)) [UIdentifier (Identifier (UnsupportedOperationException))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] : PsiType:UnsupportedOperationException
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<Callback>
UClassLiteralExpression [Callback] : PsiType:KClass<Callback>
USimpleNameReferenceExpression (identifier = java) [java] : PsiType:Class<Callback>
ULambdaExpression [{ ...}] : PsiType:<ErrorType>
UBlockExpression [{...}]
UObjectLiteralExpression [anonymous object : Callback {... }] : PsiType:Callback
UClass (name = null) [final class null : 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 <init>("")] : PsiType:Void
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) [<init>("")] : PsiType:UnsupportedOperationException
UIdentifier (Identifier (UnsupportedOperationException)) [UIdentifier (Identifier (UnsupportedOperationException))]
USimpleNameReferenceExpression (identifier = <init>) [<init>] : PsiType:UnsupportedOperationException
UPolyadicExpression (value = "") [""] : PsiType:String
UAnnotationMethod (name = Model$1$1) [fun Model$1$1() = UastEmptyExpression]
@@ -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 = <anonymous class>)
ULocalVariable (name = statementFilter)
UAnnotation (fqName = null)
UQualifiedReferenceExpression
USimpleNameReferenceExpression (identifier = var837f1e82)
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
UIdentifier (Identifier (component2))
USimpleNameReferenceExpression (identifier = <anonymous class>)
UReturnExpression
USimpleNameReferenceExpression (identifier = bindingContext)
UBreakExpression (label = null)
+25
View File
@@ -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 = "<error>")
UBreakExpression (label = null)
@@ -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 = <no name provided>)
UBlockExpression
UPolyadicExpression (operator = +)
ULiteralExpression (value = "abc1")
UPolyadicExpression (operator = +)
ULiteralExpression (value = "def1")
@@ -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<ULiteralExpression>("abc").let { literalExpression ->
file.findElementByTextFromPsi<UInjectionHost>("\"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<ULiteralExpression>("def").let { literalExpression ->
file.findElementByTextFromPsi<UInjectionHost>("\"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<ULiteralExpression>("def1").let { literalExpression ->
file.findElementByTextFromPsi<UInjectionHost>("\"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<UElement>(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 ->