Refactor getDefaultSupertype, drop obsolete diagnostic

This commit is contained in:
Alexander Udalov
2017-06-19 19:12:31 +03:00
parent 90f2ea87a6
commit 9471f33c38
4 changed files with 8 additions and 22 deletions
@@ -255,8 +255,6 @@ public interface Errors {
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> NO_GENERICS_IN_SUPERTYPE_SPECIFIER = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtTypeReference> SUPERTYPE_APPEARS_TWICE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory3<KtSuperTypeList, TypeParameterDescriptor, ClassDescriptor, Collection<KotlinType>>
@@ -405,7 +405,6 @@ public class DefaultErrorMessages {
MAP.put(NO_COMPANION_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a companion object", NAME);
MAP.put(TYPE_PARAMETER_IS_NOT_AN_EXPRESSION, "Type parameter ''{0}'' is not an expression", NAME);
MAP.put(TYPE_PARAMETER_ON_LHS_OF_DOT, "Type parameter ''{0}'' cannot have or inherit a companion object, so it cannot be on the left hand side of dot", NAME);
MAP.put(NO_GENERICS_IN_SUPERTYPE_SPECIFIER, "Generic arguments of the base type must be specified");
MAP.put(NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE, "Nested {0} accessed via instance reference", RENDER_CLASS_OR_OBJECT_NAME);
MAP.put(NESTED_CLASS_SHOULD_BE_QUALIFIED, "Nested {0} should be qualified as ''{1}''", RENDER_CLASS_OR_OBJECT_NAME, TO_STRING);
@@ -144,9 +144,7 @@ public class DescriptorResolver {
syntheticResolveExtension.addSyntheticSupertypes(classDescriptor, supertypes);
if (supertypes.isEmpty()) {
KotlinType defaultSupertype = correspondingClassOrObject == null ? builtIns.getAnyType() :
getDefaultSupertype(correspondingClassOrObject, trace, classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS);
addValidSupertype(supertypes, defaultSupertype);
addValidSupertype(supertypes, getDefaultSupertype(classDescriptor));
}
return supertypes;
@@ -168,27 +166,18 @@ public class DescriptorResolver {
return false;
}
private KotlinType getDefaultSupertype(KtPureClassOrObject ktClass, BindingTrace trace, boolean isAnnotation) {
// TODO : beautify
if (ktClass instanceof KtEnumEntry) {
KtEnumEntry enumEntry = (KtEnumEntry) ktClass;
KtClassOrObject parent = KtStubbedPsiUtil.getContainingDeclaration(enumEntry, KtClassOrObject.class);
ClassDescriptor parentDescriptor = trace.getBindingContext().get(BindingContext.CLASS, parent);
if (parentDescriptor.getTypeConstructor().getParameters().isEmpty()) {
return parentDescriptor.getDefaultType();
}
else {
trace.report(NO_GENERICS_IN_SUPERTYPE_SPECIFIER.on(enumEntry.getNameIdentifier()));
return ErrorUtils.createErrorType("Supertype not specified");
}
@NotNull
private KotlinType getDefaultSupertype(@NotNull ClassDescriptor classDescriptor) {
if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY) {
return ((ClassDescriptor) classDescriptor.getContainingDeclaration()).getDefaultType();
}
else if (isAnnotation) {
else if (classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS) {
return builtIns.getAnnotationType();
}
return builtIns.getAnyType();
}
public Collection<KotlinType> resolveSuperTypeListEntries(
private static Collection<KotlinType> resolveSuperTypeListEntries(
LexicalScope extensibleScope,
List<KtSuperTypeListEntry> delegationSpecifiers,
@NotNull TypeResolver resolver,
@@ -3,5 +3,5 @@
package bug
public enum class Foo<!TYPE_PARAMETERS_IN_ENUM!><T><!> {
<!NO_GENERICS_IN_SUPERTYPE_SPECIFIER!>A<!><!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><!>()
A<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><!>()
}