Skip to content

Commit

Permalink
Upgrade kotlin to 1.8.22 and deps
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Jun 23, 2023
1 parent 0ff5667 commit ce1247f
Show file tree
Hide file tree
Showing 26 changed files with 118 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 17 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ plugins {
id("org.jetbrains.intellij") version "0.7.2"
java
id("org.jetbrains.grammarkit") version "2021.1.2"
kotlin("jvm") version "1.4.20" // sync with version below
kotlin("jvm") version "1.8.22" // sync with version below
}

group = "com.github.oowekyala"
version = "1.10"

val IntellijVersion = "2021.1" // note: "since" version should be updated manually in plugin.xml
val KotlinVersion = "1.4.20"
val KotlinVersion = "1.8.22"
val JvmTarget = "11"
val PackageRoot = "/com/github/oowekyala/ijcc"
val PathToPsiRoot = "$PackageRoot/lang/psi"

Expand Down Expand Up @@ -60,17 +61,15 @@ sourceSets {


dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.1")
implementation("org.jetbrains.kotlin:kotlin-reflect:$KotlinVersion") // this could be avoided

compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KotlinVersion")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5")
implementation(kotlin("reflect")) // this could be avoided

// this is for tests
testCompile("com.github.oowekyala.treeutils:tree-matchers:2.0.2")
testImplementation("com.github.oowekyala.treeutils:tree-matchers:2.0.2")
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.1.11")

testImplementation(kotlin("test"))
testImplementation("junit:junit:4.12")
testImplementation("junit:junit:4.12") // todo upgrade

constraints {
testImplementation("org.jetbrains.kotlin:kotlin-stdlib:$KotlinVersion")
Expand Down Expand Up @@ -136,24 +135,28 @@ tasks {

compileJava {
dependsOn(generateParser, generateLexer)
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
sourceCompatibility = JvmTarget
targetCompatibility = JvmTarget
}

compileTestJava {
sourceCompatibility = JvmTarget
targetCompatibility = JvmTarget
}

compileKotlin {
dependsOn(generateParser, generateLexer)
kotlinOptions {
freeCompilerArgs = listOf(
"-Xjvm-default=enable",
"-Xuse-experimental=kotlin.Experimental"
"-Xjvm-default=all"
)
jvmTarget = "1.8"
jvmTarget = JvmTarget
}

}

compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = JvmTarget
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 6 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@


# Requires Java 11

build:
./gradlew b

alias b := build

buildPlugin:
./gradlew buildPlugin


Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class JccCompletionContributor : CompletionContributor() {
// FIXME doesn't work
when (parent.modelOption?.expectedType) {
BOOLEAN -> result.addAllElements(BoolOptionValueVariants)
else -> {
// todo
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.oowekyala.ijcc.ide.highlight

import com.github.oowekyala.ijcc.lang.JccTypes.*
import com.github.oowekyala.ijcc.lang.psi.JccJjtreeNodeDescriptor
import com.github.oowekyala.ijcc.util.capitalize
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
import com.intellij.ide.highlighter.JavaHighlightingColors
import com.intellij.lang.annotation.HighlightSeverity
Expand Down Expand Up @@ -65,7 +66,7 @@ enum class JavaccHighlightingColors(base: TextAttributesKey?) {

val displayName =
name.replace('_', ' ')
.toLowerCase().capitalize()
.lowercase(Locale.ROOT).capitalize()
.replace("Jjtree", "JJTree")
.replace("Javacc", "JavaCC")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ open class JccHighlightVisitor : JccVisitor(), HighlightVisitor, DumbAware {
checkCharLength(descriptor.baseCharElement, left)
&& right != null && checkCharLength(descriptor.toCharElement!!, right)

if (checkRange && (left[0].toInt() > right!![0].toInt())) {
if (checkRange && (left[0].code > right!![0].code)) {

myHolder += errorInfo(
descriptor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiFile
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.immutableListOf
import kotlinx.collections.immutable.immutableSetOf
import kotlinx.collections.immutable.*
import org.intellij.lang.annotations.Language
import org.jetbrains.annotations.TestOnly

Expand Down Expand Up @@ -52,7 +50,7 @@ class LeftRecursiveProductionInspection : JccInspectionBase(DisplayName) {

for (prod in leftMostSets.keys) {
if (visited[prod] != VisitStatus.VISITED) {
prod.checkLeftRecursion(leftMostSets, visited, immutableListOf(Pair(prod, null)), holder)
prod.checkLeftRecursion(leftMostSets, visited, persistentListOf(Pair(prod, null)), holder)
}
}

Expand All @@ -67,7 +65,7 @@ class LeftRecursiveProductionInspection : JccInspectionBase(DisplayName) {
visitStatuses[this] = VisitStatus.BEING_VISITED


val myLeftMost = leftMostSets[this] ?: immutableSetOf()
val myLeftMost = leftMostSets[this] ?: persistentSetOf()

loop@ for (ref in myLeftMost) {

Expand All @@ -78,7 +76,7 @@ class LeftRecursiveProductionInspection : JccInspectionBase(DisplayName) {

when (visitStatuses[prod]) {
VisitStatus.VISITED -> break@loop // should we continue?
VisitStatus.NOT_VISITED ->
null, VisitStatus.NOT_VISITED ->
// recurse
prod.checkLeftRecursion(leftMostSets, visitStatuses, loopPath.add(Pair(prod, ref)), holder)
VisitStatus.BEING_VISITED -> {
Expand All @@ -87,7 +85,7 @@ class LeftRecursiveProductionInspection : JccInspectionBase(DisplayName) {
val myIdx = loopPath.indexOfFirst { it.first == prod }
if (myIdx < 0) continue@loop // ??

val subPath: ProductionLoopPath = loopPath.subList(myIdx, loopPath.size).add(Pair(prod, ref))
val subPath: ProductionLoopPath = loopPath.subList(myIdx, loopPath.size).toPersistentList().add(Pair(prod, ref))

// report on the root production
holder.registerProblem(
Expand Down Expand Up @@ -139,4 +137,4 @@ enum class VisitStatus {
* added them to the path. Only the first in the list has no corresponding
* expansion unit.
*/
private typealias ProductionLoopPath = ImmutableList<Pair<JccNonTerminalProduction, JccNonTerminalExpansionUnit?>>
private typealias ProductionLoopPath = PersistentList<Pair<JccNonTerminalProduction, JccNonTerminalExpansionUnit?>>
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiFile
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.immutableListOf
import kotlinx.collections.immutable.*
import org.intellij.lang.annotations.Language
import org.jetbrains.annotations.TestOnly

Expand All @@ -37,7 +36,7 @@ class LoopInRegexInspection : JccInspectionBase(DisplayName) {
// Like left-recursion checking but simpler, we check for any kind of loop
// and not just those at start positions

override fun checkFile(file: PsiFile, manager: InspectionManager, isOnTheFly: Boolean): Array<ProblemDescriptor>? {
override fun checkFile(file: PsiFile, manager: InspectionManager, isOnTheFly: Boolean): Array<ProblemDescriptor> {
if (file !is JccFile) return emptyArray()

val grammar = file.lexicalGrammar
Expand All @@ -51,15 +50,15 @@ class LoopInRegexInspection : JccInspectionBase(DisplayName) {

for (token in allTokens) {
if (visited[token] != VisitStatus.VISITED) {
token.checkLoop(visited, immutableListOf(token), holder)
token.checkLoop(visited, persistentListOf(token), holder)
}
}

return holder.resultsArray
}

private fun Token.checkLoop(visitStatuses: MutableMap<Token, VisitStatus>,
loopPath: ImmutableList<Token>,
loopPath: PersistentList<Token>,
holder: ProblemsHolder) {

visitStatuses[this] = VisitStatus.BEING_VISITED
Expand All @@ -82,7 +81,7 @@ class LoopInRegexInspection : JccInspectionBase(DisplayName) {
// report left recursion
holder.registerProblem(
reffed.psiElement!!,
makeMessage(loopPath.subList(myIdx, loopPath.size).add(reffed)),
makeMessage(loopPath.subList(myIdx, loopPath.size).toPersistentList().add(reffed)),
ProblemHighlightType.ERROR
)
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.github.oowekyala.ijcc.ide.inspections.UnusedProductionInspection.Comp
import com.github.oowekyala.ijcc.lang.JccTypes
import com.github.oowekyala.ijcc.lang.psi.*
import com.github.oowekyala.ijcc.util.addIfNotNull
import com.github.oowekyala.ijcc.util.capitalize
import com.github.oowekyala.ijcc.util.runIt
import com.intellij.codeInspection.*
import com.intellij.openapi.util.Condition
Expand All @@ -14,6 +15,7 @@ import com.intellij.psi.PsiFile
import com.intellij.util.containers.JBIterable
import gnu.trove.THashSet
import org.intellij.lang.annotations.Language
import java.util.*

/**
* @author Clément Fournier
Expand Down Expand Up @@ -108,7 +110,8 @@ class UnusedProductionInspection : JccInspectionBase(DisplayName) {
enum class ErrorType {
UNUSED, UNREACHABLE;

fun makeMessage(prodName: String) = name.toLowerCase().capitalize() + " production \"$prodName\""
fun makeMessage(prodName: String) =
name.lowercase(Locale.ROOT).capitalize() + " production \"$prodName\""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,41 @@ import com.github.oowekyala.ijcc.util.foldNullable
import com.github.oowekyala.ijcc.util.takeUntil
import com.intellij.openapi.util.Key
import com.intellij.util.ThreeState
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.immutableListOf
import kotlinx.collections.immutable.immutableSetOf
import kotlinx.collections.immutable.*


/**
* Returns true if this regular expression can match the empty string.
*/
fun JccRegularExpression.isEmptyMatchPossible(): Boolean = computeNullability(immutableListOf())
fun JccRegularExpression.isEmptyMatchPossible(): Boolean = computeNullability(persistentListOf())

/**
* Returns true if this regular expression element can match the empty string.
*/
fun JccRegexElement.isEmptyMatchPossible(): Boolean = isEmptyMatchPossible(immutableListOf())
fun JccRegexElement.isEmptyMatchPossible(): Boolean = isEmptyMatchPossible(persistentListOf())


private fun JccRegularExpression.computeNullability(alreadySeen: ImmutableList<JccRegularExpression>): Boolean =
private fun JccRegularExpression.computeNullability(alreadySeen: PersistentList<JccRegularExpression>): Boolean =
computeAndCacheNullability(alreadySeen) { getRootRegexElement(followReferences = false)?.isEmptyMatchPossible(it) }

/**
* Returns true if this production can expand to the empty string.
*/
fun JccNonTerminalProduction.isEmptyMatchPossible(): Boolean = when (this) {
is JccBnfProduction -> computeNullability(immutableListOf())
is JccBnfProduction -> computeNullability(persistentListOf())
else -> false
}

/**
* Returns true if this expansion can expand to the empty string.
*/
fun JccExpansion.isEmptyMatchPossible(): Boolean = isEmptyMatchPossible(immutableListOf())
fun JccExpansion.isEmptyMatchPossible(): Boolean = isEmptyMatchPossible(persistentListOf())

private fun JccBnfProduction.computeNullability(alreadySeen: ImmutableList<JccBnfProduction>): Boolean =
private fun JccBnfProduction.computeNullability(alreadySeen: PersistentList<JccBnfProduction>): Boolean =
computeAndCacheNullability(alreadySeen) { expansion?.isEmptyMatchPossible(it) }


private fun JccRegexElement.isEmptyMatchPossible(alreadySeen: ImmutableList<JccRegularExpression>): Boolean =
private fun JccRegexElement.isEmptyMatchPossible(alreadySeen: PersistentList<JccRegularExpression>): Boolean =
when (this) {
is JccLiteralRegexUnit -> text.length == 2 // ""
is JccCharacterListRegexUnit -> false // assume that
Expand All @@ -61,7 +58,7 @@ private fun JccRegexElement.isEmptyMatchPossible(alreadySeen: ImmutableList<JccR
}


private fun JccExpansion.isEmptyMatchPossible(alreadySeen: ImmutableList<JccBnfProduction>): Boolean =
private fun JccExpansion.isEmptyMatchPossible(alreadySeen: PersistentList<JccBnfProduction>): Boolean =
when (this) {
is JccParserActionsUnit -> true
is JccLocalLookaheadUnit -> true
Expand All @@ -82,9 +79,9 @@ private fun JccExpansion.isEmptyMatchPossible(alreadySeen: ImmutableList<JccBnfP
else -> false
}

typealias LeftMostSet = ImmutableSet<JccNonTerminalExpansionUnit>
typealias LeftMostSet = PersistentSet<JccNonTerminalExpansionUnit>

private fun emptyLeftMostSet(): LeftMostSet = immutableSetOf()
private fun emptyLeftMostSet(): LeftMostSet = persistentSetOf()

/**
* Gets the set of productions that this production can expand to without consuming any tokens.
Expand All @@ -102,7 +99,7 @@ fun JccNonTerminalProduction.leftMostSet(): LeftMostSet? = when (this) {
*/
private fun JccExpansion.computeLeftMost(): LeftMostSet? =
when (this) {
is JccRegexExpansionUnit -> immutableSetOf()
is JccRegexExpansionUnit -> persistentSetOf()
is JccScopedExpansionUnit -> expansionUnit.computeLeftMost()
is JccAssignedExpansionUnit -> assignableExpansionUnit?.computeLeftMost()
is JccOptionalExpansionUnit -> expansion?.computeLeftMost()
Expand All @@ -119,18 +116,18 @@ private fun JccExpansion.computeLeftMost(): LeftMostSet? =
.map { it.computeLeftMost() }
.foldNullable(emptyLeftMostSet()) { a, b -> a.addAll(b) }

is JccNonTerminalExpansionUnit -> immutableSetOf(this)
else -> immutableSetOf() // valid, but nothing to do
is JccNonTerminalExpansionUnit -> persistentSetOf(this)
else -> persistentSetOf() // valid, but nothing to do
}


private val nullableKey: Key<ThreeState> = Key.create<ThreeState>("jcc.bnf.isNullable")
private val nullableKey: Key<ThreeState> = Key.create("jcc.bnf.isNullable")

// This caches the nullability status of productions and regexes,
// so as to avoid running in quadratic time, in case of very long
// call chains. This appears to be safe
private fun <T : JccPsiElement> T.computeAndCacheNullability(alreadySeen: ImmutableList<T>,
compute: T.(ImmutableList<T>) -> Boolean?): Boolean {
private fun <T : JccPsiElement> T.computeAndCacheNullability(alreadySeen: PersistentList<T>,
compute: T.(PersistentList<T>) -> Boolean?): Boolean {

val isNullable = getUserData(nullableKey) ?: ThreeState.UNSURE

Expand Down
Loading

0 comments on commit ce1247f

Please sign in to comment.