use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class InplaceIntroduceParameterTest method testLocalInsideAnonymous1.
public void testLocalInsideAnonymous1() throws Exception {
final Pass<AbstractInplaceIntroducer> pass = new Pass<AbstractInplaceIntroducer>() {
@Override
public void pass(AbstractInplaceIntroducer inplaceIntroducePopup) {
}
};
String name = getTestName(true);
configureByFile(getBasePath() + name + getExtension());
final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled();
try {
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
getEditor().getSettings().setVariableInplaceRenameEnabled(true);
//ensure extract local var
final MyIntroduceHandler introduceHandler = createIntroduceHandler();
introduceHandler.invokeImpl(LightPlatformTestCase.getProject(), getLocalVariableFromEditor(), getEditor());
final AbstractInplaceIntroducer introducer = introduceHandler.getInplaceIntroducer();
pass.pass(introducer);
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
assert state != null;
state.gotoEnd(false);
checkResultByFile(getBasePath() + name + "_after" + getExtension());
} finally {
getEditor().getSettings().setVariableInplaceRenameEnabled(enabled);
}
}
use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class InplaceIntroduceVariableTest method doTestReplaceChoice.
private void doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice choice, Pass<AbstractInplaceIntroducer> pass) {
String name = getTestName(true);
configureByFile(getBasePath() + name + getExtension());
final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled();
try {
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
getEditor().getSettings().setVariableInplaceRenameEnabled(true);
MyIntroduceHandler handler = createIntroduceHandler();
((MyIntroduceVariableHandler) handler).setChoice(choice);
final AbstractInplaceIntroducer introducer = invokeRefactoring(handler);
if (pass != null) {
pass.pass(introducer);
}
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
assert state != null;
state.gotoEnd(false);
checkResultByFile(getBasePath() + name + "_after" + getExtension());
} finally {
getEditor().getSettings().setVariableInplaceRenameEnabled(enabled);
}
}
use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class InplaceIntroduceVariableTest method doTestStopEditing.
private void doTestStopEditing(Pass<AbstractInplaceIntroducer> pass) {
String name = getTestName(true);
configureByFile(getBasePath() + name + getExtension());
final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled();
try {
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
getEditor().getSettings().setVariableInplaceRenameEnabled(true);
final AbstractInplaceIntroducer introducer = invokeRefactoring();
pass.pass(introducer);
checkResultByFile(getBasePath() + name + "_after" + getExtension());
} finally {
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
if (state != null) {
state.gotoEnd(true);
}
getEditor().getSettings().setVariableInplaceRenameEnabled(enabled);
}
}
use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class AbstractInplaceIntroducer method stopIntroduce.
public void stopIntroduce(Editor editor) {
final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
if (templateState != null) {
final Runnable runnable = () -> templateState.gotoEnd(true);
CommandProcessor.getInstance().executeCommand(myProject, runnable, getCommandName(), getCommandName());
}
}
use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class AbstractInplaceIntroducer method startInplaceIntroduceTemplate.
/**
* Begins the in-place refactoring operation.
*
* @return true if the in-place refactoring was successfully started, false if it failed to start and a dialog should be shown instead.
*/
public boolean startInplaceIntroduceTemplate() {
final boolean replaceAllOccurrences = isReplaceAllOccurrences();
final Ref<Boolean> result = new Ref<>();
CommandProcessor.getInstance().executeCommand(myProject, () -> {
final String[] names = suggestNames(replaceAllOccurrences, getLocalVariable());
final V variable = createFieldToStartTemplateOn(replaceAllOccurrences, names);
boolean started = false;
if (variable != null) {
int caretOffset = getCaretOffset();
myEditor.getCaretModel().moveToOffset(caretOffset);
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final LinkedHashSet<String> nameSuggestions = new LinkedHashSet<>();
nameSuggestions.add(variable.getName());
nameSuggestions.addAll(Arrays.asList(names));
initOccurrencesMarkers();
setElementToRename(variable);
updateTitle(getVariable());
started = super.performInplaceRefactoring(nameSuggestions);
if (started) {
onRenameTemplateStarted();
myDocumentAdapter = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
if (myPreview == null)
return;
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
if (templateState != null) {
final TextResult value = templateState.getVariableValue(InplaceRefactoring.PRIMARY_VARIABLE_NAME);
if (value != null) {
updateTitle(getVariable(), value.getText());
}
}
}
};
myEditor.getDocument().addDocumentListener(myDocumentAdapter);
updateTitle(getVariable());
if (TemplateManagerImpl.getTemplateState(myEditor) != null) {
myEditor.putUserData(ACTIVE_INTRODUCE, this);
}
}
}
result.set(started);
if (!started) {
finish(true);
}
}, getCommandName(), getCommandName());
return result.get();
}
Aggregations