當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiDocumentManager.doPostponedOperationsAndUnblockDocument方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiDocumentManager.doPostponedOperationsAndUnblockDocument方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiDocumentManager.doPostponedOperationsAndUnblockDocument方法的具體用法?Java PsiDocumentManager.doPostponedOperationsAndUnblockDocument怎麽用?Java PsiDocumentManager.doPostponedOperationsAndUnblockDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiDocumentManager的用法示例。


在下文中一共展示了PsiDocumentManager.doPostponedOperationsAndUnblockDocument方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyFix

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
    PsiElement element = problemDescriptor.getPsiElement();
    if ( ! (element instanceof PhpClass)) {
        return;
    }

    PsiFile containingFile = element.getContainingFile();
    PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
    Document document = manager.getDocument(containingFile);

    PhpClass phpClass = (PhpClass) element;
    String template = "\n\n(new " + phpClass.getName() + "())->run();";
    Statement runMethodCall = PhpPsiElementFactory.createStatement(project, template);

    phpClass.getParent().addAfter(runMethodCall, phpClass);

    if (document != null) {
        manager.doPostponedOperationsAndUnblockDocument(document);
        TextRange reformatRange = runMethodCall.getTextRange();
        CodeStyleManager.getInstance(project).reformatText(containingFile, reformatRange.getStartOffset(), reformatRange.getEndOffset());
    }
}
 
開發者ID:jiripudil,項目名稱:intellij-nette-tester,代碼行數:24,代碼來源:TestCaseIsRunInspection.java

示例2: forcePsiPostprocessAndRestoreElement

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
public static <T extends PsiElement> T forcePsiPostprocessAndRestoreElement(@NotNull T element,
                                                                            boolean useFileLanguage) {
  final PsiFile psiFile = element.getContainingFile();
  final Document document = psiFile.getViewProvider().getDocument();
  //if (document == null) return element;
  final Language language = useFileLanguage ? psiFile.getLanguage() : PsiUtilCore.getDialect(element);
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(psiFile.getProject());
  final RangeMarker rangeMarker = document.createRangeMarker(element.getTextRange());
  documentManager.doPostponedOperationsAndUnblockDocument(document);
  documentManager.commitDocument(document);

  T elementInRange = findElementInRange(psiFile, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(),
                                        (Class<? extends T>)element.getClass(),
                                        language);
  rangeMarker.dispose();
  return elementInRange;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:CodeInsightUtilCore.java

示例3: applyPendingChangesToPsi

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
private static void applyPendingChangesToPsi(@NotNull PsiElement source) {
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(source.getContainingFile().getProject());
  final Document document = documentManager.getDocument(source.getContainingFile());
  if (document != null) {
    documentManager.doPostponedOperationsAndUnblockDocument(document);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:PyTrailingBlankLinesPostFormatProcessor.java

示例4: buildAndInsert

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@NotNull
public PyDocStringOwner buildAndInsert() {
  Preconditions.checkNotNull(myDocStringOwner, "For this action docstring owner must be supplied");
  final String replacementText = buildDocString();

  final Project project = myDocStringOwner.getProject();
  PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
  final PyExpressionStatement replacement = elementGenerator.createDocstring(replacementText);

  final PyStringLiteralExpression docStringExpression = getDocStringExpression();
  if (docStringExpression != null) {
    docStringExpression.replace(replacement.getExpression());
  }
  else {
    PyStatementListContainer container = PyUtil.as(myDocStringOwner, PyStatementListContainer.class);
    if (container == null) {
      throw new IllegalStateException("Should be a function or class");
    }
    final PyStatementList statements = container.getStatementList();
    final String indentation = PyIndentUtil.getExpectedElementIndent(statements);
    final Document document = PsiDocumentManager.getInstance(project).getDocument(myDocStringOwner.getContainingFile());

    if (document != null) {
      final PsiElement beforeStatements = statements.getPrevSibling();
      final boolean onSameLine = !(beforeStatements instanceof PsiWhiteSpace) || !beforeStatements.textContains('\n');
      if (onSameLine || statements.getStatements().length == 0) {
        String replacementWithLineBreaks = "\n" + indentation + replacementText;
        if (statements.getStatements().length > 0) {
          replacementWithLineBreaks += "\n" + indentation;
        }
        final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
        documentManager.doPostponedOperationsAndUnblockDocument(document);
        final TextRange range = beforeStatements.getTextRange();
        try {
          if (beforeStatements instanceof PsiWhiteSpace) {
            if (statements.getStatements().length > 0) {
              document.replaceString(range.getStartOffset(), range.getEndOffset(), replacementWithLineBreaks);
            }
            else {
              // preserve original spacing, since it probably separates function and other declarations
              document.insertString(range.getStartOffset(), replacementWithLineBreaks);
            }
          }
          else {
            document.insertString(range.getEndOffset(), replacementWithLineBreaks);
          }
        }
        finally {
          documentManager.commitDocument(document);
        }
      }
      else {
        statements.addBefore(replacement, statements.getStatements()[0]);
      }
    }
  }
  myDocStringOwner = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(myDocStringOwner);
  return myDocStringOwner;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:60,代碼來源:PyDocstringGenerator.java

示例5: processIntention

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
  final GrMethodCallExpression expression = (GrMethodCallExpression)element;
  final GrClosableBlock block = expression.getClosureArguments()[0];
  final GrParameterList parameterList = block.getParameterList();
  final GrParameter[] parameters = parameterList.getParameters();

  String var;
  if (parameters.length == 1) {
    var = parameters[0].getText();
    var = StringUtil.replace(var, GrModifier.DEF, "");
  }
  else {
    var = "it";
  }

  final GrExpression invokedExpression = expression.getInvokedExpression();
  GrExpression qualifier = ((GrReferenceExpression)invokedExpression).getQualifierExpression();
  final GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(element.getProject());
  if (qualifier == null) {
    qualifier = elementFactory.createExpressionFromText("this");
  }

  StringBuilder builder = new StringBuilder();
  builder.append("for (").append(var).append(" in ").append(qualifier.getText()).append(") {\n");
  String text = block.getText();
  final PsiElement blockArrow = block.getArrow();
  int index;
  if (blockArrow != null) {
    index = blockArrow.getStartOffsetInParent() + blockArrow.getTextLength();
  }
  else {
    index = 1;
  }
  while (index < text.length() && Character.isWhitespace(text.charAt(index))) index++;
  text = text.substring(index, text.length() - 1);
  builder.append(text);
  builder.append("}");

  final GrStatement statement = elementFactory.createStatementFromText(builder.toString());
  GrForStatement forStatement = (GrForStatement)expression.replaceWithStatement(statement);
  final GrForClause clause = forStatement.getClause();
  GrVariable variable = clause.getDeclaredVariable();

  forStatement = updateReturnStatements(forStatement);

  if (variable == null) return;

  if (ApplicationManager.getApplication().isUnitTestMode()) return;

  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final Document doc = documentManager.getDocument(element.getContainingFile());
  if (doc == null) return;

  documentManager.doPostponedOperationsAndUnblockDocument(doc);
  editor.getCaretModel().moveToOffset(variable.getTextOffset());
  new VariableInplaceRenamer(variable, editor).performInplaceRename();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:59,代碼來源:EachToForIntention.java


注:本文中的com.intellij.psi.PsiDocumentManager.doPostponedOperationsAndUnblockDocument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。