clean up psi package

This commit is contained in:
Kirill Rakhman
2016-11-01 00:01:21 +01:00
committed by Mikhail Glukhikh
parent e10d10c49e
commit ba7f60040a
27 changed files with 188 additions and 213 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -28,8 +28,8 @@ fun KtElement.getDebugText(): String {
return text return text
} }
if (this is KtPackageDirective) { if (this is KtPackageDirective) {
val fqName = getFqName() val fqName = fqName
if (fqName.isRoot()) { if (fqName.isRoot) {
return "" return ""
} }
return "package " + fqName.asString() return "package " + fqName.asString()
@@ -54,12 +54,9 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
} }
override fun visitImportDirective(importDirective: KtImportDirective, data: Unit?): String? { override fun visitImportDirective(importDirective: KtImportDirective, data: Unit?): String? {
val importPath = importDirective.getImportPath() val importPath = importDirective.importPath ?: return "import <invalid>"
if (importPath == null) { val aliasStr = if (importPath.hasAlias()) " as " + importPath.alias!!.asString() else ""
return "import <invalid>" return "import ${importPath.pathStr}" + aliasStr
}
val aliasStr = if (importPath.hasAlias()) " as " + importPath.getAlias()!!.asString() else ""
return "import ${importPath.getPathStr()}" + aliasStr
} }
override fun visitImportList(importList: KtImportList, data: Unit?): String? { override fun visitImportList(importList: KtImportList, data: Unit?): String? {
@@ -67,7 +64,7 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
} }
override fun visitAnnotationEntry(annotationEntry: KtAnnotationEntry, data: Unit?): String? { override fun visitAnnotationEntry(annotationEntry: KtAnnotationEntry, data: Unit?): String? {
return render(annotationEntry, annotationEntry.getCalleeExpression(), annotationEntry.getTypeArgumentList()) return render(annotationEntry, annotationEntry.calleeExpression, annotationEntry.typeArgumentList)
} }
override fun visitTypeReference(typeReference: KtTypeReference, data: Unit?): String? { override fun visitTypeReference(typeReference: KtTypeReference, data: Unit?): String? {
@@ -83,7 +80,7 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
} }
override fun visitUserType(userType: KtUserType, data: Unit?): String? { override fun visitUserType(userType: KtUserType, data: Unit?): String? {
return render(userType, userType.getQualifier(), userType.getReferenceExpression(), userType.getTypeArgumentList()) return render(userType, userType.qualifier, userType.referenceExpression, userType.typeArgumentList)
} }
override fun visitDynamicType(type: KtDynamicType, data: Unit?): String? { override fun visitDynamicType(type: KtDynamicType, data: Unit?): String? {
@@ -95,11 +92,11 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
} }
override fun visitConstructorCalleeExpression(constructorCalleeExpression: KtConstructorCalleeExpression, data: Unit?): String? { override fun visitConstructorCalleeExpression(constructorCalleeExpression: KtConstructorCalleeExpression, data: Unit?): String? {
return render(constructorCalleeExpression, constructorCalleeExpression.getConstructorReferenceExpression()) return render(constructorCalleeExpression, constructorCalleeExpression.constructorReferenceExpression)
} }
override fun visitSuperTypeListEntry(specifier: KtSuperTypeListEntry, data: Unit?): String? { override fun visitSuperTypeListEntry(specifier: KtSuperTypeListEntry, data: Unit?): String? {
return render(specifier, specifier.getTypeReference()) return render(specifier, specifier.typeReference)
} }
override fun visitSuperTypeList(list: KtSuperTypeList, data: Unit?): String? { override fun visitSuperTypeList(list: KtSuperTypeList, data: Unit?): String? {
@@ -125,34 +122,34 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
override fun visitEnumEntry(enumEntry: KtEnumEntry, data: Unit?): String? { override fun visitEnumEntry(enumEntry: KtEnumEntry, data: Unit?): String? {
return buildText { return buildText {
append("STUB: ") append("STUB: ")
appendInn(enumEntry.getModifierList(), suffix = " ") appendInn(enumEntry.modifierList, suffix = " ")
append("enum entry ") append("enum entry ")
appendInn(enumEntry.getNameAsName()) appendInn(enumEntry.nameAsName)
appendInn(enumEntry.getInitializerList(), prefix = " : ") appendInn(enumEntry.initializerList, prefix = " : ")
} }
} }
override fun visitFunctionType(functionType: KtFunctionType, data: Unit?): String? { override fun visitFunctionType(functionType: KtFunctionType, data: Unit?): String? {
return buildText { return buildText {
appendInn(functionType.getReceiverTypeReference(), suffix = ".") appendInn(functionType.receiverTypeReference, suffix = ".")
appendInn(functionType.getParameterList()) appendInn(functionType.parameterList)
appendInn(functionType.getReturnTypeReference(), prefix = " -> ") appendInn(functionType.returnTypeReference, prefix = " -> ")
} }
} }
override fun visitTypeParameter(parameter: KtTypeParameter, data: Unit?): String? { override fun visitTypeParameter(parameter: KtTypeParameter, data: Unit?): String? {
return buildText { return buildText {
appendInn(parameter.getModifierList(), suffix = " ") appendInn(parameter.modifierList, suffix = " ")
appendInn(parameter.getNameAsName()) appendInn(parameter.nameAsName)
appendInn(parameter.getExtendsBound(), prefix = " : ") appendInn(parameter.extendsBound, prefix = " : ")
} }
} }
override fun visitTypeProjection(typeProjection: KtTypeProjection, data: Unit?): String? { override fun visitTypeProjection(typeProjection: KtTypeProjection, data: Unit?): String? {
return buildText { return buildText {
val token = typeProjection.getProjectionKind().getToken() val token = typeProjection.projectionKind.token
appendInn(token?.getValue()) appendInn(token?.value)
val typeReference = typeProjection.getTypeReference() val typeReference = typeProjection.typeReference
if (token != null && typeReference != null) { if (token != null && typeReference != null) {
append(" ") append(" ")
} }
@@ -195,17 +192,17 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
override fun visitPropertyAccessor(accessor: KtPropertyAccessor, data: Unit?): String? { override fun visitPropertyAccessor(accessor: KtPropertyAccessor, data: Unit?): String? {
val containingProperty = KtStubbedPsiUtil.getContainingDeclaration(accessor, KtProperty::class.java) val containingProperty = KtStubbedPsiUtil.getContainingDeclaration(accessor, KtProperty::class.java)
val what = (if (accessor.isGetter()) "getter" else "setter") val what = (if (accessor.isGetter) "getter" else "setter")
return what + " for " + (containingProperty?.getDebugText() ?: "...") return what + " for " + (containingProperty?.getDebugText() ?: "...")
} }
override fun visitClass(klass: KtClass, data: Unit?): String? { override fun visitClass(klass: KtClass, data: Unit?): String? {
return buildText { return buildText {
append("STUB: ") append("STUB: ")
appendInn(klass.getModifierList(), suffix = " ") appendInn(klass.modifierList, suffix = " ")
append("class ") append("class ")
appendInn(klass.getNameAsName()) appendInn(klass.nameAsName)
appendInn(klass.getTypeParameterList()) appendInn(klass.typeParameterList)
appendInn(klass.getPrimaryConstructorModifierList(), prefix = " ", suffix = " ") appendInn(klass.getPrimaryConstructorModifierList(), prefix = " ", suffix = " ")
appendInn(klass.getPrimaryConstructorParameterList()) appendInn(klass.getPrimaryConstructorParameterList())
appendInn(klass.getSuperTypeList(), prefix = " : ") appendInn(klass.getSuperTypeList(), prefix = " : ")
@@ -215,30 +212,30 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
override fun visitNamedFunction(function: KtNamedFunction, data: Unit?): String? { override fun visitNamedFunction(function: KtNamedFunction, data: Unit?): String? {
return buildText { return buildText {
append("STUB: ") append("STUB: ")
appendInn(function.getModifierList(), suffix = " ") appendInn(function.modifierList, suffix = " ")
append("fun ") append("fun ")
val typeParameterList = function.getTypeParameterList() val typeParameterList = function.typeParameterList
if (function.hasTypeParameterListBeforeFunctionName()) { if (function.hasTypeParameterListBeforeFunctionName()) {
appendInn(typeParameterList, suffix = " ") appendInn(typeParameterList, suffix = " ")
} }
appendInn(function.getReceiverTypeReference(), suffix = ".") appendInn(function.receiverTypeReference, suffix = ".")
appendInn(function.getNameAsName()) appendInn(function.nameAsName)
if (!function.hasTypeParameterListBeforeFunctionName()) { if (!function.hasTypeParameterListBeforeFunctionName()) {
appendInn(typeParameterList) appendInn(typeParameterList)
} }
appendInn(function.getValueParameterList()) appendInn(function.valueParameterList)
appendInn(function.getTypeReference(), prefix = ": ") appendInn(function.typeReference, prefix = ": ")
appendInn(function.getTypeConstraintList(), prefix = " ") appendInn(function.typeConstraintList, prefix = " ")
} }
} }
override fun visitObjectDeclaration(declaration: KtObjectDeclaration, data: Unit?): String? { override fun visitObjectDeclaration(declaration: KtObjectDeclaration, data: Unit?): String? {
return buildText { return buildText {
append("STUB: ") append("STUB: ")
appendInn(declaration.getModifierList(), suffix = " ") appendInn(declaration.modifierList, suffix = " ")
append("object ") append("object ")
appendInn(declaration.getNameAsName()) appendInn(declaration.nameAsName)
appendInn(declaration.getSuperTypeList(), prefix = " : ") appendInn(declaration.getSuperTypeList(), prefix = " : ")
} }
} }
@@ -246,11 +243,11 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
override fun visitParameter(parameter: KtParameter, data: Unit?): String? { override fun visitParameter(parameter: KtParameter, data: Unit?): String? {
return buildText { return buildText {
if (parameter.hasValOrVar()) { if (parameter.hasValOrVar()) {
if (parameter.isMutable()) append("var ") else append("val ") if (parameter.isMutable) append("var ") else append("val ")
} }
val name = parameter.getNameAsName() val name = parameter.nameAsName
appendInn(name) appendInn(name)
val typeReference = parameter.getTypeReference() val typeReference = parameter.typeReference
if (typeReference != null && name != null) { if (typeReference != null && name != null) {
append(": ") append(": ")
} }
@@ -261,17 +258,17 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
override fun visitProperty(property: KtProperty, data: Unit?): String? { override fun visitProperty(property: KtProperty, data: Unit?): String? {
return buildText { return buildText {
append("STUB: ") append("STUB: ")
appendInn(property.getModifierList(), suffix = " ") appendInn(property.modifierList, suffix = " ")
append(if (property.isVar()) "var " else "val ") append(if (property.isVar) "var " else "val ")
appendInn(property.getNameAsName()) appendInn(property.nameAsName)
appendInn(property.getTypeReference(), prefix = ": ") appendInn(property.typeReference, prefix = ": ")
} }
} }
override fun visitTypeConstraint(constraint: KtTypeConstraint, data: Unit?): String? { override fun visitTypeConstraint(constraint: KtTypeConstraint, data: Unit?): String? {
return buildText { return buildText {
appendInn(constraint.getSubjectTypeParameterName()) appendInn(constraint.subjectTypeParameterName)
appendInn(constraint.getBoundTypeReference(), prefix = " : ") appendInn(constraint.boundTypeReference, prefix = " : ")
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -63,10 +63,10 @@ object EditCommaSeparatedListHelper {
if (anchor != null) { if (anchor != null) {
val index = allItems.indexOf(anchor) val index = allItems.indexOf(anchor)
assert(index >= 0) assert(index >= 0)
anchorAfter = if (index > 0) allItems.get(index - 1) else null anchorAfter = if (index > 0) allItems[index - 1] else null
} }
else { else {
anchorAfter = allItems.get(allItems.size - 1) anchorAfter = allItems[allItems.size - 1]
} }
} }
return addItemAfter(list, allItems, item, anchorAfter, prefix) return addItemAfter(list, allItems, item, anchorAfter, prefix)
@@ -74,9 +74,9 @@ object EditCommaSeparatedListHelper {
fun <TItem: KtElement> removeItem(item: TItem) { fun <TItem: KtElement> removeItem(item: TItem) {
var comma = item.siblings(withItself = false).firstOrNull { it !is PsiWhiteSpace && it !is PsiComment } var comma = item.siblings(withItself = false).firstOrNull { it !is PsiWhiteSpace && it !is PsiComment }
if (comma?.getNode()?.getElementType() != KtTokens.COMMA) { if (comma?.node?.elementType != KtTokens.COMMA) {
comma = item.siblings(forward = false, withItself = false).firstOrNull { it !is PsiWhiteSpace && it !is PsiComment } comma = item.siblings(forward = false, withItself = false).firstOrNull { it !is PsiWhiteSpace && it !is PsiComment }
if (comma?.getNode()?.getElementType() != KtTokens.COMMA) { if (comma?.node?.elementType != KtTokens.COMMA) {
comma = null comma = null
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,11 +16,10 @@
package org.jetbrains.kotlin.psi.findDocComment package org.jetbrains.kotlin.psi.findDocComment
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
import org.jetbrains.kotlin.psi.psiUtil.siblings
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.PsiComment import com.intellij.psi.PsiComment
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.psiUtil.allChildren import org.jetbrains.kotlin.psi.psiUtil.allChildren
fun findDocComment(declaration: KtDeclaration): KDoc? { fun findDocComment(declaration: KtDeclaration): KDoc? {
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -17,13 +17,9 @@
package org.jetbrains.kotlin.psi package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode import com.intellij.lang.ASTNode
import com.intellij.psi.impl.source.tree.TreeElement
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.lexer.KtKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub
import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationUseSiteTargetStub import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationUseSiteTargetStub
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
class KtAnnotationUseSiteTarget : KtElementImplStub<KotlinAnnotationUseSiteTargetStub> { class KtAnnotationUseSiteTarget : KtElementImplStub<KotlinAnnotationUseSiteTargetStub> {
@@ -44,8 +40,8 @@ class KtAnnotationUseSiteTarget : KtElementImplStub<KotlinAnnotationUseSiteTarge
} }
} }
val node = getFirstChild().getNode() val node = firstChild.node
return when (node.getElementType()) { return when (node.elementType) {
KtTokens.FIELD_KEYWORD -> AnnotationUseSiteTarget.FIELD KtTokens.FIELD_KEYWORD -> AnnotationUseSiteTarget.FIELD
KtTokens.FILE_KEYWORD -> AnnotationUseSiteTarget.FILE KtTokens.FILE_KEYWORD -> AnnotationUseSiteTarget.FILE
KtTokens.PROPERTY_KEYWORD -> AnnotationUseSiteTarget.PROPERTY KtTokens.PROPERTY_KEYWORD -> AnnotationUseSiteTarget.PROPERTY
@@ -55,7 +51,7 @@ class KtAnnotationUseSiteTarget : KtElementImplStub<KotlinAnnotationUseSiteTarge
KtTokens.PARAM_KEYWORD -> AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER KtTokens.PARAM_KEYWORD -> AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER
KtTokens.SETPARAM_KEYWORD -> AnnotationUseSiteTarget.SETTER_PARAMETER KtTokens.SETPARAM_KEYWORD -> AnnotationUseSiteTarget.SETTER_PARAMETER
KtTokens.DELEGATE_KEYWORD -> AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD KtTokens.DELEGATE_KEYWORD -> AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD
else -> throw IllegalStateException("Unknown annotation target " + node.getText()) else -> throw IllegalStateException("Unknown annotation target " + node.text)
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -74,8 +74,7 @@ open class KtClass : KtClassOrObject {
parts.add(current.name!!) parts.add(current.name!!)
current = PsiTreeUtil.getParentOfType<KtClassOrObject>(current, KtClassOrObject::class.java) current = PsiTreeUtil.getParentOfType<KtClassOrObject>(current, KtClassOrObject::class.java)
} }
val file = containingFile val file = containingFile as? KtFile ?: return null
if (file !is KtFile) return null
val fileQualifiedName = file.packageFqName.asString() val fileQualifiedName = file.packageFqName.asString()
if (!fileQualifiedName.isEmpty()) { if (!fileQualifiedName.isEmpty()) {
parts.add(fileQualifiedName) parts.add(fileQualifiedName)
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ abstract class KtConstructor<T : KtConstructor<T>> : KtDeclarationStub<KotlinPla
override fun getValueParameterList() = getStubOrPsiChild(KtStubElementTypes.VALUE_PARAMETER_LIST) override fun getValueParameterList() = getStubOrPsiChild(KtStubElementTypes.VALUE_PARAMETER_LIST)
override fun getValueParameters() = getValueParameterList()?.getParameters() ?: emptyList() override fun getValueParameters() = valueParameterList?.parameters ?: emptyList()
override fun getReceiverTypeReference() = null override fun getReceiverTypeReference() = null
@@ -51,9 +51,9 @@ abstract class KtConstructor<T : KtConstructor<T>> : KtDeclarationStub<KotlinPla
override fun getEqualsToken() = null override fun getEqualsToken() = null
override fun hasBlockBody() = getBodyExpression() != null override fun hasBlockBody() = bodyExpression != null
override fun hasBody() = getBodyExpression() != null override fun hasBody() = bodyExpression != null
override fun hasDeclaredReturnType() = false override fun hasDeclaredReturnType() = false
@@ -65,13 +65,13 @@ abstract class KtConstructor<T : KtConstructor<T>> : KtDeclarationStub<KotlinPla
override fun getTypeParameters() = emptyList<KtTypeParameter>() override fun getTypeParameters() = emptyList<KtTypeParameter>()
override fun getName(): String? = getContainingClassOrObject().getName() override fun getName(): String? = getContainingClassOrObject().name
override fun getNameAsSafeName() = KtPsiUtil.safeName(getName()) override fun getNameAsSafeName() = KtPsiUtil.safeName(name)
override fun getFqName() = null override fun getFqName() = null
override fun getNameAsName() = getNameAsSafeName() override fun getNameAsName() = nameAsSafeName
override fun getNameIdentifier() = null override fun getNameIdentifier() = null
@@ -82,15 +82,15 @@ abstract class KtConstructor<T : KtConstructor<T>> : KtDeclarationStub<KotlinPla
open fun getConstructorKeyword(): PsiElement? = findChildByType(KtTokens.CONSTRUCTOR_KEYWORD) open fun getConstructorKeyword(): PsiElement? = findChildByType(KtTokens.CONSTRUCTOR_KEYWORD)
fun hasConstructorKeyword(): Boolean = getStub() != null || getConstructorKeyword() != null fun hasConstructorKeyword(): Boolean = stub != null || getConstructorKeyword() != null
override fun getTextOffset(): Int { override fun getTextOffset(): Int {
return getConstructorKeyword()?.getTextOffset() return getConstructorKeyword()?.textOffset
?: getValueParameterList()?.getTextOffset() ?: valueParameterList?.textOffset
?: super.getTextOffset() ?: super.getTextOffset()
} }
override fun getUseScope(): SearchScope { override fun getUseScope(): SearchScope {
return getContainingClassOrObject().getUseScope() return getContainingClassOrObject().useScope
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ class KtDotQualifiedExpression : KtExpressionImplStub<KotlinPlaceHolderStub<KtDo
} }
else { else {
val expressions = stub.getChildrenByType(INSIDE_DIRECTIVE_EXPRESSIONS, KtExpression.ARRAY_FACTORY) val expressions = stub.getChildrenByType(INSIDE_DIRECTIVE_EXPRESSIONS, KtExpression.ARRAY_FACTORY)
if (expressions.size < 1 || expressions.size > 2) { if (expressions.size !in 1..2) {
LOG.error("Invalid stub structure. DOT_QUALIFIED_EXPRESSION must have one or two children. Was: ${expressions.size}\n" + LOG.error("Invalid stub structure. DOT_QUALIFIED_EXPRESSION must have one or two children. Was: ${expressions.size}\n" +
"File text:\n${containingFile.text}") "File text:\n${containingFile.text}")
return null return null
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -40,12 +40,7 @@ abstract class KtDoubleColonExpression(node: ASTNode) : KtExpressionImpl(node) {
fun setReceiverExpression(newReceiverExpression: KtExpression) { fun setReceiverExpression(newReceiverExpression: KtExpression) {
val oldReceiverExpression = this.receiverExpression val oldReceiverExpression = this.receiverExpression
if (oldReceiverExpression != null) { oldReceiverExpression?.replace(newReceiverExpression) ?: addBefore(newReceiverExpression, doubleColonTokenReference)
oldReceiverExpression.replace(newReceiverExpression)
}
else {
addBefore(newReceiverExpression, doubleColonTokenReference)
}
} }
val isEmptyLHS: Boolean val isEmptyLHS: Boolean
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -41,11 +41,11 @@ class KtEnumEntrySuperclassReferenceExpression :
private fun calcReferencedElement(): KtClass? { private fun calcReferencedElement(): KtClass? {
val owner = this.getStrictParentOfType<KtEnumEntry>() as? KtEnumEntry val owner = this.getStrictParentOfType<KtEnumEntry>() as? KtEnumEntry
return owner?.getParent()?.getParent() as? KtClass return owner?.parent?.parent as? KtClass
} }
override fun getReferencedName(): String { override fun getReferencedName(): String {
val stub = getStub() val stub = stub
if (stub != null) { if (stub != null) {
return stub.getReferencedName() return stub.getReferencedName()
} }
@@ -54,7 +54,7 @@ class KtEnumEntrySuperclassReferenceExpression :
} }
override fun getReferencedNameAsName(): Name { override fun getReferencedNameAsName(): Name {
return referencedElement.getName()?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED return referencedElement.name?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED
} }
override fun getReferencedNameElement(): PsiElement { override fun getReferencedNameElement(): PsiElement {
@@ -62,11 +62,11 @@ class KtEnumEntrySuperclassReferenceExpression :
} }
override fun getIdentifier(): PsiElement? { override fun getIdentifier(): PsiElement? {
return referencedElement.getNameIdentifier() return referencedElement.nameIdentifier
} }
override fun getReferencedNameElementType(): IElementType { override fun getReferencedNameElementType(): IElementType {
return getReferencedNameElement().getNode()!!.getElementType() return getReferencedNameElement().node!!.elementType
} }
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D): R { override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D): R {
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
package org.jetbrains.kotlin.psi package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode import com.intellij.lang.ASTNode
import org.jetbrains.kotlin.lexer.KtTokens
import com.intellij.psi.PsiElement
class KtLabelReferenceExpression(node: ASTNode) : KtSimpleNameExpressionImpl(node) { class KtLabelReferenceExpression(node: ASTNode) : KtSimpleNameExpressionImpl(node) {
override fun getReferencedNameElement() = getIdentifier() ?: this override fun getReferencedNameElement() = getIdentifier() ?: this
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,12 +20,11 @@ import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.IElementType
import com.intellij.psi.tree.TokenSet import com.intellij.psi.tree.TokenSet
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.stubs.KotlinNameReferenceExpressionStub import org.jetbrains.kotlin.psi.stubs.KotlinNameReferenceExpressionStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.lexer.KtTokens.*
class KtNameReferenceExpression : KtExpressionImplStub<KotlinNameReferenceExpressionStub>, KtSimpleNameExpression { class KtNameReferenceExpression : KtExpressionImplStub<KotlinNameReferenceExpressionStub>, KtSimpleNameExpression {
constructor(node: ASTNode) : super(node) { constructor(node: ASTNode) : super(node) {
@@ -35,7 +34,7 @@ class KtNameReferenceExpression : KtExpressionImplStub<KotlinNameReferenceExpres
} }
override fun getReferencedName(): String { override fun getReferencedName(): String {
val stub = getStub() val stub = stub
if (stub != null) { if (stub != null) {
return stub.getReferencedName() return stub.getReferencedName()
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ class KtPrimaryConstructor : KtConstructor<KtPrimaryConstructor> {
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D) = visitor.visitPrimaryConstructor(this, data) override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D) = visitor.visitPrimaryConstructor(this, data)
override fun getContainingClassOrObject() = getParent() as KtClassOrObject override fun getContainingClassOrObject() = parent as KtClassOrObject
private fun getOrCreateConstructorKeyword(): PsiElement { private fun getOrCreateConstructorKeyword(): PsiElement {
return getConstructorKeyword() ?: addBefore(KtPsiFactory(this).createConstructorKeyword(), valueParameterList!!) return getConstructorKeyword() ?: addBefore(KtPsiFactory(this).createConstructorKeyword(), valueParameterList!!)
@@ -59,13 +59,13 @@ class KtPrimaryConstructor : KtConstructor<KtPrimaryConstructor> {
} }
override fun addAnnotationEntry(annotationEntry: KtAnnotationEntry): KtAnnotationEntry { override fun addAnnotationEntry(annotationEntry: KtAnnotationEntry): KtAnnotationEntry {
val modifierList = getModifierList() val modifierList = modifierList
return if (modifierList != null) { return if (modifierList != null) {
modifierList.addBefore(annotationEntry, modifierList.firstChild) as KtAnnotationEntry modifierList.addBefore(annotationEntry, modifierList.firstChild) as KtAnnotationEntry
} }
else { else {
val parameterList = getValueParameterList()!! val parameterList = valueParameterList!!
val newModifierList = KtPsiFactory(getProject()).createModifierList(annotationEntry.text) val newModifierList = KtPsiFactory(project).createModifierList(annotationEntry.text)
(addBefore(newModifierList, parameterList) as KtModifierList).annotationEntries.first() (addBefore(newModifierList, parameterList) as KtModifierList).annotationEntries.first()
} }
} }
@@ -47,12 +47,12 @@ class KtPsiFactory(private val project: Project) {
fun createValKeyword(): PsiElement { fun createValKeyword(): PsiElement {
val property = createProperty("val x = 1") val property = createProperty("val x = 1")
return property.getValOrVarKeyword() return property.valOrVarKeyword
} }
fun createVarKeyword(): PsiElement { fun createVarKeyword(): PsiElement {
val property = createProperty("var x = 1") val property = createProperty("var x = 1")
return property.getValOrVarKeyword() return property.valOrVarKeyword
} }
fun createSafeCallNode(): ASTNode { fun createSafeCallNode(): ASTNode {
@@ -61,7 +61,7 @@ class KtPsiFactory(private val project: Project) {
private fun doCreateExpression(text: String): KtExpression { private fun doCreateExpression(text: String): KtExpression {
//TODO: '\n' below if important - some strange code indenting problems appear without it //TODO: '\n' below if important - some strange code indenting problems appear without it
val expression = createProperty("val x =\n$text").getInitializer() ?: error("Failed to create expression from text: '$text'") val expression = createProperty("val x =\n$text").initializer ?: error("Failed to create expression from text: '$text'")
return expression return expression
} }
@@ -83,12 +83,12 @@ class KtPsiFactory(private val project: Project) {
fun createCallArguments(text: String): KtValueArgumentList { fun createCallArguments(text: String): KtValueArgumentList {
val property = createProperty("val x = foo $text") val property = createProperty("val x = foo $text")
return (property.getInitializer() as KtCallExpression).valueArgumentList!! return (property.initializer as KtCallExpression).valueArgumentList!!
} }
fun createTypeArguments(text: String): KtTypeArgumentList { fun createTypeArguments(text: String): KtTypeArgumentList {
val property = createProperty("val x = foo$text()") val property = createProperty("val x = foo$text()")
return (property.getInitializer() as KtCallExpression).typeArgumentList!! return (property.initializer as KtCallExpression).typeArgumentList!!
} }
fun createTypeArgument(text: String) = createTypeArguments("<$text>").arguments.first() fun createTypeArgument(text: String) = createTypeArguments("<$text>").arguments.first()
@@ -114,7 +114,7 @@ class KtPsiFactory(private val project: Project) {
fun createTypeAlias(name: String, typeParameters: List<String>, body: String): KtTypeAlias { fun createTypeAlias(name: String, typeParameters: List<String>, body: String): KtTypeAlias {
val typeParametersText = if (typeParameters.isNotEmpty()) typeParameters.joinToString(prefix = "<", postfix = ">") else "" val typeParametersText = if (typeParameters.isNotEmpty()) typeParameters.joinToString(prefix = "<", postfix = ">") else ""
return createDeclaration<KtTypeAlias>("typealias $name$typeParametersText = $body") return createDeclaration("typealias $name$typeParametersText = $body")
} }
fun createStar(): PsiElement { fun createStar(): PsiElement {
@@ -134,7 +134,7 @@ class KtPsiFactory(private val project: Project) {
} }
fun createEQ(): PsiElement { fun createEQ(): PsiElement {
return createFunction("fun foo() = foo").getEqualsToken()!! return createFunction("fun foo() = foo").equalsToken!!
} }
fun createSemicolon(): PsiElement { fun createSemicolon(): PsiElement {
@@ -177,7 +177,7 @@ class KtPsiFactory(private val project: Project) {
} }
fun createFileAnnotationListWithAnnotation(annotationText: String) : KtFileAnnotationList { fun createFileAnnotationListWithAnnotation(annotationText: String) : KtFileAnnotationList {
return createFile("@file:${annotationText}").fileAnnotationList!! return createFile("@file:$annotationText").fileAnnotationList!!
} }
fun createFile(text: String): KtFile { fun createFile(text: String): KtFile {
@@ -213,7 +213,7 @@ class KtPsiFactory(private val project: Project) {
} }
fun createProperty(modifiers: String?, name: String, type: String?, isVar: Boolean, initializer: String?): KtProperty { fun createProperty(modifiers: String?, name: String, type: String?, isVar: Boolean, initializer: String?): KtProperty {
val text = (modifiers.let { "$it "} ?: "") + val text = modifiers.let { "$it "} +
(if (isVar) " var " else " val ") + name + (if (isVar) " var " else " val ") + name +
(if (type != null) ":" + type else "") + (if (initializer == null) "" else " = " + initializer) (if (type != null) ":" + type else "") + (if (initializer == null) "" else " = " + initializer)
return createProperty(text) return createProperty(text)
@@ -259,11 +259,11 @@ class KtPsiFactory(private val project: Project) {
} }
fun createNameIdentifier(name: String): PsiElement { fun createNameIdentifier(name: String): PsiElement {
return createProperty(name, null, false).getNameIdentifier()!! return createProperty(name, null, false).nameIdentifier!!
} }
fun createSimpleName(name: String): KtSimpleNameExpression { fun createSimpleName(name: String): KtSimpleNameExpression {
return createProperty(name, null, false, name).getInitializer() as KtSimpleNameExpression return createProperty(name, null, false, name).initializer as KtSimpleNameExpression
} }
fun createOperationName(name: String): KtSimpleNameExpression { fun createOperationName(name: String): KtSimpleNameExpression {
@@ -289,7 +289,7 @@ class KtPsiFactory(private val project: Project) {
} }
fun createModifierList(text: String): KtModifierList { fun createModifierList(text: String): KtModifierList {
return createProperty(text + " val x").getModifierList()!! return createProperty(text + " val x").modifierList!!
} }
fun createModifier(modifier: KtModifierKeywordToken): PsiElement { fun createModifier(modifier: KtModifierKeywordToken): PsiElement {
@@ -297,12 +297,12 @@ class KtPsiFactory(private val project: Project) {
} }
fun createAnnotationEntry(text: String): KtAnnotationEntry { fun createAnnotationEntry(text: String): KtAnnotationEntry {
val modifierList = createProperty(text + " val x").getModifierList() val modifierList = createProperty(text + " val x").modifierList
return modifierList!!.getAnnotationEntries().first() return modifierList!!.annotationEntries.first()
} }
fun createEmptyBody(): KtBlockExpression { fun createEmptyBody(): KtBlockExpression {
return createFunction("fun foo() {}").getBodyExpression() as KtBlockExpression return createFunction("fun foo() {}").bodyExpression as KtBlockExpression
} }
fun createAnonymousInitializer(): KtAnonymousInitializer { fun createAnonymousInitializer(): KtAnonymousInitializer {
@@ -318,7 +318,7 @@ class KtPsiFactory(private val project: Project) {
} }
fun createParameterList(text: String): KtParameterList { fun createParameterList(text: String): KtParameterList {
return createFunction("fun foo$text{}").getValueParameterList()!! return createFunction("fun foo$text{}").valueParameterList!!
} }
fun createTypeParameterList(text: String) = createClass("class Foo$text").typeParameterList!! fun createTypeParameterList(text: String) = createClass("class Foo$text").typeParameterList!!
@@ -330,7 +330,7 @@ class KtPsiFactory(private val project: Project) {
} }
fun createEnumEntry(text: String): KtEnumEntry { fun createEnumEntry(text: String): KtEnumEntry {
return createDeclaration<KtClass>("enum class E {$text}").getDeclarations()[0] as KtEnumEntry return createDeclaration<KtClass>("enum class E {$text}").declarations[0] as KtEnumEntry
} }
fun createEnumEntryInitializerList(): KtInitializerList { fun createEnumEntryInitializerList(): KtInitializerList {
@@ -338,7 +338,7 @@ class KtPsiFactory(private val project: Project) {
} }
fun createWhenEntry(entryText: String): KtWhenEntry { fun createWhenEntry(entryText: String): KtWhenEntry {
val function = createFunction("fun foo() { when(12) { " + entryText + " } }") val function = createFunction("fun foo() { when(12) { $entryText } }")
val whenEntry = PsiTreeUtil.findChildOfType(function, KtWhenEntry::class.java) val whenEntry = PsiTreeUtil.findChildOfType(function, KtWhenEntry::class.java)
assert(whenEntry != null) { "Couldn't generate when entry" } assert(whenEntry != null) { "Couldn't generate when entry" }
@@ -386,7 +386,7 @@ class KtPsiFactory(private val project: Project) {
fun createImportDirectiveWithImportList(importPath: ImportPath): KtImportList { fun createImportDirectiveWithImportList(importPath: ImportPath): KtImportList {
val importDirective = createImportDirective(importPath) val importDirective = createImportDirective(importPath)
return importDirective.getParent() as KtImportList return importDirective.parent as KtImportList
} }
fun createPrimaryConstructor(): KtPrimaryConstructor { fun createPrimaryConstructor(): KtPrimaryConstructor {
@@ -485,7 +485,7 @@ class KtPsiFactory(private val project: Project) {
private fun placeKeyword() { private fun placeKeyword() {
assert(state == State.MODIFIERS) assert(state == State.MODIFIERS)
if (sb.length != 0) { if (sb.isNotEmpty()) {
sb.append(" ") sb.append(" ")
} }
sb.append("class ") sb.append("class ")
@@ -592,7 +592,7 @@ class KtPsiFactory(private val project: Project) {
private fun placeKeyword() { private fun placeKeyword() {
assert(state == State.MODIFIERS) assert(state == State.MODIFIERS)
if (sb.length != 0) { if (sb.isNotEmpty()) {
sb.append(" ") sb.append(" ")
} }
val keyword = when (target) { val keyword = when (target) {
@@ -743,11 +743,11 @@ class KtPsiFactory(private val project: Project) {
} }
fun createBlock(bodyText: String): KtBlockExpression { fun createBlock(bodyText: String): KtBlockExpression {
return createFunction("fun foo() {\n" + bodyText + "\n}").getBodyExpression() as KtBlockExpression return createFunction("fun foo() {\n$bodyText\n}").bodyExpression as KtBlockExpression
} }
fun createSingleStatementBlock(statement: KtExpression): KtBlockExpression { fun createSingleStatementBlock(statement: KtExpression): KtBlockExpression {
return createDeclarationByPattern<KtNamedFunction>("fun foo() {\n$0\n}", statement).getBodyExpression() as KtBlockExpression return createDeclarationByPattern<KtNamedFunction>("fun foo() {\n$0\n}", statement).bodyExpression as KtBlockExpression
} }
fun createComment(text: String): PsiComment { fun createComment(text: String): PsiComment {
@@ -765,7 +765,7 @@ class KtPsiFactory(private val project: Project) {
return expression return expression
} }
val function = createFunction("fun f() { ${expression.text} }") val function = createFunction("fun f() { ${expression.text} }")
val block = function.getBodyExpression() as KtBlockExpression val block = function.bodyExpression as KtBlockExpression
return BlockWrapper(block, expression) return BlockWrapper(block, expression)
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ class KtSecondaryConstructor : KtConstructor<KtSecondaryConstructor> {
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D) = visitor.visitSecondaryConstructor(this, data) override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D) = visitor.visitSecondaryConstructor(this, data)
override fun getContainingClassOrObject() = getParent().getParent() as KtClassOrObject override fun getContainingClassOrObject() = parent.parent as KtClassOrObject
override fun getBodyExpression() = findChildByClass(KtBlockExpression::class.java) override fun getBodyExpression() = findChildByClass(KtBlockExpression::class.java)
@@ -35,16 +35,16 @@ class KtSecondaryConstructor : KtConstructor<KtSecondaryConstructor> {
fun getDelegationCall(): KtConstructorDelegationCall = findNotNullChildByClass(KtConstructorDelegationCall::class.java) fun getDelegationCall(): KtConstructorDelegationCall = findNotNullChildByClass(KtConstructorDelegationCall::class.java)
fun hasImplicitDelegationCall(): Boolean = getDelegationCall().isImplicit() fun hasImplicitDelegationCall(): Boolean = getDelegationCall().isImplicit
fun replaceImplicitDelegationCallWithExplicit(isThis: Boolean): KtConstructorDelegationCall { fun replaceImplicitDelegationCallWithExplicit(isThis: Boolean): KtConstructorDelegationCall {
val psiFactory = KtPsiFactory(getProject()) val psiFactory = KtPsiFactory(project)
val current = getDelegationCall() val current = getDelegationCall()
assert(current.isImplicit()) { "Method should not be called with explicit delegation call: " + getText() } assert(current.isImplicit) { "Method should not be called with explicit delegation call: " + text }
current.delete() current.delete()
val colon = addAfter(psiFactory.createColon(), getValueParameterList()) val colon = addAfter(psiFactory.createColon(), valueParameterList)
val delegationName = if (isThis) "this" else "super" val delegationName = if (isThis) "this" else "super"
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiReference
import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.IElementType
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.psi package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode import com.intellij.lang.ASTNode
import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.ItemPresentationProviders import com.intellij.navigation.ItemPresentationProviders
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.KtNodeTypes
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,20 +16,20 @@
package org.jetbrains.kotlin.psi.typeRefHelpers package org.jetbrains.kotlin.psi.typeRefHelpers
import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.psiUtil.siblings
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.KtPsiFactory
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.PsiErrorElement import com.intellij.psi.PsiErrorElement
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtCallableDeclaration import org.jetbrains.kotlin.psi.KtCallableDeclaration
import org.jetbrains.kotlin.psi.KtFunctionType import org.jetbrains.kotlin.psi.KtFunctionType
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.psi.psiUtil.siblings
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
fun getTypeReference(declaration: KtCallableDeclaration): KtTypeReference? { fun getTypeReference(declaration: KtCallableDeclaration): KtTypeReference? {
return declaration.getFirstChild()!!.siblings(forward = true) return declaration.firstChild!!.siblings(forward = true)
.dropWhile { it.getNode()!!.getElementType() != KtTokens.COLON } .dropWhile { it.node!!.elementType != KtTokens.COLON }
.firstIsInstanceOrNull<KtTypeReference>() .firstIsInstanceOrNull<KtTypeReference>()
} }
@@ -40,16 +40,16 @@ fun setTypeReference(declaration: KtCallableDeclaration, addAfter: PsiElement?,
return oldTypeRef.replace(typeRef) as KtTypeReference return oldTypeRef.replace(typeRef) as KtTypeReference
} }
else { else {
var anchor = addAfter ?: declaration.getNameIdentifier()?.siblings(forward = true)?.firstOrNull { it is PsiErrorElement } val anchor = addAfter ?: declaration.nameIdentifier?.siblings(forward = true)?.firstOrNull { it is PsiErrorElement }
val newTypeRef = declaration.addAfter(typeRef, anchor) as KtTypeReference val newTypeRef = declaration.addAfter(typeRef, anchor) as KtTypeReference
declaration.addAfter(KtPsiFactory(declaration.getProject()).createColon(), anchor) declaration.addAfter(KtPsiFactory(declaration.project).createColon(), anchor)
return newTypeRef return newTypeRef
} }
} }
else { else {
if (oldTypeRef != null) { if (oldTypeRef != null) {
val colon = declaration.getColon()!! val colon = declaration.colon!!
val removeFrom = colon.getPrevSibling() as? PsiWhiteSpace ?: colon val removeFrom = colon.prevSibling as? PsiWhiteSpace ?: colon
declaration.deleteChildRange(removeFrom, oldTypeRef) declaration.deleteChildRange(removeFrom, oldTypeRef)
} }
return null return null
@@ -58,28 +58,28 @@ fun setTypeReference(declaration: KtCallableDeclaration, addAfter: PsiElement?,
fun KtCallableDeclaration.setReceiverTypeReference(typeRef: KtTypeReference?): KtTypeReference? { fun KtCallableDeclaration.setReceiverTypeReference(typeRef: KtTypeReference?): KtTypeReference? {
val needParentheses = typeRef != null && typeRef.typeElement is KtFunctionType && !typeRef.hasParentheses() val needParentheses = typeRef != null && typeRef.typeElement is KtFunctionType && !typeRef.hasParentheses()
val oldTypeRef = getReceiverTypeReference() val oldTypeRef = receiverTypeReference
if (typeRef != null) { if (typeRef != null) {
val newTypeRef = val newTypeRef =
if (oldTypeRef != null) { if (oldTypeRef != null) {
oldTypeRef.replace(typeRef) as KtTypeReference oldTypeRef.replace(typeRef) as KtTypeReference
} }
else { else {
val anchor = getNameIdentifier() ?: valueParameterList val anchor = nameIdentifier ?: valueParameterList
val newTypeRef = addBefore(typeRef, anchor) as KtTypeReference val newTypeRef = addBefore(typeRef, anchor) as KtTypeReference
addAfter(KtPsiFactory(getProject()).createDot(), newTypeRef) addAfter(KtPsiFactory(project).createDot(), newTypeRef)
newTypeRef newTypeRef
} }
if (needParentheses) { if (needParentheses) {
val argList = KtPsiFactory(getProject()).createCallArguments("()") val argList = KtPsiFactory(project).createCallArguments("()")
newTypeRef.addBefore(argList.getLeftParenthesis()!!, newTypeRef.getFirstChild()) newTypeRef.addBefore(argList.leftParenthesis!!, newTypeRef.firstChild)
newTypeRef.add(argList.getRightParenthesis()!!) newTypeRef.add(argList.rightParenthesis!!)
} }
return newTypeRef return newTypeRef
} }
else { else {
if (oldTypeRef != null) { if (oldTypeRef != null) {
val dot = oldTypeRef.siblings(forward = true).firstOrNull { it.getNode().getElementType() == KtTokens.DOT } val dot = oldTypeRef.siblings(forward = true).firstOrNull { it.node.elementType == KtTokens.DOT }
deleteChildRange(oldTypeRef, dot ?: oldTypeRef) deleteChildRange(oldTypeRef, dot ?: oldTypeRef)
} }
return null return null
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.siblings import org.jetbrains.kotlin.psi.psiUtil.siblings
@@ -85,12 +84,12 @@ internal fun addModifier(modifierList: KtModifierList, modifier: KtModifierKeywo
return newModifierOrder > order return newModifierOrder > order
} }
val lastChild = modifierList.getLastChild() val lastChild = modifierList.lastChild
val anchor = lastChild?.siblings(forward = false)?.firstOrNull(::placeAfter) val anchor = lastChild?.siblings(forward = false)?.firstOrNull(::placeAfter)
modifierList.addAfter(newModifier, anchor) modifierList.addAfter(newModifier, anchor)
if (anchor == lastChild) { // add line break if needed, otherwise visibility keyword may appear on previous line if (anchor == lastChild) { // add line break if needed, otherwise visibility keyword may appear on previous line
val whiteSpace = modifierList.getNextSibling() as? PsiWhiteSpace val whiteSpace = modifierList.nextSibling as? PsiWhiteSpace
if (whiteSpace != null && whiteSpace.text.contains('\n')) { if (whiteSpace != null && whiteSpace.text.contains('\n')) {
modifierList.addAfter(whiteSpace, anchor) modifierList.addAfter(whiteSpace, anchor)
whiteSpace.delete() whiteSpace.delete()
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ var KtFile.suppressDiagnosticsInDebugMode: Boolean
is KtFile -> getUserData(SUPPRESS_DIAGNOSTICS_IN_DEBUG_MODE) ?: false is KtFile -> getUserData(SUPPRESS_DIAGNOSTICS_IN_DEBUG_MODE) ?: false
else -> false else -> false
} }
set(skip: Boolean) { set(skip) {
putUserData(SUPPRESS_DIAGNOSTICS_IN_DEBUG_MODE, skip) putUserData(SUPPRESS_DIAGNOSTICS_IN_DEBUG_MODE, skip)
} }
@@ -50,8 +50,8 @@ val DEBUG_TYPE_REFERENCE_STRING: String = "DebugTypeKotlinRulezzzz"
val DEBUG_TYPE_INFO: Key<KotlinType> = Key.create<KotlinType>("DEBUG_TYPE_INFO") val DEBUG_TYPE_INFO: Key<KotlinType> = Key.create<KotlinType>("DEBUG_TYPE_INFO")
var KtTypeReference.debugTypeInfo: KotlinType? var KtTypeReference.debugTypeInfo: KotlinType?
get() = getUserData(DEBUG_TYPE_INFO) get() = getUserData(DEBUG_TYPE_INFO)
set(type: KotlinType?) { set(type) {
if (type != null && this.getText() == DEBUG_TYPE_REFERENCE_STRING) { if (type != null && this.text == DEBUG_TYPE_REFERENCE_STRING) {
putUserData(DEBUG_TYPE_INFO, type) putUserData(DEBUG_TYPE_INFO, type)
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -87,10 +87,10 @@ private object PsiChildRangeArgumentType : PsiElementPlaceholderArgumentType<Psi
} }
private val SUPPORTED_ARGUMENT_TYPES = listOf( private val SUPPORTED_ARGUMENT_TYPES = listOf(
PsiElementArgumentType<KtExpression>(KtExpression::class.java), PsiElementArgumentType(KtExpression::class.java),
PsiElementArgumentType<KtTypeReference>(KtTypeReference::class.java), PsiElementArgumentType(KtTypeReference::class.java),
PlainTextArgumentType<String>(String::class.java, toPlainText = { it }), PlainTextArgumentType(String::class.java, toPlainText = { it }),
PlainTextArgumentType<Name>(Name::class.java, toPlainText = { it.render() }), PlainTextArgumentType(Name::class.java, toPlainText = Name::render),
PsiChildRangeArgumentType PsiChildRangeArgumentType
) )
@@ -130,7 +130,7 @@ fun <TElement : KtElement> createByPattern(pattern: String, vararg args: Any, fa
for ((range, text) in placeholders) { for ((range, text) in placeholders) {
val token = resultElement.findElementAt(range.startOffset)!! val token = resultElement.findElementAt(range.startOffset)!!
for (element in token.parentsWithSelf) { for (element in token.parentsWithSelf) {
val elementRange = element.getTextRange().shiftRight(-start) val elementRange = element.textRange.shiftRight(-start)
if (elementRange == range && expectedElementType.isInstance(element)) { if (elementRange == range && expectedElementType.isInstance(element)) {
val pointer = pointerManager.createSmartPsiElementPointer(element) val pointer = pointerManager.createSmartPsiElementPointer(element)
pointers.put(pointer, n) pointers.put(pointer, n)
@@ -208,7 +208,7 @@ private fun processPattern(pattern: String, args: List<Any>): PatternData {
val text = buildString { val text = buildString {
var i = 0 var i = 0
while (i < pattern.length) { while (i < pattern.length) {
var c = pattern[i] val c = pattern[i]
if (c == '$') { if (c == '$') {
val nextChar = charOrNull(++i) val nextChar = charOrNull(++i)
@@ -47,7 +47,7 @@ fun KtCallElement.getCallNameExpression(): KtSimpleNameExpression? {
return when (calleeExpression) { return when (calleeExpression) {
is KtSimpleNameExpression -> calleeExpression is KtSimpleNameExpression -> calleeExpression
is KtConstructorCalleeExpression -> calleeExpression.getConstructorReferenceExpression() is KtConstructorCalleeExpression -> calleeExpression.constructorReferenceExpression
else -> null else -> null
} }
} }
@@ -82,9 +82,9 @@ fun KtElement.getQualifiedElementSelector(): KtElement? {
is KtCallExpression -> calleeExpression is KtCallExpression -> calleeExpression
is KtQualifiedExpression -> { is KtQualifiedExpression -> {
val selector = selectorExpression val selector = selectorExpression
if (selector is KtCallExpression) selector.calleeExpression else selector (selector as? KtCallExpression)?.calleeExpression ?: selector
} }
is KtUserType -> getReferenceExpression() is KtUserType -> referenceExpression
else -> null else -> null
} }
} }
@@ -111,15 +111,15 @@ fun KtSimpleNameExpression.getReceiverExpression(): KtExpression? {
} }
} }
parent is KtBinaryExpression && parent.operationReference == this -> { parent is KtBinaryExpression && parent.operationReference == this -> {
return if (parent.getOperationToken() in OperatorConventions.IN_OPERATIONS) parent.right else parent.left return if (parent.operationToken in OperatorConventions.IN_OPERATIONS) parent.right else parent.left
} }
parent is KtUnaryExpression && parent.operationReference == this -> { parent is KtUnaryExpression && parent.operationReference == this -> {
return parent.baseExpression return parent.baseExpression
} }
parent is KtUserType -> { parent is KtUserType -> {
val qualifier = parent.getQualifier() val qualifier = parent.qualifier
if (qualifier != null) { if (qualifier != null) {
return qualifier.getReferenceExpression()!! return qualifier.referenceExpression!!
} }
} }
} }
@@ -204,11 +204,11 @@ fun StubBasedPsiElementBase<out KotlinClassOrObjectStub<out KtClassOrObject>>.ge
fun addSuperName(result: MutableList<String>, referencedName: String): Unit { fun addSuperName(result: MutableList<String>, referencedName: String): Unit {
result.add(referencedName) result.add(referencedName)
val file = getContainingFile() val file = containingFile
if (file is KtFile) { if (file is KtFile) {
val directive = file.findImportByAlias(referencedName) val directive = file.findImportByAlias(referencedName)
if (directive != null) { if (directive != null) {
var reference = directive.getImportedReference() var reference = directive.importedReference
while (reference is KtDotQualifiedExpression) { while (reference is KtDotQualifiedExpression) {
reference = reference.selectorExpression reference = reference.selectorExpression
} }
@@ -221,7 +221,7 @@ fun StubBasedPsiElementBase<out KotlinClassOrObjectStub<out KtClassOrObject>>.ge
require(this is KtClassOrObject) { "it should be ${KtClassOrObject::class} but it is a ${this.javaClass.name}" } require(this is KtClassOrObject) { "it should be ${KtClassOrObject::class} but it is a ${this.javaClass.name}" }
val stub = getStub() val stub = stub
if (stub != null) { if (stub != null) {
return stub.getSuperNames() return stub.getSuperNames()
} }
@@ -231,9 +231,9 @@ fun StubBasedPsiElementBase<out KotlinClassOrObjectStub<out KtClassOrObject>>.ge
val result = ArrayList<String>() val result = ArrayList<String>()
for (specifier in specifiers) { for (specifier in specifiers) {
val superType = specifier.getTypeAsUserType() val superType = specifier.typeAsUserType
if (superType != null) { if (superType != null) {
val referencedName = superType.getReferencedName() val referencedName = superType.referencedName
if (referencedName != null) { if (referencedName != null) {
addSuperName(result, referencedName) addSuperName(result, referencedName)
} }
@@ -267,7 +267,7 @@ private fun StubElement<*>.collectAnnotationEntriesFromStubElement(): List<KtAnn
child -> child ->
when (child.stubType) { when (child.stubType) {
KtNodeTypes.ANNOTATION_ENTRY -> listOf(child.psi as KtAnnotationEntry) KtNodeTypes.ANNOTATION_ENTRY -> listOf(child.psi as KtAnnotationEntry)
KtNodeTypes.ANNOTATION -> (child.psi as KtAnnotation).getEntries() KtNodeTypes.ANNOTATION -> (child.psi as KtAnnotation).entries
else -> emptyList<KtAnnotationEntry>() else -> emptyList<KtAnnotationEntry>()
} }
} }
@@ -277,7 +277,7 @@ private fun KtAnnotationsContainer.collectAnnotationEntriesFromPsi(): List<KtAnn
return children.flatMap { child -> return children.flatMap { child ->
when (child) { when (child) {
is KtAnnotationEntry -> listOf(child) is KtAnnotationEntry -> listOf(child)
is KtAnnotation -> child.getEntries() is KtAnnotation -> child.entries
else -> emptyList<KtAnnotationEntry>() else -> emptyList<KtAnnotationEntry>()
} }
} }
@@ -307,7 +307,7 @@ inline fun <reified T : KtElement, R> flatMapDescendantsOfTypeVisitor(accumulato
fun KtClassOrObject.effectiveDeclarations(): List<KtDeclaration> { fun KtClassOrObject.effectiveDeclarations(): List<KtDeclaration> {
return when(this) { return when(this) {
is KtClass -> getDeclarations() + getPrimaryConstructorParameters().filter { p -> p.hasValOrVar() } is KtClass -> getDeclarations() + getPrimaryConstructorParameters().filter { p -> p.hasValOrVar() }
else -> getDeclarations() else -> declarations
} }
} }
@@ -327,7 +327,7 @@ fun KtClassOrObject.isObjectLiteral(): Boolean = this is KtObjectDeclaration &&
fun PsiElement.parameterIndex(): Int { fun PsiElement.parameterIndex(): Int {
val parent = parent val parent = parent
return when { return when {
this is KtParameter && parent is KtParameterList -> parent.getParameters().indexOf(this) this is KtParameter && parent is KtParameterList -> parent.parameters.indexOf(this)
this is PsiParameter && parent is PsiParameterList -> parent.getParameterIndex(this) this is PsiParameter && parent is PsiParameterList -> parent.getParameterIndex(this)
else -> -1 else -> -1
} }
@@ -375,7 +375,7 @@ fun KtStringTemplateExpression.isSingleQuoted(): Boolean
= node.firstChildNode.textLength == 1 = node.firstChildNode.textLength == 1
fun KtNamedDeclaration.getValueParameters(): List<KtParameter> { fun KtNamedDeclaration.getValueParameters(): List<KtParameter> {
return getValueParameterList()?.getParameters() ?: Collections.emptyList() return getValueParameterList()?.parameters ?: Collections.emptyList()
} }
fun KtNamedDeclaration.getValueParameterList(): KtParameterList? { fun KtNamedDeclaration.getValueParameterList(): KtParameterList? {
@@ -461,7 +461,7 @@ fun KtElement.nonStaticOuterClasses(): Sequence<KtClass> {
return generateSequence(containingClass()) { if (it.isInner()) it.containingClass() else null } return generateSequence(containingClass()) { if (it.isInner()) it.containingClass() else null }
} }
fun KtElement.containingClass(): KtClass? = getStrictParentOfType<KtClass>() fun KtElement.containingClass(): KtClass? = getStrictParentOfType()
fun KtClassOrObject.findPropertyByName(name: String): KtNamedDeclaration? { fun KtClassOrObject.findPropertyByName(name: String): KtNamedDeclaration? {
return declarations.firstOrNull { it is KtProperty && it.name == name } as KtNamedDeclaration? return declarations.firstOrNull { it is KtProperty && it.name == name } as KtNamedDeclaration?
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -183,7 +183,7 @@ fun PsiChildRange.trimWhiteSpaces(): PsiChildRange {
// -------------------- Recursive tree visiting -------------------------------------------------------------------------------------------- // -------------------- Recursive tree visiting --------------------------------------------------------------------------------------------
inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(noinline action: (T) -> Unit) { inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(noinline action: (T) -> Unit) {
forEachDescendantOfType<T>({ true }, action) forEachDescendantOfType({ true }, action)
} }
inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline action: (T) -> Unit) { inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline action: (T) -> Unit) {
@@ -201,15 +201,15 @@ inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(crossinli
} }
inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(noinline predicate: (T) -> Boolean = { true }): Boolean { inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(noinline predicate: (T) -> Boolean = { true }): Boolean {
return findDescendantOfType<T>(predicate) != null return findDescendantOfType(predicate) != null
} }
inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): Boolean { inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): Boolean {
return findDescendantOfType<T>(canGoInside, predicate) != null return findDescendantOfType(canGoInside, predicate) != null
} }
inline fun <reified T : PsiElement> PsiElement.findDescendantOfType(noinline predicate: (T) -> Boolean = { true }): T? { inline fun <reified T : PsiElement> PsiElement.findDescendantOfType(noinline predicate: (T) -> Boolean = { true }): T? {
return findDescendantOfType<T>({ true }, predicate) return findDescendantOfType({ true }, predicate)
} }
inline fun <reified T : PsiElement> PsiElement.findDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): T? { inline fun <reified T : PsiElement> PsiElement.findDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): T? {
@@ -231,7 +231,7 @@ inline fun <reified T : PsiElement> PsiElement.findDescendantOfType(crossinline
} }
inline fun <reified T : PsiElement> PsiElement.collectDescendantsOfType(noinline predicate: (T) -> Boolean = { true }): List<T> { inline fun <reified T : PsiElement> PsiElement.collectDescendantsOfType(noinline predicate: (T) -> Boolean = { true }): List<T> {
return collectDescendantsOfType<T>({ true }, predicate) return collectDescendantsOfType({ true }, predicate)
} }
inline fun <reified T : PsiElement> PsiElement.collectDescendantsOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): List<T> { inline fun <reified T : PsiElement> PsiElement.collectDescendantsOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): List<T> {
@@ -37,7 +37,7 @@ class KtTypeAliasElementType(debugName: String) :
} }
override fun serialize(stub: KotlinTypeAliasStub, dataStream: StubOutputStream) { override fun serialize(stub: KotlinTypeAliasStub, dataStream: StubOutputStream) {
dataStream.writeName(stub.getName()) dataStream.writeName(stub.name)
dataStream.writeName(stub.getFqName()?.asString()) dataStream.writeName(stub.getFqName()?.asString())
dataStream.writeBoolean(stub.isTopLevel()) dataStream.writeBoolean(stub.isTopLevel())
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,15 +16,14 @@
package org.jetbrains.kotlin.psi.stubs.impl package org.jetbrains.kotlin.psi.stubs.impl
import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.StubElement import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef import com.intellij.util.io.StringRef
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.stubs.KotlinClassStub import org.jetbrains.kotlin.psi.stubs.KotlinClassStub
import org.jetbrains.kotlin.psi.stubs.elements.KtClassElementType import org.jetbrains.kotlin.psi.stubs.elements.KtClassElementType
import org.jetbrains.kotlin.name.FqName import java.util.*
import java.util.ArrayList
import com.intellij.psi.PsiElement
class KotlinClassStubImpl( class KotlinClassStubImpl(
type: KtClassElementType, type: KtClassElementType,
@@ -39,10 +38,7 @@ class KotlinClassStubImpl(
) : KotlinStubBaseImpl<KtClass>(parent, type), KotlinClassStub { ) : KotlinStubBaseImpl<KtClass>(parent, type), KotlinClassStub {
override fun getFqName(): FqName? { override fun getFqName(): FqName? {
val stringRef = StringRef.toString(qualifiedName) val stringRef = StringRef.toString(qualifiedName) ?: return null
if (stringRef == null) {
return null
}
return FqName(stringRef) return FqName(stringRef)
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.psi.stubs.impl package org.jetbrains.kotlin.psi.stubs.impl
import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.StubElement import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef import com.intellij.util.io.StringRef
import org.jetbrains.kotlin.psi.KtEnumEntrySuperclassReferenceExpression import org.jetbrains.kotlin.psi.KtEnumEntrySuperclassReferenceExpression
@@ -35,7 +35,7 @@ class KotlinTypeAliasStubImpl(
StringRef.toString(name) StringRef.toString(name)
override fun getFqName(): FqName? = override fun getFqName(): FqName? =
StringRef.toString(qualifiedName)?.let { FqName(it) } StringRef.toString(qualifiedName)?.let(::FqName)
override fun isTopLevel(): Boolean = isTopLevel override fun isTopLevel(): Boolean = isTopLevel
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,6 +20,6 @@ import com.intellij.util.io.StringRef
object Utils { object Utils {
fun wrapStrings(names : List<String>) : Array<StringRef> { fun wrapStrings(names : List<String>) : Array<StringRef> {
return Array(names.size) { i -> StringRef.fromString(names.get(i))!! } return Array(names.size) { i -> StringRef.fromString(names[i])!! }
} }
} }