From 815ca2fe57748c690c24aa5110e0de5bd8e59649 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Fri, 7 Feb 2014 13:26:12 -0800 Subject: [PATCH] Separate GUI logic from smartSelectExpression Previously smartSelectExpression did both the determination of suitable expressions and displaying the GUI. Separate the actual logic into a new method, getSmartSelectSuggestions so that smart selection can be tested in the future. --- .../refactoring/JetRefactoringUtil.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java index 4f6fdaf1052..50345e9b618 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java @@ -383,16 +383,22 @@ public class JetRefactoringUtil { } } - private static void smartSelectExpression(@NotNull Editor editor, @NotNull PsiFile file, int offset, - @NotNull final SelectExpressionCallback callback) - throws IntroduceRefactoringException { - if (offset < 0) throw new IntroduceRefactoringException(JetRefactoringBundle.message("cannot.refactor.not.expression")); - PsiElement element = file.findElementAt(offset); - if (element == null) throw new IntroduceRefactoringException(JetRefactoringBundle.message("cannot.refactor.not.expression")); - if (element instanceof PsiWhiteSpace) { - smartSelectExpression(editor, file, offset - 1, callback); - return; + public static List getSmartSelectSuggestions( + @NotNull PsiFile file, + int offset + ) throws IntroduceRefactoringException { + if (offset < 0) { + return new ArrayList(); } + + PsiElement element = file.findElementAt(offset); + if (element == null) { + return new ArrayList(); + } + if (element instanceof PsiWhiteSpace) { + return getSmartSelectSuggestions(file, offset - 1); + } + ArrayList expressions = new ArrayList(); while (element != null && !(element instanceof JetBlockExpression && !(element.getParent() instanceof JetFunctionLiteral)) && !(element instanceof JetNamedFunction) @@ -427,6 +433,13 @@ public class JetRefactoringUtil { } element = element.getParent(); } + return expressions; + } + + private static void smartSelectExpression( + @NotNull Editor editor, @NotNull PsiFile file, int offset, + @NotNull final SelectExpressionCallback callback) throws IntroduceRefactoringException { + List expressions = getSmartSelectSuggestions(file, offset); if (expressions.size() == 0) throw new IntroduceRefactoringException(JetRefactoringBundle.message("cannot.refactor.not.expression")); if (expressions.size() == 1) {