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