Reverse dependency 'psi' <-> 'frontend.common'

Move ParseUtils to 'psi', and ImportPath to 'frontend.common'.

Now 'psi' depends on 'frontend.common', and that allows to remove
dependency of 'fir:tree:tree-generator' on 'psi', allowing the former to
compile in parallel with the old frontend code.
This commit is contained in:
Alexander Udalov
2020-03-15 15:14:54 +01:00
committed by Alexander Udalov
parent d70271b6aa
commit b6fdc96994
8 changed files with 11 additions and 30 deletions
+3 -6
View File
@@ -4,15 +4,12 @@ plugins {
}
dependencies {
compile(project(":compiler:psi"))
compile(project(":compiler:config"))
compile(project(":compiler:container"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
}
sourceSets {
"main" {
projectDefault()
}
"main" { projectDefault() }
"test" {}
}
}
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.renderer.*
data class ImportPath @JvmOverloads constructor(val fqName: FqName, val isAllUnder: Boolean, val alias: Name? = null) {
val pathStr: String
get() = fqName.toUnsafe().render() + if (isAllUnder) ".*" else ""
override fun toString(): String {
return pathStr + if (alias != null) " as " + alias.asString() else ""
}
fun hasAlias(): Boolean {
return alias != null
}
val importedName: Name?
get() {
if (!isAllUnder) {
return alias ?: fqName.shortName()
}
return null
}
companion object {
@JvmStatic
fun fromString(pathStr: String): ImportPath {
return if (pathStr.endsWith(".*")) {
ImportPath(FqName(pathStr.substring(0, pathStr.length - 2)), isAllUnder = true)
} else {
ImportPath(FqName(pathStr), isAllUnder = false)
}
}
}
}
@@ -1,96 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.constants.evaluate
import com.intellij.psi.tree.IElementType
import com.intellij.util.text.LiteralFormatUtil
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.utils.extractRadix
fun hasLongSuffix(text: String) = text.endsWith('l') || text.endsWith('L')
fun hasUnsignedSuffix(text: String) = text.endsWith('u') || text.endsWith('U')
fun hasUnsignedLongSuffix(text: String) =
text.endsWith("ul") || text.endsWith("uL") ||
text.endsWith("Ul") || text.endsWith("UL")
fun parseNumericLiteral(text: String, type: IElementType): Number? {
val canonicalText = LiteralFormatUtil.removeUnderscores(text)
return when (type) {
KtNodeTypes.INTEGER_CONSTANT -> parseLong(canonicalText)
KtNodeTypes.FLOAT_CONSTANT -> parseFloatingLiteral(canonicalText)
else -> null
}
}
private fun parseLong(text: String): Long? {
fun String.removeSuffix(i: Int): String = this.substring(0, this.length - i)
return try {
val isUnsigned: Boolean
val numberWithoutSuffix: String
when {
hasUnsignedLongSuffix(text) -> {
isUnsigned = true
numberWithoutSuffix = text.removeSuffix(2)
}
hasUnsignedSuffix(text) -> {
isUnsigned = true
numberWithoutSuffix = text.removeSuffix(1)
}
hasLongSuffix(text) -> {
isUnsigned = false
numberWithoutSuffix = text.removeSuffix(1)
}
else -> {
isUnsigned = false
numberWithoutSuffix = text
}
}
val (number, radix) = extractRadix(numberWithoutSuffix)
if (isUnsigned) {
java.lang.Long.parseUnsignedLong(number, radix)
} else {
java.lang.Long.parseLong(number, radix)
}
} catch (e: NumberFormatException) {
null
}
}
private fun parseFloatingLiteral(text: String): Number? {
if (text.toLowerCase().endsWith('f')) {
return parseFloat(text)
}
return parseDouble(text)
}
private fun parseDouble(text: String): Double? {
try {
return java.lang.Double.parseDouble(text)
} catch (e: NumberFormatException) {
return null
}
}
private fun parseFloat(text: String): Float? {
try {
return java.lang.Float.parseFloat(text)
} catch (e: NumberFormatException) {
return null
}
}
fun parseBoolean(text: String): Boolean {
if ("true".equals(text)) {
return true
} else if ("false".equals(text)) {
return false
}
throw IllegalStateException("Must not happen. A boolean literal has text: " + text)
}