introduce functional parameter from substring

EA-80674 - AIOOBE: IntroduceParameterHandler.introduceStrategy
This commit is contained in:
Anna.Kozlova
2016-03-17 21:25:32 +01:00
parent 5c8090dd02
commit 4ad5c2006c
5 changed files with 59 additions and 26 deletions
@@ -0,0 +1,7 @@
import java.util.function.Supplier;
class Test {
void foo(Supplier<String> anObject) {
System.out.println("a" + anObject.get() + "d");
}
}
@@ -0,0 +1,5 @@
class Test {
void foo() {
System.out.println("a<selection>bc</selection>d");
}
}
@@ -16,12 +16,11 @@
package com.intellij.refactoring;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiExpression;
import com.intellij.refactoring.extractMethod.ExtractMethodHandler;
import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.TestDataPath;
@@ -69,6 +68,10 @@ public class IntroduceFunctionalParameterTest extends LightRefactoringTestCase
doTest();
}
public void testPartialString() throws Exception {
doTest();
}
@NotNull
@Override
protected String getTestDataPath() {
@@ -97,15 +100,7 @@ public class IntroduceFunctionalParameterTest extends LightRefactoringTestCase
myEditor.getSettings().setVariableInplaceRenameEnabled(false);
final SelectionModel selectionModel = getEditor().getSelectionModel();
if (selectionModel.hasSelection()) {
final int selectionStart = selectionModel.getSelectionStart();
final int selectionEnd = selectionModel.getSelectionEnd();
PsiElement[] elements = CodeInsightUtil.findStatementsInRange(getFile(), selectionStart, selectionEnd);
if (elements.length == 0) {
final PsiExpression expression = CodeInsightUtil.findExpressionInRange(getFile(), selectionStart, selectionEnd);
if (expression != null) {
elements = new PsiElement[] {expression};
}
}
PsiElement[] elements = ExtractMethodHandler.getElements(getProject(), getEditor(), getFile());
new IntroduceParameterHandler().introduceStrategy(getProject(), getEditor(), getFile(), elements);
}
checkResultByFile("/refactoring/introduceFunctionalParameter/after" + getTestName(false) + ".java");