Search in sources :

Example 6 with VirtualFileWithId

use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.

the class PsiFileImpl method calcStubTree.

@NotNull
public StubTree calcStubTree() {
    StubTree tree = derefStub();
    if (tree != null) {
        return tree;
    }
    assert myFileElementBeingLoaded.get() == null : "non-empty thread-local";
    FileElement fileElement = calcTreeElement();
    synchronized (myStubFromTreeLock) {
        tree = derefStub();
        if (tree == null) {
            ApplicationManager.getApplication().assertReadAccessAllowed();
            IStubFileElementType contentElementType = getElementTypeForStubBuilder();
            if (contentElementType == null) {
                VirtualFile vFile = getVirtualFile();
                String message = "ContentElementType: " + getContentElementType() + "; file: " + this + "\n\t" + "Boolean.TRUE.equals(getUserData(BUILDING_STUB)) = " + Boolean.TRUE.equals(getUserData(BUILDING_STUB)) + "\n\t" + "getTreeElement() = " + getTreeElement() + "\n\t" + "vFile instanceof VirtualFileWithId = " + (vFile instanceof VirtualFileWithId) + "\n\t" + "StubUpdatingIndex.canHaveStub(vFile) = " + StubTreeLoader.getInstance().canHaveStub(vFile);
                rebuildStub();
                throw new AssertionError(message);
            }
            StubElement currentStubTree = contentElementType.getBuilder().buildStubTree(this);
            if (currentStubTree == null) {
                throw new AssertionError("Stub tree wasn't built for " + contentElementType + "; file: " + this);
            }
            tree = new StubTree((PsiFileStub) currentStubTree);
            tree.setDebugInfo("created in calcStubTree");
            try {
                TreeUtil.bindStubsToTree(this, tree, fileElement);
            } catch (TreeUtil.StubBindingException e) {
                rebuildStub();
                throw new RuntimeException("Stub and PSI element type mismatch in " + getName(), e);
            }
            updateTrees(myTrees.withGreenStub(tree, this));
        }
        return tree;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with VirtualFileWithId

use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.

the class AstPath method getNodePath.

@Nullable
public static AstPath getNodePath(@NotNull CompositeElement node) {
    if (node instanceof FileElement) {
        PsiElement psi = node.getCachedPsi();
        if (!(psi instanceof PsiFileImpl))
            return null;
        PsiFileImpl file = (PsiFileImpl) psi;
        if (!(file.getVirtualFile() instanceof VirtualFileWithId) || file.getElementTypeForStubBuilder() == null) {
            return null;
        }
        return new RootPath(file);
    }
    return node.getUserData(NODE_PATH);
}
Also used : PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with VirtualFileWithId

use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.

the class IdFilter method buildProjectIdFilter.

@NotNull
private static IdFilter buildProjectIdFilter(Project project, boolean includeNonProjectItems) {
    long started = System.currentTimeMillis();
    final BitSet idSet = new BitSet();
    ContentIterator iterator = new ContentIterator() {

        @Override
        public boolean processFile(VirtualFile fileOrDir) {
            int id = ((VirtualFileWithId) fileOrDir).getId();
            // workaround for encountering invalid files, see EA-49915, EA-50599
            if (id < 0)
                id = -id;
            idSet.set(id);
            ProgressManager.checkCanceled();
            return true;
        }
    };
    if (!includeNonProjectItems) {
        ProjectRootManager.getInstance(project).getFileIndex().iterateContent(iterator);
    } else {
        FileBasedIndex.getInstance().iterateIndexableFiles(iterator, project, null);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Done filter " + (System.currentTimeMillis() - started) + ":" + idSet.size());
    }
    return new IdFilter() {

        @Override
        public boolean containsFileId(int id) {
            return id >= 0 && idSet.get(id);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) BitSet(java.util.BitSet) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with VirtualFileWithId

use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.

the class JavaScratchConfigurable method applyEditorTo.

@Override
public void applyEditorTo(@NotNull JavaScratchConfiguration configuration) throws ConfigurationException {
    myCommonProgramParameters.applyTo(configuration);
    myModuleSelector.applyTo(configuration);
    configuration.MAIN_CLASS_NAME = myMainClass.getComponent().getText().trim();
    configuration.ALTERNATIVE_JRE_PATH = myJrePathEditor.getJrePathOrName();
    configuration.ALTERNATIVE_JRE_PATH_ENABLED = myJrePathEditor.isAlternativeJreSelected();
    final VirtualFile vFile = getVFileFromEditor();
    configuration.SCRATCH_FILE_ID = vFile instanceof VirtualFileWithId ? ((VirtualFileWithId) vFile).getId() : 0;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId)

Example 10 with VirtualFileWithId

use of com.intellij.openapi.vfs.VirtualFileWithId in project intellij-community by JetBrains.

the class PsiFileImpl method getStubTree.

/**
   * @return a stub tree, if this file has it, and only if AST isn't loaded
   */
@Override
@Nullable
public StubTree getStubTree() {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    if (myTrees.astLoaded && !mayReloadStub())
        return null;
    if (Boolean.TRUE.equals(getUserData(BUILDING_STUB)))
        return null;
    final StubTree derefd = derefStub();
    if (derefd != null)
        return derefd;
    if (getElementTypeForStubBuilder() == null)
        return null;
    final VirtualFile vFile = getVirtualFile();
    if (!(vFile instanceof VirtualFileWithId) || !vFile.isValid())
        return null;
    ObjectStubTree tree = StubTreeLoader.getInstance().readOrBuild(getProject(), vFile, this);
    if (!(tree instanceof StubTree))
        return null;
    final FileViewProvider viewProvider = getViewProvider();
    final List<Pair<IStubFileElementType, PsiFile>> roots = StubTreeBuilder.getStubbedRoots(viewProvider);
    synchronized (PsiLock.LOCK) {
        if (getTreeElement() != null || hasUnbindableCachedPsi())
            return null;
        final StubTree derefdOnLock = derefStub();
        if (derefdOnLock != null)
            return derefdOnLock;
        PsiFileStub baseRoot = ((StubTree) tree).getRoot();
        if (baseRoot instanceof PsiFileStubImpl && !((PsiFileStubImpl) baseRoot).rootsAreSet()) {
            LOG.error("Stub roots must be set when stub tree was read or built with StubTreeLoader");
            return null;
        }
        final PsiFileStub[] stubRoots = baseRoot.getStubRoots();
        if (stubRoots.length != roots.size()) {
            final Function<PsiFileStub, String> stubToString = stub -> stub.getClass().getSimpleName();
            LOG.error("readOrBuilt roots = " + StringUtil.join(stubRoots, stubToString, ", ") + "; " + StubTreeLoader.getFileViewProviderMismatchDiagnostics(viewProvider));
            rebuildStub();
            return null;
        }
        // first, set all references from stubs to existing PSI (in AST or AstPathPsiMap)
        Map<PsiFileImpl, StubTree> bindings = prepareAllStubTrees(roots, stubRoots);
        StubTree result = bindings.get(this);
        assert result != null : "Current file not in root list: " + roots + ", vp=" + viewProvider;
        // now stubs can be safely published
        for (PsiFileImpl eachPsiRoot : bindings.keySet()) {
            eachPsiRoot.updateTrees(eachPsiRoot.myTrees.withExclusiveStub(bindings.get(eachPsiRoot), bindings.keySet()));
        }
        return result;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StubBasedPsiElementBase(com.intellij.extapi.psi.StubBasedPsiElementBase) com.intellij.openapi.util(com.intellij.openapi.util) com.intellij.psi.tree(com.intellij.psi.tree) java.util(java.util) Array(java.lang.reflect.Array) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileImplUtil(com.intellij.psi.impl.file.PsiFileImplUtil) com.intellij.psi.stubs(com.intellij.psi.stubs) ModalityState(com.intellij.openapi.application.ModalityState) Document(com.intellij.openapi.editor.Document) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) CodeEditUtil(com.intellij.psi.impl.source.codeStyle.CodeEditUtil) SearchScope(com.intellij.psi.search.SearchScope) ContainerUtil(com.intellij.util.containers.ContainerUtil) BlockSupportImpl(com.intellij.psi.impl.source.text.BlockSupportImpl) FileContextUtil(com.intellij.psi.impl.source.resolve.FileContextUtil) ItemPresentation(com.intellij.navigation.ItemPresentation) com.intellij.lang(com.intellij.lang) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) AtomicFieldUpdater(com.intellij.util.concurrency.AtomicFieldUpdater) com.intellij.psi.impl(com.intellij.psi.impl) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) PsiNavigationSupport(com.intellij.ide.util.PsiNavigationSupport) IncorrectOperationException(com.intellij.util.IncorrectOperationException) SoftReference(com.intellij.reference.SoftReference) StringUtil(com.intellij.openapi.util.text.StringUtil) FileContentUtilCore(com.intellij.util.FileContentUtilCore) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) com.intellij.psi.impl.source.tree(com.intellij.psi.impl.source.tree) Nullable(org.jetbrains.annotations.Nullable) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Queryable(com.intellij.openapi.ui.Queryable) PatchedWeakReference(com.intellij.util.PatchedWeakReference) Function(com.intellij.util.Function) ApplicationManager(com.intellij.openapi.application.ApplicationManager) FileManagerImpl(com.intellij.psi.impl.file.impl.FileManagerImpl) com.intellij.psi(com.intellij.psi) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull) Factory(com.intellij.openapi.util.Factory) CharArrayUtil(com.intellij.util.text.CharArrayUtil) javax.swing(javax.swing) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)16 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)5 Project (com.intellij.openapi.project.Project)2 FileAttributes (com.intellij.openapi.util.io.FileAttributes)2 FileInfo (com.intellij.openapi.util.io.win32.FileInfo)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 THashMap (gnu.trove.THashMap)2 DuplicatesProfile (com.intellij.dupLocator.DuplicatesProfile)1 DuplocatorState (com.intellij.dupLocator.DuplocatorState)1 LightDuplicateProfile (com.intellij.dupLocator.LightDuplicateProfile)1 FragmentsCollector (com.intellij.dupLocator.treeHash.FragmentsCollector)1 PsiFragment (com.intellij.dupLocator.util.PsiFragment)1 StubBasedPsiElementBase (com.intellij.extapi.psi.StubBasedPsiElementBase)1 DomSupportEnabled (com.intellij.ide.highlighter.DomSupportEnabled)1 PsiNavigationSupport (com.intellij.ide.util.PsiNavigationSupport)1 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)1