mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[extract method] switch tests to new implementation
GitOrigin-RevId: 7b3bfba8e61bead1c927368ffb8921f325143f34
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0e860160e5
commit
5ab38e68cc
@@ -152,8 +152,7 @@ public class ExtractMethodHandler implements RefactoringActionHandler, ContextAw
|
||||
return expressions.toArray(PsiElement.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
public static boolean shouldUseNewImpl(@NotNull Project project, PsiFile file, PsiElement @NotNull [] elements){
|
||||
if (! Registry.is("java.refactoring.extractMethod.newImplementation")) return false;
|
||||
public static boolean canUseNewImpl(@NotNull Project project, PsiFile file, PsiElement @NotNull [] elements){
|
||||
final ExtractMethodProcessor processor = getProcessor(project, elements, file, false);
|
||||
if (processor == null) return true;
|
||||
try {
|
||||
@@ -169,7 +168,7 @@ public class ExtractMethodHandler implements RefactoringActionHandler, ContextAw
|
||||
}
|
||||
|
||||
public static void invokeOnElements(@NotNull Project project, final Editor editor, PsiFile file, PsiElement @NotNull [] elements) {
|
||||
if (shouldUseNewImpl(project, file, elements)) {
|
||||
if (Registry.is("java.refactoring.extractMethod.newImplementation") && canUseNewImpl(project, file, elements)) {
|
||||
new MethodExtractor().doExtract(editor, getRefactoringName(), HelpID.EXTRACT_METHOD);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -800,7 +800,6 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
myNullability = initNullability();
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public void testPrepare() {
|
||||
myInputVariables.setFoldingAvailable(myInputVariables.isFoldingSelectedByDefault());
|
||||
myMethodName = myInitialMethodName;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
@@ -22,6 +22,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.extractMethod.ExtractMethodHandler;
|
||||
import com.intellij.refactoring.extractMethod.ExtractMethodProcessor;
|
||||
import com.intellij.refactoring.extractMethod.PrepareFailedException;
|
||||
import com.intellij.refactoring.extractMethod.newImpl.MethodExtractor;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.refactoring.util.duplicates.Match;
|
||||
import com.intellij.testFramework.LightJavaCodeInsightTestCase;
|
||||
@@ -709,11 +710,11 @@ public class ExtractMethodNewTest extends LightJavaCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testMethod2InterfaceFromStatic() throws Exception {
|
||||
doTest();
|
||||
doTestWithLanguageLevel(LanguageLevel.JDK_1_8);
|
||||
}
|
||||
|
||||
public void testMethod2InterfaceFromConstant() throws Exception {
|
||||
doTest();
|
||||
doTestWithLanguageLevel(LanguageLevel.JDK_1_8);
|
||||
}
|
||||
|
||||
public void testParamDetection() throws Exception {
|
||||
@@ -1405,7 +1406,7 @@ public class ExtractMethodNewTest extends LightJavaCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testFromStaticMethodInInterface() throws Exception {
|
||||
doTest();
|
||||
doTestWithLanguageLevel(LanguageLevel.JDK_1_8);
|
||||
}
|
||||
|
||||
public void testDisjunctionType() throws Exception {
|
||||
@@ -1463,7 +1464,7 @@ public class ExtractMethodNewTest extends LightJavaCodeInsightTestCase {
|
||||
private void doPrepareErrorTest(final String expectedMessage) throws Exception {
|
||||
String expectedError = null;
|
||||
try {
|
||||
doExitPointsTest(false);
|
||||
doErrorTest();
|
||||
}
|
||||
catch(PrepareFailedException ex) {
|
||||
expectedError = ex.getMessage();
|
||||
@@ -1471,11 +1472,22 @@ public class ExtractMethodNewTest extends LightJavaCodeInsightTestCase {
|
||||
assertEquals(expectedMessage, expectedError);
|
||||
}
|
||||
|
||||
private void doErrorTest() throws Exception {
|
||||
String fileName = getTestName(false) + ".java";
|
||||
configureByFile(BASE_PATH + fileName);
|
||||
performAction(false,false);
|
||||
}
|
||||
|
||||
private void doExitPointsTest(boolean shouldSucceed) throws Exception {
|
||||
String fileName = getTestName(false) + ".java";
|
||||
configureByFile(BASE_PATH + fileName);
|
||||
boolean success = performAction(false, false);
|
||||
assertEquals(shouldSucceed, success);
|
||||
boolean succeed = false;
|
||||
try {
|
||||
doErrorTest();
|
||||
succeed = true;
|
||||
} catch (PrepareFailedException e) {
|
||||
}
|
||||
assertEquals(shouldSucceed, succeed);
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
@@ -1583,6 +1595,11 @@ public class ExtractMethodNewTest extends LightJavaCodeInsightTestCase {
|
||||
processor.setShowErrorDialogs(false);
|
||||
processor.setChainedConstructor(extractChainedConstructor);
|
||||
|
||||
if (ExtractMethodHandler.canUseNewImpl(project, file, elements)) {
|
||||
return new MethodExtractor().doTestExtract(true, editor, extractChainedConstructor, makeStatic, returnType,
|
||||
newNameOfFirstParam, targetClass, methodVisibility, disabledParams);
|
||||
}
|
||||
|
||||
if (!processor.prepare()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user