Pass BindingContext to CodegenUtil.getActualDeclarations
Will be used in a subsequent commit. Also rename getActualDeclarations -> getDeclarationsToGenerate
This commit is contained in:
@@ -167,9 +167,13 @@ object CodegenUtil {
|
||||
return KtPsiFactory(project, markGenerated = false).createExpression(fakeFunctionCall) as KtCallExpression
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns declarations in the given [file] which should be generated by the back-end. This includes all declarations
|
||||
* minus all expected declarations.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getActualDeclarations(file: KtFile): List<KtDeclaration> =
|
||||
file.declarations.filterNot(KtDeclaration::hasExpectModifier)
|
||||
fun getDeclarationsToGenerate(file: KtFile, bindingContext: BindingContext): List<KtDeclaration> =
|
||||
file.declarations.filterNot(KtDeclaration::hasExpectModifier)
|
||||
|
||||
@JvmStatic
|
||||
fun findExpectedFunctionForActual(descriptor: FunctionDescriptor): FunctionDescriptor? {
|
||||
|
||||
@@ -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;
|
||||
|
||||
+4
-4
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
|
||||
@@ -87,7 +88,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
// If there are many files, the first 'box(): String' function will be executed.
|
||||
GeneratedClassLoader generatedClassLoader = generateAndCreateClassLoader();
|
||||
for (KtFile firstFile : myFiles.getPsiFiles()) {
|
||||
String className = getFacadeFqName(firstFile);
|
||||
String className = getFacadeFqName(firstFile, classFileFactory.getGenerationState().getBindingContext());
|
||||
if (className == null) continue;
|
||||
Class<?> aClass = getGeneratedClass(generatedClassLoader, className);
|
||||
try {
|
||||
@@ -108,10 +109,9 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
fail("Can't find box method!");
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private static String getFacadeFqName(@NotNull KtFile firstFile) {
|
||||
for (KtDeclaration declaration : CodegenUtil.getActualDeclarations(firstFile)) {
|
||||
private static String getFacadeFqName(@NotNull KtFile firstFile, @NotNull BindingContext bindingContext) {
|
||||
for (KtDeclaration declaration : CodegenUtil.getDeclarationsToGenerate(firstFile, bindingContext)) {
|
||||
if (declaration instanceof KtProperty || declaration instanceof KtNamedFunction || declaration instanceof KtTypeAlias) {
|
||||
return JvmFileClassUtil.getFileClassInfoNoResolve(firstFile).getFacadeClassFqName().asString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user