mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
idea: brace matching and function resolution
This commit is contained in:
@ -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"
|
||||
)
|
||||
)
|
||||
|
@ -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>()
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user