Search in sources :

Example 6 with FileASTNode

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);
}
Also used : FileASTNode(com.intellij.lang.FileASTNode)

Example 7 with FileASTNode

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;
}
Also used : FileASTNode(com.intellij.lang.FileASTNode) TreeBackedLighterAST(com.intellij.lang.TreeBackedLighterAST) TreeBackedLighterAST(com.intellij.lang.TreeBackedLighterAST) LighterAST(com.intellij.lang.LighterAST) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with FileASTNode

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;
}
Also used : ElementBase(com.intellij.psi.impl.ElementBase) FileASTNode(com.intellij.lang.FileASTNode) ASTNode(com.intellij.lang.ASTNode) FileASTNode(com.intellij.lang.FileASTNode)

Example 9 with FileASTNode

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());
}
Also used : FileASTNode(com.intellij.lang.FileASTNode)

Example 10 with FileASTNode

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;
    };
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) PomModelEvent(com.intellij.pom.event.PomModelEvent) UIUtil(com.intellij.util.ui.UIUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Date(java.util.Date) Document(com.intellij.openapi.editor.Document) TimeoutException(java.util.concurrent.TimeoutException) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) com.intellij.openapi.application(com.intellij.openapi.application) SmartList(com.intellij.util.SmartList) FileASTNode(com.intellij.lang.FileASTNode) PomModel(com.intellij.pom.PomModel) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) Logger(com.intellij.openapi.diagnostic.Logger) ProgressManager(com.intellij.openapi.progress.ProgressManager) BlockSupport(com.intellij.psi.text.BlockSupport) Set(java.util.Set) FileElement(com.intellij.psi.impl.source.tree.FileElement) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) TreeAspect(com.intellij.pom.tree.TreeAspect) PooledThreadExecutor(org.jetbrains.ide.PooledThreadExecutor) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) NonNls(org.jetbrains.annotations.NonNls) SimpleDateFormat(java.text.SimpleDateFormat) ForeignLeafPsiElement(com.intellij.psi.impl.source.tree.ForeignLeafPsiElement) ContainerUtil(com.intellij.util.containers.ContainerUtil) PomManager(com.intellij.pom.PomManager) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) TreeAspectEvent(com.intellij.pom.tree.TreeAspectEvent) Project(com.intellij.openapi.project.Project) ExecutorService(java.util.concurrent.ExecutorService) BoundedTaskExecutor(com.intellij.util.concurrency.BoundedTaskExecutor) DiffLog(com.intellij.psi.impl.source.text.DiffLog) HashSetQueue(com.intellij.util.containers.HashSetQueue) ReentrantLock(java.util.concurrent.locks.ReentrantLock) StandardProgressIndicatorBase(com.intellij.openapi.progress.util.StandardProgressIndicatorBase) StringUtil(com.intellij.openapi.util.text.StringUtil) TreeUtil(com.intellij.psi.impl.source.tree.TreeUtil) Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ASTNode(com.intellij.lang.ASTNode) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) Lock(java.util.concurrent.locks.Lock) ExceptionUtil(com.intellij.util.ExceptionUtil) Collections(java.util.Collections) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileElement(com.intellij.psi.impl.source.tree.FileElement) Document(com.intellij.openapi.editor.Document) BlockSupport(com.intellij.psi.text.BlockSupport) DiffLog(com.intellij.psi.impl.source.text.DiffLog) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FileASTNode (com.intellij.lang.FileASTNode)20 ASTNode (com.intellij.lang.ASTNode)6 Project (com.intellij.openapi.project.Project)5 NotNull (org.jetbrains.annotations.NotNull)5 Document (com.intellij.openapi.editor.Document)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)3 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)3 SmartList (com.intellij.util.SmartList)3 Nullable (org.jetbrains.annotations.Nullable)3 LighterAST (com.intellij.lang.LighterAST)2 TreeBackedLighterAST (com.intellij.lang.TreeBackedLighterAST)2 TextRange (com.intellij.openapi.util.TextRange)2 StubElement (com.intellij.psi.stubs.StubElement)2 Processor (com.intellij.util.Processor)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 LogEventException (com.intellij.diagnostic.LogEventException)1 DuplicatesProfile (com.intellij.dupLocator.DuplicatesProfile)1 DuplocatorState (com.intellij.dupLocator.DuplocatorState)1