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


Java CodeInsightUtilCore类代码示例

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


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

示例1: surroundExpression

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
public TextRange surroundExpression(Project project, Editor editor, PsiExpression expr) throws IncorrectOperationException {
    PsiManager manager = expr.getManager();
    PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);

    @NonNls String text = "if(a){\nst;\n}elseif(){else{\n}";
    PsiIfStatement ifStatement = (PsiIfStatement)factory.createStatementFromText(text, null);
    ifStatement = (PsiIfStatement)codeStyleManager.reformat(ifStatement);

    ifStatement.getCondition().replace(expr);

    PsiExpressionStatement statement = (PsiExpressionStatement)expr.getParent();
    ifStatement = (PsiIfStatement)statement.replace(ifStatement);

    PsiCodeBlock block = ((PsiBlockStatement)ifStatement.getThenBranch()).getCodeBlock();

    PsiStatement afterStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(block.getStatements()[0]);

    TextRange range = afterStatement.getTextRange();
    editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
    return new TextRange(range.getStartOffset(), range.getStartOffset());
}
 
开发者ID:cesards,项目名称:HakunaMatataIntelliJPlugin,代码行数:24,代码来源:JavaWithIfElseIfExpressionSurrounder.java

示例2: surroundExpression

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
public TextRange surroundExpression(Project project, Editor editor, PsiExpression expr) throws IncorrectOperationException {
  PsiManager manager = expr.getManager();
  PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);

  @NonNls String text = "if(a){\nst;\n}else{\n}";
  PsiIfStatement ifStatement = (PsiIfStatement)factory.createStatementFromText(text, null);
  ifStatement = (PsiIfStatement)codeStyleManager.reformat(ifStatement);

  ifStatement.getCondition().replace(expr);

  PsiExpressionStatement statement = (PsiExpressionStatement)expr.getParent();
  ifStatement = (PsiIfStatement)statement.replace(ifStatement);

  PsiCodeBlock block = ((PsiBlockStatement)ifStatement.getThenBranch()).getCodeBlock();

  PsiStatement afterStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(block.getStatements()[0]);

  TextRange range = afterStatement.getTextRange();
  editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
  return new TextRange(range.getStartOffset(), range.getStartOffset());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:JavaWithIfElseExpressionSurrounder.java

示例3: surroundExpression

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
public TextRange surroundExpression(Project project, Editor editor, PsiExpression expr) throws IncorrectOperationException {
  PsiManager manager = expr.getManager();
  PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);

  PsiPrefixExpression prefixExpr = (PsiPrefixExpression)factory.createExpressionFromText("!(a instanceof Type)", null);
  prefixExpr = (PsiPrefixExpression)codeStyleManager.reformat(prefixExpr);
  PsiParenthesizedExpression parenthExpr = (PsiParenthesizedExpression)prefixExpr.getOperand();
  PsiInstanceOfExpression instanceofExpr = (PsiInstanceOfExpression)parenthExpr.getExpression();
  instanceofExpr.getOperand().replace(expr);
  prefixExpr = (PsiPrefixExpression)expr.replace(prefixExpr);
  parenthExpr = (PsiParenthesizedExpression)prefixExpr.getOperand();
  instanceofExpr = (PsiInstanceOfExpression)parenthExpr.getExpression();
  instanceofExpr = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(instanceofExpr);
  TextRange range = instanceofExpr.getCheckType().getTextRange();
  editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
  return new TextRange(range.getStartOffset(), range.getStartOffset());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:JavaWithNotInstanceofSurrounder.java

示例4: invoke

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的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

示例5: invoke

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().prepareFileForWrite(myVariable.getContainingFile())) return;

  String initializerText = suggestInitializer();
  PsiElementFactory factory = JavaPsiFacade.getInstance(myVariable.getProject()).getElementFactory();
  PsiExpression initializer = factory.createExpressionFromText(initializerText, myVariable);
  if (myVariable instanceof PsiLocalVariable) {
    ((PsiLocalVariable)myVariable).setInitializer(initializer);
  }
  else if (myVariable instanceof PsiField) {
    ((PsiField)myVariable).setInitializer(initializer);
  }
  else {
    LOG.error("Unknown variable type: "+myVariable);
  }
  PsiVariable var = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(myVariable);
  TextRange range = var.getInitializer().getTextRange();
  int offset = range.getStartOffset();
  editor.getCaretModel().moveToOffset(offset);
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:AddVariableInitializerFix.java

示例6: beforeMove

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
public void beforeMove(@NotNull final Editor editor, @NotNull final MoveInfo info, final boolean down) {
  super.beforeMove(editor, info, down);

  if (myEnumToInsertSemicolonAfter != null) {
    TreeElement semicolon = Factory.createSingleLeafElement(JavaTokenType.SEMICOLON, ";", 0, 1, null, myEnumToInsertSemicolonAfter.getManager());

    try {
      PsiElement inserted = myEnumToInsertSemicolonAfter.getParent().addAfter(semicolon.getPsi(), myEnumToInsertSemicolonAfter);
      inserted = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(inserted);
      final LogicalPosition position = editor.offsetToLogicalPosition(inserted.getTextRange().getEndOffset());

      info.toMove2 = new LineRange(position.line + 1, position.line + 1);
    }
    catch (IncorrectOperationException e) {
      LOG.error(e);
    }
    finally {
      myEnumToInsertSemicolonAfter = null;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:DeclarationMover.java

示例7: showTemplateBuilder

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
private static void showTemplateBuilder(PyFunction method, @NotNull final PsiFile file) {
  method = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(method);

  final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(method);
  ParamHelper.walkDownParamArray(
    method.getParameterList().getParameters(),
    new ParamHelper.ParamVisitor() {
      public void visitNamedParameter(PyNamedParameter param, boolean first, boolean last) {
        builder.replaceElement(param, param.getName());
      }
    }
  );

  // TODO: detect expected return type from call site context: PY-1863
  builder.replaceElement(method.getStatementList(), "return None");
  final VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) return;
  final Editor editor = FileEditorManager.getInstance(file.getProject()).openTextEditor(
    new OpenFileDescriptor(file.getProject(), virtualFile), true);
  if (editor == null) return;
  builder.run(editor, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AddFunctionQuickFix.java

示例8: applyFix

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  final PsiElement element = descriptor.getPsiElement();
  final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
  final PyNamedParameter parameter = elementGenerator.createParameter(element.getText() + "=None");
  final PyFunction function = PsiTreeUtil.getParentOfType(element, PyFunction.class);
  if (function != null) {
    final PyParameterList parameterList = function.getParameterList();
    parameterList.addParameter(parameter);
    CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(parameterList);
    final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(parameter);
    builder.replaceRange(TextRange.create(parameter.getTextLength() - 4, parameter.getTextLength()), "None");
    final VirtualFile virtualFile = function.getContainingFile().getVirtualFile();
    if (virtualFile == null) return;
    final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
    if (editor == null) return;
    builder.run(editor, false);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:UnresolvedReferenceAddParameterQuickFix.java

示例9: showTemplateBuilder

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
private void showTemplateBuilder(PsiElement initStatement, @NotNull final PsiFile file) {
  initStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(initStatement);
  if (initStatement instanceof PyAssignmentStatement) {
    final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(initStatement);
    final PyExpression assignedValue = ((PyAssignmentStatement)initStatement).getAssignedValue();
    final PyExpression leftExpression = ((PyAssignmentStatement)initStatement).getLeftHandSideExpression();
    if (assignedValue != null && leftExpression != null) {
      if (replaceInitializer)
        builder.replaceElement(assignedValue, myInitializer);
      else
        builder.replaceElement(leftExpression.getLastChild(), myIdentifier);
      final VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile == null) return;
      final Editor editor = FileEditorManager.getInstance(file.getProject()).openTextEditor(
                new OpenFileDescriptor(file.getProject(), virtualFile), true);
      if (editor == null) return;
      builder.run(editor, false);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:AddFieldQuickFix.java

示例10: showTemplateBuilder

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
private static void showTemplateBuilder(@NotNull PyFunction method) {
  method = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(method);
  final PsiFile file = method.getContainingFile();
  if (file == null) return;
  final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(method);
  ParamHelper.walkDownParamArray(
    method.getParameterList().getParameters(),
    new ParamHelper.ParamVisitor() {
      public void visitNamedParameter(PyNamedParameter param, boolean first, boolean last) {
        builder.replaceElement(param, param.getName());
      }
    }
  );

  final PyStatementList statementList = method.getStatementList();
  builder.replaceElement(statementList, PyNames.PASS);

  final VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) return;
  final Editor editor = FileEditorManager.getInstance(file.getProject()).openTextEditor(
    new OpenFileDescriptor(file.getProject(), virtualFile), true);
  if (editor == null) return;
  builder.run(editor, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:AddMethodQuickFix.java

示例11: surroundStatement

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
@Nullable
protected TextRange surroundStatement(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements)
  throws IncorrectOperationException {
  PyIfStatement ifStatement = PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyIfStatement.class, "if True:\n    ");
  final PsiElement parent = elements[0].getParent();
  final PyStatementList statementList = ifStatement.getIfPart().getStatementList();
  statementList.addRange(elements[0], elements[elements.length - 1]);
  ifStatement = (PyIfStatement) parent.addBefore(ifStatement, elements[0]);
  parent.deleteChildRange(elements[0], elements[elements.length - 1]);

  ifStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(ifStatement);
  if (ifStatement == null) {
    return null;
  }
  final PyExpression condition = ifStatement.getIfPart().getCondition();
  return condition != null ? condition.getTextRange() : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:PyWithIfSurrounder.java

示例12: surroundStatement

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
@Nullable
protected TextRange surroundStatement(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements)
  throws IncorrectOperationException {
  PyWhileStatement whileStatement =
    PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyWhileStatement.class, "while True:\n    \nelse:\n");
  final PsiElement parent = elements[0].getParent();
  whileStatement.addRange(elements[0], elements[elements.length - 1]);
  whileStatement = (PyWhileStatement) parent.addBefore(whileStatement, elements[0]);
  parent.deleteChildRange(elements[0], elements[elements.length - 1]);

  whileStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(whileStatement);
  if (whileStatement == null) {
    return null;
  }
  return whileStatement.getTextRange();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PyWithWhileElseSurrounder.java

示例13: surroundStatement

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
@Nullable
protected TextRange surroundStatement(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements)
  throws IncorrectOperationException {
  PyIfStatement ifStatement =
    PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyIfStatement.class, "if True:\n    pass\nelse:    pass\n");
  final PsiElement parent = elements[0].getParent();
  final PyStatementList statementList = ifStatement.getIfPart().getStatementList();
  statementList.addRange(elements[0], elements[elements.length - 1]);
  statementList.deleteChildRange(statementList.getFirstChild(), statementList.getFirstChild());

  ifStatement = (PyIfStatement) parent.addBefore(ifStatement, elements[0]);
  parent.deleteChildRange(elements[0], elements[elements.length - 1]);

  ifStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(ifStatement);
  if (ifStatement == null) {
    return null;
  }
  return ifStatement.getTextRange();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PyWithIfElseSurrounder.java

示例14: invokeInplaceRename

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
private static void invokeInplaceRename(PsiNameIdentifierOwner nameIdentifierOwner, final String... suggestedNames) {
  final PsiNameIdentifierOwner elementToRename = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(nameIdentifierOwner);
  final Editor editor = FileEditorManager.getInstance(nameIdentifierOwner.getProject()).getSelectedTextEditor();
  if (editor == null) {
    return;
  }
  final PsiElement identifier = elementToRename.getNameIdentifier();
  if (identifier == null) {
    return;
  }
  editor.getCaretModel().moveToOffset(identifier.getTextOffset());
  final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(elementToRename);
  if (!processor.isInplaceRenameSupported()) {
    return;
  }
  processor.substituteElementToRename(elementToRename, editor, new Pass<PsiElement>() {
    @Override
    public void pass(PsiElement substitutedElement) {
      final MemberInplaceRenamer renamer = new MemberInplaceRenamer(elementToRename, substitutedElement, editor);
      final LinkedHashSet<String> nameSuggestions = new LinkedHashSet<String>(Arrays.asList(suggestedNames));
      renamer.performInplaceRefactoring(nameSuggestions);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:NonThreadSafeLazyInitializationInspection.java

示例15: surroundExpression

import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
public TextRange surroundExpression(Project project, Editor editor, PsiExpression expr) throws IncorrectOperationException {
  PsiManager manager = expr.getManager();
  PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);

  @NonNls String text = "if(a){\nst;\n}";
  PsiIfStatement ifStatement = (PsiIfStatement)factory.createStatementFromText(text, null);
  ifStatement = (PsiIfStatement)codeStyleManager.reformat(ifStatement);

  ifStatement.getCondition().replace(expr);

  PsiExpressionStatement statement = (PsiExpressionStatement)expr.getParent();
  ifStatement = (PsiIfStatement)statement.replace(ifStatement);

  PsiCodeBlock block = ((PsiBlockStatement)ifStatement.getThenBranch()).getCodeBlock();
  block = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(block);
  TextRange range = block.getStatements()[0].getTextRange();
  editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
  return new TextRange(range.getStartOffset(), range.getStartOffset());
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:JavaWithIfExpressionSurrounder.java


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