本文整理汇总了Java中com.intellij.codeInsight.template.impl.TemplateState类的典型用法代码示例。如果您正苦于以下问题:Java TemplateState类的具体用法?Java TemplateState怎么用?Java TemplateState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TemplateState类属于com.intellij.codeInsight.template.impl包,在下文中一共展示了TemplateState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testSingleExpressionTemplate
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
public void testSingleExpressionTemplate() {
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
myFixture.configureByFile(getTestName(true) + ".java");
myFixture.type('\t');
TemplateState templateState = TemplateManagerImpl.getTemplateState(myFixture.getEditor());
assertNotNull(templateState);
assertFalse(templateState.isFinished());
myFixture.type("Integer");
templateState.nextTab();
assertTrue(templateState.isFinished());
myFixture.checkResultByFile(getTestName(true) + "_after.java", true);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:InstanceofPostfixTemplateTest.java
示例2: doTestStopEditing
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
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);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:InplaceIntroduceVariableTest.java
示例3: doApplyInformationToEditor
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@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);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ShowIntentionsPass.java
示例4: execute
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void execute(Editor editor, 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 && range.getStartOffset() <= caretOffset && caretOffset <= range.getEndOffset()) {
int offsetToMove = myIsHomeHandler ? range.getStartOffset() : range.getEndOffset();
if (offsetToMove != caretOffset) {
editor.getCaretModel().moveToOffset(offsetToMove);
}
editor.getSelectionModel().removeSelection();
} else {
myOriginalHandler.execute(editor, dataContext);
}
} else {
myOriginalHandler.execute(editor, dataContext);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:HomeEndHandler.java
示例5: highlightTemplateVariables
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
private void highlightTemplateVariables(Template template, Editor topLevelEditor) {
//add highlights
if (myHighlighters != null) { // can be null if finish is called during testing
Map<TextRange, TextAttributes> rangesToHighlight = new HashMap<TextRange, TextAttributes>();
final TemplateState templateState = TemplateManagerImpl.getTemplateState(topLevelEditor);
if (templateState != null) {
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
for (int i = 0; i < templateState.getSegmentsCount(); i++) {
final TextRange segmentOffset = templateState.getSegmentRange(i);
final String name = template.getSegmentName(i);
TextAttributes attributes = null;
if (name.equals(PRIMARY_VARIABLE_NAME)) {
attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
}
else if (name.equals(OTHER_VARIABLE_NAME)) {
attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
}
if (attributes == null) continue;
rangesToHighlight.put(segmentOffset, attributes);
}
}
addHighlights(rangesToHighlight, topLevelEditor, myHighlighters, HighlightManager.getInstance(myProject));
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:InplaceRefactoring.java
示例6: beforeTemplateFinished
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void beforeTemplateFinished(final TemplateState templateState, Template template) {
try {
final TextResult value = templateState.getVariableValue(PRIMARY_VARIABLE_NAME);
myInsertedName = value != null ? value.toString() : null;
TextRange range = templateState.getCurrentVariableRange();
final int currentOffset = myEditor.getCaretModel().getOffset();
if (range == null && myRenameOffset != null) {
range = new TextRange(myRenameOffset.getStartOffset(), myRenameOffset.getEndOffset());
}
myBeforeRevert =
range != null && range.getEndOffset() >= currentOffset && range.getStartOffset() <= currentOffset
? myEditor.getDocument().createRangeMarker(range.getStartOffset(), currentOffset)
: null;
if (myBeforeRevert != null) {
myBeforeRevert.setGreedyToRight(true);
}
finish(true);
}
finally {
restoreDaemonUpdateState();
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:InplaceRefactoring.java
示例7: execute
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void execute(Editor editor, DataContext dataContext) {
final SelectionModel selectionModel = editor.getSelectionModel();
if (selectionModel.hasSelection()) {
final TemplateState state = TemplateManagerImpl.getTemplateState(editor);
if (state != null && editor.getUserData(InplaceRefactoring.INPLACE_RENAMER) != null) {
final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
if (lookup != null) {
selectionModel.removeSelection();
lookup.hideLookup(true);
return;
}
}
}
myOriginalHandler.execute(editor, dataContext);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:EscapeHandler.java
示例8: finish
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void finish(boolean success) {
myFinished = true;
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
if (templateState != null) {
myEditor.putUserData(ACTIVE_INTRODUCE, null);
}
if (myDocumentAdapter != null) {
myEditor.getDocument().removeDocumentListener(myDocumentAdapter);
}
if (myBalloon == null) {
releaseIfNotRestart();
}
super.finish(success);
if (success) {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
final V variable = getVariable();
if (variable == null) {
return;
}
restoreState(variable);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:AbstractInplaceIntroducer.java
示例9: execute
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void execute(Editor editor, DataContext dataContext) {
final SelectionModel selectionModel = editor.getSelectionModel();
if (selectionModel.hasSelection()) {
final TemplateState state = TemplateManagerImpl.getTemplateState(editor);
if (state != null && editor.getUserData(InplaceRefactoring.INPLACE_RENAMER) != null) {
final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
if (lookup != null) {
selectionModel.removeSelection();
lookup.hide();
return;
}
}
}
myOriginalHandler.execute(editor, dataContext);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:EscapeHandler.java
示例10: format
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
public void format(PsiFile psiFile, int startOffset, int endOffset) throws FileDoesNotExistsException {
LOG.debug("#format " + startOffset + "-" + endOffset);
boolean wholeFile = FileUtils.isWholeFile(startOffset, endOffset, psiFile.getText());
Range range = new Range(startOffset, endOffset, wholeFile);
final Editor editor = PsiUtilBase.findEditor(psiFile);
if (editor != null) {
TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
if (templateState != null && !settings.isUseForLiveTemplates()) {
throw new ReformatItInIntelliJ();
}
formatWhenEditorIsOpen(editor, range, psiFile);
} else {
formatWhenEditorIsClosed(range, psiFile);
}
}
开发者ID:krasa,项目名称:EclipseCodeFormatter,代码行数:18,代码来源:EclipseCodeFormatter.java
示例11: doExecute
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@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);
}
开发者ID:consulo,项目名称:consulo,代码行数:24,代码来源:TemplateLineStartEndHandler.java
示例12: execute
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void execute(Editor editor, DataContext dataContext) {
TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
if (templateState != null && !templateState.isFinished()) {
SelectionModel selectionModel = editor.getSelectionModel();
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
// the idea behind lookup checking is that if there is a preselected value in lookup
// then user might want just to close lookup but not finish a template.
// E.g. user wants to move to the next template segment by Tab without completion invocation.
// If there is no selected value in completion that user definitely wants to finish template
boolean lookupIsEmpty = lookup == null || lookup.getCurrentItem() == null;
if (!selectionModel.hasSelection() && lookupIsEmpty) {
CommandProcessor.getInstance().setCurrentCommandName(CodeInsightBundle.message("finish.template.command"));
templateState.gotoEnd(true);
return;
}
}
if (myOriginalHandler.isEnabled(editor, dataContext)) {
myOriginalHandler.execute(editor, dataContext);
}
}
开发者ID:consulo,项目名称:consulo,代码行数:24,代码来源:EscapeHandler.java
示例13: finishTemplate
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
private static void finishTemplate(Editor editor) {
final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
final InplaceRefactoring renamer = editor.getUserData(InplaceRefactoring.INPLACE_RENAMER);
if (templateState != null && renamer != null) {
templateState.gotoEnd(true);
editor.putUserData(InplaceRefactoring.INPLACE_RENAMER, null);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:ReassignVariableUtil.java
示例14: doTestWithTemplateFinish
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
private void doTestWithTemplateFinish(@NotNull String fileName, Surrounder surrounder, @Nullable String textToType) {
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
configureByFile(BASE_PATH + fileName + ".java");
SurroundWithHandler.invoke(getProject(), getEditor(), getFile(), surrounder);
if (textToType != null) {
type(textToType);
}
TemplateState templateState = TemplateManagerImpl.getTemplateState(getEditor());
assertNotNull(templateState);
templateState.nextTab();
checkResultByFile(BASE_PATH + fileName + "_after.java");
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:JavaSurroundWithTest.java
示例15: testValueTyping
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
public void testValueTyping() {
configureByFile(getBasePath() + "/beforeValueTyping.java");
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
doAction("Add missing annotation parameters - value3, value2, value1");
final TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
assertNotNull(state);
type("\"value33\"");
state.nextTab();
type("\"value22\"");
state.nextTab();
type("\"value11\"");
state.nextTab();
assertTrue(state.isFinished());
checkResultByFile(getBasePath() + "/afterValueTyping.java");
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:AddMissingRequiredAnnotationParametersTest.java
示例16: doCollectInformation
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void doCollectInformation(@NotNull ProgressIndicator progress) {
if (!ApplicationManager.getApplication().isUnitTestMode() && !myEditor.getContentComponent().hasFocus()) return;
TemplateState state = TemplateManagerImpl.getTemplateState(myEditor);
if (state != null && !state.isFinished()) return;
DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject);
getIntentionActionsToShow();
updateActions(codeAnalyzer);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ShowIntentionsPass.java
示例17: considerNextTab
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
private static void considerNextTab(Editor editor) {
TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
if (templateState != null) {
TextRange range = templateState.getCurrentVariableRange();
if (range != null && range.getLength() > 0) {
int caret = editor.getCaretModel().getOffset();
if (caret == range.getEndOffset()) {
templateState.nextTab();
}
else if (caret > range.getEndOffset()) {
templateState.gotoEnd(true);
}
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:BaseCompleteMacro.java
示例18: execute
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void execute(Editor editor, 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 && range.getStartOffset() <= caretOffset && caretOffset <= range.getEndOffset()) {
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
return;
}
}
myOriginalHandler.execute(editor, dataContext);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:SelectAllHandler.java
示例19: execute
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void execute(Editor editor, 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 && range.getStartOffset() <= caretOffset && caretOffset <= range.getEndOffset()) {
int offsetToMove = myIsHomeHandler ? range.getStartOffset() : range.getEndOffset();
editor.getCaretModel().moveToOffset(offsetToMove);
editor.getSelectionModel().setSelection(myIsHomeHandler ? offsetToMove : caretOffset, myIsHomeHandler ? caretOffset : offsetToMove);
return;
}
}
myOriginalHandler.execute(editor, dataContext);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:LineStartEndWithSelectionHandler.java
示例20: execute
import com.intellij.codeInsight.template.impl.TemplateState; //导入依赖的package包/类
@Override
public void execute(Editor editor, DataContext dataContext) {
if (!editor.getSelectionModel().hasSelection()) { //remove selection has higher precedence over finishing template editing
final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
if (templateState != null && !templateState.isFinished()) {
CommandProcessor.getInstance().setCurrentCommandName(CodeInsightBundle.message("finish.template.command"));
templateState.gotoEnd(true);
return;
}
}
myOriginalHandler.execute(editor, dataContext);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:EscapeHandler.java
注:本文中的com.intellij.codeInsight.template.impl.TemplateState类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论