From ba7f60040acd87d23348828b12c939ea5bb1bcf0 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 1 Nov 2016 00:01:21 +0100 Subject: [PATCH] clean up psi package --- .../org/jetbrains/kotlin/psi/DebugTextUtil.kt | 91 +++++++++---------- .../psi/EditCommaSeparatedListHelper.kt | 10 +- .../jetbrains/kotlin/psi/FindDocComment.kt | 9 +- .../kotlin/psi/KtAnnotationUseSiteTarget.kt | 12 +-- .../src/org/jetbrains/kotlin/psi/KtClass.kt | 5 +- .../org/jetbrains/kotlin/psi/KtConstructor.kt | 22 ++--- .../kotlin/psi/KtDotQualifiedExpression.kt | 4 +- .../kotlin/psi/KtDoubleColonExpression.kt | 9 +- ...tEnumEntrySuperclassReferenceExpression.kt | 12 +-- .../kotlin/psi/KtLabelReferenceExpression.kt | 4 +- .../kotlin/psi/KtNameReferenceExpression.kt | 11 +-- .../kotlin/psi/KtPrimaryConstructor.kt | 10 +- .../org/jetbrains/kotlin/psi/KtPsiFactory.kt | 48 +++++----- .../kotlin/psi/KtSecondaryConstructor.kt | 12 +-- .../kotlin/psi/KtSimpleNameExpression.kt | 3 +- .../org/jetbrains/kotlin/psi/KtTypeAlias.kt | 1 - .../jetbrains/kotlin/psi/TypeRefHelpers.kt | 38 ++++---- .../jetbrains/kotlin/psi/addRemoveModifier.kt | 7 +- .../jetbrains/kotlin/psi/codeFragmentUtil.kt | 8 +- .../jetbrains/kotlin/psi/createByPattern.kt | 14 +-- .../jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt | 34 +++---- .../jetbrains/kotlin/psi/psiUtil/psiUtils.kt | 12 +-- .../stubs/elements/KtTypeAliasElementType.kt | 2 +- .../psi/stubs/impl/KotlinClassStubImpl.kt | 14 +-- ...rySuperclassReferenceExpressionStubImpl.kt | 3 +- .../psi/stubs/impl/KotlinTypeAliasStubImpl.kt | 2 +- .../jetbrains/kotlin/psi/stubs/impl/Utils.kt | 4 +- 27 files changed, 188 insertions(+), 213 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/DebugTextUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/DebugTextUtil.kt index d1f29a2c2b2..760d9a1af4e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/DebugTextUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/DebugTextUtil.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ fun KtElement.getDebugText(): String { return text } if (this is KtPackageDirective) { - val fqName = getFqName() - if (fqName.isRoot()) { + val fqName = fqName + if (fqName.isRoot) { return "" } return "package " + fqName.asString() @@ -54,12 +54,9 @@ private object DebugTextBuildingVisitor : KtVisitor() { } override fun visitImportDirective(importDirective: KtImportDirective, data: Unit?): String? { - val importPath = importDirective.getImportPath() - if (importPath == null) { - return "import " - } - val aliasStr = if (importPath.hasAlias()) " as " + importPath.getAlias()!!.asString() else "" - return "import ${importPath.getPathStr()}" + aliasStr + val importPath = importDirective.importPath ?: return "import " + val aliasStr = if (importPath.hasAlias()) " as " + importPath.alias!!.asString() else "" + return "import ${importPath.pathStr}" + aliasStr } override fun visitImportList(importList: KtImportList, data: Unit?): String? { @@ -67,7 +64,7 @@ private object DebugTextBuildingVisitor : KtVisitor() { } 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? { @@ -83,7 +80,7 @@ private object DebugTextBuildingVisitor : KtVisitor() { } 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? { @@ -95,11 +92,11 @@ private object DebugTextBuildingVisitor : KtVisitor() { } 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? { - return render(specifier, specifier.getTypeReference()) + return render(specifier, specifier.typeReference) } override fun visitSuperTypeList(list: KtSuperTypeList, data: Unit?): String? { @@ -125,34 +122,34 @@ private object DebugTextBuildingVisitor : KtVisitor() { override fun visitEnumEntry(enumEntry: KtEnumEntry, data: Unit?): String? { return buildText { append("STUB: ") - appendInn(enumEntry.getModifierList(), suffix = " ") + appendInn(enumEntry.modifierList, suffix = " ") append("enum entry ") - appendInn(enumEntry.getNameAsName()) - appendInn(enumEntry.getInitializerList(), prefix = " : ") + appendInn(enumEntry.nameAsName) + appendInn(enumEntry.initializerList, prefix = " : ") } } override fun visitFunctionType(functionType: KtFunctionType, data: Unit?): String? { return buildText { - appendInn(functionType.getReceiverTypeReference(), suffix = ".") - appendInn(functionType.getParameterList()) - appendInn(functionType.getReturnTypeReference(), prefix = " -> ") + appendInn(functionType.receiverTypeReference, suffix = ".") + appendInn(functionType.parameterList) + appendInn(functionType.returnTypeReference, prefix = " -> ") } } override fun visitTypeParameter(parameter: KtTypeParameter, data: Unit?): String? { return buildText { - appendInn(parameter.getModifierList(), suffix = " ") - appendInn(parameter.getNameAsName()) - appendInn(parameter.getExtendsBound(), prefix = " : ") + appendInn(parameter.modifierList, suffix = " ") + appendInn(parameter.nameAsName) + appendInn(parameter.extendsBound, prefix = " : ") } } override fun visitTypeProjection(typeProjection: KtTypeProjection, data: Unit?): String? { return buildText { - val token = typeProjection.getProjectionKind().getToken() - appendInn(token?.getValue()) - val typeReference = typeProjection.getTypeReference() + val token = typeProjection.projectionKind.token + appendInn(token?.value) + val typeReference = typeProjection.typeReference if (token != null && typeReference != null) { append(" ") } @@ -195,17 +192,17 @@ private object DebugTextBuildingVisitor : KtVisitor() { override fun visitPropertyAccessor(accessor: KtPropertyAccessor, data: Unit?): String? { 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() ?: "...") } override fun visitClass(klass: KtClass, data: Unit?): String? { return buildText { append("STUB: ") - appendInn(klass.getModifierList(), suffix = " ") + appendInn(klass.modifierList, suffix = " ") append("class ") - appendInn(klass.getNameAsName()) - appendInn(klass.getTypeParameterList()) + appendInn(klass.nameAsName) + appendInn(klass.typeParameterList) appendInn(klass.getPrimaryConstructorModifierList(), prefix = " ", suffix = " ") appendInn(klass.getPrimaryConstructorParameterList()) appendInn(klass.getSuperTypeList(), prefix = " : ") @@ -215,30 +212,30 @@ private object DebugTextBuildingVisitor : KtVisitor() { override fun visitNamedFunction(function: KtNamedFunction, data: Unit?): String? { return buildText { append("STUB: ") - appendInn(function.getModifierList(), suffix = " ") + appendInn(function.modifierList, suffix = " ") append("fun ") - val typeParameterList = function.getTypeParameterList() + val typeParameterList = function.typeParameterList if (function.hasTypeParameterListBeforeFunctionName()) { appendInn(typeParameterList, suffix = " ") } - appendInn(function.getReceiverTypeReference(), suffix = ".") - appendInn(function.getNameAsName()) + appendInn(function.receiverTypeReference, suffix = ".") + appendInn(function.nameAsName) if (!function.hasTypeParameterListBeforeFunctionName()) { appendInn(typeParameterList) } - appendInn(function.getValueParameterList()) - appendInn(function.getTypeReference(), prefix = ": ") - appendInn(function.getTypeConstraintList(), prefix = " ") + appendInn(function.valueParameterList) + appendInn(function.typeReference, prefix = ": ") + appendInn(function.typeConstraintList, prefix = " ") } } override fun visitObjectDeclaration(declaration: KtObjectDeclaration, data: Unit?): String? { return buildText { append("STUB: ") - appendInn(declaration.getModifierList(), suffix = " ") + appendInn(declaration.modifierList, suffix = " ") append("object ") - appendInn(declaration.getNameAsName()) + appendInn(declaration.nameAsName) appendInn(declaration.getSuperTypeList(), prefix = " : ") } } @@ -246,11 +243,11 @@ private object DebugTextBuildingVisitor : KtVisitor() { override fun visitParameter(parameter: KtParameter, data: Unit?): String? { return buildText { 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) - val typeReference = parameter.getTypeReference() + val typeReference = parameter.typeReference if (typeReference != null && name != null) { append(": ") } @@ -261,17 +258,17 @@ private object DebugTextBuildingVisitor : KtVisitor() { override fun visitProperty(property: KtProperty, data: Unit?): String? { return buildText { append("STUB: ") - appendInn(property.getModifierList(), suffix = " ") - append(if (property.isVar()) "var " else "val ") - appendInn(property.getNameAsName()) - appendInn(property.getTypeReference(), prefix = ": ") + appendInn(property.modifierList, suffix = " ") + append(if (property.isVar) "var " else "val ") + appendInn(property.nameAsName) + appendInn(property.typeReference, prefix = ": ") } } override fun visitTypeConstraint(constraint: KtTypeConstraint, data: Unit?): String? { return buildText { - appendInn(constraint.getSubjectTypeParameterName()) - appendInn(constraint.getBoundTypeReference(), prefix = " : ") + appendInn(constraint.subjectTypeParameterName) + appendInn(constraint.boundTypeReference, prefix = " : ") } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt index ffedf6e3813..bd30fa92f11 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -63,10 +63,10 @@ object EditCommaSeparatedListHelper { if (anchor != null) { val index = allItems.indexOf(anchor) assert(index >= 0) - anchorAfter = if (index > 0) allItems.get(index - 1) else null + anchorAfter = if (index > 0) allItems[index - 1] else null } else { - anchorAfter = allItems.get(allItems.size - 1) + anchorAfter = allItems[allItems.size - 1] } } return addItemAfter(list, allItems, item, anchorAfter, prefix) @@ -74,9 +74,9 @@ object EditCommaSeparatedListHelper { fun removeItem(item: TItem) { 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 } - if (comma?.getNode()?.getElementType() != KtTokens.COMMA) { + if (comma?.node?.elementType != KtTokens.COMMA) { comma = null } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/FindDocComment.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/FindDocComment.kt index 0da644e47fc..a67a874c860 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/FindDocComment.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/FindDocComment.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -16,11 +16,10 @@ 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.PsiWhiteSpace +import org.jetbrains.kotlin.kdoc.psi.api.KDoc +import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.psiUtil.allChildren fun findDocComment(declaration: KtDeclaration): KDoc? { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtAnnotationUseSiteTarget.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtAnnotationUseSiteTarget.kt index 454d3019642..6281777beb5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtAnnotationUseSiteTarget.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtAnnotationUseSiteTarget.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -17,13 +17,9 @@ package org.jetbrains.kotlin.psi import com.intellij.lang.ASTNode -import com.intellij.psi.impl.source.tree.TreeElement import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget -import org.jetbrains.kotlin.lexer.KtKeywordToken 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.KotlinPlaceHolderStub import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes class KtAnnotationUseSiteTarget : KtElementImplStub { @@ -44,8 +40,8 @@ class KtAnnotationUseSiteTarget : KtElementImplStub AnnotationUseSiteTarget.FIELD KtTokens.FILE_KEYWORD -> AnnotationUseSiteTarget.FILE KtTokens.PROPERTY_KEYWORD -> AnnotationUseSiteTarget.PROPERTY @@ -55,7 +51,7 @@ class KtAnnotationUseSiteTarget : KtElementImplStub AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER KtTokens.SETPARAM_KEYWORD -> AnnotationUseSiteTarget.SETTER_PARAMETER KtTokens.DELEGATE_KEYWORD -> AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD - else -> throw IllegalStateException("Unknown annotation target " + node.getText()) + else -> throw IllegalStateException("Unknown annotation target " + node.text) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClass.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClass.kt index c2efe714948..acba723b2ab 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClass.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClass.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -74,8 +74,7 @@ open class KtClass : KtClassOrObject { parts.add(current.name!!) current = PsiTreeUtil.getParentOfType(current, KtClassOrObject::class.java) } - val file = containingFile - if (file !is KtFile) return null + val file = containingFile as? KtFile ?: return null val fileQualifiedName = file.packageFqName.asString() if (!fileQualifiedName.isEmpty()) { parts.add(fileQualifiedName) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtConstructor.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtConstructor.kt index 7238b5dc0d0..9e5a310bd50 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtConstructor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtConstructor.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ abstract class KtConstructor> : KtDeclarationStub> : KtDeclarationStub> : KtDeclarationStub() - 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 getNameAsName() = getNameAsSafeName() + override fun getNameAsName() = nameAsSafeName override fun getNameIdentifier() = null @@ -82,15 +82,15 @@ abstract class KtConstructor> : KtDeclarationStub 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" + "File text:\n${containingFile.text}") return null diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtDoubleColonExpression.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtDoubleColonExpression.kt index 5842b9657bc..a3a4eede6a2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtDoubleColonExpression.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtDoubleColonExpression.kt @@ -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"); * 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) { val oldReceiverExpression = this.receiverExpression - if (oldReceiverExpression != null) { - oldReceiverExpression.replace(newReceiverExpression) - } - else { - addBefore(newReceiverExpression, doubleColonTokenReference) - } + oldReceiverExpression?.replace(newReceiverExpression) ?: addBefore(newReceiverExpression, doubleColonTokenReference) } val isEmptyLHS: Boolean diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtEnumEntrySuperclassReferenceExpression.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtEnumEntrySuperclassReferenceExpression.kt index b2407084281..f8ddd2a4ebc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtEnumEntrySuperclassReferenceExpression.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtEnumEntrySuperclassReferenceExpression.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -41,11 +41,11 @@ class KtEnumEntrySuperclassReferenceExpression : private fun calcReferencedElement(): KtClass? { val owner = this.getStrictParentOfType() as? KtEnumEntry - return owner?.getParent()?.getParent() as? KtClass + return owner?.parent?.parent as? KtClass } override fun getReferencedName(): String { - val stub = getStub() + val stub = stub if (stub != null) { return stub.getReferencedName() } @@ -54,7 +54,7 @@ class KtEnumEntrySuperclassReferenceExpression : } 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 { @@ -62,11 +62,11 @@ class KtEnumEntrySuperclassReferenceExpression : } override fun getIdentifier(): PsiElement? { - return referencedElement.getNameIdentifier() + return referencedElement.nameIdentifier } override fun getReferencedNameElementType(): IElementType { - return getReferencedNameElement().getNode()!!.getElementType() + return getReferencedNameElement().node!!.elementType } override fun accept(visitor: KtVisitor, data: D): R { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtLabelReferenceExpression.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtLabelReferenceExpression.kt index 7b59d38c477..60e09f4dc5a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtLabelReferenceExpression.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtLabelReferenceExpression.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -17,8 +17,6 @@ package org.jetbrains.kotlin.psi import com.intellij.lang.ASTNode -import org.jetbrains.kotlin.lexer.KtTokens -import com.intellij.psi.PsiElement class KtLabelReferenceExpression(node: ASTNode) : KtSimpleNameExpressionImpl(node) { override fun getReferencedNameElement() = getIdentifier() ?: this diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtNameReferenceExpression.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtNameReferenceExpression.kt index a5b9e9df994..e9bdd1a37e3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtNameReferenceExpression.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtNameReferenceExpression.kt @@ -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"); * 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.tree.IElementType 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.elements.KtStubElementTypes -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.lexer.KtTokens - -import org.jetbrains.kotlin.lexer.KtTokens.* class KtNameReferenceExpression : KtExpressionImplStub, KtSimpleNameExpression { constructor(node: ASTNode) : super(node) { @@ -35,7 +34,7 @@ class KtNameReferenceExpression : KtExpressionImplStub { override fun accept(visitor: KtVisitor, data: D) = visitor.visitPrimaryConstructor(this, data) - override fun getContainingClassOrObject() = getParent() as KtClassOrObject + override fun getContainingClassOrObject() = parent as KtClassOrObject private fun getOrCreateConstructorKeyword(): PsiElement { return getConstructorKeyword() ?: addBefore(KtPsiFactory(this).createConstructorKeyword(), valueParameterList!!) @@ -59,13 +59,13 @@ class KtPrimaryConstructor : KtConstructor { } override fun addAnnotationEntry(annotationEntry: KtAnnotationEntry): KtAnnotationEntry { - val modifierList = getModifierList() + val modifierList = modifierList return if (modifierList != null) { modifierList.addBefore(annotationEntry, modifierList.firstChild) as KtAnnotationEntry } else { - val parameterList = getValueParameterList()!! - val newModifierList = KtPsiFactory(getProject()).createModifierList(annotationEntry.text) + val parameterList = valueParameterList!! + val newModifierList = KtPsiFactory(project).createModifierList(annotationEntry.text) (addBefore(newModifierList, parameterList) as KtModifierList).annotationEntries.first() } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt index bdcdae2fc70..f126a222be5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt @@ -47,12 +47,12 @@ class KtPsiFactory(private val project: Project) { fun createValKeyword(): PsiElement { val property = createProperty("val x = 1") - return property.getValOrVarKeyword() + return property.valOrVarKeyword } fun createVarKeyword(): PsiElement { val property = createProperty("var x = 1") - return property.getValOrVarKeyword() + return property.valOrVarKeyword } fun createSafeCallNode(): ASTNode { @@ -61,7 +61,7 @@ class KtPsiFactory(private val project: Project) { private fun doCreateExpression(text: String): KtExpression { //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 } @@ -83,12 +83,12 @@ class KtPsiFactory(private val project: Project) { fun createCallArguments(text: String): KtValueArgumentList { val property = createProperty("val x = foo $text") - return (property.getInitializer() as KtCallExpression).valueArgumentList!! + return (property.initializer as KtCallExpression).valueArgumentList!! } fun createTypeArguments(text: String): KtTypeArgumentList { 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() @@ -114,7 +114,7 @@ class KtPsiFactory(private val project: Project) { fun createTypeAlias(name: String, typeParameters: List, body: String): KtTypeAlias { val typeParametersText = if (typeParameters.isNotEmpty()) typeParameters.joinToString(prefix = "<", postfix = ">") else "" - return createDeclaration("typealias $name$typeParametersText = $body") + return createDeclaration("typealias $name$typeParametersText = $body") } fun createStar(): PsiElement { @@ -134,7 +134,7 @@ class KtPsiFactory(private val project: Project) { } fun createEQ(): PsiElement { - return createFunction("fun foo() = foo").getEqualsToken()!! + return createFunction("fun foo() = foo").equalsToken!! } fun createSemicolon(): PsiElement { @@ -177,7 +177,7 @@ class KtPsiFactory(private val project: Project) { } fun createFileAnnotationListWithAnnotation(annotationText: String) : KtFileAnnotationList { - return createFile("@file:${annotationText}").fileAnnotationList!! + return createFile("@file:$annotationText").fileAnnotationList!! } 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 { - val text = (modifiers.let { "$it "} ?: "") + + val text = modifiers.let { "$it "} + (if (isVar) " var " else " val ") + name + (if (type != null) ":" + type else "") + (if (initializer == null) "" else " = " + initializer) return createProperty(text) @@ -259,11 +259,11 @@ class KtPsiFactory(private val project: Project) { } fun createNameIdentifier(name: String): PsiElement { - return createProperty(name, null, false).getNameIdentifier()!! + return createProperty(name, null, false).nameIdentifier!! } 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 { @@ -289,7 +289,7 @@ class KtPsiFactory(private val project: Project) { } fun createModifierList(text: String): KtModifierList { - return createProperty(text + " val x").getModifierList()!! + return createProperty(text + " val x").modifierList!! } fun createModifier(modifier: KtModifierKeywordToken): PsiElement { @@ -297,12 +297,12 @@ class KtPsiFactory(private val project: Project) { } fun createAnnotationEntry(text: String): KtAnnotationEntry { - val modifierList = createProperty(text + " val x").getModifierList() - return modifierList!!.getAnnotationEntries().first() + val modifierList = createProperty(text + " val x").modifierList + return modifierList!!.annotationEntries.first() } fun createEmptyBody(): KtBlockExpression { - return createFunction("fun foo() {}").getBodyExpression() as KtBlockExpression + return createFunction("fun foo() {}").bodyExpression as KtBlockExpression } fun createAnonymousInitializer(): KtAnonymousInitializer { @@ -318,7 +318,7 @@ class KtPsiFactory(private val project: Project) { } 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!! @@ -330,7 +330,7 @@ class KtPsiFactory(private val project: Project) { } fun createEnumEntry(text: String): KtEnumEntry { - return createDeclaration("enum class E {$text}").getDeclarations()[0] as KtEnumEntry + return createDeclaration("enum class E {$text}").declarations[0] as KtEnumEntry } fun createEnumEntryInitializerList(): KtInitializerList { @@ -338,7 +338,7 @@ class KtPsiFactory(private val project: Project) { } 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) assert(whenEntry != null) { "Couldn't generate when entry" } @@ -386,7 +386,7 @@ class KtPsiFactory(private val project: Project) { fun createImportDirectiveWithImportList(importPath: ImportPath): KtImportList { val importDirective = createImportDirective(importPath) - return importDirective.getParent() as KtImportList + return importDirective.parent as KtImportList } fun createPrimaryConstructor(): KtPrimaryConstructor { @@ -485,7 +485,7 @@ class KtPsiFactory(private val project: Project) { private fun placeKeyword() { assert(state == State.MODIFIERS) - if (sb.length != 0) { + if (sb.isNotEmpty()) { sb.append(" ") } sb.append("class ") @@ -592,7 +592,7 @@ class KtPsiFactory(private val project: Project) { private fun placeKeyword() { assert(state == State.MODIFIERS) - if (sb.length != 0) { + if (sb.isNotEmpty()) { sb.append(" ") } val keyword = when (target) { @@ -743,11 +743,11 @@ class KtPsiFactory(private val project: Project) { } 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 { - return createDeclarationByPattern("fun foo() {\n$0\n}", statement).getBodyExpression() as KtBlockExpression + return createDeclarationByPattern("fun foo() {\n$0\n}", statement).bodyExpression as KtBlockExpression } fun createComment(text: String): PsiComment { @@ -765,7 +765,7 @@ class KtPsiFactory(private val project: Project) { return expression } val function = createFunction("fun f() { ${expression.text} }") - val block = function.getBodyExpression() as KtBlockExpression + val block = function.bodyExpression as KtBlockExpression return BlockWrapper(block, expression) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtSecondaryConstructor.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtSecondaryConstructor.kt index 700705ea058..10104004521 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtSecondaryConstructor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtSecondaryConstructor.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ class KtSecondaryConstructor : KtConstructor { override fun accept(visitor: KtVisitor, 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) @@ -35,16 +35,16 @@ class KtSecondaryConstructor : KtConstructor { fun getDelegationCall(): KtConstructorDelegationCall = findNotNullChildByClass(KtConstructorDelegationCall::class.java) - fun hasImplicitDelegationCall(): Boolean = getDelegationCall().isImplicit() + fun hasImplicitDelegationCall(): Boolean = getDelegationCall().isImplicit fun replaceImplicitDelegationCallWithExplicit(isThis: Boolean): KtConstructorDelegationCall { - val psiFactory = KtPsiFactory(getProject()) + val psiFactory = KtPsiFactory(project) 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() - val colon = addAfter(psiFactory.createColon(), getValueParameterList()) + val colon = addAfter(psiFactory.createColon(), valueParameterList) val delegationName = if (isThis) "this" else "super" diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtSimpleNameExpression.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtSimpleNameExpression.kt index 58dd82b5147..21caac0a93a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtSimpleNameExpression.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtSimpleNameExpression.kt @@ -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"); * 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.psi.PsiElement -import com.intellij.psi.PsiReference import com.intellij.psi.tree.IElementType import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.name.Name diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtTypeAlias.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtTypeAlias.kt index 438697de8d5..f99c5dfffe6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtTypeAlias.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtTypeAlias.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.psi import com.intellij.lang.ASTNode -import com.intellij.navigation.ItemPresentation import com.intellij.navigation.ItemPresentationProviders import com.intellij.psi.PsiElement import org.jetbrains.kotlin.KtNodeTypes diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt index b4673563d37..9fffaad4907 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -16,20 +16,20 @@ 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 org.jetbrains.kotlin.psi.KtPsiFactory -import com.intellij.psi.PsiWhiteSpace 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.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 fun getTypeReference(declaration: KtCallableDeclaration): KtTypeReference? { - return declaration.getFirstChild()!!.siblings(forward = true) - .dropWhile { it.getNode()!!.getElementType() != KtTokens.COLON } + return declaration.firstChild!!.siblings(forward = true) + .dropWhile { it.node!!.elementType != KtTokens.COLON } .firstIsInstanceOrNull() } @@ -40,16 +40,16 @@ fun setTypeReference(declaration: KtCallableDeclaration, addAfter: PsiElement?, return oldTypeRef.replace(typeRef) as KtTypeReference } 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 - declaration.addAfter(KtPsiFactory(declaration.getProject()).createColon(), anchor) + declaration.addAfter(KtPsiFactory(declaration.project).createColon(), anchor) return newTypeRef } } else { if (oldTypeRef != null) { - val colon = declaration.getColon()!! - val removeFrom = colon.getPrevSibling() as? PsiWhiteSpace ?: colon + val colon = declaration.colon!! + val removeFrom = colon.prevSibling as? PsiWhiteSpace ?: colon declaration.deleteChildRange(removeFrom, oldTypeRef) } return null @@ -58,28 +58,28 @@ fun setTypeReference(declaration: KtCallableDeclaration, addAfter: PsiElement?, fun KtCallableDeclaration.setReceiverTypeReference(typeRef: KtTypeReference?): KtTypeReference? { val needParentheses = typeRef != null && typeRef.typeElement is KtFunctionType && !typeRef.hasParentheses() - val oldTypeRef = getReceiverTypeReference() + val oldTypeRef = receiverTypeReference if (typeRef != null) { val newTypeRef = if (oldTypeRef != null) { oldTypeRef.replace(typeRef) as KtTypeReference } else { - val anchor = getNameIdentifier() ?: valueParameterList + val anchor = nameIdentifier ?: valueParameterList val newTypeRef = addBefore(typeRef, anchor) as KtTypeReference - addAfter(KtPsiFactory(getProject()).createDot(), newTypeRef) + addAfter(KtPsiFactory(project).createDot(), newTypeRef) newTypeRef } if (needParentheses) { - val argList = KtPsiFactory(getProject()).createCallArguments("()") - newTypeRef.addBefore(argList.getLeftParenthesis()!!, newTypeRef.getFirstChild()) - newTypeRef.add(argList.getRightParenthesis()!!) + val argList = KtPsiFactory(project).createCallArguments("()") + newTypeRef.addBefore(argList.leftParenthesis!!, newTypeRef.firstChild) + newTypeRef.add(argList.rightParenthesis!!) } return newTypeRef } else { 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) } return null diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/addRemoveModifier.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/addRemoveModifier.kt index 78a87bf9f7c..3079c34b586 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/addRemoveModifier.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/addRemoveModifier.kt @@ -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"); * 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.PsiWhiteSpace import org.jetbrains.kotlin.lexer.KtModifierKeywordToken -import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.siblings @@ -85,12 +84,12 @@ internal fun addModifier(modifierList: KtModifierList, modifier: KtModifierKeywo return newModifierOrder > order } - val lastChild = modifierList.getLastChild() + val lastChild = modifierList.lastChild val anchor = lastChild?.siblings(forward = false)?.firstOrNull(::placeAfter) modifierList.addAfter(newModifier, anchor) 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')) { modifierList.addAfter(whiteSpace, anchor) whiteSpace.delete() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/codeFragmentUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/codeFragmentUtil.kt index 6580707818b..e4e95798d11 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/codeFragmentUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/codeFragmentUtil.kt @@ -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"); * 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 else -> false } - set(skip: Boolean) { + set(skip) { putUserData(SUPPRESS_DIAGNOSTICS_IN_DEBUG_MODE, skip) } @@ -50,8 +50,8 @@ val DEBUG_TYPE_REFERENCE_STRING: String = "DebugTypeKotlinRulezzzz" val DEBUG_TYPE_INFO: Key = Key.create("DEBUG_TYPE_INFO") var KtTypeReference.debugTypeInfo: KotlinType? get() = getUserData(DEBUG_TYPE_INFO) - set(type: KotlinType?) { - if (type != null && this.getText() == DEBUG_TYPE_REFERENCE_STRING) { + set(type) { + if (type != null && this.text == DEBUG_TYPE_REFERENCE_STRING) { putUserData(DEBUG_TYPE_INFO, type) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt index 9b1c95bbe59..aa947b35a2e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -87,10 +87,10 @@ private object PsiChildRangeArgumentType : PsiElementPlaceholderArgumentType(KtExpression::class.java), - PsiElementArgumentType(KtTypeReference::class.java), - PlainTextArgumentType(String::class.java, toPlainText = { it }), - PlainTextArgumentType(Name::class.java, toPlainText = { it.render() }), + PsiElementArgumentType(KtExpression::class.java), + PsiElementArgumentType(KtTypeReference::class.java), + PlainTextArgumentType(String::class.java, toPlainText = { it }), + PlainTextArgumentType(Name::class.java, toPlainText = Name::render), PsiChildRangeArgumentType ) @@ -130,7 +130,7 @@ fun createByPattern(pattern: String, vararg args: Any, fa for ((range, text) in placeholders) { val token = resultElement.findElementAt(range.startOffset)!! for (element in token.parentsWithSelf) { - val elementRange = element.getTextRange().shiftRight(-start) + val elementRange = element.textRange.shiftRight(-start) if (elementRange == range && expectedElementType.isInstance(element)) { val pointer = pointerManager.createSmartPsiElementPointer(element) pointers.put(pointer, n) @@ -208,7 +208,7 @@ private fun processPattern(pattern: String, args: List): PatternData { val text = buildString { var i = 0 while (i < pattern.length) { - var c = pattern[i] + val c = pattern[i] if (c == '$') { val nextChar = charOrNull(++i) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index 1db8639ce3f..7effa552691 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -47,7 +47,7 @@ fun KtCallElement.getCallNameExpression(): KtSimpleNameExpression? { return when (calleeExpression) { is KtSimpleNameExpression -> calleeExpression - is KtConstructorCalleeExpression -> calleeExpression.getConstructorReferenceExpression() + is KtConstructorCalleeExpression -> calleeExpression.constructorReferenceExpression else -> null } } @@ -82,9 +82,9 @@ fun KtElement.getQualifiedElementSelector(): KtElement? { is KtCallExpression -> calleeExpression is KtQualifiedExpression -> { val selector = selectorExpression - if (selector is KtCallExpression) selector.calleeExpression else selector + (selector as? KtCallExpression)?.calleeExpression ?: selector } - is KtUserType -> getReferenceExpression() + is KtUserType -> referenceExpression else -> null } } @@ -111,15 +111,15 @@ fun KtSimpleNameExpression.getReceiverExpression(): KtExpression? { } } 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 -> { return parent.baseExpression } parent is KtUserType -> { - val qualifier = parent.getQualifier() + val qualifier = parent.qualifier if (qualifier != null) { - return qualifier.getReferenceExpression()!! + return qualifier.referenceExpression!! } } } @@ -204,11 +204,11 @@ fun StubBasedPsiElementBase>.ge fun addSuperName(result: MutableList, referencedName: String): Unit { result.add(referencedName) - val file = getContainingFile() + val file = containingFile if (file is KtFile) { val directive = file.findImportByAlias(referencedName) if (directive != null) { - var reference = directive.getImportedReference() + var reference = directive.importedReference while (reference is KtDotQualifiedExpression) { reference = reference.selectorExpression } @@ -221,7 +221,7 @@ fun StubBasedPsiElementBase>.ge 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) { return stub.getSuperNames() } @@ -231,9 +231,9 @@ fun StubBasedPsiElementBase>.ge val result = ArrayList() for (specifier in specifiers) { - val superType = specifier.getTypeAsUserType() + val superType = specifier.typeAsUserType if (superType != null) { - val referencedName = superType.getReferencedName() + val referencedName = superType.referencedName if (referencedName != null) { addSuperName(result, referencedName) } @@ -267,7 +267,7 @@ private fun StubElement<*>.collectAnnotationEntriesFromStubElement(): List when (child.stubType) { KtNodeTypes.ANNOTATION_ENTRY -> listOf(child.psi as KtAnnotationEntry) - KtNodeTypes.ANNOTATION -> (child.psi as KtAnnotation).getEntries() + KtNodeTypes.ANNOTATION -> (child.psi as KtAnnotation).entries else -> emptyList() } } @@ -277,7 +277,7 @@ private fun KtAnnotationsContainer.collectAnnotationEntriesFromPsi(): List when (child) { is KtAnnotationEntry -> listOf(child) - is KtAnnotation -> child.getEntries() + is KtAnnotation -> child.entries else -> emptyList() } } @@ -307,7 +307,7 @@ inline fun flatMapDescendantsOfTypeVisitor(accumulato fun KtClassOrObject.effectiveDeclarations(): List { return when(this) { 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 { val parent = parent 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) else -> -1 } @@ -375,7 +375,7 @@ fun KtStringTemplateExpression.isSingleQuoted(): Boolean = node.firstChildNode.textLength == 1 fun KtNamedDeclaration.getValueParameters(): List { - return getValueParameterList()?.getParameters() ?: Collections.emptyList() + return getValueParameterList()?.parameters ?: Collections.emptyList() } fun KtNamedDeclaration.getValueParameterList(): KtParameterList? { @@ -461,7 +461,7 @@ fun KtElement.nonStaticOuterClasses(): Sequence { return generateSequence(containingClass()) { if (it.isInner()) it.containingClass() else null } } -fun KtElement.containingClass(): KtClass? = getStrictParentOfType() +fun KtElement.containingClass(): KtClass? = getStrictParentOfType() fun KtClassOrObject.findPropertyByName(name: String): KtNamedDeclaration? { return declarations.firstOrNull { it is KtProperty && it.name == name } as KtNamedDeclaration? diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt index dab06e24bde..d9121a098c6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -183,7 +183,7 @@ fun PsiChildRange.trimWhiteSpaces(): PsiChildRange { // -------------------- Recursive tree visiting -------------------------------------------------------------------------------------------- inline fun PsiElement.forEachDescendantOfType(noinline action: (T) -> Unit) { - forEachDescendantOfType({ true }, action) + forEachDescendantOfType({ true }, action) } inline fun PsiElement.forEachDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline action: (T) -> Unit) { @@ -201,15 +201,15 @@ inline fun PsiElement.forEachDescendantOfType(crossinli } inline fun PsiElement.anyDescendantOfType(noinline predicate: (T) -> Boolean = { true }): Boolean { - return findDescendantOfType(predicate) != null + return findDescendantOfType(predicate) != null } inline fun PsiElement.anyDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): Boolean { - return findDescendantOfType(canGoInside, predicate) != null + return findDescendantOfType(canGoInside, predicate) != null } inline fun PsiElement.findDescendantOfType(noinline predicate: (T) -> Boolean = { true }): T? { - return findDescendantOfType({ true }, predicate) + return findDescendantOfType({ true }, predicate) } inline fun PsiElement.findDescendantOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): T? { @@ -231,7 +231,7 @@ inline fun PsiElement.findDescendantOfType(crossinline } inline fun PsiElement.collectDescendantsOfType(noinline predicate: (T) -> Boolean = { true }): List { - return collectDescendantsOfType({ true }, predicate) + return collectDescendantsOfType({ true }, predicate) } inline fun PsiElement.collectDescendantsOfType(crossinline canGoInside: (PsiElement) -> Boolean, noinline predicate: (T) -> Boolean = { true }): List { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtTypeAliasElementType.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtTypeAliasElementType.kt index 97ec9823739..ede75ae37bd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtTypeAliasElementType.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtTypeAliasElementType.kt @@ -37,7 +37,7 @@ class KtTypeAliasElementType(debugName: String) : } override fun serialize(stub: KotlinTypeAliasStub, dataStream: StubOutputStream) { - dataStream.writeName(stub.getName()) + dataStream.writeName(stub.name) dataStream.writeName(stub.getFqName()?.asString()) dataStream.writeBoolean(stub.isTopLevel()) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinClassStubImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinClassStubImpl.kt index 0d1d46ed631..5cd6f04d4fd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinClassStubImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinClassStubImpl.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -16,15 +16,14 @@ package org.jetbrains.kotlin.psi.stubs.impl +import com.intellij.psi.PsiElement import com.intellij.psi.stubs.StubElement import com.intellij.util.io.StringRef +import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.stubs.KotlinClassStub import org.jetbrains.kotlin.psi.stubs.elements.KtClassElementType -import org.jetbrains.kotlin.name.FqName - -import java.util.ArrayList -import com.intellij.psi.PsiElement +import java.util.* class KotlinClassStubImpl( type: KtClassElementType, @@ -39,10 +38,7 @@ class KotlinClassStubImpl( ) : KotlinStubBaseImpl(parent, type), KotlinClassStub { override fun getFqName(): FqName? { - val stringRef = StringRef.toString(qualifiedName) - if (stringRef == null) { - return null - } + val stringRef = StringRef.toString(qualifiedName) ?: return null return FqName(stringRef) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinEnumEntrySuperclassReferenceExpressionStubImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinEnumEntrySuperclassReferenceExpressionStubImpl.kt index d6b04de45ce..20e66edc945 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinEnumEntrySuperclassReferenceExpressionStubImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinEnumEntrySuperclassReferenceExpressionStubImpl.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.psi.stubs.impl -import com.intellij.psi.PsiElement import com.intellij.psi.stubs.StubElement import com.intellij.util.io.StringRef import org.jetbrains.kotlin.psi.KtEnumEntrySuperclassReferenceExpression diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinTypeAliasStubImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinTypeAliasStubImpl.kt index fb133f3e952..93ec9779696 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinTypeAliasStubImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinTypeAliasStubImpl.kt @@ -35,7 +35,7 @@ class KotlinTypeAliasStubImpl( StringRef.toString(name) override fun getFqName(): FqName? = - StringRef.toString(qualifiedName)?.let { FqName(it) } + StringRef.toString(qualifiedName)?.let(::FqName) override fun isTopLevel(): Boolean = isTopLevel } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/Utils.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/Utils.kt index b303698b87f..59615c1b7f7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/Utils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/Utils.kt @@ -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"); * you may not use this file except in compliance with the License. @@ -20,6 +20,6 @@ import com.intellij.util.io.StringRef object Utils { fun wrapStrings(names : List) : Array { - return Array(names.size) { i -> StringRef.fromString(names.get(i))!! } + return Array(names.size) { i -> StringRef.fromString(names[i])!! } } }