Java Code Examples for com.intellij.psi.impl.source.PsiFileImpl#calcTreeElement()

The following examples show how to use com.intellij.psi.impl.source.PsiFileImpl#calcTreeElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StubBasedPsiElementBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures this element is AST-based. This is an expensive operation that might take significant time and allocate lots of objects,
 * so it should be to be avoided if possible.
 *
 * @return an AST node corresponding to this element. If the element is currently operating via stubs,
 * this causes AST to be loaded for the whole file and all stub-based PSI elements in this file (including the current one)
 * to be switched from stub to AST. So, after this call {@link #getStub()} will return null.
 */
@Override
@Nonnull
public ASTNode getNode() {
  if (mySubstrateRef instanceof SubstrateRef.StubRef) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    PsiFileImpl file = (PsiFileImpl)getContainingFile();
    if (!file.isValid()) throw new PsiInvalidElementAccessException(file);

    FileElement treeElement = file.getTreeElement();
    if (treeElement != null && mySubstrateRef instanceof SubstrateRef.StubRef) {
      return notBoundInExistingAst(file, treeElement);
    }

    treeElement = file.calcTreeElement();
    if (mySubstrateRef instanceof SubstrateRef.StubRef) {
      return failedToBindStubToAst(file, treeElement);
    }
  }

  return mySubstrateRef.getNode();
}
 
Example 2
Source File: PsiDocumentManagerBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
public void reparseFileFromText(@Nonnull PsiFileImpl file) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (isCommitInProgress()) throw new IllegalStateException("Re-entrant commit is not allowed");

  FileElement node = file.calcTreeElement();
  CharSequence text = node.getChars();
  ourIsFullReparseInProgress = true;
  try {
    WriteAction.run(() -> {
      ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
      if (indicator == null) indicator = new EmptyProgressIndicator();
      DiffLog log = BlockSupportImpl.makeFullParse(file, node, text, indicator, text).log;
      log.doActualPsiChange(file);
      file.getViewProvider().contentsSynchronized();
    });
  }
  finally {
    ourIsFullReparseInProgress = false;
  }
}
 
Example 3
Source File: CsvAnnotatorTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingDataWrapper data) {
    Project project = myFixture.getProject();
    EdtTestUtil.runInEdtAndWait(() -> {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
    });
    PsiFileImpl file = (PsiFileImpl)this.getHostFile();
    FileElement hardRefToFileElement = file.calcTreeElement();
    if (!DumbService.isDumb(project)) {
        ServiceManager.getService(project, CacheManager.class).getFilesWithWord("XXX", (short)2, GlobalSearchScope.allScope(project), true);
    }

    long start = System.currentTimeMillis();
    Disposable disposable = Disposer.newDisposable();

    List<HighlightInfo> infos;
    try {
        infos = myFixture.doHighlighting();
        this.removeDuplicatedRangesForInjected(infos);
    } finally {
        Disposer.dispose(disposable);
    }

    long elapsed = System.currentTimeMillis() - start;
    data.checkResultWrapper(file, infos, file.getText());
    hardRefToFileElement.hashCode();
    return elapsed;
}
 
Example 4
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private long collectAndCheckHighlighting(@Nonnull ExpectedHighlightingData data) {
    final Project project = getProject();
    PsiDocumentManager.getInstance(project).commitAllDocuments();

    PsiFileImpl file = (PsiFileImpl)getHostFile();
    FileElement hardRefToFileElement = file.calcTreeElement();//to load text

    //to initialize caches
    if (!DumbService.isDumb(project)) {
      CacheManager.getInstance(project).getFilesWithWord(XXX, UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(project), true);
    }

    List<HighlightInfo> infos;
    final long start = System.currentTimeMillis();
    try {
      ((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(myJavaFilesFilter, myTestRootDisposable);

//    ProfilingUtil.startCPUProfiling();
      infos = doHighlighting();
      removeDuplicatedRangesForInjected(infos);
//    ProfilingUtil.captureCPUSnapshot("testing");
    }
    finally {
      ((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable);
    }
    final long elapsed = System.currentTimeMillis() - start;

    data.checkResult(infos, file.getText());
    hardRefToFileElement.hashCode(); // use it so gc won't collect it
    return elapsed;
  }