Kotlin Uast: Support type parameters on functions

This commit is contained in:
Yan Zhulanow
2016-03-04 18:51:07 +03:00
parent 668172d68e
commit f4422b3b19
3 changed files with 49 additions and 34 deletions
@@ -0,0 +1,45 @@
/*
* 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.kotlin.uast
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.psi.KtTypeParameter
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.uast.KotlinPsiElementStub
import org.jetbrains.kotlin.uast.orAnonymous
import org.jetbrains.uast.*
import org.jetbrains.uast.psi.PsiElementBacked
class KotlinParameterUTypeReference(
override val psi: KtTypeParameter,
override val parent: UElement
) : UTypeReference, PsiElementBacked {
override fun resolve(context: UastContext): UClass? {
val descriptor = psi.analyze(BodyResolveMode.PARTIAL)[BindingContext.TYPE_PARAMETER, psi]
?.typeConstructor?.declarationDescriptor as? ClassDescriptor ?: return null
return context.convert(DescriptorToSourceUtilsIde.getAnyDeclaration(psi.project, descriptor)) as? UClass
}
override val nameElement: UElement?
get() = KotlinPsiElementStub(psi, this)
override val name: String
get() = psi.name.orAnonymous()
}
@@ -83,7 +83,8 @@ class KotlinUFunction(
KotlinConverter.convert(type, psi.project, this)
}
//TODO
override val typeParameterCount = 0
override val typeParameters = emptyList<UTypeReference>()
override val typeParameterCount: Int
get() = psi.typeParameters.size
override val typeParameters by lz { psi.typeParameters.map { KotlinParameterUTypeReference(it, this) } }
}
@@ -1,31 +0,0 @@
/*
* 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.kotlin.uast
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
import org.jetbrains.uast.NoEvaluate
import org.jetbrains.uast.UArrayAccessExpression
import org.jetbrains.uast.UElement
import org.jetbrains.uast.psi.PsiElementBacked
class KotlinUArrayAccess(
override val psi: KtArrayAccessExpression,
override val parent: UElement
) : UArrayAccessExpression, PsiElementBacked, KotlinTypeHelper, NoEvaluate {
override val receiver by lz { KotlinConverter.convertOrEmpty(psi.arrayExpression, this) }
override val indices by lz { psi.indexExpressions.map { KotlinConverter.convert(it, this) } }
}