Search in sources :

Example 1 with ExtractMethodObjectProcessor

use of com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor in project intellij-community by JetBrains.

the class ExtractMethodObjectTest method doTest.

private void doTest(final boolean createInnerClass) throws Exception {
    final String testName = getTestName(false);
    configureByFile("/refactoring/extractMethodObject/" + testName + ".java");
    PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
    assertTrue(element instanceof PsiMethod);
    final PsiMethod method = (PsiMethod) element;
    final ExtractMethodObjectProcessor processor = new ExtractMethodObjectProcessor(getProject(), getEditor(), method.getBody().getStatements(), "InnerClass");
    final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = processor.getExtractProcessor();
    processor.setCreateInnerClass(createInnerClass);
    extractProcessor.setShowErrorDialogs(false);
    extractProcessor.prepare();
    extractProcessor.testPrepare();
    ExtractMethodObjectHandler.run(getProject(), getEditor(), processor, extractProcessor);
    checkResultByFile("/refactoring/extractMethodObject/" + testName + ".java" + ".after");
}
Also used : ExtractMethodObjectProcessor(com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor) PsiMethod(com.intellij.psi.PsiMethod) PsiElement(com.intellij.psi.PsiElement)

Example 2 with ExtractMethodObjectProcessor

use of com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor in project intellij-community by JetBrains.

the class ExtractMethodObjectWithMultipleExitPointsTest method doTest.

private void doTest(final boolean createInnerClass) throws Exception {
    final String testName = getTestName(false);
    configureByFile("/refactoring/extractMethodObject/multipleExitPoints/" + testName + ".java");
    int startOffset = myEditor.getSelectionModel().getSelectionStart();
    int endOffset = myEditor.getSelectionModel().getSelectionEnd();
    final PsiElement[] elements;
    PsiExpression expr = CodeInsightUtil.findExpressionInRange(myFile, startOffset, endOffset);
    if (expr != null) {
        elements = new PsiElement[] { expr };
    } else {
        elements = CodeInsightUtil.findStatementsInRange(myFile, startOffset, endOffset);
    }
    final ExtractMethodObjectProcessor processor = new ExtractMethodObjectProcessor(getProject(), getEditor(), elements, "Inner");
    final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = processor.getExtractProcessor();
    extractProcessor.setShowErrorDialogs(false);
    extractProcessor.prepare();
    extractProcessor.testPrepare();
    processor.setCreateInnerClass(createInnerClass);
    ExtractMethodObjectHandler.run(getProject(), getEditor(), processor, extractProcessor);
    checkResultByFile("/refactoring/extractMethodObject/multipleExitPoints/" + testName + ".java" + ".after");
}
Also used : ExtractMethodObjectProcessor(com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor) PsiExpression(com.intellij.psi.PsiExpression) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 ExtractMethodObjectProcessor (com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor)2 PsiExpression (com.intellij.psi.PsiExpression)1 PsiMethod (com.intellij.psi.PsiMethod)1