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(
@NotNull Editor editor,
@NotNull PsiFile file,
@NotNull KtFile file,
@NotNull SelectExpressionCallback callback) throws IntroduceRefactoringException {
selectExpression(editor, file, true, callback);
}
public static void selectExpression(@NotNull Editor editor,
@NotNull PsiFile file,
boolean failOnEmptySuggestion,
@NotNull SelectExpressionCallback callback) throws IntroduceRefactoringException {
@NotNull KtFile file,
boolean failOnEmptySuggestion,
@NotNull SelectExpressionCallback callback) throws IntroduceRefactoringException {
if (editor.getSelectionModel().hasSelection()) {
int selectionStart = editor.getSelectionModel().getSelectionStart();
int selectionEnd = editor.getSelectionModel().getSelectionEnd();
@@ -439,7 +439,7 @@ public class KotlinRefactoringUtil {
final ScopeHighlighter highlighter = new ScopeHighlighter(editor);
final JList list = new JBList(model);
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
@@ -478,7 +478,7 @@ public class KotlinRefactoringUtil {
highlighter.dropHighlight();
}
}).createPopup().showInBestPositionFor(editor);
}
public static String getExpressionShortText(@NotNull KtElement element) { //todo: write appropriate implementation
@@ -487,7 +487,7 @@ public class KotlinRefactoringUtil {
@Nullable
private static KtExpression findExpression(
@NotNull PsiFile file, int startOffset, int endOffset, boolean failOnNoExpression
@NotNull KtFile file, int startOffset, int endOffset, boolean failOnNoExpression
) throws IntroduceRefactoringException {
KtExpression element = CodeInsightUtils.findExpression(file, startOffset, endOffset);
if (element == null) {
@@ -16,22 +16,21 @@
package org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction
import com.intellij.refactoring.RefactoringActionHandler
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.psi.PsiFile
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
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.refactoring.KotlinRefactoringBundle
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.*
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 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(
EXTRACT_FUNCTION,
editor,
@@ -171,7 +171,7 @@ private fun isObjectOrNonInnerClass(e: PsiElement): Boolean = e is KtObjectDecla
fun selectNewParameterContext(
editor: Editor,
file: PsiFile,
file: KtFile,
continuation: (elements: List<PsiElement>, targetParent: PsiElement) -> Unit
) {
selectElementsWithTargetParent(
@@ -28,8 +28,6 @@ import org.jetbrains.kotlin.idea.util.psi.patternMatching.*
import kotlin.test.*
import com.intellij.openapi.application.*
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.*
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(
INTRODUCE_PROPERTY,
editor,
@@ -21,13 +21,13 @@ import com.intellij.openapi.editor.ScrollType
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
import org.jetbrains.kotlin.idea.core.refactoring.chooseContainerElementIfNecessary
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringBundle
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringUtil
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.findDescendantOfType
import org.jetbrains.kotlin.psi.psiUtil.getOutermostParentContainedIn
@@ -43,7 +43,7 @@ fun showErrorHintByKey(project: Project, editor: Editor, messageKey: String, tit
fun selectElementsWithTargetSibling(
operationName: String,
editor: Editor,
file: PsiFile,
file: KtFile,
getContainers: (elements: List<PsiElement>, commonParent: PsiElement) -> List<PsiElement>,
continuation: (elements: List<PsiElement>, targetSibling: PsiElement) -> Unit
) {
@@ -71,7 +71,7 @@ fun selectElementsWithTargetSibling(
fun selectElementsWithTargetParent(
operationName: String,
editor: Editor,
file: PsiFile,
file: KtFile,
getContainers: (elements: List<PsiElement>, commonParent: PsiElement) -> List<PsiElement>,
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) {
if (file !is KtFile) return
try {
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());
try {
KotlinRefactoringUtil.selectExpression(getEditor(), getFile(), new KotlinRefactoringUtil.SelectExpressionCallback() {
KotlinRefactoringUtil.selectExpression(getEditor(), (KtFile) getFile(), new KotlinRefactoringUtil.SelectExpressionCallback() {
@Override
public void run(@Nullable KtExpression expression) {
assertNotNull("Selected expression mustn't be null", expression);