Java Code Examples for com.intellij.psi.stubs.StubElement#getPsi()
The following examples show how to use
com.intellij.psi.stubs.StubElement#getPsi() .
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: PsiTreeUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static <T extends PsiElement> List<T> getStubChildrenOfTypeAsList(@Nullable PsiElement element, @Nonnull Class<T> aClass) { if (element == null) return Collections.emptyList(); StubElement<?> stub = element instanceof StubBasedPsiElement ? ((StubBasedPsiElement)element).getStub() : null; if (stub == null) { return getChildrenOfTypeAsList(element, aClass); } List<T> result = new SmartList<>(); for (StubElement childStub : stub.getChildrenStubs()) { PsiElement child = childStub.getPsi(); if (aClass.isInstance(child)) { result.add(aClass.cast(child)); } } return result; }
Example 2
Source File: ShaderLabFile.java From consulo-unity3d with Apache License 2.0 | 5 votes |
@Nullable public ShaderDef getShaderDef() { StubElement<?> stub = getStub(); if(stub != null) { StubElement<ShaderDef> childStubByType = stub.findChildStubByType(ShaderLabStubElements.SHADER_DEF); if(childStubByType != null) { return childStubByType.getPsi(); } } return findChildByClass(ShaderDef.class); }
Example 3
Source File: PsiTreeUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @Contract("null -> null") public static PsiElement getStubOrPsiParent(@Nullable PsiElement element) { if (element instanceof StubBasedPsiElement) { StubBase stub = (StubBase)((StubBasedPsiElement)element).getStub(); if (stub != null) { //noinspection unchecked final StubElement parentStub = stub.getParentStub(); return parentStub != null ? parentStub.getPsi() : null; } } return element != null ? element.getParent() : null; }
Example 4
Source File: SubstrateRef.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isValid() { StubElement parent = myStub.getParentStub(); if (parent == null) { LOG.error("No parent for stub " + myStub + " of class " + myStub.getClass()); return false; } PsiElement psi = parent.getPsi(); return psi != null && psi.isValid(); }
Example 5
Source File: SubstrateRef.java From consulo with Apache License 2.0 | 5 votes |
@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 6
Source File: PsiInvalidElementAccessException.java From consulo with Apache License 2.0 | 4 votes |
@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"; }