use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class TemplateLineStartEndHandler method doExecute.
@Override
protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
if (templateState != null && !templateState.isFinished()) {
final TextRange range = templateState.getCurrentVariableRange();
final int caretOffset = editor.getCaretModel().getOffset();
if (range != null && shouldStayInsideVariable(range, caretOffset)) {
int selectionOffset = editor.getSelectionModel().getLeadSelectionOffset();
int offsetToMove = myIsHomeHandler ? range.getStartOffset() : range.getEndOffset();
LogicalPosition logicalPosition = editor.offsetToLogicalPosition(offsetToMove).leanForward(myIsHomeHandler);
editor.getCaretModel().moveToLogicalPosition(logicalPosition);
EditorModificationUtil.scrollToCaret(editor);
if (myWithSelection) {
editor.getSelectionModel().setSelection(selectionOffset, offsetToMove);
} else {
editor.getSelectionModel().removeSelection();
}
return;
}
}
myOriginalHandler.execute(editor, caret, dataContext);
}
use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class ClassNameCompletionTest method testTypeParametersTemplate.
public void testTypeParametersTemplate() throws Exception {
createClass("package pack; public interface Foo<T> {void foo(T t};");
String path = "/template";
TemplateManagerImpl.setTemplateTesting(getProject(), myFixture.getTestRootDisposable());
configureByFile(path + "/before1.java");
selectItem(myItems[0]);
TemplateState state = TemplateManagerImpl.getTemplateState(myFixture.getEditor());
type("String");
assert state != null;
state.gotoEnd(false);
checkResultByFile(path + "/after1.java");
configureByFile(path + "/before2.java");
selectItem(myItems[0]);
assert TemplateManagerImpl.getTemplateState(myFixture.getEditor()) == null;
checkResultByFile(path + "/after2.java");
}
use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class RenameLocalTest method doRenameWrongRef.
private void doRenameWrongRef(final String newName) throws Exception {
final String name = getTestName(false);
configureByFile(BASE_PATH + name + ".java");
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
new RenameWrongRefHandler().invoke(getProject(), getEditor(), getFile(), null);
final TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
assert state != null;
final TextRange range = state.getCurrentVariableRange();
assert range != null;
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
getEditor().getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), newName);
}
}.execute().throwException();
state.gotoEnd(false);
checkResultByFile(BASE_PATH + name + "_after.java");
}
use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class RenameMembersInplaceTest method testSameNamedMethodsInOneFile.
public void testSameNamedMethodsInOneFile() throws Exception {
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
final PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.getInstance().getAllAccepted());
assertNotNull(element);
Editor editor = getEditor();
Project project = editor.getProject();
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
new MemberInplaceRenameHandler().doRename(element, editor, DataManager.getInstance().getDataContext(editor.getComponent()));
TemplateState state = TemplateManagerImpl.getTemplateState(editor);
assert state != null;
assertEquals(2, state.getSegmentsCount());
final TextRange range = state.getCurrentVariableRange();
assert range != null;
final Editor finalEditor = editor;
new WriteCommandAction.Simple(project) {
@Override
protected void run() throws Throwable {
finalEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), "newDoSomething");
}
}.execute().throwException();
state = TemplateManagerImpl.getTemplateState(editor);
assert state != null;
state.gotoEnd(false);
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
use of com.intellij.codeInsight.template.impl.TemplateState in project intellij-community by JetBrains.
the class ShowIntentionsPass method doApplyInformationToEditor.
@Override
public void doApplyInformationToEditor() {
ApplicationManager.getApplication().assertIsDispatchThread();
if (!ApplicationManager.getApplication().isUnitTestMode() && !myEditor.getContentComponent().hasFocus())
return;
// do not show intentions if caret is outside visible area
LogicalPosition caretPos = myEditor.getCaretModel().getLogicalPosition();
Rectangle visibleArea = myEditor.getScrollingModel().getVisibleArea();
Point xy = myEditor.logicalPositionToXY(caretPos);
if (!visibleArea.contains(xy))
return;
TemplateState state = TemplateManagerImpl.getTemplateState(myEditor);
if (myShowBulb && (state == null || state.isFinished()) && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(false)) {
DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(myProject);
codeAnalyzer.setLastIntentionHint(myProject, myFile, myEditor, myIntentionsInfo, myHasToRecreate);
}
}
Aggregations