From 52cd7109c7fb2b691a4cbab530b3dc6118f8ceab Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 11 May 2016 19:41:02 +0300 Subject: [PATCH] Use left bound element types to tight empty delegation contructor call to declaration CONSTRUCTOR_DELEGATION_CALL and CONSTRUCTOR_DELEGATION_REFERENCE types were modified. --- .../src/org/jetbrains/kotlin/KtNodeType.java | 17 ++++++++++++----- .../src/org/jetbrains/kotlin/KtNodeTypes.java | 5 ++--- .../psi/annotation/at/validDeclarations.txt | 2 +- compiler/testData/psi/examples/BinaryTree.txt | 2 +- .../primaryConstructor/nestedClassAmbiguity.txt | 2 +- .../firstInSecondaryConstructor.txt | 4 ++-- .../secondInSecondaryConstructor.txt | 2 +- .../psi/secondaryConstructors/basic.txt | 4 ++-- .../psi/secondaryConstructors/emptyBody.txt | 4 ++-- .../psi/secondaryConstructors/enumParsing.txt | 2 +- .../recoveryJustConstructorKeyword.txt | 12 ++++++------ ...overyJustConstructorKeywordSameLineBrace.txt | 8 ++++---- .../recoveryNoDelegationCallAfterColon.txt | 10 +++++----- .../recoveryWithoutBodyWrongDelegationName.txt | 8 ++++---- 14 files changed, 44 insertions(+), 38 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/KtNodeType.java b/compiler/frontend/src/org/jetbrains/kotlin/KtNodeType.java index 453c0d9a54e..9593cf094e4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/KtNodeType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/KtNodeType.java @@ -27,11 +27,7 @@ import org.jetbrains.kotlin.psi.KtElementImpl; import java.lang.reflect.Constructor; public class KtNodeType extends IElementType { - private Constructor myPsiFactory; - - public KtNodeType(@NotNull @NonNls String debugName) { - this(debugName, null); - } + private final Constructor myPsiFactory; public KtNodeType(@NotNull @NonNls String debugName, Class psiClass) { super(debugName, KotlinLanguage.INSTANCE); @@ -54,4 +50,15 @@ public class KtNodeType extends IElementType { throw new RuntimeException("Error creating psi element for node", e); } } + + public static class KtLeftBoundNodeType extends KtNodeType { + public KtLeftBoundNodeType(@NotNull @NonNls String debugName, Class psiClass) { + super(debugName, psiClass); + } + + @Override + public boolean isLeftBound() { + return true; + } + } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/KtNodeTypes.java b/compiler/frontend/src/org/jetbrains/kotlin/KtNodeTypes.java index 27357d4d437..8a62711034a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/KtNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/KtNodeTypes.java @@ -81,9 +81,8 @@ public interface KtNodeTypes { IElementType TYPE_CONSTRAINT_LIST = KtStubElementTypes.TYPE_CONSTRAINT_LIST; IElementType TYPE_CONSTRAINT = KtStubElementTypes.TYPE_CONSTRAINT; - IElementType CONSTRUCTOR_DELEGATION_CALL = new KtNodeType("CONSTRUCTOR_DELEGATION_CALL", KtConstructorDelegationCall.class); - KtNodeType CONSTRUCTOR_DELEGATION_REFERENCE = - new KtNodeType("CONSTRUCTOR_DELEGATION_REFERENCE", KtConstructorDelegationReferenceExpression.class); + IElementType CONSTRUCTOR_DELEGATION_CALL = new KtNodeType.KtLeftBoundNodeType("CONSTRUCTOR_DELEGATION_CALL", KtConstructorDelegationCall.class); + KtNodeType CONSTRUCTOR_DELEGATION_REFERENCE = new KtNodeType.KtLeftBoundNodeType("CONSTRUCTOR_DELEGATION_REFERENCE", KtConstructorDelegationReferenceExpression.class); // TODO: Not sure if we need separate NT for each kind of constants KtNodeType NULL = new KtNodeType("NULL", KtConstantExpression.class); diff --git a/compiler/testData/psi/annotation/at/validDeclarations.txt b/compiler/testData/psi/annotation/at/validDeclarations.txt index 69f8c317d18..e66d9428c04 100644 --- a/compiler/testData/psi/annotation/at/validDeclarations.txt +++ b/compiler/testData/psi/annotation/at/validDeclarations.txt @@ -512,10 +512,10 @@ JetFile: validDeclarations.kt VALUE_PARAMETER_LIST PsiElement(LPAR)('(') PsiElement(RPAR)(')') - PsiWhiteSpace('\n\n ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n\n ') FUN PsiElement(fun)('fun') PsiWhiteSpace(' ') diff --git a/compiler/testData/psi/examples/BinaryTree.txt b/compiler/testData/psi/examples/BinaryTree.txt index aa17bff61b5..5eb11d13747 100644 --- a/compiler/testData/psi/examples/BinaryTree.txt +++ b/compiler/testData/psi/examples/BinaryTree.txt @@ -175,10 +175,10 @@ JetFile: BinaryTree.kt PsiElement(IDENTIFIER)('T') PsiElement(GT)('>') PsiElement(RPAR)(')') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') diff --git a/compiler/testData/psi/primaryConstructor/nestedClassAmbiguity.txt b/compiler/testData/psi/primaryConstructor/nestedClassAmbiguity.txt index 08914920908..3faeffcaac3 100644 --- a/compiler/testData/psi/primaryConstructor/nestedClassAmbiguity.txt +++ b/compiler/testData/psi/primaryConstructor/nestedClassAmbiguity.txt @@ -65,10 +65,10 @@ JetFile: nestedClassAmbiguity.kt VALUE_PARAMETER_LIST PsiElement(LPAR)('(') PsiElement(RPAR)(')') - PsiWhiteSpace('\n') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n') PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n') CLASS diff --git a/compiler/testData/psi/recovery/unnamedParameter/firstInSecondaryConstructor.txt b/compiler/testData/psi/recovery/unnamedParameter/firstInSecondaryConstructor.txt index 05c517612e5..ec9e5bef11b 100644 --- a/compiler/testData/psi/recovery/unnamedParameter/firstInSecondaryConstructor.txt +++ b/compiler/testData/psi/recovery/unnamedParameter/firstInSecondaryConstructor.txt @@ -25,13 +25,13 @@ JetFile: firstInSecondaryConstructor.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('Int') PsiElement(RPAR)(')') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n\n ') PsiElement(RBRACE)('}') PsiWhiteSpace('\n') - PsiElement(RBRACE)('}') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/unnamedParameter/secondInSecondaryConstructor.txt b/compiler/testData/psi/recovery/unnamedParameter/secondInSecondaryConstructor.txt index a1cfa1c3dd9..2364d4feb76 100644 --- a/compiler/testData/psi/recovery/unnamedParameter/secondInSecondaryConstructor.txt +++ b/compiler/testData/psi/recovery/unnamedParameter/secondInSecondaryConstructor.txt @@ -35,10 +35,10 @@ JetFile: secondInSecondaryConstructor.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('Int') PsiElement(RPAR)(')') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n\n ') diff --git a/compiler/testData/psi/secondaryConstructors/basic.txt b/compiler/testData/psi/secondaryConstructors/basic.txt index 1e3dfe18451..5dedddfc768 100644 --- a/compiler/testData/psi/secondaryConstructors/basic.txt +++ b/compiler/testData/psi/secondaryConstructors/basic.txt @@ -16,10 +16,10 @@ JetFile: basic.kt VALUE_PARAMETER_LIST PsiElement(LPAR)('(') PsiElement(RPAR)(')') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') @@ -59,10 +59,10 @@ JetFile: basic.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('Int') PsiElement(RPAR)(')') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') diff --git a/compiler/testData/psi/secondaryConstructors/emptyBody.txt b/compiler/testData/psi/secondaryConstructors/emptyBody.txt index 91235005040..9b006484f73 100644 --- a/compiler/testData/psi/secondaryConstructors/emptyBody.txt +++ b/compiler/testData/psi/secondaryConstructors/emptyBody.txt @@ -16,10 +16,10 @@ JetFile: emptyBody.kt VALUE_PARAMETER_LIST PsiElement(LPAR)('(') PsiElement(RPAR)(')') - PsiWhiteSpace('\n ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n ') FUN PsiElement(fun)('fun') PsiWhiteSpace(' ') @@ -41,10 +41,10 @@ JetFile: emptyBody.kt VALUE_PARAMETER_LIST PsiElement(LPAR)('(') PsiElement(RPAR)(')') - PsiWhiteSpace('\n ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n ') PROPERTY PsiElement(val)('val') PsiWhiteSpace(' ') diff --git a/compiler/testData/psi/secondaryConstructors/enumParsing.txt b/compiler/testData/psi/secondaryConstructors/enumParsing.txt index 0dfe087e2e5..0bbb6e6b799 100644 --- a/compiler/testData/psi/secondaryConstructors/enumParsing.txt +++ b/compiler/testData/psi/secondaryConstructors/enumParsing.txt @@ -85,10 +85,10 @@ JetFile: enumParsing.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('Int') PsiElement(RPAR)(')') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') diff --git a/compiler/testData/psi/secondaryConstructors/recoveryJustConstructorKeyword.txt b/compiler/testData/psi/secondaryConstructors/recoveryJustConstructorKeyword.txt index ae46ae78126..bc677fe7fca 100644 --- a/compiler/testData/psi/secondaryConstructors/recoveryJustConstructorKeyword.txt +++ b/compiler/testData/psi/secondaryConstructors/recoveryJustConstructorKeyword.txt @@ -15,10 +15,10 @@ JetFile: recoveryJustConstructorKeyword.kt PsiElement(constructor)('constructor') PsiErrorElement:Expecting '(' - PsiWhiteSpace('\n ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n ') PROPERTY PsiElement(val)('val') PsiWhiteSpace(' ') @@ -34,19 +34,19 @@ JetFile: recoveryJustConstructorKeyword.kt PsiElement(constructor)('constructor') PsiErrorElement:Expecting '(' - PsiWhiteSpace('\n ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n ') SECONDARY_CONSTRUCTOR PsiElement(constructor)('constructor') VALUE_PARAMETER_LIST PsiElement(LPAR)('(') PsiElement(RPAR)(')') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') @@ -55,10 +55,10 @@ JetFile: recoveryJustConstructorKeyword.kt PsiElement(constructor)('constructor') PsiErrorElement:Expecting '(' - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') @@ -75,13 +75,13 @@ JetFile: recoveryJustConstructorKeyword.kt PsiElement(constructor)('constructor') PsiErrorElement:Expecting '(' - PsiWhiteSpace('\n') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n') PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n') CLASS PsiElement(class)('class') PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('B') + PsiElement(IDENTIFIER)('B') \ No newline at end of file diff --git a/compiler/testData/psi/secondaryConstructors/recoveryJustConstructorKeywordSameLineBrace.txt b/compiler/testData/psi/secondaryConstructors/recoveryJustConstructorKeywordSameLineBrace.txt index 08ae1b20b33..7a1d6f8520a 100644 --- a/compiler/testData/psi/secondaryConstructors/recoveryJustConstructorKeywordSameLineBrace.txt +++ b/compiler/testData/psi/secondaryConstructors/recoveryJustConstructorKeywordSameLineBrace.txt @@ -15,10 +15,10 @@ JetFile: recoveryJustConstructorKeywordSameLineBrace.kt PsiElement(constructor)('constructor') PsiErrorElement:Expecting '(' - PsiWhiteSpace('\n ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n ') PROPERTY PsiElement(val)('val') PsiWhiteSpace(' ') @@ -34,19 +34,19 @@ JetFile: recoveryJustConstructorKeywordSameLineBrace.kt PsiElement(constructor)('constructor') PsiErrorElement:Expecting '(' - PsiWhiteSpace('\n ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n ') SECONDARY_CONSTRUCTOR PsiElement(constructor)('constructor') VALUE_PARAMETER_LIST PsiElement(LPAR)('(') PsiElement(RPAR)(')') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') @@ -55,10 +55,10 @@ JetFile: recoveryJustConstructorKeywordSameLineBrace.kt PsiElement(constructor)('constructor') PsiErrorElement:Expecting '(' - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') diff --git a/compiler/testData/psi/secondaryConstructors/recoveryNoDelegationCallAfterColon.txt b/compiler/testData/psi/secondaryConstructors/recoveryNoDelegationCallAfterColon.txt index 4f17b14273c..40ed32026ca 100644 --- a/compiler/testData/psi/secondaryConstructors/recoveryNoDelegationCallAfterColon.txt +++ b/compiler/testData/psi/secondaryConstructors/recoveryNoDelegationCallAfterColon.txt @@ -17,10 +17,10 @@ JetFile: recoveryNoDelegationCallAfterColon.kt PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiElement(COLON)(':') - PsiWhiteSpace('\n ') CONSTRUCTOR_DELEGATION_CALL PsiErrorElement:Expecting a 'this' or 'super' constructor call + PsiWhiteSpace('\n ') PROPERTY PsiElement(val)('val') PsiWhiteSpace(' ') @@ -37,29 +37,29 @@ JetFile: recoveryNoDelegationCallAfterColon.kt PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiElement(COLON)(':') - PsiWhiteSpace('\n ') CONSTRUCTOR_DELEGATION_CALL PsiErrorElement:Expecting a 'this' or 'super' constructor call + PsiWhiteSpace('\n ') SECONDARY_CONSTRUCTOR PsiElement(constructor)('constructor') VALUE_PARAMETER_LIST PsiElement(LPAR)('(') PsiElement(RPAR)(')') - PsiWhiteSpace('\n\n ') CONSTRUCTOR_DELEGATION_CALL CONSTRUCTOR_DELEGATION_REFERENCE + PsiWhiteSpace('\n\n ') SECONDARY_CONSTRUCTOR PsiElement(constructor)('constructor') VALUE_PARAMETER_LIST PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiElement(COLON)(':') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL PsiErrorElement:Expecting a 'this' or 'super' constructor call + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') @@ -78,10 +78,10 @@ JetFile: recoveryNoDelegationCallAfterColon.kt PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiElement(COLON)(':') - PsiWhiteSpace('\n') CONSTRUCTOR_DELEGATION_CALL PsiErrorElement:Expecting a 'this' or 'super' constructor call + PsiWhiteSpace('\n') PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n') CLASS diff --git a/compiler/testData/psi/secondaryConstructors/recoveryWithoutBodyWrongDelegationName.txt b/compiler/testData/psi/secondaryConstructors/recoveryWithoutBodyWrongDelegationName.txt index ed7c8da1f38..cbb0554e8c8 100644 --- a/compiler/testData/psi/secondaryConstructors/recoveryWithoutBodyWrongDelegationName.txt +++ b/compiler/testData/psi/secondaryConstructors/recoveryWithoutBodyWrongDelegationName.txt @@ -17,10 +17,10 @@ JetFile: recoveryWithoutBodyWrongDelegationName.kt PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiElement(COLON)(':') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL PsiErrorElement:Expecting a 'this' or 'super' constructor call + PsiWhiteSpace(' ') PsiErrorElement:Expecting member declaration PsiElement(IDENTIFIER)('thi') PsiErrorElement:Expecting member declaration @@ -45,10 +45,10 @@ JetFile: recoveryWithoutBodyWrongDelegationName.kt PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiElement(COLON)(':') - PsiWhiteSpace('\n\n ') CONSTRUCTOR_DELEGATION_CALL PsiErrorElement:Expecting a 'this' or 'super' constructor call + PsiWhiteSpace('\n\n ') FUN MODIFIER_LIST ANNOTATION_ENTRY @@ -72,10 +72,10 @@ JetFile: recoveryWithoutBodyWrongDelegationName.kt PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiElement(COLON)(':') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL PsiErrorElement:Expecting a 'this' or 'super' constructor call + PsiWhiteSpace(' ') PsiErrorElement:Expecting member declaration PsiElement(IDENTIFIER)('sup') PsiWhiteSpace('\n\n ') @@ -85,10 +85,10 @@ JetFile: recoveryWithoutBodyWrongDelegationName.kt PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiElement(COLON)(':') - PsiWhiteSpace(' ') CONSTRUCTOR_DELEGATION_CALL PsiErrorElement:Expecting a 'this' or 'super' constructor call + PsiWhiteSpace(' ') PsiErrorElement:Expecting member declaration PsiElement(IDENTIFIER)('thi') PsiErrorElement:Expecting member declaration