use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class TreeElement method setTreeParent.
final void setTreeParent(CompositeElement parent) {
if (parent == myParent)
return;
PsiFileImpl file = getCachedFile(this);
if (file != null) {
file.beforeAstChange();
}
myParent = parent;
if (parent != null && parent.getElementType() != TokenType.DUMMY_HOLDER) {
DebugUtil.revalidateNode(this);
}
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class JavaFunctionalExpressionPresentationTest method doTest.
private void doTest(@Language("JAVA") @NotNull String funExprText, @NotNull String expectedPresentableString) {
final PsiFileImpl file = assertInstanceOf(configureByText(JavaFileType.INSTANCE, funExprText), PsiFileImpl.class);
//stub based test
final FunctionalExpressionStub functionalExpressionStub = StreamEx.of(file.calcStubTree().getPlainList()).select(FunctionalExpressionStub.class).collect(MoreCollectors.onlyOne()).orElse(null);
assertNotNull(functionalExpressionStub);
assertEquals("Comparing with stub based rendering", expectedPresentableString, functionalExpressionStub.getPresentableText());
//ast based test
final PsiExpression psi = assertInstanceOf(functionalExpressionStub.getPsi(), PsiExpression.class);
assertEquals("Comparing with AST based rendering", expectedPresentableString, PsiExpressionTrimRenderer.render(psi));
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class DocumentCommitThread method commitUnderProgress.
// returns (finish commit Runnable (to be invoked later in EDT), null) on success or (null, failure reason) on failure
@NotNull
private Pair<Runnable, Object> commitUnderProgress(@NotNull final CommitTask task, final boolean synchronously) {
if (synchronously) {
assert !task.indicator.isCanceled();
}
final Document document = task.getDocument();
final Project project = task.project;
final PsiDocumentManagerBase documentManager = (PsiDocumentManagerBase) PsiDocumentManager.getInstance(project);
final List<Processor<Document>> finishProcessors = new SmartList<>();
Runnable runnable = () -> {
myApplication.assertReadAccessAllowed();
if (project.isDisposed())
return;
Lock lock = getDocumentLock(document);
if (!lock.tryLock()) {
task.cancel("Can't obtain document lock", this);
return;
}
boolean canceled = false;
try {
if (documentManager.isCommitted(document))
return;
if (!task.isStillValid()) {
canceled = true;
return;
}
FileViewProvider viewProvider = documentManager.getCachedViewProvider(document);
if (viewProvider == null) {
finishProcessors.add(handleCommitWithoutPsi(documentManager, task));
return;
}
for (Pair<PsiFileImpl, FileASTNode> pair : task.myOldFileNodes) {
PsiFileImpl file = pair.first;
if (file.isValid()) {
FileASTNode oldFileNode = pair.second;
Processor<Document> finishProcessor = doCommit(task, file, oldFileNode);
if (finishProcessor != null) {
finishProcessors.add(finishProcessor);
}
} else {
// file became invalid while sitting in the queue
if (task.reason.equals(SYNC_COMMIT_REASON)) {
throw new PsiInvalidElementAccessException(file, "File " + file + " invalidated during sync commit");
}
commitAsynchronously(project, document, "File " + file + " invalidated during background commit; task: " + task, task.myCreationContext);
}
}
} finally {
lock.unlock();
if (canceled) {
task.cancel("Task invalidated", this);
}
}
};
if (synchronously) {
runnable.run();
} else if (!myApplication.tryRunReadAction(runnable)) {
log(project, "Could not start read action", task, myApplication.isReadAccessAllowed(), Thread.currentThread());
return new Pair<>(null, "Could not start read action");
}
boolean canceled = task.indicator.isCanceled();
assert !synchronously || !canceled;
if (canceled) {
return new Pair<>(null, "Indicator was canceled");
}
Runnable result = createEdtRunnable(task, synchronously, finishProcessors);
return Pair.create(result, null);
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class PsiDocumentManagerBase method documentChanged.
@Override
public void documentChanged(DocumentEvent event) {
if (myStopTrackingDocuments || myProject.isDisposed())
return;
final Document document = event.getDocument();
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
boolean isRelevant = virtualFile != null && isRelevant(virtualFile);
final FileViewProvider viewProvider = getCachedViewProvider(document);
if (viewProvider == null) {
handleCommitWithoutPsi(document);
return;
}
boolean inMyProject = viewProvider.getManager() == myPsiManager;
if (!isRelevant || !inMyProject) {
clearUncommittedInfo(document);
return;
}
List<PsiFile> files = viewProvider.getAllFiles();
boolean commitNecessary = files.stream().noneMatch(file -> PsiToDocumentSynchronizer.isInsideAtomicChange(file) || !(file instanceof PsiFileImpl));
boolean forceCommit = ApplicationManager.getApplication().hasWriteAction(ExternalChangeAction.class) && (SystemProperties.getBooleanProperty("idea.force.commit.on.external.change", false) || ApplicationManager.getApplication().isHeadlessEnvironment() && !ApplicationManager.getApplication().isUnitTestMode());
// for the huge file (that causes the whole document to be reloaded and 'merge' way takes a while to complete).
if (event.isWholeTextReplaced() && document.getTextLength() > 100000) {
document.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE);
}
if (commitNecessary) {
assert !(document instanceof DocumentWindow);
myUncommittedDocuments.add(document);
if (forceCommit) {
commitDocument(document);
} else if (!((DocumentEx) document).isInBulkUpdate() && myPerformBackgroundCommit) {
myDocumentCommitProcessor.commitAsynchronously(myProject, document, event, TransactionGuard.getInstance().getContextTransaction());
}
} else {
clearUncommittedInfo(document);
}
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class SmartPsiElementPointerImpl method createAnchorInfo.
@Nullable
private static SmartPointerElementInfo createAnchorInfo(@NotNull PsiElement element, @NotNull PsiFile containingFile) {
if (element instanceof StubBasedPsiElement && containingFile instanceof PsiFileWithStubSupport) {
PsiFileWithStubSupport stubFile = (PsiFileWithStubSupport) containingFile;
StubTree stubTree = stubFile.getStubTree();
if (stubTree != null) {
// use stubs when tree is not loaded
StubBasedPsiElement stubPsi = (StubBasedPsiElement) element;
int stubId = PsiAnchor.calcStubIndex(stubPsi);
IStubElementType myStubElementType = stubPsi.getElementType();
IStubFileElementType elementTypeForStubBuilder = ((PsiFileImpl) containingFile).getElementTypeForStubBuilder();
if (stubId != -1 && elementTypeForStubBuilder != null) {
// TemplateDataElementType is not IStubFileElementType
return new AnchorElementInfo(element, stubFile, stubId, myStubElementType);
}
}
}
Pair<Identikit.ByAnchor, PsiElement> pair = Identikit.withAnchor(element, LanguageUtil.getRootLanguage(containingFile));
if (pair != null) {
return new AnchorElementInfo(pair.second, containingFile, pair.first);
}
return null;
}
Aggregations