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;
}
}
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);
}
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);
}
};
}
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;
}
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;
}
}
Aggregations