Converted JetTypeReference to Kotlin

This commit is contained in:
Svetlana Isakova
2015-10-07 21:13:53 +03:00
parent d8e7dccc90
commit 63d9e287b7
11 changed files with 36 additions and 55 deletions
@@ -107,7 +107,7 @@ public class JetPsiFactory(private val project: Project) {
//the pair contains the first and the last elements of a range
public fun createWhitespaceAndArrow(): Pair<PsiElement, PsiElement> {
val functionType = createType("() -> Int").getTypeElement() as JetFunctionType
val functionType = createType("() -> Int").typeElement as JetFunctionType
return Pair(functionType.findElementAt(2)!!, functionType.findElementAt(3)!!)
}
@@ -14,60 +14,41 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.psi;
package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.JetNodeTypes;
import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes.ANNOTATION;
import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.psiUtil.collectAnnotationEntriesFromStubOrPsi
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
/**
* Type reference element.
* Underlying token is {@link org.jetbrains.kotlin.JetNodeTypes#TYPE_REFERENCE}
* Underlying token is [org.jetbrains.kotlin.JetNodeTypes.TYPE_REFERENCE]
*/
public class JetTypeReference extends JetElementImplStub<KotlinPlaceHolderStub<JetTypeReference>> implements JetAnnotated, JetAnnotationsContainer {
class JetTypeReference : JetElementImplStub<KotlinPlaceHolderStub<JetTypeReference>>, JetAnnotated, JetAnnotationsContainer {
public JetTypeReference(@NotNull ASTNode node) {
super(node);
constructor(node: ASTNode) : super(node)
constructor(stub: KotlinPlaceHolderStub<JetTypeReference>) : super(stub, JetStubElementTypes.TYPE_REFERENCE)
override fun <R, D> accept(visitor: JetVisitor<R, D>, data: D): R {
return visitor.visitTypeReference(this, data)
}
public JetTypeReference(KotlinPlaceHolderStub<JetTypeReference> stub) {
super(stub, JetStubElementTypes.TYPE_REFERENCE);
val typeElement: JetTypeElement?
get() = JetStubbedPsiUtil.getStubOrPsiChild(this, JetStubElementTypes.TYPE_ELEMENT_TYPES, JetTypeElement.ARRAY_FACTORY)
override fun getAnnotations(): List<JetAnnotation> {
return getStubOrPsiChildrenAsList(JetStubElementTypes.ANNOTATION)
}
@Override
public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
return visitor.visitTypeReference(this, data);
override fun getAnnotationEntries(): List<JetAnnotationEntry> {
return this.collectAnnotationEntriesFromStubOrPsi()
}
@Nullable
public JetTypeElement getTypeElement() {
return JetStubbedPsiUtil.getStubOrPsiChild(this, JetStubElementTypes.TYPE_ELEMENT_TYPES, JetTypeElement.ARRAY_FACTORY);
}
@NotNull
@Override
public List<JetAnnotation> getAnnotations() {
return getStubOrPsiChildrenAsList(JetStubElementTypes.ANNOTATION);
}
@NotNull
@Override
public List<JetAnnotationEntry> getAnnotationEntries() {
return PsiUtilPackage.collectAnnotationEntriesFromStubOrPsi(this);
}
public boolean hasParentheses() {
return findChildByType(JetTokens.LPAR) != null && findChildByType(JetTokens.LPAR) != null;
fun hasParentheses(): Boolean {
return findChildByType<PsiElement>(JetTokens.LPAR) != null && findChildByType<PsiElement>(JetTokens.LPAR) != null
}
}
@@ -57,7 +57,7 @@ fun setTypeReference(declaration: JetCallableDeclaration, addAfter: PsiElement?,
}
fun JetCallableDeclaration.setReceiverTypeReference(typeRef: JetTypeReference?): JetTypeReference? {
val needParentheses = typeRef != null && typeRef.getTypeElement() is JetFunctionType && !typeRef.hasParentheses()
val needParentheses = typeRef != null && typeRef.typeElement is JetFunctionType && !typeRef.hasParentheses()
val oldTypeRef = getReceiverTypeReference()
if (typeRef != null) {
val newTypeRef =
@@ -42,7 +42,7 @@ interface TypeArgumentBinding<out P: PsiElement> {
fun JetTypeReference.createTypeBinding(trace: BindingContext): TypeBinding<JetTypeElement>? {
val jetType = trace[BindingContext.TYPE, this]
val psiElement = getTypeElement()
val psiElement = typeElement
if (jetType == null || psiElement == null) {
return null
}
@@ -84,7 +84,7 @@ private class ExplicitTypeBinding(
return psiTypeArguments.indices.map { index: Int ->
// todo fix for List<*>
val jetTypeReference = psiTypeArguments[index]
val jetTypeElement = jetTypeReference?.getTypeElement()
val jetTypeElement = jetTypeReference?.typeElement
if (jetTypeElement == null) return@map null;
if (isErrorBinding) {
@@ -107,7 +107,7 @@ public class TypeResolver(
private fun doResolvePossiblyBareType(c: TypeResolutionContext, typeReference: JetTypeReference): PossiblyBareType {
val annotations = annotationResolver.resolveAnnotationsWithoutArguments(c.scope, typeReference.getAnnotationEntries(), c.trace)
val typeElement = typeReference.getTypeElement()
val typeElement = typeReference.typeElement
val type = resolveTypeElement(c, annotations, typeElement)
c.trace.recordScope(c.scope, typeReference)
@@ -563,7 +563,7 @@ class PartialBodyResolveFilter(
private fun PsiElement.isStatement() = this is JetExpression && getParent() is JetBlockExpression
private fun JetTypeReference?.containsProbablyNothing()
= this?.getTypeElement()?.anyDescendantOfType<JetUserType> { it.isProbablyNothing() } ?: false
= this?.typeElement?.anyDescendantOfType<JetUserType> { it.isProbablyNothing() } ?: false
}
private inner class StatementMarks {
@@ -59,7 +59,7 @@ private class CachedAliasImportData(val map: Multimap<String, String>, val fileM
private val ALIAS_IMPORT_DATA_KEY = Key<CachedAliasImportData>("ALIAS_IMPORT_MAP_KEY")
public fun JetTypeReference?.isProbablyNothing(): Boolean {
val userType = this?.getTypeElement() as? JetUserType ?: return false
val userType = this?.typeElement as? JetUserType ?: return false
return userType.isProbablyNothing()
}
@@ -171,7 +171,7 @@ class JetSimpleNameReference(expression: JetSimpleNameExpression) : JetSimpleRef
return when (elementToReplace) {
is JetUserType -> {
val typeText = "$text${elementToReplace.getTypeArgumentList()?.getText() ?: ""}"
elementToReplace.replace(psiFactory.createType(typeText).getTypeElement()!!)
elementToReplace.replace(psiFactory.createType(typeText).typeElement!!)
}
else -> elementToReplace.replace(psiFactory.createExpression(text))
} as JetElement
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.util.aliasImportMap
fun indexTopLevelExtension<TDeclaration : JetCallableDeclaration>(stub: KotlinCallableStubBase<TDeclaration>, sink: IndexSink) {
if (stub.isExtension()) {
val declaration = stub.getPsi()
declaration.getReceiverTypeReference()!!.getTypeElement()?.index(declaration, sink)
declaration.getReceiverTypeReference()!!.typeElement?.index(declaration, sink)
}
}
@@ -43,7 +43,7 @@ private fun JetTypeElement.index<TDeclaration : JetCallableDeclaration>(declarat
if (typeParameter != null) {
val bound = typeParameter.getExtendsBound()
if (bound != null) {
bound.getTypeElement()?.index(declaration, sink)
bound.typeElement?.index(declaration, sink)
}
else {
occurrence("Any")
@@ -304,7 +304,7 @@ public class KotlinCompletionContributor : CompletionContributor() {
val nameRef = position.getParent() as? JetNameReferenceExpression ?: return null
val userType = nameRef.getParent() as? JetUserType ?: return null
val typeRef = userType.getParent() as? JetTypeReference ?: return null
if (userType != typeRef.getTypeElement()) return null
if (userType != typeRef.typeElement) return null
val parent = typeRef.getParent()
return when (parent) {
is JetNamedFunction -> parent.check { typeRef == it.receiverTypeReference }
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.types.JetType
public class ReconstructTypeInCastOrIsIntention : JetSelfTargetingOffsetIndependentIntention<JetTypeReference>(javaClass(), "Replace by reconstructed type"), LowPriorityAction {
override fun isApplicableTo(element: JetTypeReference): Boolean {
// Only user types (like Foo) are interesting
val typeElement = element.getTypeElement() as? JetUserType ?: return false
val typeElement = element.typeElement as? JetUserType ?: return false
// If there are generic arguments already, there's nothing to reconstruct
if (typeElement.getTypeArguments().isNotEmpty()) return false