本文整理汇总了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());
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}