Beispiel #1
0
 @NotNull
 private Getter<FileElement> createTreeElementPointer(@NotNull FileElement treeElement) {
   if (isKeepTreeElementByHardReference()) {
     return treeElement;
   }
   return myManager.isBatchFilesProcessingMode()
       ? new PatchedWeakReference<FileElement>(treeElement)
       : new SoftReference<FileElement>(treeElement);
 }
Beispiel #2
0
 @Override
 public boolean isValid() {
   FileViewProvider provider = getViewProvider();
   final VirtualFile vFile = provider.getVirtualFile();
   if (!vFile.isValid()) return false;
   if (!provider.isEventSystemEnabled()) return true; // "dummy" file
   if (myManager.getProject().isDisposed()) return false;
   return isPsiUpToDate(vFile);
 }
Beispiel #3
0
 protected boolean isPsiUpToDate(@NotNull VirtualFile vFile) {
   final FileViewProvider provider = myManager.findViewProvider(vFile);
   Language language = getLanguage();
   if (provider == null || provider.getPsi(language) == this) { // provider == null in tests
     return true;
   }
   Language baseLanguage = provider.getBaseLanguage();
   return baseLanguage != language && provider.getPsi(baseLanguage) == this;
 }
 public PsiElementFactoryImpl(final PsiManagerEx manager) {
   super(manager);
   manager.registerRunnableToRunOnChange(
       new Runnable() {
         @Override
         public void run() {
           myCachedObjectType.clear();
         }
       });
 }
Beispiel #5
0
  @NotNull
  private FileElement loadTreeElement() {
    ApplicationManager.getApplication().assertReadAccessAllowed();

    final FileViewProvider viewProvider = getViewProvider();
    if (viewProvider.isPhysical()
        && myManager.isAssertOnFileLoading(viewProvider.getVirtualFile())) {
      LOG.error(
          "Access to tree elements not allowed in tests. path='"
              + viewProvider.getVirtualFile().getPresentableUrl()
              + "'");
    }

    Document cachedDocument =
        FileDocumentManager.getInstance().getCachedDocument(getViewProvider().getVirtualFile());

    FileElement treeElement = createFileElement(viewProvider.getContents());
    treeElement.setPsi(this);

    List<Pair<StubBasedPsiElementBase, CompositeElement>> bindings =
        calcStubAstBindings(treeElement, cachedDocument);

    synchronized (PsiLock.LOCK) {
      FileElement existing = derefTreeElement();
      if (existing != null) {
        return existing;
      }

      switchFromStubToAst(bindings);
      myStub = null;
      myTreeElementPointer = createTreeElementPointer(treeElement);

      if (LOG.isDebugEnabled() && viewProvider.isPhysical()) {
        LOG.debug("Loaded text for file " + viewProvider.getVirtualFile().getPresentableUrl());
      }

      return treeElement;
    }
  }