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

highlighted the separate Mixin and PsiElement #28

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .run/Run Generate Parser.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</option>
<option name="taskNames">
<list>
<option value=":generateLexer" />
<option value=":generateParser" />
</list>
</option>
<option name="vmOptions" value="" />
Expand Down
21 changes: 17 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,23 @@ koverReport {

tasks {
generateLexer {
sourceFile = file("src/main/grammars/TLShcema.flex")
targetDir = "src/main/gen/com/vk/tlschema"
targetClass = "TLSchemaLexer"
purgeOldFiles = true
sourceFile.set(file("src/main/grammars/TLShcema.flex"))
targetOutputDir.set(file("src/main/gen/com/vk/tlschema"))
purgeOldFiles.set(true)
}

generateParser {
dependsOn(generateLexer)

sourceFile.set(file("src/main/grammars/TLSchema.bnf"))
targetRootOutputDir.set(file("src/main/gen"))
pathToParser.set("/com/vk/tlschema/parser/TLSchemaParser.java")
pathToPsiRoot.set("/com/vk/tlschema/psi")
purgeOldFiles.set(true)
}

withType<KotlinCompile> {
dependsOn(generateParser)
}

wrapper {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pluginGroup = com.vk.tlschema
pluginName = TL Schema Support
pluginRepositoryUrl = https://github.com/VKCOM/TL-Schema-idea-plugin
# SemVer format -> https://semver.org
pluginVersion = 1.4.0
pluginVersion = 1.4.1

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 223
pluginUntilBuild = 233.*
pluginUntilBuild =

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ kotlin = "1.9.21"
changelog = "2.2.0"
gradleIntelliJPlugin = "1.16.1"
kover = "0.7.5"
grammarkit = "2022.3.2.1"
grammarkit = "2022.3.2.2"

[libraries]
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
Expand Down
63 changes: 46 additions & 17 deletions src/main/grammars/TLSchema.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
elementTypeHolderClass="com.vk.tlschema.psi.TLSchemaTypes"
elementTypeClass="com.vk.tlschema.psi.TLSchemaElementType"
tokenTypeClass="com.vk.tlschema.psi.TLSchemaTokenType"

psiImplUtilClass="com.vk.tlschema.psi.impl.TLSchemaPsiImplUtil"
}


TLShemaFile ::= constructor_declarations [ ((TRIPPLE_MINUS FUNCTIONS_KW TRIPPLE_MINUS fun_declarations) | (TRIPPLE_MINUS TYPES_KW TRIPPLE_MINUS constructor_declarations)) *]
TLSchemaFile ::= constructor_declarations [ ((TRIPPLE_MINUS FUNCTIONS_KW TRIPPLE_MINUS fun_declarations) | (TRIPPLE_MINUS TYPES_KW TRIPPLE_MINUS constructor_declarations)) *]

comment_node ::= COMMENT

Expand All @@ -26,20 +24,42 @@ lc_ident_node ::= LC_IDENT
attribute_node ::= ATTRIBUTE;

namespace_ident ::= LC_IDENT

lc_ident_ns ::= [ namespace_ident DOT ] lc_ident_node {
mixin="com.vk.tlschema.psi.impl.TLSchemaNamedElementImpl"
implements="com.vk.tlschema.psi.TLSchemaNamedElement"
methods=[getName setName getReference getReferences getPresentation getDeclaration]}
implements=[
"com.vk.tlschema.psi.TLSchemaNamedElement"
"com.vk.tlschema.psi.TLSchemaDeclarationBase"
]
mixin="com.vk.tlschema.psi.mixins.TLSchemaLcIdentNsMixin"
}

uc_ident_ns ::= [ namespace_ident DOT ] uc_ident_node {
mixin="com.vk.tlschema.psi.impl.TLSchemaNamedElementImpl"
implements="com.vk.tlschema.psi.TLSchemaNamedElement"
methods=[getName setName getReference getReferences getPresentation getDeclaration]}
lc_ident_full ::= lc_ident_ns [ SHARP_HEX_NUMBER ] {methods=[getDeclaration]}
implements=[
"com.vk.tlschema.psi.TLSchemaNamedElement"
"com.vk.tlschema.psi.TLSchemaDeclarationBase"
]
mixin="com.vk.tlschema.psi.mixins.TLSchemaUcIdentNsMixin"
}

lc_ident_full ::= lc_ident_ns [ SHARP_HEX_NUMBER ] {
implements="com.vk.tlschema.psi.TLSchemaDeclarationBase"
mixin="com.vk.tlschema.psi.mixins.TLSchemaLcIdentFullMixin"
}

constructor_declarations ::= [ declaration * ] {
implements="com.vk.tlschema.psi.TLSchemaNamespacesElement"
mixin="com.vk.tlschema.psi.mixins.TLSchemaConstructorDeclarationsMixin"
}

constructor_declarations ::= [ declaration * ] {methods=[getNamespaces]}
fun_declarations ::= [ declaration * ] {methods=[getNamespaces]}
fun_declarations ::= [ declaration * ] {
implements="com.vk.tlschema.psi.TLSchemaNamespacesElement"
mixin="com.vk.tlschema.psi.mixins.TLSchemaFunDeclarationsMixin"
}

declaration ::= combinator_decl | combinator_decl_builtin {methods=[getCombinator getResultType getNumVars getTypeVars haveConditionalArgs getNamespace]}
declaration ::= combinator_decl | combinator_decl_builtin {
implements="com.vk.tlschema.psi.TLSchemaDeclarationElement"
mixin="com.vk.tlschema.psi.mixins.TLSchemaDeclarationMixin"
}

combinator_decl_builtin ::= combinator_decl_builtin_type;

Expand All @@ -55,10 +75,15 @@ type_with_triangle_braces ::= type_ident LEQ type_expr [ (COMA type_expr) * ] GE
percent_term ::= PERCENT term
type_ident ::= boxed_type_ident | lc_ident_ns | SHARP
boxed_type_ident ::= uc_ident_ns

var_ident ::= lc_ident_node | uc_ident_node {
mixin="com.vk.tlschema.psi.impl.TLSchemaNamedElementImpl"
implements="com.vk.tlschema.psi.TLSchemaNamedElement"
methods=[getName setName getReference getReferences getPresentation getDeclaration]}
implements=[
"com.vk.tlschema.psi.TLSchemaNamedElement"
"com.vk.tlschema.psi.TLSchemaDeclarationBase"
]
mixin="com.vk.tlschema.psi.mixins.TLSchemaVarIdentMixin"
}

type_term ::= term
nat_term ::= nat_expr

Expand All @@ -75,4 +100,8 @@ type_term_exc ::= type_term | EXCMARK type_term
multiplicity ::= nat_term
var_ident_opt ::= var_ident | UNDERSCORE
conditional_def ::= var_ident [ DOT NAT_CONST ] QMARK
result_type ::= (boxed_type_ident LEQ type_expr [ (COMA type_expr ) * ] GEQ) | (boxed_type_ident [type_expr]) {methods=[getDeclaration]}

result_type ::= (boxed_type_ident LEQ type_expr [ (COMA type_expr ) * ] GEQ) | (boxed_type_ident [type_expr]) {
implements="com.vk.tlschema.psi.TLSchemaDeclarationBase"
mixin="com.vk.tlschema.psi.mixins.TLSchemaResultTypeMixin"
}
7 changes: 0 additions & 7 deletions src/main/java/com/vk/tlschema/psi/TLSchemaNamedElement.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.util.List;
import java.util.Set;

@Deprecated
public class TLSchemaPsiImplUtil {
@Nullable
public static TLSchemaLcIdentNs getCombinator(TLSchemaDeclaration decl) {
TLSchemaFullCombinatorId type;
if (decl.getCombinatorDecl() != null) {
Expand All @@ -37,6 +39,7 @@ public static TLSchemaLcIdentNs getCombinator(TLSchemaDeclaration decl) {
}
}

@Nullable
public static List<TLSchemaVarIdent> getNumVars(TLSchemaDeclaration _decl) {
if (_decl.getCombinatorDeclBuiltin() != null) {
return null;
Expand Down Expand Up @@ -87,7 +90,7 @@ public static boolean haveConditionalArgs(TLSchemaDeclaration _decl) {
return false;
}


@Nullable
public static List<TLSchemaVarIdent> getTypeVars(TLSchemaDeclaration _decl) {
if (_decl.getCombinatorDeclBuiltin() != null) {
return null;
Expand Down Expand Up @@ -123,6 +126,7 @@ public static TLSchemaResultType getResultType(TLSchemaDeclaration decl) {
return type;
}

@Nullable
public static TLSchemaDeclaration getDeclaration(@NotNull PsiElement element) {
return PsiTreeUtil.getParentOfType(element, TLSchemaDeclaration.class);
}
Expand Down Expand Up @@ -183,6 +187,7 @@ public static PsiReference[] getReferences(PsiElement element) {
return ReferenceProvidersRegistry.getReferencesFromProviders(element);
}

@Nullable
public static PsiReference getReference(PsiElement element) {
PsiReference[] references = getReferences(element);
return references.length == 1 ? references[0] : null;
Expand Down Expand Up @@ -256,4 +261,4 @@ public Icon getIcon(boolean unused) {
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TLSchemaBreadcrumbsProvider : BreadcrumbsProvider {
override fun getElementInfo(element: PsiElement): String = when (element) {
is TLSchemaFunDeclarations -> "functions"
is TLSchemaConstructorDeclarations -> "types"
is TLSchemaDeclaration -> element.getCombinator().getName()!!
is TLSchemaDeclaration -> element.getCombinator()?.getName()!!
else -> throw IllegalArgumentException("Not supported")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.vk.tlschema.psi

interface TLSchemaDeclarationBase : TLSchemaElement {
fun getDeclaration(): TLSchemaDeclaration?
}
15 changes: 15 additions & 0 deletions src/main/kotlin/com/vk/tlschema/psi/TLSchemaDeclarationElement.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.vk.tlschema.psi

interface TLSchemaDeclarationElement : TLSchemaElement {
fun getCombinator(): TLSchemaLcIdentNs?

fun getResultType(): TLSchemaResultType

fun getNumVars(): List<TLSchemaVarIdent>?

fun getTypeVars(): List<TLSchemaVarIdent>?

fun haveConditionalArgs(): Boolean

fun getNamespace(): String
}
5 changes: 5 additions & 0 deletions src/main/kotlin/com/vk/tlschema/psi/TLSchemaElement.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.vk.tlschema.psi

import com.intellij.psi.PsiElement

interface TLSchemaElement : PsiElement
19 changes: 19 additions & 0 deletions src/main/kotlin/com/vk/tlschema/psi/TLSchemaNamedElement.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.vk.tlschema.psi

import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.NavigationItem
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiNamedElement
import com.intellij.psi.PsiReference

interface TLSchemaNamedElement : TLSchemaElement, PsiNamedElement, NavigationItem {
override fun getName(): String?

override fun setName(newName: String): PsiElement

override fun getReference(): PsiReference?

override fun getReferences(): Array<PsiReference>

override fun getPresentation(): ItemPresentation?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.vk.tlschema.psi

interface TLSchemaNamespacesElement : TLSchemaElement {
fun getNamespaces(result: Set<String>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.vk.tlschema.psi.mixins

import com.intellij.lang.ASTNode
import com.vk.tlschema.psi.TLSchemaConstructorDeclarations
import com.vk.tlschema.psi.impl.TLSchemaPsiImplUtil

internal abstract class TLSchemaConstructorDeclarationsMixin(node: ASTNode) :
TLSchemaElementMixin(node), TLSchemaConstructorDeclarations {
override fun getNamespaces(result: Set<String>) {
TLSchemaPsiImplUtil.getNamespaces(this, result)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.vk.tlschema.psi.mixins

import com.intellij.lang.ASTNode
import com.vk.tlschema.psi.TLSchemaDeclaration
import com.vk.tlschema.psi.TLSchemaLcIdentNs
import com.vk.tlschema.psi.TLSchemaResultType
import com.vk.tlschema.psi.TLSchemaVarIdent
import com.vk.tlschema.psi.impl.TLSchemaPsiImplUtil

internal abstract class TLSchemaDeclarationMixin(node: ASTNode) : TLSchemaElementMixin(node), TLSchemaDeclaration {
override fun getCombinator(): TLSchemaLcIdentNs? {
return TLSchemaPsiImplUtil.getCombinator(this)
}

override fun getResultType(): TLSchemaResultType {
return TLSchemaPsiImplUtil.getResultType(this)
}

override fun getNumVars(): List<TLSchemaVarIdent>? {
return TLSchemaPsiImplUtil.getNumVars(this)
}

override fun getTypeVars(): List<TLSchemaVarIdent>? {
return TLSchemaPsiImplUtil.getTypeVars(this)
}

override fun haveConditionalArgs(): Boolean {
return TLSchemaPsiImplUtil.haveConditionalArgs(this)
}

override fun getNamespace(): String {
return TLSchemaPsiImplUtil.getNamespace(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.vk.tlschema.psi.mixins

import com.intellij.extapi.psi.ASTWrapperPsiElement
import com.intellij.lang.ASTNode
import com.vk.tlschema.psi.TLSchemaElement

internal abstract class TLSchemaElementMixin(node: ASTNode) : ASTWrapperPsiElement(node), TLSchemaElement
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.vk.tlschema.psi.mixins

import com.intellij.lang.ASTNode
import com.vk.tlschema.psi.TLSchemaFunDeclarations
import com.vk.tlschema.psi.impl.TLSchemaPsiImplUtil

internal abstract class TLSchemaFunDeclarationsMixin(node: ASTNode) :
TLSchemaElementMixin(node), TLSchemaFunDeclarations {
override fun getNamespaces(result: Set<String>) {
TLSchemaPsiImplUtil.getNamespaces(this, result)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.vk.tlschema.psi.mixins

import com.intellij.lang.ASTNode
import com.vk.tlschema.psi.TLSchemaDeclaration
import com.vk.tlschema.psi.TLSchemaLcIdentFull
import com.vk.tlschema.psi.impl.TLSchemaPsiImplUtil

internal abstract class TLSchemaLcIdentFullMixin(node: ASTNode) : TLSchemaElementMixin(node), TLSchemaLcIdentFull {
override fun getDeclaration(): TLSchemaDeclaration? {
return TLSchemaPsiImplUtil.getDeclaration(this)
}
}
Loading