Minor: Replace PsiFile with KtFile in utility functions

This commit is contained in:
Alexey Sedunov
2015-11-17 20:15:27 +03:00
parent c80826aab4
commit 7dbcceee79
7 changed files with 23 additions and 25 deletions
@@ -332,15 +332,15 @@ public class KotlinRefactoringUtil {
public static void selectExpression( public static void selectExpression(
@NotNull Editor editor, @NotNull Editor editor,
@NotNull PsiFile file, @NotNull KtFile file,
@NotNull SelectExpressionCallback callback) throws IntroduceRefactoringException { @NotNull SelectExpressionCallback callback) throws IntroduceRefactoringException {
selectExpression(editor, file, true, callback); selectExpression(editor, file, true, callback);
} }
public static void selectExpression(@NotNull Editor editor, public static void selectExpression(@NotNull Editor editor,
@NotNull PsiFile file, @NotNull KtFile file,
boolean failOnEmptySuggestion, boolean failOnEmptySuggestion,
@NotNull SelectExpressionCallback callback) throws IntroduceRefactoringException { @NotNull SelectExpressionCallback callback) throws IntroduceRefactoringException {
if (editor.getSelectionModel().hasSelection()) { if (editor.getSelectionModel().hasSelection()) {
int selectionStart = editor.getSelectionModel().getSelectionStart(); int selectionStart = editor.getSelectionModel().getSelectionStart();
int selectionEnd = editor.getSelectionModel().getSelectionEnd(); int selectionEnd = editor.getSelectionModel().getSelectionEnd();
@@ -487,7 +487,7 @@ public class KotlinRefactoringUtil {
@Nullable @Nullable
private static KtExpression findExpression( private static KtExpression findExpression(
@NotNull PsiFile file, int startOffset, int endOffset, boolean failOnNoExpression @NotNull KtFile file, int startOffset, int endOffset, boolean failOnNoExpression
) throws IntroduceRefactoringException { ) throws IntroduceRefactoringException {
KtExpression element = CodeInsightUtils.findExpression(file, startOffset, endOffset); KtExpression element = CodeInsightUtils.findExpression(file, startOffset, endOffset);
if (element == null) { if (element == null) {
@@ -16,22 +16,21 @@
package org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction package org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction
import com.intellij.refactoring.RefactoringActionHandler
import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.actionSystem.DataContext
import com.intellij.psi.PsiFile
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.refactoring.RefactoringActionHandler
import org.jetbrains.kotlin.idea.core.refactoring.getExtractionContainers import org.jetbrains.kotlin.idea.core.refactoring.getExtractionContainers
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringBundle import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringBundle
import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.ui.KotlinExtractFunctionDialog import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.ui.KotlinExtractFunctionDialog
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtBlockExpression
import kotlin.test.fail
import org.jetbrains.kotlin.psi.KtFunctionLiteral
import org.jetbrains.kotlin.idea.util.psi.patternMatching.toRange
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.* import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*
import org.jetbrains.kotlin.idea.refactoring.introduce.* import org.jetbrains.kotlin.idea.refactoring.introduce.selectElementsWithTargetSibling
import org.jetbrains.kotlin.idea.util.psi.patternMatching.toRange
import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtFile
import kotlin.test.fail
public class ExtractKotlinFunctionHandler( public class ExtractKotlinFunctionHandler(
public val allContainersEnabled: Boolean = false, public val allContainersEnabled: Boolean = false,
@@ -63,7 +62,7 @@ public class ExtractKotlinFunctionHandler(
} }
} }
fun selectElements(editor: Editor, file: PsiFile, continuation: (elements: List<PsiElement>, targetSibling: PsiElement) -> Unit) { fun selectElements(editor: Editor, file: KtFile, continuation: (elements: List<PsiElement>, targetSibling: PsiElement) -> Unit) {
selectElementsWithTargetSibling( selectElementsWithTargetSibling(
EXTRACT_FUNCTION, EXTRACT_FUNCTION,
editor, editor,
@@ -171,7 +171,7 @@ private fun isObjectOrNonInnerClass(e: PsiElement): Boolean = e is KtObjectDecla
fun selectNewParameterContext( fun selectNewParameterContext(
editor: Editor, editor: Editor,
file: PsiFile, file: KtFile,
continuation: (elements: List<PsiElement>, targetParent: PsiElement) -> Unit continuation: (elements: List<PsiElement>, targetParent: PsiElement) -> Unit
) { ) {
selectElementsWithTargetParent( selectElementsWithTargetParent(
@@ -28,8 +28,6 @@ import org.jetbrains.kotlin.idea.util.psi.patternMatching.*
import kotlin.test.* import kotlin.test.*
import com.intellij.openapi.application.* import com.intellij.openapi.application.*
import org.jetbrains.kotlin.idea.core.refactoring.getExtractionContainers import org.jetbrains.kotlin.idea.core.refactoring.getExtractionContainers
import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.EXTRACT_FUNCTION
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceProperty.*
import java.util.* import java.util.*
public class KotlinIntroducePropertyHandler( public class KotlinIntroducePropertyHandler(
@@ -54,7 +52,7 @@ public class KotlinIntroducePropertyHandler(
} }
} }
public fun selectElements(editor: Editor, file: PsiFile, continuation: (elements: List<PsiElement>, targetSibling: PsiElement) -> Unit) { public fun selectElements(editor: Editor, file: KtFile, continuation: (elements: List<PsiElement>, targetSibling: PsiElement) -> Unit) {
selectElementsWithTargetSibling( selectElementsWithTargetSibling(
INTRODUCE_PROPERTY, INTRODUCE_PROPERTY,
editor, editor,
@@ -21,13 +21,13 @@ import com.intellij.openapi.editor.ScrollType
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key import com.intellij.openapi.util.Key
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
import org.jetbrains.kotlin.idea.core.refactoring.chooseContainerElementIfNecessary import org.jetbrains.kotlin.idea.core.refactoring.chooseContainerElementIfNecessary
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringBundle import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringBundle
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringUtil import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringUtil
import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
import org.jetbrains.kotlin.psi.psiUtil.getOutermostParentContainedIn import org.jetbrains.kotlin.psi.psiUtil.getOutermostParentContainedIn
@@ -43,7 +43,7 @@ fun showErrorHintByKey(project: Project, editor: Editor, messageKey: String, tit
fun selectElementsWithTargetSibling( fun selectElementsWithTargetSibling(
operationName: String, operationName: String,
editor: Editor, editor: Editor,
file: PsiFile, file: KtFile,
getContainers: (elements: List<PsiElement>, commonParent: PsiElement) -> List<PsiElement>, getContainers: (elements: List<PsiElement>, commonParent: PsiElement) -> List<PsiElement>,
continuation: (elements: List<PsiElement>, targetSibling: PsiElement) -> Unit continuation: (elements: List<PsiElement>, targetSibling: PsiElement) -> Unit
) { ) {
@@ -71,7 +71,7 @@ fun selectElementsWithTargetSibling(
fun selectElementsWithTargetParent( fun selectElementsWithTargetParent(
operationName: String, operationName: String,
editor: Editor, editor: Editor,
file: PsiFile, file: KtFile,
getContainers: (elements: List<PsiElement>, commonParent: PsiElement) -> List<PsiElement>, getContainers: (elements: List<PsiElement>, commonParent: PsiElement) -> List<PsiElement>,
continuation: (elements: List<PsiElement>, targetParent: PsiElement) -> Unit continuation: (elements: List<PsiElement>, targetParent: PsiElement) -> Unit
) { ) {
@@ -579,6 +579,7 @@ object KotlinIntroduceVariableHandler : KotlinIntroduceHandlerBase() {
} }
override fun invoke(project: Project, editor: Editor, file: PsiFile, dataContext: DataContext) { override fun invoke(project: Project, editor: Editor, file: PsiFile, dataContext: DataContext) {
if (file !is KtFile) return
try { try {
KotlinRefactoringUtil.selectExpression(editor, file) { doRefactoring(project, editor, it, null, null) } KotlinRefactoringUtil.selectExpression(editor, file) { doRefactoring(project, editor, it, null, null) }
} }
@@ -31,7 +31,7 @@ public abstract class AbstractExpressionSelectionTest extends LightCodeInsightTe
final String expectedExpression = KotlinTestUtils.getLastCommentInFile((KtFile) getFile()); final String expectedExpression = KotlinTestUtils.getLastCommentInFile((KtFile) getFile());
try { try {
KotlinRefactoringUtil.selectExpression(getEditor(), getFile(), new KotlinRefactoringUtil.SelectExpressionCallback() { KotlinRefactoringUtil.selectExpression(getEditor(), (KtFile) getFile(), new KotlinRefactoringUtil.SelectExpressionCallback() {
@Override @Override
public void run(@Nullable KtExpression expression) { public void run(@Nullable KtExpression expression) {
assertNotNull("Selected expression mustn't be null", expression); assertNotNull("Selected expression mustn't be null", expression);