// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.refactoring;

import com.intellij.JavaTestUtil;
import com.intellij.application.options.CodeStyle;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.codeInsight.NullableNotNullManager;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.registry.RegistryValue;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.IntroduceVariableUtil;
import com.intellij.refactoring.extractMethod.ExtractMethodHandler;
import com.intellij.refactoring.extractMethod.ExtractMethodProcessor;
import com.intellij.refactoring.extractMethod.PrepareFailedException;
import com.intellij.refactoring.util.duplicates.Match;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.LightJavaCodeInsightTestCase;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ExtractMethodTest extends LightJavaCodeInsightTestCase {
  @NonNls private static final String BASE_PATH = "/refactoring/extractMethod/";
  private boolean myCatchOnNewLine = true;

  @Override
  protected Sdk getProjectJDK() {
    return IdeaTestUtil.getMockJdk21();
  }

  @NotNull
  @Override
  protected String getTestDataPath() {
    return JavaTestUtil.getJavaTestDataPath();
  }

  public void testExitPoints1() throws Exception {
    doExitPointsTest(true);
  }

  public void testExitPoints2() throws Exception {
    doTest();
  }

  public void testExitPoints3() throws Exception {
    doExitPointsTest(true);
  }

  public void testExitPoints4() throws Exception {
    doTest();
  }

  public void testExitPoints4Nullable() throws Exception {
    doExitPointsTest(false);
  }

  public void testExitPointsInsideLoop() throws Exception {
    doExitPointsTest(true);
  }

  public void testExitPoints5() throws Exception {
    doTest();
  }

  public void testExitPoints6() throws Exception {
    doExitPointsTest(false);
  }

  public void testExitPoints7() throws Exception {
    doExitPointsTest(false);
  }

  public void testExitPoints8() throws Exception {
    doTest();
  }

  public void testExitPoints9() throws Exception {
    doTest();
  }

  public void testExitPoints10() throws Exception {
    doExitPointsTest(false);
  }

  public void testExitPoints11() throws Exception {
    doTest();
  }

  public void testNotNullCheckNameConflicts() throws Exception {
    doTest();
  }

  public void testContinueInside() throws Exception {
    doTest();
  }

  public void testBooleanExpression() throws Exception {
    doTest();
  }

  public void testScr6241() throws Exception {
    doTest();
  }

  public void testScr7091() throws Exception {
    doTest();
  }

  public void testScr10464() throws Exception {
    doTest();
  }

  public void testScr9852() throws Exception {
    doTest();
  }

  public void testUseVarAfterTry() throws Exception {
    doTest();
  }

  public void testUseParamInCatch() throws Exception {
    doExitPointsTest(false);
  }

  public void testUseParamInFinally() throws Exception {
    doExitPointsTest(false);
  }

  public void testUseVarAfterCatch() throws Exception {
    doExitPointsTest(false);
  }

  public void testUseVarInCatch1() throws Exception {
    doTest();
  }

  public void testUseVarInCatch2() throws Exception {
    doExitPointsTest(false);
  }

  public void testUseVarInCatchInvisible() throws Exception {
    doTest();
  }

  public void testUseVarInCatchNested1() throws Exception {
    doTest();
  }

  public void testUseVarInCatchNested2() throws Exception {
    doExitPointsTest(false);
  }

  public void testUseVarInOtherCatch() throws Exception {
    doTest();
  }

  public void testUseVarInFinally1() throws Exception {
    doTest();
  }

  public void testUseVarInFinally2() throws Exception {
    doExitPointsTest(false);
  }

  public void testOneBranchAssignment() throws Exception {
    doTest();
  }

  public void testExtractFromCodeBlock() throws Exception {
    doTest();
  }

  public void testUnusedInitializedVar() throws Exception {
    doTest();
  }

  public void testTryFinally() throws Exception {
    doTest();
  }

  public void testFinally() throws Exception {
    doTest();
  }

  public void testExtractFromAnonymous() throws Exception {
    doTest();
  }

  public void testSCR12245() throws Exception {
    doTest();
  }

  public void testLeaveCommentsWhenExpressionExtracted() throws Exception {
    doTest();
  }

  public void testSCR15815() throws Exception {
    doTest();
  }

  public void testSCR27887() throws Exception {
    doTest();
  }

  public void testSCR28427() throws Exception {
    doTest();
  }

  public void testTryFinallyInsideFor() throws Exception {
    doTest();
  }

  public void testExtractFromTryFinally() throws Exception {
    doTest();
  }

  public void testExtractAssignmentExpression() throws Exception {
    doTest();
  }

  public void testExtractAssignmentExpressionFromStatement() throws Exception {
    doTest();
  }

  public void testExtractFromTryFinally2() throws Exception {
    doTest();
  }

  public void testLesyaBug() throws Exception {
    myCatchOnNewLine = false;
    doTest();
  }

  public void testForEach() throws Exception {
    doTest();
  }

  public void testAnonInner() throws Exception {
    doTest();
  }


  public void testConflictingAnonymous() throws Exception {
    doTest();
  }

  public void testVarDeclAfterExpressionExtraction() throws Exception {
    doTest();
  }

  public void testFinalParamUsedInsideAnon() throws Exception {
    JavaCodeStyleSettings.getInstance(getProject()).GENERATE_FINAL_PARAMETERS = false;
    doTestWithJava17();
  }

  public void testStringTemplateJava21Preview() throws Exception {
    doTest();
  }

  public void testStringTemplateExceptionJava21Preview() throws Exception {
    doTest();
  }

  private void doTestWithJava17() throws Exception {
    doTestWithLanguageLevel(LanguageLevel.JDK_1_7);
  }

  private void doTestWithLanguageLevel(LanguageLevel languageLevel) throws Exception {
    LanguageLevel oldLevel = IdeaTestUtil.setProjectLanguageLevel(getProject(), languageLevel);
    try {
      doTest();
    }
    finally {
      IdeaTestUtil.setProjectLanguageLevel(getProject(), oldLevel);
    }
  }

  public void testNonFinalWritableParam() throws Exception {
    JavaCodeStyleSettings.getInstance(getProject()).GENERATE_FINAL_PARAMETERS = true;
    doTest();
  }

  public void testCodeDuplicatesWithContinue() throws Exception {
    doDuplicatesTest();
  }

  public void testDuplicatesFromAnonymous() throws Exception {
    doDuplicatesTest();
  }

  public void testDuplicatesFullyQualifiedType() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithContinueNoReturn() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithStaticInitializer() throws Exception {
    doDuplicatesTest();
  }

  public void testDuplicateInUnreachableCode() throws Exception {
    doDuplicatesTest();
  }

  public void testExpressionDuplicates() throws Exception {
    doDuplicatesTest();
  }

  public void testClassReference() throws Exception {
    doDuplicatesTest();
  }

  public void testClassReference2() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicates() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicates2() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicates3() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicates4() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicates5() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithOutputValue() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithOutputValue1() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithEmptyStatementsBlocksParentheses() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithMultExitPoints() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithReturn() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithReturn2() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithReturnInAnonymous() throws Exception {
    doDuplicatesTest();
  }

  public void testCodeDuplicatesWithComments() throws Exception {
    doDuplicatesTest();
  }

  public void testSCR32924() throws Exception {
    doDuplicatesTest();
  }

  public void testFinalOutputVar() throws Exception {
    doDuplicatesTest();
  }

  public void testIdeaDev2291() throws Exception {
    doTest();
  }

  public void testOxfordBug() throws Exception {
    doTest();
  }

  public void testIDEADEV33368() throws Exception {
    doExitPointsTest(false);
  }

  public void testInlineCreated2ReturnLocalVariablesOnly() throws Exception {
    doTest();
  }

  public void testGuardMethodDuplicates() throws Exception {
    doDuplicatesTest();
  }

  public void testGuardMethodDuplicates1() throws Exception {
    doDuplicatesTest();
  }

  public void testInstanceMethodDuplicatesInStaticContext() throws Exception {
    doDuplicatesTest();
  }


  public void testLValueNotDuplicate() throws Exception {
    doDuplicatesTest();
  }

  protected void doDuplicatesTest() throws Exception {
    doTest(true);
  }

  public void testExtractFromFinally() throws Exception {
    doTest();
  }

  public void testNoShortCircuit() throws Exception {
    doTest();
  }

  public void testStopFolding() throws Exception {
    doTest();
  }

  public void testStopFoldingForArrayWriteAccessInConsequentUsages() throws Exception {
    doTest();
  }

  public void testStopFoldingPostfixInside() throws Exception {
    doTest();
  }

  public void testFoldedWithNestedExpressions() throws Exception {
    doTest();
  }

  public void testFoldedWithConflictedNames() throws Exception {
    doTest();
  }

  public void testFoldingWithFieldInvolved() throws Exception {
    doTest();
  }

  public void testFoldingWithFunctionCall() throws Exception {
    doTest();
  }

  public void testDontSkipVariablesUsedInLeftSideOfAssignments() throws Exception {
    doTest();
  }

  public void testIDEADEV11748() throws Exception {
    doTest();
  }

  public void testIDEADEV11848() throws Exception {
    doTest();
  }

  public void testIDEADEV11036() throws Exception {
    doTest();
  }

  public void testLocalClass() throws Exception {
    doPrepareErrorTest("Cannot extract method because the selected code fragment uses local classes defined outside of the fragment");
  }

  public void testLocalClassUsage() throws Exception {
    doPrepareErrorTest("Cannot extract method because the selected code fragment defines local classes used outside of the fragment");
  }

  public void testStaticImport() throws Exception {
    doTest();
  }

  public void testThisCall() throws Exception {
    doTest();
  }

  public void testChainedConstructor() throws Exception {
    doChainedConstructorTest(false);
  }

  public void testChainedConstructorDuplicates() throws Exception {
    doChainedConstructorTest(true);
  }

  public void testChainedConstructorInvalidDuplicates() throws Exception {
    doChainedConstructorTest(true);
  }

  public void testReturnFromTry() throws Exception {
    doTest();
  }

  public void testLocalClassDefinedInMethodWhichIsUsedLater() throws Exception {
    doPrepareErrorTest("Cannot extract method because the selected code fragment defines variable of local class type used outside of the fragment");
  }

  public void testForceBraces() throws Exception {
    final CommonCodeStyleSettings settings = CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
    int old = settings.IF_BRACE_FORCE;
    settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
    try {
      doTest();
    }
    finally {
      settings.IF_BRACE_FORCE = old;
    }
  }

  public void testConstantConditionsAffectingControlFlow() throws Exception {
    doTest();
  }

  public void testConstantConditionsAffectingControlFlow1() throws Exception {
    doTest();
  }
  public void testNotInitializedInsideFinally() throws Exception {
    doTest();
  }

  public void testGenericsParameters() throws Exception {
    doTest();
  }

  public void testUnusedGenerics() throws Exception {
    doTest();
  }

  public void testParamsUsedInLocalClass() throws Exception {
    doTestWithJava17();
  }

  private void doChainedConstructorTest(final boolean replaceAllDuplicates) throws Exception {
    configureByFile(BASE_PATH + getTestName(false) + ".java");
    boolean success = performExtractMethod(true, replaceAllDuplicates, getEditor(), getFile(), getProject(), true);
    assertTrue(success);
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
  }

  public void testReassignedVarAfterCall() throws Exception {
    final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
    settings.GENERATE_FINAL_LOCALS = true;
    doTest();
  }

  public void testNonPhysicalAssumptions() throws Exception {
    doTest();
  }

  public void testNullableCheck() throws Exception {
    doTest();
  }

  public void testNullableCheck1() throws Exception {
    doTest();
  }

  public void testNullableCheckVoid() throws Exception {
    doTest();
  }

  public void testNullableCheckDontMissFinal() throws Exception {
    doTest();
  }

  public void testNullableCheckBreak() throws Exception {
    doTest();
  }

  public void testSimpleArrayAccess() throws Exception {
    doTest();
  }

  public void testArrayAccess() throws Exception {
    doTest();
  }

  public void testArrayAccess1() throws Exception {
    doTest();
  }

  public void testArrayAccessWithLocalIndex() throws Exception {
    doTest();
  }

  public void testArrayAccessWithTopExpression() throws Exception {
    doTest();
  }

  public void testArrayAccessWithDuplicates() throws Exception {
    doDuplicatesTest();
  }

  public void testVerboseArrayAccess() throws Exception {
    doTest();
  }

  public void testReturnStatementFolding() throws Exception {
    doTest();
  }

  public void testWriteArrayAccess() throws Exception {
    doTest();
  }

  public void testShortCircuit() throws Exception {
    doTest();
  }

  public void testRecursiveCallToExtracted() throws Exception {
    doTest();
  }

  public void testCodeDuplicatesVarargsShouldNotChangeReturnType() throws Exception {
    doDuplicatesTest();
  }

  public void testParametersFromAnonymous() throws Exception {
    doTest();
  }

  public void testCast4ParamGeneration() throws Exception {
    doTest();
  }

  public void testNearComment() throws Exception {
    doTest();
  }

  public void testFoldInWhile() throws Exception {
    doTest();
  }

  public void testFoldedParamNameSuggestion() throws Exception {
    doTest();
  }

  public void testNonFoldInIfBody() throws Exception {
    doTest();
  }

  public void testComplexTypeParams() throws Exception {
    doTest();
  }

  public void testExtractWithLeadingComment() throws Exception {
    doTest();
  }

  public void testInvalidReference() throws Exception {
    doTest();
  }

  public void testRedundantCast() throws Exception {
    doTest();
  }

  public void testDisabledParam() throws Exception {
    doTestDisabledParam();
  }

  public void testTypeParamsList() throws Exception {
    doTest();
  }

  public void testTypeParamsListWithRecursiveDependencies() throws Exception {
    doTest();
  }

  public void testFromLambdaBody() throws Exception {
    doTest();
  }

  public void testFromLambdaBody1() throws Exception {
    doTest();
  }

  public void testFromLambdaBodyCapturedWildcardParams() throws Exception {
    doTest();
  }

  public void testFromLambdaBodyToAnonymous() throws Exception {
    doTest();
  }

  public void testFromLambdaBodyToToplevelInsideCodeBlock() throws Exception {
    doTest();
  }

  public void testFromLambdaBodyWithReturn() throws Exception {
    doTest();
  }

  public void testOneLineLambda() throws Exception {
    doTest();
  }

  public void testMethod2Interface() throws Exception {
    doTestWithLanguageLevel(LanguageLevel.JDK_1_8);
  }

  public void testMethod2InterfaceFromStatic() throws Exception {
    doTest();
  }

  public void testMethod2InterfaceFromConstant() throws Exception {
    doTest();
  }

  public void testParamDetection() throws Exception {
    doTest();
  }

  public void testSkipComments() throws Exception {
    doTest();
  }

  public void testFinalParams4LocalClasses() throws Exception {
    doTestWithJava17();
  }

  public void testIncompleteExpression() throws Exception {
    doTest();
  }

  public void testTwoFromThreeEqStatements() throws Exception {
    doDuplicatesTest();
  }

  public void testCastWhenDuplicateReplacement() throws Exception {
    doDuplicatesTest();
  }

  public void testCheckQualifierMapping() throws Exception {
    doDuplicatesTest();
  }

  public void testArrayReturnType() throws Exception {
    doDuplicatesTest();
  }

  public void testOverloadedMethods() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureOneParam() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureOneParamMultipleTimesInside() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureLeaveSameExpressionsUntouched() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureSameParamNames() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureCallToSameClassMethod() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureInitialParameterUnused() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureWithFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureWithArrayFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureWithGetterFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureWithMultiFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureWithTwoWayFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureSameSubexpression() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureSameSubexpressionWholeLine() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureTrivialMethod() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignaturePlusOneFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureVoidCallFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureThreeOccurrencesTwoLiteralFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureFourOccurrencesTwoLiteralFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureThreeOccurrencesTwoVariableFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureFourOccurrencesTwoVariableFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureWithOutputVariables() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureEqualConstExprFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureLongConstExprFolding() throws Exception {
    doDuplicatesTest();
  }

  public void testSuggestChangeSignatureTwoFieldInitializers() throws Exception {
    doDuplicatesTest();
  }

  public void testConditionalReturnInDuplicate() throws Exception {
    doDuplicatesTest();
  }

  // todo DuplicatesFinder.canBeEquivalent() should see the difference between 'return' and assignment
  public void _testConditionalReturnVsAssignDuplicate() throws Exception {
    doDuplicatesTest();
  }

  public void testConditionalWithTwoParameters() throws Exception {
    doDuplicatesTest();
  }

  public void testOverlappingDuplicate() throws Exception {
    doDuplicatesTest();
  }

  public void testEffectivelyLocalVariables() throws Exception {
    doDuplicatesTest();
  }

  public void testEffectivelyLocalWithinExpression() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateNestedSubexpression() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateDeclaredOutputVariable() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateDeclaredReusedVariable() throws Exception {
    doDuplicatesTest();
  }

  public void testExactDuplicateDeclaredReusedVariable() throws Exception {
    doDuplicatesTest();
  }

  public void testExactDuplicateTwoDeclaredReusedVariables() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateUnfoldArrayArgument() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateFoldListElement() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateFoldArrayElement() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedMultiDuplicatesFoldArrayElement() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateFoldArrayElementTwoUsages() throws Exception {
    doDuplicatesTest();
  }

  public void testTripleParametrizedDuplicate() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateKeepSignature() throws Exception {
    doExactDuplicatesTest();
  }

  public void testRejectParametrizedDuplicate() throws Exception {
    doExactDuplicatesTest();
  }

  public void testParametrizedDuplicateRepeatedArguments() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateTripleRepeatedArguments() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateExactlyRepeatedArguments() throws Exception {
    doDuplicatesTest();
  }

  public void testParametrizedDuplicateExpression() throws Exception {
    doDuplicatesTest();
  }
  
  public void testPatternVariable() throws Exception {
    doTestWithLanguageLevel(LanguageLevel.HIGHEST);
  }

  public void testPatternVariableIntroduced() throws Exception {
    doExitPointsTest(false);
  }

  public void testPatternVariableIntroduced2() throws Exception {
    doExitPointsTest(false);
  }

  public void testPatternVariableIntroduced3() throws Exception {
    doTestWithLanguageLevel(LanguageLevel.HIGHEST);
  }

  public void testRecordPatternIntroduced() throws Exception {
    doExitPointsTest(false);
  }

  public void testRecordPatternIntroduced2() throws Exception {
    doExitPointsTest(false);
  }

  public void testRecordPatternIntroduced3() throws Exception {
    doExitPointsTest(false);
  }

  public void testRecordPatternIntroduced4() throws Exception {
    doExitPointsTest(false);
  }

  public void testRecordPatternIntroduced5() throws Exception {
    doTestWithLanguageLevel(LanguageLevel.HIGHEST);
  }

  public void testSuggestChangeSignatureWithChangedParameterName() throws Exception {
    configureByFile(BASE_PATH + getTestName(false) + ".java");
    boolean success = performExtractMethod(true, true, getEditor(), getFile(), getProject(), false, null, false, "p");
    assertTrue(success);
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
  }

  public void testTargetAnonymous() throws Exception {
    doTest();
  }

  public void testSimpleMethodsInOneLine() throws Exception {
    CodeStyleSettings settings = CodeStyle.getSettings(getProject());
    CommonCodeStyleSettings javaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
    javaSettings.KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
    doTest();
  }

  public void testExtractUnresolvedLambdaParameter() throws Exception {
    doTest();
  }

  public void testExtractUnresolvedLambdaExpression() throws Exception {
    doTest();
  }

  public void testNoNPE1() throws Exception {
    doTest();
  }

  public void testNoNPE2() throws Exception {
    doTest();
  }

  public void testTheOnlyParenthesisExpressionWhichIsSkippedInControlFlow() throws Exception {
    doTest();
  }

  public void testExpression() throws Exception {
    doTestWithJava17();
  }

  public void testCopyParamAnnotations() throws Exception {
    doTest();
  }

  public void testInferredNotNullInReturnStatement() throws Exception {
    doTest();
  }

  public void testSkipThrowsDeclaredInLambda() throws Exception {
    doTest();
  }

  public void testChangedReturnType() throws Exception {
    doTestReturnTypeChanged(PsiType.getJavaLangObject(getPsiManager(), GlobalSearchScope.allScope(getProject())));
  }

  public void testMakeVoidMethodReturnVariable() throws Exception {
    doTestReturnTypeChanged(PsiTypes.intType());
  }

  public void testNoReturnTypesSuggested() throws Exception {
    doTestReturnTypeChanged(PsiTypes.intType());
  }

  public void testMultipleVarsInMethodNoReturnStatementAndAssignment() throws Exception {
    //return type should not be suggested but still
    doTestReturnTypeChanged(PsiTypes.intType());
  }

  public void testReassignFinalFieldInside() throws Exception {
    doTestReturnTypeChanged(PsiTypes.intType());
  }

  public void testShortenClassRefsInNewReturnType() throws Exception {
    doTestReturnTypeChanged(PsiType.getTypeByName(CommonClassNames.JAVA_UTIL_COLLECTION, getProject(), GlobalSearchScope.allScope(getProject())));
  }

  public void testPassFieldAsParameterAndMakeStatic() throws Exception {
    doTestPassFieldsAsParams();
  }

  public void testDefaultNamesConflictResolution() throws Exception {
    final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
    settings.LOCAL_VARIABLE_NAME_PREFIX = "_";
    doTest();
  }

  public void testInferredNotNull() throws Exception {
    doTest();
  }

  public void testCantPassFieldAsParameter() {
    try {
      doTestPassFieldsAsParams();
      fail("Field was modified inside. Make static should be disabled");
    }
    catch (PrepareFailedException ignore) {
    }
  }

  public void testConditionalExitCombinedWithNullabilityShouldPreserveVarsUsedInExitStatements() throws Exception {
    doTest();
  }

  public void testSingleExitPOintWithTryFinally() throws Exception {
    doTest();
  }

  public void testLocalVariableModifierList() throws Exception {
    doTest();
  }

  public void testLocalVariableAnnotationsOrder() throws Exception {
    doTest();
  }

  public void testDifferentAnnotations() throws Exception {
    doTest();
  }

  public void testTypeUseAnnotationsOnParameter() throws Exception {
    doTest();
  }

  public void testSameAnnotations() throws Exception {
    doTest();
  }

  public void testNormalExitIf() throws Exception {
    doTest();
  }

  public void testNormalExitTry() throws Exception {
    doTest();
  }

  public void testMethodAnnotations() throws Exception {
    doTest();
  }

  public void testNotNullArgument0() throws Exception {
    doTest();
  }

  public void testNotNullArgument1() throws Exception {
    doTest();
  }

  public void testNotNullArgument2() throws Exception {
    doTest();
  }

  public void testNotNullArgument3() throws Exception {
    doTest();
  }

  public void testNotNullArgument4() throws Exception {
    doTest();
  }

  public void testNotNullArgument5() throws Exception {
    doTest();
  }

  public void testNotNullArgument6() throws Exception {
    doTest();
  }

  public void testNotNullArgument7() throws Exception {
    doTest();
  }

  public void testNotNullArgumentTooComplexCode() throws Exception {
    RegistryValue value = Registry.get("ide.dfa.state.limit");
    int oldValue = value.asInteger();
    try {
      value.setValue(50);
      doTest();
    }finally {
      value.setValue(oldValue);
    }
  }

  public void testVariableInLoopWithConditionalBreak() throws Exception {
    doTest();
  }

  public void testNotNullArgumentLambdaBare() throws Exception {
    doTest();
  }

  public void testNotNullArgumentLambdaInIf() throws Exception {
    doTest();
  }

  public void testNotNullArgumentLambdaInIfNoBlock() throws Exception {
    doTest();
  }

  public void testNotNullArgumentLambdaInWhileNoBlock() throws Exception {
    doTest();
  }

  public void testNotNullArgumentLambdaInsideBody() throws Exception {
    doTest();
  }

  public void testNotNullArgumentLambdaInIfInsideBody() throws Exception {
    doTest();
  }

  public void testNotNullArgumentAnonymousClassBare() throws Exception {
    doTest();
  }

  public void testNotNullArgumentAnonymousClassInIf() throws Exception {
    doTest();
  }

  public void testNotNullArgumentAnonymousClassInIfNoBlock() throws Exception {
    doTest();
  }

  public void testNotNullArgumentLambdaInForInitializer() throws Exception {
    doTest();
  }

  public void testEmptyParenthesis() throws Exception {
    try {
      doTest();
      fail("Should not work for empty parenthesis");
    }
    catch (PrepareFailedException ignore) {
    }
  }

  public void testQualifyWhenConflictingNamePresent() throws Exception {
    final CommonCodeStyleSettings settings = CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
    settings.ELSE_ON_NEW_LINE = true;
    settings.CATCH_ON_NEW_LINE = myCatchOnNewLine;
    configureByFile(BASE_PATH + getTestName(false) + ".java");
    final PsiClass psiClass = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getSelectionModel().getLeadSelectionOffset()), PsiClass.class);
    assertNotNull(psiClass);
    boolean success =
      performExtractMethod(true, true, getEditor(), getFile(), getProject(), false, null, false, null, psiClass.getContainingClass(), null);
    assertTrue(success);
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
  }

  public void testDontMakeParametersFinalDueToUsagesInsideAnonymous() throws Exception {
    doTest();
  }

  public void testBuilderChainWithArrayAccess() throws Exception {
    doTest();
  }

  public void testBuilderChainWithArrayAccessExpr() throws Exception {
    doTest();
  }

  public void testBuilderChainWithArrayAccessIf() throws Exception {
    doTest();
  }

  public void testBuilderChainWith2DimArrayAccess() throws Exception {
    doTest();
  }

  public void testCallOnArrayElement() throws Exception {
    doTest();
  }

  public void testCallOn2DimArrayElement() throws Exception {
    doTest();
  }

  public void testCallOnFieldArrayElement() throws Exception {
    doTest();
  }

  public void testExtractedVariableReused() throws Exception {
    doTest();
  }

  public void testExtractBareThenBranch() throws Exception {
    doTest();
  }

  public void testExtractBareElseBranch() throws Exception {
    doTest();
  }

  public void testExtractBareForBody() throws Exception {
    doTest();
  }

  public void testExtractBareDoWhileBody() throws Exception {
    doTest();
  }

  public void testExtractBracedElseBranch() throws Exception {
    doTest();
  }

  public void testExtractBracedDoWhileBody() throws Exception {
    doTest();
  }

  public void testInferredNotNullInReturnStatementDuplicate() throws Exception {
    doDuplicatesTest();
  }

  public void testNullableCheckBreakDuplicate() throws Exception {
    doDuplicatesTest();
  }

  public void testOutputVariableDuplicate() throws Exception {
    doDuplicatesTest();
  }

  public void testNullableCheckVoidDuplicate() throws Exception {
    doTest();
  }

  public void testWriteDifferentFieldsDuplicate() throws Exception {
    doDuplicatesTest();
  }

