Make ModuleDescriptor#getPackage() return not null lazy object with lazy scope
Refactor: no need to create package view in order to obtain its subpackages LazyPackageViewDescriptorImpl to replace PackageViewDescriptorImpl This allows to avoid computations when package views are requested but their contents not necessarily queried For example: DescriptorResolver.resolvePackageHeader()
This commit is contained in:
+1
-1
@@ -108,7 +108,7 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun serializePackage(module: ModuleDescriptor, fqName: FqName, destDir: File) {
|
private fun serializePackage(module: ModuleDescriptor, fqName: FqName, destDir: File) {
|
||||||
val packageView = module.getPackage(fqName) ?: error("No package resolved in $module")
|
val packageView = module.getPackage(fqName)
|
||||||
|
|
||||||
// TODO: perform some kind of validation? At the moment not possible because DescriptorValidator is in compiler-tests
|
// TODO: perform some kind of validation? At the moment not possible because DescriptorValidator is in compiler-tests
|
||||||
// DescriptorValidator.validate(packageView)
|
// DescriptorValidator.validate(packageView)
|
||||||
|
|||||||
+1
-3
@@ -167,15 +167,13 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean packageExists(@NotNull FqName fqName, @NotNull GlobalSearchScope scope) {
|
public boolean packageExists(@NotNull FqName fqName, @NotNull GlobalSearchScope scope) {
|
||||||
return getModule().getPackage(fqName) != null;
|
return !getModule().getPackage(fqName).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<FqName> getSubPackages(@NotNull FqName fqn, @NotNull GlobalSearchScope scope) {
|
public Collection<FqName> getSubPackages(@NotNull FqName fqn, @NotNull GlobalSearchScope scope) {
|
||||||
PackageViewDescriptor packageView = getModule().getPackage(fqn);
|
PackageViewDescriptor packageView = getModule().getPackage(fqn);
|
||||||
if (packageView == null) return Collections.emptyList();
|
|
||||||
|
|
||||||
Collection<DeclarationDescriptor> members = packageView.getMemberScope().getDescriptors(DescriptorKindFilter.PACKAGES, JetScope.ALL_NAME_FILTER);
|
Collection<DeclarationDescriptor> members = packageView.getMemberScope().getDescriptors(DescriptorKindFilter.PACKAGES, JetScope.ALL_NAME_FILTER);
|
||||||
return ContainerUtil.mapNotNull(members, new Function<DeclarationDescriptor, FqName>() {
|
return ContainerUtil.mapNotNull(members, new Function<DeclarationDescriptor, FqName>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1227,11 +1227,10 @@ public class DescriptorResolver {
|
|||||||
FqName fqName = packageDirective.getFqName(nameExpression);
|
FqName fqName = packageDirective.getFqName(nameExpression);
|
||||||
|
|
||||||
PackageViewDescriptor packageView = module.getPackage(fqName);
|
PackageViewDescriptor packageView = module.getPackage(fqName);
|
||||||
assert packageView != null : "package not found: " + fqName;
|
|
||||||
trace.record(REFERENCE_TARGET, nameExpression, packageView);
|
trace.record(REFERENCE_TARGET, nameExpression, packageView);
|
||||||
|
|
||||||
PackageViewDescriptor parentPackageView = packageView.getContainingDeclaration();
|
PackageViewDescriptor parentPackageView = packageView.getContainingDeclaration();
|
||||||
assert parentPackageView != null : "package has no parent: " + packageView;
|
assert parentPackageView != null : "Should not be null since " + fqName + " should not be root";
|
||||||
trace.record(RESOLUTION_SCOPE, nameExpression, parentPackageView.getMemberScope());
|
trace.record(RESOLUTION_SCOPE, nameExpression, parentPackageView.getMemberScope());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,10 +86,10 @@ public class ImportDirectiveProcessor(
|
|||||||
val packageView = moduleDescriptor.getPackage(fqName)
|
val packageView = moduleDescriptor.getPackage(fqName)
|
||||||
if (jetExpression == null) {
|
if (jetExpression == null) {
|
||||||
assert(fqName.isRoot())
|
assert(fqName.isRoot())
|
||||||
return packageView.sure { "Root package does not exist in module $moduleDescriptor" }
|
return packageView
|
||||||
}
|
}
|
||||||
return when {
|
return when {
|
||||||
packageView != null -> {
|
!packageView.isEmpty() -> {
|
||||||
recordPackageViews(jetExpression, packageView, trace)
|
recordPackageViews(jetExpression, packageView, trace)
|
||||||
packageView
|
packageView
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.resolve.lazy
|
package org.jetbrains.kotlin.resolve.lazy
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.impl.SubpackagesScope
|
import org.jetbrains.kotlin.descriptors.impl.SubpackagesScope
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.JetCodeFragment
|
import org.jetbrains.kotlin.psi.JetCodeFragment
|
||||||
@@ -67,8 +66,8 @@ class LazyFileScope private constructor(
|
|||||||
else
|
else
|
||||||
file.getImportDirectives()
|
file.getImportDirectives()
|
||||||
|
|
||||||
val packageView = getPackageViewDescriptor(file, resolveSession)
|
|
||||||
val moduleDescriptor = resolveSession.getModuleDescriptor()
|
val moduleDescriptor = resolveSession.getModuleDescriptor()
|
||||||
|
val packageView = moduleDescriptor.getPackage(file.getPackageFqName())
|
||||||
val packageFragment = resolveSession.getPackageFragment(file.getPackageFqName())
|
val packageFragment = resolveSession.getPackageFragment(file.getPackageFqName())
|
||||||
.sure { "Could not find fragment ${file.getPackageFqName()} for file ${file.getName()}" }
|
.sure { "Could not find fragment ${file.getPackageFqName()} for file ${file.getName()}" }
|
||||||
|
|
||||||
@@ -96,11 +95,5 @@ class LazyFileScope private constructor(
|
|||||||
|
|
||||||
return LazyFileScope(scopeChain, aliasImportResolver, allUnderImportResolver, packageFragment, debugName)
|
return LazyFileScope(scopeChain, aliasImportResolver, allUnderImportResolver, packageFragment, debugName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPackageViewDescriptor(file: JetFile, resolveSession: ResolveSession): PackageViewDescriptor {
|
|
||||||
val fqName = file.getPackageFqName()
|
|
||||||
return resolveSession.getModuleDescriptor().getPackage(fqName)
|
|
||||||
?: throw IllegalStateException("Package not found: $fqName maybe the file is not in scope of this resolve session: ${file.getName()}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class ResolveSessionUtils {
|
|||||||
FqName packageFqName = fqName.parent();
|
FqName packageFqName = fqName.parent();
|
||||||
while (true) {
|
while (true) {
|
||||||
PackageViewDescriptor packageDescriptor = module.getPackage(packageFqName);
|
PackageViewDescriptor packageDescriptor = module.getPackage(packageFqName);
|
||||||
if (packageDescriptor != null) {
|
if (!packageDescriptor.isEmpty()) {
|
||||||
FqName relativeClassFqName = NamePackage.tail(fqName, packageFqName);
|
FqName relativeClassFqName = NamePackage.tail(fqName, packageFqName);
|
||||||
ClassDescriptor classDescriptor = findByQualifiedName(packageDescriptor.getMemberScope(), relativeClassFqName);
|
ClassDescriptor classDescriptor = findByQualifiedName(packageDescriptor.getMemberScope(), relativeClassFqName);
|
||||||
if (classDescriptor != null && filter.apply(classDescriptor)) {
|
if (classDescriptor != null && filter.apply(classDescriptor)) {
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public final class JetScopeUtils {
|
|||||||
if (packageFragment == null) return null;
|
if (packageFragment == null) return null;
|
||||||
|
|
||||||
PackageViewDescriptor packageView = packageFragment.getContainingDeclaration().getPackage(((JetFile) parent).getPackageFqName());
|
PackageViewDescriptor packageView = packageFragment.getContainingDeclaration().getPackage(((JetFile) parent).getPackageFqName());
|
||||||
return packageView != null ? packageView.getMemberScope() : null;
|
return packageView.getMemberScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
JetExpression expression = PsiTreeUtil.getParentOfType(element, JetExpression.class, false);
|
JetExpression expression = PsiTreeUtil.getParentOfType(element, JetExpression.class, false);
|
||||||
|
|||||||
@@ -262,8 +262,8 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
|||||||
|
|
||||||
for (TestModule module : KotlinPackage.sort(modules.keySet())) {
|
for (TestModule module : KotlinPackage.sort(modules.keySet())) {
|
||||||
ModuleDescriptorImpl moduleDescriptor = modules.get(module);
|
ModuleDescriptorImpl moduleDescriptor = modules.get(module);
|
||||||
DeclarationDescriptor aPackage = moduleDescriptor.getPackage(FqName.ROOT);
|
PackageViewDescriptor aPackage = moduleDescriptor.getPackage(FqName.ROOT);
|
||||||
assertNotNull(aPackage);
|
assertFalse(aPackage.isEmpty());
|
||||||
|
|
||||||
if (isMultiModuleTest) {
|
if (isMultiModuleTest) {
|
||||||
rootPackageText.append(String.format("// -- Module: %s --\n", moduleDescriptor.getName()));
|
rootPackageText.append(String.format("// -- Module: %s --\n", moduleDescriptor.getName()));
|
||||||
|
|||||||
+1
-1
@@ -76,7 +76,7 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT
|
|||||||
|
|
||||||
AnalysisResult exhaust = JvmResolveUtil.analyzeFilesWithJavaIntegration(environment.getProject(), Collections.<JetFile>emptySet());
|
AnalysisResult exhaust = JvmResolveUtil.analyzeFilesWithJavaIntegration(environment.getProject(), Collections.<JetFile>emptySet());
|
||||||
PackageViewDescriptor packageView = exhaust.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageView = exhaust.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
||||||
assertNotNull(packageView);
|
assertFalse(packageView.isEmpty());
|
||||||
|
|
||||||
validateAndCompareDescriptorWithFile(packageView, CONFIGURATION, expectedFile);
|
validateAndCompareDescriptorWithFile(packageView, CONFIGURATION, expectedFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
|||||||
configurationKind);
|
configurationKind);
|
||||||
|
|
||||||
PackageViewDescriptor packageFromSource = result.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageFromSource = result.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
|
||||||
assert packageFromSource != null : "Package " + TEST_PACKAGE_FQNAME + " not found";
|
|
||||||
Assert.assertEquals("test", packageFromSource.getName().asString());
|
Assert.assertEquals("test", packageFromSource.getName().asString());
|
||||||
|
|
||||||
PackageViewDescriptor packageFromBinary = LoadDescriptorUtil.loadTestPackageAndBindingContextFromJavaRoot(
|
PackageViewDescriptor packageFromBinary = LoadDescriptorUtil.loadTestPackageAndBindingContextFromJavaRoot(
|
||||||
@@ -157,8 +156,6 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
|||||||
);
|
);
|
||||||
|
|
||||||
PackageViewDescriptor packageView = moduleContext.getModule().getPackage(TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageView = moduleContext.getModule().getPackage(TEST_PACKAGE_FQNAME);
|
||||||
assert packageView != null : "Test package not found";
|
|
||||||
|
|
||||||
checkJavaPackage(expectedFile, packageView, trace.getBindingContext(), DONT_INCLUDE_METHODS_OF_OBJECT);
|
checkJavaPackage(expectedFile, packageView, trace.getBindingContext(), DONT_INCLUDE_METHODS_OF_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +184,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
|||||||
environment.getProject(), Collections.singleton(jetFile)
|
environment.getProject(), Collections.singleton(jetFile)
|
||||||
);
|
);
|
||||||
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
|
||||||
assertNotNull(packageView);
|
assertFalse(packageView.isEmpty());
|
||||||
|
|
||||||
validateAndCompareDescriptorWithFile(packageView, DONT_INCLUDE_METHODS_OF_OBJECT.withValidationStrategy(
|
validateAndCompareDescriptorWithFile(packageView, DONT_INCLUDE_METHODS_OF_OBJECT.withValidationStrategy(
|
||||||
new DeserializedScopeValidationVisitor()
|
new DeserializedScopeValidationVisitor()
|
||||||
|
|||||||
+1
-1
@@ -93,7 +93,7 @@ public abstract class AbstractSdkAnnotationsValidityTest extends UsefulTestCase
|
|||||||
|
|
||||||
topLevelClass.acceptVoid(visitor);
|
topLevelClass.acceptVoid(visitor);
|
||||||
|
|
||||||
if (topLevelPackage != null) {
|
if (!topLevelPackage.isEmpty()) {
|
||||||
topLevelPackage.acceptVoid(visitor);
|
topLevelPackage.acceptVoid(visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -90,7 +90,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
|||||||
);
|
);
|
||||||
|
|
||||||
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
||||||
assertNotNull("Failed to find package: " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView);
|
assertFalse("Failed to find package: " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
|
||||||
return packageView;
|
return packageView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,8 +105,6 @@ public final class LoadDescriptorUtil {
|
|||||||
ModuleDescriptor module = LazyResolveTestUtil.resolve(environment.getProject(), trace, Collections.<JetFile>emptyList());
|
ModuleDescriptor module = LazyResolveTestUtil.resolve(environment.getProject(), trace, Collections.<JetFile>emptyList());
|
||||||
|
|
||||||
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
|
||||||
assert packageView != null;
|
|
||||||
|
|
||||||
return Pair.create(packageView, trace.getBindingContext());
|
return Pair.create(packageView, trace.getBindingContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -111,7 +111,7 @@ public class MultiModuleJavaAnalysisCustomTest : UsefulTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkClassInPackage(moduleDescriptor: ModuleDescriptor, packageName: String, className: String) {
|
private fun checkClassInPackage(moduleDescriptor: ModuleDescriptor, packageName: String, className: String) {
|
||||||
val kotlinPackage = moduleDescriptor.getPackage(FqName(packageName))!!
|
val kotlinPackage = moduleDescriptor.getPackage(FqName(packageName))
|
||||||
val kotlinClassName = Name.identifier(className)
|
val kotlinClassName = Name.identifier(className)
|
||||||
val kotlinClass = kotlinPackage.memberScope.getClassifier(kotlinClassName) as ClassDescriptor
|
val kotlinClass = kotlinPackage.memberScope.getClassifier(kotlinClassName) as ClassDescriptor
|
||||||
checkClass(kotlinClass)
|
checkClass(kotlinClass)
|
||||||
|
|||||||
+1
-1
@@ -144,7 +144,7 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi
|
|||||||
val header = ReflectKotlinClass.create(klass)?.getClassHeader()
|
val header = ReflectKotlinClass.create(klass)?.getClassHeader()
|
||||||
|
|
||||||
if (header?.kind == KotlinClassHeader.Kind.PACKAGE_FACADE) {
|
if (header?.kind == KotlinClassHeader.Kind.PACKAGE_FACADE) {
|
||||||
val packageView = module.getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME).sure { "Couldn't resolve package ${LoadDescriptorUtil.TEST_PACKAGE_FQNAME}" }
|
val packageView = module.getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME)
|
||||||
packageScopes.add(packageView.memberScope)
|
packageScopes.add(packageView.memberScope)
|
||||||
}
|
}
|
||||||
else if (header == null ||
|
else if (header == null ||
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ public class BuiltInsSerializerTest : TestCaseWithTmpdir() {
|
|||||||
module.setDependencies(module, KotlinBuiltIns.getInstance().getBuiltInsModule())
|
module.setDependencies(module, KotlinBuiltIns.getInstance().getBuiltInsModule())
|
||||||
|
|
||||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
||||||
module.getPackage(TEST_PACKAGE_FQNAME)!!,
|
module.getPackage(TEST_PACKAGE_FQNAME),
|
||||||
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||||
File(source.replace(".kt", ".txt"))
|
File(source.replace(".kt", ".txt"))
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public class KotlinJavascriptSerializerTest : TestCaseWithTmpdir() {
|
|||||||
val module = deserialize(metaFile)
|
val module = deserialize(metaFile)
|
||||||
|
|
||||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
||||||
module.getPackage(TEST_PACKAGE_FQNAME)!!,
|
module.getPackage(TEST_PACKAGE_FQNAME),
|
||||||
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||||
File(source.replace(".kt", ".txt"))
|
File(source.replace(".kt", ".txt"))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public class RecursiveDescriptorProcessorTest extends KotlinTestWithEnvironment
|
|||||||
JetFile jetFile = JetTestUtils.createFile("declarations.kt", text, getEnvironment().getProject());
|
JetFile jetFile = JetTestUtils.createFile("declarations.kt", text, getEnvironment().getProject());
|
||||||
AnalysisResult result = JetTestUtils.analyzeFile(jetFile);
|
AnalysisResult result = JetTestUtils.analyzeFile(jetFile);
|
||||||
PackageViewDescriptor testPackage = result.getModuleDescriptor().getPackage(FqName.topLevel(Name.identifier("test")));
|
PackageViewDescriptor testPackage = result.getModuleDescriptor().getPackage(FqName.topLevel(Name.identifier("test")));
|
||||||
assert testPackage != null;
|
|
||||||
|
|
||||||
List<String> descriptors = recursivelyCollectDescriptors(testPackage);
|
List<String> descriptors = recursivelyCollectDescriptors(testPackage);
|
||||||
|
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ import kotlin.properties.Delegates
|
|||||||
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
|
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
|
||||||
|
|
||||||
public class ReflectionTypes(private val module: ModuleDescriptor) {
|
public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||||
private val kotlinReflectScope: JetScope? by Delegates.lazy {
|
private val kotlinReflectScope: JetScope by Delegates.lazy {
|
||||||
module.getPackage(KOTLIN_REFLECT_FQ_NAME)?.memberScope
|
module.getPackage(KOTLIN_REFLECT_FQ_NAME).memberScope
|
||||||
}
|
}
|
||||||
|
|
||||||
fun find(className: String): ClassDescriptor {
|
fun find(className: String): ClassDescriptor {
|
||||||
val name = Name.identifier(className)
|
val name = Name.identifier(className)
|
||||||
return kotlinReflectScope?.getClassifier(name) as? ClassDescriptor
|
return kotlinReflectScope.getClassifier(name) as? ClassDescriptor
|
||||||
?: ErrorUtils.createErrorClass(KOTLIN_REFLECT_FQ_NAME.child(name).asString())
|
?: ErrorUtils.createErrorClass(KOTLIN_REFLECT_FQ_NAME.child(name).asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ public class BuiltInFictitiousFunctionClassFactory(
|
|||||||
val kindWithArity = parseClassName(className, packageFqName) ?: return null
|
val kindWithArity = parseClassName(className, packageFqName) ?: return null
|
||||||
val (kind, arity) = kindWithArity // KT-5100
|
val (kind, arity) = kindWithArity // KT-5100
|
||||||
|
|
||||||
val containingPackageFragment = module.getPackage(packageFqName)!!.fragments.single()
|
val containingPackageFragment = module.getPackage(packageFqName).fragments.single()
|
||||||
|
|
||||||
return FunctionClassDescriptor(storageManager, containingPackageFragment, kind, arity)
|
return FunctionClassDescriptor(storageManager, containingPackageFragment, kind, arity)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -158,7 +158,7 @@ public class FunctionClassDescriptor(
|
|||||||
if (functionKind.hasExtensionReceiver) functionArity++
|
if (functionKind.hasExtensionReceiver) functionArity++
|
||||||
|
|
||||||
val module = containingDeclaration.getContainingDeclaration()
|
val module = containingDeclaration.getContainingDeclaration()
|
||||||
val kotlinPackageFragment = module.getPackage(BUILT_INS_PACKAGE_FQ_NAME)!!.fragments.single()
|
val kotlinPackageFragment = module.getPackage(BUILT_INS_PACKAGE_FQ_NAME).fragments.single()
|
||||||
|
|
||||||
// If this is a KMemberFunction{n} or KExtensionFunction{n}, it extends Function{n} with the annotation kotlin.extension,
|
// If this is a KMemberFunction{n} or KExtensionFunction{n}, it extends Function{n} with the annotation kotlin.extension,
|
||||||
// so that the value of this type is callable as an extension function, with the receiver before the dot
|
// so that the value of this type is callable as an extension function, with the receiver before the dot
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ import org.jetbrains.kotlin.resolve.ImportPath
|
|||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
|
|
||||||
public trait ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
public trait ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
||||||
public fun getPackage(fqName: FqName): PackageViewDescriptor?
|
|
||||||
public fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
|
||||||
|
|
||||||
override fun getContainingDeclaration(): DeclarationDescriptor? = null
|
override fun getContainingDeclaration(): DeclarationDescriptor? = null
|
||||||
|
|
||||||
public val builtIns: KotlinBuiltIns
|
public val builtIns: KotlinBuiltIns
|
||||||
@@ -40,6 +37,10 @@ public trait ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
|||||||
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R {
|
||||||
return visitor.visitModuleDeclaration(this, data)
|
return visitor.visitModuleDeclaration(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun getPackage(fqName: FqName): PackageViewDescriptor
|
||||||
|
|
||||||
|
public fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ModuleParameters {
|
trait ModuleParameters {
|
||||||
@@ -56,4 +57,4 @@ public fun ModuleParameters(defaultImports: List<ImportPath>, platformToKotlinCl
|
|||||||
object : ModuleParameters {
|
object : ModuleParameters {
|
||||||
override val defaultImports: List<ImportPath> = defaultImports
|
override val defaultImports: List<ImportPath> = defaultImports
|
||||||
override val platformToKotlinClassMap: PlatformToKotlinClassMap = platformToKotlinClassMap
|
override val platformToKotlinClassMap: PlatformToKotlinClassMap = platformToKotlinClassMap
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,6 @@ public interface PackageViewDescriptor : DeclarationDescriptor {
|
|||||||
public val module: ModuleDescriptor
|
public val module: ModuleDescriptor
|
||||||
|
|
||||||
public val fragments: List<PackageFragmentDescriptor>
|
public val fragments: List<PackageFragmentDescriptor>
|
||||||
|
|
||||||
|
public fun isEmpty(): Boolean = fragments.isEmpty()
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-16
@@ -16,36 +16,46 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.descriptors.impl
|
package org.jetbrains.kotlin.descriptors.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorVisitor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
|
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.LazyScopeAdapter
|
||||||
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
|
import org.jetbrains.kotlin.storage.get
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
|
|
||||||
public class PackageViewDescriptorImpl(
|
public class LazyPackageViewDescriptorImpl(
|
||||||
override val module: ModuleDescriptor,
|
override val module: ModuleDescriptorImpl,
|
||||||
override val fqName: FqName,
|
override val fqName: FqName,
|
||||||
override val fragments: List<PackageFragmentDescriptor>
|
storageManager: StorageManager
|
||||||
) : DeclarationDescriptorImpl(Annotations.EMPTY, fqName.shortNameOrSpecial()), PackageViewDescriptor {
|
) : DeclarationDescriptorImpl(Annotations.EMPTY, fqName.shortNameOrSpecial()), PackageViewDescriptor {
|
||||||
override val memberScope: JetScope = run {
|
|
||||||
assert(fragments.isNotEmpty()) { "$fqName in module" }
|
|
||||||
|
|
||||||
val scopes = fragments.map { it.getMemberScope() } + SubpackagesScope(this)
|
override val fragments: List<PackageFragmentDescriptor> by storageManager.createLazyValue {
|
||||||
ChainedScope(this, "package view scope for $fqName in ${module.getName()}", *scopes.toTypedArray())
|
module.packageFragmentProvider.getPackageFragments(fqName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContainingDeclaration(): PackageViewDescriptor? = if (fqName.isRoot()) null else module.getPackage(fqName.parent())
|
override val memberScope: JetScope = LazyScopeAdapter(storageManager.createLazyValue {
|
||||||
|
if (fragments.isEmpty()) {
|
||||||
|
JetScope.Empty
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val scopes = fragments.map { it.getMemberScope() } + SubpackagesScope(module, fqName)
|
||||||
|
ChainedScope(this, "package view scope for $fqName in ${module.getName()}", *scopes.toTypedArray())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
override fun substitute(substitutor: TypeSubstitutor): DeclarationDescriptor? = this
|
override fun getContainingDeclaration(): PackageViewDescriptor? {
|
||||||
|
return if (fqName.isRoot()) null else module.getPackage(fqName.parent())
|
||||||
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R = visitor.visitPackageViewDescriptor(this, data)
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (javaClass != other?.javaClass) return false
|
val that = other as? PackageViewDescriptor ?: return false
|
||||||
|
return this.fqName == that.fqName && this.module == that.module
|
||||||
val that = other as PackageViewDescriptorImpl
|
|
||||||
return fqName == that.fqName && module == that.module
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
@@ -53,4 +63,8 @@ public class PackageViewDescriptorImpl(
|
|||||||
result = 31 * result + fqName.hashCode()
|
result = 31 * result + fqName.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun substitute(substitutor: TypeSubstitutor): DeclarationDescriptor? = this
|
||||||
|
|
||||||
|
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R = visitor.visitPackageViewDescriptor(this, data)
|
||||||
}
|
}
|
||||||
+10
-10
@@ -43,6 +43,12 @@ public class ModuleDescriptorImpl(
|
|||||||
private var dependencies: ModuleDependencies? = null
|
private var dependencies: ModuleDependencies? = null
|
||||||
private var packageFragmentProviderForModuleContent: PackageFragmentProvider? = null
|
private var packageFragmentProviderForModuleContent: PackageFragmentProvider? = null
|
||||||
|
|
||||||
|
override fun getPackage(fqName: FqName): PackageViewDescriptor = LazyPackageViewDescriptorImpl(this, fqName, storageManager)
|
||||||
|
|
||||||
|
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName> {
|
||||||
|
return packageFragmentProvider.getSubPackagesOf(fqName, nameFilter)
|
||||||
|
}
|
||||||
|
|
||||||
private val packageFragmentProviderForWholeModuleWithDependencies by Delegates.lazy {
|
private val packageFragmentProviderForWholeModuleWithDependencies by Delegates.lazy {
|
||||||
val moduleDependencies = dependencies.sure { "Dependencies of module $id were not set before querying module content" }
|
val moduleDependencies = dependencies.sure { "Dependencies of module $id were not set before querying module content" }
|
||||||
val dependenciesDescriptors = moduleDependencies.descriptors
|
val dependenciesDescriptors = moduleDependencies.descriptors
|
||||||
@@ -82,17 +88,11 @@ public class ModuleDescriptorImpl(
|
|||||||
*/
|
*/
|
||||||
public fun initialize(providerForModuleContent: PackageFragmentProvider) {
|
public fun initialize(providerForModuleContent: PackageFragmentProvider) {
|
||||||
assert(!isInitialized) { "Attempt to initialize module $id twice" }
|
assert(!isInitialized) { "Attempt to initialize module $id twice" }
|
||||||
packageFragmentProviderForModuleContent = providerForModuleContent
|
this.packageFragmentProviderForModuleContent = providerForModuleContent
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPackage(fqName: FqName): PackageViewDescriptor? {
|
val packageFragmentProvider: PackageFragmentProvider
|
||||||
val fragments = packageFragmentProviderForWholeModuleWithDependencies.getPackageFragments(fqName)
|
get() = packageFragmentProviderForWholeModuleWithDependencies
|
||||||
return if (!fragments.isEmpty()) PackageViewDescriptorImpl(this, fqName, fragments) else null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName> {
|
|
||||||
return packageFragmentProviderForWholeModuleWithDependencies.getSubPackagesOf(fqName, nameFilter)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val friendModules = LinkedHashSet<ModuleDescriptor>()
|
private val friendModules = LinkedHashSet<ModuleDescriptor>()
|
||||||
|
|
||||||
@@ -121,4 +121,4 @@ public class LazyModuleDependencies(
|
|||||||
|
|
||||||
override val descriptors: List<ModuleDescriptorImpl>
|
override val descriptors: List<ModuleDescriptorImpl>
|
||||||
get() = dependencies()
|
get() = dependencies()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,28 +17,38 @@
|
|||||||
package org.jetbrains.kotlin.descriptors.impl
|
package org.jetbrains.kotlin.descriptors.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
|
||||||
import org.jetbrains.kotlin.utils.*
|
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
||||||
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
import org.jetbrains.kotlin.utils.sure
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
public class SubpackagesScope(private val containingDeclaration: PackageViewDescriptor) : JetScopeImpl() {
|
public class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, private val fqName: FqName) : JetScopeImpl() {
|
||||||
override fun getContainingDeclaration(): DeclarationDescriptor {
|
override fun getContainingDeclaration(): DeclarationDescriptor {
|
||||||
return containingDeclaration
|
return moduleDescriptor.getPackage(fqName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPackage(name: Name): PackageViewDescriptor? {
|
override fun getPackage(name: Name): PackageViewDescriptor? {
|
||||||
return if (name.isSpecial()) null else containingDeclaration.getModule().getPackage(containingDeclaration.getFqName().child(name))
|
if (name.isSpecial()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val packageViewDescriptor = moduleDescriptor.getPackage(fqName.child(name))
|
||||||
|
if (packageViewDescriptor.isEmpty()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return packageViewDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
if (!kindFilter.acceptsKinds(DescriptorKindFilter.PACKAGES_MASK)) return listOf()
|
if (!kindFilter.acceptsKinds(DescriptorKindFilter.PACKAGES_MASK)) return listOf()
|
||||||
|
|
||||||
val subFqNames = containingDeclaration.getModule().getSubPackagesOf(containingDeclaration.getFqName(), nameFilter)
|
val subFqNames = moduleDescriptor.getSubPackagesOf(fqName, nameFilter)
|
||||||
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
|
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
|
||||||
for (subFqName in subFqNames) {
|
for (subFqName in subFqNames) {
|
||||||
val shortName = subFqName.shortName()
|
val shortName = subFqName.shortName()
|
||||||
@@ -53,7 +63,7 @@ public class SubpackagesScope(private val containingDeclaration: PackageViewDesc
|
|||||||
p.println(javaClass.getSimpleName(), " {")
|
p.println(javaClass.getSimpleName(), " {")
|
||||||
p.pushIndent()
|
p.pushIndent()
|
||||||
|
|
||||||
p.println("thisDescriptor = ", containingDeclaration)
|
p.println("thisDescriptor = ", getContainingDeclaration())
|
||||||
|
|
||||||
p.popIndent()
|
p.popIndent()
|
||||||
p.println("}")
|
p.println("}")
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ public val DeclarationDescriptor.module: ModuleDescriptor
|
|||||||
|
|
||||||
public fun ModuleDescriptor.resolveTopLevelClass(topLevelClassFqName: FqName): ClassDescriptor? {
|
public fun ModuleDescriptor.resolveTopLevelClass(topLevelClassFqName: FqName): ClassDescriptor? {
|
||||||
assert(!topLevelClassFqName.isRoot())
|
assert(!topLevelClassFqName.isRoot())
|
||||||
return getPackage(topLevelClassFqName.parent())?.memberScope
|
return getPackage(topLevelClassFqName.parent()).memberScope.getClassifier(topLevelClassFqName.shortName()) as? ClassDescriptor
|
||||||
?.getClassifier(topLevelClassFqName.shortName()) as? ClassDescriptor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public val ClassDescriptor.classId: ClassId
|
public val ClassDescriptor.classId: ClassId
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class KPackageImpl(override val jClass: Class<*>) : KCallableContainerImpl(), KP
|
|||||||
val moduleData = jClass.getOrCreateModule()
|
val moduleData = jClass.getOrCreateModule()
|
||||||
val fqName = jClass.classId.getPackageFqName()
|
val fqName = jClass.classId.getPackageFqName()
|
||||||
|
|
||||||
moduleData.module.getPackage(fqName) ?: throw KotlinReflectionInternalError("Package not resolved: $fqName")
|
moduleData.module.getPackage(fqName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val scope: JetScope get() = descriptor.memberScope
|
override val scope: JetScope get() = descriptor.memberScope
|
||||||
|
|||||||
@@ -181,7 +181,6 @@ public abstract class ElementResolver protected constructor(
|
|||||||
if (trace.getBindingContext()[BindingContext.REFERENCE_TARGET, jetElement] == null) {
|
if (trace.getBindingContext()[BindingContext.REFERENCE_TARGET, jetElement] == null) {
|
||||||
val fqName = header.getFqName(jetElement)
|
val fqName = header.getFqName(jetElement)
|
||||||
val packageDescriptor = resolveSession.getModuleDescriptor().getPackage(fqName)
|
val packageDescriptor = resolveSession.getModuleDescriptor().getPackage(fqName)
|
||||||
?: error("Package descriptor should be present in session for $fqName")
|
|
||||||
trace.record(BindingContext.REFERENCE_TARGET, jetElement, packageDescriptor)
|
trace.record(BindingContext.REFERENCE_TARGET, jetElement, packageDescriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -410,14 +409,13 @@ public abstract class ElementResolver protected constructor(
|
|||||||
|
|
||||||
// Inside import
|
// Inside import
|
||||||
if (expression.getParentOfType<JetImportDirective>(false) != null) {
|
if (expression.getParentOfType<JetImportDirective>(false) != null) {
|
||||||
val rootPackage = resolveSession.getModuleDescriptor().getPackage(FqName.ROOT)!!
|
val rootPackage = resolveSession.getModuleDescriptor().getPackage(FqName.ROOT)
|
||||||
|
|
||||||
if (parent is JetDotQualifiedExpression) {
|
if (parent is JetDotQualifiedExpression) {
|
||||||
val element = parent.getReceiverExpression()
|
val element = parent.getReceiverExpression()
|
||||||
val fqName = expression.getContainingJetFile().getPackageFqName()
|
val fqName = expression.getContainingJetFile().getPackageFqName()
|
||||||
|
|
||||||
val filePackage = resolveSession.getModuleDescriptor().getPackage(fqName)
|
val filePackage = resolveSession.getModuleDescriptor().getPackage(fqName)
|
||||||
?: error("File package should be already resolved and be found")
|
|
||||||
|
|
||||||
val descriptors = if (element is JetDotQualifiedExpression) {
|
val descriptors = if (element is JetDotQualifiedExpression) {
|
||||||
qualifiedExpressionResolver.lookupDescriptorsForQualifiedExpression(
|
qualifiedExpressionResolver.lookupDescriptorsForQualifiedExpression(
|
||||||
@@ -439,7 +437,7 @@ public abstract class ElementResolver protected constructor(
|
|||||||
val packageDirective = expression.getParentOfType<JetPackageDirective>(false)
|
val packageDirective = expression.getParentOfType<JetPackageDirective>(false)
|
||||||
if (packageDirective != null) {
|
if (packageDirective != null) {
|
||||||
val packageDescriptor = resolveSession.getModuleDescriptor().getPackage(packageDirective.getFqName(expression as JetSimpleNameExpression).parent())
|
val packageDescriptor = resolveSession.getModuleDescriptor().getPackage(packageDirective.getFqName(expression as JetSimpleNameExpression).parent())
|
||||||
return packageDescriptor?.memberScope
|
return packageDescriptor.memberScope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -128,7 +128,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
|||||||
|
|
||||||
// make sure we create a package descriptor
|
// make sure we create a package descriptor
|
||||||
PackageViewDescriptor packageDescriptor = session.getModuleDescriptor().getPackage(packageFqName);
|
PackageViewDescriptor packageDescriptor = session.getModuleDescriptor().getPackage(packageFqName);
|
||||||
if (packageDescriptor == null) {
|
if (packageDescriptor.isEmpty()) {
|
||||||
LOG.warn("No descriptor found for package " + packageFqName + " in file " + file.getName() + "\n" + file.getText());
|
LOG.warn("No descriptor found for package " + packageFqName + " in file " + file.getName() + "\n" + file.getText());
|
||||||
session.forceResolveAll();
|
session.forceResolveAll();
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -127,10 +127,7 @@ private fun resolveParamLink(fromDescriptor: DeclarationDescriptor, qualifiedNam
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getPackageInnerScope(descriptor: PackageFragmentDescriptor): JetScope {
|
private fun getPackageInnerScope(descriptor: PackageFragmentDescriptor): JetScope {
|
||||||
val module = descriptor.getContainingDeclaration()
|
return descriptor.getContainingDeclaration().getPackage(descriptor.fqName).memberScope
|
||||||
val packageView = module.getPackage(descriptor.fqName)
|
|
||||||
val packageScope = packageView!!.memberScope
|
|
||||||
return packageScope
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getClassInnerScope(outerScope: JetScope, descriptor: ClassDescriptor): JetScope {
|
private fun getClassInnerScope(outerScope: JetScope, descriptor: ClassDescriptor): JetScope {
|
||||||
|
|||||||
-1
@@ -122,7 +122,6 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PackageViewDescriptor packageView = newModuleContext.getModule().getPackage(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME);
|
PackageViewDescriptor packageView = newModuleContext.getModule().getPackage(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME);
|
||||||
assert packageView != null : "Should contain " + KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME + " package";
|
|
||||||
List<PackageFragmentDescriptor> fragments = packageView.getFragments();
|
List<PackageFragmentDescriptor> fragments = packageView.getFragments();
|
||||||
|
|
||||||
BuiltInsReferenceResolver.this.moduleDescriptor = newModuleContext.getModule();
|
BuiltInsReferenceResolver.this.moduleDescriptor = newModuleContext.getModule();
|
||||||
|
|||||||
@@ -61,11 +61,6 @@ fun findPackagePartInternalNameForLibraryFile(topLevelDeclaration: JetDeclaratio
|
|||||||
|
|
||||||
val packageFqName = topLevelDeclaration.getContainingJetFile().getPackageFqName()
|
val packageFqName = topLevelDeclaration.getContainingJetFile().getPackageFqName()
|
||||||
val packageDescriptor = descriptor.module.getPackage(packageFqName)
|
val packageDescriptor = descriptor.module.getPackage(packageFqName)
|
||||||
if (packageDescriptor == null) {
|
|
||||||
reportError(topLevelDeclaration, descriptor)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
val descFromSourceText = render(descriptor)
|
val descFromSourceText = render(descriptor)
|
||||||
|
|
||||||
val descriptors: Collection<CallableDescriptor> = when (descriptor) {
|
val descriptors: Collection<CallableDescriptor> = when (descriptor) {
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
return when (descriptor) {
|
return when (descriptor) {
|
||||||
is PackageFragmentDescriptor -> {
|
is PackageFragmentDescriptor -> {
|
||||||
val moduleDescriptor = descriptor.getContainingDeclaration()
|
val moduleDescriptor = descriptor.getContainingDeclaration()
|
||||||
getResolutionScope(moduleDescriptor.getPackage(descriptor.fqName)!!)
|
getResolutionScope(moduleDescriptor.getPackage(descriptor.fqName))
|
||||||
}
|
}
|
||||||
|
|
||||||
is PackageViewDescriptor ->
|
is PackageViewDescriptor ->
|
||||||
|
|||||||
+1
-1
@@ -329,7 +329,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
|
|
||||||
private fun getDeclarationScope(): JetScope {
|
private fun getDeclarationScope(): JetScope {
|
||||||
if (config.isExtension || receiverClassDescriptor == null) {
|
if (config.isExtension || receiverClassDescriptor == null) {
|
||||||
return currentFileModule.getPackage(config.currentFile.getPackageFqName())!!.memberScope
|
return currentFileModule.getPackage(config.currentFile.getPackageFqName()).memberScope
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receiverClassDescriptor is ClassDescriptorWithResolutionScopes) {
|
if (receiverClassDescriptor is ClassDescriptorWithResolutionScopes) {
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
|||||||
}
|
}
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
|
|
||||||
val filePackage = moduleDescriptor.getPackage(file.getPackageFqName())!!
|
val filePackage = moduleDescriptor.getPackage(file.getPackageFqName())
|
||||||
|
|
||||||
fun isVisible(descriptor: DeclarationDescriptor): Boolean {
|
fun isVisible(descriptor: DeclarationDescriptor): Boolean {
|
||||||
if (descriptor !is DeclarationDescriptorWithVisibility) return true
|
if (descriptor !is DeclarationDescriptorWithVisibility) return true
|
||||||
@@ -263,7 +263,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
|||||||
|
|
||||||
private fun getMemberScope(fqName: FqName, moduleDescriptor: ModuleDescriptor): JetScope? {
|
private fun getMemberScope(fqName: FqName, moduleDescriptor: ModuleDescriptor): JetScope? {
|
||||||
val packageView = moduleDescriptor.getPackage(fqName)
|
val packageView = moduleDescriptor.getPackage(fqName)
|
||||||
if (packageView != null) {
|
if (!packageView.isEmpty()) {
|
||||||
return packageView.memberScope
|
return packageView.memberScope
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -67,8 +67,7 @@ private class ResolverForDecompilerImpl(val module: ModuleDescriptor) : Resolver
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun resolveDeclarationsInPackage(packageFqName: FqName): Collection<DeclarationDescriptor> {
|
override fun resolveDeclarationsInPackage(packageFqName: FqName): Collection<DeclarationDescriptor> {
|
||||||
val packageView = module.getPackage(packageFqName) ?: return listOf()
|
return module.getPackage(packageFqName).memberScope.getAllDescriptors() filter {
|
||||||
return packageView.memberScope.getAllDescriptors() filter {
|
|
||||||
it is CallableMemberDescriptor && it.module != KotlinBuiltIns.getInstance().getBuiltInsModule()
|
it is CallableMemberDescriptor && it.module != KotlinBuiltIns.getInstance().getBuiltInsModule()
|
||||||
} sortBy MemberComparator.INSTANCE
|
} sortBy MemberComparator.INSTANCE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
|
|||||||
val scopeToSearch = if (classIdStr != null) {
|
val scopeToSearch = if (classIdStr != null) {
|
||||||
module.findClassAcrossModuleDependencies(classIdStr.toClassId())!!.getDefaultType().getMemberScope()
|
module.findClassAcrossModuleDependencies(classIdStr.toClassId())!!.getDefaultType().getMemberScope()
|
||||||
} else {
|
} else {
|
||||||
module.getPackage(FqName(packageFqnStr!!))!!.memberScope
|
module.getPackage(FqName(packageFqnStr!!)).memberScope
|
||||||
}
|
}
|
||||||
|
|
||||||
val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(findDescriptorToRename(scopeToSearch))!!
|
val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(findDescriptorToRename(scopeToSearch))!!
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public abstract class AbstractResolveByStubTest extends KotlinCodeInsightTestCas
|
|||||||
JetFile file = (JetFile) getFile();
|
JetFile file = (JetFile) getFile();
|
||||||
ModuleDescriptor module = ResolvePackage.findModuleDescriptor(file);
|
ModuleDescriptor module = ResolvePackage.findModuleDescriptor(file);
|
||||||
PackageViewDescriptor packageViewDescriptor = module.getPackage(new FqName("test"));
|
PackageViewDescriptor packageViewDescriptor = module.getPackage(new FqName("test"));
|
||||||
Assert.assertNotNull(packageViewDescriptor);
|
Assert.assertFalse(packageViewDescriptor.isEmpty());
|
||||||
|
|
||||||
File fileToCompareTo = new File(FileUtil.getNameWithoutExtension(path) + ".txt");
|
File fileToCompareTo = new File(FileUtil.getNameWithoutExtension(path) + ".txt");
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -101,7 +101,7 @@ public object KotlinJavascriptSerializationUtil {
|
|||||||
KotlinJavascriptMetadataUtils.formatMetadataAsString(moduleName, moduleDescriptor.toBinaryMetadata())
|
KotlinJavascriptMetadataUtils.formatMetadataAsString(moduleName, moduleDescriptor.toBinaryMetadata())
|
||||||
|
|
||||||
fun serializePackage(module: ModuleDescriptor, fqName: FqName, writeFun: (String, ByteArrayOutputStream) -> Unit) {
|
fun serializePackage(module: ModuleDescriptor, fqName: FqName, writeFun: (String, ByteArrayOutputStream) -> Unit) {
|
||||||
val packageView = module.getPackage(fqName) ?: error("No package resolved in $module")
|
val packageView = module.getPackage(fqName)
|
||||||
|
|
||||||
val skip: (DeclarationDescriptor) -> Boolean = { DescriptorUtils.getContainingModule(it) != module }
|
val skip: (DeclarationDescriptor) -> Boolean = { DescriptorUtils.getContainingModule(it) != module }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user