Pass BindingContext to CodegenUtil.getActualDeclarations
Will be used in a subsequent commit. Also rename getActualDeclarations -> getDeclarationsToGenerate
This commit is contained in:
@@ -85,7 +85,7 @@ class MultifileClassCodegenImpl(
|
||||
private val partInternalNamesSorted = run {
|
||||
val partInternalNamesSet = hashSetOf<String>()
|
||||
for (file in files) {
|
||||
if (file.hasDeclarationsForPartClass()) {
|
||||
if (file.hasDeclarationsForPartClass(state.bindingContext)) {
|
||||
partInternalNamesSet.add(JvmFileClassUtil.getFileClassInternalName(file))
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ class MultifileClassCodegenImpl(
|
||||
|
||||
val singleSourceFile =
|
||||
if (previouslyCompiledCallables.isEmpty())
|
||||
files.singleOrNull { it.hasDeclarationsForPartClass() }
|
||||
files.singleOrNull { it.hasDeclarationsForPartClass(state.bindingContext) }
|
||||
else
|
||||
null
|
||||
|
||||
@@ -209,7 +209,9 @@ class MultifileClassCodegenImpl(
|
||||
|
||||
generateNonPartClassDeclarations(file, partContext)
|
||||
|
||||
if (!state.generateDeclaredClassFilter.shouldGeneratePackagePart(file) || !file.hasDeclarationsForPartClass()) return
|
||||
if (!state.generateDeclaredClassFilter.shouldGeneratePackagePart(file) ||
|
||||
!file.hasDeclarationsForPartClass(state.bindingContext)
|
||||
) return
|
||||
|
||||
packagePartRegistry.addPart(partType.internalName, facadeClassType.internalName)
|
||||
|
||||
@@ -243,7 +245,7 @@ class MultifileClassCodegenImpl(
|
||||
private fun addDelegateGenerationTasksForDeclarationsInFile(file: KtFile, packageFragment: PackageFragmentDescriptor, partType: Type) {
|
||||
val facadeContext = state.rootContext.intoMultifileClass(packageFragment, facadeClassType, partType)
|
||||
val memberCodegen = createCodegenForDelegatesInMultifileFacade(facadeContext)
|
||||
for (declaration in CodegenUtil.getActualDeclarations(file)) {
|
||||
for (declaration in CodegenUtil.getDeclarationsToGenerate(file, state.bindingContext)) {
|
||||
if (declaration is KtNamedFunction || declaration is KtProperty || declaration is KtTypeAlias) {
|
||||
val descriptor = state.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
|
||||
if (descriptor !is MemberDescriptor) {
|
||||
@@ -375,8 +377,8 @@ class MultifileClassCodegenImpl(
|
||||
return fragments.firstOrNull()
|
||||
}
|
||||
|
||||
private fun KtFile.hasDeclarationsForPartClass() =
|
||||
CodegenUtil.getActualDeclarations(this).any { it is KtProperty || it is KtFunction || it is KtTypeAlias }
|
||||
private fun KtFile.hasDeclarationsForPartClass(bindingContext: BindingContext) =
|
||||
CodegenUtil.getDeclarationsToGenerate(this, bindingContext).any { it is KtProperty || it is KtFunction || it is KtTypeAlias }
|
||||
|
||||
private fun getCompiledPackageFragment(
|
||||
facadeFqName: FqName, state: GenerationState
|
||||
|
||||
@@ -132,7 +132,7 @@ class MultifileClassPartCodegen(
|
||||
}
|
||||
|
||||
override fun generateBody() {
|
||||
for (declaration in CodegenUtil.getActualDeclarations(element)) {
|
||||
for (declaration in CodegenUtil.getDeclarationsToGenerate(element, state.bindingContext)) {
|
||||
if (declaration is KtNamedFunction || declaration is KtProperty || declaration is KtTypeAlias) {
|
||||
genSimpleMember(declaration)
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class PackageCodegenImpl implements PackageCodegen {
|
||||
|
||||
List<KtClassOrObject> classOrObjects = new ArrayList<>();
|
||||
|
||||
for (KtDeclaration declaration : CodegenUtil.getActualDeclarations(file)) {
|
||||
for (KtDeclaration declaration : CodegenUtil.getDeclarationsToGenerate(file, state.getBindingContext())) {
|
||||
if (isFilePartDeclaration(declaration)) {
|
||||
generatePackagePart = true;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class PackagePartCodegen extends MemberCodegen<KtFile> {
|
||||
|
||||
@Override
|
||||
protected void generateBody() {
|
||||
for (KtDeclaration declaration : CodegenUtil.getActualDeclarations(element)) {
|
||||
for (KtDeclaration declaration : CodegenUtil.getDeclarationsToGenerate(element, state.getBindingContext())) {
|
||||
if (declaration instanceof KtNamedFunction || declaration instanceof KtProperty || declaration instanceof KtTypeAlias) {
|
||||
genSimpleMember(declaration);
|
||||
}
|
||||
@@ -123,7 +123,8 @@ public class PackagePartCodegen extends MemberCodegen<KtFile> {
|
||||
@NotNull Type packagePartType
|
||||
) {
|
||||
BindingContext bindingContext = codegen.bindingContext;
|
||||
List<DeclarationDescriptor> members = CollectionsKt.mapNotNull(CodegenUtil.getActualDeclarations(codegen.element), declaration -> {
|
||||
List<KtDeclaration> allDeclarations = CodegenUtil.getDeclarationsToGenerate(codegen.element, bindingContext);
|
||||
List<DeclarationDescriptor> members = CollectionsKt.mapNotNull(allDeclarations, declaration -> {
|
||||
if (declaration instanceof KtNamedFunction) {
|
||||
return bindingContext.get(BindingContext.FUNCTION, declaration);
|
||||
}
|
||||
|
||||
@@ -193,8 +193,10 @@ public class SamWrapperCodegen {
|
||||
@NotNull KtFile containingFile,
|
||||
CallableMemberDescriptor contextDescriptor
|
||||
) {
|
||||
boolean hasPackagePartClass =
|
||||
CollectionsKt.any(CodegenUtil.getActualDeclarations(containingFile), PackageCodegenImpl::isFilePartDeclaration);
|
||||
boolean hasPackagePartClass = CollectionsKt.any(
|
||||
CodegenUtil.getDeclarationsToGenerate(containingFile, state.getBindingContext()),
|
||||
PackageCodegenImpl::isFilePartDeclaration
|
||||
);
|
||||
FqName filePartFqName = JvmFileClassUtil.getFileClassInfoNoResolve(containingFile).getFileClassFqName();
|
||||
|
||||
FqName outermostOwner;
|
||||
|
||||
Reference in New Issue
Block a user