use of com.intellij.psi.stubs.IStubElementType in project kotlin by JetBrains.
the class KtStubElementType method createStubDependingOnParent.
private static boolean createStubDependingOnParent(ASTNode node) {
ASTNode parent = node.getTreeParent();
IElementType parentType = parent.getElementType();
if (parentType instanceof IStubElementType) {
return ((IStubElementType) parentType).shouldCreateStub(parent);
}
if (parentType instanceof IStubFileElementType) {
return true;
}
return false;
}
use of com.intellij.psi.stubs.IStubElementType in project intellij-community by JetBrains.
the class TreeUtil method bindStubsToTree.
public static void bindStubsToTree(@NotNull PsiFileImpl file, @NotNull StubTree stubTree, @NotNull FileElement tree) throws StubBindingException {
final ListIterator<StubElement<?>> stubs = stubTree.getPlainList().listIterator();
// skip file root stub
stubs.next();
final IStubFileElementType type = file.getElementTypeForStubBuilder();
assert type != null;
final StubBuilder builder = type.getBuilder();
tree.acceptTree(new RecursiveTreeElementWalkingVisitor() {
@Override
protected void visitNode(TreeElement node) {
CompositeElement parent = node.getTreeParent();
if (parent != null && builder.skipChildProcessingWhenBuildingStubs(parent, node)) {
return;
}
IElementType type = node.getElementType();
if (type instanceof IStubElementType && ((IStubElementType) type).shouldCreateStub(node)) {
final StubElement stub = stubs.hasNext() ? stubs.next() : null;
if (stub == null || stub.getStubType() != type) {
throw new StubBindingException("stub:" + stub + ", AST:" + type);
}
StubBasedPsiElementBase psi = (StubBasedPsiElementBase) node.getPsi();
//noinspection unchecked
((StubBase) stub).setPsi(psi);
psi.setStubIndex(stubs.previousIndex());
}
super.visitNode(node);
}
});
}
use of com.intellij.psi.stubs.IStubElementType in project intellij-community by JetBrains.
the class SmartPsiElementPointerImpl method createAnchorInfo.
@Nullable
private static SmartPointerElementInfo createAnchorInfo(@NotNull PsiElement element, @NotNull PsiFile containingFile) {
if (element instanceof StubBasedPsiElement && containingFile instanceof PsiFileWithStubSupport) {
PsiFileWithStubSupport stubFile = (PsiFileWithStubSupport) containingFile;
StubTree stubTree = stubFile.getStubTree();
if (stubTree != null) {
// use stubs when tree is not loaded
StubBasedPsiElement stubPsi = (StubBasedPsiElement) element;
int stubId = PsiAnchor.calcStubIndex(stubPsi);
IStubElementType myStubElementType = stubPsi.getElementType();
IStubFileElementType elementTypeForStubBuilder = ((PsiFileImpl) containingFile).getElementTypeForStubBuilder();
if (stubId != -1 && elementTypeForStubBuilder != null) {
// TemplateDataElementType is not IStubFileElementType
return new AnchorElementInfo(element, stubFile, stubId, myStubElementType);
}
}
}
Pair<Identikit.ByAnchor, PsiElement> pair = Identikit.withAnchor(element, LanguageUtil.getRootLanguage(containingFile));
if (pair != null) {
return new AnchorElementInfo(pair.second, containingFile, pair.first);
}
return null;
}
use of com.intellij.psi.stubs.IStubElementType in project intellij-community by JetBrains.
the class AnchorElementInfo method restoreElement.
@Override
@Nullable
public PsiElement restoreElement() {
long typeAndId = myStubElementTypeAndId;
int stubId = (int) typeAndId;
if (stubId != -1) {
PsiFile file = restoreFile();
if (!(file instanceof PsiFileWithStubSupport))
return null;
short index = (short) (typeAndId >> 32);
IStubElementType stubElementType = (IStubElementType) IElementType.find(index);
return PsiAnchor.restoreFromStubIndex((PsiFileWithStubSupport) file, stubId, stubElementType, false);
}
return super.restoreElement();
}
use of com.intellij.psi.stubs.IStubElementType in project intellij-community by JetBrains.
the class GrTypeDefinitionImpl method getScope.
@Nullable
@Override
public PsiElement getScope() {
final GrTypeDefinitionStub stub = getStub();
if (stub != null) {
return stub.getParentStub().getPsi();
}
ASTNode treeElement = getNode();
ASTNode parent = treeElement.getTreeParent();
while (parent != null) {
if (parent.getElementType() instanceof IStubElementType && !(parent.getElementType() == GroovyElementTypes.CLASS_BODY)) {
return parent.getPsi();
}
parent = parent.getTreeParent();
}
return getContainingFile();
}
Aggregations