Refactoring: decomposition of checkExposed... methods
This commit is contained in:
@@ -207,16 +207,40 @@ public class DeclarationsChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkClassExposedType(@NotNull JetClassOrObject klass, @NotNull ClassDescriptor classDescriptor) {
|
private void checkClassExposedType(@NotNull JetClassOrObject klass, @NotNull ClassDescriptor classDescriptor) {
|
||||||
|
checkExposedSupertypes(klass, classDescriptor);
|
||||||
|
checkExposedParameterBounds(klass, classDescriptor);
|
||||||
|
|
||||||
|
if (classDescriptor.getUnsubstitutedPrimaryConstructor() != null && klass.getPrimaryConstructor() != null) {
|
||||||
|
checkFunctionExposedType(klass.getPrimaryConstructor(), classDescriptor.getUnsubstitutedPrimaryConstructor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkExposedParameterBounds(@NotNull JetClassOrObject klass, @NotNull ClassDescriptor classDescriptor) {
|
||||||
|
EffectiveVisibility classVisibility = EffectiveVisibility.Companion.forClass(classDescriptor);
|
||||||
|
List<JetTypeParameter> typeParameterList = klass.getTypeParameters();
|
||||||
|
int i = 0;
|
||||||
|
for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getTypeConstructor().getParameters()) {
|
||||||
|
if (i >= typeParameterList.size()) return;
|
||||||
|
for (JetType upperBound : typeParameterDescriptor.getUpperBounds()) {
|
||||||
|
EffectiveVisibility upperBoundVisibility = EffectiveVisibility.Companion.forType(upperBound);
|
||||||
|
if (!upperBoundVisibility.sameOrMorePermissive(classVisibility)) {
|
||||||
|
JetTypeParameter typeParameter = typeParameterList.get(i);
|
||||||
|
trace.report(EXPOSED_TYPE_PARAMETER_BOUND.on(typeParameter, classVisibility, upperBoundVisibility));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkExposedSupertypes(@NotNull JetClassOrObject klass, @NotNull ClassDescriptor classDescriptor) {
|
||||||
EffectiveVisibility classVisibility = EffectiveVisibility.Companion.forClass(classDescriptor);
|
EffectiveVisibility classVisibility = EffectiveVisibility.Companion.forClass(classDescriptor);
|
||||||
boolean isInterface = classDescriptor.getKind() == ClassKind.INTERFACE;
|
boolean isInterface = classDescriptor.getKind() == ClassKind.INTERFACE;
|
||||||
List<JetDelegationSpecifier> delegationList = klass.getDelegationSpecifiers();
|
List<JetDelegationSpecifier> delegationList = klass.getDelegationSpecifiers();
|
||||||
int i = -1;
|
int i = -1;
|
||||||
// Encapsulate
|
|
||||||
for (JetType superType : classDescriptor.getTypeConstructor().getSupertypes()) {
|
for (JetType superType : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||||
i++;
|
i++;
|
||||||
if (i >= delegationList.size()) {
|
if (i >= delegationList.size()) return;
|
||||||
break;
|
|
||||||
}
|
|
||||||
ClassDescriptor superDescriptor = TypeUtils.getClassDescriptor(superType);
|
ClassDescriptor superDescriptor = TypeUtils.getClassDescriptor(superType);
|
||||||
if (superDescriptor == null) {
|
if (superDescriptor == null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -235,26 +259,6 @@ public class DeclarationsChecker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Encapsulate
|
|
||||||
List<JetTypeParameter> typeParameterList = klass.getTypeParameters();
|
|
||||||
int j = 0;
|
|
||||||
for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getTypeConstructor().getParameters()) {
|
|
||||||
if (j >= typeParameterList.size()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (JetType upperBound : typeParameterDescriptor.getUpperBounds()) {
|
|
||||||
EffectiveVisibility upperBoundVisibility = EffectiveVisibility.Companion.forType(upperBound);
|
|
||||||
if (!upperBoundVisibility.sameOrMorePermissive(classVisibility)) {
|
|
||||||
JetTypeParameter typeParameter = typeParameterList.get(i);
|
|
||||||
trace.report(EXPOSED_TYPE_PARAMETER_BOUND.on(typeParameter, classVisibility, upperBoundVisibility));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
if (classDescriptor.getUnsubstitutedPrimaryConstructor() != null && klass.getPrimaryConstructor() != null) {
|
|
||||||
checkFunctionExposedType(klass.getPrimaryConstructor(), classDescriptor.getUnsubstitutedPrimaryConstructor());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void removeDuplicateTypes(Set<JetType> conflictingTypes) {
|
private static void removeDuplicateTypes(Set<JetType> conflictingTypes) {
|
||||||
|
|||||||
Reference in New Issue
Block a user