Search in sources :

Example 1 with IntroduceHandler

use of com.jetbrains.python.refactoring.introduce.IntroduceHandler in project intellij-community by JetBrains.

the class PyIntroduceTestCase method doTestInplace.

protected void doTestInplace(@Nullable Consumer<IntroduceOperation> customization) {
    String name = getTestName(true);
    myFixture.configureByFile(name + ".py");
    final boolean enabled = myFixture.getEditor().getSettings().isVariableInplaceRenameEnabled();
    try {
        TemplateManagerImpl.setTemplateTesting(myFixture.getProject(), myFixture.getTestRootDisposable());
        myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(true);
        IntroduceHandler handler = createHandler();
        final IntroduceOperation introduceOperation = new IntroduceOperation(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile(), "a");
        introduceOperation.setReplaceAll(true);
        if (customization != null) {
            customization.consume(introduceOperation);
        }
        handler.performAction(introduceOperation);
        WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> {
            TemplateState state = TemplateManagerImpl.getTemplateState(myFixture.getEditor());
            assert state != null;
            state.gotoEnd(false);
        });
        myFixture.checkResultByFile(name + ".after.py", true);
    } finally {
        myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(enabled);
    }
}
Also used : IntroduceHandler(com.jetbrains.python.refactoring.introduce.IntroduceHandler) IntroduceOperation(com.jetbrains.python.refactoring.introduce.IntroduceOperation) TemplateState(com.intellij.codeInsight.template.impl.TemplateState)

Example 2 with IntroduceHandler

use of com.jetbrains.python.refactoring.introduce.IntroduceHandler in project intellij-community by JetBrains.

the class PyIntroduceVariableTest method testMultiReference.

// PY-10964
public void testMultiReference() {
    myFixture.configureByFile(getTestName(true) + ".py");
    boolean inplaceEnabled = myFixture.getEditor().getSettings().isVariableInplaceRenameEnabled();
    try {
        myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(true);
        IntroduceHandler handler = createHandler();
        final IntroduceOperation operation = new IntroduceOperation(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile(), "a_");
        operation.setReplaceAll(true);
        handler.performAction(operation);
        myFixture.checkResultByFile(getTestName(true) + ".after.py");
    } finally {
        myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(inplaceEnabled);
    }
}
Also used : IntroduceHandler(com.jetbrains.python.refactoring.introduce.IntroduceHandler) IntroduceOperation(com.jetbrains.python.refactoring.introduce.IntroduceOperation)

Example 3 with IntroduceHandler

use of com.jetbrains.python.refactoring.introduce.IntroduceHandler in project intellij-community by JetBrains.

the class PyIntroduceTestCase method doTest.

protected void doTest(@Nullable Consumer<IntroduceOperation> customization) {
    myFixture.configureByFile(getTestName(true) + ".py");
    boolean inplaceEnabled = myFixture.getEditor().getSettings().isVariableInplaceRenameEnabled();
    try {
        myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(false);
        IntroduceHandler handler = createHandler();
        final IntroduceOperation operation = new IntroduceOperation(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile(), "a");
        operation.setReplaceAll(true);
        if (customization != null) {
            customization.consume(operation);
        }
        handler.performAction(operation);
        myFixture.checkResultByFile(getTestName(true) + ".after.py");
    } finally {
        myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(inplaceEnabled);
    }
}
Also used : IntroduceHandler(com.jetbrains.python.refactoring.introduce.IntroduceHandler) IntroduceOperation(com.jetbrains.python.refactoring.introduce.IntroduceOperation)

Example 4 with IntroduceHandler

use of com.jetbrains.python.refactoring.introduce.IntroduceHandler in project intellij-community by JetBrains.

the class PyIntroduceTestCase method buildSuggestions.

protected Collection<String> buildSuggestions(Class<? extends PyExpression> parentClass) {
    myFixture.configureByFile(getTestName(true) + ".py");
    final IntroduceHandler handler = createHandler();
    final PyExpression expr = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getCaretOffset()), parentClass);
    assertNotNull(expr);
    return handler.getSuggestedNames(expr);
}
Also used : PyExpression(com.jetbrains.python.psi.PyExpression) IntroduceHandler(com.jetbrains.python.refactoring.introduce.IntroduceHandler)

Aggregations

IntroduceHandler (com.jetbrains.python.refactoring.introduce.IntroduceHandler)4 IntroduceOperation (com.jetbrains.python.refactoring.introduce.IntroduceOperation)3 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)1 PyExpression (com.jetbrains.python.psi.PyExpression)1