mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Cleanup (new test case; simplification)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,8 +25,6 @@ import com.intellij.psi.impl.source.JavaLightStubBuilder;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.testFramework.LightIdeaTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
@@ -460,9 +458,35 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
" THROWS_LIST:PsiRefListStub[THROWS_LIST:]\n");
|
||||
}
|
||||
|
||||
public void testLocalClass() {
|
||||
doTest("class C {\n" +
|
||||
" void m() {\n" +
|
||||
" class L { }\n" +
|
||||
" }\n" +
|
||||
"}",
|
||||
|
||||
"PsiJavaFileStub []\n" +
|
||||
" IMPORT_LIST:PsiImportListStub\n" +
|
||||
" CLASS:PsiClassStub[name=C fqn=C]\n" +
|
||||
" MODIFIER_LIST:PsiModifierListStub[mask=4096]\n" +
|
||||
" TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" +
|
||||
" EXTENDS_LIST:PsiRefListStub[EXTENDS_LIST:]\n" +
|
||||
" IMPLEMENTS_LIST:PsiRefListStub[IMPLEMENTS_LIST:]\n" +
|
||||
" METHOD:PsiMethodStub[m:void]\n" +
|
||||
" MODIFIER_LIST:PsiModifierListStub[mask=4096]\n" +
|
||||
" TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" +
|
||||
" PARAMETER_LIST:PsiParameterListStub\n" +
|
||||
" THROWS_LIST:PsiRefListStub[THROWS_LIST:]\n" +
|
||||
" CLASS:PsiClassStub[name=L fqn=null]\n" +
|
||||
" MODIFIER_LIST:PsiModifierListStub[mask=4096]\n" +
|
||||
" TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" +
|
||||
" EXTENDS_LIST:PsiRefListStub[EXTENDS_LIST:]\n" +
|
||||
" IMPLEMENTS_LIST:PsiRefListStub[IMPLEMENTS_LIST:]\n");
|
||||
}
|
||||
|
||||
public void testSOEProof() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final SecureRandom random = new SecureRandom();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
SecureRandom random = new SecureRandom();
|
||||
sb.append("class SOE_test {\n BigInteger BIG = new BigInteger(\n");
|
||||
int i;
|
||||
for (i = 0; i < 100000; i++) {
|
||||
@@ -470,9 +494,9 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
}
|
||||
sb.append(" \"\");\n}");
|
||||
|
||||
final PsiJavaFile file = (PsiJavaFile)createLightFile("SOE_test.java", sb.toString());
|
||||
PsiJavaFile file = (PsiJavaFile)createLightFile("SOE_test.java", sb.toString());
|
||||
long t = System.currentTimeMillis();
|
||||
final StubElement tree = NEW_BUILDER.buildStubTree(file);
|
||||
StubElement tree = NEW_BUILDER.buildStubTree(file);
|
||||
t = System.currentTimeMillis() - t;
|
||||
assertEquals("PsiJavaFileStub []\n" +
|
||||
" IMPORT_LIST:PsiImportListStub\n" +
|
||||
@@ -488,51 +512,31 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
}
|
||||
|
||||
public void testPerformance() throws Exception {
|
||||
final String path = PathManagerEx.getTestDataPath() + "/psi/stub/StubPerformanceTest.java";
|
||||
String path = PathManagerEx.getTestDataPath() + "/psi/stub/StubPerformanceTest.java";
|
||||
String text = FileUtil.loadFile(new File(path));
|
||||
final PsiJavaFile file = (PsiJavaFile)createLightFile("test.java", text);
|
||||
|
||||
PlatformTestUtil.startPerformanceTest("Source file size: " + text.length(), 2000, new ThrowableRunnable() {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
NEW_BUILDER.buildStubTree(file);
|
||||
}
|
||||
}).cpuBound().assertTiming();
|
||||
PsiJavaFile file = (PsiJavaFile)createLightFile("test.java", text);
|
||||
String message = "Source file size: " + text.length();
|
||||
PlatformTestUtil.startPerformanceTest(message, 2000, () -> NEW_BUILDER.buildStubTree(file)).cpuBound().assertTiming();
|
||||
}
|
||||
|
||||
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();
|
||||
private static void doTest(String source, @Nullable String expected) {
|
||||
PsiJavaFile file = (PsiJavaFile)createLightFile("test.java", source);
|
||||
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);
|
||||
StubElement lightTree = NEW_BUILDER.buildStubTree(file);
|
||||
assertFalse(fileNode.isParsed());
|
||||
|
||||
file.getNode().getChildren(null); // force switch to AST
|
||||
StubElement astBasedTree = NEW_BUILDER.buildStubTree(file);
|
||||
assertTrue(fileNode.isParsed());
|
||||
|
||||
long t2 = System.nanoTime();
|
||||
final StubElement lighterTree2 = NEW_BUILDER.buildStubTree(file); // build over AST
|
||||
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);
|
||||
}
|
||||
String lightStr = DebugUtil.stubTreeToString(lightTree);
|
||||
String lightStr2 = DebugUtil.stubTreeToString(astBasedTree);
|
||||
if (expected != null) {
|
||||
assertEquals("light tree differs", expected, lightStr);
|
||||
assertEquals("AST-based tree differs", expected, lightStr2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user