Skip to content

Commit

Permalink
Minor, move SpecialNames.isSafeIdentifier check a little earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
udalov committed Apr 29, 2016
1 parent d858844 commit a3055ed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Expand Up @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.structure.JavaPackage
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.getValue
Expand All @@ -47,6 +48,8 @@ class JvmPackageScope(
}

override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
if (!SpecialNames.isSafeIdentifier(name)) return null

recordLookup(location, name)

val javaClassifier = javaScope.getContributedClassifier(name, location)
Expand Down
Expand Up @@ -30,7 +30,6 @@ import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.storage.NullableLazyValue

Expand Down Expand Up @@ -103,19 +102,17 @@ class LazyJavaPackageScope(
override fun hashCode() = name.hashCode()
}

override fun getContributedClassifier(name: Name, location: LookupLocation) = findClassifier(name, null)

private fun findClassifier(name: Name, javaClass: JavaClass?): ClassDescriptor? {
if (!SpecialNames.isSafeIdentifier(name)) return null

override fun getContributedClassifier(name: Name, location: LookupLocation): ClassDescriptor? {
val knownClassNamesInPackage = knownClassNamesInPackage()
if (javaClass == null && knownClassNamesInPackage != null && name.asString() !in knownClassNamesInPackage) {
if (knownClassNamesInPackage != null && name.asString() !in knownClassNamesInPackage) {
return null
}

return classes(FindClassRequest(name, javaClass))
return findClassifier(name, null)
}

private fun findClassifier(name: Name, javaClass: JavaClass?): ClassDescriptor? = classes(FindClassRequest(name, javaClass))

internal fun findClassifierByJavaClass(javaClass: JavaClass) = findClassifier(javaClass.name, javaClass)

override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> = emptyList()
Expand Down
Expand Up @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents
Expand Down Expand Up @@ -49,8 +48,7 @@ open class DeserializedPackageMemberScope(
= computeDescriptors(kindFilter, nameFilter, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS)

override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
if (SpecialNames.isSafeIdentifier(name) &&
(name in classNames || c.components.fictitiousClassDescriptorFactory.shouldCreateClass(packageFqName, name))) {
if (name in classNames || c.components.fictitiousClassDescriptorFactory.shouldCreateClass(packageFqName, name)) {
return getClassDescriptor(name)
}
return null
Expand Down

0 comments on commit a3055ed

Please sign in to comment.