use of com.intellij.lang.FileASTNode in project intellij-community by JetBrains.
the class SmartPsiElementPointersTest method testEqualPointersWhenCreatedFromStubAndAST.
public void testEqualPointersWhenCreatedFromStubAndAST() {
PsiJavaFile file = (PsiJavaFile) myJavaFacade.findClass("AClass", GlobalSearchScope.allScope(getProject())).getContainingFile();
int hash1 = file.getClasses()[0].hashCode();
final SmartPsiElementPointer<PsiClass> pointer1 = createPointer(file.getClasses()[0]);
assertNotNull(((PsiFileImpl) file).getStubTree());
PlatformTestUtil.tryGcSoftlyReachableObjects();
final FileASTNode node = file.getNode();
final SmartPsiElementPointer<PsiClass> pointer2 = createPointer(file.getClasses()[0]);
assertFalse(hash1 == file.getClasses()[0].hashCode());
assertEquals(pointer1, pointer2);
assertEquals(pointer1.getRange(), pointer2.getRange());
assertNotNull(node);
}
use of com.intellij.lang.FileASTNode in project intellij-community by JetBrains.
the class FileContentImpl method getLighterASTForPsiDependentIndex.
@NotNull
public LighterAST getLighterASTForPsiDependentIndex() {
LighterAST lighterAST = getUserData(IndexingDataKeys.LIGHTER_AST_NODE_KEY);
if (lighterAST == null) {
FileASTNode node = getPsiFileForPsiDependentIndex().getNode();
lighterAST = myLighterASTShouldBeThreadSafe ? new TreeBackedLighterAST(node) : node.getLighterAST();
putUserData(IndexingDataKeys.LIGHTER_AST_NODE_KEY, lighterAST);
}
return lighterAST;
}
use of com.intellij.lang.FileASTNode in project intellij-community by JetBrains.
the class SharedImplUtil method findFileElement.
public static FileASTNode findFileElement(@NotNull ASTNode element) {
if (CHECK_FOR_READ_ACTION && element instanceof ElementBase) {
ApplicationManager.getApplication().assertReadAccessAllowed();
}
ASTNode parent = element.getTreeParent();
while (parent != null) {
element = parent;
parent = parent.getTreeParent();
}
if (element instanceof FileASTNode) {
return (FileASTNode) element;
}
return null;
}
use of com.intellij.lang.FileASTNode in project intellij-community by JetBrains.
the class SharedImplUtil method getContainingFile.
public static PsiFile getContainingFile(ASTNode thisElement) {
FileASTNode node = findFileElement(thisElement);
PsiElement psi = node == null ? null : node.getPsi();
if (psi == null || psi instanceof PsiFile)
return (PsiFile) psi;
throw new AssertionError("Invalid PSI " + psi + " of " + psi.getClass() + " for AST " + node + " of " + node.getClass());
}
use of com.intellij.lang.FileASTNode 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;
};
}
Aggregations