Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
ebced14d
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,发现更多精彩内容 >>
提交
ebced14d
编写于
2月 01, 2021
作者:
D
Dmitriy Novozhilov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIR] Implement suppressing diagnostics with @Suppress
上级
459a2886
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
376 addition
and
43 deletion
+376
-43
compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java
...r/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java
+33
-0
compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.fir.txt
...lysis-tests/testData/resolve/suppress/allWarnings.fir.txt
+10
-0
compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.kt
...r/analysis-tests/testData/resolve/suppress/allWarnings.kt
+6
-0
compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.fir.txt
...-tests/testData/resolve/suppress/multipleWarnings.fir.txt
+10
-0
compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.kt
...lysis-tests/testData/resolve/suppress/multipleWarnings.kt
+7
-0
compiler/fir/analysis-tests/testData/resolve/suppress/singleError.fir.txt
...lysis-tests/testData/resolve/suppress/singleError.fir.txt
+6
-0
compiler/fir/analysis-tests/testData/resolve/suppress/singleError.kt
...r/analysis-tests/testData/resolve/suppress/singleError.kt
+6
-0
compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.fir.txt
...sis-tests/testData/resolve/suppress/singleWarning.fir.txt
+3
-0
compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.kt
...analysis-tests/testData/resolve/suppress/singleWarning.kt
+4
-0
compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java
...rains/kotlin/test/runners/FirDiagnosticTestGenerated.java
+34
-0
compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java
...est/runners/FirDiagnosticsWithLightTreeTestGenerated.java
+35
-0
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/context/CheckerContext.kt
...ns/kotlin/fir/analysis/checkers/context/CheckerContext.kt
+48
-6
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt
...in/fir/analysis/collectors/AbstractDiagnosticCollector.kt
+95
-24
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/SimpleDiagnosticsCollector.kt
...lin/fir/analysis/collectors/SimpleDiagnosticsCollector.kt
+14
-4
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt
...ins/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt
+0
-8
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/BaseDiagnosticReporter.kt
...n/fir/analysis/diagnostics/impl/BaseDiagnosticReporter.kt
+13
-0
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/DiagnosticReporterWithSuppress.kt
...alysis/diagnostics/impl/DiagnosticReporterWithSuppress.kt
+30
-0
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/SimpleDiagnosticReporter.kt
...fir/analysis/diagnostics/impl/SimpleDiagnosticReporter.kt
+20
-0
compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/StandardClassIds.kt
.../src/org/jetbrains/kotlin/fir/symbols/StandardClassIds.kt
+2
-0
compiler/testData/codegen/boxInline/private/privateClassExtensionLambda.kt
.../codegen/boxInline/private/privateClassExtensionLambda.kt
+0
-1
未找到文件。
compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java
浏览文件 @
ebced14d
...
...
@@ -3103,6 +3103,39 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
}
}
@TestMetadata
(
"compiler/fir/analysis-tests/testData/resolve/suppress"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
static
class
Suppress
extends
AbstractLazyBodyIsNotTouchedTilContractsPhaseTest
{
private
void
runTest
(
String
testDataFilePath
)
throws
Exception
{
KotlinTestUtils
.
runTest
(
this
::
doTest
,
this
,
testDataFilePath
);
}
public
void
testAllFilesPresentInSuppress
()
throws
Exception
{
KtTestUtil
.
assertAllTestsPresentByMetadataWithExcluded
(
this
.
getClass
(),
new
File
(
"compiler/fir/analysis-tests/testData/resolve/suppress"
),
Pattern
.
compile
(
"^([^.]+)\\.kt$"
),
null
,
true
);
}
@TestMetadata
(
"allWarnings.kt"
)
public
void
testAllWarnings
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.kt"
);
}
@TestMetadata
(
"multipleWarnings.kt"
)
public
void
testMultipleWarnings
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.kt"
);
}
@TestMetadata
(
"singleError.kt"
)
public
void
testSingleError
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/singleError.kt"
);
}
@TestMetadata
(
"singleWarning.kt"
)
public
void
testSingleWarning
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.kt"
);
}
}
@TestMetadata
(
"compiler/fir/analysis-tests/testData/resolve/types"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
...
...
compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.fir.txt
0 → 100644
浏览文件 @
ebced14d
FILE: allWarnings.kt
@R|kotlin/Suppress|(vararg(String(warnings))) public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final fun foo(): R|kotlin/Unit| {
}
}
compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.kt
0 → 100644
浏览文件 @
ebced14d
// WITH_EXTENDED_CHECKERS
@Suppress
(
"warnings"
)
public
class
A
{
final
fun
foo
()
{}
}
compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.fir.txt
0 → 100644
浏览文件 @
ebced14d
FILE: multipleWarnings.kt
@R|kotlin/Suppress|(vararg(String(REDUNDANT_VISIBILITY_MODIFIER))) public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
@R|kotlin/Suppress|(vararg(String(REDUNDANT_MODALITY_MODIFIER))) public final fun foo(): R|kotlin/Unit| {
}
}
compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.kt
0 → 100644
浏览文件 @
ebced14d
// WITH_EXTENDED_CHECKERS
@Suppress
(
"REDUNDANT_VISIBILITY_MODIFIER"
)
public
class
A
{
@Suppress
(
"REDUNDANT_MODALITY_MODIFIER"
)
public
final
fun
foo
()
{}
}
compiler/fir/analysis-tests/testData/resolve/suppress/singleError.fir.txt
0 → 100644
浏览文件 @
ebced14d
FILE: singleError.kt
public final fun foo(x: R|kotlin/String|): R|kotlin/Unit| {
}
@R|kotlin/Suppress|(vararg(String(INAPPLICABLE_CANDIDATE))) public final fun bar(): R|kotlin/Unit| {
<Inapplicable(INAPPLICABLE): /foo>#(Int(10))
}
compiler/fir/analysis-tests/testData/resolve/suppress/singleError.kt
0 → 100644
浏览文件 @
ebced14d
fun
foo
(
x
:
String
)
{}
@Suppress
(
"INAPPLICABLE_CANDIDATE"
)
fun
bar
()
{
foo
(
10
)
}
compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.fir.txt
0 → 100644
浏览文件 @
ebced14d
FILE: singleWarning.kt
@R|kotlin/Suppress|(vararg(String(REDUNDANT_VISIBILITY_MODIFIER))) public final fun foo(): R|kotlin/Unit| {
}
compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.kt
0 → 100644
浏览文件 @
ebced14d
// WITH_EXTENDED_CHECKERS
@Suppress
(
"REDUNDANT_VISIBILITY_MODIFIER"
)
public
fun
foo
()
{}
compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java
浏览文件 @
ebced14d
...
...
@@ -3474,6 +3474,40 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
}
}
@Nested
@TestMetadata
(
"compiler/fir/analysis-tests/testData/resolve/suppress"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
public
class
Suppress
extends
AbstractFirDiagnosticTest
{
@Test
public
void
testAllFilesPresentInSuppress
()
throws
Exception
{
KtTestUtil
.
assertAllTestsPresentByMetadataWithExcluded
(
this
.
getClass
(),
new
File
(
"compiler/fir/analysis-tests/testData/resolve/suppress"
),
Pattern
.
compile
(
"^([^.]+)\\.kt$"
),
null
,
true
);
}
@Test
@TestMetadata
(
"allWarnings.kt"
)
public
void
testAllWarnings
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.kt"
);
}
@Test
@TestMetadata
(
"multipleWarnings.kt"
)
public
void
testMultipleWarnings
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.kt"
);
}
@Test
@TestMetadata
(
"singleError.kt"
)
public
void
testSingleError
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/singleError.kt"
);
}
@Test
@TestMetadata
(
"singleWarning.kt"
)
public
void
testSingleWarning
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.kt"
);
}
}
@Nested
@TestMetadata
(
"compiler/fir/analysis-tests/testData/resolve/types"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
...
...
compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java
浏览文件 @
ebced14d
...
...
@@ -3520,6 +3520,41 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
}
}
@Nested
@TestMetadata
(
"compiler/fir/analysis-tests/testData/resolve/suppress"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@Execution
(
ExecutionMode
.
SAME_THREAD
)
public
class
Suppress
extends
AbstractFirDiagnosticsWithLightTreeTest
{
@Test
public
void
testAllFilesPresentInSuppress
()
throws
Exception
{
KtTestUtil
.
assertAllTestsPresentByMetadataWithExcluded
(
this
.
getClass
(),
new
File
(
"compiler/fir/analysis-tests/testData/resolve/suppress"
),
Pattern
.
compile
(
"^([^.]+)\\.kt$"
),
null
,
true
);
}
@Test
@TestMetadata
(
"allWarnings.kt"
)
public
void
testAllWarnings
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.kt"
);
}
@Test
@TestMetadata
(
"multipleWarnings.kt"
)
public
void
testMultipleWarnings
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.kt"
);
}
@Test
@TestMetadata
(
"singleError.kt"
)
public
void
testSingleError
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/singleError.kt"
);
}
@Test
@TestMetadata
(
"singleWarning.kt"
)
public
void
testSingleWarning
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.kt"
);
}
}
@Nested
@TestMetadata
(
"compiler/fir/analysis-tests/testData/resolve/types"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
...
...
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/context/CheckerContext.kt
浏览文件 @
ebced14d
...
...
@@ -6,13 +6,16 @@
package
org.jetbrains.kotlin.fir.analysis.checkers.context
import
kotlinx.collections.immutable.PersistentList
import
kotlinx.collections.immutable.PersistentSet
import
kotlinx.collections.immutable.persistentListOf
import
kotlinx.collections.immutable.persistentSetOf
import
org.jetbrains.kotlin.fir.FirSession
import
org.jetbrains.kotlin.fir.declarations.FirDeclaration
import
org.jetbrains.kotlin.fir.resolve.ImplicitReceiverStack
import
org.jetbrains.kotlin.fir.resolve.PersistentImplicitReceiverStack
import
org.jetbrains.kotlin.fir.resolve.SessionHolder
import
org.jetbrains.kotlin.fir.resolve.calls.ImplicitReceiverValue
import
org.jetbrains.kotlin.fir.resolve.calls.InapplicableArgumentDiagnostic
import
org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
import
org.jetbrains.kotlin.name.Name
...
...
@@ -21,6 +24,10 @@ abstract class CheckerContext {
abstract
val
containingDeclarations
:
List
<
FirDeclaration
>
abstract
val
sessionHolder
:
SessionHolder
abstract
val
returnTypeCalculator
:
ReturnTypeCalculator
abstract
val
suppressedDiagnostics
:
Set
<
String
>
abstract
val
allInfosSuppressed
:
Boolean
abstract
val
allWarningsSuppressed
:
Boolean
abstract
val
allErrorsSuppressed
:
Boolean
val
session
:
FirSession
get
()
=
sessionHolder
.
session
...
...
@@ -38,17 +45,25 @@ abstract class CheckerContext {
}
}
class
PersistentCheckerContext
(
override
val
implicitReceiverStack
:
PersistentImplicitReceiverStack
=
PersistentImplicitReceiverStack
()
,
override
val
containingDeclarations
:
PersistentList
<
FirDeclaration
>
=
persistentListOf
()
,
class
PersistentCheckerContext
private
constructor
(
override
val
implicitReceiverStack
:
PersistentImplicitReceiverStack
,
override
val
containingDeclarations
:
PersistentList
<
FirDeclaration
>,
override
val
sessionHolder
:
SessionHolder
,
override
val
returnTypeCalculator
:
ReturnTypeCalculator
,
override
val
suppressedDiagnostics
:
PersistentSet
<
String
>,
override
val
allInfosSuppressed
:
Boolean
,
override
val
allWarningsSuppressed
:
Boolean
,
override
val
allErrorsSuppressed
:
Boolean
)
:
CheckerContext
()
{
constructor
(
sessionHolder
:
SessionHolder
,
returnTypeCalculator
:
ReturnTypeCalculator
)
:
this
(
PersistentImplicitReceiverStack
(),
persistentListOf
(),
sessionHolder
,
returnTypeCalculator
returnTypeCalculator
,
persistentSetOf
(),
allInfosSuppressed
=
false
,
allWarningsSuppressed
=
false
,
allErrorsSuppressed
=
false
)
fun
addImplicitReceiver
(
name
:
Name
?,
value
:
ImplicitReceiverValue
<
*
>):
PersistentCheckerContext
{
...
...
@@ -56,7 +71,11 @@ class PersistentCheckerContext(
implicitReceiverStack
.
add
(
name
,
value
),
containingDeclarations
,
sessionHolder
,
returnTypeCalculator
returnTypeCalculator
,
suppressedDiagnostics
,
allInfosSuppressed
,
allWarningsSuppressed
,
allErrorsSuppressed
)
}
...
...
@@ -65,7 +84,30 @@ class PersistentCheckerContext(
implicitReceiverStack
,
containingDeclarations
.
add
(
declaration
),
sessionHolder
,
returnTypeCalculator
returnTypeCalculator
,
suppressedDiagnostics
,
allInfosSuppressed
,
allWarningsSuppressed
,
allErrorsSuppressed
)
}
fun
addSuppressedDiagnostics
(
diagnosticNames
:
Collection
<
String
>,
allInfosSuppressed
:
Boolean
,
allWarningsSuppressed
:
Boolean
,
allErrorsSuppressed
:
Boolean
):
PersistentCheckerContext
{
if
(
diagnosticNames
.
isEmpty
())
return
this
return
PersistentCheckerContext
(
implicitReceiverStack
,
containingDeclarations
,
sessionHolder
,
returnTypeCalculator
,
suppressedDiagnostics
.
addAll
(
diagnosticNames
),
this
.
allInfosSuppressed
||
allInfosSuppressed
,
this
.
allWarningsSuppressed
||
allWarningsSuppressed
,
this
.
allErrorsSuppressed
||
allErrorsSuppressed
)
}
}
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt
浏览文件 @
ebced14d
...
...
@@ -5,6 +5,7 @@
package
org.jetbrains.kotlin.fir.analysis.collectors
import
org.jetbrains.kotlin.fir.FirAnnotationContainer
import
org.jetbrains.kotlin.fir.FirElement
import
org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import
org.jetbrains.kotlin.fir.FirSession
...
...
@@ -21,11 +22,9 @@ import org.jetbrains.kotlin.fir.resolve.collectImplicitReceivers
import
org.jetbrains.kotlin.fir.resolve.defaultType
import
org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
import
org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve
import
org.jetbrains.kotlin.fir.types.ConeKotlinType
import
org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import
org.jetbrains.kotlin.fir.types.FirTypeRef
import
org.jetbrains.kotlin.fir.symbols.StandardClassIds
import
org.jetbrains.kotlin.fir.types.*
import
org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import
org.jetbrains.kotlin.fir.types.coneTypeSafe
import
org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
import
org.jetbrains.kotlin.name.Name
...
...
@@ -34,6 +33,12 @@ abstract class AbstractDiagnosticCollector(
override
val
scopeSession
:
ScopeSession
=
ScopeSession
(),
returnTypeCalculator
:
ReturnTypeCalculator
=
ReturnTypeCalculatorForFullBodyResolve
()
)
:
SessionHolder
{
companion
object
{
private
const
val
SUPPRESS_ALL_INFOS
=
"infos"
private
const
val
SUPPRESS_ALL_WARNINGS
=
"warnings"
private
const
val
SUPPRESS_ALL_ERRORS
=
"errors"
}
fun
collectDiagnostics
(
firFile
:
FirFile
):
List
<
FirDiagnostic
<
*
>>
{
if
(!
componentsInitialized
)
{
throw
IllegalStateException
(
"Components are not initialized"
)
...
...
@@ -74,13 +79,26 @@ abstract class AbstractDiagnosticCollector(
}
override
fun
visitElement
(
element
:
FirElement
,
data
:
Nothing
?)
{
if
(
element
is
FirAnnotationContainer
)
{
visitAnnotationContainer
(
element
,
data
)
return
}
element
.
runComponents
()
element
.
acceptChildren
(
this
,
null
)
}
override
fun
visitAnnotationContainer
(
annotationContainer
:
FirAnnotationContainer
,
data
:
Nothing
?)
{
withSuppressedDiagnostics
(
annotationContainer
)
{
annotationContainer
.
runComponents
()
annotationContainer
.
acceptChildren
(
this
,
null
)
}
}
private
fun
visitJump
(
loopJump
:
FirLoopJump
)
{
loopJump
.
runComponents
()
loopJump
.
target
.
labeledElement
.
takeIf
{
it
is
FirErrorLoop
}
?.
accept
(
this
,
null
)
withSuppressedDiagnostics
(
loopJump
)
{
loopJump
.
runComponents
()
loopJump
.
target
.
labeledElement
.
takeIf
{
it
is
FirErrorLoop
}
?.
accept
(
this
,
null
)
}
}
override
fun
visitBreakExpression
(
breakExpression
:
FirBreakExpression
,
data
:
Nothing
?)
{
...
...
@@ -96,55 +114,74 @@ abstract class AbstractDiagnosticCollector(
this
.
type
=
type
}
visitWithDeclarationAndReceiver
(
klass
,
(
klass
as
?
FirRegularClass
)
?.
name
,
typeRef
)
}
override
fun
visitRegularClass
(
regularClass
:
FirRegularClass
,
data
:
Nothing
?)
{
visitClassAndChildren
(
regularClass
,
regularClass
.
defaultType
())
withSuppressedDiagnostics
(
regularClass
)
{
visitClassAndChildren
(
regularClass
,
regularClass
.
defaultType
())
}
}
override
fun
visitAnonymousObject
(
anonymousObject
:
FirAnonymousObject
,
data
:
Nothing
?)
{
visitClassAndChildren
(
anonymousObject
,
anonymousObject
.
defaultType
())
withSuppressedDiagnostics
(
anonymousObject
)
{
visitClassAndChildren
(
anonymousObject
,
anonymousObject
.
defaultType
())
}
}
override
fun
visitSimpleFunction
(
simpleFunction
:
FirSimpleFunction
,
data
:
Nothing
?)
{
visitWithDeclarationAndReceiver
(
simpleFunction
,
simpleFunction
.
name
,
simpleFunction
.
receiverTypeRef
)
withSuppressedDiagnostics
(
simpleFunction
)
{
visitWithDeclarationAndReceiver
(
simpleFunction
,
simpleFunction
.
name
,
simpleFunction
.
receiverTypeRef
)
}
}
override
fun
visitConstructor
(
constructor
:
FirConstructor
,
data
:
Nothing
?)
{
visitWithDeclaration
(
constructor
)
withSuppressedDiagnostics
(
constructor
)
{
visitWithDeclaration
(
constructor
)
}
}
override
fun
visitAnonymousFunction
(
anonymousFunction
:
FirAnonymousFunction
,
data
:
Nothing
?)
{
val
labelName
=
anonymousFunction
.
label
?.
name
?.
let
{
Name
.
identifier
(
it
)
}
visitWithDeclarationAndReceiver
(
anonymousFunction
,
labelName
,
anonymousFunction
.
receiverTypeRef
)
withSuppressedDiagnostics
(
anonymousFunction
)
{
val
labelName
=
anonymousFunction
.
label
?.
name
?.
let
{
Name
.
identifier
(
it
)
}
visitWithDeclarationAndReceiver
(
anonymousFunction
,
labelName
,
anonymousFunction
.
receiverTypeRef
)
}
}
override
fun
visitProperty
(
property
:
FirProperty
,
data
:
Nothing
?)
{
visitWithDeclaration
(
property
)
withSuppressedDiagnostics
(
property
)
{
visitWithDeclaration
(
property
)
}
}
override
fun
visitPropertyAccessor
(
propertyAccessor
:
FirPropertyAccessor
,
data
:
Nothing
?)
{
if
(
propertyAccessor
!
is
FirDefaultPropertyAccessor
)
{
val
property
=
context
.
containingDeclarations
.
last
()
as
FirProperty
visitWithDeclarationAndReceiver
(
propertyAccessor
,
property
.
name
,
property
.
receiverTypeRef
)
withSuppressedDiagnostics
(
propertyAccessor
)
{
visitWithDeclarationAndReceiver
(
propertyAccessor
,
property
.
name
,
property
.
receiverTypeRef
)
}
}
}
override
fun
visitValueParameter
(
valueParameter
:
FirValueParameter
,
data
:
Nothing
?)
{
visitWithDeclaration
(
valueParameter
)
withSuppressedDiagnostics
(
valueParameter
)
{
visitWithDeclaration
(
valueParameter
)
}
}
override
fun
visitEnumEntry
(
enumEntry
:
FirEnumEntry
,
data
:
Nothing
?)
{
visitWithDeclaration
(
enumEntry
)
withSuppressedDiagnostics
(
enumEntry
)
{
visitWithDeclaration
(
enumEntry
)
}
}
override
fun
visitFile
(
file
:
FirFile
,
data
:
Nothing
?)
{
visitWithDeclaration
(
file
)
withSuppressedDiagnostics
(
file
)
{
visitWithDeclaration
(
file
)
}
}
override
fun
visitAnonymousInitializer
(
anonymousInitializer
:
FirAnonymousInitializer
,
data
:
Nothing
?)
{
...
...
@@ -152,12 +189,17 @@ abstract class AbstractDiagnosticCollector(
}
override
fun
visitBlock
(
block
:
FirBlock
,
data
:
Nothing
?)
{
visitExpression
(
block
,
data
)
withSuppressedDiagnostics
(
block
)
{
visitExpression
(
block
,
data
)
}
}
override
fun
visitTypeRef
(
typeRef
:
FirTypeRef
,
data
:
Nothing
?)
{
if
(
typeRef
.
source
!=
null
&&
typeRef
.
source
?.
kind
!
is
FirFakeSourceElementKind
)
{
super
.
visitTypeRef
(
typeRef
,
null
)
withSuppressedDiagnostics
(
typeRef
)
{
typeRef
.
runComponents
()
typeRef
.
acceptChildren
(
this
,
data
)
}
}
}
...
...
@@ -233,6 +275,35 @@ abstract class AbstractDiagnosticCollector(
}
}
private
inline
fun
<
R
>
withSuppressedDiagnostics
(
annotationContainer
:
FirAnnotationContainer
,
block
:
()
->
R
):
R
{
val
existingContext
=
context
addSuppressedDiagnosticsToContext
(
annotationContainer
)
return
try
{
block
()
}
finally
{
context
=
existingContext
}
}
private
fun
addSuppressedDiagnosticsToContext
(
annotationContainer
:
FirAnnotationContainer
)
{
val
annotations
=
annotationContainer
.
annotations
.
filter
{
val
type
=
it
.
annotationTypeRef
.
coneType
as
?
ConeClassLikeType
?:
return
@filter
false
type
.
lookupTag
.
classId
==
StandardClassIds
.
Suppress
}
if
(
annotations
.
isEmpty
())
return
val
arguments
=
annotations
.
flatMap
{
annotationCall
->
annotationCall
.
arguments
.
filterIsInstance
<
FirVarargArgumentsExpression
>().
flatMap
{
varargArgument
->
varargArgument
.
arguments
.
mapNotNull
{
(
it
as
?
FirConstExpression
<
*
>)
?.
value
as
?
String
?
}
}
}
context
=
context
.
addSuppressedDiagnostics
(
arguments
,
allInfosSuppressed
=
SUPPRESS_ALL_INFOS
in
arguments
,
allWarningsSuppressed
=
SUPPRESS_ALL_WARNINGS
in
arguments
,
allErrorsSuppressed
=
SUPPRESS_ALL_ERRORS
in
arguments
)
}
private
inline
fun
<
R
>
withDiagnosticsAction
(
action
:
DiagnosticCollectorDeclarationAction
,
block
:
()
->
R
):
R
{
val
oldAction
=
currentAction
currentAction
=
action
...
...
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/SimpleDiagnosticsCollector.kt
浏览文件 @
ebced14d
...
...
@@ -7,14 +7,24 @@ package org.jetbrains.kotlin.fir.analysis.collectors
import
org.jetbrains.kotlin.fir.FirSession
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
import
org.jetbrains.kotlin.fir.analysis.diagnostics.SimpleDiagnosticReporter
import
org.jetbrains.kotlin.fir.analysis.diagnostics.impl.BaseDiagnosticReporter
import
org.jetbrains.kotlin.fir.analysis.diagnostics.impl.DiagnosticReporterWithSuppress
import
org.jetbrains.kotlin.fir.analysis.diagnostics.impl.SimpleDiagnosticReporter
class
SimpleDiagnosticsCollector
(
session
:
FirSession
)
:
AbstractDiagnosticCollector
(
session
)
{
override
var
reporter
=
Simpl
eDiagnosticReporter
()
class
SimpleDiagnosticsCollector
(
session
:
FirSession
,
private
val
disableSuppress
:
Boolean
=
false
)
:
AbstractDiagnosticCollector
(
session
)
{
override
var
reporter
=
creat
eDiagnosticReporter
()
private
set
private
fun
createDiagnosticReporter
():
BaseDiagnosticReporter
{
return
if
(
disableSuppress
)
{
SimpleDiagnosticReporter
()
}
else
{
DiagnosticReporterWithSuppress
()
}
}
override
fun
initializeCollector
()
{
reporter
=
Simpl
eDiagnosticReporter
()
reporter
=
creat
eDiagnosticReporter
()
}
override
fun
getCollectedDiagnostics
():
List
<
FirDiagnostic
<
*
>>
{
...
...
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt
浏览文件 @
ebced14d
...
...
@@ -51,11 +51,3 @@ inline fun <reified T : FirSourceElement, P : PsiElement, A : Any, B : Any, C :
source
?.
let
{
report
(
factory
.
on
(
it
,
a
,
b
,
c
),
context
)
}
}
class
SimpleDiagnosticReporter
:
DiagnosticReporter
()
{
val
diagnostics
:
MutableList
<
FirDiagnostic
<
*
>>
=
mutableListOf
()
override
fun
report
(
diagnostic
:
FirDiagnostic
<
*
>?,
context
:
CheckerContext
)
{
if
(
diagnostic
==
null
)
return
diagnostics
+=
diagnostic
}
}
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/BaseDiagnosticReporter.kt
0 → 100644
浏览文件 @
ebced14d
/*
* 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.diagnostics.impl
import
org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
abstract
class
BaseDiagnosticReporter
:
DiagnosticReporter
()
{
abstract
val
diagnostics
:
List
<
FirDiagnostic
<
*
>>
}
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/DiagnosticReporterWithSuppress.kt
0 → 100644
浏览文件 @
ebced14d
/*
* 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.diagnostics.impl
import
org.jetbrains.kotlin.diagnostics.Severity
import
org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
class
DiagnosticReporterWithSuppress
:
BaseDiagnosticReporter
()
{
private
val
_diagnostics
:
MutableList
<
FirDiagnostic
<
*
>>
=
mutableListOf
()
override
val
diagnostics
:
List
<
FirDiagnostic
<
*
>>
get
()
=
_diagnostics
override
fun
report
(
diagnostic
:
FirDiagnostic
<
*
>?,
context
:
CheckerContext
)
{
if
(
diagnostic
==
null
)
return
val
factory
=
diagnostic
.
factory
val
name
=
factory
.
name
val
suppressedByAll
=
when
(
factory
.
severity
)
{
Severity
.
INFO
->
context
.
allInfosSuppressed
Severity
.
WARNING
->
context
.
allWarningsSuppressed
Severity
.
ERROR
->
context
.
allErrorsSuppressed
}
if
(
suppressedByAll
||
name
in
context
.
suppressedDiagnostics
)
return
_diagnostics
+=
diagnostic
}
}
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/impl/SimpleDiagnosticReporter.kt
0 → 100644
浏览文件 @
ebced14d
/*
* 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.diagnostics.impl
import
org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
class
SimpleDiagnosticReporter
:
BaseDiagnosticReporter
()
{
private
val
_diagnostics
:
MutableList
<
FirDiagnostic
<
*
>>
=
mutableListOf
()
override
val
diagnostics
:
List
<
FirDiagnostic
<
*
>>
get
()
=
_diagnostics
override
fun
report
(
diagnostic
:
FirDiagnostic
<
*
>?,
context
:
CheckerContext
)
{
if
(
diagnostic
==
null
)
return
_diagnostics
+=
diagnostic
}
}
compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/StandardClassIds.kt
浏览文件 @
ebced14d
...
...
@@ -83,6 +83,8 @@ object StandardClassIds {
fun
FunctionN
(
n
:
Int
):
ClassId
{
return
"Function$n"
.
baseId
()
}
val
Suppress
=
"Suppress"
.
baseId
()
}
private
fun
<
K
,
V
>
Map
<
K
,
V
>.
inverseMap
()
=
entries
.
associate
{
(
k
,
v
)
->
v
to
k
}
compiler/testData/codegen/boxInline/private/privateClassExtensionLambda.kt
浏览文件 @
ebced14d
// IGNORE_FIR_DIAGNOSTICS
// FILE: 1.kt
package
test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录