Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
724ca1d3
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
724ca1d3
编写于
2月 19, 2021
作者:
T
Tianyu Geng
提交者:
Mikhail Glukhikh
3月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIR: introduce diagnostic NESTED_CLASS_NOT_ALLOWED
上级
c5cabce2
变更
39
隐藏空白更改
内联
并排
Showing
39 changed file
with
125 addition
and
103 deletion
+125
-103
compiler/fir/analysis-tests/testData/resolve/diagnostics/localAnnotationClass.kt
...ests/testData/resolve/diagnostics/localAnnotationClass.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/diagnostics/localEntitytNotAllowed.kt
...ts/testData/resolve/diagnostics/localEntitytNotAllowed.kt
+2
-2
compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt
.../fir/checkers/generator/diagnostics/FirDiagnosticsList.kt
+3
-0
compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt
...rg/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt
+1
-0
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNestedClassChecker.kt
...ir/analysis/checkers/declaration/FirNestedClassChecker.kt
+50
-0
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt
...otlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt
+2
-0
compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonDeclarationCheckers.kt
...etbrains/kotlin/fir/checkers/CommonDeclarationCheckers.kt
+1
-0
compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt
...fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt
+5
-1
compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt
...sts/classObjects/InnerClassAccessThroughEnum_after.fir.kt
+1
-1
compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_before.fir.kt
...ts/classObjects/InnerClassAccessThroughEnum_before.fir.kt
+1
-1
compiler/testData/diagnostics/tests/classObjects/InnerClassClassObject.fir.kt
...agnostics/tests/classObjects/InnerClassClassObject.fir.kt
+1
-1
compiler/testData/diagnostics/tests/classObjects/multipleDissallowedDefaultObjects.fir.kt
...sts/classObjects/multipleDissallowedDefaultObjects.fir.kt
+3
-3
compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_after.fir.kt
...tests/enum/dontCreatePackageTypeForEnumEntry_after.fir.kt
+0
-16
compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_after.kt
...ics/tests/enum/dontCreatePackageTypeForEnumEntry_after.kt
+1
-0
compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_before.fir.kt
...ests/enum/dontCreatePackageTypeForEnumEntry_before.fir.kt
+1
-1
compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.fir.kt
...ostics/tests/enum/inner/insideInnerClassNotAllowed.fir.kt
+0
-7
compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.kt
...iagnostics/tests/enum/inner/insideInnerClassNotAllowed.kt
+1
-0
compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.fir.kt
...ests/enum/inner/twoEnumsInClassObjectAndInnerClass.fir.kt
+0
-9
compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.kt
...cs/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.kt
+1
-0
compiler/testData/diagnostics/tests/inline/unsupportedConstruction.fir.kt
...a/diagnostics/tests/inline/unsupportedConstruction.fir.kt
+1
-1
compiler/testData/diagnostics/tests/inner/annotationInInnerClass.fir.kt
...ata/diagnostics/tests/inner/annotationInInnerClass.fir.kt
+2
-2
compiler/testData/diagnostics/tests/inner/enumInInnerClass.fir.kt
.../testData/diagnostics/tests/inner/enumInInnerClass.fir.kt
+2
-2
compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv11.fir.kt
...ostics/tests/inner/innerClassInEnumEntryClass_lv11.fir.kt
+2
-2
compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv12.fir.kt
...ostics/tests/inner/innerClassInEnumEntryClass_lv12.fir.kt
+2
-2
compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv13.fir.kt
...ostics/tests/inner/innerClassInEnumEntryClass_lv13.fir.kt
+2
-2
compiler/testData/diagnostics/tests/inner/interfaceInInnerClass.fir.kt
...Data/diagnostics/tests/inner/interfaceInInnerClass.fir.kt
+2
-2
compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_after.fir.kt
...iagnostics/tests/inner/nestedClassNotAllowed_after.fir.kt
+0
-26
compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_after.kt
...ta/diagnostics/tests/inner/nestedClassNotAllowed_after.kt
+1
-0
compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_before.fir.kt
...agnostics/tests/inner/nestedClassNotAllowed_before.fir.kt
+4
-4
compiler/testData/diagnostics/tests/inner/nestedObject.fir.kt
...iler/testData/diagnostics/tests/inner/nestedObject.fir.kt
+3
-3
compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt
...iagnostics/tests/localClasses/localAnnotationClass.fir.kt
+1
-1
compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt
...stics/tests/localClasses/localAnnotationClassError.fir.kt
+0
-9
compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.kt
...agnostics/tests/localClasses/localAnnotationClassError.kt
+1
-0
compiler/testData/diagnostics/tests/localInterfaces.fir.kt
compiler/testData/diagnostics/tests/localInterfaces.fir.kt
+2
-2
compiler/testData/diagnostics/tests/modifiers/const/applicability.fir.kt
...ta/diagnostics/tests/modifiers/const/applicability.fir.kt
+1
-1
idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/structure/FileStructureElement.kt
.../fir/low/level/api/file/structure/FileStructureElement.kt
+4
-1
idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt
.../frontend/api/fir/diagnostics/KtFirDataClassConverters.kt
+7
-0
idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt
...lin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt
+5
-0
idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt
...idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt
+8
-0
未找到文件。
compiler/fir/analysis-tests/testData/resolve/diagnostics/localAnnotationClass.kt
浏览文件 @
724ca1d3
...
@@ -3,6 +3,6 @@ fun foo() {
...
@@ -3,6 +3,6 @@ fun foo() {
@Ann
class
Local
{
@Ann
class
Local
{
<!
LOCAL_ANNOTATION_CLASS_ERROR
{
LT
}!>
// There should also be NESTED_CLASS_NOT_ALLOWED report here.
<!
LOCAL_ANNOTATION_CLASS_ERROR
{
LT
}!>
// There should also be NESTED_CLASS_NOT_ALLOWED report here.
<!
LOCAL_ANNOTATION_CLASS_ERROR
{
PSI
}!>
annotation
class
Nested
<!><!>
<!
LOCAL_ANNOTATION_CLASS_ERROR
{
PSI
}!>
annotation
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
Nested
<!>
<!><!>
}
}
}
}
compiler/fir/analysis-tests/testData/resolve/diagnostics/localEntitytNotAllowed.kt
浏览文件 @
724ca1d3
...
@@ -8,7 +8,7 @@ object A {
...
@@ -8,7 +8,7 @@ object A {
val
a
=
object
:
Any
()
{
val
a
=
object
:
Any
()
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
D
<!>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
D
<!>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
G
<!>
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
G
<!>
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
Z
<!>
<!
LOCAL_INTERFACE_NOT_ALLOWED
,
NESTED_CLASS_NOT_ALLOWED
!>
interface
Z
<!>
}
}
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
Y
<!>
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
Y
<!>
...
@@ -17,7 +17,7 @@ object A {
...
@@ -17,7 +17,7 @@ object A {
fun
b
()
{
fun
b
()
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
E
<!>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
E
<!>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
F
<!>
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
F
<!>
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
M
<!>
<!
LOCAL_INTERFACE_NOT_ALLOWED
,
NESTED_CLASS_NOT_ALLOWED
!>
interface
M
<!>
}
}
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
N
<!>
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
N
<!>
...
...
compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt
浏览文件 @
724ca1d3
...
@@ -42,6 +42,9 @@ object DIAGNOSTICS_LIST : DiagnosticList() {
...
@@ -42,6 +42,9 @@ object DIAGNOSTICS_LIST : DiagnosticList() {
val
VARIABLE_EXPECTED
by
error
<
FirSourceElement
,
PsiElement
>()
val
VARIABLE_EXPECTED
by
error
<
FirSourceElement
,
PsiElement
>()
val
RETURN_NOT_ALLOWED
by
error
<
FirSourceElement
,
PsiElement
>()
val
RETURN_NOT_ALLOWED
by
error
<
FirSourceElement
,
PsiElement
>()
val
DELEGATION_IN_INTERFACE
by
error
<
FirSourceElement
,
PsiElement
>()
val
DELEGATION_IN_INTERFACE
by
error
<
FirSourceElement
,
PsiElement
>()
val
NESTED_CLASS_NOT_ALLOWED
by
error
<
FirSourceElement
,
KtNamedDeclaration
>(
PositioningStrategy
.
DECLARATION_NAME
)
{
parameter
<
String
>(
"declaration"
)
}
}
}
val
UNRESOLVED
by
object
:
DiagnosticGroup
(
"Unresolved"
)
{
val
UNRESOLVED
by
object
:
DiagnosticGroup
(
"Unresolved"
)
{
...
...
compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt
浏览文件 @
724ca1d3
...
@@ -61,6 +61,7 @@ object FirErrors {
...
@@ -61,6 +61,7 @@ object FirErrors {
val
VARIABLE_EXPECTED
by
error0
<
FirSourceElement
,
PsiElement
>()
val
VARIABLE_EXPECTED
by
error0
<
FirSourceElement
,
PsiElement
>()
val
RETURN_NOT_ALLOWED
by
error0
<
FirSourceElement
,
PsiElement
>()
val
RETURN_NOT_ALLOWED
by
error0
<
FirSourceElement
,
PsiElement
>()
val
DELEGATION_IN_INTERFACE
by
error0
<
FirSourceElement
,
PsiElement
>()
val
DELEGATION_IN_INTERFACE
by
error0
<
FirSourceElement
,
PsiElement
>()
val
NESTED_CLASS_NOT_ALLOWED
by
error1
<
FirSourceElement
,
KtNamedDeclaration
,
String
>(
SourceElementPositioningStrategies
.
DECLARATION_NAME
)
// Unresolved
// Unresolved
val
HIDDEN
by
error1
<
FirSourceElement
,
PsiElement
,
AbstractFirBasedSymbol
<
*
>>(
SourceElementPositioningStrategies
.
REFERENCE_BY_QUALIFIED
)
val
HIDDEN
by
error1
<
FirSourceElement
,
PsiElement
,
AbstractFirBasedSymbol
<
*
>>(
SourceElementPositioningStrategies
.
REFERENCE_BY_QUALIFIED
)
...
...
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNestedClassChecker.kt
0 → 100644
浏览文件 @
724ca1d3
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package
org.jetbrains.kotlin.fir.analysis.checkers.declaration
import
org.jetbrains.kotlin.descriptors.ClassKind
import
org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import
org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NESTED_CLASS_NOT_ALLOWED
import
org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import
org.jetbrains.kotlin.fir.declarations.*
// No need to visit anonymous object since an anonymous object is always inner. This aligns with
// compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java:198
object
FirNestedClassChecker
:
FirRegularClassChecker
()
{
override
fun
check
(
declaration
:
FirRegularClass
,
context
:
CheckerContext
,
reporter
:
DiagnosticReporter
)
{
// Local enums / objects / companion objects are handled with different diagnostic codes.
if
((
declaration
.
classKind
.
isSingleton
||
declaration
.
classKind
==
ClassKind
.
ENUM_CLASS
)
&&
declaration
.
isLocal
)
return
val
containingDeclaration
=
context
.
containingDeclarations
.
lastOrNull
()
?:
return
when
(
containingDeclaration
)
{
is
FirRegularClass
->
{
if
(!
declaration
.
isInner
&&
(
containingDeclaration
.
isInner
||
containingDeclaration
.
isLocal
))
{
reporter
.
reportOn
(
declaration
.
source
,
NESTED_CLASS_NOT_ALLOWED
,
declaration
.
description
,
context
)
}
}
is
FirClass
<
*
>
->
{
// Since 1.3, enum entries can contain inner classes only.
// Companion objects are reported with code WRONG_MODIFIER_CONTAINING_DECLARATION instead
if
(
containingDeclaration
.
classKind
==
ClassKind
.
ENUM_ENTRY
&&
!
declaration
.
isInner
&&
!
declaration
.
isCompanion
)
{
reporter
.
reportOn
(
declaration
.
source
,
NESTED_CLASS_NOT_ALLOWED
,
declaration
.
description
,
context
)
}
}
}
}
// Note: here we don't differentiate anonymous object like in FE1.0
// (org.jetbrains.kotlin.resolve.ModifiersChecker.DetailedClassKind) because this case has been ruled out in the first place.
private
val
FirRegularClass
.
description
:
String
get
()
=
when
(
classKind
)
{
ClassKind
.
CLASS
->
"Class"
ClassKind
.
INTERFACE
->
"Interface"
ClassKind
.
ENUM_CLASS
->
"Enum class"
ClassKind
.
ENUM_ENTRY
->
"Enum entry"
ClassKind
.
ANNOTATION_CLASS
->
"Annotation class"
ClassKind
.
OBJECT
->
if
(
this
.
isCompanion
)
"Companion object"
else
"Object"
}
}
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt
浏览文件 @
724ca1d3
...
@@ -98,6 +98,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.LOCAL_INTERFACE_N
...
@@ -98,6 +98,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.LOCAL_INTERFACE_N
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.LOCAL_OBJECT_NOT_ALLOWED
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.LOCAL_OBJECT_NOT_ALLOWED
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MANY_COMPANION_OBJECTS
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MANY_COMPANION_OBJECTS
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MISSING_VAL_ON_ANNOTATION_PARAMETER
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MISSING_VAL_ON_ANNOTATION_PARAMETER
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NESTED_CLASS_NOT_ALLOWED
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTIPLE_VARARG_PARAMETERS
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTIPLE_VARARG_PARAMETERS
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NONE_APPLICABLE
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NONE_APPLICABLE
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY
...
@@ -211,6 +212,7 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension {
...
@@ -211,6 +212,7 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension {
map
.
put
(
VARIABLE_EXPECTED
,
"Variable expected"
)
map
.
put
(
VARIABLE_EXPECTED
,
"Variable expected"
)
map
.
put
(
RETURN_NOT_ALLOWED
,
"'return' is not allowed here"
)
map
.
put
(
RETURN_NOT_ALLOWED
,
"'return' is not allowed here"
)
map
.
put
(
DELEGATION_IN_INTERFACE
,
"Interfaces cannot use delegation"
)
map
.
put
(
DELEGATION_IN_INTERFACE
,
"Interfaces cannot use delegation"
)
map
.
put
(
NESTED_CLASS_NOT_ALLOWED
,
"{0} is not allowed here"
,
TO_STRING
)
// Unresolved
// Unresolved
map
.
put
(
HIDDEN
,
"Symbol {0} is invisible"
,
SYMBOL
)
map
.
put
(
HIDDEN
,
"Symbol {0} is invisible"
,
SYMBOL
)
...
...
compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonDeclarationCheckers.kt
浏览文件 @
724ca1d3
...
@@ -60,6 +60,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
...
@@ -60,6 +60,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
FirTypeParametersInObjectChecker
,
FirTypeParametersInObjectChecker
,
FirMemberFunctionChecker
,
FirMemberFunctionChecker
,
FirMemberPropertyChecker
,
FirMemberPropertyChecker
,
FirNestedClassChecker
,
)
)
override
val
constructorCheckers
:
Set
<
FirConstructorChecker
>
=
setOf
(
override
val
constructorCheckers
:
Set
<
FirConstructorChecker
>
=
setOf
(
...
...
compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt
浏览文件 @
724ca1d3
...
@@ -793,7 +793,11 @@ class RawFirBuilder(
...
@@ -793,7 +793,11 @@ class RawFirBuilder(
override
fun
visitClassOrObject
(
classOrObject
:
KtClassOrObject
,
data
:
Unit
):
FirElement
{
override
fun
visitClassOrObject
(
classOrObject
:
KtClassOrObject
,
data
:
Unit
):
FirElement
{
return
withChildClassName
(
return
withChildClassName
(
classOrObject
.
nameAsSafeName
,
classOrObject
.
nameAsSafeName
,
classOrObject
.
isLocal
||
classOrObject
.
getStrictParentOfType
<
KtEnumEntry
>()
!=
null
classOrObject
.
isLocal
// TODO: currently enum entry initializer is represented in FIR as an FirAnonymousObject. Because of this, all
// nested declarations are now marked local. This causes the FirNestedClassChecker to ignore some invalid programs.
// See KT-45115
||
classOrObject
.
getStrictParentOfType
<
KtEnumEntry
>()
!=
null
)
{
)
{
val
classKind
=
when
(
classOrObject
)
{
val
classKind
=
when
(
classOrObject
)
{
is
KtObjectDeclaration
->
ClassKind
.
OBJECT
is
KtObjectDeclaration
->
ClassKind
.
OBJECT
...
...
compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt
浏览文件 @
724ca1d3
...
@@ -11,7 +11,7 @@ enum class C {
...
@@ -11,7 +11,7 @@ enum class C {
O_O
O_O
}
}
class
G
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
G
<!>
},
},
E4
{
E4
{
...
...
compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_before.fir.kt
浏览文件 @
724ca1d3
...
@@ -11,7 +11,7 @@ enum class C {
...
@@ -11,7 +11,7 @@ enum class C {
O_O
O_O
}
}
class
G
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
G
<!>
},
},
E4
{
E4
{
...
...
compiler/testData/diagnostics/tests/classObjects/InnerClassClassObject.fir.kt
浏览文件 @
724ca1d3
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
class
A
{
class
A
{
inner
class
B
{
inner
class
B
{
companion
object
{
}
companion
<!
NESTED_CLASS_NOT_ALLOWED
!>
object
<!>
{
}
}
}
}
}
...
...
compiler/testData/diagnostics/tests/classObjects/multipleDissallowedDefaultObjects.fir.kt
浏览文件 @
724ca1d3
class
A
{
class
A
{
inner
class
I
{
inner
class
I
{
companion
object
A
companion
<!
NESTED_CLASS_NOT_ALLOWED
!>
object
A
<!>
companion
<!
MANY_COMPANION_OBJECTS
!>
object
B
<!>
companion
<!
MANY_COMPANION_OBJECTS
,
NESTED_CLASS_NOT_ALLOWED
!>
object
B
<!>
companion
<!
MANY_COMPANION_OBJECTS
!>
object
C
<!>
companion
<!
MANY_COMPANION_OBJECTS
,
NESTED_CLASS_NOT_ALLOWED
!>
object
C
<!>
}
}
}
}
...
...
compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_after.fir.kt
已删除
100644 → 0
浏览文件 @
c5cabce2
// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner
enum
class
E
{
FIRST
,
SECOND
{
class
A
};
}
val
foo
:
Any
.()
->
Unit
=
{}
fun
f1
()
=
E
.
FIRST
.
foo
()
fun
f2
()
=
E
.
FIRST
.(
foo
)()
fun
f3
()
=
E
.
SECOND
.
foo
()
fun
f4
()
=
E
.
SECOND
.(
foo
)()
fun
f5
()
=
E
.
SECOND
.<!
UNRESOLVED_REFERENCE
!>
A
<
!
>()
compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_after.kt
浏览文件 @
724ca1d3
// FIR_IDENTICAL
// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner
// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner
enum
class
E
{
enum
class
E
{
...
...
compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_before.fir.kt
浏览文件 @
724ca1d3
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
enum
class
E
{
enum
class
E
{
FIRST
,
FIRST
,
SECOND
{
SECOND
{
class
A
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
A
<!>
};
};
}
}
...
...
compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.fir.kt
已删除
100644 → 0
浏览文件 @
c5cabce2
class
A
{
inner
class
B
{
enum
class
E
{
ENTRY
}
}
}
compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.kt
浏览文件 @
724ca1d3
// FIR_IDENTICAL
class
A
{
class
A
{
inner
class
B
{
inner
class
B
{
<!
NESTED_CLASS_NOT_ALLOWED
!>
enum
class
E
<!>
{
<!
NESTED_CLASS_NOT_ALLOWED
!>
enum
class
E
<!>
{
...
...
compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.fir.kt
已删除
100644 → 0
浏览文件 @
c5cabce2
class
A
{
companion
object
{
enum
class
E
{
ENTRY
}
// OK
}
inner
class
B
{
enum
class
E
{
ENTRY
}
}
}
compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.kt
浏览文件 @
724ca1d3
// FIR_IDENTICAL
class
A
{
class
A
{
companion
object
{
companion
object
{
enum
class
E
{
ENTRY
}
// OK
enum
class
E
{
ENTRY
}
// OK
...
...
compiler/testData/diagnostics/tests/inline/unsupportedConstruction.fir.kt
浏览文件 @
724ca1d3
...
@@ -30,4 +30,4 @@ class Derived: Base() {
...
@@ -30,4 +30,4 @@ class Derived: Base() {
inline
final
override
fun
foo
(
a
:
Int
)
{
inline
final
override
fun
foo
(
a
:
Int
)
{
}
}
}
}
\ No newline at end of file
compiler/testData/diagnostics/tests/inner/annotationInInnerClass.fir.kt
浏览文件 @
724ca1d3
class
Outer
{
class
Outer
{
inner
class
Inner
{
inner
class
Inner
{
annotation
class
TestNestedAnnotation
annotation
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
TestNestedAnnotation
<!>
}
}
}
}
\ No newline at end of file
compiler/testData/diagnostics/tests/inner/enumInInnerClass.fir.kt
浏览文件 @
724ca1d3
class
Outer
{
class
Outer
{
inner
class
Inner
{
inner
class
Inner
{
enum
class
TestNestedEnum
<!
NESTED_CLASS_NOT_ALLOWED
!>
enum
class
TestNestedEnum
<!>
}
}
}
}
\ No newline at end of file
compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv11.fir.kt
浏览文件 @
724ca1d3
...
@@ -4,9 +4,9 @@ enum class Enum {
...
@@ -4,9 +4,9 @@ enum class Enum {
ENTRY_WITH_CLASS
{
ENTRY_WITH_CLASS
{
inner
class
TestInner
inner
class
TestInner
class
TestNested
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
TestNested
<!>
interface
TestInterface
<!
NESTED_CLASS_NOT_ALLOWED
!>
interface
TestInterface
<!>
object
TestObject
object
TestObject
...
...
compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv12.fir.kt
浏览文件 @
724ca1d3
...
@@ -4,9 +4,9 @@ enum class Enum {
...
@@ -4,9 +4,9 @@ enum class Enum {
ENTRY_WITH_CLASS
{
ENTRY_WITH_CLASS
{
inner
class
TestInner
inner
class
TestInner
class
TestNested
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
TestNested
<!>
interface
TestInterface
<!
NESTED_CLASS_NOT_ALLOWED
!>
interface
TestInterface
<!>
object
TestObject
object
TestObject
...
...
compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv13.fir.kt
浏览文件 @
724ca1d3
...
@@ -4,9 +4,9 @@ enum class Enum {
...
@@ -4,9 +4,9 @@ enum class Enum {
ENTRY_WITH_CLASS
{
ENTRY_WITH_CLASS
{
inner
class
TestInner
inner
class
TestInner
class
TestNested
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
TestNested
<!>
interface
TestInterface
<!
NESTED_CLASS_NOT_ALLOWED
!>
interface
TestInterface
<!>
object
TestObject
object
TestObject
...
...
compiler/testData/diagnostics/tests/inner/interfaceInInnerClass.fir.kt
浏览文件 @
724ca1d3
class
Outer
{
class
Outer
{
inner
class
Inner
{
inner
class
Inner
{
interface
TestNestedInterface
<!
NESTED_CLASS_NOT_ALLOWED
!>
interface
TestNestedInterface
<!>
}
}
}
}
\ No newline at end of file
compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_after.fir.kt
已删除
100644 → 0
浏览文件 @
c5cabce2
// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner
class
A
{
inner
class
B
{
class
C
}
fun
foo
()
{
class
B
{
class
C
}
}
}
fun
foo
()
{
class
B
{
class
C
}
}
enum
class
E
{
E1
{
class
D
}
}
compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_after.kt
浏览文件 @
724ca1d3
// FIR_IDENTICAL
// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner
// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner
class
A
{
class
A
{
...
...
compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_before.fir.kt
浏览文件 @
724ca1d3
...
@@ -2,25 +2,25 @@
...
@@ -2,25 +2,25 @@
class
A
{
class
A
{
inner
class
B
{
inner
class
B
{
class
C
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
C
<!>
}
}
fun
foo
()
{
fun
foo
()
{
class
B
{
class
B
{
class
C
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
C
<!>
}
}
}
}
}
}
fun
foo
()
{
fun
foo
()
{
class
B
{
class
B
{
class
C
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
C
<!>
}
}
}
}
enum
class
E
{
enum
class
E
{
E1
{
E1
{
class
D
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
D
<!>
}
}
}
}
compiler/testData/diagnostics/tests/inner/nestedObject.fir.kt
浏览文件 @
724ca1d3
// SKIP_TXT
// SKIP_TXT
class
Outer
{
class
Outer
{
inner
class
Inner1
{
inner
class
Inner1
{
object
Obj1
<!
NESTED_CLASS_NOT_ALLOWED
!>
object
Obj1
<!>
companion
object
Obj2
companion
<!
NESTED_CLASS_NOT_ALLOWED
!>
object
Obj2
<!>
inner
class
Inner2
{
inner
class
Inner2
{
object
Obj3
<!
NESTED_CLASS_NOT_ALLOWED
!>
object
Obj3
<!>
}
}
}
}
}
}
compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt
浏览文件 @
724ca1d3
...
@@ -4,6 +4,6 @@ fun f() {
...
@@ -4,6 +4,6 @@ fun f() {
<!
LOCAL_ANNOTATION_CLASS_ERROR
!>
annotation
class
Anno
<!>
<!
LOCAL_ANNOTATION_CLASS_ERROR
!>
annotation
class
Anno
<!>
@Anno
class
Local
{
@Anno
class
Local
{
<!
LOCAL_ANNOTATION_CLASS_ERROR
!>
annotation
class
Nested
<!>
<!
LOCAL_ANNOTATION_CLASS_ERROR
!>
annotation
<!
NESTED_CLASS_NOT_ALLOWED
!>
class
Nested
<!>
<!>
}
}
}
}
compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt
已删除
100644 → 0
浏览文件 @
c5cabce2
// !LANGUAGE: +ProhibitLocalAnnotations
fun
f
()
{
<!
LOCAL_ANNOTATION_CLASS_ERROR
!>
annotation
class
Anno
<!>
@Anno
class
Local
{
<!
LOCAL_ANNOTATION_CLASS_ERROR
!>
annotation
class
Nested
<!>
}
}
compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.kt
浏览文件 @
724ca1d3
// FIR_IDENTICAL
// !LANGUAGE: +ProhibitLocalAnnotations
// !LANGUAGE: +ProhibitLocalAnnotations
fun
f
()
{
fun
f
()
{
...
...
compiler/testData/diagnostics/tests/localInterfaces.fir.kt
浏览文件 @
724ca1d3
...
@@ -6,9 +6,9 @@ fun foo() {
...
@@ -6,9 +6,9 @@ fun foo() {
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
c<!> {}
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
c<!> {}
}
}
class
A
{
class
A
{
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
d<!> {}
<!
LOCAL_INTERFACE_NOT_ALLOWED
,
NESTED_CLASS_NOT_ALLOWED
!>
interface
d<!> {}
}
}
val f = {
val f = {
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
e<!> {}
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
e<!> {}
}
}
}
}
\ No newline at end of file
compiler/testData/diagnostics/tests/modifiers/const/applicability.fir.kt
浏览文件 @
724ca1d3
...
@@ -61,7 +61,7 @@ enum class MyEnum {
...
@@ -61,7 +61,7 @@ enum class MyEnum {
class
Outer
{
class
Outer
{
inner
class
Inner
{
inner
class
Inner
{
object
C
{
<!
NESTED_CLASS_NOT_ALLOWED
!>
object
C
<!>
{
const
val
a
=
18
const
val
a
=
18
}
}
}
}
...
...
idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/structure/FileStructureElement.kt
浏览文件 @
724ca1d3
...
@@ -173,7 +173,10 @@ internal class NonReanalyzableDeclarationStructureElement(
...
@@ -173,7 +173,10 @@ internal class NonReanalyzableDeclarationStructureElement(
firFile
,
firFile
,
onDeclarationEnter
=
{
firDeclaration
->
onDeclarationEnter
=
{
firDeclaration
->
when
{
when
{
firDeclaration
.
isGeneratedDeclaration
->
DiagnosticCollectorDeclarationAction
.
SKIP
// Some generated declaration contains structures that we need to check. For example the FIR representation of an
// enum entry initializer, when present, is a generated anonymous object of kind `ENUM_ENTRY`.
firDeclaration
.
isGeneratedDeclaration
->
DiagnosticCollectorDeclarationAction
.
SKIP_CURRENT_DECLARATION_AND_CHECK_NESTED
firDeclaration
is
FirFile
->
DiagnosticCollectorDeclarationAction
.
CHECK_CURRENT_DECLARATION_AND_CHECK_NESTED
firDeclaration
is
FirFile
->
DiagnosticCollectorDeclarationAction
.
CHECK_CURRENT_DECLARATION_AND_CHECK_NESTED
firDeclaration
==
fir
->
{
firDeclaration
==
fir
->
{
inCurrentDeclaration
=
true
inCurrentDeclaration
=
true
...
...
idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt
浏览文件 @
724ca1d3
...
@@ -99,6 +99,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
...
@@ -99,6 +99,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token
,
token
,
)
)
}
}
add
(
FirErrors
.
NESTED_CLASS_NOT_ALLOWED
)
{
firDiagnostic
->
NestedClassNotAllowedImpl
(
firDiagnostic
.
a
,
firDiagnostic
as
FirPsiDiagnostic
<
*
>,
token
,
)
}
add
(
FirErrors
.
HIDDEN
)
{
firDiagnostic
->
add
(
FirErrors
.
HIDDEN
)
{
firDiagnostic
->
HiddenImpl
(
HiddenImpl
(
firSymbolBuilder
.
buildSymbol
(
firDiagnostic
.
a
.
fir
as
FirDeclaration
),
firSymbolBuilder
.
buildSymbol
(
firDiagnostic
.
a
.
fir
as
FirDeclaration
),
...
...
idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt
浏览文件 @
724ca1d3
...
@@ -83,6 +83,11 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
...
@@ -83,6 +83,11 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
override
val
diagnosticClass
get
()
=
DelegationInInterface
::
class
override
val
diagnosticClass
get
()
=
DelegationInInterface
::
class
}
}
abstract
class
NestedClassNotAllowed
:
KtFirDiagnostic
<
KtNamedDeclaration
>()
{
override
val
diagnosticClass
get
()
=
NestedClassNotAllowed
::
class
abstract
val
declaration
:
String
}
abstract
class
Hidden
:
KtFirDiagnostic
<
PsiElement
>()
{
abstract
class
Hidden
:
KtFirDiagnostic
<
PsiElement
>()
{
override
val
diagnosticClass
get
()
=
Hidden
::
class
override
val
diagnosticClass
get
()
=
Hidden
::
class
abstract
val
hidden
:
KtSymbol
abstract
val
hidden
:
KtSymbol
...
...
idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt
浏览文件 @
724ca1d3
...
@@ -114,6 +114,14 @@ internal class DelegationInInterfaceImpl(
...
@@ -114,6 +114,14 @@ internal class DelegationInInterfaceImpl(
override
val
firDiagnostic
:
FirPsiDiagnostic
<
*
>
by
weakRef
(
firDiagnostic
)
override
val
firDiagnostic
:
FirPsiDiagnostic
<
*
>
by
weakRef
(
firDiagnostic
)
}
}
internal
class
NestedClassNotAllowedImpl
(
override
val
declaration
:
String
,
firDiagnostic
:
FirPsiDiagnostic
<
*
>,
override
val
token
:
ValidityToken
,
)
:
KtFirDiagnostic
.
NestedClassNotAllowed
(),
KtAbstractFirDiagnostic
<
KtNamedDeclaration
>
{
override
val
firDiagnostic
:
FirPsiDiagnostic
<
*
>
by
weakRef
(
firDiagnostic
)
}
internal
class
HiddenImpl
(
internal
class
HiddenImpl
(
override
val
hidden
:
KtSymbol
,
override
val
hidden
:
KtSymbol
,
firDiagnostic
:
FirPsiDiagnostic
<
*
>,
firDiagnostic
:
FirPsiDiagnostic
<
*
>,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录