idea: brace matching and function resolution

This commit is contained in:
2023-09-21 21:08:20 -07:00
parent c4f65a66ca
commit d12aadf18c
22 changed files with 229 additions and 49 deletions

View File

@ -76,15 +76,14 @@ class AstPorkIdeaCodegen(pkg: String, outputDirectory: Path, world: AstWorld) :
if (baseType == "PorkNamedElement") {
kotlinClass.imports.add(0, "com.intellij.psi.PsiElement")
kotlinClass.imports.add("gay.pizza.pork.ast.NodeType")
kotlinClass.imports.add("gay.pizza.pork.idea.PorkElementTypes")
kotlinClass.imports.add("gay.pizza.pork.idea.psi.PorkElementHelpers")
val getNameFunction = KotlinFunction(
"getName",
overridden = true,
returnType = "String?",
isImmediateExpression = true
)
getNameFunction.body.add("node.findChildByType(PorkElementTypes.elementTypeFor(NodeType.${type.name}))?.text")
getNameFunction.body.add("PorkElementHelpers.nameOfNamedElement(this)")
kotlinClass.functions.add(getNameFunction)
val setNameFunction = KotlinFunction(
@ -96,8 +95,32 @@ class AstPorkIdeaCodegen(pkg: String, outputDirectory: Path, world: AstWorld) :
KotlinParameter("name", "String")
)
)
setNameFunction.body.add("this")
setNameFunction.body.add("PorkElementHelpers.setNameOfNamedElement(this, name)")
kotlinClass.functions.add(setNameFunction)
val getNameIdentifierFunction = KotlinFunction(
"getNameIdentifier",
overridden = true,
returnType = "PsiElement?",
isImmediateExpression = true
)
getNameIdentifierFunction.body.add("PorkElementHelpers.nameIdentifierOfNamedElement(this)")
kotlinClass.functions.add(getNameIdentifierFunction)
}
if (type.referencedElementValue != null && type.referencedElementType != null) {
kotlinClass.imports.add(0, "com.intellij.psi.PsiReference")
kotlinClass.imports.add("gay.pizza.pork.ast.NodeType")
kotlinClass.imports.add("gay.pizza.pork.idea.psi.PorkElementHelpers")
val getReferenceFunction = KotlinFunction(
"getReference",
overridden = true,
returnType = "PsiReference?",
isImmediateExpression = true
)
getReferenceFunction.body.add("PorkElementHelpers.referenceOfElement(this, NodeType.${type.referencedElementType})")
kotlinClass.functions.add(getReferenceFunction)
}
write("${type.name}Element.kt", KotlinWriter(kotlinClass))
@ -153,10 +176,12 @@ class AstPorkIdeaCodegen(pkg: String, outputDirectory: Path, world: AstWorld) :
),
inherits = mutableListOf(
"PorkElement(node)",
"PsiNamedElement"
"PsiNamedElement",
"PsiNameIdentifierOwner"
),
imports = mutableListOf(
"com.intellij.lang.ASTNode",
"com.intellij.psi.PsiNameIdentifierOwner",
"com.intellij.psi.PsiNamedElement"
)
)

View File

@ -1,6 +1,11 @@
package gay.pizza.pork.buildext.ast
class AstType(val name: String, var parent: AstType? = null, var namedElementValue: String? = null) {
class AstType(
val name: String, var parent: AstType? = null,
var namedElementValue: String? = null,
var referencedElementValue: String? = null,
var referencedElementType: String? = null
) {
private var internalValues: MutableList<AstValue>? = null
private val internalEnums = mutableListOf<AstEnum>()

View File

@ -7,5 +7,7 @@ data class AstTypeDescription(
val parent: String? = null,
val values: List<AstValueDescription>? = null,
val enums: List<AstEnumDescription> = emptyList(),
val namedElementValue: String? = null
val namedElementValue: String? = null,
val referencedElementValue: String? = null,
val referencedElementType: String? = null
)

View File

@ -57,6 +57,14 @@ class AstWorld {
type.namedElementValue = typeDescription.namedElementValue
}
if (typeDescription.referencedElementValue != null) {
type.referencedElementValue = typeDescription.referencedElementValue
}
if (typeDescription.referencedElementType != null) {
type.referencedElementType = typeDescription.referencedElementType
}
if (typeDescription.values != null) {
type.markHasValues()
for (value in typeDescription.values) {