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
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user