diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt index f4062e69f1f..0960f192d99 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt @@ -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 { - val functionType = createType("() -> Int").getTypeElement() as JetFunctionType + val functionType = createType("() -> Int").typeElement as JetFunctionType return Pair(functionType.findElementAt(2)!!, functionType.findElementAt(3)!!) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetTypeReference.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetTypeReference.kt index d9f36909f26..98591e2d6af 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetTypeReference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetTypeReference.kt @@ -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> implements JetAnnotated, JetAnnotationsContainer { +class JetTypeReference : JetElementImplStub>, JetAnnotated, JetAnnotationsContainer { - public JetTypeReference(@NotNull ASTNode node) { - super(node); + constructor(node: ASTNode) : super(node) + + constructor(stub: KotlinPlaceHolderStub) : super(stub, JetStubElementTypes.TYPE_REFERENCE) + + override fun accept(visitor: JetVisitor, data: D): R { + return visitor.visitTypeReference(this, data) } - public JetTypeReference(KotlinPlaceHolderStub stub) { - super(stub, JetStubElementTypes.TYPE_REFERENCE); + val typeElement: JetTypeElement? + get() = JetStubbedPsiUtil.getStubOrPsiChild(this, JetStubElementTypes.TYPE_ELEMENT_TYPES, JetTypeElement.ARRAY_FACTORY) + + override fun getAnnotations(): List { + return getStubOrPsiChildrenAsList(JetStubElementTypes.ANNOTATION) } - @Override - public R accept(@NotNull JetVisitor visitor, D data) { - return visitor.visitTypeReference(this, data); + override fun getAnnotationEntries(): List { + return this.collectAnnotationEntriesFromStubOrPsi() } - @Nullable - public JetTypeElement getTypeElement() { - return JetStubbedPsiUtil.getStubOrPsiChild(this, JetStubElementTypes.TYPE_ELEMENT_TYPES, JetTypeElement.ARRAY_FACTORY); - } - - @NotNull - @Override - public List getAnnotations() { - return getStubOrPsiChildrenAsList(JetStubElementTypes.ANNOTATION); - } - - @NotNull - @Override - public List getAnnotationEntries() { - return PsiUtilPackage.collectAnnotationEntriesFromStubOrPsi(this); - } - - public boolean hasParentheses() { - return findChildByType(JetTokens.LPAR) != null && findChildByType(JetTokens.LPAR) != null; + fun hasParentheses(): Boolean { + return findChildByType(JetTokens.LPAR) != null && findChildByType(JetTokens.LPAR) != null } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt index b182cf45caa..7853a3d4fa9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt @@ -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 = diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeBinding.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeBinding.kt index 13dc2c5eb0d..a0c3b046902 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeBinding.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeBinding.kt @@ -42,7 +42,7 @@ interface TypeArgumentBinding { fun JetTypeReference.createTypeBinding(trace: BindingContext): TypeBinding? { 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) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index e38768773c0..4872a05023d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -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) diff --git a/idea/ide-common/src/org/jetbrains/kotlin/resolve/lazy/PartialBodyResolveFilter.kt b/idea/ide-common/src/org/jetbrains/kotlin/resolve/lazy/PartialBodyResolveFilter.kt index 14bd73b4c39..436c36bb62d 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/resolve/lazy/PartialBodyResolveFilter.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/resolve/lazy/PartialBodyResolveFilter.kt @@ -563,7 +563,7 @@ class PartialBodyResolveFilter( private fun PsiElement.isStatement() = this is JetExpression && getParent() is JetBlockExpression private fun JetTypeReference?.containsProbablyNothing() - = this?.getTypeElement()?.anyDescendantOfType { it.isProbablyNothing() } ?: false + = this?.typeElement?.anyDescendantOfType { it.isProbablyNothing() } ?: false } private inner class StatementMarks { diff --git a/idea/ide-common/src/org/jetbrains/kotlin/util/TypeIndexUtil.kt b/idea/ide-common/src/org/jetbrains/kotlin/util/TypeIndexUtil.kt index 6c1b758a3dc..2d675ad0dc5 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/util/TypeIndexUtil.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/util/TypeIndexUtil.kt @@ -59,7 +59,7 @@ private class CachedAliasImportData(val map: Multimap, val fileM private val ALIAS_IMPORT_DATA_KEY = Key("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() } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt index 848375400e3..cb6fbe35fbf 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt @@ -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 diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt index 0efe7fc4519..6d6b19ba323 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt @@ -24,7 +24,7 @@ import org.jetbrains.kotlin.util.aliasImportMap fun indexTopLevelExtension(stub: KotlinCallableStubBase, 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(declarat if (typeParameter != null) { val bound = typeParameter.getExtendsBound() if (bound != null) { - bound.getTypeElement()?.index(declaration, sink) + bound.typeElement?.index(declaration, sink) } else { occurrence("Any") diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt index 12f245a32c0..1a17f4e9d8d 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt @@ -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 } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReconstructTypeInCastOrIsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReconstructTypeInCastOrIsIntention.kt index 798b82ceb23..5c925337584 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReconstructTypeInCastOrIsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReconstructTypeInCastOrIsIntention.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.types.JetType public class ReconstructTypeInCastOrIsIntention : JetSelfTargetingOffsetIndependentIntention(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