use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PsiClassImpl method isAnonymousOrLocal.
private static boolean isAnonymousOrLocal(PsiClass aClass) {
if (aClass instanceof PsiAnonymousClass)
return true;
final PsiClassStub stub = ((PsiClassImpl) aClass).getGreenStub();
if (stub != null) {
final StubElement parentStub = stub.getParentStub();
return !(parentStub instanceof PsiClassStub || parentStub instanceof PsiFileStub);
}
PsiElement parent = aClass.getParent();
while (parent != null) {
if (parent instanceof PsiMethod || parent instanceof PsiField || parent instanceof PsiClassInitializer)
return true;
if (parent instanceof PsiClass || parent instanceof PsiFile)
return false;
parent = parent.getParent();
}
return false;
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PsiAnchor method calcStubIndex.
public static int calcStubIndex(@NotNull StubBasedPsiElement psi) {
if (psi instanceof PsiFile) {
return 0;
}
final StubElement liveStub = psi.getStub();
if (liveStub != null) {
return ((StubBase) liveStub).id;
}
PsiFileImpl file = (PsiFileImpl) psi.getContainingFile();
final StubTree stubTree = file.calcStubTree();
for (StubElement<?> stb : stubTree.getPlainList()) {
if (stb.getPsi() == psi) {
return ((StubBase) stb).id;
}
}
// it is possible via custom stub builder intentionally not producing stubs for stubbed elements
return -1;
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class PsiAnchor method restoreFromStubIndex.
@Nullable
public static PsiElement restoreFromStubIndex(PsiFileWithStubSupport fileImpl, int index, @NotNull IStubElementType elementType, boolean throwIfNull) {
if (fileImpl == null) {
if (throwIfNull)
throw new AssertionError("Null file");
return null;
}
StubTree tree = fileImpl.getStubTree();
if (tree == null) {
if (fileImpl instanceof PsiFileImpl) {
// Note: as far as this is a realization of StubIndexReference fileImpl#getContentElementType() must be instance of IStubFileElementType
tree = ((PsiFileImpl) fileImpl).calcStubTree();
} else {
if (throwIfNull)
throw new AssertionError("Not PsiFileImpl: " + fileImpl.getClass());
return null;
}
}
List<StubElement<?>> list = tree.getPlainList();
if (index >= list.size()) {
if (throwIfNull)
throw new AssertionError("Too large index: " + index + ">=" + list.size());
return null;
}
StubElement stub = list.get(index);
if (stub.getStubType() != elementType) {
if (throwIfNull)
throw new AssertionError("Element type mismatch: " + stub.getStubType() + "!=" + elementType);
return null;
}
return stub.getPsi();
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class Test method testSOEProof.
public void testSOEProof() {
final StringBuilder sb = new StringBuilder();
final SecureRandom random = new SecureRandom();
sb.append("class SOE_test {\n BigInteger BIG = new BigInteger(\n");
int i;
for (i = 0; i < 100000; i++) {
sb.append(" \"").append(Math.abs(random.nextInt())).append("\" +\n");
}
sb.append(" \"\");\n}");
final PsiJavaFile file = (PsiJavaFile) createLightFile("SOE_test.java", sb.toString());
long t = System.currentTimeMillis();
final StubElement tree = NEW_BUILDER.buildStubTree(file);
t = System.currentTimeMillis() - t;
assertEquals("PsiJavaFileStub []\n" + " IMPORT_LIST:PsiImportListStub\n" + " CLASS:PsiClassStub[name=SOE_test fqn=SOE_test]\n" + " MODIFIER_LIST:PsiModifierListStub[mask=4096]\n" + " TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" + " EXTENDS_LIST:PsiRefListStub[EXTENDS_LIST:]\n" + " IMPLEMENTS_LIST:PsiRefListStub[IMPLEMENTS_LIST:]\n" + " FIELD:PsiFieldStub[BIG:BigInteger=;INITIALIZER_NOT_STORED;]\n" + " MODIFIER_LIST:PsiModifierListStub[mask=4096]\n", DebugUtil.stubTreeToString(tree));
System.out.println("SOE depth=" + i + ", time=" + t + "ms");
}
use of com.intellij.psi.stubs.StubElement in project intellij-community by JetBrains.
the class Test method doTest.
private static void doTest(@NonNls final String source, @NonNls @Nullable final String tree) {
final PsiJavaFile file = (PsiJavaFile) createLightFile("test.java", source);
final FileASTNode fileNode = file.getNode();
assertNotNull(fileNode);
assertFalse(fileNode.isParsed());
long t1 = System.nanoTime();
final StubElement lighterTree = NEW_BUILDER.buildStubTree(file);
t1 = Math.max((System.nanoTime() - t1) / 1000, 1);
assertFalse(fileNode.isParsed());
// force switch to AST
file.getNode().getChildren(null);
long t2 = System.nanoTime();
// build over AST
final StubElement lighterTree2 = NEW_BUILDER.buildStubTree(file);
t2 = Math.max((System.nanoTime() - t2) / 1000, 1);
file.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
assert !(element instanceof PsiErrorElement) : element;
super.visitElement(element);
}
});
final String lightStr = DebugUtil.stubTreeToString(lighterTree);
final String lightStr2 = DebugUtil.stubTreeToString(lighterTree2);
if (tree != null) {
System.out.println("light=" + t1 + "mks, heavy=" + t2 + "mks");
if (!tree.isEmpty()) {
assertEquals("light tree differs", tree, lightStr);
assertEquals("light tree (2nd) differs", tree, lightStr2);
}
}
}
Aggregations