use of com.intellij.psi.text.BlockSupport in project intellij-community by JetBrains.
the class ExpressionUtil method getNames.
@Nullable
public static String[] getNames(final ExpressionContext context) {
final Project project = context.getProject();
final int offset = context.getStartOffset();
PsiDocumentManager.getInstance(project).commitAllDocuments();
String[] names = null;
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
PsiElement element = file.findElementAt(offset);
if (element instanceof PsiIdentifier) {
names = getNamesForIdentifier(project, (PsiIdentifier) element);
} else {
final PsiFile fileCopy = (PsiFile) file.copy();
ApplicationManager.getApplication().runWriteAction(() -> {
BlockSupport blockSupport = BlockSupport.getInstance(project);
try {
blockSupport.reparseRange(fileCopy, offset, offset, "xxx");
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
PsiElement identifierCopy = fileCopy.findElementAt(offset);
if (identifierCopy instanceof PsiIdentifier) {
names = getNamesForIdentifier(project, (PsiIdentifier) identifierCopy);
}
}
return names;
}
use of com.intellij.psi.text.BlockSupport in project intellij-community by JetBrains.
the class DocumentCommitThread method assertAfterCommit.
private void assertAfterCommit(@NotNull Document document, @NotNull final PsiFile file, @NotNull FileElement oldFileNode) {
if (oldFileNode.getTextLength() != document.getTextLength()) {
final String documentText = document.getText();
String fileText = file.getText();
boolean sameText = Comparing.equal(fileText, documentText);
LOG.error("commitDocument() left PSI inconsistent: " + DebugUtil.diagnosePsiDocumentInconsistency(file, document) + "; node.length=" + oldFileNode.getTextLength() + "; doc.text" + (sameText ? "==" : "!=") + "file.text" + "; file name:" + file.getName() + "; type:" + file.getFileType() + "; lang:" + file.getLanguage());
file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE);
try {
BlockSupport blockSupport = BlockSupport.getInstance(file.getProject());
final DiffLog diffLog = blockSupport.reparseRange(file, file.getNode(), new TextRange(0, documentText.length()), documentText, createProgressIndicator(), oldFileNode.getText());
doActualPsiChange(file, diffLog);
if (oldFileNode.getTextLength() != document.getTextLength()) {
LOG.error("PSI is broken beyond repair in: " + file);
}
} finally {
file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, null);
}
}
}
Aggregations