Introduce UNKNOWN visibility as default in FunctionDescriptor

It's needed to prevent NPE when requesting non-nullable visibility of descriptor
before `initialize` has been called.
Currently it happens because of indirect calls of `DescriptorUtils.isLocal`
between descriptor creation and it's initialization.
This commit is contained in:
Denis Zharkov
2015-06-04 10:59:09 +03:00
parent 4f85afb3f0
commit 0e718fbaab
2 changed files with 17 additions and 1 deletions
@@ -173,6 +173,22 @@ public class Visibilities {
}
};
// Currently used as default visibility of FunctionDescriptor
// It's needed to prevent NPE when requesting non-nullable visibility of descriptor before `initialize` has been called
public static final Visibility UNKNOWN = new Visibility("unknown", false) {
@Override
public boolean mustCheckInImports() {
throw new IllegalStateException("This method shouldn't be invoked for UNKNOWN visibility");
}
@Override
protected boolean isVisible(
@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from
) {
return false;
}
};
public static final Set<Visibility> INVISIBLE_FROM_OTHER_MODULES =
Collections.unmodifiableSet(KotlinPackage.setOf(PRIVATE, PRIVATE_TO_THIS, INTERNAL, LOCAL));
@@ -40,7 +40,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
private ReceiverParameterDescriptor extensionReceiverParameter;
private ReceiverParameterDescriptor dispatchReceiverParameter;
private Modality modality;
private Visibility visibility;
private Visibility visibility = Visibilities.UNKNOWN;
private final Set<FunctionDescriptor> overriddenFunctions = new LinkedHashSet<FunctionDescriptor>(); // LinkedHashSet is essential here
private final FunctionDescriptor original;
private final Kind kind;