From 133928626193054af53992dfa4acb36b165e2f6d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 30 May 2016 14:24:11 +0300 Subject: [PATCH] Drop undocumented absolute name specification feature with 'package.' --- .../parsing/KotlinExpressionParsing.java | 1 - .../kotlin/parsing/KotlinParsing.java | 5 ++-- .../kotlin/psi/KtImportDirective.java | 11 ++----- .../org/jetbrains/kotlin/psi/KtUserType.java | 17 ----------- .../KtImportDirectiveElementType.java | 2 +- .../stubs/elements/KtUserTypeElementType.java | 2 +- .../resolve/QualifiedExpressionResolver.kt | 29 +++++-------------- .../SmartcastsForStableIdentifiers.kt | 5 +--- compiler/testData/psi/When.txt | 3 +- .../psi/greatSyntacticShift/functionTypes.txt | 3 +- .../IncompleteTypeRefWithPackageKeyword.txt | 3 +- grammar/src/expressions.grm | 1 - grammar/src/types.grm | 2 +- .../keywords/InFunctionTypePosition.kt | 2 -- 14 files changed, 22 insertions(+), 64 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java index 4e365920a76..603b3136344 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java @@ -106,7 +106,6 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing { IDENTIFIER, // SimpleName - PACKAGE_KEYWORD, // for absolute qualified names AT // Just for better recovery and maybe for annotations ); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java index 767696e13f3..46cf26a43bb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java @@ -23,7 +23,6 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.KtNodeType; import org.jetbrains.kotlin.lexer.KtKeywordToken; import org.jetbrains.kotlin.lexer.KtTokens; @@ -1939,7 +1938,7 @@ public class KotlinParsing extends AbstractKotlinParsing { /* * userType - * : ("package" ".")? simpleUserType{"."} + * : simpleUserType{"."} * ; * * recovers on platform types: @@ -1951,7 +1950,9 @@ public class KotlinParsing extends AbstractKotlinParsing { PsiBuilder.Marker userType = mark(); if (at(PACKAGE_KEYWORD)) { + PsiBuilder.Marker keyword = mark(); advance(); // PACKAGE_KEYWORD + keyword.error("Expecting an element"); expect(DOT, "Expecting '.'", TokenSet.create(IDENTIFIER, LBRACE, RBRACE)); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtImportDirective.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtImportDirective.java index 0ecf7ab1bf9..d5b32e7e116 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtImportDirective.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtImportDirective.java @@ -43,15 +43,8 @@ public class KtImportDirective extends KtElementImplStub 0) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtUserType.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtUserType.java index fcddcfbef62..5bea5128077 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtUserType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtUserType.java @@ -37,14 +37,6 @@ public class KtUserType extends KtElementImplStub implements super(stub, KtStubElementTypes.USER_TYPE); } - public boolean isAbsoluteInRootPackage() { - KotlinUserTypeStub stub = getStub(); - if (stub != null) { - return stub.isAbsoluteInRootPackage(); - } - return findChildByType(KtTokens.PACKAGE_KEYWORD) != null; - } - @Override public R accept(@NotNull KtVisitor visitor, D data) { return visitor.visitUserType(this, data); @@ -83,15 +75,6 @@ public class KtUserType extends KtElementImplStub implements return getStubOrPsiChild(KtStubElementTypes.USER_TYPE); } - public boolean hasTypesWithTypeArgsInside() { - for (KtUserType type : getStubOrPsiChildrenAsList(KtStubElementTypes.USER_TYPE)) { - if (!type.getTypeArguments().isEmpty() || type.hasTypesWithTypeArgsInside()) { - return true; - } - } - return false; - } - public void deleteQualifier() { KtUserType qualifier = getQualifier(); assert qualifier != null; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtImportDirectiveElementType.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtImportDirectiveElementType.java index 8667dc86867..44d2d7e5d1a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtImportDirectiveElementType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtImportDirectiveElementType.java @@ -39,7 +39,7 @@ public class KtImportDirectiveElementType extends KtStubElementType, ownerDescriptor: DeclarationDescriptor?, - module: ModuleDescriptor, - scope: LexicalScope?, + scope: LexicalScope, trace: BindingTrace, isQualifier: Boolean ): TypeQualifierResolutionResult { assert(qualifierPartList.isNotEmpty()) { "Qualifier list should not be empty" } val qualifier = resolveToPackageOrClass( - qualifierPartList.subList(0, qualifierPartList.size - 1), module, trace, ownerDescriptor, scope, + qualifierPartList.subList(0, qualifierPartList.size - 1), + scope.ownerDescriptor.module, trace, ownerDescriptor, scope, position = QualifierPosition.TYPE ) ?: return TypeQualifierResolutionResult(qualifierPartList, null) @@ -140,21 +137,9 @@ class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageValidator return TypeQualifierResolutionResult(qualifierPartList, descriptor) } - return resolveQualifierPartListForType( - qualifierPartList, ownerDescriptor, scope.ownerDescriptor.module, scope, trace, isQualifier = true - ) + return resolveQualifierPartListForType(qualifierPartList, ownerDescriptor, scope, trace, isQualifier = true) } - private val KtUserType.startWithPackage: Boolean - get() { - var firstPart = this - while (firstPart.qualifier != null) { - firstPart = firstPart.qualifier!! - } - return firstPart.isAbsoluteInRootPackage - } - - private fun KtUserType.asQualifierPartList(): Pair, Boolean> { var hasError = false val result = SmartList() diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastsForStableIdentifiers.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastsForStableIdentifiers.kt index 81340fd5293..fe2cb6fae30 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastsForStableIdentifiers.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastsForStableIdentifiers.kt @@ -28,9 +28,6 @@ fun Any?.vars(a: Any?) : Int { if (example.ns.y is Int) { b = example.ns.y } -// if (package.bottles.ns.y is Int) { -// b = ns.y -// } if (Obj.y is Int) { b = Obj.y } @@ -86,4 +83,4 @@ open class C { t = this@C } } -} \ No newline at end of file +} diff --git a/compiler/testData/psi/When.txt b/compiler/testData/psi/When.txt index a9ea0c34d49..86d07032ab6 100644 --- a/compiler/testData/psi/When.txt +++ b/compiler/testData/psi/When.txt @@ -359,7 +359,8 @@ JetFile: When.kt TYPE_REFERENCE USER_TYPE USER_TYPE - PsiElement(package)('package') + PsiErrorElement:Expecting an element + PsiElement(package)('package') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('a') diff --git a/compiler/testData/psi/greatSyntacticShift/functionTypes.txt b/compiler/testData/psi/greatSyntacticShift/functionTypes.txt index 53683a5e262..ce8387a95f5 100644 --- a/compiler/testData/psi/greatSyntacticShift/functionTypes.txt +++ b/compiler/testData/psi/greatSyntacticShift/functionTypes.txt @@ -74,7 +74,8 @@ JetFile: functionTypes.kt PsiWhiteSpace(' ') TYPE_REFERENCE USER_TYPE - PsiElement(package)('package') + PsiErrorElement:Expecting an element + PsiElement(package)('package') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('Int') diff --git a/compiler/testData/psi/recovery/IncompleteTypeRefWithPackageKeyword.txt b/compiler/testData/psi/recovery/IncompleteTypeRefWithPackageKeyword.txt index 4393e23142e..ef5a26fb8f7 100644 --- a/compiler/testData/psi/recovery/IncompleteTypeRefWithPackageKeyword.txt +++ b/compiler/testData/psi/recovery/IncompleteTypeRefWithPackageKeyword.txt @@ -22,7 +22,8 @@ JetFile: IncompleteTypeRefWithPackageKeyword.kt PsiWhiteSpace(' ') TYPE_REFERENCE USER_TYPE - PsiElement(package)('package') + PsiErrorElement:Expecting an element + PsiElement(package)('package') PsiErrorElement:Expecting '.' PsiWhiteSpace('\n') diff --git a/grammar/src/expressions.grm b/grammar/src/expressions.grm index 59cf593b70a..904202cb2b4 100644 --- a/grammar/src/expressions.grm +++ b/grammar/src/expressions.grm @@ -122,7 +122,6 @@ atomicExpression : loop : SimpleName : FieldName - : "package" // for the root package ; labelReference diff --git a/grammar/src/types.grm b/grammar/src/types.grm index 9715cd466d6..402e141401e 100644 --- a/grammar/src/types.grm +++ b/grammar/src/types.grm @@ -36,7 +36,7 @@ selfType */ userType - : ("package" ".")? simpleUserType{"."} + : simpleUserType{"."} ; simpleUserType diff --git a/idea/idea-completion/testData/keywords/InFunctionTypePosition.kt b/idea/idea-completion/testData/keywords/InFunctionTypePosition.kt index 65588a1800d..62a7b377fe3 100644 --- a/idea/idea-completion/testData/keywords/InFunctionTypePosition.kt +++ b/idea/idea-completion/testData/keywords/InFunctionTypePosition.kt @@ -2,6 +2,4 @@ fun foo() { val test : } -/*TODO: Is 'package' type qualifier syntax correct?*/ -// EXIST: package // NOTHING_ELSE