From 29984efe765b278faec1bab4fca5d2263525a229 Mon Sep 17 00:00:00 2001 From: "Natalia.Ukhorskaya" Date: Fri, 26 Apr 2013 10:36:54 +0400 Subject: [PATCH] Parse delegated property --- .../src/org/jetbrains/jet/JetNodeTypes.java | 1 + .../jet/lang/parsing/JetParsing.java | 32 +++++-- .../jetbrains/jet/lang/psi/JetProperty.java | 24 ++++++ .../jet/lang/psi/JetPropertyDelegate.java | 42 ++++++++++ .../jetbrains/jet/lang/psi/JetVisitor.java | 4 + .../jet/lang/psi/JetVisitorVoid.java | 4 + .../propertyDelegate/BracketsInDelegate.kt | 1 + .../propertyDelegate/BracketsInDelegate.txt | 21 +++++ .../DelegateAndInitializer.kt | 3 + .../DelegateAndInitializer.txt | 84 +++++++++++++++++++ .../psi/propertyDelegate/GetterInSameLine.kt | 1 + .../psi/propertyDelegate/GetterInSameLine.txt | 29 +++++++ .../psi/propertyDelegate/LocalProperty.kt | 5 ++ .../psi/propertyDelegate/LocalProperty.txt | 48 +++++++++++ .../testData/psi/propertyDelegate/OnlyBy.kt | 3 + .../testData/psi/propertyDelegate/OnlyBy.txt | 22 +++++ .../psi/propertyDelegate/PropertyInClass.kt | 3 + .../psi/propertyDelegate/PropertyInClass.txt | 35 ++++++++ .../propertyDelegate/PropertyWithGetter.kt | 2 + .../propertyDelegate/PropertyWithGetter.txt | 33 ++++++++ .../PropertyWithInitializer.kt | 1 + .../PropertyWithInitializer.txt | 30 +++++++ .../PropertyWithoutTypeRef.kt | 1 + .../PropertyWithoutTypeRef.txt | 17 ++++ .../psi/propertyDelegate/TopLevelProperty.kt | 1 + .../psi/propertyDelegate/TopLevelProperty.txt | 23 +++++ .../psi/propertyDelegate/TwoProperties.kt | 1 + .../psi/propertyDelegate/TwoProperties.txt | 34 ++++++++ .../jetbrains/jet/parsing/JetParsingTest.java | 1 + grammar/src/class_members.grm | 2 +- 30 files changed, 501 insertions(+), 7 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPropertyDelegate.java create mode 100644 compiler/testData/psi/propertyDelegate/BracketsInDelegate.kt create mode 100644 compiler/testData/psi/propertyDelegate/BracketsInDelegate.txt create mode 100644 compiler/testData/psi/propertyDelegate/DelegateAndInitializer.kt create mode 100644 compiler/testData/psi/propertyDelegate/DelegateAndInitializer.txt create mode 100644 compiler/testData/psi/propertyDelegate/GetterInSameLine.kt create mode 100644 compiler/testData/psi/propertyDelegate/GetterInSameLine.txt create mode 100644 compiler/testData/psi/propertyDelegate/LocalProperty.kt create mode 100644 compiler/testData/psi/propertyDelegate/LocalProperty.txt create mode 100644 compiler/testData/psi/propertyDelegate/OnlyBy.kt create mode 100644 compiler/testData/psi/propertyDelegate/OnlyBy.txt create mode 100644 compiler/testData/psi/propertyDelegate/PropertyInClass.kt create mode 100644 compiler/testData/psi/propertyDelegate/PropertyInClass.txt create mode 100644 compiler/testData/psi/propertyDelegate/PropertyWithGetter.kt create mode 100644 compiler/testData/psi/propertyDelegate/PropertyWithGetter.txt create mode 100644 compiler/testData/psi/propertyDelegate/PropertyWithInitializer.kt create mode 100644 compiler/testData/psi/propertyDelegate/PropertyWithInitializer.txt create mode 100644 compiler/testData/psi/propertyDelegate/PropertyWithoutTypeRef.kt create mode 100644 compiler/testData/psi/propertyDelegate/PropertyWithoutTypeRef.txt create mode 100644 compiler/testData/psi/propertyDelegate/TopLevelProperty.kt create mode 100644 compiler/testData/psi/propertyDelegate/TopLevelProperty.txt create mode 100644 compiler/testData/psi/propertyDelegate/TwoProperties.kt create mode 100644 compiler/testData/psi/propertyDelegate/TwoProperties.txt diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index aabba80665c..e38fe393858 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -45,6 +45,7 @@ public interface JetNodeTypes { JetNodeType DELEGATOR_BY = new JetNodeType("DELEGATOR_BY", JetDelegatorByExpressionSpecifier.class); JetNodeType DELEGATOR_SUPER_CALL = new JetNodeType("DELEGATOR_SUPER_CALL", JetDelegatorToSuperCall.class); JetNodeType DELEGATOR_SUPER_CLASS = new JetNodeType("DELEGATOR_SUPER_CLASS", JetDelegatorToSuperClass.class); + JetNodeType PROPERTY_DELEGATE = new JetNodeType("PROPERTY_DELEGATE", JetPropertyDelegate.class); JetNodeType CONSTRUCTOR_CALLEE = new JetNodeType("CONSTRUCTOR_CALLEE", JetConstructorCalleeExpression.class); IElementType VALUE_PARAMETER_LIST = JetStubElementTypes.VALUE_PARAMETER_LIST; IElementType VALUE_PARAMETER = JetStubElementTypes.VALUE_PARAMETER; 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 d73aea15f5c..dd519065f11 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -819,7 +819,7 @@ public class JetParsing extends AbstractJetParsing { * typeParameters? (type "." | annotations)? * ("(" variableDeclarationEntry{","} ")" | variableDeclarationEntry) * typeConstraints - * ("=" element SEMI?)? + * ("by" | "=" expression SEMI?)? * (getter? setter? | setter? getter?) SEMI? * ; */ @@ -887,14 +887,21 @@ public class JetParsing extends AbstractJetParsing { parseTypeConstraintsGuarded(typeParametersDeclared); if (local) { - if (at(EQ)) { + if (at(BY_KEYWORD)) { + parsePropertyDelegate(); + } + else if (at(EQ)) { advance(); // EQ myExpressionParsing.parseExpression(); // "val a = 1; b" must not be an infix call of b on "val ...;" } } else { - if (at(EQ)) { + if (at(BY_KEYWORD)) { + parsePropertyDelegate(); + consumeIf(SEMICOLON); + } + else if (at(EQ)) { advance(); // EQ myExpressionParsing.parseExpression(); consumeIf(SEMICOLON); @@ -903,7 +910,7 @@ public class JetParsing extends AbstractJetParsing { if (parsePropertyGetterOrSetter()) { parsePropertyGetterOrSetter(); } - if (!atSet(EOL_OR_SEMICOLON, RBRACE)) { + if (!atSet(EOL_OR_SEMICOLON, RBRACE)) { if (getLastToken() != SEMICOLON) { errorUntil("Property getter or setter expected", TokenSet.create(EOL_OR_SEMICOLON)); } @@ -916,6 +923,19 @@ public class JetParsing extends AbstractJetParsing { return multiDeclaration ? MULTI_VARIABLE_DECLARATION : PROPERTY; } + /* + * propertyDelegate + * : "by" expression + * ; + */ + private void parsePropertyDelegate() { + assert _at(BY_KEYWORD); + PsiBuilder.Marker delegate = mark(); + advance(); // BY_KEYWORD + myExpressionParsing.parseExpression(); + delegate.done(PROPERTY_DELEGATE); + } + /* * (SimpleName (":" type)){","} */ @@ -1456,7 +1476,7 @@ public class JetParsing extends AbstractJetParsing { receiverType.done(FUNCTION_TYPE_RECEIVER); advance(); // DOT - + if (at(LPAR)) { parseFunctionTypeContents().drop(); } @@ -1707,7 +1727,7 @@ public class JetParsing extends AbstractJetParsing { } } } - + expect(RPAR, "Expecting ')'", recoverySet); myBuilder.restoreNewlinesState(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java index d1b478db74d..836897bc6f7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java @@ -36,6 +36,7 @@ import org.jetbrains.jet.lexer.JetTokens; import java.util.List; import static org.jetbrains.jet.JetNodeTypes.PROPERTY_ACCESSOR; +import static org.jetbrains.jet.JetNodeTypes.PROPERTY_DELEGATE; import static org.jetbrains.jet.lexer.JetTokens.*; public class JetProperty extends JetTypeParameterListOwnerStub implements JetVariableDeclaration { @@ -155,12 +156,35 @@ public class JetProperty extends JetTypeParameterListOwnerStub R accept(@NotNull JetVisitor visitor, D data) { + return visitor.visitPropertyDelegate(this, data); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java index 0780f0b985e..082ad68d492 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java @@ -129,6 +129,10 @@ public class JetVisitor extends PsiElementVisitor { return visitDelegationSpecifier(thisCall, data); } + public R visitPropertyDelegate(JetPropertyDelegate delegate, D data) { + return visitJetElement(delegate, data); + } + public R visitTypeReference(JetTypeReference typeReference, D data) { return visitJetElement(typeReference, data); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java index d25489bbb14..1e33c5279dc 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java @@ -119,6 +119,10 @@ public class JetVisitorVoid extends PsiElementVisitor { visitDelegationSpecifier(thisCall); } + public void visitPropertyDelegate(JetPropertyDelegate delegate) { + visitJetElement(delegate); + } + public void visitTypeReference(JetTypeReference typeReference) { visitJetElement(typeReference); } diff --git a/compiler/testData/psi/propertyDelegate/BracketsInDelegate.kt b/compiler/testData/psi/propertyDelegate/BracketsInDelegate.kt new file mode 100644 index 00000000000..7e3a3b7078a --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/BracketsInDelegate.kt @@ -0,0 +1 @@ +val a by A {} \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/BracketsInDelegate.txt b/compiler/testData/psi/propertyDelegate/BracketsInDelegate.txt new file mode 100644 index 00000000000..b4ea70eb1ed --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/BracketsInDelegate.txt @@ -0,0 +1,21 @@ +JetFile: BracketsInDelegate.kt + NAMESPACE_HEADER + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + PsiWhiteSpace(' ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/DelegateAndInitializer.kt b/compiler/testData/psi/propertyDelegate/DelegateAndInitializer.kt new file mode 100644 index 00000000000..753fbe5dbed --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/DelegateAndInitializer.kt @@ -0,0 +1,3 @@ +val a: Int = 1 by A() +val b: Int = 1 by A() +val c: Int by A(); = 3 diff --git a/compiler/testData/psi/propertyDelegate/DelegateAndInitializer.txt b/compiler/testData/psi/propertyDelegate/DelegateAndInitializer.txt new file mode 100644 index 00000000000..ec3e3ba8d75 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/DelegateAndInitializer.txt @@ -0,0 +1,84 @@ +JetFile: DelegateAndInitializer.kt + NAMESPACE_HEADER + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(IDENTIFIER)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(IDENTIFIER)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('c') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting package directive or top level declaration + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting package directive or top level declaration + PsiElement(INTEGER_LITERAL)('3') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/GetterInSameLine.kt b/compiler/testData/psi/propertyDelegate/GetterInSameLine.kt new file mode 100644 index 00000000000..470264649a4 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/GetterInSameLine.kt @@ -0,0 +1 @@ +val a by A(); get() = 1; \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/GetterInSameLine.txt b/compiler/testData/psi/propertyDelegate/GetterInSameLine.txt new file mode 100644 index 00000000000..47ce24b56ef --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/GetterInSameLine.txt @@ -0,0 +1,29 @@ +JetFile: GetterInSameLine.kt + NAMESPACE_HEADER + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace(' ') + PROPERTY_ACCESSOR + PsiElement(get)('get') + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(SEMICOLON)(';') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/LocalProperty.kt b/compiler/testData/psi/propertyDelegate/LocalProperty.kt new file mode 100644 index 00000000000..d549eae7d85 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/LocalProperty.kt @@ -0,0 +1,5 @@ +class B { + fun foo() { + val p: Int by A() + } +} \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/LocalProperty.txt b/compiler/testData/psi/propertyDelegate/LocalProperty.txt new file mode 100644 index 00000000000..556512e6d08 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/LocalProperty.txt @@ -0,0 +1,48 @@ +JetFile: LocalProperty.kt + NAMESPACE_HEADER + + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('B') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + + 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)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('p') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/OnlyBy.kt b/compiler/testData/psi/propertyDelegate/OnlyBy.kt new file mode 100644 index 00000000000..fe718160aa7 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/OnlyBy.kt @@ -0,0 +1,3 @@ +val a by + +val b = 1 \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/OnlyBy.txt b/compiler/testData/psi/propertyDelegate/OnlyBy.txt new file mode 100644 index 00000000000..ec51ff8ce06 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/OnlyBy.txt @@ -0,0 +1,22 @@ +JetFile: OnlyBy.kt + NAMESPACE_HEADER + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiErrorElement:Expecting an expression + + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('b') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/PropertyInClass.kt b/compiler/testData/psi/propertyDelegate/PropertyInClass.kt new file mode 100644 index 00000000000..db6cdb61fb5 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/PropertyInClass.kt @@ -0,0 +1,3 @@ +class B { + val p: Int by A() +} \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/PropertyInClass.txt b/compiler/testData/psi/propertyDelegate/PropertyInClass.txt new file mode 100644 index 00000000000..322b7cb98a9 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/PropertyInClass.txt @@ -0,0 +1,35 @@ +JetFile: PropertyInClass.kt + NAMESPACE_HEADER + + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('B') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('p') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/PropertyWithGetter.kt b/compiler/testData/psi/propertyDelegate/PropertyWithGetter.kt new file mode 100644 index 00000000000..7a6902ef702 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/PropertyWithGetter.kt @@ -0,0 +1,2 @@ +val p: Int by A() + get() = 1 \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/PropertyWithGetter.txt b/compiler/testData/psi/propertyDelegate/PropertyWithGetter.txt new file mode 100644 index 00000000000..3388462b625 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/PropertyWithGetter.txt @@ -0,0 +1,33 @@ +JetFile: PropertyWithGetter.kt + NAMESPACE_HEADER + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('p') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + PsiElement(get)('get') + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/PropertyWithInitializer.kt b/compiler/testData/psi/propertyDelegate/PropertyWithInitializer.kt new file mode 100644 index 00000000000..9a82d77bc3c --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/PropertyWithInitializer.kt @@ -0,0 +1 @@ +val p: Int by A() = 1 \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/PropertyWithInitializer.txt b/compiler/testData/psi/propertyDelegate/PropertyWithInitializer.txt new file mode 100644 index 00000000000..616548a94d5 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/PropertyWithInitializer.txt @@ -0,0 +1,30 @@ +JetFile: PropertyWithInitializer.kt + NAMESPACE_HEADER + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('p') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/PropertyWithoutTypeRef.kt b/compiler/testData/psi/propertyDelegate/PropertyWithoutTypeRef.kt new file mode 100644 index 00000000000..03da513a8ce --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/PropertyWithoutTypeRef.kt @@ -0,0 +1 @@ +val p by A() \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/PropertyWithoutTypeRef.txt b/compiler/testData/psi/propertyDelegate/PropertyWithoutTypeRef.txt new file mode 100644 index 00000000000..141ebad4ba8 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/PropertyWithoutTypeRef.txt @@ -0,0 +1,17 @@ +JetFile: PropertyWithoutTypeRef.kt + NAMESPACE_HEADER + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('p') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/TopLevelProperty.kt b/compiler/testData/psi/propertyDelegate/TopLevelProperty.kt new file mode 100644 index 00000000000..6fd11d86cc0 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/TopLevelProperty.kt @@ -0,0 +1 @@ +val p: Int by A() \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/TopLevelProperty.txt b/compiler/testData/psi/propertyDelegate/TopLevelProperty.txt new file mode 100644 index 00000000000..95c4d8230a7 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/TopLevelProperty.txt @@ -0,0 +1,23 @@ +JetFile: TopLevelProperty.kt + NAMESPACE_HEADER + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('p') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') \ No newline at end of file diff --git a/compiler/testData/psi/propertyDelegate/TwoProperties.kt b/compiler/testData/psi/propertyDelegate/TwoProperties.kt new file mode 100644 index 00000000000..95a3745c4a1 --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/TwoProperties.kt @@ -0,0 +1 @@ +val a by A(); val b by A(); diff --git a/compiler/testData/psi/propertyDelegate/TwoProperties.txt b/compiler/testData/psi/propertyDelegate/TwoProperties.txt new file mode 100644 index 00000000000..441977f1d4f --- /dev/null +++ b/compiler/testData/psi/propertyDelegate/TwoProperties.txt @@ -0,0 +1,34 @@ +JetFile: TwoProperties.kt + NAMESPACE_HEADER + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace(' ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('b') + PsiWhiteSpace(' ') + PROPERTY_DELEGATE + PsiElement(by)('by') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(SEMICOLON)(';') \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTest.java b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTest.java index 9bd17578ad8..5ab65c1a2e3 100644 --- a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTest.java +++ b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTest.java @@ -138,6 +138,7 @@ public class JetParsingTest extends ParsingTestCase { suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "greatSyntacticShift", true, factory)); suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "script", true, factory)); suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "recovery", true, factory)); + suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "propertyDelegate", true, factory)); return suite; } diff --git a/grammar/src/class_members.grm b/grammar/src/class_members.grm index 4f24e5fcce7..a894dae155f 100644 --- a/grammar/src/class_members.grm +++ b/grammar/src/class_members.grm @@ -93,7 +93,7 @@ property typeParameters? (type "." | annotations)? (multipleVariableDeclarations | variableDeclarationEntry) typeConstraints - ("=" expression SEMI?)? + ("by" | "=" expression SEMI?)? (getter? setter? | setter? getter?) SEMI? ;