Skip to content

Commit ce779c0

Browse files
committed
backport new approach to walt a stub tree
1 parent cbc4989 commit ce779c0

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/StubTestBase.kt

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.vk.kphpstorm.testing.infrastructure
22

3-
import com.intellij.psi.impl.DebugUtil
3+
import com.intellij.openapi.util.text.StringUtil
4+
import com.intellij.psi.stubs.PsiFileStubImpl
5+
import com.intellij.psi.stubs.Stub
6+
import com.intellij.psi.stubs.StubElement
7+
import com.jetbrains.php.lang.documentation.phpdoc.psi.stubs.PhpDocTagStub
48
import com.jetbrains.php.lang.psi.stubs.PhpFileStubBuilder
59
import com.vk.kphpstorm.configuration.KphpStormConfiguration
610
import java.io.File
@@ -19,7 +23,7 @@ abstract class StubTestBase : KphpStormTestBase() {
1923
myFixture.configureByFile(fixtureFile)
2024

2125
val stubTree = stubBuilder.buildStubTree(myFixture.file)
22-
val stubTreeString = DebugUtil.stubTreeToString(stubTree)
26+
val stubTreeString = dumpToString(stubTree)
2327

2428
val expectedFileRelPath = fixtureFile.replace(".fixture.php", ".stub.php")
2529
if (fixtureFile == expectedFileRelPath) {
@@ -35,4 +39,45 @@ abstract class StubTestBase : KphpStormTestBase() {
3539

3640
assertSameLinesWithFile(expectedFile.absolutePath, stubTreeString)
3741
}
42+
43+
44+
private fun dumpToString(node: StubElement<*>): String {
45+
val buffer = StringBuilder()
46+
dumpToString(node, buffer, 0)
47+
48+
return buffer.toString()
49+
}
50+
51+
private fun dumpToString(node: StubElement<*>, buffer: StringBuilder, indent: Int) {
52+
StringUtil.repeatSymbol(buffer, ' ', indent)
53+
54+
val presentable = getPresentable(node)
55+
56+
if (presentable != null) {
57+
buffer.append(presentable.toString()).append(':')
58+
}
59+
60+
buffer.append(node.toString()).append('\n')
61+
62+
for (child in node.childrenStubs) {
63+
dumpToString(child, buffer, indent + 2)
64+
}
65+
}
66+
67+
@Suppress("UnstableApiUsage")
68+
private fun getPresentable(node: Stub): Any? {
69+
return when (node) {
70+
is PsiFileStubImpl<*> -> {
71+
null
72+
}
73+
74+
is PhpDocTagStub -> {
75+
"${node.elementType} {name: ${node.name}${if (node.value != null) ", value: " + node.value else ""}}"
76+
}
77+
78+
else -> {
79+
if (node is StubElement<*>) node.elementType else node.stubSerializer
80+
}
81+
}
82+
}
3883
}

0 commit comments

Comments
 (0)