'add primary constructor fix' changed to 'change to invocation fix' (for delegators to super class)

This commit is contained in:
svtk
2012-01-24 16:32:52 +04:00
parent 70d0cd882b
commit 428681f1d3
8 changed files with 90 additions and 75 deletions
@@ -140,7 +140,7 @@ public interface Errors {
SimpleDiagnosticFactory PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = SimpleDiagnosticFactory.create(ERROR, "Projections are not allowed on type arguments of functions and properties"); // TODO : better positioning
SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "This type has a constructor, and thus must be initialized here");
SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED_DEFAULT = SimpleDiagnosticFactory.create(ERROR, "Constructor invocation should be explicitly specified");
SimplePsiElementOnlyDiagnosticFactory<JetDelegatorToSuperClass> SUPERTYPE_NOT_INITIALIZED_DEFAULT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Constructor invocation should be explicitly specified");
SimpleDiagnosticFactory SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY = SimpleDiagnosticFactory.create(ERROR, "A secondary constructor may appear only in a class that has a primary constructor");
SimpleDiagnosticFactory SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST = SimpleDiagnosticFactory.create(ERROR, "Secondary constructors must have an initializer list");
SimpleDiagnosticFactory BY_IN_SECONDARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "'by'-clause is only supported for primary constructors");
@@ -148,26 +148,23 @@ public class BodyResolver {
JetTypeReference typeReference = specifier.getTypeReference();
JetType supertype = context.getTrace().getBindingContext().get(BindingContext.TYPE, typeReference);
recordSupertype(typeReference, supertype);
if (supertype != null) {
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
if (classDescriptor != null) {
if (descriptor.getKind() != ClassKind.TRAIT) {
if (classDescriptor.hasConstructors() && !ErrorUtils.isError(classDescriptor.getTypeConstructor()) && classDescriptor.getKind() != ClassKind.TRAIT) {
boolean hasConstructorWithoutParams = false;
for (ConstructorDescriptor constructor : classDescriptor.getConstructors()) {
if (constructor.getValueParameters().isEmpty()) {
hasConstructorWithoutParams = true;
}
}
if (!hasConstructorWithoutParams) {
context.getTrace().report(SUPERTYPE_NOT_INITIALIZED.on(specifier));
}
else {
context.getTrace().report(SUPERTYPE_NOT_INITIALIZED_DEFAULT.on(specifier));
}
}
if (supertype == null) return;
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
if (classDescriptor == null) return;
if (descriptor.getKind() != ClassKind.TRAIT && classDescriptor.hasConstructors() &&
!ErrorUtils.isError(classDescriptor.getTypeConstructor()) && classDescriptor.getKind() != ClassKind.TRAIT) {
boolean hasConstructorWithoutParams = false;
for (ConstructorDescriptor constructor : classDescriptor.getConstructors()) {
if (constructor.getValueParameters().isEmpty()) {
hasConstructorWithoutParams = true;
}
}
if (!hasConstructorWithoutParams) {
context.getTrace().report(SUPERTYPE_NOT_INITIALIZED.on(specifier));
}
else {
context.getTrace().report(SUPERTYPE_NOT_INITIALIZED_DEFAULT.on(specifier));
}
}
}