From a3bd6ca017c8aa0c835b726e5865ec039f01afe3 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 11 May 2015 19:48:01 +0300 Subject: [PATCH] Introduced shortcut properties + getArrowNode -> getArrow --- .../diagnostics/PositioningStrategies.kt | 3 ++- .../kotlin/diagnostics/PositioningStrategy.kt | 14 ++++++++------ .../kotlin/psi/JetFunctionLiteral.java | 4 ++-- .../jetbrains/kotlin/psi/createByPattern.kt | 6 ++++-- .../jetbrains/kotlin/psi/psiUtil/jetPsiUtil.kt | 14 ++++++++++---- .../SoftKeywordsHighlightingVisitor.java | 7 +++---- .../idea/references/JetSimpleNameReference.kt | 2 +- .../completion/KotlinCompletionContributor.kt | 13 +++++-------- .../completion/ToFromOriginalFileMapper.kt | 5 +++-- .../handlers/KotlinCallableInsertHandler.kt | 3 ++- .../kotlin/idea/KotlinFoldingBuilder.kt | 8 +++++--- .../upDownMover/JetExpressionMover.java | 9 ++++----- .../kotlin/idea/editor/KotlinEnterHandler.kt | 8 +++----- .../KotlinDeclarationSelectioner.kt | 6 ++++-- .../KotlinStringLiteralSelectioner.kt | 6 ++++-- .../idea/intentions/AddBracesIntention.kt | 3 ++- .../ConvertToExpressionBodyIntention.kt | 4 +++- .../ConvertToForEachFunctionCallIntention.kt | 3 ++- .../idea/intentions/IfNullToElvisIntention.kt | 4 +++- .../MoveLambdaOutsideParenthesesIntention.kt | 3 ++- ...oveExplicitLambdaParameterTypesIntention.kt | 5 +++-- ...licitFunctionLiteralParamWithItIntention.kt | 7 ++++--- ...ithExplicitFunctionLiteralParamIntention.kt | 2 +- .../SpecifyExplicitLambdaSignatureIntention.kt | 5 +++-- .../EliminateWhenSubjectIntention.kt | 3 ++- .../intentions/FlattenWhenIntention.kt | 4 +++- .../intentions/IfThenToDoubleBangIntention.kt | 4 +++- .../UnfoldAssignmentToIfIntention.kt | 4 +++- .../UnfoldAssignmentToWhenIntention.kt | 4 +++- .../intentions/UnfoldPropertyToIfIntention.kt | 4 +++- .../UnfoldPropertyToWhenIntention.kt | 4 +++- .../intentions/UnfoldReturnToIfIntention.kt | 4 +++- .../intentions/UnfoldReturnToWhenIntention.kt | 4 +++- .../SplitPropertyDeclarationIntention.kt | 3 ++- .../idea/quickfix/DeprecatedLambdaSyntaxFix.kt | 2 +- .../idea/quickfix/SuperClassNotInitialized.kt | 3 ++- .../callableBuilder/CallableBuilder.kt | 18 +++++++++--------- .../usages/JetFunctionDefinitionUsage.java | 8 ++++---- .../extractionEngine/extractorUtil.kt | 4 ++-- 39 files changed, 129 insertions(+), 88 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index c4e1b27c805..fed359d7d4c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.JetNodeTypes import org.jetbrains.kotlin.lexer.JetKeywordToken import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.getCalleeHighlightingRange import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.utils.sure @@ -387,7 +388,7 @@ public object PositioningStrategies { override fun mark(element: JetElement): List { if (element is JetConstantExpression) { if (element.getNode().getElementType() == JetNodeTypes.INTEGER_CONSTANT) { - val endOffset = element.getTextRange().getEndOffset() + val endOffset = element.endOffset return listOf(TextRange.create(endOffset - 1, endOffset)) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategy.kt index ff31bbf571f..2b2156b63ea 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategy.kt @@ -22,6 +22,8 @@ import com.intellij.psi.PsiComment import com.intellij.psi.PsiElement import com.intellij.psi.PsiErrorElement import com.intellij.psi.PsiWhiteSpace +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset public open class PositioningStrategy { public open fun markDiagnostic(diagnostic: ParametrizedDiagnostic): List { @@ -57,26 +59,26 @@ private fun getStartOffset(element: PsiElement): Int { var child = element.getFirstChild() if (child != null) { while (child is PsiComment || child is PsiWhiteSpace) { - child = child!!.getNextSibling() + child = child.getNextSibling() } if (child != null) { - return getStartOffset(child!!) + return getStartOffset(child) } } - return element.getTextRange().getStartOffset() + return element.startOffset } private fun getEndOffset(element: PsiElement): Int { var child = element.getLastChild() if (child != null) { while (child is PsiComment || child is PsiWhiteSpace) { - child = child!!.getPrevSibling() + child = child.getPrevSibling() } if (child != null) { - return getEndOffset(child!!) + return getEndOffset(child) } } - return element.getTextRange().getEndOffset() + return element.endOffset } fun hasSyntaxErrors(psiElement: PsiElement): Boolean { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetFunctionLiteral.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetFunctionLiteral.java index 5c0feb032d7..0bef29ddb52 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetFunctionLiteral.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetFunctionLiteral.java @@ -70,8 +70,8 @@ public class JetFunctionLiteral extends JetFunctionNotStubbed { } @Nullable - public ASTNode getArrowNode() { - return getNode().findChildByType(JetTokens.ARROW); + public PsiElement getArrow() { + return findChildByType(JetTokens.ARROW); } @Nullable diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt index 59205673ba9..482c0d6b6e8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt @@ -22,7 +22,9 @@ import com.intellij.psi.SmartPointerManager import com.intellij.psi.SmartPsiElementPointer import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.impl.source.codeStyle.CodeEditUtil +import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import java.util.ArrayList import java.util.HashMap @@ -34,7 +36,7 @@ public fun JetPsiFactory.createExpressionByPattern(pattern: String, vararg args: var expression = createExpression(processedText) val project = expression.getProject() - val start = expression.getTextRange().getStartOffset() + val start = expression.startOffset val pointerManager = SmartPointerManager.getInstance(project) @@ -80,7 +82,7 @@ public fun JetPsiFactory.createExpressionByPattern(pattern: String, vararg args: expression = codeStyleManager.reformat(expression, true) as JetExpression } else { - var bound = expression.getTextRange().getEndOffset() - 1 + var bound = expression.endOffset - 1 for (range in stringPlaceholderRanges) { // we extend reformatting range by 1 to the right because otherwise some of spaces are not reformatted expression = codeStyleManager.reformatRange(expression, range.getEndOffset() + start, bound + 1, true) as JetExpression diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/jetPsiUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/jetPsiUtil.kt index 61dfde993ba..58d4ab3bd23 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/jetPsiUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/jetPsiUtil.kt @@ -473,7 +473,7 @@ public fun PsiFile.elementsInRange(range: TextRange): List { } result.add(element) - offset = element.getTextRange().getEndOffset() + offset = element.endOffset } return result } @@ -510,7 +510,7 @@ public fun PsiElement.getElementTextWithContext(): String { val topLevelElement = PsiTreeUtil.findFirstParent(this, { it.getParent() is PsiFile }) ?: throw AssertionError("For non-file element we should always be able to find parent in file children") - val startContextOffset = topLevelElement.getTextRange().getStartOffset() + val startContextOffset = topLevelElement.startOffset val elementContextOffset = getTextRange().getStartOffset() val inFileParentOffset = elementContextOffset - startContextOffset @@ -583,7 +583,13 @@ public fun JetElement.getCalleeHighlightingRange(): TextRange { ) ?: return getTextRange() val startOffset = annotationEntry.getAtSymbol()?.getTextRange()?.getStartOffset() - ?: annotationEntry.getCalleeExpression().getTextRange().getStartOffset() + ?: annotationEntry.getCalleeExpression().startOffset - return TextRange(startOffset, annotationEntry.getCalleeExpression().getTextRange().getEndOffset()) + return TextRange(startOffset, annotationEntry.getCalleeExpression().endOffset) } + +public val PsiElement.startOffset: Int + get() = getTextRange().getStartOffset() + +public val PsiElement.endOffset: Int + get() = getTextRange().getEndOffset() diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/SoftKeywordsHighlightingVisitor.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/SoftKeywordsHighlightingVisitor.java index b7a89f7a0cf..f53eab183c6 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/SoftKeywordsHighlightingVisitor.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/SoftKeywordsHighlightingVisitor.java @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.idea.highlighter; -import com.intellij.lang.ASTNode; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.colors.TextAttributesKey; @@ -59,9 +58,9 @@ class SoftKeywordsHighlightingVisitor extends HighlightingVisitor { if (closingBrace != null) { holder.createInfoAnnotation(closingBrace, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW); } - ASTNode arrowNode = functionLiteral.getArrowNode(); - if (arrowNode != null) { - holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW); + PsiElement arrow = functionLiteral.getArrow(); + if (arrow != null) { + holder.createInfoAnnotation(arrow, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW); } } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt index e4893a9056b..171ede805e3 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/JetSimpleNameReference.kt @@ -63,7 +63,7 @@ public class JetSimpleNameReference( override fun getRangeInElement(): TextRange { val element = getElement().getReferencedNameElement() - val startOffset = getElement().getTextRange().getStartOffset() + val startOffset = getElement().startOffset return element.getTextRange().shiftRight(-startOffset) } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt index 635e99ddb9c..4f72868147e 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt @@ -37,10 +37,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.completion.smart.SmartCompletion import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType -import org.jetbrains.kotlin.psi.psiUtil.getParentOfType -import org.jetbrains.kotlin.psi.psiUtil.parents -import org.jetbrains.kotlin.psi.psiUtil.prevLeaf +import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull @@ -108,12 +105,12 @@ public class KotlinCompletionContributor : CompletionContributor() { context.setReplacementOffset(suggestedReplacementOffset) } - context.getOffsetMap().addOffset(SmartCompletion.OLD_ARGUMENTS_REPLACEMENT_OFFSET, expression.getTextRange().getEndOffset()) + context.getOffsetMap().addOffset(SmartCompletion.OLD_ARGUMENTS_REPLACEMENT_OFFSET, expression.endOffset) val argumentList = (expression.getParent() as? JetValueArgument)?.getParent() as? JetValueArgumentList if (argumentList != null) { context.getOffsetMap().addOffset(SmartCompletion.MULTIPLE_ARGUMENTS_REPLACEMENT_OFFSET, - argumentList.getRightParenthesis()?.getTextRange()?.getStartOffset() ?: argumentList.getTextRange().getEndOffset()) + argumentList.getRightParenthesis()?.getTextRange()?.getStartOffset() ?: argumentList.endOffset) } } } @@ -149,8 +146,8 @@ public class KotlinCompletionContributor : CompletionContributor() { val classOrObject = tokenBefore?.parents(false)?.firstIsInstanceOrNull() ?: return false val name = classOrObject.getNameIdentifier() ?: return false val body = classOrObject.getBody() ?: return false - val offset = tokenBefore!!.getTextRange().getStartOffset() - return name.getTextRange().getEndOffset() <= offset && offset <= body.getTextRange().getStartOffset() + val offset = tokenBefore!!.startOffset + return name.endOffset <= offset && offset <= body.startOffset } private val declarationKeywords = TokenSet.create(JetTokens.FUN_KEYWORD, JetTokens.VAL_KEYWORD, JetTokens.VAR_KEYWORD) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ToFromOriginalFileMapper.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ToFromOriginalFileMapper.kt index 131d5216640..eb387bd9353 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ToFromOriginalFileMapper.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ToFromOriginalFileMapper.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.completion import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.JetDeclaration import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.kotlin.psi.psiUtil.startOffset class ToFromOriginalFileMapper( val originalFile: JetFile, @@ -64,13 +65,13 @@ class ToFromOriginalFileMapper( public fun toOriginalFile(declaration: JetDeclaration): JetDeclaration? { if (declaration.getContainingFile() != syntheticFile) return declaration - val offset = toOriginalFile(declaration.getTextRange().getStartOffset()) ?: return null + val offset = toOriginalFile(declaration.startOffset) ?: return null return PsiTreeUtil.findElementOfClassAtOffset(originalFile, offset, javaClass(), true) } public fun toSyntheticFile(declaration: JetDeclaration): JetDeclaration? { if (declaration.getContainingFile() != originalFile) return declaration - val offset = toSyntheticFile(declaration.getTextRange().getStartOffset()) ?: return null + val offset = toSyntheticFile(declaration.startOffset) ?: return null return PsiTreeUtil.findElementOfClassAtOffset(syntheticFile, offset, javaClass(), true) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinCallableInsertHandler.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinCallableInsertHandler.kt index 89814f20418..fcb8721f67f 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinCallableInsertHandler.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinCallableInsertHandler.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.idea.util.ShortenReferences import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.types.JetType @@ -150,7 +151,7 @@ public class KotlinFunctionInsertHandler(val caretPosition : CaretPosition, val if (token.getNode().getElementType() == JetTokens.LT) { val parent = token.getParent() if (parent is JetTypeArgumentList && parent.getText().indexOf('\n') < 0/* if type argument list is on multiple lines this is more likely wrong parsing*/) { - offset = parent.getTextRange().getEndOffset() + offset = parent.endOffset } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/KotlinFoldingBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/KotlinFoldingBuilder.kt index c4a9e4edc92..fe1996cdaa3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/KotlinFoldingBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/KotlinFoldingBuilder.kt @@ -32,6 +32,8 @@ import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.JetFunctionLiteral import org.jetbrains.kotlin.psi.JetImportList +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class KotlinFoldingBuilder : CustomFoldingBuilder(), DumbAware { override fun buildLanguageFoldRegions(descriptors: MutableList, @@ -42,11 +44,11 @@ public class KotlinFoldingBuilder : CustomFoldingBuilder(), DumbAware { val imports = root.getImportDirectives() if (imports.size() > 1) { val importKeyword = imports.get(0).getFirstChild() - val startOffset = importKeyword.getTextRange().getEndOffset() + 1 + val startOffset = importKeyword.endOffset + 1 val importList = root.getImportList() if (importList != null) { - val endOffset = importList.getTextRange().getEndOffset() + val endOffset = importList.endOffset val range = TextRange(startOffset, endOffset) descriptors.add(FoldingDescriptor(importList, range)) @@ -85,7 +87,7 @@ public class KotlinFoldingBuilder : CustomFoldingBuilder(), DumbAware { val lbrace = psi?.getLBrace() val rbrace = psi?.getRBrace() if (lbrace != null && rbrace != null) { - return TextRange(lbrace.getTextRange().getStartOffset(), rbrace.getTextRange().getEndOffset()) + return TextRange(lbrace.startOffset, rbrace.endOffset) } } return node.getTextRange() diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/JetExpressionMover.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/JetExpressionMover.java index a6241462e6b..39104a235af 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/JetExpressionMover.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/JetExpressionMover.java @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.codeInsight.upDownMover; import com.google.common.base.Predicate; import com.intellij.codeInsight.editorActions.moveUpDown.LineRange; -import com.intellij.lang.ASTNode; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.Pair; @@ -259,9 +258,9 @@ public class JetExpressionMover extends AbstractJetUpDownMover { newBlock = findClosestBlock(((JetFunctionLiteral) parent).getBodyExpression(), down, false); if (!down) { - ASTNode arrow = ((JetFunctionLiteral) parent).getArrowNode(); + PsiElement arrow = ((JetFunctionLiteral) parent).getArrow(); if (arrow != null) { - end = arrow.getPsi(); + end = arrow; } } } else { @@ -306,9 +305,9 @@ public class JetExpressionMover extends AbstractJetUpDownMover { if (down) { end = JetPsiUtil.findChildByType(blockLikeElement, JetTokens.LBRACE); if (blockLikeElement instanceof JetFunctionLiteral) { - ASTNode arrow = ((JetFunctionLiteral) blockLikeElement).getArrowNode(); + PsiElement arrow = ((JetFunctionLiteral) blockLikeElement).getArrow(); if (arrow != null) { - end = arrow.getPsi(); + end = arrow; } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinEnterHandler.kt b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinEnterHandler.kt index 564bb991faa..8fd420a938c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinEnterHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinEnterHandler.kt @@ -33,9 +33,7 @@ import com.intellij.util.IncorrectOperationException import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType -import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType -import org.jetbrains.kotlin.psi.psiUtil.isSingleQuoted +import org.jetbrains.kotlin.psi.psiUtil.* public class KotlinEnterHandler: EnterHandlerDelegateAdapter() { companion object { @@ -110,8 +108,8 @@ public class KotlinEnterHandler: EnterHandlerDelegateAdapter() { val doc = editor.getDocument() var caretAdvance = 1 if (stringTemplate.getParent() is JetDotQualifiedExpression) { - doc.insertString(stringTemplate.getTextRange().getEndOffset(), ")") - doc.insertString(stringTemplate.getTextRange().getStartOffset(), "(") + doc.insertString(stringTemplate.endOffset, ")") + doc.insertString(stringTemplate.startOffset, "(") caretOffset++ caretAdvance++ } diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinDeclarationSelectioner.kt b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinDeclarationSelectioner.kt index f5218e8af9c..8f29e298216 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinDeclarationSelectioner.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinDeclarationSelectioner.kt @@ -25,6 +25,8 @@ import java.util.ArrayList import org.jetbrains.kotlin.psi.psiUtil.siblings import com.intellij.psi.PsiComment import com.intellij.psi.PsiWhiteSpace +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class KotlinDeclarationSelectioner : ExtendWordSelectionHandlerBase() { override fun canSelect(e: PsiElement) @@ -44,8 +46,8 @@ public class KotlinDeclarationSelectioner : ExtendWordSelectionHandlerBase() { .first { it !is PsiComment && it !is PsiWhiteSpace } if (firstNonComment != firstChild || lastNonComment != lastChild) { - val start = firstNonComment.getTextRange().getStartOffset() - val end = lastNonComment.getTextRange().getEndOffset() + val start = firstNonComment.startOffset + val end = lastNonComment.endOffset result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, TextRange(start, end))) } diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStringLiteralSelectioner.kt b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStringLiteralSelectioner.kt index 839a77e3af3..ad8130bdef7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStringLiteralSelectioner.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStringLiteralSelectioner.kt @@ -21,6 +21,8 @@ import com.intellij.psi.PsiElement import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.TextRange import org.jetbrains.kotlin.psi.JetStringTemplateExpression +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class KotlinStringLiteralSelectioner : ExtendWordSelectionHandlerBase() { override fun canSelect(e: PsiElement) = e is JetStringTemplateExpression @@ -28,8 +30,8 @@ public class KotlinStringLiteralSelectioner : ExtendWordSelectionHandlerBase() { override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List? { val entries = (e as JetStringTemplateExpression).getEntries() if (entries.isEmpty()) return null - val start = entries.first().getTextRange().getStartOffset() - val end = entries.last().getTextRange().getEndOffset() + val start = entries.first().startOffset + val end = entries.last().endOffset return listOf(TextRange(start, end)) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt index 42d5ca63736..d2dfb78e182 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class AddBracesIntention : JetSelfTargetingIntention(javaClass(), "Add braces") { override fun isApplicableTo(element: JetExpression, caretOffset: Int): Boolean { @@ -50,7 +51,7 @@ public class AddBracesIntention : JetSelfTargetingIntention(javaC is JetIfExpression -> { val thenExpr = getThen() ?: return null val elseExpr = getElse() - if (elseExpr != null && caretLocation >= getElseKeyword()!!.getTextRange().getStartOffset()) { + if (elseExpr != null && caretLocation >= getElseKeyword()!!.startOffset) { return elseExpr } return thenExpr diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToExpressionBodyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToExpressionBodyIntention.kt index 7ffb1cf62d8..1fde9d8ee01 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToExpressionBodyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToExpressionBodyIntention.kt @@ -27,6 +27,8 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsStatement import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf @@ -70,7 +72,7 @@ public class ConvertToExpressionBodyIntention : JetSelfTargetingOffsetIndependen val typeRef = declaration.getTypeReference()!! val colon = declaration.getColon()!! if (editor != null) { - val range = TextRange(colon.getTextRange().getStartOffset(), typeRef.getTextRange().getEndOffset()) + val range = TextRange(colon.startOffset, typeRef.endOffset) editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()) editor.getCaretModel().moveToOffset(range.getEndOffset()) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachFunctionCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachFunctionCallIntention.kt index fd468beb005..eb75cce72a1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachFunctionCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachFunctionCallIntention.kt @@ -21,11 +21,12 @@ import org.jetbrains.kotlin.psi.JetBlockExpression import org.jetbrains.kotlin.psi.JetForExpression import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.createExpressionByPattern +import org.jetbrains.kotlin.psi.psiUtil.endOffset public class ConvertToForEachFunctionCallIntention : JetSelfTargetingIntention(javaClass(), "Replace with a forEach function call") { override fun isApplicableTo(element: JetForExpression, caretOffset: Int): Boolean { val rParen = element.getRightParenthesis() ?: return false - if (caretOffset > rParen.getTextRange().getEndOffset()) return false // available only on the loop header, not in the body + if (caretOffset > rParen.endOffset) return false // available only on the loop header, not in the body return element.getLoopRange() != null && element.getLoopParameter() != null && element.getBody() != null } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/IfNullToElvisIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/IfNullToElvisIntention.kt index 007dbb60d15..80efd684487 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/IfNullToElvisIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/IfNullToElvisIntention.kt @@ -26,8 +26,10 @@ import org.jetbrains.kotlin.idea.intentions.branchedTransformations.expressionCo import org.jetbrains.kotlin.idea.util.isNothing import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.replaced import org.jetbrains.kotlin.psi.psiUtil.siblings +import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import java.util.ArrayList @@ -39,7 +41,7 @@ public class IfNullToElvisIntention : JetSelfTargetingRangeIntention(javaClass(), "Move lambda argument out of parentheses") { @@ -26,7 +27,7 @@ public class MoveLambdaOutsideParenthesesIntention : JetSelfTargetingIntention(javaClass(), "Remove explicit lambda parameter types (may break code)") { override fun isApplicableTo(element: JetFunctionLiteralExpression, caretOffset: Int): Boolean { if (element.getValueParameters().none { it.getTypeReference() != null }) return false - val arrow = element.getFunctionLiteral().getArrowNode() ?: return false - return caretOffset <= arrow.getTextRange().getEndOffset() + val arrow = element.getFunctionLiteral().getArrow() ?: return false + return caretOffset <= arrow.endOffset } override fun applyTo(element: JetFunctionLiteralExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt index 265fcf05a1a..ae2fa4b3bf1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.references.JetReference import org.jetbrains.kotlin.psi.JetFunctionLiteral import org.jetbrains.kotlin.psi.JetSimpleNameExpression +import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils @@ -63,8 +64,8 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa } val functionLiteral = element.getParentOfType(true) ?: return null - val arrow = functionLiteral.getArrowNode() ?: return null - if (caretOffset > arrow.getTextRange().getEndOffset()) return null + val arrow = functionLiteral.getArrow() ?: return null + if (caretOffset > arrow.endOffset) return null return functionLiteral } @@ -81,7 +82,7 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa public override fun performRefactoring(usages: Array) { super.performRefactoring(usages) - functionLiteral.deleteChildRange(functionLiteral.getValueParameterList(), functionLiteral.getArrowNode()!!.getPsi()) + functionLiteral.deleteChildRange(functionLiteral.getValueParameterList(), functionLiteral.getArrow()!!) if (cursorWasInParameterList) { editor.getCaretModel().moveToOffset(functionLiteral.getBodyExpression()!!.getTextOffset()) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceItWithExplicitFunctionLiteralParamIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceItWithExplicitFunctionLiteralParamIntention.kt index 4357f170fcd..7217fd588d3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceItWithExplicitFunctionLiteralParamIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceItWithExplicitFunctionLiteralParamIntention.kt @@ -50,7 +50,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : JetSelfTarge val newExpr = JetPsiFactory(element).createExpression("{ it -> }") as JetFunctionLiteralExpression functionLiteral.addRangeAfter( newExpr.getFunctionLiteral().getValueParameterList(), - newExpr.getFunctionLiteral().getArrowNode()!!.getPsi(), + newExpr.getFunctionLiteral().getArrow()!!, functionLiteral.getLBrace()) PsiDocumentManager.getInstance(element.getProject()).doPostponedOperationsAndUnblockDocument(editor.getDocument()) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt index f26d54e70c0..16e909b7e40 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt @@ -25,13 +25,14 @@ import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.idea.util.ShortenReferences import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.psi.psiUtil.endOffset public class SpecifyExplicitLambdaSignatureIntention : JetSelfTargetingIntention(javaClass(), "Specify explicit lambda signature") { override fun isApplicableTo(element: JetFunctionLiteralExpression, caretOffset: Int): Boolean { - val arrow = element.getFunctionLiteral().getArrowNode() + val arrow = element.getFunctionLiteral().getArrow() if (arrow != null) { - if (caretOffset > arrow.getTextRange().getEndOffset()) return false + if (caretOffset > arrow.endOffset) return false if (element.getValueParameters().all { it.getTypeReference() != null }) return false } else { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt index d152ab31f76..2123b3aa3d7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt @@ -23,12 +23,13 @@ import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetSimpleNameExpression import org.jetbrains.kotlin.psi.JetWhenExpression import org.jetbrains.kotlin.psi.buildExpression +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class EliminateWhenSubjectIntention : JetSelfTargetingIntention(javaClass(), "Eliminate argument of 'when'") { override fun isApplicableTo(element: JetWhenExpression, caretOffset: Int): Boolean { if (element.getSubjectExpression() !is JetSimpleNameExpression) return false val lBrace = element.getOpenBrace() ?: return false - return caretOffset <= lBrace.getTextRange().getStartOffset() + return caretOffset <= lBrace.startOffset } override fun applyTo(element: JetWhenExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt index 3c27570d85e..11ee336f93f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt @@ -21,7 +21,9 @@ import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention import org.jetbrains.kotlin.idea.quickfix.moveCaret import org.jetbrains.kotlin.idea.util.psi.patternMatching.matches import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.replaced +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class FlattenWhenIntention : JetSelfTargetingIntention(javaClass(), "Flatten 'when' expression") { override fun isApplicableTo(element: JetWhenExpression, caretOffset: Int): Boolean { @@ -37,7 +39,7 @@ public class FlattenWhenIntention : JetSelfTargetingIntention if (!subject.matches(innerWhen.getSubjectExpression())) return false if (!JetPsiUtil.checkWhenExpressionHasSingleElse(innerWhen)) return false - return elseEntry.getTextRange().getStartOffset() <= caretOffset && caretOffset <= innerWhen.getWhenKeywordElement().getTextRange().getEndOffset() + return elseEntry.startOffset <= caretOffset && caretOffset <= innerWhen.getWhenKeywordElement().endOffset } override fun applyTo(element: JetWhenExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt index 2b5b03bbb65..f1ece36cad3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt @@ -23,6 +23,8 @@ import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsStatement public class IfThenToDoubleBangIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace 'if' expression with '!!' expression") { @@ -61,7 +63,7 @@ public class IfThenToDoubleBangIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace assignment with 'if' expression") { override fun applicabilityRange(element: JetBinaryExpression): TextRange? { if (element.getOperationToken() !in JetTokens.ALL_ASSIGNMENTS) return null if (element.getLeft() == null) return null val right = element.getRight() as? JetIfExpression ?: return null - return TextRange(element.getTextRange().getStartOffset(), right.getIfKeyword().getTextRange().getEndOffset()) + return TextRange(element.startOffset, right.getIfKeyword().endOffset) } override fun applyTo(element: JetBinaryExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToWhenIntention.kt index 06525b46ded..22a8b534524 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToWhenIntention.kt @@ -24,6 +24,8 @@ import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.JetBinaryExpression import org.jetbrains.kotlin.psi.JetPsiUtil import org.jetbrains.kotlin.psi.JetWhenExpression +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class UnfoldAssignmentToWhenIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace assignment with 'when' expression" ) { override fun applicabilityRange(element: JetBinaryExpression): TextRange? { @@ -31,7 +33,7 @@ public class UnfoldAssignmentToWhenIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace property initializer with 'if' expression") { override fun applicabilityRange(element: JetProperty): TextRange? { if (!element.isLocal()) return null val initializer = element.getInitializer() as? JetIfExpression ?: return null - return TextRange(element.getTextRange().getStartOffset(), initializer.getIfKeyword().getTextRange().getEndOffset()) + return TextRange(element.startOffset, initializer.getIfKeyword().endOffset) } override fun applyTo(element: JetProperty, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt index 993db3ac1a8..57b68afc34d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt @@ -24,13 +24,15 @@ import org.jetbrains.kotlin.idea.intentions.splitPropertyDeclaration import org.jetbrains.kotlin.psi.JetProperty import org.jetbrains.kotlin.psi.JetPsiUtil import org.jetbrains.kotlin.psi.JetWhenExpression +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class UnfoldPropertyToWhenIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace property initializer with 'when' expression") { override fun applicabilityRange(element: JetProperty): TextRange? { if (!element.isLocal()) return null val initializer = element.getInitializer() as? JetWhenExpression ?: return null if (!JetPsiUtil.checkWhenExpressionHasSingleElse(initializer)) return null - return TextRange(element.getTextRange().getStartOffset(), initializer.getWhenKeywordElement().getTextRange().getEndOffset()) + return TextRange(element.startOffset, initializer.getWhenKeywordElement().endOffset) } override fun applyTo(element: JetProperty, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt index 1a2370c98c4..bba476e3ad7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt @@ -25,11 +25,13 @@ import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetReturnExpression import org.jetbrains.kotlin.psi.createExpressionByPattern import org.jetbrains.kotlin.psi.psiUtil.copied +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class UnfoldReturnToIfIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace return with 'if' expression") { override fun applicabilityRange(element: JetReturnExpression): TextRange? { val ifExpression = element.getReturnedExpression() as? JetIfExpression ?: return null - return TextRange(element.getTextRange().getStartOffset(), ifExpression.getIfKeyword().getTextRange().getEndOffset()) + return TextRange(element.startOffset, ifExpression.getIfKeyword().endOffset) } override fun applyTo(element: JetReturnExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToWhenIntention.kt index e12837e6bee..9667d5cacd4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToWhenIntention.kt @@ -22,12 +22,14 @@ import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.copied +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class UnfoldReturnToWhenIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace return with 'when' expression") { override fun applicabilityRange(element: JetReturnExpression): TextRange? { val whenExpr = element.getReturnedExpression() as? JetWhenExpression ?: return null if (!JetPsiUtil.checkWhenExpressionHasSingleElse(whenExpr)) return null - return TextRange(element.getTextRange().getStartOffset(), whenExpr.getWhenKeywordElement().getTextRange().getEndOffset()) + return TextRange(element.startOffset, whenExpr.getWhenKeywordElement().endOffset) } override fun applyTo(element: JetReturnExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/SplitPropertyDeclarationIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/SplitPropertyDeclarationIntention.kt index 4cd7dd1cd7a..f0fbc02c384 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/SplitPropertyDeclarationIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/SplitPropertyDeclarationIntention.kt @@ -21,12 +21,13 @@ import com.intellij.openapi.util.TextRange import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention import org.jetbrains.kotlin.idea.intentions.splitPropertyDeclaration import org.jetbrains.kotlin.psi.JetProperty +import org.jetbrains.kotlin.psi.psiUtil.startOffset public class SplitPropertyDeclarationIntention : JetSelfTargetingRangeIntention(javaClass(), "Split property declaration") { override fun applicabilityRange(element: JetProperty): TextRange? { if (!element.isLocal()) return null val initializer = element.getInitializer() ?: return null - return TextRange(element.getTextRange().getStartOffset(), initializer.getTextRange().getStartOffset()) + return TextRange(element.startOffset, initializer.startOffset) } override fun applyTo(element: JetProperty, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt index 9123c3025cd..93cca5850b0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt @@ -196,7 +196,7 @@ private class LambdaToFunctionExpression( // many statements if (returnType != null) statements.filterIsInstance().lastOrNull()?.replaceWithReturn(psiFactory) - val fromElement = functionLiteral.getArrowNode()?.getPsi() ?: functionLiteral.getLBrace() + val fromElement = functionLiteral.getArrow() ?: functionLiteral.getLBrace() val toElement = functionLiteral.getRBrace() // to include comments in the start/end of the body val bodyText = fromElement.siblings(withItself = false) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt index 903b45004b4..e07e1f30fd2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.idea.core.isVisible import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.ShortenReferences import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.replaced import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.BindingContext @@ -89,7 +90,7 @@ public object SuperClassNotInitialized : JetIntentionActionsFactory() { if (putCaretIntoParenthesis) { if (editor != null) { - val offset = newSpecifier.getValueArgumentList()!!.getLeftParenthesis()!!.getTextRange().getEndOffset() + val offset = newSpecifier.getValueArgumentList()!!.getLeftParenthesis()!!.endOffset editor.moveCaret(offset) if (!ApplicationManager.getApplication().isUnitTestMode()) { ShowParameterInfoHandler.invoke(project, editor, file, offset - 1, null) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index 17c1979d26e..2df9c1e2d51 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -892,17 +892,17 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { when (newJavaMember) { is PsiMethod -> CreateFromUsageUtils.setupEditor(newJavaMember, targetEditor) - is PsiField -> targetEditor.getCaretModel().moveToOffset(newJavaMember.getTextRange().getEndOffset() - 1) + is PsiField -> targetEditor.getCaretModel().moveToOffset(newJavaMember.endOffset - 1) is PsiClass -> { val constructor = newJavaMember.getConstructors().firstOrNull() val superStatement = constructor?.getBody()?.getStatements()?.firstOrNull() as? PsiExpressionStatement val superCall = superStatement?.getExpression() as? PsiMethodCallExpression if (superCall != null) { val lParen = superCall.getArgumentList().getFirstChild() - targetEditor.getCaretModel().moveToOffset(lParen.getTextRange().getEndOffset()) + targetEditor.getCaretModel().moveToOffset(lParen.endOffset) } else { - targetEditor.getCaretModel().moveToOffset(newJavaMember.getTextRange().getStartOffset()) + targetEditor.getCaretModel().moveToOffset(newJavaMember.startOffset) } } } @@ -916,17 +916,17 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val selectionModel = containingFileEditor.getSelectionModel() if (declaration is JetSecondaryConstructor) { - caretModel.moveToOffset(declaration.getConstructorKeyword().getTextRange().getEndOffset()) + caretModel.moveToOffset(declaration.getConstructorKeyword().endOffset) } else { - caretModel.moveToOffset(declaration.getNameIdentifier()!!.getTextRange().getEndOffset()) + caretModel.moveToOffset(declaration.getNameIdentifier()!!.endOffset) } fun positionBetween(left: PsiElement, right: PsiElement) { val from = left.siblings(withItself = false, forward = true).firstOrNull { it !is PsiWhiteSpace } ?: return val to = right.siblings(withItself = false, forward = false).firstOrNull { it !is PsiWhiteSpace } ?: return - val startOffset = from.getTextRange().getStartOffset() - val endOffset = to.getTextRange().getEndOffset() + val startOffset = from.startOffset + val endOffset = to.endOffset caretModel.moveToOffset(endOffset) selectionModel.setSelection(startOffset, endOffset) } @@ -938,7 +938,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } } is JetClassOrObject -> { - caretModel.moveToOffset(declaration.getTextRange().getStartOffset()) + caretModel.moveToOffset(declaration.startOffset) } is JetProperty -> { if (!declaration.hasInitializer() && containingElement is JetBlockExpression) { @@ -949,7 +949,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val range = initializer.getTextRange() selectionModel.setSelection(range.getStartOffset(), range.getEndOffset()) } - caretModel.moveToOffset(declaration.getTextRange().getEndOffset()) + caretModel.moveToOffset(declaration.endOffset) } } containingFileEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetFunctionDefinitionUsage.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetFunctionDefinitionUsage.java index 032d54c0d60..337a55abc41 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetFunctionDefinitionUsage.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetFunctionDefinitionUsage.java @@ -248,9 +248,9 @@ public class JetFunctionDefinitionUsage extends JetUsageIn if (parametersCount == 0 && ((JetFunctionLiteral) element).getTypeReference() == null) { if (parameterList != null) { parameterList.delete(); - ASTNode arrowNode = ((JetFunctionLiteral)element).getArrowNode(); - if (arrowNode != null) { - arrowNode.getPsi().delete(); + PsiElement arrow = ((JetFunctionLiteral)element).getArrow(); + if (arrow != null) { + arrow.delete(); } parameterList = null; } @@ -298,7 +298,7 @@ public class JetFunctionDefinitionUsage extends JetUsageIn JetFunctionLiteral functionLiteral = (JetFunctionLiteral) element; PsiElement anchor = functionLiteral.getLBrace(); newParameterList = (JetParameterList) element.addAfter(newParameterList, anchor); - if (functionLiteral.getArrowNode() == null) { + if (functionLiteral.getArrow() == null) { Pair whitespaceAndArrow = psiFactory.createWhitespaceAndArrow(); element.addRangeAfter(whitespaceAndArrow.getFirst(), whitespaceAndArrow.getSecond(), newParameterList); } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt index aadc0dda702..e8162f43957 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt @@ -574,10 +574,10 @@ fun ExtractionGeneratorConfiguration.generateDeclaration( anchorCandidates.add(targetSibling) val marginalCandidate = if (insertBefore) { - anchorCandidates.minBy { it.getTextRange().getStartOffset() }!! + anchorCandidates.minBy { it.startOffset }!! } else { - anchorCandidates.maxBy { it.getTextRange().getStartOffset() }!! + anchorCandidates.maxBy { it.startOffset }!! } // Ascend to the level of targetSibling