FIR: unify common special names scattered around the code base
This commit is contained in:
committed by
teamcityserver
parent
263b876e6e
commit
684ef871ee
@@ -14,7 +14,7 @@ data class CallableId(
|
||||
private val pathToLocal: FqName? = null
|
||||
) {
|
||||
private companion object {
|
||||
val LOCAL_NAME = Name.special("<local>")
|
||||
val LOCAL_NAME = SpecialNames.LOCAL
|
||||
val PACKAGE_FQ_NAME_FOR_LOCAL = FqName.topLevel(LOCAL_NAME)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.name
|
||||
|
||||
import java.util.*
|
||||
|
||||
object NameUtils {
|
||||
private val SANITIZE_AS_JAVA_INVALID_CHARACTERS = "[^\\p{L}\\p{Digit}]".toRegex()
|
||||
|
||||
@@ -52,5 +50,5 @@ object NameUtils {
|
||||
Name.identifier(NameUtils.getPackagePartClassNamePrefix(filePath.substringAfterLast('/').substringBeforeLast('.')))
|
||||
|
||||
@JvmStatic
|
||||
fun hasName(name: Name) = name != SpecialNames.NO_NAME_PROVIDED && name != SpecialNames.ANONYMOUS_FUNCTION
|
||||
fun hasName(name: Name) = name != SpecialNames.NO_NAME_PROVIDED && name != SpecialNames.ANONYMOUS
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.name;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SpecialNames {
|
||||
public static final Name NO_NAME_PROVIDED = Name.special("<no name provided>");
|
||||
public static final Name ROOT_PACKAGE = Name.special("<root package>");
|
||||
public static final Name UNDERSCORE_FOR_UNUSED_VAR = Name.special("<unused var>");
|
||||
|
||||
public static final Name DEFAULT_NAME_FOR_COMPANION_OBJECT = Name.identifier("Companion");
|
||||
|
||||
// This name is used as a key for the case when something has no name _due to a syntactic error_
|
||||
// Example: fun (x: Int) = 5
|
||||
// There's no name for this function in the PSI
|
||||
// The name contains a GUID to avoid clashes, if a clash happens, it's not a big deal: the code does not compile anyway
|
||||
public static final Name SAFE_IDENTIFIER_FOR_NO_NAME = Name.identifier("no_name_in_PSI_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40");
|
||||
|
||||
public static final String ANONYMOUS = "<anonymous>";
|
||||
public static final Name ANONYMOUS_FUNCTION = Name.special(ANONYMOUS);
|
||||
|
||||
@NotNull
|
||||
public static Name safeIdentifier(@Nullable Name name) {
|
||||
return name != null && !name.isSpecial() ? name : SAFE_IDENTIFIER_FOR_NO_NAME;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Name safeIdentifier(@Nullable String name) {
|
||||
return safeIdentifier(name == null ? null : Name.identifier(name));
|
||||
}
|
||||
|
||||
public static boolean isSafeIdentifier(@NotNull Name name) {
|
||||
return !name.asString().isEmpty() && !name.isSpecial();
|
||||
}
|
||||
|
||||
private SpecialNames() {}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.kotlin.name
|
||||
|
||||
object SpecialNames {
|
||||
@JvmField
|
||||
val NO_NAME_PROVIDED = Name.special("<no name provided>")
|
||||
|
||||
@JvmField
|
||||
val ROOT_PACKAGE = Name.special("<root package>")
|
||||
|
||||
@JvmField
|
||||
val DEFAULT_NAME_FOR_COMPANION_OBJECT = Name.identifier("Companion")
|
||||
|
||||
// This name is used as a key for the case when something has no name _due to a syntactic error_
|
||||
// Example: fun (x: Int) = 5
|
||||
// There's no name for this function in the PSI
|
||||
// The name contains a GUID to avoid clashes, if a clash happens, it's not a big deal: the code does not compile anyway
|
||||
@JvmField
|
||||
val SAFE_IDENTIFIER_FOR_NO_NAME = Name.identifier("no_name_in_PSI_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40")
|
||||
|
||||
const val ANONYMOUS_STRING = "<anonymous>"
|
||||
|
||||
@JvmField
|
||||
val ANONYMOUS = Name.special(ANONYMOUS_STRING)
|
||||
|
||||
@JvmField
|
||||
val UNARY = Name.special("<unary>")
|
||||
|
||||
@JvmField
|
||||
val THIS = Name.special("<this>")
|
||||
|
||||
@JvmField
|
||||
val INIT = Name.special("<init>")
|
||||
|
||||
@JvmField
|
||||
val ITERATOR = Name.special("<iterator>")
|
||||
|
||||
@JvmField
|
||||
val DESTRUCT = Name.special("<destruct>")
|
||||
|
||||
@JvmField
|
||||
val LOCAL = Name.special("<local>")
|
||||
|
||||
@JvmField
|
||||
val UNDERSCORE_FOR_UNUSED_VAR = Name.special("<unused var>")
|
||||
|
||||
@JvmStatic
|
||||
fun safeIdentifier(name: Name?): Name {
|
||||
return if (name != null && !name.isSpecial) name else SAFE_IDENTIFIER_FOR_NO_NAME
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun safeIdentifier(name: String?): Name {
|
||||
return safeIdentifier(if (name == null) null else Name.identifier(name))
|
||||
}
|
||||
|
||||
fun isSafeIdentifier(name: Name): Boolean {
|
||||
return name.asString().isNotEmpty() && !name.isSpecial
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user