com.intellij.psi.stubs.PsiFileStub Java Examples

The following examples show how to use com.intellij.psi.stubs.PsiFileStub. 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: SubstrateRef.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public PsiFile getContainingFile() {
  StubElement stub = myStub;
  while (!(stub instanceof PsiFileStub)) {
    stub = stub.getParentStub();
  }
  PsiFile psi = (PsiFile)stub.getPsi();
  if (psi != null) {
    return psi;
  }
  return reportError(stub);
}
 
Example #2
Source File: PsiInvalidElementAccessException.java    From consulo with Apache License 2.0 4 votes vote down vote up
@NonNls
@Nonnull
private static String reason(@Nonnull PsiElement root) {
  if (root == PsiUtilCore.NULL_PSI_ELEMENT) return "NULL_PSI_ELEMENT";

  PsiElement element = root instanceof PsiFile ? root : root.getParent();
  if (element == null) {
    String m = "parent is null";
    if (root instanceof StubBasedPsiElement) {
      StubElement stub = ((StubBasedPsiElement)root).getStub();
      while (stub != null) {
        m += "\n  each stub=" + stub;
        if (stub instanceof PsiFileStub) {
          m += "; fileStub.psi=" + stub.getPsi() + "; reason=" + ((PsiFileStub)stub).getInvalidationReason();
        }
        stub = stub.getParentStub();
      }
    }
    return m;
  }

  while (element != null && !(element instanceof PsiFile)) element = element.getParent();
  PsiFile file = (PsiFile)element;
  if (file == null) return "containing file is null";

  FileViewProvider provider = file.getViewProvider();
  VirtualFile vFile = provider.getVirtualFile();
  if (!vFile.isValid()) return vFile + " is invalid";
  if (!provider.isPhysical()) {
    PsiElement context = file.getContext();
    if (context != null && !context.isValid()) {
      return "invalid context: " + reason(context);
    }
  }

  PsiManager manager = file.getManager();
  if (manager.getProject().isDisposed()) return "project is disposed";

  Language language = file.getLanguage();
  if (language != provider.getBaseLanguage()) return "File language:" + language + " != Provider base language:" + provider.getBaseLanguage();

  FileViewProvider p = manager.findViewProvider(vFile);
  if (provider != p) return "different providers: " + provider + "(" + id(provider) + "); " + p + "(" + id(p) + ")";

  if (!provider.isPhysical()) return "non-physical provider: " + provider; // "dummy" file?

  return "psi is outdated";
}