Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: added support for generics #5

Closed
wants to merge 61 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c01af26
initial implementation
i582 Mar 14, 2022
d373f2f
fixed situation when it was necessary to resolve a function during ty…
i582 Mar 14, 2022
1d35cff
added initial support for class generics
i582 Mar 15, 2022
df53c16
fixed type inference for shape with unresolved types
i582 Mar 15, 2022
19943d0
fixed type inference for non-template classes
i582 Mar 15, 2022
015d276
fixed NullPointerException when generic comment contains syntacticall…
i582 Mar 15, 2022
ebfa25c
added class TypeTestBase for type testing and added several tests for…
i582 Mar 15, 2022
3c0674a
fixed class-string comparison with other types
i582 Mar 15, 2022
6b749b7
added more tests
i582 Mar 15, 2022
f8220bc
wip
i582 Mar 27, 2022
26102d0
fixed tests
i582 Mar 27, 2022
87ce1f2
extended generic inspections for method and constructor calls and add…
i582 Mar 27, 2022
62b1369
added initial support for generic types bounds
i582 Mar 28, 2022
afa6442
removed old generic type provider
i582 Mar 28, 2022
9c274bc
added Map and Pair generic classes
i582 Mar 28, 2022
a248737
update
i582 Apr 22, 2022
cba4ab1
implementation of generics instantiation is redesigned through the in…
i582 May 23, 2022
48f300a
fixed tests
i582 May 23, 2022
afc47aa
update (wip)
i582 May 26, 2022
6887870
added initial support for default generic types
i582 May 26, 2022
c2b5be2
added AddExplicitInstantiationComment quick fix
i582 May 27, 2022
dec32ed
added support for static methods
i582 May 27, 2022
96c502f
reworked complex type resolution system, now all tests are green
i582 May 28, 2022
829cd14
added optimisation for non-generic symbols
i582 May 28, 2022
18b65d5
added more tests
i582 May 28, 2022
7c12652
added checks for generic type duplication with class types and added …
i582 May 28, 2022
b746f71
fixed bug with class-string
i582 May 28, 2022
8c9feab
added type inference for parameters when they have a generic type tha…
i582 May 28, 2022
c1140f7
wip
i582 May 29, 2022
707a475
update
i582 May 29, 2022
1dc21d7
added support for generic name in generic isntantiation list
i582 May 29, 2022
43a2bb5
refactor
i582 May 30, 2022
f78a639
refactor
i582 May 30, 2022
969e0f7
small refactor
i582 May 30, 2022
8511964
dropped kphp-template-class support
i582 May 30, 2022
b806f49
Merge branch 'master' into pmakhnev/generic
i582 May 30, 2022
2f846c8
added fields tests
i582 May 30, 2022
3d83f60
fixed @var tag
i582 May 30, 2022
96af2be
added tests for callback
i582 May 30, 2022
00d923a
now generic names in static fields are treated as a usual class inste…
i582 May 30, 2022
57f898a
small fix
i582 Jun 6, 2022
897f64d
update
i582 Jun 7, 2022
02dc6a7
update
i582 Jun 7, 2022
6fd074a
fixed stubs
i582 Jun 7, 2022
80500cf
small fixes
i582 Jun 7, 2022
77a4003
added type inference for a class methods parameters
i582 Jun 7, 2022
810956f
fixed type inference for tuples and shapes for simple cases
i582 Jun 8, 2022
3e2195e
fixed check for union extends class
i582 Jun 8, 2022
4e7bac8
added type inference from extends/default types for fields
i582 Jun 8, 2022
37bc52c
added check for generic instantiation count in PHPDoc
i582 Jun 9, 2022
2820bba
added highlight for @kphp-generic parts
i582 Jun 9, 2022
5f203d3
small rename
i582 Jun 9, 2022
7b6f053
added initial support for @kphp-inherit tag
i582 Jun 9, 2022
363a80e
small fixes
i582 Jun 9, 2022
25a39b8
added more checks and tests
i582 Jun 10, 2022
f7b998d
added initial support for class inherit
i582 Jun 10, 2022
cbc91b1
refactored
i582 Jun 12, 2022
37d5b3a
added generics T names settings for color scheme
i582 Jun 12, 2022
d967da2
fixed several KPHP tests
i582 Jun 12, 2022
80330d1
improved test bases
i582 Jun 12, 2022
9da0627
added support for depth inheritance
i582 Jun 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed NullPointerException when generic comment contains syntacticall…
…y incorrect types
i582 committed Mar 15, 2022
commit 015d27697d99540a03fe8e97172eb65cb0cf3375
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.impl.DebugUtil
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.impl.source.tree.PsiCommentImpl
import com.intellij.psi.tree.IElementType
@@ -158,7 +159,9 @@ class GenericInstantiationPsiCommentImpl(type: IElementType, text: CharSequence)
val newName = resolveInstance(element.text)
val namePsi = element.firstChild
if (namePsi is LeafPsiElement) {
namePsi.rawReplaceWithText(newName)
DebugUtil.performPsiModification<Exception>(null) {
namePsi.rawReplaceWithText(newName)
}
}
}

@@ -170,17 +173,17 @@ class GenericInstantiationPsiCommentImpl(type: IElementType, text: CharSequence)
}
})

val firstElement = genericPsi.firstChild.nextSibling.nextSibling
val endElement = genericPsi.lastChild.prevSibling
var curElement = firstElement
val firstElement = genericPsi.firstChild?.nextSibling?.nextSibling
val endElement = genericPsi.lastChild?.prevSibling
var curElement: PsiElement? = firstElement ?: return emptyList()

if (firstElement == endElement) {
return listOf(endElement)
}

val genericSpecElements = mutableListOf<PsiElement>()

while (curElement != endElement) {
while (curElement != endElement && curElement != null) {
if (curElement is LeafPsiElement || curElement is PsiWhiteSpace) {
curElement = curElement.nextSibling
continue
@@ -190,15 +193,17 @@ class GenericInstantiationPsiCommentImpl(type: IElementType, text: CharSequence)
curElement = curElement.nextSibling
}

genericSpecElements.add(endElement)
if (endElement != null) {
genericSpecElements.add(endElement)
}

return genericSpecElements
}

fun instantiationPartsTypes(): List<ExPhpType> {
val instantiationParts = instantiationParts()
val instantiationTypes = instantiationParts.map {
PhpType().add(it.text).toExPhpType()!!
val instantiationTypes = instantiationParts.mapNotNull {
PhpType().add(it.text).toExPhpType()
}

return instantiationTypes