use of com.intellij.psi.text.BlockSupport in project intellij-elixir by KronicDeth.
the class RemoveSpaceInFrontOfNoParenthesesStrict method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
assert startElement == endElement;
com.intellij.lang.ASTNode parentNode = startElement.getNode();
com.intellij.lang.ASTNode whiteSpace = parentNode.findChildByType(TokenType.WHITE_SPACE);
BlockSupport blockSupport = BlockSupport.getInstance(project);
final int startOffset = whiteSpace.getStartOffset();
final int endOffset = startOffset + whiteSpace.getTextLength();
blockSupport.reparseRange(file, startOffset, endOffset, "");
}
use of com.intellij.psi.text.BlockSupport in project intellij-community by JetBrains.
the class SrcRepositoryUseTest method testModification3.
public void testModification3() throws Exception {
PsiClass aClass = myJavaFacade.findClass("pack.MyInterface1", GlobalSearchScope.allScope(myProject));
TextRange classRange = aClass.getTextRange();
String text = aClass.getText();
BlockSupport blockSupport = ServiceManager.getService(myProject, BlockSupport.class);
final PsiFile psiFile = aClass.getContainingFile();
ApplicationManager.getApplication().runWriteAction(() -> blockSupport.reparseRange(psiFile, classRange.getStartOffset(), classRange.getEndOffset(), ""));
LOG.assertTrue(!aClass.isValid());
ApplicationManager.getApplication().runWriteAction(() -> blockSupport.reparseRange(psiFile, classRange.getStartOffset(), classRange.getStartOffset(), text));
aClass = myJavaFacade.findClass("pack.MyInterface1", GlobalSearchScope.allScope(myProject));
PsiElement[] children = aClass.getChildren();
for (PsiElement child : children) {
if (child instanceof PsiModifierList) {
PsiElement parent = child.getParent();
assertEquals(aClass, parent);
PsiModifierList modifierList = aClass.getModifierList();
assertEquals(modifierList, child);
}
}
PsiJavaFile file = (PsiJavaFile) aClass.getContainingFile();
PsiImportList importList = file.getImportList();
children = importList.getChildren();
int index = 0;
for (PsiElement child : children) {
if (child instanceof PsiImportStatement) {
PsiElement parent = child.getParent();
assertEquals(importList, parent);
PsiImportStatement statement = importList.getImportStatements()[index++];
assertEquals(statement, child);
}
}
}
use of com.intellij.psi.text.BlockSupport in project intellij-community by JetBrains.
the class DocumentCommitThread method doCommit.
// public for Upsource
@Nullable("returns runnable to execute under write action in AWT to finish the commit")
public Processor<Document> doCommit(@NotNull final CommitTask task, @NotNull final PsiFile file, @NotNull final FileASTNode oldFileNode) {
Document document = task.getDocument();
final CharSequence newDocumentText = document.getImmutableCharSequence();
final TextRange changedPsiRange = getChangedPsiRange(file, task.myLastCommittedText, newDocumentText);
if (changedPsiRange == null) {
return null;
}
final Boolean data = document.getUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY);
if (data != null) {
document.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, null);
file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, data);
}
BlockSupport blockSupport = BlockSupport.getInstance(file.getProject());
final DiffLog diffLog = blockSupport.reparseRange(file, oldFileNode, changedPsiRange, newDocumentText, task.indicator, task.myLastCommittedText);
return document1 -> {
FileViewProvider viewProvider = file.getViewProvider();
if (!task.isStillValid() || ((PsiDocumentManagerBase) PsiDocumentManager.getInstance(file.getProject())).getCachedViewProvider(document1) != viewProvider) {
return false;
}
if (file.isPhysical() && !ApplicationManager.getApplication().isWriteAccessAllowed()) {
VirtualFile vFile = viewProvider.getVirtualFile();
LOG.error("Write action expected" + "; document=" + document1 + "; file=" + file + " of " + file.getClass() + "; file.valid=" + file.isValid() + "; file.eventSystemEnabled=" + viewProvider.isEventSystemEnabled() + "; viewProvider=" + viewProvider + " of " + viewProvider.getClass() + "; language=" + file.getLanguage() + "; vFile=" + vFile + " of " + vFile.getClass() + "; free-threaded=" + SingleRootFileViewProvider.isFreeThreaded(viewProvider));
}
doActualPsiChange(file, diffLog);
assertAfterCommit(document1, file, (FileElement) oldFileNode);
return true;
};
}
use of com.intellij.psi.text.BlockSupport in project intellij-elixir by KronicDeth.
the class ConvertKeywordPairToTypeOperation method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
assert startElement == endElement;
BlockSupport blockSupport = BlockSupport.getInstance(project);
TextRange textRange = startElement.getTextRange();
int startOffset = textRange.getStartOffset();
int endOffset = textRange.getEndOffset();
blockSupport.reparseRange(file, startOffset, endOffset, " ::");
}
use of com.intellij.psi.text.BlockSupport in project intellij-elixir by KronicDeth.
the class ConvertMatchToTypeOperation method applyFix.
/*
* Instance Methods
*/
/**
* Called to apply the fix.
*
* @param project {@link Project}
* @param descriptor problem reported by the tool which provided this quick fix action
*/
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
BlockSupport blockSupport = BlockSupport.getInstance(project);
TextRange textRange = matchOperatorASTNode.getTextRange();
blockSupport.reparseRange(matchOperatorASTNode.getPsi().getContainingFile(), textRange.getStartOffset(), textRange.getEndOffset(), "::");
}
Aggregations