[K/JS] Add ability to exclude declarations from export by a new annotation @JsExport.Ignore.

This commit is contained in:
Artem Kobzar
2022-10-03 11:07:25 +00:00
committed by Space Team
parent 917c8606f5
commit eb2326eabb
49 changed files with 970 additions and 42 deletions
@@ -89,13 +89,8 @@ public class PackageCodegenImpl implements PackageCodegen {
for (KtDeclaration declaration : file.getDeclarations()) {
if (declaration instanceof KtClassOrObject) {
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, declaration);
if (PsiUtilsKt.hasExpectModifier(declaration)) {
if (descriptor != null && OptionalAnnotationUtil.shouldGenerateExpectClass(descriptor)) {
assert OptionalAnnotationUtil.isOptionalAnnotationClass(descriptor) :
"Expect class should be generated only if it's an optional annotation: " + descriptor;
state.getFactory().getPackagePartRegistry().getOptionalAnnotations().add(descriptor);
}
addDescriptorToOptionalAnnotationsIfNeeded((KtClassOrObject) declaration, state);
continue;
}
@@ -120,6 +115,27 @@ public class PackageCodegenImpl implements PackageCodegen {
}
}
private static void addDescriptorToOptionalAnnotationsIfNeeded(@NotNull KtClassOrObject declaration, @NotNull GenerationState state) {
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, declaration);
if (descriptor == null || !OptionalAnnotationUtil.shouldGenerateExpectClass(descriptor)) {
return;
}
assert OptionalAnnotationUtil.isOptionalAnnotationClass(descriptor) :
"Expect class should be generated only if it's an optional annotation: " + descriptor;
state.getFactory().getPackagePartRegistry().getOptionalAnnotations().add(descriptor);
KtClassBody body = declaration.getBody();
if (body != null) {
for (KtDeclaration childDeclaration : body.getDeclarations()) {
if (!(childDeclaration instanceof KtClassOrObject)) continue;
addDescriptorToOptionalAnnotationsIfNeeded((KtClassOrObject) childDeclaration, state);
}
}
}
private void generateFile(@NotNull KtFile file) {
JvmFileClassInfo fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(file);
if (fileClassInfo.getWithJvmMultifileClass()) return;