diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/AbstractJetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/AbstractJetParsing.java index 826e37cbf6d..b1a90199ee0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/AbstractJetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/AbstractJetParsing.java @@ -276,6 +276,36 @@ import static org.jetbrains.jet.lexer.JetTokens.*; } } + protected class OptionalMarker { + private final PsiBuilder.Marker marker; + private final int offset; + + public OptionalMarker(boolean actuallyMark) { + marker = actuallyMark ? mark() : null; + offset = myBuilder.getCurrentOffset(); + } + + public void done(IElementType elementType) { + if (marker == null) return; + marker.done(elementType); + } + + public void error(String message) { + if (marker == null) return; + if (offset == myBuilder.getCurrentOffset()) { + marker.drop(); // no empty errors + } + else { + marker.error(message); + } + } + + public void drop() { + if (marker == null) return; + marker.drop(); + } + } + protected int matchTokenStreamPredicate(TokenStreamPattern pattern) { PsiBuilder.Marker currentPosition = mark(); Stack opens = new Stack(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java index fc40a92440a..2b873a777d2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -555,21 +555,45 @@ public class JetParsing extends AbstractJetParsing { * typeConstraints * (classBody? | enumClassBody) * ; + * + * object + * : "object" SimpleName? ":" delegationSpecifier{","}? classBody? + * ; */ - IElementType parseClass(boolean enumClass) { - assert _atSet(CLASS_KEYWORD, TRAIT_KEYWORD); - advance(); // CLASS_KEYWORD or TRAIT_KEYWORD + IElementType parseClassOrObject(final boolean object, boolean named, boolean optionalBody, boolean enumClass) { + if (object) { + assert _at(OBJECT_KEYWORD); + } + else { + assert _atSet(CLASS_KEYWORD, TRAIT_KEYWORD); + } + advance(); // CLASS_KEYWORD, TRAIT_KEYWORD or OBJECT_KEYWORD - expect(IDENTIFIER, "Class name expected", CLASS_NAME_RECOVERY_SET); + if (named) { + OptionalMarker marker = new OptionalMarker(object); + expect(IDENTIFIER, "Name expected", CLASS_NAME_RECOVERY_SET); + marker.done(OBJECT_DECLARATION_NAME); + } + else { + if (at(IDENTIFIER)) { + assert object : "Must be an object to be nameless"; + errorAndAdvance("An object expression cannot bind a name"); + } + } + + OptionalMarker typeParamsMarker = new OptionalMarker(object); boolean typeParametersDeclared = parseTypeParameterList(TYPE_PARAMETER_GT_RECOVERY_SET); + typeParamsMarker.error("Type parameters are not allowed for objects"); + OptionalMarker constructorModifiersMarker = new OptionalMarker(object); PsiBuilder.Marker beforeConstructorModifiers = mark(); boolean hasConstructorModifiers = parseModifierList(PRIMARY_CONSTRUCTOR_MODIFIER_LIST, REGULAR_ANNOTATIONS_ONLY_WITH_BRACKETS); // Some modifiers found, but no parentheses following: class has already ended, and we are looking at something else if (hasConstructorModifiers && !atSet(LPAR, LBRACE, COLON) ) { beforeConstructorModifiers.rollbackTo(); - return CLASS; + constructorModifiersMarker.drop(); + return object ? OBJECT_DECLARATION : CLASS; } // We are still inside a class declaration @@ -585,13 +609,16 @@ public class JetParsing extends AbstractJetParsing { // class A private { error("Expecting primary constructor parameter list"); } + constructorModifiersMarker.error("Constructors are not allowed for objects"); - if (at(COLON)) { + if (at(COLON) ) { advance(); // COLON parseDelegationSpecifierList(); } + OptionalMarker whereMarker = new OptionalMarker(object); parseTypeConstraintsGuarded(typeParametersDeclared); + whereMarker.error("Where clause is not allowed for objects"); if (at(LBRACE)) { if (enumClass) { @@ -601,8 +628,21 @@ public class JetParsing extends AbstractJetParsing { parseClassBody(); } } + else if (!optionalBody) { + PsiBuilder.Marker fakeBody = mark(); + error("Expecting a class body"); + fakeBody.done(CLASS_BODY); + } - return CLASS; + return object ? OBJECT_DECLARATION : CLASS; + } + + IElementType parseClass(boolean enumClass) { + return parseClassOrObject(false, true, true, enumClass); + } + + void parseObject(boolean named, boolean optionalBody) { + parseClassOrObject(true, named, optionalBody, false); } /* @@ -768,48 +808,6 @@ public class JetParsing extends AbstractJetParsing { return declType; } - /* - * object - * : "object" SimpleName? ":" delegationSpecifier{","}? classBody? - * ; - */ - void parseObject(boolean named, boolean optionalBody) { - assert _at(OBJECT_KEYWORD); - - advance(); // OBJECT_KEYWORD - - if (named) { - PsiBuilder.Marker propertyDeclaration = mark(); - expect(IDENTIFIER, "Expecting object name", TokenSet.create(LBRACE)); - propertyDeclaration.done(OBJECT_DECLARATION_NAME); - } - else { - if (at(IDENTIFIER)) { - error("An object expression cannot bind a name"); - } - } - - if (optionalBody) { - if (at(COLON)) { - advance(); // COLON - parseDelegationSpecifierList(); - } - if (at(LBRACE)) { - parseClassBody(); - } - } - else { - if (at(LBRACE)) { - parseClassBody(); - } - else { - expect(COLON, "Expecting ':'", TokenSet.create(IDENTIFIER, PACKAGE_KEYWORD)); - parseDelegationSpecifierList(); - parseClassBody(); - } - } - } - /* * initializer{","} */ diff --git a/compiler/testData/psi/TypeDef_ERR.txt b/compiler/testData/psi/TypeDef_ERR.txt index b032ecf10d8..6d2273e6c93 100644 --- a/compiler/testData/psi/TypeDef_ERR.txt +++ b/compiler/testData/psi/TypeDef_ERR.txt @@ -178,7 +178,7 @@ JetFile: TypeDef_ERR.kt PsiWhiteSpace('\n\n') CLASS PsiElement(class)('class') - PsiErrorElement:Class name expected + PsiErrorElement:Name expected PsiWhiteSpace('\n') TYPEDEF diff --git a/compiler/testData/psi/recovery/objects/declarations/ConstructorModifiers.kt b/compiler/testData/psi/recovery/objects/declarations/ConstructorModifiers.kt new file mode 100644 index 00000000000..68a749403e0 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/ConstructorModifiers.kt @@ -0,0 +1,9 @@ +object Foo private () + +object Foo private () {} + +object Foo private () : Bar { + +} + +object Foo [foo] private [bar()] () \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/ConstructorModifiers.txt b/compiler/testData/psi/recovery/objects/declarations/ConstructorModifiers.txt new file mode 100644 index 00000000000..d1c27aa3b24 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/ConstructorModifiers.txt @@ -0,0 +1,99 @@ +JetFile: ConstructorModifiers.kt + PACKAGE_DIRECTIVE + + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/EmptyParentheses.kt b/compiler/testData/psi/recovery/objects/declarations/EmptyParentheses.kt new file mode 100644 index 00000000000..bfee8b8bba7 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/EmptyParentheses.kt @@ -0,0 +1,7 @@ +object Foo() + +object Foo() {} + +object Foo() : Bar { + +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/EmptyParentheses.txt b/compiler/testData/psi/recovery/objects/declarations/EmptyParentheses.txt new file mode 100644 index 00000000000..9c191b0c655 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/EmptyParentheses.txt @@ -0,0 +1,50 @@ +JetFile: EmptyParentheses.kt + PACKAGE_DIRECTIVE + + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/Everything.kt b/compiler/testData/psi/recovery/objects/declarations/Everything.kt new file mode 100644 index 00000000000..210cc26d2b7 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/Everything.kt @@ -0,0 +1,3 @@ +object Foo private (x: Int, y: Int) : Bar, Baz { + fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/Everything.txt b/compiler/testData/psi/recovery/objects/declarations/Everything.txt new file mode 100644 index 00000000000..cdf5176d9d3 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/Everything.txt @@ -0,0 +1,77 @@ +JetFile: Everything.kt + PACKAGE_DIRECTIVE + + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('y') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Baz') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/FollowedByModifiers.kt b/compiler/testData/psi/recovery/objects/declarations/FollowedByModifiers.kt new file mode 100644 index 00000000000..930721fb7a2 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/FollowedByModifiers.kt @@ -0,0 +1,7 @@ +object Foo + +public class Bar + +object Foo + +[foo] class Bar \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/FollowedByModifiers.txt b/compiler/testData/psi/recovery/objects/declarations/FollowedByModifiers.txt new file mode 100644 index 00000000000..c2ce4306741 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/FollowedByModifiers.txt @@ -0,0 +1,38 @@ +JetFile: FollowedByModifiers.kt + PACKAGE_DIRECTIVE + + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiWhiteSpace('\n\n') + CLASS + MODIFIER_LIST + PsiElement(public)('public') + PsiWhiteSpace(' ') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiWhiteSpace('\n\n') + CLASS + MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Bar') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/ParametersInParentheses.kt b/compiler/testData/psi/recovery/objects/declarations/ParametersInParentheses.kt new file mode 100644 index 00000000000..7cd5f327ea8 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/ParametersInParentheses.kt @@ -0,0 +1,7 @@ +object Foo(a: Int, b: String) + +object Foo(a: Int, b: String) {} + +object Foo(a: Int, b: String) : Bar { + +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/ParametersInParentheses.txt b/compiler/testData/psi/recovery/objects/declarations/ParametersInParentheses.txt new file mode 100644 index 00000000000..983b9af1600 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/ParametersInParentheses.txt @@ -0,0 +1,104 @@ +JetFile: ParametersInParentheses.kt + PACKAGE_DIRECTIVE + + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('String') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('String') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('String') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/TypeParametersAndParentheses.kt b/compiler/testData/psi/recovery/objects/declarations/TypeParametersAndParentheses.kt new file mode 100644 index 00000000000..a2fa186a749 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/TypeParametersAndParentheses.kt @@ -0,0 +1,7 @@ +object Foo() + +object Foo(x: Int) {} + +object Foo() : Bar { + +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/TypeParametersAndParentheses.txt b/compiler/testData/psi/recovery/objects/declarations/TypeParametersAndParentheses.txt new file mode 100644 index 00000000000..95c60476c3f --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/TypeParametersAndParentheses.txt @@ -0,0 +1,88 @@ +JetFile: TypeParametersAndParentheses.kt + PACKAGE_DIRECTIVE + + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/TypeParameterss.kt b/compiler/testData/psi/recovery/objects/declarations/TypeParameterss.kt new file mode 100644 index 00000000000..7ed3af0ad71 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/TypeParameterss.kt @@ -0,0 +1,7 @@ +object Foo + +object Foo {} + +object Foo : Bar { + +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/TypeParameterss.txt b/compiler/testData/psi/recovery/objects/declarations/TypeParameterss.txt new file mode 100644 index 00000000000..0163728c011 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/TypeParameterss.txt @@ -0,0 +1,68 @@ +JetFile: TypeParameterss.kt + PACKAGE_DIRECTIVE + + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/Where.kt b/compiler/testData/psi/recovery/objects/declarations/Where.kt new file mode 100644 index 00000000000..bc3f0400cc2 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/Where.kt @@ -0,0 +1,7 @@ +object Foo where T : G +object Foo : Bar where T : G + +object Foo() where T : G +object Foo() : Bar where T : G + +object Foo() : Bar where T : G {} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/declarations/Where.txt b/compiler/testData/psi/recovery/objects/declarations/Where.txt new file mode 100644 index 00000000000..3dca30b43c9 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/declarations/Where.txt @@ -0,0 +1,155 @@ +JetFile: Where.kt + PACKAGE_DIRECTIVE + + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace('\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace('\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace('\n\n') + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Foo') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiers.kt b/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiers.kt new file mode 100644 index 00000000000..4efe42fdf72 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiers.kt @@ -0,0 +1,9 @@ +val foo = object private () {} + +val foo = object private () : Bar { + +} + +val foo = object [foo] private [bar()] () {} + +val foo = object private () diff --git a/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiers.txt b/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiers.txt new file mode 100644 index 00000000000..8dc0264bb21 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiers.txt @@ -0,0 +1,126 @@ +JetFile: ConstructorModifiers.kt + PACKAGE_DIRECTIVE + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + CLASS_BODY + PsiErrorElement:Expecting a class body + \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiersAndName.kt b/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiersAndName.kt new file mode 100644 index 00000000000..7242c49ddbf --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiersAndName.kt @@ -0,0 +1,10 @@ + +val foo = object Name private () {} + +val foo = object Name private () : Bar { + +} + +val foo = object Name [foo] private [bar()] () {} + +val foo = object Name private () diff --git a/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiersAndName.txt b/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiersAndName.txt new file mode 100644 index 00000000000..1710d98a846 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/ConstructorModifiersAndName.txt @@ -0,0 +1,138 @@ +JetFile: ConstructorModifiersAndName.kt + PACKAGE_DIRECTIVE + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('Name') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('Name') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('Name') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('Name') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + CLASS_BODY + PsiErrorElement:Expecting a class body + \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/EmptyParentheses.kt b/compiler/testData/psi/recovery/objects/expressions/EmptyParentheses.kt new file mode 100644 index 00000000000..da4b94be220 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/EmptyParentheses.kt @@ -0,0 +1,7 @@ +val foo = object() {} + +val foo = object() : Bar { + +} + +val foo = object() diff --git a/compiler/testData/psi/recovery/objects/expressions/EmptyParentheses.txt b/compiler/testData/psi/recovery/objects/expressions/EmptyParentheses.txt new file mode 100644 index 00000000000..d3c5d500b32 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/EmptyParentheses.txt @@ -0,0 +1,68 @@ +JetFile: EmptyParentheses.kt + PACKAGE_DIRECTIVE + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + CLASS_BODY + PsiErrorElement:Expecting a class body + \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/Everything.kt b/compiler/testData/psi/recovery/objects/expressions/Everything.kt new file mode 100644 index 00000000000..e2098efe353 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/Everything.kt @@ -0,0 +1,3 @@ +val foo = object private (x: Int, y: Int) : Bar, Baz { + fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/Everything.txt b/compiler/testData/psi/recovery/objects/expressions/Everything.txt new file mode 100644 index 00000000000..f660ca8768b --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/Everything.txt @@ -0,0 +1,82 @@ +JetFile: Everything.kt + PACKAGE_DIRECTIVE + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('y') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Baz') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/InFunction.kt b/compiler/testData/psi/recovery/objects/expressions/InFunction.kt new file mode 100644 index 00000000000..4c725072fcd --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/InFunction.kt @@ -0,0 +1,9 @@ +fun foo() { + val foo = object private () + + val foo = object private () : Bar + + val foo = object [foo] private [bar()] () + + val foo = object private () +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/InFunction.txt b/compiler/testData/psi/recovery/objects/expressions/InFunction.txt new file mode 100644 index 00000000000..ad92fff1037 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/InFunction.txt @@ -0,0 +1,135 @@ +JetFile: InFunction.kt + PACKAGE_DIRECTIVE + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + CLASS_BODY + PsiErrorElement:Expecting a class body + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace('\n\n ') + CLASS_BODY + PsiErrorElement:Expecting a class body + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + PRIMARY_CONSTRUCTOR_MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + CLASS_BODY + PsiErrorElement:Expecting a class body + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + CLASS_BODY + PsiErrorElement:Expecting a class body + + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/ParametersInParentheses.kt b/compiler/testData/psi/recovery/objects/expressions/ParametersInParentheses.kt new file mode 100644 index 00000000000..df6fd7492ce --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/ParametersInParentheses.kt @@ -0,0 +1,7 @@ +val foo = object(a: Int, b: String) {} + +val foo = object(a: Int, b: String) : Bar { + +} + +val foo = object(a: Int, b: String) diff --git a/compiler/testData/psi/recovery/objects/expressions/ParametersInParentheses.txt b/compiler/testData/psi/recovery/objects/expressions/ParametersInParentheses.txt new file mode 100644 index 00000000000..8172bf32b7f --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/ParametersInParentheses.txt @@ -0,0 +1,122 @@ +JetFile: ParametersInParentheses.kt + PACKAGE_DIRECTIVE + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('String') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('String') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('String') + PsiElement(RPAR)(')') + CLASS_BODY + PsiErrorElement:Expecting a class body + \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/TypeParametersAndParentheses.kt b/compiler/testData/psi/recovery/objects/expressions/TypeParametersAndParentheses.kt new file mode 100644 index 00000000000..3157c6a1a24 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/TypeParametersAndParentheses.kt @@ -0,0 +1,7 @@ +val foo = object(x: Int) {} + +val foo = object() : Bar { + +} + +val foo = object() diff --git a/compiler/testData/psi/recovery/objects/expressions/TypeParametersAndParentheses.txt b/compiler/testData/psi/recovery/objects/expressions/TypeParametersAndParentheses.txt new file mode 100644 index 00000000000..5cb977443d8 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/TypeParametersAndParentheses.txt @@ -0,0 +1,106 @@ +JetFile: TypeParametersAndParentheses.kt + PACKAGE_DIRECTIVE + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + CLASS_BODY + PsiErrorElement:Expecting a class body + \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/TypeParameterss.kt b/compiler/testData/psi/recovery/objects/expressions/TypeParameterss.kt new file mode 100644 index 00000000000..0137680999f --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/TypeParameterss.kt @@ -0,0 +1,7 @@ +val foo = object {} + +val foo = object : Bar { + +} + +val foo = object(a: Int, b: String) diff --git a/compiler/testData/psi/recovery/objects/expressions/TypeParameterss.txt b/compiler/testData/psi/recovery/objects/expressions/TypeParameterss.txt new file mode 100644 index 00000000000..62c4bf4f123 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/TypeParameterss.txt @@ -0,0 +1,98 @@ +JetFile: TypeParameterss.kt + PACKAGE_DIRECTIVE + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Type parameters are not allowed for objects + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('String') + PsiElement(RPAR)(')') + CLASS_BODY + PsiErrorElement:Expecting a class body + \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/Where.kt b/compiler/testData/psi/recovery/objects/expressions/Where.kt new file mode 100644 index 00000000000..b23265245e3 --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/Where.kt @@ -0,0 +1,7 @@ +val foo = object Name where T : G {} +val foo = object : Bar where T : G {} + +val foo = object() where T : G {} +val foo = object() : Bar where T : G {} + +val foo = object() : Bar where T : G {} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/objects/expressions/Where.txt b/compiler/testData/psi/recovery/objects/expressions/Where.txt new file mode 100644 index 00000000000..9aba56f525d --- /dev/null +++ b/compiler/testData/psi/recovery/objects/expressions/Where.txt @@ -0,0 +1,199 @@ +JetFile: Where.kt + PACKAGE_DIRECTIVE + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiErrorElement:An object expression cannot bind a name + PsiElement(IDENTIFIER)('Name') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiErrorElement:Constructors are not allowed for objects + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiWhiteSpace(' ') + PsiErrorElement:Where clause is not allowed for objects + PsiErrorElement:Type constraints are not allowed when no type parameters declared + PsiElement(where)('where') + PsiWhiteSpace(' ') + TYPE_CONSTRAINT_LIST + TYPE_CONSTRAINT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('G') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java index a9b58559223..25076326fd4 100644 --- a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java @@ -1176,6 +1176,7 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { @TestMetadata("compiler/testData/psi/recovery") @TestDataPath("$PROJECT_ROOT") + @InnerTestClasses({Recovery.Objects.class}) @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) public static class Recovery extends AbstractJetParsingTest { @TestMetadata("AbsentLeftHandSide.kt") @@ -1368,6 +1369,139 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { doParsingTest(fileName); } + @TestMetadata("compiler/testData/psi/recovery/objects") + @TestDataPath("$PROJECT_ROOT") + @InnerTestClasses({Objects.Declarations.class, Objects.Expressions.class}) + @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) + public static class Objects extends AbstractJetParsingTest { + public void testAllFilesPresentInObjects() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/psi/recovery/objects"), Pattern.compile("^(.*)\\.kts?$"), true); + } + + @TestMetadata("compiler/testData/psi/recovery/objects/declarations") + @TestDataPath("$PROJECT_ROOT") + @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) + public static class Declarations extends AbstractJetParsingTest { + public void testAllFilesPresentInDeclarations() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/psi/recovery/objects/declarations"), Pattern.compile("^(.*)\\.kts?$"), true); + } + + @TestMetadata("ConstructorModifiers.kt") + public void testConstructorModifiers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/declarations/ConstructorModifiers.kt"); + doParsingTest(fileName); + } + + @TestMetadata("EmptyParentheses.kt") + public void testEmptyParentheses() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/declarations/EmptyParentheses.kt"); + doParsingTest(fileName); + } + + @TestMetadata("Everything.kt") + public void testEverything() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/declarations/Everything.kt"); + doParsingTest(fileName); + } + + @TestMetadata("FollowedByModifiers.kt") + public void testFollowedByModifiers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/declarations/FollowedByModifiers.kt"); + doParsingTest(fileName); + } + + @TestMetadata("ParametersInParentheses.kt") + public void testParametersInParentheses() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/declarations/ParametersInParentheses.kt"); + doParsingTest(fileName); + } + + @TestMetadata("TypeParametersAndParentheses.kt") + public void testTypeParametersAndParentheses() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/declarations/TypeParametersAndParentheses.kt"); + doParsingTest(fileName); + } + + @TestMetadata("TypeParameterss.kt") + public void testTypeParameterss() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/declarations/TypeParameterss.kt"); + doParsingTest(fileName); + } + + @TestMetadata("Where.kt") + public void testWhere() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/declarations/Where.kt"); + doParsingTest(fileName); + } + + } + + @TestMetadata("compiler/testData/psi/recovery/objects/expressions") + @TestDataPath("$PROJECT_ROOT") + @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) + public static class Expressions extends AbstractJetParsingTest { + public void testAllFilesPresentInExpressions() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/psi/recovery/objects/expressions"), Pattern.compile("^(.*)\\.kts?$"), true); + } + + @TestMetadata("ConstructorModifiers.kt") + public void testConstructorModifiers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/expressions/ConstructorModifiers.kt"); + doParsingTest(fileName); + } + + @TestMetadata("ConstructorModifiersAndName.kt") + public void testConstructorModifiersAndName() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/expressions/ConstructorModifiersAndName.kt"); + doParsingTest(fileName); + } + + @TestMetadata("EmptyParentheses.kt") + public void testEmptyParentheses() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/expressions/EmptyParentheses.kt"); + doParsingTest(fileName); + } + + @TestMetadata("Everything.kt") + public void testEverything() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/expressions/Everything.kt"); + doParsingTest(fileName); + } + + @TestMetadata("InFunction.kt") + public void testInFunction() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/expressions/InFunction.kt"); + doParsingTest(fileName); + } + + @TestMetadata("ParametersInParentheses.kt") + public void testParametersInParentheses() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/expressions/ParametersInParentheses.kt"); + doParsingTest(fileName); + } + + @TestMetadata("TypeParametersAndParentheses.kt") + public void testTypeParametersAndParentheses() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/expressions/TypeParametersAndParentheses.kt"); + doParsingTest(fileName); + } + + @TestMetadata("TypeParameterss.kt") + public void testTypeParameterss() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/expressions/TypeParameterss.kt"); + doParsingTest(fileName); + } + + @TestMetadata("Where.kt") + public void testWhere() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/objects/expressions/Where.kt"); + doParsingTest(fileName); + } + + } + + } + } @TestMetadata("compiler/testData/psi/script") diff --git a/idea/testData/checker/regression/BadParseForClass.kt b/idea/testData/checker/regression/BadParseForClass.kt index 297cf905bcb..70620be3825 100644 --- a/idea/testData/checker/regression/BadParseForClass.kt +++ b/idea/testData/checker/regression/BadParseForClass.kt @@ -1,5 +1,5 @@ fun main(args: Array) { String.class -} +} // EA-56152: An attempt to build light class in checker to get diagnotics \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/findClassUsages/kotlinTraitDerivedAnonymousObjects.1.kt b/idea/testData/findUsages/kotlin/findClassUsages/kotlinTraitDerivedAnonymousObjects.1.kt index 31a4c108e6e..9af18a585f6 100644 --- a/idea/testData/findUsages/kotlin/findClassUsages/kotlinTraitDerivedAnonymousObjects.1.kt +++ b/idea/testData/findUsages/kotlin/findClassUsages/kotlinTraitDerivedAnonymousObjects.1.kt @@ -9,7 +9,7 @@ fun foo() { doSomething(object : A() {}, object: X {}) fun bar() { - val x = object O2: X { + val x = object : X { } } diff --git a/idea/testData/findUsages/kotlin/findClassUsages/kotlinTraitDerivedAnonymousObjects.results.txt b/idea/testData/findUsages/kotlin/findClassUsages/kotlinTraitDerivedAnonymousObjects.results.txt index 29cbc819c68..e4ece4bd5cd 100644 --- a/idea/testData/findUsages/kotlin/findClassUsages/kotlinTraitDerivedAnonymousObjects.results.txt +++ b/idea/testData/findUsages/kotlin/findClassUsages/kotlinTraitDerivedAnonymousObjects.results.txt @@ -1,3 +1,4 @@ +Unclassified usage (12: 17) val x = object : X { Unclassified usage (7: 12) open class A: X { Unclassified usage (9: 17) doSomething(object : A() {}, object: X {}) Unclassified usage (9: 34) doSomething(object : A() {}, object: X {})