Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
40bec303
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,发现更多精彩内容 >>
提交
40bec303
编写于
1月 21, 2021
作者:
M
Mikhail Glukhikh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIR: implement LT positioning in diagnostic tests, fix LT strategies
上级
f1d8a6e5
变更
36
隐藏空白更改
内联
并排
Showing
36 changed file
with
275 addition
and
210 deletion
+275
-210
compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationClassMember.kt
...sts/testData/resolve/diagnostics/annotationClassMember.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/diagnostics/conflictingOverloads.kt
...ests/testData/resolve/diagnostics/conflictingOverloads.kt
+7
-7
compiler/fir/analysis-tests/testData/resolve/diagnostics/constructorInInterface.kt
...ts/testData/resolve/diagnostics/constructorInInterface.kt
+3
-3
compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt
...ta/resolve/diagnostics/cyclicConstructorDelegationCall.kt
+15
-15
compiler/fir/analysis-tests/testData/resolve/diagnostics/delegationSuperCallInEnumConstructor.kt
...solve/diagnostics/delegationSuperCallInEnumConstructor.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/diagnostics/explicitDelegationCallRequired.kt
...ata/resolve/diagnostics/explicitDelegationCallRequired.kt
+3
-3
compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.kt
...Data/resolve/diagnostics/instanceAccessBeforeSuperCall.kt
+2
-2
compiler/fir/analysis-tests/testData/resolve/diagnostics/localEntitytNotAllowed.kt
...ts/testData/resolve/diagnostics/localEntitytNotAllowed.kt
+4
-4
compiler/fir/analysis-tests/testData/resolve/diagnostics/manyCompanionObjects.kt
...ests/testData/resolve/diagnostics/manyCompanionObjects.kt
+6
-6
compiler/fir/analysis-tests/testData/resolve/diagnostics/sealedSupertype.kt
...sis-tests/testData/resolve/diagnostics/sealedSupertype.kt
+2
-2
compiler/fir/analysis-tests/testData/resolve/diagnostics/typeParametersInObject.kt
...ts/testData/resolve/diagnostics/typeParametersInObject.kt
+7
-7
compiler/fir/analysis-tests/testData/resolve/diagnostics/valOnAnnotationParameter.kt
.../testData/resolve/diagnostics/valOnAnnotationParameter.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/expresssions/localObjects.kt
...lysis-tests/testData/resolve/expresssions/localObjects.kt
+2
-2
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/ArrayEqualityCanBeReplacedWithEquals.kt
.../extendedCheckers/ArrayEqualityCanBeReplacedWithEquals.kt
+3
-3
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/CanBeValChecker.kt
...ests/testData/resolve/extendedCheckers/CanBeValChecker.kt
+11
-11
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantExplicitTypeChecker.kt
.../resolve/extendedCheckers/RedundantExplicitTypeChecker.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt
...olve/extendedCheckers/RedundantModalityModifierChecker.kt
+29
-29
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt
...ve/extendedCheckers/RedundantVisibilityModifierChecker.kt
+14
-14
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/BasicTest.kt
...Checkers/canBeReplacedWithOperatorAssignment/BasicTest.kt
+2
-2
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/multipleOperators.kt
.../canBeReplacedWithOperatorAssignment/multipleOperators.kt
+2
-2
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/multipleOperatorsRightSideRepeat.kt
...ithOperatorAssignment/multipleOperatorsRightSideRepeat.kt
+2
-2
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/nonCommutativeRepeat.kt
...nBeReplacedWithOperatorAssignment/nonCommutativeRepeat.kt
+3
-3
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/rightSideRepeat.kt
...rs/canBeReplacedWithOperatorAssignment/rightSideRepeat.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/simpleAssign.kt
...ckers/canBeReplacedWithOperatorAssignment/simpleAssign.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/validAddition.kt
...kers/canBeReplacedWithOperatorAssignment/validAddition.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/validSubtraction.kt
...s/canBeReplacedWithOperatorAssignment/validSubtraction.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/manyLocalVariables.kt
...ata/resolve/extendedCheckers/unused/manyLocalVariables.kt
+1
-1
compiler/fir/analysis-tests/testData/resolve/openInInterface.kt
...er/fir/analysis-tests/testData/resolve/openInInterface.kt
+3
-3
compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.kt
...martcasts/receivers/mixingImplicitAndExplicitReceivers.kt
+2
-2
compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/assignSafeCall.kt
...s/testData/resolve/smartcasts/safeCalls/assignSafeCall.kt
+4
-4
compiler/fir/analysis-tests/testData/resolve/typeAliasWithTypeArguments.kt
...ysis-tests/testData/resolve/typeAliasWithTypeArguments.kt
+2
-2
compiler/fir/analysis-tests/testData/resolve/whenElse.kt
compiler/fir/analysis-tests/testData/resolve/whenElse.kt
+4
-4
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt
...ir/analysis/diagnostics/LightTreePositioningStrategies.kt
+100
-45
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategy.kt
.../fir/analysis/diagnostics/LightTreePositioningStrategy.kt
+29
-11
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/SourceElementPositioningStrategy.kt
.../analysis/diagnostics/SourceElementPositioningStrategy.kt
+1
-1
compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirDiagnosticCodeMetaInfo.kt
...n/test/frontend/fir/handlers/FirDiagnosticCodeMetaInfo.kt
+4
-12
未找到文件。
compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationClassMember.kt
浏览文件 @
40bec303
annotation
class
A
()
{
<!
ANNOTATION_CLASS_MEMBER
!><!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
PSI
}!>
constructor
(
s
:
Nothing
?)<!><!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
LT
}!>
<!>
{}<!>
<!
ANNOTATION_CLASS_MEMBER
!><!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
!>
constructor
(
s
:
Nothing
?)
<!>
{}<!>
<!
ANNOTATION_CLASS_MEMBER
!>
init
{}<!>
<!
ANNOTATION_CLASS_MEMBER
!>
fun
foo
()
{}<!>
<!
ANNOTATION_CLASS_MEMBER
!>
val
bar
:
Nothing
?<!>
...
...
compiler/fir/analysis-tests/testData/resolve/diagnostics/conflictingOverloads.kt
浏览文件 @
40bec303
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}!>
fun
test
(
x
:
Int
)<!>
{}<!>
<!
CONFLICTING_OVERLOADS
!>
fun
test
(
x
:
Int
)<!>
{}
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}!>
fun
test
(
y
:
Int
)<!>
{}<!>
<!
CONFLICTING_OVERLOADS
!>
fun
test
(
y
:
Int
)<!>
{}
fun
test
()
{}
...
...
@@ -17,9 +17,9 @@ fun test(z: Int, c: Char) {}
}<!>
<!
REDECLARATION
!>
class
B
:
A
{
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}!>
override
fun
rest
(
s
:
String
)<!>
{}<!>
<!
CONFLICTING_OVERLOADS
!>
override
fun
rest
(
s
:
String
)<!>
{}
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}!>
fun
rest
(
s
:
String
)<!>
{}<!>
<!
CONFLICTING_OVERLOADS
!>
fun
rest
(
s
:
String
)<!>
{}
fun
rest
(
l
:
Long
)
{}
...
...
@@ -45,11 +45,11 @@ fun <T : Int> kek(t: T) {}
fun
lol
(
a
:
Array
<
Int
>)
{}
fun
lol
(
a
:
Array
<
Boolean
>)
{}
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}!>
fun
<
T
>
mem
(
t
:
T
)<!>
where
T
:
()
->
Boolean
,
T
:
String
{}<!>
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}!>
fun
<
T
>
mem
(
t
:
T
)<!>
where
T
:
String
,
T
:
()
->
Boolean
{}<!>
<!
CONFLICTING_OVERLOADS
!>
fun
<
T
>
mem
(
t
:
T
)<!>
where
T
:
()
->
Boolean
,
T
:
String
{}
<!
CONFLICTING_OVERLOADS
!>
fun
<
T
>
mem
(
t
:
T
)<!>
where
T
:
String
,
T
:
()
->
Boolean
{}
class
M
{
<!
REDECLARATION
{
LT
}!>
companion
<!
REDECLARATION
{
PSI
}!>
object
<!>
{}<!>
companion
<!
REDECLARATION
!>
object
<!>
{}
<!
REDECLARATION
!>
val
Companion
=
object
:
Any
{}<!>
}
...
...
compiler/fir/analysis-tests/testData/resolve/diagnostics/constructorInInterface.kt
浏览文件 @
40bec303
<!
CONSTRUCTOR_IN_INTERFACE
{
LT
}!>
interface
<!
CONSTRUCTOR_IN_INTERFACE
{
PSI
}!>
A
(
val
s
:
String
)<!>
<!>
interface
<!
CONSTRUCTOR_IN_INTERFACE
!>
A
(
val
s
:
String
)
<!>
<!
CONSTRUCTOR_IN_INTERFACE
{
LT
}!>
interface
<!
CONSTRUCTOR_IN_INTERFACE
{
PSI
}!>
B
constructor
(
val
s
:
String
)<!>
<!>
interface
<!
CONSTRUCTOR_IN_INTERFACE
!>
B
constructor
(
val
s
:
String
)
<!>
interface
C
{
<!
CONSTRUCTOR_IN_INTERFACE
{
LT
}!><!
CONSTRUCTOR_IN_INTERFACE
{
PSI
}!>
constructor
(
val
s
:
String
)<!>
{}<!>
<!
CONSTRUCTOR_IN_INTERFACE
!>
constructor
(
val
s
:
String
)<!>
{}
}
compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt
浏览文件 @
40bec303
...
...
@@ -2,14 +2,14 @@ class B
class
C
class
A
()
{
constructor
(
a
:
Int
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
LT
}!><!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
PSI
}!>
this
<!>(
"test"
)<!>
{}
constructor
(
a
:
String
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
LT
}!><!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
PSI
}!>
this
<!>(
10
)<!>
{}
constructor
(
a
:
Int
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
!>
this
<!>(
"test"
)
{}
constructor
(
a
:
String
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
!>
this
<!>(
10
)
{}
constructor
(
a
:
Boolean
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
LT
}!><!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
PSI
}!>
this
<!>(
'\n'
)<!>
{}
constructor
(
a
:
Char
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
LT
}!><!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
PSI
}!>
this
<!>(
0.0
)<!>
{}
constructor
(
a
:
Double
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
LT
}!><!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
PSI
}!>
this
<!>(
false
)<!>
{}
constructor
(
a
:
Boolean
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
!>
this
<!>(
'\n'
)
{}
constructor
(
a
:
Char
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
!>
this
<!>(
0.0
)
{}
constructor
(
a
:
Double
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
!>
this
<!>(
false
)
{}
constructor
(
b
:
B
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
LT
}!><!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
PSI
}!>
this
<!>(
3.14159265
)<!>
{}
constructor
(
b
:
B
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
!>
this
<!>(
3.14159265
)
{}
constructor
(
c
:
C
)
:
this
()
{}
constructor
(
a
:
List
<
Int
>)
:
this
(
C
())
{}
...
...
@@ -17,7 +17,7 @@ class A() {
class
D
{
constructor
(
i
:
Boolean
)
{}
constructor
(
i
:
Int
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
LT
}!><!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
PSI
}!>
this
<!>(
3
)<!>
{}
constructor
(
i
:
Int
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
!>
this
<!>(
3
)
{}
}
class
E
<
T
>
{
...
...
@@ -25,7 +25,7 @@ class E<T> {
// selection of the proper constructor
// but a type mismatch for the first
// argument
constructor
(
e
:
T
,
i
:
Int
)
:
<!
INAPPLICABLE_CANDIDATE
{
LT
}!><!
INAPPLICABLE_CANDIDATE
{
PSI
}!>
this
<!>(
i
,
10
)<!>
{}
constructor
(
e
:
T
,
i
:
Int
)
:
<!
INAPPLICABLE_CANDIDATE
!>
this
<!>(
i
,
10
)
{}
}
class
I
<
T
>
{
...
...
@@ -33,7 +33,7 @@ class I<T> {
// selection of the proper constructor
// but a type mismatch for the first
// argument
constructor
(
e
:
T
,
i
:
Int
)
:
<!
INAPPLICABLE_CANDIDATE
{
LT
}!><!
INAPPLICABLE_CANDIDATE
{
PSI
}!>
this
<!>(
i
,
10
)<!>
constructor
(
e
:
T
,
i
:
Int
)
:
<!
INAPPLICABLE_CANDIDATE
!>
this
<!>(
i
,
10
)
}
class
J
<
T
>
{
...
...
@@ -42,20 +42,20 @@ class J<T> {
}
class
F
(
s
:
String
)
{
<!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
PSI
}!>
constructor
(
i
:
Boolean
)<!><!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
LT
}!>
<!>
{}
constructor
(
i
:
Int
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
LT
}!><!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
PSI
}!>
this
<!>(
3
)<!>
{}
<!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
!>
constructor
(
i
:
Boolean
)
<!>
{}
constructor
(
i
:
Int
)
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
!>
this
<!>(
3
)
{}
}
class
G
(
x
:
Int
)
{
<!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
PSI
}!>
constructor
()<!><!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
LT
}!>
<!>
{}
<!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
!>
constructor
()
<!>
{}
}
class
H
(
x
:
Int
)
{
<!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
PSI
}!>
constructor
()<!><!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
LT
}!>
<!>
<!
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
!>
constructor
()
<!>
}
class
K
(
x
:
Int
)
{
constructor
()
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
LT
}!><!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
{
PSI
}!>
this
<!>()<!>
{}
constructor
()
:
<!
CYCLIC_CONSTRUCTOR_DELEGATION_CALL
!>
this
<!>()
{}
}
class
M
{
...
...
@@ -63,5 +63,5 @@ class M {
}
class
U
:
M
{
<!
INAPPLICABLE_CANDIDATE
{
PSI
}!>
constructor
()<!><!
INAPPLICABLE_CANDIDATE
{
LT
}!>
<!>
<!
INAPPLICABLE_CANDIDATE
!>
constructor
()
<!>
}
compiler/fir/analysis-tests/testData/resolve/diagnostics/delegationSuperCallInEnumConstructor.kt
浏览文件 @
40bec303
enum
class
A
{
A
(
1
),
B
(
2
),
C
(
"test"
);
constructor
(
x
:
Int
)
:
<!
DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR
{
LT
}!><!
DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR
{
PSI
}!>
super
<!>()<!>
constructor
(
x
:
Int
)
:
<!
DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR
!>
super
<!>()
constructor
(
t
:
String
)
:
this
(
10
)
}
compiler/fir/analysis-tests/testData/resolve/diagnostics/explicitDelegationCallRequired.kt
浏览文件 @
40bec303
...
...
@@ -3,16 +3,16 @@ class A(x: Int) {
}
class
B
:
A
{
<!
EXPLICIT_DELEGATION_CALL_REQUIRED
,
NONE_APPLICABLE
{
PSI
}!>
constructor
()<!><!
NONE_APPLICABLE
{
LT
}!>
<!>
<!
EXPLICIT_DELEGATION_CALL_REQUIRED
,
NONE_APPLICABLE
!>
constructor
()
<!>
constructor
(
z
:
String
)
:
this
()
}
<!
SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR
!>
class
C
:
A
(
20
)
{
<!
EXPLICIT_DELEGATION_CALL_REQUIRED
,
NONE_APPLICABLE
{
PSI
}!>
constructor
()<!><!
NONE_APPLICABLE
{
LT
}!>
<!>
<!
EXPLICIT_DELEGATION_CALL_REQUIRED
,
NONE_APPLICABLE
!>
constructor
()
<!>
constructor
(
z
:
String
)
:
this
()
}<!>
class
D
()
:
A
(
20
)
{
<!
NONE_APPLICABLE
{
PSI
},
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
PSI
}!>
constructor
(
x
:
Int
)<!><!
NONE_APPLICABLE
{
LT
},
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
{
LT
}!>
<!>
<!
NONE_APPLICABLE
,
PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
!>
constructor
(
x
:
Int
)
<!>
constructor
(
z
:
String
)
:
this
()
}
compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.kt
浏览文件 @
40bec303
...
...
@@ -7,10 +7,10 @@ class A {
class
B
(
other
:
B
=
<!
NO_THIS
!>
this
<!>)
class
C
()
{
constructor
(
x
:
Int
)
:
<!
INAPPLICABLE_CANDIDATE
{
LT
}!><!
INAPPLICABLE_CANDIDATE
{
PSI
}
!>
this
<!>({
constructor
(
x
:
Int
)
:
<!
INAPPLICABLE_CANDIDATE
!>
this
<!>({
val
a
=
10
<!
INSTANCE_ACCESS_BEFORE_SUPER_CALL
!>
this
<!>
})
<!>
{}
})
{}
}
class
D
{
...
...
compiler/fir/analysis-tests/testData/resolve/diagnostics/localEntitytNotAllowed.kt
浏览文件 @
40bec303
...
...
@@ -6,19 +6,19 @@ object A {
interface
X
val
a
=
object
:
Any
()
{
<!
LOCAL_OBJECT_NOT_ALLOWED
{
LT
}!><!
LOCAL_OBJECT_NOT_ALLOWED
{
PSI
}
!>
object
D
<!>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
D
<!>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
G
<!>
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
Z
<!>
}
<!>
}
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
Y
<!>
}
fun
b
()
{
<!
LOCAL_OBJECT_NOT_ALLOWED
{
LT
}!><!
LOCAL_OBJECT_NOT_ALLOWED
{
PSI
}
!>
object
E
<!>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
E
<!>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
F
<!>
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
M
<!>
}
<!>
}
<!
LOCAL_INTERFACE_NOT_ALLOWED
!>
interface
N
<!>
...
...
compiler/fir/analysis-tests/testData/resolve/diagnostics/manyCompanionObjects.kt
浏览文件 @
40bec303
class
A
{
<!
REDECLARATION
{
LT
}!>
companion
<!
REDECLARATION
{
PSI
}
!>
object
<!>
{
companion
<!
REDECLARATION
!>
object
<!>
{
}
<!>
}
<!
MANY_COMPANION_OBJECTS
{
LT
},
REDECLARATION
{
LT
}!>
companion
<!
MANY_COMPANION_OBJECTS
{
PSI
},
REDECLARATION
{
PSI
}
!>
object
<!>
{
companion
<!
MANY_COMPANION_OBJECTS
,
REDECLARATION
!>
object
<!>
{
}
<!>
}
}
class
B
{
...
...
@@ -13,7 +13,7 @@ class B {
}
<!
MANY_COMPANION_OBJECTS
{
LT
}!>
companion
<!
MANY_COMPANION_OBJECTS
{
PSI
}
!>
object
B
<!>
{
companion
<!
MANY_COMPANION_OBJECTS
!>
object
B
<!>
{
}
<!>
}
}
compiler/fir/analysis-tests/testData/resolve/diagnostics/sealedSupertype.kt
浏览文件 @
40bec303
...
...
@@ -28,9 +28,9 @@ sealed class P {
class
K
:
P
()
<!
REDECLARATION
{
LT
}!><!
REDECLARATION
{
PSI
}
!>
object
B
<!>
{
<!
REDECLARATION
!>
object
B
<!>
{
class
I
:
<!
SEALED_SUPERTYPE
!>
P
<
!
>()
}
<!>
}
fun
test
()
{
class
L
:
<!
SEALED_SUPERTYPE_IN_LOCAL_CLASS
!>
P
<
!
>()
...
...
compiler/fir/analysis-tests/testData/resolve/diagnostics/typeParametersInObject.kt
浏览文件 @
40bec303
<!
TYPE_PARAMETERS_IN_OBJECT
{
LT
}!><!
TYPE_PARAMETERS_IN_OBJECT
{
PSI
}
!>
object
A
<!><
T
,
K
:
T
>
{
<!
TYPE_PARAMETERS_IN_OBJECT
{
LT
}!><!
TYPE_PARAMETERS_IN_OBJECT
{
PSI
}!>
object
B
<!><
L
><!
>
}
<!>
<!
TYPE_PARAMETERS_IN_OBJECT
!>
object
A
<!><
T
,
K
:
T
>
{
<!
TYPE_PARAMETERS_IN_OBJECT
!>
object
B
<!><
L
>
}
class
N
{
<!
TYPE_PARAMETERS_IN_OBJECT
{
LT
}!>
companion
<!
TYPE_PARAMETERS_IN_OBJECT
{
PSI
}
!>
object
<!><
T
>
{
companion
<!
TYPE_PARAMETERS_IN_OBJECT
!>
object
<!><
T
>
{
}
<!>
}
}
fun
test
()
{
<!
LOCAL_OBJECT_NOT_ALLOWED
{
LT
},
TYPE_PARAMETERS_IN_OBJECT
{
LT
}!><!
LOCAL_OBJECT_NOT_ALLOWED
{
PSI
},
TYPE_PARAMETERS_IN_OBJECT
{
PSI
}
!>
object
M
<!><
H
>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
,
TYPE_PARAMETERS_IN_OBJECT
!>
object
M
<!><
H
>
{
}
<!>
}
}
compiler/fir/analysis-tests/testData/resolve/diagnostics/valOnAnnotationParameter.kt
浏览文件 @
40bec303
annotation
class
A
(
<!
VAR_ANNOTATION_PARAMETER
{
LT
}!><!
VAR_ANNOTATION_PARAMETER
{
PSI
}!>
var
<!>
a
:
Int
<
!
>
,
<!
VAR_ANNOTATION_PARAMETER
!>
var
<!>
a
:
Int
,
<!
MISSING_VAL_ON_ANNOTATION_PARAMETER
!>
b
:
String
<
!
>
)
compiler/fir/analysis-tests/testData/resolve/expresssions/localObjects.kt
浏览文件 @
40bec303
...
...
@@ -12,9 +12,9 @@ fun test() {
}
b
.
foo
()
<!
LOCAL_OBJECT_NOT_ALLOWED
{
LT
}!><!
LOCAL_OBJECT_NOT_ALLOWED
{
PSI
}
!>
object
B
<!>
{
<!
LOCAL_OBJECT_NOT_ALLOWED
!>
object
B
<!>
{
fun
foo
()
{}
}
<!>
}
B
.
foo
()
}
...
...
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/ArrayEqualityCanBeReplacedWithEquals.kt
浏览文件 @
40bec303
...
...
@@ -4,14 +4,14 @@ fun foo(p: Int) {
val
a
=
arrayOf
(
1
,
2
,
3
)
val
b
=
arrayOf
(
3
,
2
,
1
)
if
(
<!
ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
{
LT
}!>
a
<!
ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
{
PSI
}!>==<!>
b
<!>
)
{
}
if
(
a
<!
ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
!>==<!>
b
)
{
}
}
fun
testsFromIdea
()
{
val
a
=
arrayOf
(
"a"
)
val
b
=
a
val
c
:
Any
?
=
null
<!
ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
{
LT
}!>
a
<!
ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
{
PSI
}!>==<!>
b
<!>
a
<!
ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
!>==<!>
b
a
==
c
<!
ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
{
LT
}!>
a
<!
ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
{
PSI
}!>!=<!>
b
<!>
a
<!
ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
!>!=<!>
b
}
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/CanBeValChecker.kt
浏览文件 @
40bec303
...
...
@@ -23,7 +23,7 @@ operator fun C.plusAssign(a: Any) {}
fun
testOperatorAssignment
()
{
val
c
=
C
()
c
+=
""
<!
CAN_BE_VAL
{
LT
}!><!
CAN_BE_VAL
{
PSI
}!>
var
<!>
c1
=
C
()<!>
<!
CAN_BE_VAL
!>
var
<!>
c1
=
C
()
<!
ASSIGN_OPERATOR_AMBIGUITY
!>
c1
+=
""
<!>
var
a
=
1
...
...
@@ -33,7 +33,7 @@ fun testOperatorAssignment() {
fun
destructuringDeclaration
()
{
<!
CAN_BE_VAL
{
LT
}!><!
CAN_BE_VAL
{
PSI
}!>
var
<!>
(
v1
,
<!
UNUSED_VARIABLE
!>
v2
<!>)
=
getPair
()<!>
<!
CAN_BE_VAL
!>
var
<!>
(
v1
,
<!
UNUSED_VARIABLE
!>
v2
<!>)
=
getPair
()
print
(
v1
)
var
(
v3
,
<!
VARIABLE_NEVER_READ
!>
v4
<!>
)
=
getPair
()
...
...
@@ -49,11 +49,11 @@ fun destructuringDeclaration() {
val
(
<!
UNUSED_VARIABLE
!>
a
<!>
,
<!
UNUSED_VARIABLE
!>
b
<!>
,
<!
UNUSED_VARIABLE
!>
c
<!>
)
=
Triple
(
1
,
1
,
1
)
<!
CAN_BE_VAL
{
LT
}!><!
CAN_BE_VAL
{
PSI
}!>
var
<!>
(<!
UNUSED_VARIABLE
!>
x
<!>,
<!
UNUSED_VARIABLE
!>
y
<!>,
<!
UNUSED_VARIABLE
!>
z
<!>)
=
Triple
(
1
,
1
,
1
)<!>
<!
CAN_BE_VAL
!>
var
<!>
(<!
UNUSED_VARIABLE
!>
x
<!>,
<!
UNUSED_VARIABLE
!>
y
<!>,
<!
UNUSED_VARIABLE
!>
z
<!>)
=
Triple
(
1
,
1
,
1
)
}
fun
stackOverflowBug
()
{
<!
CAN_BE_VAL
{
LT
},
VARIABLE_NEVER_READ
{
LT
}!><!
CAN_BE_VAL
{
PSI
}
!>
var
<!>
<!
VARIABLE_NEVER_READ
{
PSI
}!>
a
<!>:
Int
<
!
>
<!
VARIABLE_NEVER_READ
{
LT
}!><!
CAN_BE_VAL
!>
var
<!>
<!
VARIABLE_NEVER_READ
{
PSI
}!>
a
<!>:
Int
<
!
>
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
a
<!>
=
1
for
(
i
in
1
..
10
)
print
(
i
)
...
...
@@ -71,8 +71,8 @@ fun smth(flag: Boolean) {
}
fun
withAnnotation
(
p
:
List
<
Any
>)
{
<!
CAN_BE_VAL
{
LT
}!>
@Suppress
(
"UNCHECKED_CAST"
)
<!
CAN_BE_VAL
{
PSI
}!>
var
<!>
v
=
p
as
List
<
String
><!
>
@Suppress
(
"UNCHECKED_CAST"
)
<!
CAN_BE_VAL
!>
var
<!>
v
=
p
as
List
<
String
>
print
(
v
)
}
...
...
@@ -88,7 +88,7 @@ fun listReceiver(p: List<String>) {}
fun
withInitializer
()
{
<!
VARIABLE_NEVER_READ
{
LT
}!>
var
<!
VARIABLE_NEVER_READ
{
PSI
}!>
v1
<!>
=
1
<!>
var
v2
=
2
<!
CAN_BE_VAL
{
LT
}!><!
CAN_BE_VAL
{
PSI
}!>
var
<!>
v3
=
3
<!>
<!
CAN_BE_VAL
!>
var
<!>
v3
=
3
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
v1
<!>
=
1
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
v2
<!>++
// todo mark this UNUSED_CHANGED_VALUES
print
(
v3
)
...
...
@@ -102,7 +102,7 @@ fun test() {
}
fun
foo
()
{
<!
CAN_BE_VAL
{
LT
},
VARIABLE_NEVER_READ
{
LT
}!><!
CAN_BE_VAL
{
PSI
}
!>
var
<!>
<!
VARIABLE_NEVER_READ
{
PSI
}!>
a
<!>:
Int
<
!
>
<!
VARIABLE_NEVER_READ
{
LT
}!><!
CAN_BE_VAL
!>
var
<!>
<!
VARIABLE_NEVER_READ
{
PSI
}!>
a
<!>:
Int
<
!
>
val
bool
=
true
if
(
bool
)
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
a
<!>
=
4
else
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
a
<!>
=
42
<!
UNUSED_VARIABLE
{
LT
}!>
val
<!
UNUSED_VARIABLE
{
PSI
}!>
b
<!>:
String
<
!
>
...
...
@@ -130,7 +130,7 @@ fun assignedTwice(p: Int) {
}
fun
main
(
args
:
Array
<
String
?
>)
{
<!
CAN_BE_VAL
{
LT
}!><!
CAN_BE_VAL
{
PSI
}!>
var
<!>
a
:
String
?<!>
<!
CAN_BE_VAL
!>
var
<!>
a
:
String
?
<!
UNUSED_VARIABLE
{
LT
}!>
val
<!
UNUSED_VARIABLE
{
PSI
}!>
unused
<!>
=
0
<!>
if
(
args
.
size
==
1
)
{
...
...
@@ -153,7 +153,7 @@ fun lambda() {
}
fun
lambdaInitialization
()
{
<!
CAN_BE_VAL
{
LT
},
VARIABLE_NEVER_READ
{
LT
}!><!
CAN_BE_VAL
{
PSI
}
!>
var
<!>
<!
VARIABLE_NEVER_READ
{
PSI
}!>
a
<!>:
Int
<
!
>
<!
VARIABLE_NEVER_READ
{
LT
}!><!
CAN_BE_VAL
!>
var
<!>
<!
VARIABLE_NEVER_READ
{
PSI
}!>
a
<!>:
Int
<
!
>
run
{
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
a
<!>
=
20
...
...
@@ -161,7 +161,7 @@ fun lambdaInitialization() {
}
fun
notAssignedWhenNotUsed
(
p
:
Int
)
{
<!
CAN_BE_VAL
{
LT
}!><!
CAN_BE_VAL
{
PSI
}!>
var
<!>
v
:
Int
<
!
>
<!
CAN_BE_VAL
!>
var
<!>
v
:
Int
if
(
p
>
0
)
{
v
=
1
print
(
v
)
...
...
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantExplicitTypeChecker.kt
浏览文件 @
40bec303
...
...
@@ -52,7 +52,7 @@ fun foo() {
<!
UNUSED_VARIABLE
{
LT
}!>
val
<!
UNUSED_VARIABLE
{
PSI
}!>
piFloat
<!>:
<!
REDUNDANT_EXPLICIT_TYPE
!>
Float
<
!
>
=
3.14f
<!>
<!
UNUSED_VARIABLE
{
LT
}!>
val
<!
UNUSED_VARIABLE
{
PSI
}!>
piDouble
<!>:
<!
REDUNDANT_EXPLICIT_TYPE
!>
Double
<
!
>
=
3.14
<!>
<!
UNUSED_VARIABLE
{
LT
}!>
val
<!
UNUSED_VARIABLE
{
PSI
}!>
charZ
<!>:
<!
REDUNDANT_EXPLICIT_TYPE
!>
Char
<
!
>
=
'z'
<!>
<!
CAN_BE_VAL
{
LT
},
UNUSED_VARIABLE
{
LT
}!><!
CAN_BE_VAL
{
PSI
}
!>
var
<!>
<!
UNUSED_VARIABLE
{
PSI
}!>
alpha
<!>:
<!
REDUNDANT_EXPLICIT_TYPE
!>
Int
<
!
>
=
0
<!>
<!
UNUSED_VARIABLE
{
LT
}!><!
CAN_BE_VAL
!>
var
<!>
<!
UNUSED_VARIABLE
{
PSI
}!>
alpha
<!>:
<!
REDUNDANT_EXPLICIT_TYPE
!>
Int
<
!
>
=
0
<!>
}
fun
test
(
boolean
:
Boolean
)
{
...
...
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt
浏览文件 @
40bec303
...
...
@@ -4,23 +4,23 @@ object O {
// Interface
interface
Interface
{
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Questionable cuz compiler reports warning here in FE 1.0
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}
!>
open
<!>
val
gav
:
Int
get
()
=
42
<!>
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Redundant
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
abstract
<!>
fun
foo
()<!>
<!
PRIVATE_FUNCTION_WITH_NO_BODY
{
LT
}!>
// error
<!
PRIVATE_FUNCTION_WITH_NO_BODY
{
PSI
}!>
private
<!>
final
fun
bar
()<!>
// Questionable cuz compiler reports warning here in FE 1.0
<!
REDUNDANT_MODALITY_MODIFIER
!>
open
<!>
val
gav
:
Int
get
()
=
42
// Redundant
<!
REDUNDANT_MODALITY_MODIFIER
!>
abstract
<!>
fun
foo
()
// error
<!
PRIVATE_FUNCTION_WITH_NO_BODY
!>
private
<!>
final
fun
bar
()
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!><!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
open
<!>
fun
goo
()
{}<!>
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!><!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
abstract
<!>
fun
tar
()<!>
<!
REDUNDANT_MODALITY_MODIFIER
!>
open
<!>
fun
goo
()
{}
<!
REDUNDANT_MODALITY_MODIFIER
!>
abstract
<!>
fun
tar
()
<!
ABSTRACT_FUNCTION_WITH_BODY
{
LT
}!>
// error
<!
ABSTRACT_FUNCTION_WITH_BODY
{
PSI
}!>
abstract
<!>
fun
too
()
{}<!>
// error
<!
ABSTRACT_FUNCTION_WITH_BODY
!>
abstract
<!>
fun
too
()
{}
}
interface
B
{
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!><!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
abstract
<!>
var
bar
:
Unit
<
!
>
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!><!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
abstract
<!>
fun
foo
()<!>
<!
REDUNDANT_MODALITY_MODIFIER
!>
abstract
<!>
var
bar
:
Unit
<!
REDUNDANT_MODALITY_MODIFIER
!>
abstract
<!>
fun
foo
()
}
interface
Foo
...
...
@@ -35,8 +35,8 @@ expect abstract class AbstractClass : Foo {
// Abstract
abstract
class
Base
{
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Redundant final
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
final
<!>
fun
foo
()
{}<!>
// Redundant final
<!
REDUNDANT_MODALITY_MODIFIER
!>
final
<!>
fun
foo
()
{}
// Abstract
abstract
fun
bar
()
// Open
...
...
@@ -44,8 +44,8 @@ abstract class Base {
}
class
FinalDerived
:
Base
()
{
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Redundant final
override
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
final
<!>
fun
bar
()
{}<!>
// Redundant final
override
<!
REDUNDANT_MODALITY_MODIFIER
!>
final
<!>
fun
bar
()
{}
// Non-final member in final class
override
open
val
gav
=
13
}
...
...
@@ -53,33 +53,33 @@ class FinalDerived : Base() {
open
class
OpenDerived
:
Base
()
{
// Final
override
final
fun
bar
()
{}
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Redundant open
override
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
open
<!>
val
gav
=
13
<!>
// Redundant open
override
<!
REDUNDANT_MODALITY_MODIFIER
!>
open
<!>
val
gav
=
13
}
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Redundant final
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
final
<!>
class
Final
<!>
// Redundant final
<!
REDUNDANT_MODALITY_MODIFIER
!>
final
<!>
class
Final
// Derived interface
interface
Derived
:
Interface
{
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Redundant
override
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
open
<!>
fun
foo
()
{}<!>
// Redundant
override
<!
REDUNDANT_MODALITY_MODIFIER
!>
open
<!>
fun
foo
()
{}
// error
final
class
Nested
}
// Derived abstract class
abstract
class
AbstractDerived1
(
override
final
val
gav
:
Int
)
:
Interface
{
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Redundant
override
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
open
<!>
fun
foo
()
{}<!>
// Redundant
override
<!
REDUNDANT_MODALITY_MODIFIER
!>
open
<!>
fun
foo
()
{}
}
// Derived abstract class
abstract
class
AbstractDerived2
:
Interface
{
// Final
override
final
fun
foo
()
{}
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Redundant
override
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
open
<!>
val
gav
=
13
<!>
// Redundant
override
<!
REDUNDANT_MODALITY_MODIFIER
!>
open
<!>
val
gav
=
13
}
// Redundant abstract interface
abstract
interface
AbstractInterface
<!
REDUNDANT_MODALITY_MODIFIER
{
LT
}!>
// Redundant final object
<!
REDUNDANT_MODALITY_MODIFIER
{
PSI
}!>
final
<!>
object
FinalObject
<!>
// Redundant final object
<!
REDUNDANT_MODALITY_MODIFIER
!>
final
<!>
object
FinalObject
// Open interface
open
interface
OpenInterface
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt
浏览文件 @
40bec303
fun
f
()
{
<!
CAN_BE_VAL
{
LT
},
REDUNDANT_VISIBILITY_MODIFIER
{
LT
},
UNUSED_VARIABLE
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}!>
public
<!>
<!
CAN_BE_VAL
{
PSI
}
!>
var
<!>
<!
UNUSED_VARIABLE
{
PSI
}!>
baz
<!>
=
0
<!>
<!
UNUSED_VARIABLE
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
!>
public
<!>
<!
CAN_BE_VAL
!>
var
<!>
<!
UNUSED_VARIABLE
{
PSI
}!>
baz
<!>
=
0
<!>
class
LocalClass
{
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}!>
internal
<!>
var
foo
=
0
<!>
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
internal
<!>
var
foo
=
0
}
LocalClass
().
foo
=
1
}
...
...
@@ -26,10 +26,10 @@ class Foo2<
internal
inner
class
B
<
T
,
T2
,>
}
<!
REDECLARATION
,
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}
!>
public
<!>
class
C
{
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}!>
public
<!>
val
foo
:
Int
=
0
<!>
<!
REDECLARATION
!><!
REDUNDANT_VISIBILITY_MODIFIER
!>
public
<!>
class
C
{
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
public
<!>
val
foo
:
Int
=
0
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}!>
public
<!>
fun
bar
()
{}<!>
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
public
<!>
fun
bar
()
{}
}<!>
...
...
@@ -42,19 +42,19 @@ open class D {
}
class
E
:
D
()
{
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}
!>
protected
<!>
override
fun
willRemainProtected
()
{
}
<!>
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
protected
<!>
override
fun
willRemainProtected
()
{
}
public
override
fun
willBecomePublic
()
{
}
}
enum
class
F
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}!>
private
<!>
constructor
(
val
x
:
Int
)<!>
{
enum
class
F
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
private
<!>
constructor
(
val
x
:
Int
)
{
FIRST
(
42
)
}
sealed
class
G
constructor
(
val
y
:
Int
)
{
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}!>
private
<!>
constructor
():
this
(
42
)<!>
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
private
<!>
constructor
():
this
(
42
)
object
H
:
G
()
}
...
...
@@ -63,16 +63,16 @@ interface I {
fun
bar
()
}
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}!>
public
<!>
var
baz
=
0
<!>
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
public
<!>
var
baz
=
0
open
class
J
{
protected
val
baz
=
0
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}!>
protected
<!>
get
()
=
field
*
2
<!>
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
protected
<!>
get
()
=
field
*
2
var
baf
=
0
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}!>
public
<!>
get
()
=
1
<!>
<!
REDUNDANT_VISIBILITY_MODIFIER
{
LT
}!><!
REDUNDANT_VISIBILITY_MODIFIER
{
PSI
}
!>
public
<!>
set
(
value
)
{
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
public
<!>
get
()
=
1
<!
REDUNDANT_VISIBILITY_MODIFIER
!>
public
<!>
set
(
value
)
{
field
=
value
}
<!>
}
var
buf
=
0
private
get
()
=
42
...
...
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/BasicTest.kt
浏览文件 @
40bec303
fun
goo
()
{
var
a
=
2
val
b
=
4
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!>
a
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
a
+
1
+
b
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!>
a
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
(
a
+
1
)<!>
a
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
a
+
1
+
b
a
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
(
a
+
1
)
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
a
<!>
=
a
*
b
+
1
}
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/multipleOperators.kt
浏览文件 @
40bec303
fun
foo
()
{
var
x
=
0
<!
CAN_BE_VAL
{
LT
}!><!
CAN_BE_VAL
{
PSI
}!>
var
<!>
y
=
0
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!><!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
x
+
y
+
5
<!>
<!
CAN_BE_VAL
!>
var
<!>
y
=
0
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
x
+
y
+
5
}
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/multipleOperatorsRightSideRepeat.kt
浏览文件 @
40bec303
fun
foo
()
{
var
x
=
0
<!
CAN_BE_VAL
{
LT
}!><!
CAN_BE_VAL
{
PSI
}!>
var
<!>
y
=
0
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!><!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
y
+
x
+
5
<!>
<!
CAN_BE_VAL
!>
var
<!>
y
=
0
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
y
+
x
+
5
}
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/nonCommutativeRepeat.kt
浏览文件 @
40bec303
fun
foo
()
{
var
x
=
0
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!>
x
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
x
-
1
-
1
<!>
x
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
x
-
1
-
1
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!>
x
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
x
/
1
<!>
x
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
x
/
1
x
=
1
/
x
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!><!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
-
1
+
x
<!>
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
-
1
+
x
}
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/rightSideRepeat.kt
浏览文件 @
40bec303
fun
foo
()
{
var
x
=
0
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!><!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
1
+
x
<!>
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
1
+
x
}
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/simpleAssign.kt
浏览文件 @
40bec303
fun
foo
()
{
var
y
=
0
val
x
=
0
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!><!
ASSIGNED_VALUE_IS_NEVER_READ
!>
y
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
y
+
x
<!>
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
y
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
y
+
x
}
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/validAddition.kt
浏览文件 @
40bec303
fun
foo
()
{
var
x
=
0
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!><!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
x
+
1
<!>
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
x
+
1
}
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment/validSubtraction.kt
浏览文件 @
40bec303
fun
foo
()
{
var
x
=
0
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
LT
}!><!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
{
PSI
}!>=<!>
x
-
1
<!>
<!
ASSIGNED_VALUE_IS_NEVER_READ
!>
x
<!>
<!
CAN_BE_REPLACED_WITH_OPERATOR_ASSIGNMENT
!>=<!>
x
-
1
}
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/manyLocalVariables.kt
浏览文件 @
40bec303
fun
foo
()
{
<!
CAN_BE_VAL
{
LT
}!><!
CAN_BE_VAL
{
PSI
}!>
var
<!>
a
=
1
<!>
<!
CAN_BE_VAL
!>
var
<!>
a
=
1
var
b
=
<!
VARIABLE_INITIALIZER_IS_REDUNDANT
!>
2
<!>
var
c
=
3
...
...
compiler/fir/analysis-tests/testData/resolve/openInInterface.kt
浏览文件 @
40bec303
interface
Some
{
<!
REDUNDANT_OPEN_IN_INTERFACE
{
LT
}!><!
REDUNDANT_OPEN_IN_INTERFACE
{
PSI
}!>
open
<!>
fun
foo
()<!>
<!
REDUNDANT_OPEN_IN_INTERFACE
!>
open
<!>
fun
foo
()
open
fun
bar
()
{}
<!
REDUNDANT_OPEN_IN_INTERFACE
{
LT
}!><!
REDUNDANT_OPEN_IN_INTERFACE
{
PSI
}!>
open
<!>
val
x
:
Int
<
!
>
<!
REDUNDANT_OPEN_IN_INTERFACE
!>
open
<!>
val
x
:
Int
open
val
y
=
<!
PROPERTY_INITIALIZER_IN_INTERFACE
!>
1
<!>
open
val
z
get
()
=
1
<!
REDUNDANT_OPEN_IN_INTERFACE
{
LT
}!><!
REDUNDANT_OPEN_IN_INTERFACE
{
PSI
}!>
open
<!>
var
xx
:
Int
<
!
>
<!
REDUNDANT_OPEN_IN_INTERFACE
!>
open
<!>
var
xx
:
Int
open
var
yy
=
<!
PROPERTY_INITIALIZER_IN_INTERFACE
!>
1
<!>
open
var
zz
:
Int
set
(
value
)
{
...
...
compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.kt
浏览文件 @
40bec303
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}!>
fun
takeString
(
s
:
String
)<!>
{}<!>
<!
CONFLICTING_OVERLOADS
!>
fun
takeString
(
s
:
String
)<!>
{}
class
Wrapper
(
val
s
:
String
?)
{
fun
withThis
()
{
...
...
@@ -11,4 +11,4 @@ class Wrapper(val s: String?) {
}
}
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}!>
fun
takeString
(
s
:
String
)<!>
{}<!>
<!
CONFLICTING_OVERLOADS
!>
fun
takeString
(
s
:
String
)<!>
{}
compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/assignSafeCall.kt
浏览文件 @
40bec303
...
...
@@ -23,11 +23,11 @@ fun test_2(a: A?) {
}
}
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}
!>
fun
test_3
(
x
:
Any
?)<!>
{
<!
CONFLICTING_OVERLOADS
!>
fun
test_3
(
x
:
Any
?)<!>
{
val
a
=
x
as
?
A
?:
return
a
.
foo
()
// Should be OK
x
.
foo
()
// Should be OK
}
<!>
}
// ----------------- Unstable -----------------
...
...
@@ -53,8 +53,8 @@ fun test_2(a: B?) {
}
}
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}
!>
fun
test_3
(
x
:
Any
?)<!>
{
<!
CONFLICTING_OVERLOADS
!>
fun
test_3
(
x
:
Any
?)<!>
{
val
a
=
x
as
?
B
?:
return
a
.
foo
()
// Should be OK
x
.
foo
()
// Should be OK
}
<!>
}
compiler/fir/analysis-tests/testData/resolve/typeAliasWithTypeArguments.kt
浏览文件 @
40bec303
...
...
@@ -10,10 +10,10 @@ interface C {
fun
baz
()
}
<!
CONSTRUCTOR_IN_INTERFACE
{
LT
}!>
interface
<!
CONSTRUCTOR_IN_INTERFACE
{
PSI
}
!>
Inv
<
K
,
T
>()<!>
{
interface
<!
CONSTRUCTOR_IN_INTERFACE
!>
Inv
<
K
,
T
>()<!>
{
fun
k
():
K
fun
t
():
T
}
<!>
}
typealias
Inv0
=
Inv
<
A
,
B
>
typealias
Inv1
<
X
>
=
Inv
<
A
,
X
>
...
...
compiler/fir/analysis-tests/testData/resolve/whenElse.kt
浏览文件 @
40bec303
...
...
@@ -13,7 +13,7 @@ class B()
class
C
(
val
b
:
B
)
fun
get
(
f
:
Boolean
)
=
if
(
f
)
{
A
.
A1
}
else
{
""
}
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}
!>
fun
case2
()<!>
{
<!
CONFLICTING_OVERLOADS
!>
fun
case2
()<!>
{
val
flag
:
Any
=
get
(
false
)
//string
val
l1
=
when
(
flag
!!
)
{
// should be NO_ELSE_IN_WHEN
...
...
@@ -25,9 +25,9 @@ fun get(f: Boolean) = if (f) {A.A1} else {""}
A
.
A1
->
B
()
A
.
A2
->
B
()
}
}
<!>
}
<!
CONFLICTING_OVERLOADS
{
LT
}!><!
CONFLICTING_OVERLOADS
{
PSI
}
!>
fun
case2
()<!>
{
<!
CONFLICTING_OVERLOADS
!>
fun
case2
()<!>
{
val
flag
:
Any
=
get
(
true
)
//A
val
l1
=
when
(
flag
!!
)
{
// should be NO_ELSE_IN_WHEN
...
...
@@ -39,7 +39,7 @@ fun get(f: Boolean) = if (f) {A.A1} else {""}
A
.
A1
->
B
()
A
.
A2
->
B
()
}
}
<!>
}
fun
case3
()
{
...
...
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt
浏览文件 @
40bec303
...
...
@@ -20,39 +20,56 @@ import org.jetbrains.kotlin.psi.KtParameter.VAL_VAR_TOKEN_SET
object
LightTreePositioningStrategies
{
val
DEFAULT
=
object
:
LightTreePositioningStrategy
()
{
override
fun
mark
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
{
override
fun
mark
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
{
when
(
node
.
tokenType
)
{
KtNodeTypes
.
OBJECT_DECLARATION
->
{
val
objectKeyword
=
tree
.
objectKeyword
(
node
)
!!
return
markRange
(
from
=
objectKeyword
,
to
=
tree
.
nameIdentifier
(
node
)
?:
objectKeyword
,
tre
e
startOffset
,
endOffset
,
tree
,
nod
e
)
}
KtNodeTypes
.
CONSTRUCTOR_DELEGATION_CALL
->
{
return
SECONDARY_CONSTRUCTOR_DELEGATION_CALL
.
mark
(
node
,
tree
)
return
SECONDARY_CONSTRUCTOR_DELEGATION_CALL
.
mark
(
node
,
startOffset
,
endOffset
,
tree
)
}
}
return
super
.
mark
(
node
,
tree
)
return
super
.
mark
(
node
,
startOffset
,
endOffset
,
tree
)
}
}
val
VAL_OR_VAR_NODE
:
LightTreePositioningStrategy
=
object
:
LightTreePositioningStrategy
()
{
override
fun
mark
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
{
override
fun
mark
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
{
val
target
=
tree
.
valOrVarKeyword
(
node
)
?:
node
return
markElement
(
target
,
tre
e
)
return
markElement
(
target
,
startOffset
,
endOffset
,
tree
,
nod
e
)
}
}
val
SECONDARY_CONSTRUCTOR_DELEGATION_CALL
:
LightTreePositioningStrategy
=
object
:
LightTreePositioningStrategy
()
{
override
fun
mark
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
{
override
fun
mark
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
{
when
(
node
.
tokenType
)
{
KtNodeTypes
.
SECONDARY_CONSTRUCTOR
->
{
val
valueParameterList
=
tree
.
valueParameterList
(
node
)
?:
return
markElement
(
node
,
tree
)
val
valueParameterList
=
tree
.
valueParameterList
(
node
)
?:
return
markElement
(
node
,
startOffset
,
endOffset
,
tree
)
return
markRange
(
tree
.
constructorKeyword
(
node
)
!!
,
tree
.
lastChild
(
valueParameterList
)
!!
,
tree
tree
.
lastChild
(
valueParameterList
)
?:
valueParameterList
,
startOffset
,
endOffset
,
tree
,
node
)
}
KtNodeTypes
.
CONSTRUCTOR_DELEGATION_CALL
->
{
...
...
@@ -60,13 +77,14 @@ object LightTreePositioningStrategies {
if
(
delegationReference
!=
null
&&
tree
.
firstChild
(
delegationReference
)
==
null
)
{
val
constructor
=
tree
.
findParentOfType
(
node
,
KtNodeTypes
.
SECONDARY_CONSTRUCTOR
)
!!
val
valueParameterList
=
tree
.
valueParameterList
(
constructor
)
?:
return
markElement
(
constructor
,
tre
e
)
?:
return
markElement
(
constructor
,
startOffset
,
endOffset
,
tree
,
nod
e
)
return
markRange
(
tree
.
constructorKeyword
(
constructor
)
!!
,
tree
.
lastChild
(
valueParameterList
)
!!
,
tree
tree
.
lastChild
(
valueParameterList
)
?:
valueParameterList
,
startOffset
,
endOffset
,
tree
,
node
)
}
return
markElement
(
delegationReference
?:
node
,
tre
e
)
return
markElement
(
delegationReference
?:
node
,
startOffset
,
endOffset
,
tree
,
nod
e
)
}
else
->
error
(
"unexpected element $node"
)
}
...
...
@@ -74,7 +92,12 @@ object LightTreePositioningStrategies {
}
val
DECLARATION_NAME
:
LightTreePositioningStrategy
=
object
:
LightTreePositioningStrategy
()
{
override
fun
mark
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
{
override
fun
mark
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
{
val
nameIdentifier
=
tree
.
nameIdentifier
(
node
)
if
(
nameIdentifier
!=
null
)
{
if
(
node
.
tokenType
==
KtNodeTypes
.
CLASS
||
node
.
tokenType
==
KtNodeTypes
.
OBJECT_DECLARATION
)
{
...
...
@@ -83,24 +106,31 @@ object LightTreePositioningStrategies {
?:
tree
.
findChildByType
(
node
,
TokenSet
.
create
(
KtTokens
.
CLASS_KEYWORD
,
KtTokens
.
OBJECT_KEYWORD
))
?:
node
return
markRange
(
startElement
,
nameIdentifier
,
tre
e
)
return
markRange
(
startElement
,
nameIdentifier
,
startOffset
,
endOffset
,
tree
,
nod
e
)
}
return
markElement
(
n
ameIdentifier
,
tree
)
return
markElement
(
n
ode
,
startOffset
,
endOffset
,
tree
)
}
if
(
node
.
tokenType
==
KtNodeTypes
.
FUN
)
{
return
DECLARATION_SIGNATURE
.
mark
(
node
,
tree
)
return
DECLARATION_SIGNATURE
.
mark
(
node
,
startOffset
,
endOffset
,
tree
)
}
return
DEFAULT
.
mark
(
node
,
tree
)
return
DEFAULT
.
mark
(
node
,
startOffset
,
endOffset
,
tree
)
}
}
val
DECLARATION_SIGNATURE
:
LightTreePositioningStrategy
=
object
:
LightTreePositioningStrategy
()
{
override
fun
mark
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
{
override
fun
mark
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
{
when
(
node
.
tokenType
)
{
KtNodeTypes
.
PRIMARY_CONSTRUCTOR
,
KtNodeTypes
.
SECONDARY_CONSTRUCTOR
->
{
val
begin
=
tree
.
constructorKeyword
(
node
)
?:
tree
.
valueParameterList
(
node
)
?:
return
markElement
(
node
,
tree
)
val
end
=
tree
.
valueParameterList
(
node
)
?:
tree
.
constructorKeyword
(
node
)
?:
return
markElement
(
node
,
tree
)
return
markRange
(
begin
,
end
,
tree
)
val
begin
=
tree
.
constructorKeyword
(
node
)
?:
tree
.
valueParameterList
(
node
)
?:
return
markElement
(
node
,
startOffset
,
endOffset
,
tree
)
val
end
=
tree
.
valueParameterList
(
node
)
?:
tree
.
constructorKeyword
(
node
)
?:
return
markElement
(
node
,
startOffset
,
endOffset
,
tree
)
return
markRange
(
begin
,
end
,
startOffset
,
endOffset
,
tree
,
node
)
}
KtNodeTypes
.
FUN
,
KtNodeTypes
.
FUNCTION_LITERAL
->
{
val
endOfSignatureElement
=
...
...
@@ -113,11 +143,11 @@ object LightTreePositioningStrategies {
?:
tree
.
valueParameterList
(
node
)
?:
node
}
else
node
return
markRange
(
startElement
,
endOfSignatureElement
,
tre
e
)
return
markRange
(
startElement
,
endOfSignatureElement
,
startOffset
,
endOffset
,
tree
,
nod
e
)
}
KtNodeTypes
.
PROPERTY
->
{
val
endOfSignatureElement
=
tree
.
typeReference
(
node
)
?:
tree
.
nameIdentifier
(
node
)
?:
node
return
markRange
(
node
,
endOfSignatureElement
,
tre
e
)
return
markRange
(
node
,
endOfSignatureElement
,
startOffset
,
endOffset
,
tree
,
nod
e
)
}
KtNodeTypes
.
PROPERTY_ACCESSOR
->
{
val
endOfSignatureElement
=
...
...
@@ -125,32 +155,38 @@ object LightTreePositioningStrategies {
?:
tree
.
rightParenthesis
(
node
)
?:
tree
.
accessorNamePlaceholder
(
node
)
return
markRange
(
node
,
endOfSignatureElement
,
tre
e
)
return
markRange
(
node
,
endOfSignatureElement
,
startOffset
,
endOffset
,
tree
,
nod
e
)
}
KtNodeTypes
.
CLASS
->
{
val
nameAsDeclaration
=
tree
.
nameIdentifier
(
node
)
?:
return
markElement
(
node
,
tree
)
val
nameAsDeclaration
=
tree
.
nameIdentifier
(
node
)
?:
return
markElement
(
node
,
startOffset
,
endOffset
,
tree
)
val
primaryConstructorParameterList
=
tree
.
primaryConstructor
(
node
)
?.
let
{
constructor
->
tree
.
valueParameterList
(
constructor
)
}
?:
return
markElement
(
nameAsDeclaration
,
tre
e
)
return
markRange
(
nameAsDeclaration
,
primaryConstructorParameterList
,
tre
e
)
}
?:
return
markElement
(
nameAsDeclaration
,
startOffset
,
endOffset
,
tree
,
nod
e
)
return
markRange
(
nameAsDeclaration
,
primaryConstructorParameterList
,
startOffset
,
endOffset
,
tree
,
nod
e
)
}
KtNodeTypes
.
OBJECT_DECLARATION
->
{
return
DECLARATION_NAME
.
mark
(
node
,
tree
)
return
DECLARATION_NAME
.
mark
(
node
,
startOffset
,
endOffset
,
tree
)
}
KtNodeTypes
.
CLASS_INITIALIZER
->
{
return
markElement
(
tree
.
initKeyword
(
node
)
!!
,
tre
e
)
return
markElement
(
tree
.
initKeyword
(
node
)
!!
,
startOffset
,
endOffset
,
tree
,
nod
e
)
}
}
return
super
.
mark
(
node
,
tree
)
return
super
.
mark
(
node
,
startOffset
,
endOffset
,
tree
)
}
}
val
DECLARATION_SIGNATURE_OR_DEFAULT
:
LightTreePositioningStrategy
=
object
:
LightTreePositioningStrategy
()
{
override
fun
mark
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
=
override
fun
mark
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
=
if
(
node
.
isDeclaration
)
{
DECLARATION_SIGNATURE
.
mark
(
node
,
tree
)
DECLARATION_SIGNATURE
.
mark
(
node
,
startOffset
,
endOffset
,
tree
)
}
else
{
DEFAULT
.
mark
(
node
,
tree
)
DEFAULT
.
mark
(
node
,
startOffset
,
endOffset
,
tree
)
}
private
val
LighterASTNode
.
isDeclaration
:
Boolean
...
...
@@ -170,17 +206,29 @@ object LightTreePositioningStrategies {
}
private
class
ModifierSetBasedLightTreePositioningStrategy
(
private
val
modifierSet
:
TokenSet
)
:
LightTreePositioningStrategy
()
{
override
fun
mark
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
{
tree
.
findChildByType
(
node
,
modifierSet
)
?.
let
{
return
markElement
(
it
,
tree
)
}
tree
.
nameIdentifier
(
node
)
?.
let
{
return
markElement
(
it
,
tree
)
}
override
fun
mark
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
{
val
modifierList
=
tree
.
modifierList
(
node
)
if
(
modifierList
!=
null
)
{
tree
.
findChildByType
(
modifierList
,
modifierSet
)
?.
let
{
return
markElement
(
it
,
startOffset
,
endOffset
,
tree
,
node
)
}
}
tree
.
nameIdentifier
(
node
)
?.
let
{
return
markElement
(
it
,
startOffset
,
endOffset
,
tree
,
node
)
}
return
when
(
node
.
tokenType
)
{
KtNodeTypes
.
OBJECT_DECLARATION
->
{
markElement
(
tree
.
objectKeyword
(
node
)
!!
,
tre
e
)
markElement
(
tree
.
objectKeyword
(
node
)
!!
,
startOffset
,
endOffset
,
tree
,
nod
e
)
}
KtNodeTypes
.
PROPERTY_ACCESSOR
->
{
markElement
(
tree
.
accessorNamePlaceholder
(
node
),
tre
e
)
markElement
(
tree
.
accessorNamePlaceholder
(
node
),
startOffset
,
endOffset
,
tree
,
nod
e
)
}
else
->
markElement
(
node
,
tree
)
else
->
markElement
(
node
,
startOffset
,
endOffset
,
tree
)
}
}
}
...
...
@@ -190,8 +238,13 @@ object LightTreePositioningStrategies {
val
MODALITY_MODIFIER
:
LightTreePositioningStrategy
=
ModifierSetBasedLightTreePositioningStrategy
(
MODALITY_MODIFIERS
)
val
OPERATOR
:
LightTreePositioningStrategy
=
object
:
LightTreePositioningStrategy
()
{
override
fun
mark
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
{
return
markElement
(
tree
.
operationReference
(
node
)
?:
node
,
tree
)
override
fun
mark
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
{
return
markElement
(
tree
.
operationReference
(
node
)
?:
node
,
startOffset
,
endOffset
,
tree
,
node
)
}
}
}
...
...
@@ -248,15 +301,17 @@ private fun FlyweightCapableTreeStructure<LighterASTNode>.valueParameterList(nod
findChildByType
(
node
,
KtNodeTypes
.
VALUE_PARAMETER_LIST
)
private
fun
FlyweightCapableTreeStructure
<
LighterASTNode
>.
typeReference
(
node
:
LighterASTNode
):
LighterASTNode
?
{
val
childrenRef
=
Ref
<
Array
<
LighterASTNode
>>()
val
childrenRef
=
Ref
<
Array
<
LighterASTNode
?
>>()
getChildren
(
node
,
childrenRef
)
return
childrenRef
.
get
()
?.
dropWhile
{
it
.
tokenType
!=
KtTokens
.
COLON
}
?.
firstOrNull
{
it
.
tokenType
==
KtNodeTypes
.
TYPE_REFERENCE
}
return
childrenRef
.
get
()
?.
filterNotNull
()
?.
dropWhile
{
it
.
tokenType
!=
KtTokens
.
COLON
}
?.
firstOrNull
{
it
.
tokenType
==
KtNodeTypes
.
TYPE_REFERENCE
}
}
private
fun
FlyweightCapableTreeStructure
<
LighterASTNode
>.
receiverTypeReference
(
node
:
LighterASTNode
):
LighterASTNode
?
{
val
childrenRef
=
Ref
<
Array
<
LighterASTNode
>>()
val
childrenRef
=
Ref
<
Array
<
LighterASTNode
?
>>()
getChildren
(
node
,
childrenRef
)
return
childrenRef
.
get
()
?.
firstOrNull
{
return
childrenRef
.
get
()
?.
fi
lterNotNull
()
?.
fi
rstOrNull
{
if
(
it
.
tokenType
==
KtTokens
.
COLON
||
it
.
tokenType
==
KtTokens
.
LPAR
)
return
null
it
.
tokenType
==
KtNodeTypes
.
TYPE_REFERENCE
}
...
...
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategy.kt
浏览文件 @
40bec303
...
...
@@ -15,13 +15,13 @@ import org.jetbrains.kotlin.lexer.KtTokens
import
org.jetbrains.kotlin.lexer.KtTokens.WHITE_SPACE
open
class
LightTreePositioningStrategy
{
open
fun
mark
Diagnostic
(
diagnostic
:
FirDiagnostic
<
*
>):
List
<
TextRange
>
{
val
element
=
diagnostic
.
element
return
mark
(
element
.
lighterASTNode
,
element
.
treeStructure
)
}
open
fun
mark
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
{
return
markElement
(
node
,
tree
)
open
fun
mark
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>
):
List
<
TextRange
>
{
return
markElement
(
node
,
startOffset
,
endOffset
,
tree
)
}
open
fun
isValid
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
Boolean
{
...
...
@@ -29,12 +29,30 @@ open class LightTreePositioningStrategy {
}
}
fun
markElement
(
node
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
{
return
listOf
(
TextRange
(
tree
.
getStartOffset
(
node
),
tree
.
getEndOffset
(
node
)))
fun
markElement
(
node
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>,
originalNode
:
LighterASTNode
=
node
,
):
List
<
TextRange
>
{
if
(
node
===
originalNode
)
return
listOf
(
TextRange
(
startOffset
,
endOffset
))
val
startDelta
=
tree
.
getStartOffset
(
node
)
-
tree
.
getStartOffset
(
originalNode
)
val
endDelta
=
tree
.
getEndOffset
(
node
)
-
tree
.
getEndOffset
(
originalNode
)
return
listOf
(
TextRange
(
startDelta
+
startOffset
,
endDelta
+
endOffset
))
}
fun
markRange
(
from
:
LighterASTNode
,
to
:
LighterASTNode
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>):
List
<
TextRange
>
{
return
listOf
(
TextRange
(
tree
.
getStartOffset
(
from
),
tree
.
getEndOffset
(
to
)))
fun
markRange
(
from
:
LighterASTNode
,
to
:
LighterASTNode
,
startOffset
:
Int
,
endOffset
:
Int
,
tree
:
FlyweightCapableTreeStructure
<
LighterASTNode
>,
originalNode
:
LighterASTNode
):
List
<
TextRange
>
{
val
startDelta
=
tree
.
getStartOffset
(
from
)
-
tree
.
getStartOffset
(
originalNode
)
val
endDelta
=
tree
.
getEndOffset
(
to
)
-
tree
.
getEndOffset
(
originalNode
)
return
listOf
(
TextRange
(
startDelta
+
startOffset
,
endDelta
+
endOffset
))
}
private
val
DOC_AND_COMMENT_TOKENS
=
setOf
(
...
...
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/SourceElementPositioningStrategy.kt
浏览文件 @
40bec303
...
...
@@ -21,7 +21,7 @@ open class SourceElementPositioningStrategy<in E : PsiElement>(
@Suppress
(
"UNCHECKED_CAST"
)
return
psiStrategy
.
mark
(
element
.
psi
as
E
)
}
return
lightTreeStrategy
.
mark
(
element
.
lighterASTNode
,
element
.
treeStructure
)
return
lightTreeStrategy
.
mark
(
element
.
lighterASTNode
,
element
.
startOffset
,
element
.
endOffset
,
element
.
treeStructure
)
}
fun
isValid
(
element
:
FirSourceElement
):
Boolean
{
...
...
compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirDiagnosticCodeMetaInfo.kt
浏览文件 @
40bec303
...
...
@@ -6,14 +6,11 @@
package
org.jetbrains.kotlin.test.frontend.fir.handlers
import
com.intellij.openapi.util.TextRange
import
com.intellij.psi.PsiElement
import
org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import
org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.AbstractCodeMetaInfoRenderConfiguration
import
org.jetbrains.kotlin.diagnostics.PositioningStrategy
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirDefaultErrorMessages
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderer
import
org.jetbrains.kotlin.fir.psi
object
FirMetaInfoUtils
{
val
renderDiagnosticNoArgs
=
FirDiagnosticCodeMetaRenderConfiguration
().
apply
{
renderParams
=
false
}
...
...
@@ -24,23 +21,18 @@ class FirDiagnosticCodeMetaInfo(
val
diagnostic
:
FirDiagnostic
<
*
>,
renderConfiguration
:
FirDiagnosticCodeMetaRenderConfiguration
)
:
CodeMetaInfo
{
// TODO: this implementation is hacky and doesn't support proper ranges for light tree diagnostics
private
val
textRangeFromClassicDiagnostic
:
TextRange
?
=
run
{
val
psi
=
diagnostic
.
element
.
psi
?:
return
@run
null
@Suppress
(
"UNCHECKED_CAST"
)
val
positioningStrategy
=
diagnostic
.
factory
.
positioningStrategy
.
psiStrategy
as
PositioningStrategy
<
PsiElement
>
positioningStrategy
.
mark
(
psi
).
first
()
private
val
textRangeFromClassicDiagnostic
:
TextRange
=
run
{
diagnostic
.
factory
.
positioningStrategy
.
markDiagnostic
(
diagnostic
).
first
()
}
override
var
renderConfiguration
:
FirDiagnosticCodeMetaRenderConfiguration
=
renderConfiguration
private
set
override
val
start
:
Int
get
()
=
textRangeFromClassicDiagnostic
?.
startOffset
?:
diagnostic
.
element
.
startOffset
get
()
=
textRangeFromClassicDiagnostic
.
startOffset
override
val
end
:
Int
get
()
=
textRangeFromClassicDiagnostic
?.
endOffset
?:
diagnostic
.
element
.
endOffset
get
()
=
textRangeFromClassicDiagnostic
.
endOffset
override
val
tag
:
String
get
()
=
renderConfiguration
.
getTag
(
this
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录