Visible classes take priority when resolving imports with *
This commit is contained in:
@@ -27,32 +27,31 @@ import org.jetbrains.kotlin.resolve.NoSubpackagesInPackageScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import java.util.ArrayList
|
||||
|
||||
class LazyFileScope private(
|
||||
private val aliasImportsScope: LazyImportScope,
|
||||
private val allUnderImportsScope: LazyImportScope,
|
||||
private val defaultAliasImportsScope: LazyImportScope,
|
||||
private val defaultAllUnderImportsScope: LazyImportScope,
|
||||
currentPackageMembersScope: JetScope,
|
||||
rootPackagesScope: JetScope,
|
||||
additionalScopes: List<JetScope>,
|
||||
private val scopeChain: List<JetScope>,
|
||||
private val aliasImportResolver: LazyImportResolver,
|
||||
private val allUnderImportResolver: LazyImportResolver,
|
||||
containingDeclaration: PackageFragmentDescriptor,
|
||||
debugName: String
|
||||
) : ChainedScope(containingDeclaration,
|
||||
debugName,
|
||||
*(listOf(aliasImportsScope, currentPackageMembersScope, rootPackagesScope, defaultAliasImportsScope, defaultAllUnderImportsScope, allUnderImportsScope) + additionalScopes).copyToArray()) {
|
||||
) : ChainedScope(containingDeclaration, debugName, *scopeChain.copyToArray()) {
|
||||
|
||||
public fun forceResolveAllImports() {
|
||||
aliasImportsScope.forceResolveAllContents()
|
||||
allUnderImportsScope.forceResolveAllContents()
|
||||
aliasImportResolver.forceResolveAllContents()
|
||||
allUnderImportResolver.forceResolveAllContents()
|
||||
}
|
||||
|
||||
public fun forceResolveImport(importDirective: JetImportDirective) {
|
||||
if (importDirective.isAllUnder()) {
|
||||
allUnderImportsScope.forceResolveImportDirective(importDirective)
|
||||
allUnderImportResolver.forceResolveImportDirective(importDirective)
|
||||
}
|
||||
else {
|
||||
aliasImportsScope.forceResolveImportDirective(importDirective)
|
||||
aliasImportResolver.forceResolveImportDirective(importDirective)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,17 +74,46 @@ class LazyFileScope private(
|
||||
val inRootPackage = packageView.getFqName().isRoot()
|
||||
val rootPackageView = resolveSession.getModuleDescriptor().getPackage(FqName.ROOT)
|
||||
?: throw IllegalStateException("Root package not found")
|
||||
val packageFragment = resolveSession.getPackageFragment(file.getPackageFqName())
|
||||
|
||||
val currentPackageMembersScope = NoSubpackagesInPackageScope(packageView)
|
||||
val rootPackagesScope = JetModuleUtil.getSubpackagesOfRootScope(resolveSession.getModuleDescriptor())
|
||||
val aliasImportsScope = LazyImportScope(resolveSession, packageView, AliasImportsIndexed(imports), traceForImportResolve, "Alias imports in $debugName", inRootPackage)
|
||||
val allUnderImportsScope = LazyImportScope(resolveSession, packageView, AllUnderImportsIndexed(imports), traceForImportResolve, "All under imports in $debugName", inRootPackage)
|
||||
val defaultAliasImportsScope = LazyImportScope(resolveSession, rootPackageView, AliasImportsIndexed(defaultImports), traceForDefaultImportResolve, "Default alias imports in $debugName", false)
|
||||
val defaultAllUnderImportsScope = LazyImportScope(resolveSession, rootPackageView, AllUnderImportsIndexed(defaultImports), traceForDefaultImportResolve, "Default all under imports in $debugName", false)
|
||||
val onlyVisibleFilter = VisibilityFilter(packageFragment, true)
|
||||
val onlyInvisibleFilter = VisibilityFilter(packageFragment, false)
|
||||
|
||||
return LazyFileScope(aliasImportsScope, allUnderImportsScope, defaultAliasImportsScope, defaultAllUnderImportsScope,
|
||||
currentPackageMembersScope, rootPackagesScope, additionalScopes,
|
||||
resolveSession.getPackageFragment(file.getPackageFqName()), debugName)
|
||||
val aliasImportResolver = LazyImportResolver(resolveSession, packageView, AliasImportsIndexed(imports), traceForImportResolve, inRootPackage)
|
||||
val allUnderImportResolver = LazyImportResolver(resolveSession, packageView, AllUnderImportsIndexed(imports), traceForImportResolve, inRootPackage)
|
||||
val defaultAliasImportResolver = LazyImportResolver(resolveSession, rootPackageView, AliasImportsIndexed(defaultImports), traceForDefaultImportResolve, false)
|
||||
val defaultAllUnderImportResolver = LazyImportResolver(resolveSession, rootPackageView, AllUnderImportsIndexed(defaultImports), traceForDefaultImportResolve, false)
|
||||
|
||||
val scopeChain = ArrayList<JetScope>()
|
||||
|
||||
scopeChain.add(LazyImportScope(aliasImportResolver, { true }, "Alias imports in $debugName"))
|
||||
|
||||
scopeChain.add(NoSubpackagesInPackageScope(packageView)) //TODO: problems with visibility too
|
||||
scopeChain.add(JetModuleUtil.getSubpackagesOfRootScope(resolveSession.getModuleDescriptor()))
|
||||
|
||||
scopeChain.add(LazyImportScope(defaultAliasImportResolver, { true }, "Default alias imports in $debugName"))
|
||||
|
||||
scopeChain.add(LazyImportScope(defaultAllUnderImportResolver, onlyVisibleFilter, "Default all under imports in $debugName (visible classes)"))
|
||||
scopeChain.add(LazyImportScope(allUnderImportResolver, onlyVisibleFilter, "All under imports in $debugName (visible classes)"))
|
||||
|
||||
scopeChain.addAll(additionalScopes)
|
||||
|
||||
scopeChain.add(LazyImportScope(defaultAllUnderImportResolver, onlyInvisibleFilter, "Default all under imports in $debugName (invisible classes only)"))
|
||||
scopeChain.add(LazyImportScope(allUnderImportResolver, onlyInvisibleFilter, "All under imports in $debugName (invisible classes only)"))
|
||||
|
||||
return LazyFileScope(scopeChain, aliasImportResolver, allUnderImportResolver, packageFragment, debugName)
|
||||
}
|
||||
|
||||
private class VisibilityFilter(
|
||||
private val packageFragment: PackageFragmentDescriptor,
|
||||
private val visible: Boolean
|
||||
) : (DeclarationDescriptor) -> Boolean {
|
||||
override fun invoke(descriptor: DeclarationDescriptor): Boolean {
|
||||
if (descriptor !is ClassDescriptor) return visible
|
||||
val visibility = descriptor.getVisibility()
|
||||
if (!visibility.mustCheckInImports()) return visible
|
||||
return Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, packageFragment) == visible
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPackageViewDescriptor(file: JetFile, resolveSession: ResolveSession): PackageViewDescriptor {
|
||||
|
||||
@@ -33,6 +33,8 @@ import java.util.HashSet
|
||||
import com.google.common.collect.ListMultimap
|
||||
import kotlin.properties.Delegates
|
||||
import com.google.common.collect.ImmutableListMultimap
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeSelectorUtil.ScopeByNameSelector
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeSelectorUtil.ScopeByNameMultiSelector
|
||||
|
||||
trait IndexedImports {
|
||||
val imports: List<JetImportDirective>
|
||||
@@ -61,15 +63,13 @@ class AliasImportsIndexed(allImports: Collection<JetImportDirective>) : IndexedI
|
||||
override fun importsForName(name: Name) = nameToDirectives.get(name)
|
||||
}
|
||||
|
||||
class LazyImportScope(
|
||||
private val resolveSession: ResolveSession,
|
||||
private val containingDeclaration: PackageViewDescriptor,
|
||||
private val indexedImports: IndexedImports,
|
||||
class LazyImportResolver(
|
||||
val resolveSession: ResolveSession,
|
||||
val packageView: PackageViewDescriptor,
|
||||
val indexedImports: IndexedImports,
|
||||
private val traceForImportResolve: BindingTrace,
|
||||
private val debugName: String,
|
||||
private val inRootPackage: Boolean
|
||||
) : JetScope {
|
||||
|
||||
) {
|
||||
private val importedScopesProvider = resolveSession.getStorageManager().createMemoizedFunction {
|
||||
(directive: JetImportDirective) -> ImportDirectiveResolveCache(directive)
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class LazyImportScope(
|
||||
cachedStatus.scope
|
||||
}
|
||||
else {
|
||||
val directiveImportScope = WritableScopeImpl(JetScope.Empty, containingDeclaration, RedeclarationHandler.DO_NOTHING, "Scope for import '" + directive.getDebugText() + "' resolve in " + toString())
|
||||
val directiveImportScope = WritableScopeImpl(JetScope.Empty, packageView, RedeclarationHandler.DO_NOTHING, "Scope for import '" + directive.getDebugText() + "' resolve in " + toString())
|
||||
directiveImportScope.changeLockLevel(WritableScope.LockLevel.BOTH)
|
||||
|
||||
val importer = Importer()
|
||||
@@ -104,11 +104,11 @@ class LazyImportScope(
|
||||
val descriptors: Collection<DeclarationDescriptor>
|
||||
try {
|
||||
val resolver = resolveSession.getQualifiedExpressionResolver()
|
||||
descriptors = resolver.processImportReference(directive, rootScope, containingDeclaration.getMemberScope(),
|
||||
descriptors = resolver.processImportReference(directive, rootScope, packageView.getMemberScope(),
|
||||
importer, traceForImportResolve, mode)
|
||||
importer.doImport(directiveImportScope)
|
||||
if (mode == LookupMode.EVERYTHING) {
|
||||
ImportsResolver.checkPlatformTypesMappedToKotlin(containingDeclaration.getModule(), traceForImportResolve, directive, descriptors)
|
||||
ImportsResolver.checkPlatformTypesMappedToKotlin(packageView.getModule(), traceForImportResolve, directive, descriptors)
|
||||
}
|
||||
}
|
||||
finally {
|
||||
@@ -139,10 +139,10 @@ class LazyImportScope(
|
||||
}
|
||||
}
|
||||
|
||||
private fun <D : DeclarationDescriptor> selectSingleFromImports(
|
||||
public fun <D : DeclarationDescriptor> selectSingleFromImports(
|
||||
name: Name,
|
||||
lookupMode: LookupMode,
|
||||
descriptorSelector: JetScopeSelectorUtil.ScopeByNameSelector<D>
|
||||
descriptorSelector: ScopeByNameSelector<D>
|
||||
): D? {
|
||||
fun compute(): D? {
|
||||
val imports = indexedImports.importsForName(name)
|
||||
@@ -162,10 +162,10 @@ class LazyImportScope(
|
||||
return resolveSession.getStorageManager().compute(::compute)
|
||||
}
|
||||
|
||||
private fun <D : DeclarationDescriptor> collectFromImports(
|
||||
public fun <D : DeclarationDescriptor> collectFromImports(
|
||||
name: Name,
|
||||
lookupMode: LookupMode,
|
||||
descriptorsSelector: JetScopeSelectorUtil.ScopeByNameMultiSelector<D>
|
||||
descriptorsSelector: ScopeByNameMultiSelector<D>
|
||||
): Collection<D> {
|
||||
return resolveSession.getStorageManager().compute {
|
||||
val descriptors = HashSet<D>()
|
||||
@@ -182,36 +182,69 @@ class LazyImportScope(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getImportScope(directive: JetImportDirective, lookupMode: LookupMode) = importedScopesProvider(directive).scopeForMode(lookupMode)
|
||||
public fun getImportScope(directive: JetImportDirective, lookupMode: LookupMode): JetScope {
|
||||
return importedScopesProvider(directive).scopeForMode(lookupMode)
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name) = selectSingleFromImports(name, LookupMode.ONLY_CLASSES_AND_PACKAGES, JetScopeSelectorUtil.CLASSIFIER_DESCRIPTOR_SCOPE_SELECTOR)
|
||||
public fun printScopeStructure(p: Printer) {
|
||||
p.print("rootScope = ")
|
||||
rootScope.printScopeStructure(p.withholdIndentOnce())
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPackage(name: Name) = selectSingleFromImports(name, LookupMode.ONLY_CLASSES_AND_PACKAGES, JetScopeSelectorUtil.PACKAGE_SCOPE_SELECTOR)
|
||||
class LazyImportScope(
|
||||
private val importResolver: LazyImportResolver,
|
||||
private val filter: (DeclarationDescriptor) -> Boolean,
|
||||
private val debugName: String
|
||||
) : JetScope {
|
||||
|
||||
override fun getProperties(name: Name) = collectFromImports(name, LookupMode.EVERYTHING, JetScopeSelectorUtil.NAMED_PROPERTIES_SCOPE_SELECTOR)
|
||||
private inner class FilteringScopeByNameSelector<D : DeclarationDescriptor>(
|
||||
private val selector: ScopeByNameSelector<D>
|
||||
) : ScopeByNameSelector<D> {
|
||||
override fun get(scope: JetScope, name: Name): D? {
|
||||
val descriptor = selector.get(scope, name)
|
||||
return if (descriptor != null && filter(descriptor)) descriptor else null
|
||||
}
|
||||
}
|
||||
|
||||
private inner class FilteringScopeByNameMultiSelector<D : DeclarationDescriptor>(
|
||||
private val selector: ScopeByNameMultiSelector<D>
|
||||
) : ScopeByNameMultiSelector<D> {
|
||||
override fun get(scope: JetScope, name: Name): Collection<D> {
|
||||
return selector.get(scope, name).filter(filter)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
||||
return importResolver.selectSingleFromImports(name, LookupMode.ONLY_CLASSES_AND_PACKAGES, FilteringScopeByNameSelector(JetScopeSelectorUtil.CLASSIFIER_DESCRIPTOR_SCOPE_SELECTOR))
|
||||
}
|
||||
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? {
|
||||
return importResolver.selectSingleFromImports(name, LookupMode.ONLY_CLASSES_AND_PACKAGES, FilteringScopeByNameSelector(JetScopeSelectorUtil.PACKAGE_SCOPE_SELECTOR))
|
||||
}
|
||||
|
||||
override fun getProperties(name: Name): Collection<VariableDescriptor> {
|
||||
return importResolver.collectFromImports(name, LookupMode.EVERYTHING, FilteringScopeByNameMultiSelector(JetScopeSelectorUtil.NAMED_PROPERTIES_SCOPE_SELECTOR))
|
||||
}
|
||||
|
||||
override fun getLocalVariable(name: Name) = null
|
||||
|
||||
override fun getFunctions(name: Name) = collectFromImports(name, LookupMode.EVERYTHING, JetScopeSelectorUtil.NAMED_FUNCTION_SCOPE_SELECTOR)
|
||||
override fun getFunctions(name: Name): Collection<FunctionDescriptor> {
|
||||
return importResolver.collectFromImports(name, LookupMode.EVERYTHING, FilteringScopeByNameMultiSelector(JetScopeSelectorUtil.NAMED_FUNCTION_SCOPE_SELECTOR))
|
||||
}
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return resolveSession.getStorageManager().compute {
|
||||
return importResolver.resolveSession.getStorageManager().compute {
|
||||
val descriptors = LinkedHashSet<DeclarationDescriptor>()
|
||||
for (directive in indexedImports.imports) {
|
||||
if (directive == directiveUnderResolve) {
|
||||
// This is the recursion in imports analysis
|
||||
throw IllegalStateException("Recursion while resolving many imports: " + directive.getText())
|
||||
}
|
||||
|
||||
for (directive in importResolver.indexedImports.imports) {
|
||||
val importPath = directive.getImportPath() ?: continue
|
||||
val importedName = importPath.getImportedName()
|
||||
if (importedName == null || nameFilter(importedName)) {
|
||||
descriptors.addAll(getImportScope(directive, LookupMode.EVERYTHING).getDescriptors(kindFilter, nameFilter))
|
||||
importResolver.getImportScope(directive, LookupMode.EVERYTHING).getDescriptors(kindFilter, nameFilter).filterTo(descriptors, filter)
|
||||
}
|
||||
}
|
||||
|
||||
descriptors
|
||||
}
|
||||
}
|
||||
@@ -220,7 +253,7 @@ class LazyImportScope(
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = listOf<DeclarationDescriptor>()
|
||||
|
||||
override fun getContainingDeclaration() = containingDeclaration
|
||||
override fun getContainingDeclaration() = importResolver.packageView
|
||||
|
||||
override fun toString() = "LazyImportScope: " + debugName
|
||||
|
||||
@@ -228,10 +261,9 @@ class LazyImportScope(
|
||||
p.println(javaClass.getSimpleName(), ": ", debugName, " {")
|
||||
p.pushIndent()
|
||||
|
||||
p.println("packageDescriptor = ", containingDeclaration)
|
||||
p.println("packageDescriptor = ", importResolver.packageView)
|
||||
|
||||
p.print("rootScope = ")
|
||||
rootScope.printScopeStructure(p.withholdIndentOnce())
|
||||
importResolver.printScopeStructure(p)
|
||||
|
||||
p.popIndent()
|
||||
p.println("}")
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// FILE: File.kt
|
||||
package pack
|
||||
|
||||
public open class InetAddressImpl
|
||||
|
||||
// FILE: Main.kt
|
||||
package a
|
||||
|
||||
import java.net.*
|
||||
import pack.*
|
||||
|
||||
class X : InetAddressImpl()
|
||||
@@ -0,0 +1,21 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
|
||||
internal final class X : pack.InetAddressImpl {
|
||||
public constructor X()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
package pack {
|
||||
|
||||
public open class InetAddressImpl {
|
||||
public constructor InetAddressImpl()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// FILE: File1.kt
|
||||
package pack1
|
||||
|
||||
private class SomeClass
|
||||
|
||||
// FILE: File2.kt
|
||||
package pack2
|
||||
|
||||
public open class SomeClass
|
||||
|
||||
// FILE: Main.kt
|
||||
package a
|
||||
|
||||
import pack1.*
|
||||
import pack2.*
|
||||
|
||||
class X : SomeClass()
|
||||
@@ -0,0 +1,31 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
|
||||
internal final class X : pack2.SomeClass {
|
||||
public constructor X()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
package pack1 {
|
||||
|
||||
private final class SomeClass {
|
||||
public constructor SomeClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
package pack2 {
|
||||
|
||||
public open class SomeClass {
|
||||
public constructor SomeClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// FILE: File1.kt
|
||||
package java.lang
|
||||
|
||||
private class SomeClass
|
||||
|
||||
// FILE: File2.kt
|
||||
package pack
|
||||
|
||||
public open class SomeClass
|
||||
|
||||
// FILE: Main.kt
|
||||
package a
|
||||
|
||||
import pack.*
|
||||
|
||||
class X : SomeClass()
|
||||
+17474
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
// FILE: File1.kt
|
||||
package pack1
|
||||
|
||||
private open class SomeClass
|
||||
|
||||
// FILE: Main.kt
|
||||
package a
|
||||
|
||||
import pack1.*
|
||||
|
||||
class X : <!INVISIBLE_REFERENCE, INVISIBLE_MEMBER!>SomeClass<!>()
|
||||
@@ -0,0 +1,21 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
|
||||
internal final class X : pack1.SomeClass {
|
||||
public constructor X()
|
||||
invisible_fake open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
invisible_fake open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
invisible_fake open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
package pack1 {
|
||||
|
||||
private open class SomeClass {
|
||||
public constructor SomeClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// FILE: File1.kt
|
||||
package pack1
|
||||
|
||||
public class SomeClass {
|
||||
private class N
|
||||
public open class PublicNested
|
||||
}
|
||||
|
||||
// FILE: File2.kt
|
||||
package pack2
|
||||
|
||||
public open class N
|
||||
|
||||
// FILE: Main.kt
|
||||
package a
|
||||
|
||||
import pack1.SomeClass.*
|
||||
import pack2.*
|
||||
|
||||
class X : N()
|
||||
class Y : PublicNested()
|
||||
@@ -0,0 +1,52 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
|
||||
internal final class X : pack2.N {
|
||||
public constructor X()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
internal final class Y : pack1.SomeClass.PublicNested {
|
||||
public constructor Y()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
package pack1 {
|
||||
|
||||
public final class SomeClass {
|
||||
public constructor SomeClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
private final class N {
|
||||
public constructor N()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class PublicNested {
|
||||
public constructor PublicNested()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
package pack2 {
|
||||
|
||||
public open class N {
|
||||
public constructor N()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// FILE: File1.kt
|
||||
package pack1
|
||||
|
||||
public class SomeClass {
|
||||
private class N
|
||||
public open class PublicNested
|
||||
}
|
||||
|
||||
// FILE: Main.kt
|
||||
package a
|
||||
|
||||
import pack1.SomeClass.*
|
||||
|
||||
class X : <!INVISIBLE_REFERENCE, INVISIBLE_MEMBER, FINAL_SUPERTYPE!>N<!>()
|
||||
@@ -0,0 +1,35 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
|
||||
internal final class X : pack1.SomeClass.N {
|
||||
public constructor X()
|
||||
invisible_fake open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
invisible_fake open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
invisible_fake open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
package pack1 {
|
||||
|
||||
public final class SomeClass {
|
||||
public constructor SomeClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
private final class N {
|
||||
public constructor N()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class PublicNested {
|
||||
public constructor PublicNested()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4853,6 +4853,42 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("JavaPackageLocalClassNotImported.kt")
|
||||
public void testJavaPackageLocalClassNotImported() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/JavaPackageLocalClassNotImported.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PackageLocalClassNotImported.kt")
|
||||
public void testPackageLocalClassNotImported() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/PackageLocalClassNotImported.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PackageLocalClassNotImportedWithDefaultImport.kt")
|
||||
public void testPackageLocalClassNotImportedWithDefaultImport() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/PackageLocalClassNotImportedWithDefaultImport.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PackageLocalClassReferencedError.kt")
|
||||
public void testPackageLocalClassReferencedError() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PrivateClassNotImported.kt")
|
||||
public void testPrivateClassNotImported() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/PrivateClassNotImported.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PrivateClassReferencedError.kt")
|
||||
public void testPrivateClassReferencedError() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyClassFileDependencyRecursion.kt")
|
||||
public void testPropertyClassFileDependencyRecursion() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/propertyClassFileDependencyRecursion.kt");
|
||||
|
||||
@@ -31,6 +31,11 @@ public class JavaVisibilities {
|
||||
return areInSamePackage(what, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer compareTo(@NotNull Visibility visibility) {
|
||||
if (this == visibility) return 0;
|
||||
@@ -70,6 +75,11 @@ public class JavaVisibilities {
|
||||
return isVisible(receiver, what, fromClass.getContainingDeclaration());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "protected/*protected static*/";
|
||||
@@ -101,6 +111,11 @@ public class JavaVisibilities {
|
||||
return isVisible(receiver, what, fromClass.getContainingDeclaration());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer compareTo(@NotNull Visibility visibility) {
|
||||
if (this == visibility) return 0;
|
||||
|
||||
@@ -30,6 +30,11 @@ import java.util.Set;
|
||||
|
||||
public class Visibilities {
|
||||
public static final Visibility PRIVATE = new Visibility("private", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
DeclarationDescriptor parent = what;
|
||||
@@ -72,6 +77,11 @@ public class Visibilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "private/*private to this*/";
|
||||
@@ -79,6 +89,11 @@ public class Visibilities {
|
||||
};
|
||||
|
||||
public static final Visibility PROTECTED = new Visibility("protected", true) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
ClassDescriptor classDescriptor = DescriptorUtils.getParentOfType(what, ClassDescriptor.class);
|
||||
@@ -97,6 +112,11 @@ public class Visibilities {
|
||||
};
|
||||
|
||||
public static final Visibility INTERNAL = new Visibility("internal", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
//NOTE: supposedly temporarily
|
||||
@@ -105,6 +125,11 @@ public class Visibilities {
|
||||
};
|
||||
|
||||
public static final Visibility PUBLIC = new Visibility("public", true) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return true;
|
||||
@@ -112,13 +137,23 @@ public class Visibilities {
|
||||
};
|
||||
|
||||
public static final Visibility LOCAL = new Visibility("local", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
throw new IllegalStateException("This method shouldn't be invoked for LOCAL visibility");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
throw new IllegalStateException(); //This method shouldn't be invoked for LOCAL visibility
|
||||
throw new IllegalStateException("This method shouldn't be invoked for LOCAL visibility");
|
||||
}
|
||||
};
|
||||
|
||||
public static final Visibility INHERITED = new Visibility("inherited", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
throw new IllegalStateException("This method shouldn't be invoked for INHERITED visibility");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
throw new IllegalStateException("Visibility is unknown yet"); //This method shouldn't be invoked for INHERITED visibility
|
||||
@@ -127,6 +162,11 @@ public class Visibilities {
|
||||
|
||||
/* Visibility for fake override invisible members (they are created for better error reporting) */
|
||||
public static final Visibility INVISIBLE_FAKE = new Visibility("invisible_fake", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
throw new IllegalStateException("This method shouldn't be invoked for INVISIBLE_FAKE visibility");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return false;
|
||||
|
||||
@@ -32,6 +32,18 @@ public abstract class Visibility {
|
||||
return isPublicAPI;
|
||||
}
|
||||
|
||||
/**
|
||||
* True, if it makes sense to check this visibility in imports and not import inaccessible declarations with such visibility.
|
||||
* Hint: return true, if this visibility can be checked on file's level.
|
||||
* Examples:
|
||||
* it returns false for PROTECTED because protected members of classes can be imported to be used in subclasses of their containers,
|
||||
* so when we are looking at the import, we don't know whether it is legal somewhere in this file or not.
|
||||
* it returns true for INTERNAL, because an internal declaration is either visible everywhere in a file, or invisible everywhere in the same file.
|
||||
* it returns true for PRIVATE, because there's no point in importing privates: they are inaccessible unless their short name is
|
||||
* already available without an import
|
||||
*/
|
||||
public abstract boolean mustCheckInImports();
|
||||
|
||||
/**
|
||||
* @return null if the answer is unknown
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user