当前位置: 首页>>代码示例>>Java>>正文


Java InsertionContext.getEditor方法代码示例

本文整理汇总了Java中com.intellij.codeInsight.completion.InsertionContext.getEditor方法的典型用法代码示例。如果您正苦于以下问题:Java InsertionContext.getEditor方法的具体用法?Java InsertionContext.getEditor怎么用?Java InsertionContext.getEditor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.codeInsight.completion.InsertionContext的用法示例。


在下文中一共展示了InsertionContext.getEditor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  final Editor editor = context.getEditor();
  final Document document = editor.getDocument();
  if (context.getCompletionChar() == '(') {
    context.setAddCompletionChar(false);
    final int offset = context.getTailOffset();
    document.insertString(offset, "()");

    PyClass pyClass = (PyClass) item.getObject();
    PyFunction init = pyClass.findInitOrNew(true, null);
    if (init != null && PyFunctionInsertHandler.hasParams(context, init)) {
      editor.getCaretModel().moveToOffset(offset+1);
      AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), init);
    }
    else {
      editor.getCaretModel().moveToOffset(offset+2);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PyClassInsertHandler.java

示例2: handleUserSelection

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
private static void handleUserSelection(InsertionContext context, @NotNull Function<Color, String> colorToStringConverter) {
  Color myColorAtCaret = null;

  Editor selectedTextEditor = context.getEditor();
  PsiElement element = context.getFile().findElementAt(selectedTextEditor.getCaretModel().getOffset());

  if (element instanceof XmlToken) {
    myColorAtCaret = getColorFromElement(element);
  }

  context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());

  List<ColorPickerListener> listeners = ColorPickerListenerFactory.createListenersFor(element);
  Color color = ColorChooser.chooseColor(WindowManager.getInstance().suggestParentWindow(context.getProject()),
                                         XmlBundle.message("choose.color.dialog.title"), myColorAtCaret, true, listeners, true);

  if (color != null) {
    String colorString = colorToStringConverter.fun(color);
    context.getDocument().insertString(context.getStartOffset(), colorString);
    context.getEditor().getCaretModel().moveToOffset(context.getTailOffset());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:UserColorLookup.java

示例3: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
    final Editor editor = context.getEditor();
    final Project project = editor.getProject();
    if (project != null) {

        final JSGraphQLEndpointImportDeclaration[] imports = PsiTreeUtil.getChildrenOfType(context.getFile(), JSGraphQLEndpointImportDeclaration.class);

        int insertionOffset = 0;
        if(imports != null && imports.length > 0) {
            JSGraphQLEndpointImportDeclaration lastImport = imports[imports.length - 1];
            insertionOffset = lastImport.getTextRange().getEndOffset();
        }

        final String name = JSGraphQLEndpointImportUtil.getImportName(project, fileToImport);
        String importDeclaration = "import \"" + name + "\"\n";
        if(insertionOffset > 0) {
            importDeclaration = "\n" + importDeclaration;
        }
        editor.getDocument().insertString(insertionOffset, importDeclaration);
    }
}
 
开发者ID:jimkyndemeyer,项目名称:js-graphql-intellij-plugin,代码行数:22,代码来源:JSGraphQLEndpointAutoImportInsertHandler.java

示例4: handleUserSelection

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
private static void handleUserSelection(InsertionContext context, @NotNull Function<Color, String> colorToStringConverter) {
  Color myColorAtCaret = null;

  Editor selectedTextEditor = context.getEditor();
  PsiElement element = context.getFile().findElementAt(selectedTextEditor.getCaretModel().getOffset());

  if (element instanceof XmlToken) {
    myColorAtCaret = getColorFromElement(element);
  }

  context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());

  ColorPickerListener[] listeners = ColorPickerListenerFactory.createListenersFor(element);
  Color color = ColorChooser.chooseColor(WindowManager.getInstance().suggestParentWindow(context.getProject()),
                                         XmlBundle.message("choose.color.dialog.title"), myColorAtCaret, true, listeners, true);

  if (color != null) {
    String colorString = colorToStringConverter.fun(color);
    context.getDocument().insertString(context.getStartOffset(), colorString);
    context.getEditor().getCaretModel().moveToOffset(context.getTailOffset());
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:UserColorLookup.java

示例5: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext insertionContext, LookupElement item)
{
	Editor editor = insertionContext.getEditor();
	int offset = editor.getCaretModel().getOffset();
	boolean isVoidReturnType = DotNetTypeRefUtil.isVmQNameEqual(myPseudoMethod.getReturnTypeRef(), myPseudoMethod, DotNetTypes.System.Void);
	if(!isVoidReturnType)
	{
		TailType.insertChar(editor, offset, ' ');
		TailType.insertChar(editor, offset + 1, ';');
	}
	else
	{
		TailType.insertChar(editor, offset, ';');
	}

	insertionContext.getEditor().getCaretModel().moveToOffset(offset + 1);
	if(!isVoidReturnType)
	{
		AutoPopupController.getInstance(editor.getProject()).autoPopupMemberLookup(editor, null);
	}
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:23,代码来源:CSharpStatementCompletionContributor.java

示例6: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context1, LookupElement item) {
    Editor editor = context1.getEditor();

    //If they typed the element we should replace the thing they're typing with the correct case
    // Even though Torque is case-insensitive it looks bad if we don't
    PsiElement editing = context1.getFile().findElementAt(context1.getStartOffset());
    if (editing != null) {
        //Delete the element they were typing (note to only go to their carat position)
        editor.getDocument().deleteString(editing.getTextOffset(), editor.getCaretModel().getCurrentCaret().getOffset());
        //And insert the correctly cased version
        EditorModificationUtil.insertStringAtCaret(editor, item.getLookupString(), true);
    }
}
 
开发者ID:CouleeApps,项目名称:TS-IJ,代码行数:15,代码来源:TSCaseCorrectingInsertHandler.java

示例7: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
    if (element.getParent() instanceof FieldReference) {
        final Editor     editor     = context.getEditor();
        final CaretModel caretModel = editor.getCaretModel();
        final Document   document   = editor.getDocument();

        document.insertString(caretModel.getOffset(), "()");
        caretModel.moveCaretRelatively(1, 0, false, false, false);
    }
}
 
开发者ID:rentalhost,项目名称:laravel-insight,代码行数:12,代码来源:ScopeCompletionContributor.java

示例8: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  Editor editor = context.getEditor();
  Project project = editor.getProject();

  if (project != null) {
    EditorModificationUtil.insertStringAtCaret(
        editor, closingTagBeforeCaret + closingTagAfterCaret);
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    EditorModificationUtil.moveCaretRelatively(editor, -closingTagAfterCaret.length());
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:12,代码来源:PostfixInsertHandler.java

示例9: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
    final Editor editor = context.getEditor();
    final Document document = editor.getDocument();
    context.commitDocument();
    document.insertString(context.getTailOffset(), "} ");
    
    editor.getCaretModel().moveToOffset(context.getSelectionEndOffset());
}
 
开发者ID:SlalomConsulting,项目名称:sutr-io,代码行数:10,代码来源:SlotLookupElement.java

示例10: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
  LookupElement item = getDelegate();
  Project project = context.getProject();
  Editor editor = context.getEditor();

  PsiDocumentManager.getInstance(project).commitAllDocuments();

  TextRange range = myState.getCurrentVariableRange();
  final TemplateLookupSelectionHandler handler = item.getUserData(TemplateLookupSelectionHandler.KEY_IN_LOOKUP_ITEM);
  if (handler != null && range != null) {
    handler.itemSelected(item, context.getFile(), context.getDocument(), range.getStartOffset(), range.getEndOffset());
  }
  else {
    super.handleInsert(context);
  }

  if (context.getCompletionChar() == '.') {
    EditorModificationUtil.insertStringAtCaret(editor, ".");
    AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    return;
  }

  if (!myState.isFinished()) {
    myState.calcResults(true);
  }

  myState.nextTab();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:TemplateExpressionLookupElement.java

示例11: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  final Editor editor = context.getEditor();
  final Document document = editor.getDocument();
  int tailOffset = context.getTailOffset();
  document.insertString(tailOffset, IMPORT_KWD);
  editor.getCaretModel().moveToOffset(tailOffset + IMPORT_KWD.length());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:PyImportReference.java

示例12: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, LookupElement item) {
  final PsiClassType.ClassResolveResult resolveResult = myClassType.resolveGenerics();
  final PsiClass psiClass = resolveResult.getElement();
  if (psiClass == null || !psiClass.isValid()) {
    return;
  }

  GroovyPsiElement place =
    PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GroovyPsiElement.class, false);
  boolean hasParams = place != null && GroovyCompletionUtil.hasConstructorParameters(psiClass, place);
  if (myTriggerFeature) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW);
  }

  if (hasParams) {
    ParenthesesInsertHandler.WITH_PARAMETERS.handleInsert(context, item);
  }
  else {
    ParenthesesInsertHandler.NO_PARAMETERS.handleInsert(context, item);
  }

  shortenRefsInGenerics(context);
  if (hasParams) {
    AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null);
  }

  PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument());

  if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
    final Editor editor = context.getEditor();
    final int offset = context.getTailOffset();
    editor.getDocument().insertString(offset, " {}");
    editor.getCaretModel().moveToOffset(offset + 2);

    context.setLaterRunnable(generateAnonymousBody(editor, context.getFile()));

  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:AfterNewClassInsertHandler.java

示例13: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement element)
{
	Editor editor = context.getEditor();
	CaretModel caretModel = editor.getCaretModel();
	Document document = context.getEditor().getDocument();
	PhpFile file = (PhpFile) context.getFile();

	PsiElement currElement = file.findElementAt(editor.getCaretModel().getOffset());

	StringBuilder buffer = new StringBuilder();
	int newOffset = caretModel.getOffset();
	if (insertSpace) {
		buffer.append(' ');
		newOffset++;
	}

	PsiElement testElement = currElement;
	if (testElement!= null && !(testElement.getNode().getElementType().equals(PhpDocPropertyTagParser.DOC_WHITESPACE))) {
		testElement = testElement.getNextSibling();
	}

	if (testElement != null && !(testElement.getNode().getElementType().equals(PhpDocPropertyTagParser.DOC_RBRACE))) {
		buffer.append('}');
	}

	document.insertString(caretModel.getOffset(), buffer.toString());
	caretModel.moveToOffset(newOffset);
}
 
开发者ID:nextras,项目名称:orm-intellij,代码行数:30,代码来源:ModifierInsertHandler.java

示例14: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  final Editor editor = context.getEditor();
  final Project project = editor.getProject();
  if (project != null) {
    EditorModificationUtil.insertStringAtCaret(editor, " \"\"");
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 1);
    if (myTriggerAutoPopup) {
      AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    }
  }
}
 
开发者ID:jimkyndemeyer,项目名称:js-graphql-intellij-plugin,代码行数:13,代码来源:JSGraphQLEndpointImportInsertHandler.java

示例15: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
  LookupElement item = getDelegate();
  Project project = context.getProject();
  Editor editor = context.getEditor();

  PsiDocumentManager.getInstance(project).commitAllDocuments();

  TextRange range = myState.getCurrentVariableRange();
  final TemplateLookupSelectionHandler handler =
    item instanceof LookupItem ? ((LookupItem<?>)item).getAttribute(TemplateLookupSelectionHandler.KEY_IN_LOOKUP_ITEM) : null;
  if (handler != null && range != null) {
    handler.itemSelected(item, context.getFile(), context.getDocument(), range.getStartOffset(), range.getEndOffset());
  }
  else {
    super.handleInsert(context);
  }

  if (context.getCompletionChar() == '.') {
    EditorModificationUtil.insertStringAtCaret(editor, ".");
    AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    return;
  }

  if (!myState.isFinished()) {
    myState.calcResults(true);
  }

  myState.nextTab();
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:31,代码来源:TemplateExpressionLookupElement.java


注:本文中的com.intellij.codeInsight.completion.InsertionContext.getEditor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。