Skip to content

Commit 79f110a

Browse files
authored
introduce custom stub factory to fix illegal argument exception while PSI creation (#75)
1 parent 5abb5c1 commit 79f110a

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.vk.kphpstorm.kphptags.psi.stubs
2+
3+
import com.intellij.psi.PsiElement
4+
import com.intellij.psi.stubs.StubElement
5+
import com.intellij.psi.stubs.StubElementFactory
6+
import com.intellij.psi.tree.IElementType
7+
import com.intellij.util.io.StringRef
8+
import com.jetbrains.php.lang.documentation.phpdoc.psi.impl.tags.PhpDocTagImpl
9+
import com.jetbrains.php.lang.documentation.phpdoc.psi.stubs.PhpDocTagStub
10+
import com.jetbrains.php.lang.documentation.phpdoc.psi.stubs.PhpDocTagStubImpl
11+
12+
@Suppress("UnstableApiUsage")
13+
class KphpDocTagStubFactory(private val elementType: IElementType) : StubElementFactory<PhpDocTagStub, PhpDocTagImpl> {
14+
override fun createStub(psi: PhpDocTagImpl, parentStub: StubElement<out PsiElement>?): PhpDocTagStub {
15+
return PhpDocTagStubImpl(
16+
parentStub,
17+
elementType,
18+
StringRef.fromString(psi.name),
19+
null
20+
)
21+
}
22+
23+
override fun createPsi(stub: PhpDocTagStub): PhpDocTagImpl {
24+
return PhpDocTagImpl(stub, stub.elementType)
25+
}
26+
}

src/main/kotlin/com/vk/kphpstorm/kphptags/psi/stubs/KphpStubRegistryExtension.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.vk.kphpstorm.kphptags.psi.stubs
33
import com.intellij.psi.stubs.StubRegistry
44
import com.intellij.psi.stubs.StubRegistryExtension
55
import com.jetbrains.php.lang.documentation.phpdoc.psi.stubs.PhpDocTagStubSerializer
6-
import com.jetbrains.php.lang.psi.stubs.stub_factories.PhpDocTagStubFactory
76
import com.vk.kphpstorm.kphptags.psi.KphpDocElementTypes
87

98
@Suppress("UnstableApiUsage")
@@ -38,7 +37,7 @@ class KphpStubRegistryExtension : StubRegistryExtension {
3837
private fun registerFactories(registry: StubRegistry) {
3938
registry.registerStubFactory(
4039
KphpDocElementTypes.kphpDocTagSimple,
41-
PhpDocTagStubFactory(KphpDocElementTypes.kphpDocTagSimple)
40+
KphpDocTagStubFactory(KphpDocElementTypes.kphpDocTagSimple)
4241
)
4342

4443
registry.registerStubFactory(
@@ -48,12 +47,12 @@ class KphpStubRegistryExtension : StubRegistryExtension {
4847

4948
registry.registerStubFactory(
5049
KphpDocElementTypes.kphpDocTagWarnPerformance,
51-
PhpDocTagStubFactory(KphpDocElementTypes.kphpDocTagWarnPerformance)
50+
KphpDocTagStubFactory(KphpDocElementTypes.kphpDocTagWarnPerformance)
5251
)
5352

5453
registry.registerStubFactory(
5554
KphpDocElementTypes.kphpDocTagJson,
56-
PhpDocTagStubFactory(KphpDocElementTypes.kphpDocTagJson)
55+
KphpDocTagStubFactory(KphpDocElementTypes.kphpDocTagJson)
5756
)
5857
}
5958
}

0 commit comments

Comments
 (0)