diff --git a/src/main/kotlin/com/vk/kphpstorm/kphptags/psi/KphpDocTagStubImpl.kt b/src/main/kotlin/com/vk/kphpstorm/kphptags/psi/KphpDocTagStubImpl.kt index a47c0b0f..16d3b093 100644 --- a/src/main/kotlin/com/vk/kphpstorm/kphptags/psi/KphpDocTagStubImpl.kt +++ b/src/main/kotlin/com/vk/kphpstorm/kphptags/psi/KphpDocTagStubImpl.kt @@ -11,6 +11,8 @@ import com.jetbrains.php.lang.psi.resolve.types.PhpType * When @kphp-... tags (regardless of elementType) are stored as stubs, * they hold only name and optional arbitrary string value. * Similar to [com.jetbrains.php.lang.documentation.phpdoc.psi.stubs.PhpDocTagStubImpl] + * + * TODO: make a research to check are we really need stubs? */ class KphpDocTagStubImpl( parent: StubElement<*>?, @@ -22,4 +24,6 @@ class KphpDocTagStubImpl( override fun getType() = PhpType() override fun getName() = name override fun getValue() = value + + override fun toString(): String = "$name${if (value != null) ": $value" else ""}" } diff --git a/src/test/fixtures/kphp_stub/kphp-json.fixture.php b/src/test/fixtures/kphp_stub/kphp-json.fixture.php new file mode 100644 index 00000000..c965a018 --- /dev/null +++ b/src/test/fixtures/kphp_stub/kphp-json.fixture.php @@ -0,0 +1,12 @@ +): String { + val buffer = StringBuilder() + dumpToString(node, buffer, 0) + + return buffer.toString() + } + + private fun dumpToString(node: StubElement<*>, buffer: StringBuilder, indent: Int) { + StringUtil.repeatSymbol(buffer, ' ', indent) + + val presentable = getPresentable(node) + + if (presentable != null) { + buffer.append(presentable.toString()).append(':') + } + + buffer.append(node.toString()).append('\n') + + for (child in node.childrenStubs) { + dumpToString(child, buffer, indent + 2) + } + } + + @Suppress("UnstableApiUsage") + private fun getPresentable(node: Stub): Any? { + return when (node) { + is PsiFileStubImpl<*> -> { + null + } + + is PhpDocTagStub -> { + "${node.stubType} {name: ${node.name}${if (node.value != null) ", value: " + node.value else ""}}" + } + + else -> node.stubType + } + } +} diff --git a/src/test/kotlin/com/vk/kphpstorm/testing/tests/KphpStubTest.kt b/src/test/kotlin/com/vk/kphpstorm/testing/tests/KphpStubTest.kt new file mode 100644 index 00000000..ca593f77 --- /dev/null +++ b/src/test/kotlin/com/vk/kphpstorm/testing/tests/KphpStubTest.kt @@ -0,0 +1,25 @@ +package com.vk.kphpstorm.testing.tests + +import com.vk.kphpstorm.testing.infrastructure.StubTestBase + +class KphpStubTest : StubTestBase() { + fun testKphpJson() { + doStubTest("kphp_stub/kphp-json.fixture.php") + } + + fun testKphpSimpleTags() { + doStubTest("kphp_stub/kphp-simple-tags.fixture.php") + } + + fun testKphpTemplate() { + doStubTest("kphp_stub/kphp-template.fixture.php") + } + + fun testKphpWarnPerformance() { + doStubTest("kphp_stub/kphp-warn-performance.fixture.php") + } + + fun testKphpSerialize() { + doStubTest("kphp_stub/kphp-serialize.fixture.php") + } +}