KT-650 Prohibit creating class without constructor

This commit is contained in:
svtk
2012-01-24 15:41:38 +04:00
parent ee5fcccda9
commit 70d0cd882b
43 changed files with 170 additions and 218 deletions
@@ -7,6 +7,7 @@ public enum ClassKind {
CLASS, CLASS,
TRAIT, TRAIT,
ENUM_CLASS, ENUM_CLASS,
ENUM_ENTRY,
ANNOTATION_CLASS, ANNOTATION_CLASS,
OBJECT OBJECT
} }
@@ -116,7 +116,6 @@ public interface Errors {
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Property must be initialized or be abstract"); SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Property must be initialized or be abstract");
DiagnosticWithParameterFactory<JetProperty, JetType> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed in traits", DiagnosticParameters.TYPE); DiagnosticWithParameterFactory<JetProperty, JetType> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed in traits", DiagnosticParameters.TYPE);
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field"); SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
DiagnosticWithParameterFactory<JetProperty, JetClass> PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed when no primary constructor is present", DiagnosticParameters.CLASS);
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass>(ERROR, "Abstract property {0} in non-abstract class {1}") { PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass>(ERROR, "Abstract property {0} in non-abstract class {1}") {
@NotNull @NotNull
protected DiagnosticWithPsiElement<JetModifierListOwner> on(@NotNull JetModifierListOwner elementToBlame, @NotNull TextRange textRangeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass aClass) { protected DiagnosticWithPsiElement<JetModifierListOwner> on(@NotNull JetModifierListOwner elementToBlame, @NotNull TextRange textRangeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass aClass) {
@@ -141,19 +140,13 @@ 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 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 = 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");
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_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 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"); SimpleDiagnosticFactory BY_IN_SECONDARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "'by'-clause is only supported for primary constructors");
SimpleDiagnosticFactory INITIALIZER_WITH_NO_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Constructor arguments required"); SimpleDiagnosticFactory INITIALIZER_WITH_NO_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Constructor arguments required");
SimpleDiagnosticFactory MANY_CALLS_TO_THIS = SimpleDiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed"); SimpleDiagnosticFactory MANY_CALLS_TO_THIS = SimpleDiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed");
PsiElementOnlyDiagnosticFactory1<JetModifierList, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "{0} overrides nothing", DescriptorRenderer.TEXT); PsiElementOnlyDiagnosticFactory1<JetModifierList, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "{0} overrides nothing", DescriptorRenderer.TEXT);
PsiElementOnlyDiagnosticFactory1<JetClass, PropertyDescriptor> PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "This class must have a primary constructor, because property {0} has a backing field");
ParameterizedDiagnosticFactory1<JetClassOrObject> PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL = new ParameterizedDiagnosticFactory1<JetClassOrObject>(ERROR, "Class {0} must have a constructor in order to be able to initialize supertypes") {
@Override
protected String makeMessageFor(@NotNull JetClassOrObject argument) {
return JetPsiUtil.safeName(argument.getName());
}
};
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor> VIRTUAL_MEMBER_HIDDEN = PsiElementOnlyDiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", DescriptorRenderer.TEXT); PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor> VIRTUAL_MEMBER_HIDDEN = PsiElementOnlyDiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", DescriptorRenderer.TEXT);
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, VariableDescriptor> UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME); PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, VariableDescriptor> UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME);
@@ -217,7 +210,7 @@ public interface Errors {
SimpleDiagnosticFactory CAST_NEVER_SUCCEEDS = SimpleDiagnosticFactory.create(WARNING, "This cast can never succeed"); SimpleDiagnosticFactory CAST_NEVER_SUCCEEDS = SimpleDiagnosticFactory.create(WARNING, "This cast can never succeed");
DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE); DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE); DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
ParameterizedDiagnosticFactory1<ClassifierDescriptor> NO_CLASS_OBJECT = ParameterizedDiagnosticFactory1.create(ERROR, "Classifier {0} does not have a class object", NAME); ParameterizedDiagnosticFactory1<ClassifierDescriptor> NO_CLASS_OBJECT = ParameterizedDiagnosticFactory1.create(ERROR, "Please specify constructor invocation; classifier {0} does not have a class object", NAME);
SimpleDiagnosticFactory NO_GENERICS_IN_SUPERTYPE_SPECIFIER = SimpleDiagnosticFactory.create(ERROR, "Generic arguments of the base type must be specified"); SimpleDiagnosticFactory NO_GENERICS_IN_SUPERTYPE_SPECIFIER = SimpleDiagnosticFactory.create(ERROR, "Generic arguments of the base type must be specified");
SimpleDiagnosticFactory HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext' property"); SimpleDiagnosticFactory HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext' property");
@@ -27,15 +27,17 @@ public class FunctionSignatureDiagnosticFactory extends DiagnosticFactoryWithMes
// primary constructor // primary constructor
JetClass klass = (JetClass) jetDeclaration; JetClass klass = (JetClass) jetDeclaration;
PsiElement nameAsDeclaration = klass.getNameIdentifier(); PsiElement nameAsDeclaration = klass.getNameIdentifier();
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList(); if (nameAsDeclaration == null){
if (nameAsDeclaration == null || primaryConstructorParameterList == null) {
return klass.getTextRange(); return klass.getTextRange();
} else {
return new TextRange(
nameAsDeclaration.getTextRange().getStartOffset(),
primaryConstructorParameterList.getTextRange().getEndOffset()
);
} }
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
if (primaryConstructorParameterList == null) {
return nameAsDeclaration.getTextRange();
}
return new TextRange(
nameAsDeclaration.getTextRange().getStartOffset(),
primaryConstructorParameterList.getTextRange().getEndOffset()
);
} else { } else {
// safe way // safe way
return jetDeclaration.getTextRange(); return jetDeclaration.getTextRange();
@@ -120,32 +120,26 @@ public class BodyResolver {
context.getTrace().report(SUPERTYPE_INITIALIZED_IN_TRAIT.on(node)); context.getTrace().report(SUPERTYPE_INITIALIZED_IN_TRAIT.on(node));
} }
JetTypeReference typeReference = call.getTypeReference(); JetTypeReference typeReference = call.getTypeReference();
if (typeReference != null) { if (typeReference == null) return;
if (descriptor.getUnsubstitutedPrimaryConstructor() != null) { if (descriptor.getUnsubstitutedPrimaryConstructor() == null) {
OverloadResolutionResults<FunctionDescriptor> results = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY).resolveCall( assert descriptor.getKind() == ClassKind.TRAIT;
context.getTrace(), scopeForConstructor, return;
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE); }
if (results.isSuccess()) { OverloadResolutionResults<FunctionDescriptor> results = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY).resolveCall(
JetType supertype = results.getResultingDescriptor().getReturnType(); context.getTrace(), scopeForConstructor,
recordSupertype(typeReference, supertype); CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE);
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype); if (results.isSuccess()) {
if (classDescriptor != null) { JetType supertype = results.getResultingDescriptor().getReturnType();
if (classDescriptor.getKind() == ClassKind.TRAIT) { recordSupertype(typeReference, supertype);
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(node)); ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
} if (classDescriptor != null) {
} if (classDescriptor.getKind() == ClassKind.TRAIT) {
} context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(node));
else {
recordSupertype(typeReference, context.getTrace().getBindingContext().get(BindingContext.TYPE, typeReference));
} }
} }
else if (descriptor.getKind() != ClassKind.TRAIT) { }
JetType supertype = context.getTrace().getBindingContext().get(BindingContext.TYPE, typeReference); else {
recordSupertype(typeReference, supertype); recordSupertype(typeReference, context.getTrace().getBindingContext().get(BindingContext.TYPE, typeReference));
assert valueArgumentList != null;
context.getTrace().report(PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL.on(valueArgumentList, jetClass));
}
} }
} }
@@ -159,7 +153,18 @@ public class BodyResolver {
if (classDescriptor != null) { if (classDescriptor != null) {
if (descriptor.getKind() != ClassKind.TRAIT) { if (descriptor.getKind() != ClassKind.TRAIT) {
if (classDescriptor.hasConstructors() && !ErrorUtils.isError(classDescriptor.getTypeConstructor()) && classDescriptor.getKind() != ClassKind.TRAIT) { if (classDescriptor.hasConstructors() && !ErrorUtils.isError(classDescriptor.getTypeConstructor()) && classDescriptor.getKind() != ClassKind.TRAIT) {
context.getTrace().report(SUPERTYPE_NOT_INITIALIZED.on(specifier)); 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));
}
} }
} }
} }
@@ -287,9 +292,7 @@ public class BodyResolver {
final CallResolver callResolver = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY); // TODO: dataFlowInfo final CallResolver callResolver = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY); // TODO: dataFlowInfo
JetClass containingClass = PsiTreeUtil.getParentOfType(declaration, JetClass.class); if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
assert containingClass != null : "This must be guaranteed by the parser";
if (!containingClass.hasPrimaryConstructor()) {
context.getTrace().report(SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY.on(declaration.getNameNode())); context.getTrace().report(SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY.on(declaration.getNameNode()));
} }
else { else {
@@ -143,11 +143,12 @@ public class DeclarationResolver {
} }
private void processPrimaryConstructor(MutableClassDescriptor classDescriptor, JetClass klass) { private void processPrimaryConstructor(MutableClassDescriptor classDescriptor, JetClass klass) {
if (!klass.hasPrimaryConstructor()) return;
if (classDescriptor.getKind() == ClassKind.TRAIT) { if (classDescriptor.getKind() == ClassKind.TRAIT) {
// context.getTrace().getErrorHandler().genericError(klass.getPrimaryConstructorParameterList().getNode(), "A trait may not have a constructor"); JetParameterList primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(klass.getPrimaryConstructorParameterList())); if (primaryConstructorParameterList != null) {
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(primaryConstructorParameterList));
}
if (!klass.hasPrimaryConstructor()) return;
} }
// TODO : not all the parameters are real properties // TODO : not all the parameters are real properties
@@ -34,8 +34,6 @@ public class DeclarationsChecker {
} }
public void process() { public void process() {
checkIfPrimaryConstructorIsNecessary();
Map<JetClass, MutableClassDescriptor> classes = context.getClasses(); Map<JetClass, MutableClassDescriptor> classes = context.getClasses();
for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) { for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) {
JetClass aClass = entry.getKey(); JetClass aClass = entry.getKey();
@@ -77,25 +75,6 @@ public class DeclarationsChecker {
} }
private void checkIfPrimaryConstructorIsNecessary() {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
MutableClassDescriptor classDescriptor = entry.getValue();
JetClass jetClass = entry.getKey();
if (!context.completeAnalysisNeeded(jetClass)) return;
if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null && !(classDescriptor.getKind() == ClassKind.TRAIT)) {
for (PropertyDescriptor propertyDescriptor : classDescriptor.getProperties()) {
if (context.getTrace().getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor)) {
PsiElement nameIdentifier = jetClass.getNameIdentifier();
if (nameIdentifier != null) {
context.getTrace().report(PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY.on(jetClass, nameIdentifier, propertyDescriptor));
}
break;
}
}
}
}
}
private void checkClass(JetClass aClass, MutableClassDescriptor classDescriptor) { private void checkClass(JetClass aClass, MutableClassDescriptor classDescriptor) {
checkOpenMembers(aClass, classDescriptor); checkOpenMembers(aClass, classDescriptor);
checkTraitModifiers(aClass); checkTraitModifiers(aClass);
@@ -246,12 +225,6 @@ public class DeclarationsChecker {
else if (!backingFieldRequired) { else if (!backingFieldRequired) {
context.getTrace().report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer)); context.getTrace().report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer));
} }
else if (classDescriptor != null && classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
PsiElement classElement = context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor);
assert classElement instanceof JetClass;
context.getTrace().report(PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR.on(property, initializer, (JetClass) classElement));
}
} }
protected void checkFunction(JetNamedFunction function, NamedFunctionDescriptor functionDescriptor) { protected void checkFunction(JetNamedFunction function, NamedFunctionDescriptor functionDescriptor) {
@@ -788,7 +788,7 @@ public class DescriptorResolver {
@Nullable @Nullable
public ConstructorDescriptorImpl resolvePrimaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass classElement) { public ConstructorDescriptorImpl resolvePrimaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass classElement) {
if (!classElement.hasPrimaryConstructor()) return null; if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY && !classElement.hasPrimaryConstructor()) return null;
return createConstructorDescriptor( return createConstructorDescriptor(
scope, scope,
classDescriptor, classDescriptor,
@@ -105,7 +105,7 @@ public class TypeHierarchyResolver {
@Override @Override
public void visitObjectDeclaration(JetObjectDeclaration declaration) { public void visitObjectDeclaration(JetObjectDeclaration declaration) {
final MutableClassDescriptor objectDescriptor = createClassDescriptorForObject(declaration, owner, outerScope); final MutableClassDescriptor objectDescriptor = createClassDescriptorForObject(declaration, owner, outerScope, ClassKind.OBJECT);
context.getTrace().record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(declaration), objectDescriptor); context.getTrace().record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(declaration), objectDescriptor);
} }
@@ -114,32 +114,27 @@ public class TypeHierarchyResolver {
MutableClassDescriptor classObjectDescriptor = ((MutableClassDescriptor) owner).getClassObjectDescriptor(); MutableClassDescriptor classObjectDescriptor = ((MutableClassDescriptor) owner).getClassObjectDescriptor();
assert classObjectDescriptor != null : enumEntry.getParent().getText(); assert classObjectDescriptor != null : enumEntry.getParent().getText();
if (enumEntry.getPrimaryConstructorParameterList() == null) { if (enumEntry.getPrimaryConstructorParameterList() == null) {
MutableClassDescriptor classDescriptor = createClassDescriptorForObject(enumEntry, classObjectDescriptor, outerScopeForStatic); createClassDescriptorForObject(enumEntry, classObjectDescriptor, outerScopeForStatic, ClassKind.ENUM_ENTRY);
context.getObjects().remove(enumEntry); return;
context.getClasses().put(enumEntry, classDescriptor);
}
else {
// TODO : Special kind for enum entry classes?
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), classObjectDescriptor, outerScope, ClassKind.CLASS);
visitClassOrObject(
enumEntry,
(Map) context.getClasses(),
mutableClassDescriptor
);
classObjectDescriptor.addClassifierDescriptor(mutableClassDescriptor);
} }
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), classObjectDescriptor, outerScope, ClassKind.ENUM_ENTRY);
visitClassOrObject(
enumEntry,
(Map) context.getClasses(),
mutableClassDescriptor
);
classObjectDescriptor.addClassifierDescriptor(mutableClassDescriptor);
} }
private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration, private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration, @NotNull NamespaceLike owner, JetScope scope, ClassKind classKind) {
@NotNull NamespaceLike owner, JetScope scope) { MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, scope, classKind) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, scope, ClassKind.OBJECT) {
@Override @Override
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) { public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
return ClassObjectStatus.NOT_ALLOWED; return ClassObjectStatus.NOT_ALLOWED;
} }
}; };
Map<JetClassOrObject, MutableClassDescriptor> map = classKind == ClassKind.OBJECT ? (Map) context.getObjects() : (Map) context.getClasses();
visitClassOrObject(declaration, (Map) context.getObjects(), mutableClassDescriptor); visitClassOrObject(declaration, map, mutableClassDescriptor);
createPrimaryConstructorForObject((JetDeclaration) declaration, mutableClassDescriptor); createPrimaryConstructorForObject((JetDeclaration) declaration, mutableClassDescriptor);
owner.addObjectDescriptor(mutableClassDescriptor); owner.addObjectDescriptor(mutableClassDescriptor);
context.getTrace().record(BindingContext.CLASS, declaration, mutableClassDescriptor); context.getTrace().record(BindingContext.CLASS, declaration, mutableClassDescriptor);
@@ -176,7 +171,7 @@ public class TypeHierarchyResolver {
public void visitClassObject(JetClassObject classObject) { public void visitClassObject(JetClassObject classObject) {
JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration(); JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();
if (objectDeclaration != null) { if (objectDeclaration != null) {
NamespaceLike.ClassObjectStatus status = owner.setClassObjectDescriptor(createClassDescriptorForObject(objectDeclaration, owner, outerScopeForStatic)); NamespaceLike.ClassObjectStatus status = owner.setClassObjectDescriptor(createClassDescriptorForObject(objectDeclaration, owner, outerScopeForStatic, ClassKind.OBJECT));
switch (status) { switch (status) {
case DUPLICATE: case DUPLICATE:
context.getTrace().report(MANY_CLASS_OBJECTS.on(classObject)); context.getTrace().report(MANY_CLASS_OBJECTS.on(classObject));
@@ -80,7 +80,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (classifier != null) { if (classifier != null) {
context.trace.report(NO_CLASS_OBJECT.on(expression, classifier)); context.trace.report(NO_CLASS_OBJECT.on(expression, classifier));
context.trace.record(REFERENCE_TARGET, expression, classifier); context.trace.record(REFERENCE_TARGET, expression, classifier);
return ErrorUtils.createErrorType("No class object in " + expression.getReferencedName()); return classifier.getDefaultType();
} }
temporaryTrace.commit(); temporaryTrace.commit();
return result[0]; return result[0];
+1 -1
View File
@@ -4,7 +4,7 @@ open class C {
open fun f(): Any = "C f" open fun f(): Any = "C f"
} }
class D() : C { class D() : C() {
override fun f(): String = "D f" override fun f(): String = "D f"
} }
@@ -3,7 +3,7 @@ abstract open class Default {
} }
class MyInt() { class MyInt() {
class object : Default { class object : Default() {
override fun defaultValue(): Int = 610 override fun defaultValue(): Int = 610
} }
} }
@@ -2,7 +2,7 @@ open class Foo {
fun xyzzy(): String = "xyzzy" fun xyzzy(): String = "xyzzy"
} }
class Bar(): Foo { class Bar(): Foo() {
fun test(): String = xyzzy() fun test(): String = xyzzy()
} }
@@ -6,7 +6,7 @@ trait ALE<T> : AL<T> {
fun getOrValue(index: Int, value : T) : T = get(index) ?: value fun getOrValue(index: Int, value : T) : T = get(index) ?: value
} }
class SmartArrayList() : ALE<String>, AL<String> { class SmartArrayList() : ALE<String>, AL<String>() {
} }
fun box() : String { fun box() : String {
@@ -3,7 +3,7 @@ package boundsWithSubstitutors
open class A<T> open class A<T>
class B<X : A<X>>() class B<X : A<X>>()
class C : A<C> class C : A<C>()
val a = B<C>() val a = B<C>()
val a1 = B<<!UPPER_BOUND_VIOLATED!>Int<!>>() val a1 = B<<!UPPER_BOUND_VIOLATED!>Int<!>>()
@@ -1,14 +1,14 @@
open class NoC open class NoC
class NoC1 : NoC class NoC1 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>NoC<!>
class WithC0() : NoC<!NO_CONSTRUCTOR!>()<!> class WithC0() : NoC()
open class WithC1() : NoC open class WithC1() : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>NoC<!>
class NoC2 : <!SUPERTYPE_NOT_INITIALIZED!>WithC1<!> class NoC2 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>WithC1<!>
class NoC3 : WithC1<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!> class NoC3 : WithC1()
class WithC2() : <!SUPERTYPE_NOT_INITIALIZED!>WithC1<!> class WithC2() : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>WithC1<!>
class NoPC { class <!CONFLICTING_OVERLOADS!>NoPC<!> {
<!SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY!>this<!>() {} <!CONFLICTING_OVERLOADS!><!SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST!>this<!>() {}<!>
} }
class WithPC0() { class WithPC0() {
@@ -28,7 +28,7 @@ class WithPC1(a : Int) {
} }
class Foo() : <!SUPERTYPE_NOT_INITIALIZED, FINAL_SUPERTYPE!>WithPC0<!>, <!MANY_CLASSES_IN_SUPERTYPE_LIST, SYNTAX!>this<!>() { class Foo() : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, FINAL_SUPERTYPE!>WithPC0<!>, <!MANY_CLASSES_IN_SUPERTYPE_LIST, SYNTAX!>this<!>() {
} }
@@ -42,9 +42,9 @@ class WithCPI(x : Int) {
val xy : Int = x val xy : Int = x
} }
class <!PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY!>NoCPI<!> { class NoCPI {
val a = <!PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR!>1<!> val a = 1
var ab = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1<!> var ab = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1<!>
get() = 1 get() = 1
set(v) {} set(v) {}
} }
@@ -40,14 +40,14 @@ abstract class Iteratee<in I, out O> {
abstract fun done() : O abstract fun done() : O
} }
class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O> { class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O>() {
override fun process(item: I): Iteratee<I, O> = StrangeIterateeImpl<I, O>(obj) override fun process(item: I): Iteratee<I, O> = StrangeIterateeImpl<I, O>(obj)
override val isDone = true override val isDone = true
override val result = obj override val result = obj
override fun done() = obj override fun done() = obj
} }
abstract class Sum() : Iteratee<Int, Int> { abstract class Sum() : Iteratee<Int, Int>() {
override fun process(item : Int) : Iteratee<Int, Int> { override fun process(item : Int) : Iteratee<Int, Int> {
return foobar.done<Int>(item); return foobar.done<Int>(item);
} }
@@ -71,7 +71,7 @@ package localObjects
fun test() { fun test() {
A.x A.x
val b = object : Foo { val b = object : Foo() {
} }
b.foo() b.foo()
@@ -11,7 +11,7 @@ package override.normal
} }
open class MyClass() : MyTrait, MyAbstractClass { open class MyClass() : MyTrait, MyAbstractClass() {
override fun foo() {} override fun foo() {}
override fun bar() {} override fun bar() {}
@@ -21,21 +21,21 @@ package override.normal
class MyChildClass() : MyClass() {} class MyChildClass() : MyClass() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass<!> : MyTrait, MyAbstractClass {} class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass<!> : MyTrait, MyAbstractClass() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!>() : MyTrait, MyAbstractClass { class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!>() : MyTrait, MyAbstractClass() {
override fun foo() {} override fun foo() {}
override val pr : Unit = #() override val pr : Unit = #()
override val prr : Unit = #() override val prr : Unit = #()
} }
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass3<!>() : MyTrait, MyAbstractClass { class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass3<!>() : MyTrait, MyAbstractClass() {
override fun bar() {} override fun bar() {}
override val pr : Unit = #() override val pr : Unit = #()
override val prr : Unit = #() override val prr : Unit = #()
} }
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass4<!>() : MyTrait, MyAbstractClass { class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass4<!>() : MyTrait, MyAbstractClass() {
fun <!VIRTUAL_MEMBER_HIDDEN!>foo<!>() {} fun <!VIRTUAL_MEMBER_HIDDEN!>foo<!>() {}
val <!VIRTUAL_MEMBER_HIDDEN, MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>pr<!> : Unit val <!VIRTUAL_MEMBER_HIDDEN, MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>pr<!> : Unit
<!NOTHING_TO_OVERRIDE!>override<!> fun other() {} <!NOTHING_TO_OVERRIDE!>override<!> fun other() {}
@@ -65,7 +65,7 @@ package override.generics
val p : T val p : T
} }
open class MyGenericClass<T>(t : T) : MyTrait<T>, MyAbstractClass<T>, MyProps<T> { open class MyGenericClass<T>(t : T) : MyTrait<T>, MyAbstractClass<T>(), MyProps<T> {
override fun foo(t: T) = t override fun foo(t: T) = t
override fun bar(t: T) = t override fun bar(t: T) = t
override val p : T = t override val p : T = t
@@ -81,31 +81,31 @@ package override.generics
override val p : T = t override val p : T = t
} }
open class MyClass() : MyTrait<Int>, MyAbstractClass<String> { open class MyClass() : MyTrait<Int>, MyAbstractClass<String>() {
override fun foo(i: Int) = i override fun foo(i: Int) = i
override fun bar(s: String) = s override fun bar(s: String) = s
override val pr : String = "1" override val pr : String = "1"
} }
abstract class MyAbstractClass1 : MyTrait<Int>, MyAbstractClass<String> { abstract class MyAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {
override fun foo(i: Int) = i override fun foo(i: Int) = i
override fun bar(s: String) = s override fun bar(s: String) = s
} }
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T> {} class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T>() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R>(r : R) : MyTrait<T>, MyAbstractClass<R> { class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R>(r : R) : MyTrait<T>, MyAbstractClass<R>() {
<!NOTHING_TO_OVERRIDE!>override<!> fun foo(r: R) = r <!NOTHING_TO_OVERRIDE!>override<!> fun foo(r: R) = r
<!NOTHING_TO_OVERRIDE!>override<!> val <T> pr : R = r <!NOTHING_TO_OVERRIDE!>override<!> val <T> pr : R = r
} }
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String> {} class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String>() {}
abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String> {} abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!><T>(t : T) : MyTrait<Int>, MyAbstractClass<Int> { class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!><T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t fun foo(t: T) = t
fun bar(t: T) = t fun bar(t: T) = t
val <R> pr : T = t val <R> pr : T = t
} }
abstract class MyLegalAbstractClass2<T>(t : T) : MyTrait<Int>, MyAbstractClass<Int> { abstract class MyLegalAbstractClass2<T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t fun foo(t: T) = t
fun bar(t: T) = t fun bar(t: T) = t
val <R> pr : T = t val <R> pr : T = t
@@ -1,4 +1,6 @@
class <!PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY!>X<!> { //+JDK
class X {
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>x<!> : Int val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>x<!> : Int
} }
@@ -10,5 +12,20 @@ class Y1 {
val x : Int get() = 1 val x : Int get() = 1
} }
class Z : Y<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!> { class Z : Y() {
}
//KT-650 Prohibit creating class without constructor.
class MyIterable<T> : Iterable<T>
{
override fun iterator(): Iterator<T> = MyIterator()
class MyIterator : Iterator<T>
{
override val hasNext: Boolean = false
override fun next(): T {
throw UnsupportedOperationException()
}
}
} }
@@ -39,13 +39,12 @@ trait Test6 : <!FINAL_SUPERTYPE!>C1<!> {}
class CTest1() : OC1() {} class CTest1() : OC1() {}
class CTest2 : C2 {} class CTest2 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>C2<!> {}
class CTest3 : C2, <!MANY_CLASSES_IN_SUPERTYPE_LIST!>C3<!> {} class CTest3 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>C2<!>, <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, MANY_CLASSES_IN_SUPERTYPE_LIST!>C3<!> {}
class CTest4 : T1 {} class CTest4 : T1 {}
class CTest5 : T1, <!SUPERTYPE_APPEARS_TWICE!>T1<!> {} class CTest5 : T1, <!SUPERTYPE_APPEARS_TWICE!>T1<!> {}
class CTest6 : <!SUPERTYPE_NOT_INITIALIZED, FINAL_SUPERTYPE!>C1<!> {} class CTest6 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, FINAL_SUPERTYPE!>C1<!> {}
@@ -7,5 +7,5 @@ trait Foo<!CONSTRUCTOR_IN_TRAIT!>()<!> : bar<!SUPERTYPE_INITIALIZED_IN_TRAIT!>()
trait Foo2 : bar, Foo { trait Foo2 : bar, Foo {
} }
open class Foo1() : bar(), <!SUPERTYPE_NOT_INITIALIZED, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!>, Foo, <!SUPERTYPE_APPEARS_TWICE!>Foo<!><!CONSTRUCTOR_IN_TRAIT!>()<!> {} open class Foo1() : bar(), <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!>, Foo, <!SUPERTYPE_APPEARS_TWICE!>Foo<!><!CONSTRUCTOR_IN_TRAIT!>()<!> {}
open class Foo12 : bar<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!>, <!SUPERTYPE_NOT_INITIALIZED, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!> {} open class Foo12 : bar(), <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!> {}
@@ -5,7 +5,7 @@ import java.util.List;
open class A open class A
class B : A class B : A()
fun ff(l: Collection<B>) = l is List<out A> fun ff(l: Collection<B>) = l is List<out A>
@@ -1,4 +1,4 @@
// JET-11 Redeclaration & Forward reference for classes cause an exception // JET-11 Redeclaration & Forward reference for classes cause an exception
open class <!REDECLARATION!>NoC<!> open class <!REDECLARATION!>NoC<!>
class NoC1 : NoC class NoC1 : NoC()
open class <!REDECLARATION!>NoC<!> open class <!REDECLARATION!>NoC<!>
@@ -7,10 +7,10 @@ open class A {
open fun foo() {} open fun foo() {}
} }
open class B : A { open class B : A() {
override fun foo() {} override fun foo() {}
} }
open class C : B { open class C : B() {
override fun foo() {} override fun foo() {}
} }
+2 -2
View File
@@ -1,12 +1,12 @@
~A~class A { ~A~class A {
~B~class B { ~B~class B {
~B()~this() {} ~B()~this(i: Int) {}
} }
~foo~fun foo(~foo.a~a : `std::Char`Char) = `foo.a`a`:std::Char` ~foo~fun foo(~foo.a~a : `std::Char`Char) = `foo.a`a`:std::Char`
~fooB~fun fooB() = `foo`foo('1')`:std::Char` ~fooB~fun fooB() = `foo`foo('1')`:std::Char`
~foo.1~fun foo() : Int = (1.`std::Int.plus(Int)`plus(1))`:std::Int` ~foo.1~fun foo() : Int = (1.`std::Int.plus(Int)`plus(1))`:std::Int`
~foo1~fun foo1() : `B`B = `B()`B()`:B` ~foo1~fun foo1() : `B`B = `B`B()`:B`
~A.a~val a : `std::Int`Int ~A.a~val a : `std::Int`Int
} }
+1 -1
View File
@@ -11,5 +11,5 @@ package Jet86
} }
val a = `A`A.`A.x`x val a = `A`A.`A.x`x
val c = `B`B.`!error`x val c = `B`B.`B.x`x
val d = B().`B.x`x val d = B().`B.x`x
@@ -8,7 +8,6 @@ fun f_plus(): Int {
} }
~X~class X<~T~T> { ~X~class X<~T~T> {
~X()~this() {}
fun foo(a : `T`T) : `X`X<`T`T>{} fun foo(a : `T`T) : `X`X<`T`T>{}
~plus~fun plus(t : `T`T) : Int {} ~plus~fun plus(t : `T`T) : Int {}
~minus~fun minus(t : String) : Int {} ~minus~fun minus(t : String) : Int {}
@@ -23,7 +22,7 @@ fun f_plus(): Int {
~t~fun <~t.T~T> t(~t.t~t : `t.T`T) : `t.T`T { ~t~fun <~t.T~T> t(~t.t~t : `t.T`T) : `t.T`T {
`t`t<Int>(1)`:std::Int` `t`t<Int>(1)`:std::Int`
`t`t<`t.T`T>(`t.t`t)`:t.T` `t`t<`t.T`T>(`t.t`t)`:t.T`
`X()`X<`t.T`T>() `X`X<`t.T`T>()
1 `std::Int.plus(Int)`+ 1 1 `std::Int.plus(Int)`+ 1
1 `std::Int.plus(Int)`+= 1 1 `std::Int.plus(Int)`+= 1
X<String>() `plus`+ "1" X<String>() `plus`+ "1"
@@ -50,7 +49,6 @@ fun f_plus(): Int {
} }
~Bar~class Bar : Foo { ~Bar~class Bar : Foo {
~Bar()~this() {}
~not~fun not() : String {} ~not~fun not() : String {}
~inc~fun inc() : Bar ~inc~fun inc() : Bar
~dec~fun dec() : Bar ~dec~fun dec() : Bar
@@ -61,7 +59,7 @@ fun f_plus(): Int {
fun <T> tt(t : T) : T { fun <T> tt(t : T) : T {
val x : List<Int> = 0 val x : List<Int> = 0
x`java::java.util.List.get()`[1] x`java::java.util.List.get()`[1]
val foo = `Bar()`Bar() val foo = `Bar`Bar()
foo`!!`[null, 1] foo`!!`[null, 1]
foo`get2`[1, 1] foo`get2`[1, 1]
foo`get1`[1] foo`get1`[1]
@@ -93,12 +93,6 @@ public class QuickFixes {
add(Errors.REDUNDANT_MODIFIER_IN_TRAIT, removeRedundantModifierFactory); add(Errors.REDUNDANT_MODIFIER_IN_TRAIT, removeRedundantModifierFactory);
add(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.FINAL_KEYWORD)); add(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.FINAL_KEYWORD));
add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, RemovePartsFromPropertyFix.createRemoveInitializerFactory());
JetIntentionActionFactory<JetClass> addPrimaryConstructorFactory = AddPrimaryConstructorFix.createFactory();
add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addPrimaryConstructorFactory, DiagnosticParameters.CLASS));
add(Errors.PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY, addPrimaryConstructorFactory);
JetIntentionActionFactory<JetModifierListOwner> addOpenModifierFactory = AddModifierFix.createFactory(JetTokens.OPEN_KEYWORD, new JetToken[]{JetTokens.FINAL_KEYWORD}); JetIntentionActionFactory<JetModifierListOwner> addOpenModifierFactory = AddModifierFix.createFactory(JetTokens.OPEN_KEYWORD, new JetToken[]{JetTokens.FINAL_KEYWORD});
JetIntentionActionFactory<JetModifierListOwner> removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD); JetIntentionActionFactory<JetModifierListOwner> removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD);
add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, DiagnosticParameters.CLASS)); add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, DiagnosticParameters.CLASS));
@@ -1,7 +1,7 @@
open class A<T> open class A<T>
class B<X : A<X>>() class B<X : A<X>>()
class C : A<C> class C : A<C>()
val a = B<C>() val a = B<C>()
val a1 = B<<error>Int</error>>() val a1 = B<<error>Int</error>>()
+3 -3
View File
@@ -2,11 +2,11 @@ package html
import java.util.* import java.util.*
abstract class Factory<T> { trait Factory<T> {
abstract fun create() : T fun create() : T
} }
abstract class Element trait Element
class TextElement(val text : String) : Element class TextElement(val text : String) : Element
+9 -9
View File
@@ -1,15 +1,15 @@
open class NoC open class NoC
class NoC1 : NoC class NoC1 : NoC()
class WithC0() : NoC<error>()</error> class WithC0() : NoC()
open class WithC1() : NoC open class WithC1() : NoC()
class NoC2 : <error>WithC1</error> class NoC2 : <error>WithC1</error>
class NoC3 : WithC1<error>()</error> class NoC3 : WithC1()
class WithC2() : <error>WithC1</error> class WithC2() : <error>WithC1</error>
class NoPC { class <error>NoPC</error> {
<error>this</error>() {} <error><error>this</error>() {}</error>
} }
class WithPC0() { class WithPC0() {
@@ -29,7 +29,7 @@ class WithPC1(a : Int) {
} }
class Foo() : <error>WithPC0</error>, <error>this</error>() { class Foo() : <error>WithPC0</error>(), <error>this</error>() {
} }
@@ -43,8 +43,8 @@ class WithCPI(x : Int) {
val xy : Int = x val xy : Int = x
} }
class <error>NoCPI</error> { class NoCPI {
val a = <error>1</error> val a = 1
var ab = <error>1</error> var ab = <error>1</error>
get() = 1 get() = 1
set(v) {} set(v) {}
+1 -1
View File
@@ -8,7 +8,7 @@
fun test() { fun test() {
A.x A.x
val b = object : Foo { val b = object : Foo() {
} }
b.foo() b.foo()
+2 -2
View File
@@ -14,14 +14,14 @@ abstract class Iteratee<in I, out O> {
abstract fun done() : O abstract fun done() : O
} }
class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O> { class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O>() {
override fun process(item: I): Iteratee<I, O> = StrangeIterateeImpl<I, O>(obj) override fun process(item: I): Iteratee<I, O> = StrangeIterateeImpl<I, O>(obj)
override val isDone = true override val isDone = true
override val result = obj override val result = obj
override fun done() = obj override fun done() = obj
} }
abstract class Sum() : Iteratee<Int, Int> { abstract class Sum() : Iteratee<Int, Int>() {
override fun process(item : Int) : Iteratee<Int, Int> { override fun process(item : Int) : Iteratee<Int, Int> {
return a.done<Int>(item); return a.done<Int>(item);
} }
+7 -7
View File
@@ -8,29 +8,29 @@ package override
abstract fun bar() abstract fun bar()
} }
open class MyClass : MyTrait, MyAbstractClass { open class MyClass : MyTrait, MyAbstractClass() {
override fun foo() {} override fun foo() {}
override fun bar() {} override fun bar() {}
} }
class MyChildClass : MyClass {} class MyChildClass : MyClass() {}
class <error>MyIllegalClass</error> : MyTrait, MyAbstractClass {} class <error>MyIllegalClass</error> : MyTrait, MyAbstractClass() {}
class <error>MyIllegalClass2</error> : MyTrait, MyAbstractClass { class <error>MyIllegalClass2</error> : MyTrait, MyAbstractClass() {
override fun foo() {} override fun foo() {}
} }
class <error>MyIllegalClass3</error> : MyTrait, MyAbstractClass { class <error>MyIllegalClass3</error> : MyTrait, MyAbstractClass() {
override fun bar() {} override fun bar() {}
} }
class <error>MyIllegalClass4</error> : MyTrait, MyAbstractClass { class <error>MyIllegalClass4</error> : MyTrait, MyAbstractClass() {
fun <error>foo</error>() {} fun <error>foo</error>() {}
<error>override</error> fun other() {} <error>override</error> fun other() {}
} }
class MyChildClass1 : MyClass { class MyChildClass1 : MyClass() {
fun <error>foo</error>() {} fun <error>foo</error>() {}
override fun bar() {} override fun bar() {}
} }
@@ -6,30 +6,30 @@
abstract fun bar(t: T) : T abstract fun bar(t: T) : T
} }
open class MyGenericClass<T> : MyTrait<T>, MyAbstractClass<T> { open class MyGenericClass<T> : MyTrait<T>, MyAbstractClass<T>() {
override fun foo(t: T) = t override fun foo(t: T) = t
override fun bar(t: T) = t override fun bar(t: T) = t
} }
class MyChildClass : MyGenericClass<Int> {} class MyChildClass : MyGenericClass<Int>() {}
class MyChildClass1<T> : MyGenericClass<T> {} class MyChildClass1<T> : MyGenericClass<T>() {}
class MyChildClass2<T> : MyGenericClass<T> { class MyChildClass2<T> : MyGenericClass<T>() {
fun <error>foo</error>(t: T) = t fun <error>foo</error>(t: T) = t
override fun bar(t: T) = t override fun bar(t: T) = t
} }
open class MyClass : MyTrait<Int>, MyAbstractClass<String> { open class MyClass : MyTrait<Int>, MyAbstractClass<String>() {
override fun foo(i: Int) = i override fun foo(i: Int) = i
override fun bar(s: String) = s override fun bar(s: String) = s
} }
class <error>MyIllegalGenericClass1</error><T> : MyTrait<T>, MyAbstractClass<T> {} class <error>MyIllegalGenericClass1</error><T> : MyTrait<T>, MyAbstractClass<T>() {}
class <error>MyIllegalGenericClass2</error><T, R> : MyTrait<T>, MyAbstractClass<R> { class <error>MyIllegalGenericClass2</error><T, R> : MyTrait<T>, MyAbstractClass<R>() {
<error>override</error> fun foo(r: R) = r <error>override</error> fun foo(r: R) = r
} }
class <error>MyIllegalClass1</error> : MyTrait<Int>, MyAbstractClass<String> {} class <error>MyIllegalClass1</error> : MyTrait<Int>, MyAbstractClass<String>() {}
class <error>MyIllegalClass2</error><T> : MyTrait<Int>, MyAbstractClass<Int> { class <error>MyIllegalClass2</error><T> : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t fun foo(t: T) = t
fun bar(t: T) = t fun bar(t: T) = t
} }
@@ -1,4 +1,4 @@
class <error>X</error> { class X {
val <error>x</error> : Int val <error>x</error> : Int
} }
@@ -10,5 +10,5 @@ class Y1 {
val x : Int get() = 1 val x : Int get() = 1
} }
class Z : Y<error>()</error> { class Z : Y() {
} }
@@ -39,9 +39,9 @@ trait Test6 : <error>C1</error> {}
class CTest1() : OC1() {} class CTest1() : OC1() {}
class CTest2 : C2 {} class CTest2 : <error>C2</error> {}
class CTest3 : C2, <error>C3</error> {} class CTest3 : <error>C2</error>, <error>C3</error> {}
class CTest4 : T1 {} class CTest4 : T1 {}
+1 -1
View File
@@ -8,4 +8,4 @@ trait Foo2 : bar, Foo {
} }
open class Foo1() : bar(), <error>bar</error>, Foo, <error>Foo</error><error>()</error> {} open class Foo1() : bar(), <error>bar</error>, Foo, <error>Foo</error><error>()</error> {}
open class Foo12 : bar<error>()</error>, <error>bar</error> {} open class Foo12 : bar(), <error>bar</error> {}
+1 -1
View File
@@ -1,4 +1,4 @@
// JET-11 Redeclaration & Forward reference for classes cause an exception // JET-11 Redeclaration & Forward reference for classes cause an exception
open class <error>NoC</error> open class <error>NoC</error>
class NoC1 : NoC class NoC1 : NoC()
open class <error>NoC</error> open class <error>NoC</error>
@@ -1,6 +0,0 @@
// "Add primary constructor to A" "true"
package a
class A() {
var i : Int = <caret>1
}
@@ -1,6 +0,0 @@
// "Add primary constructor to A" "true"
package a
class A<caret>() {
var i : Int = 1
}
@@ -1,6 +0,0 @@
// "Add primary constructor to A" "true"
package a
class A {
var i : Int = <caret>1
}
@@ -1,6 +0,0 @@
// "Add primary constructor to A" "true"
package a
class A<caret> {
var i : Int = 1
}