Visible classes take priority when resolving imports with *
This commit is contained in:
@@ -31,6 +31,11 @@ public class JavaVisibilities {
|
||||
return areInSamePackage(what, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer compareTo(@NotNull Visibility visibility) {
|
||||
if (this == visibility) return 0;
|
||||
@@ -70,6 +75,11 @@ public class JavaVisibilities {
|
||||
return isVisible(receiver, what, fromClass.getContainingDeclaration());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "protected/*protected static*/";
|
||||
@@ -101,6 +111,11 @@ public class JavaVisibilities {
|
||||
return isVisible(receiver, what, fromClass.getContainingDeclaration());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer compareTo(@NotNull Visibility visibility) {
|
||||
if (this == visibility) return 0;
|
||||
|
||||
@@ -30,6 +30,11 @@ import java.util.Set;
|
||||
|
||||
public class Visibilities {
|
||||
public static final Visibility PRIVATE = new Visibility("private", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
DeclarationDescriptor parent = what;
|
||||
@@ -72,6 +77,11 @@ public class Visibilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "private/*private to this*/";
|
||||
@@ -79,6 +89,11 @@ public class Visibilities {
|
||||
};
|
||||
|
||||
public static final Visibility PROTECTED = new Visibility("protected", true) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
ClassDescriptor classDescriptor = DescriptorUtils.getParentOfType(what, ClassDescriptor.class);
|
||||
@@ -97,6 +112,11 @@ public class Visibilities {
|
||||
};
|
||||
|
||||
public static final Visibility INTERNAL = new Visibility("internal", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
//NOTE: supposedly temporarily
|
||||
@@ -105,6 +125,11 @@ public class Visibilities {
|
||||
};
|
||||
|
||||
public static final Visibility PUBLIC = new Visibility("public", true) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return true;
|
||||
@@ -112,13 +137,23 @@ public class Visibilities {
|
||||
};
|
||||
|
||||
public static final Visibility LOCAL = new Visibility("local", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
throw new IllegalStateException("This method shouldn't be invoked for LOCAL visibility");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
throw new IllegalStateException(); //This method shouldn't be invoked for LOCAL visibility
|
||||
throw new IllegalStateException("This method shouldn't be invoked for LOCAL visibility");
|
||||
}
|
||||
};
|
||||
|
||||
public static final Visibility INHERITED = new Visibility("inherited", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
throw new IllegalStateException("This method shouldn't be invoked for INHERITED visibility");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
throw new IllegalStateException("Visibility is unknown yet"); //This method shouldn't be invoked for INHERITED visibility
|
||||
@@ -127,6 +162,11 @@ public class Visibilities {
|
||||
|
||||
/* Visibility for fake override invisible members (they are created for better error reporting) */
|
||||
public static final Visibility INVISIBLE_FAKE = new Visibility("invisible_fake", false) {
|
||||
@Override
|
||||
public boolean mustCheckInImports() {
|
||||
throw new IllegalStateException("This method shouldn't be invoked for INVISIBLE_FAKE visibility");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return false;
|
||||
|
||||
@@ -32,6 +32,18 @@ public abstract class Visibility {
|
||||
return isPublicAPI;
|
||||
}
|
||||
|
||||
/**
|
||||
* True, if it makes sense to check this visibility in imports and not import inaccessible declarations with such visibility.
|
||||
* Hint: return true, if this visibility can be checked on file's level.
|
||||
* Examples:
|
||||
* it returns false for PROTECTED because protected members of classes can be imported to be used in subclasses of their containers,
|
||||
* so when we are looking at the import, we don't know whether it is legal somewhere in this file or not.
|
||||
* it returns true for INTERNAL, because an internal declaration is either visible everywhere in a file, or invisible everywhere in the same file.
|
||||
* it returns true for PRIVATE, because there's no point in importing privates: they are inaccessible unless their short name is
|
||||
* already available without an import
|
||||
*/
|
||||
public abstract boolean mustCheckInImports();
|
||||
|
||||
/**
|
||||
* @return null if the answer is unknown
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user