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


Java CodeInsightUtilBase.prepareEditorForWrite方法代码示例

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


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

示例1: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  PsiMethod method = canInsertSuper(project, editor, file);
  try {
    PsiMethod template = (PsiMethod)method.copy();

    OverrideImplementUtil.setupMethodBody(template, method, method.getContainingClass());
    PsiStatement superCall = template.getBody().getStatements()[0];
    PsiCodeBlock body = method.getBody();
    PsiElement toGo;
    if (body.getLBrace() == null) {
      toGo = body.addBefore(superCall, null);
    }
    else {
      toGo = body.addAfter(superCall, body.getLBrace());
    }
    toGo = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(toGo);
    editor.getCaretModel().moveToOffset(toGo.getTextOffset());
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GenerateSuperMethodCallHandler.java

示例2: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
    return;
  }
  final PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, false);
  if (aClass == null || aClass.isInterface()) return; //?
  LOG.assertTrue(aClass.isValid());
  LOG.assertTrue(aClass.getContainingFile() != null);

  try {
    final ClassMember[] members = chooseOriginalMembers(aClass, project, editor);
    if (members == null) return;

    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        doGenerate(project, editor, aClass, members);
      }
    });
  }
  finally {
    cleanup();
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:GenerateMembersHandlerBase.java

示例3: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  PsiMethod method = canInsertSuper(project, editor, file);
  try {
    PsiMethod template = (PsiMethod)method.copy();

    OverrideImplementUtil.setupMethodBody(template, method, method.getContainingClass());
    PsiStatement superCall = template.getBody().getStatements()[0];
    PsiCodeBlock body = method.getBody();
    PsiElement toGo;
    if (body.getLBrace() == null) {
      toGo = body.addBefore(superCall, null);
    }
    else {
      toGo = body.addAfter(superCall, body.getLBrace());
    }
    toGo = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(toGo);
    editor.getCaretModel().moveToOffset(toGo.getTextOffset());
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:26,代码来源:GenerateSuperMethodCallHandler.java

示例4: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
public static void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file, Surrounder surrounder) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (file instanceof PsiCompiledElement) {
    HintManager.getInstance().showErrorHint(editor, "Can't modify decompiled code");
    return;
  }

  List<AnAction> applicable = buildSurroundActions(project, editor, file, surrounder);
  if (applicable != null) {
    showPopup(editor, applicable);
  }
  else if (!ApplicationManager.getApplication().isUnitTestMode()) {
    HintManager.getInstance().showErrorHint(editor, "Couldn't find Surround With variants applicable to the current context");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:SurroundWithHandler.java

示例5: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
    return;
  }

  Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.IMPLEMENT_METHOD.forLanguage(language);
  if (codeInsightActionHandler != null) {
    codeInsightActionHandler.invoke(project, editor, file);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ImplementMethodsHandler.java

示例6: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
    return;
  }

  Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.DELEGATE_METHODS.forLanguage(language);
  if (codeInsightActionHandler != null) {
    codeInsightActionHandler.invoke(project, editor, file);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:DelegateMethodsHandler.java

示例7: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
    return;
  }

  Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.OVERRIDE_METHOD.forLanguage(language);
  if (codeInsightActionHandler != null) {
    codeInsightActionHandler.invoke(project, editor, file);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:OverrideMethodsHandler.java

示例8: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  PsiDocumentManager.getInstance(project).commitAllDocuments();

  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
    return;
  }

  EmacsProcessingHandler emacsProcessingHandler = LanguageEmacsExtension.INSTANCE.forLanguage(file.getLanguage());
  if (emacsProcessingHandler != null) {
    EmacsProcessingHandler.Result result = emacsProcessingHandler.changeIndent(project, editor, file);
    if (result == EmacsProcessingHandler.Result.STOP) {
      return;
    }
  }

  final Document document = editor.getDocument();
  final int startOffset = editor.getCaretModel().getOffset();
  final int line = editor.offsetToLogicalPosition(startOffset).line;
  final int lineStart = document.getLineStartOffset(line);
  try{
    final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
    final int newPos = codeStyleManager.adjustLineIndent(file, lineStart);
    if (editor.getCaretModel().getOffset() < newPos) {
      editor.getCaretModel().moveToOffset(newPos);
      editor.getSelectionModel().removeSelection();
      editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    }
  }
  catch(IncorrectOperationException e){
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:EmacsStyleIndentAction.java

示例9: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
    return;
  }
  EditorUtil.fillVirtualSpaceUntilCaret(editor);

  PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
  int offset = editor.getCaretModel().getOffset();
  List<TemplateImpl> applicableTemplates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, false);

  Map<TemplateImpl, String> matchingTemplates = filterTemplatesByPrefix(applicableTemplates, editor, offset, false, true);
  MultiMap<String, CustomLiveTemplateLookupElement> customTemplatesLookupElements = getCustomTemplatesLookupItems(editor, file, offset);

  if (matchingTemplates.isEmpty()) {
    for (TemplateImpl template : applicableTemplates) {
      matchingTemplates.put(template, null);
    }
  }

  if (matchingTemplates.isEmpty() && customTemplatesLookupElements.isEmpty()) {
    HintManager.getInstance().showErrorHint(editor, CodeInsightBundle.message("templates.no.defined"));
    return;
  }

  showTemplatesLookup(project, editor, file, matchingTemplates, customTemplatesLookupElements);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:ListTemplatesHandler.java

示例10: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  DefaultActionGroup group = createActionGroup(project, editor, file);
  if (group == null) return;

  final ListPopup popup = JBPopupFactory.getInstance()
    .createActionGroupPopup(CodeInsightBundle.message("templates.select.template.chooser.title"), group,
                            DataManager.getInstance().getDataContext(editor.getContentComponent()),
                            JBPopupFactory.ActionSelectionAid.MNEMONICS, false);

  popup.showInBestPositionFor(editor);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:SurroundWithTemplateHandler.java

示例11: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, true);
  if (aClass instanceof GrTypeDefinition) {
    GrTypeDefinition typeDefinition = (GrTypeDefinition)aClass;
    if (GroovyOverrideImplementExploreUtil.getMethodSignaturesToImplement(typeDefinition).isEmpty()) {
      HintManager.getInstance().showErrorHint(editor, "No methods to implement have been found");
      return;
    }

    GroovyOverrideImplementUtil.chooseAndImplementMethods(project, editor, typeDefinition);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:GroovyImplementMethodsHandler.java

示例12: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, true);
  if (aClass instanceof GrTypeDefinition) {
    GrTypeDefinition typeDefinition = (GrTypeDefinition)aClass;

    if (GroovyOverrideImplementExploreUtil.getMethodSignaturesToOverride(typeDefinition).isEmpty()) {
      HintManager.getInstance().showErrorHint(editor, "No methods to override have been found");
      return;
    }

    GroovyOverrideImplementUtil.chooseAndOverrideMethods(project, editor, typeDefinition);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:GroovyOverrideMethodsHandler.java

示例13: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
    return;
  }

  Language language = PsiUtilBase.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.IMPLEMENT_METHOD.forLanguage(language);
  if (codeInsightActionHandler != null) {
    codeInsightActionHandler.invoke(project, editor, file);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:14,代码来源:ImplementMethodsHandler.java

示例14: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
    return;
  }

  Language language = PsiUtilBase.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.DELEGATE_METHODS.forLanguage(language);
  if (codeInsightActionHandler != null) {
    codeInsightActionHandler.invoke(project, editor, file);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:14,代码来源:DelegateMethodsHandler.java

示例15: invoke

import com.intellij.codeInsight.CodeInsightUtilBase; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
    return;
  }

  Language language = PsiUtilBase.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.OVERRIDE_METHOD.forLanguage(language);
  if (codeInsightActionHandler != null) {
    codeInsightActionHandler.invoke(project, editor, file);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:14,代码来源:OverrideMethodsHandler.java


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