Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
a0b901b2
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,发现更多精彩内容 >>
提交
a0b901b2
编写于
3月 05, 2021
作者:
A
Andrei Klunnyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "[FIR]: sealed hierarchy processor for IDE"
This reverts commit
e6ccdff2
上级
4ed341b1
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
92 addition
and
324 deletion
+92
-324
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractPhaseTransformer.kt
...n/fir/resolve/transformers/FirAbstractPhaseTransformer.kt
+11
-1
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirLegacySealedClassInheritorsTransformer.kt
...transformers/FirLegacySealedClassInheritorsTransformer.kt
+38
-0
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveProcessor.kt
...tlin/fir/resolve/transformers/FirTotalResolveProcessor.kt
+11
-1
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/ResolvePhaseUtils.kt
...ains/kotlin/fir/resolve/transformers/ResolvePhaseUtils.kt
+23
-1
generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt
...ts/org/jetbrains/kotlin/generators/tests/GenerateTests.kt
+0
-4
idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/FirIdeSealedHierarchyProcessor.kt
.../idea/fir/low/level/api/FirIdeSealedHierarchyProcessor.kt
+0
-101
idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/FirPhaseRunner.kt
...jetbrains/kotlin/idea/fir/low/level/api/FirPhaseRunner.kt
+2
-30
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/anotherModule/AnotherModuleSamePackageDeclarations.kt
...ors/anotherModule/AnotherModuleSamePackageDeclarations.kt
+0
-5
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/expected.txt
...-api/testdata/resolveSealed/directInheritors/expected.txt
+0
-18
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/main/SamePackageDeclarations.kt
...veSealed/directInheritors/main/SamePackageDeclarations.kt
+0
-5
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/main/anotherpackage/AnotherPackageDeclarations.kt
...eritors/main/anotherpackage/AnotherPackageDeclarations.kt
+0
-7
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/main/main.kt
...-api/testdata/resolveSealed/directInheritors/main/main.kt
+0
-29
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/structure.json
...pi/testdata/resolveSealed/directInheritors/structure.json
+0
-7
idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirMultiModuleLazyResolveTest.kt
...ir/low/level/api/AbstractFirMultiModuleLazyResolveTest.kt
+3
-10
idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirMultiModuleResolveTest.kt
...ea/fir/low/level/api/AbstractFirMultiModuleResolveTest.kt
+2
-13
idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirSealedInheritorsTest.kt
...idea/fir/low/level/api/AbstractFirSealedInheritorsTest.kt
+0
-39
idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/FirSealedInheritorsTestGenerated.java
...a/fir/low/level/api/FirSealedInheritorsTestGenerated.java
+0
-36
idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirTypeProvider.kt
...lin/idea/frontend/api/fir/components/KtFirTypeProvider.kt
+1
-1
idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/util/psiUtils.kt
...ndependent/src/org/jetbrains/kotlin/idea/util/psiUtils.kt
+0
-15
idea/resources-fir/META-INF/plugin.xml
idea/resources-fir/META-INF/plugin.xml
+1
-1
未找到文件。
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractPhaseTransformer.kt
浏览文件 @
a0b901b2
...
...
@@ -44,4 +44,14 @@ abstract class FirAbstractPhaseTransformer<D>(
"File ${file.name} and transformer ${this::class} have inconsistent sessions"
}
}
}
\ No newline at end of file
}
fun
FirFile
.
runResolve
(
toPhase
:
FirResolvePhase
,
fromPhase
:
FirResolvePhase
=
FirResolvePhase
.
RAW_FIR
)
{
val
scopeSession
=
ScopeSession
()
var
currentPhase
=
fromPhase
while
(
currentPhase
<
toPhase
)
{
currentPhase
=
currentPhase
.
next
val
phaseProcessor
=
currentPhase
.
createTransformerBasedProcessorByPhase
(
session
,
scopeSession
)
phaseProcessor
.
processFile
(
this
)
}
}
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirLegacySealedClassInheritorsTransformer.kt
0 → 100644
浏览文件 @
a0b901b2
/*
* Copyright 2010-2019 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.resolve.transformers
import
org.jetbrains.kotlin.fir.FirElement
import
org.jetbrains.kotlin.fir.FirSession
import
org.jetbrains.kotlin.fir.declarations.FirDeclaration
import
org.jetbrains.kotlin.fir.declarations.FirFile
import
org.jetbrains.kotlin.fir.declarations.FirRegularClass
import
org.jetbrains.kotlin.fir.resolve.ScopeSession
import
org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
import
org.jetbrains.kotlin.fir.visitors.FirTransformer
import
org.jetbrains.kotlin.fir.visitors.compose
import
org.jetbrains.kotlin.name.ClassId
/*
* This processor is needed only for IDE until there won't be proper IDE implementation
* for detecting sealed inheritors in multiple files
*/
class
FirLegacySealedClassInheritorsProcessor
(
session
:
FirSession
,
scopeSession
:
ScopeSession
)
:
FirTransformerBasedResolveProcessor
(
session
,
scopeSession
)
{
override
val
transformer
=
FirLegacySealedClassInheritorsTransformer
()
}
class
FirLegacySealedClassInheritorsTransformer
:
FirTransformer
<
Nothing
?
>()
{
override
fun
<
E
:
FirElement
>
transformElement
(
element
:
E
,
data
:
Nothing
?):
CompositeTransformResult
<
E
>
{
throw
IllegalStateException
(
"Should not be there"
)
}
override
fun
transformFile
(
file
:
FirFile
,
data
:
Nothing
?):
CompositeTransformResult
<
FirDeclaration
>
{
val
sealedClassInheritorsMap
=
mutableMapOf
<
FirRegularClass
,
MutableList
<
ClassId
>>()
file
.
accept
(
FirSealedClassInheritorsProcessor
.
InheritorsCollector
,
sealedClassInheritorsMap
)
if
(
sealedClassInheritorsMap
.
isEmpty
())
return
file
.
compose
()
return
file
.
transform
(
FirSealedClassInheritorsProcessor
.
InheritorsTransformer
(
sealedClassInheritorsMap
),
null
)
}
}
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveProcessor.kt
浏览文件 @
a0b901b2
...
...
@@ -41,7 +41,17 @@ fun createAllCompilerResolveProcessors(
}
}
inline
fun
<
T
:
FirResolveProcessor
>
createAllResolveProcessors
(
fun
createAllTransformerBasedResolveProcessors
(
session
:
FirSession
,
scopeSession
:
ScopeSession
?
=
null
,
pluginPhasesEnabled
:
Boolean
=
false
,
):
List
<
FirTransformerBasedResolveProcessor
>
{
return
createAllResolveProcessors
(
scopeSession
,
pluginPhasesEnabled
)
{
createTransformerBasedProcessorByPhase
(
session
,
it
)
}
}
private
inline
fun
<
T
:
FirResolveProcessor
>
createAllResolveProcessors
(
scopeSession
:
ScopeSession
?
=
null
,
pluginPhasesEnabled
:
Boolean
,
creator
:
FirResolvePhase
.(
ScopeSession
)
->
T
...
...
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/ResolvePhaseUtils.kt
浏览文件 @
a0b901b2
...
...
@@ -40,7 +40,29 @@ fun FirResolvePhase.createCompilerProcessorByPhase(
}
}
class
FirDummyTransformerBasedProcessor
(
fun
FirResolvePhase
.
createTransformerBasedProcessorByPhase
(
session
:
FirSession
,
scopeSession
:
ScopeSession
):
FirTransformerBasedResolveProcessor
{
return
when
(
this
)
{
RAW_FIR
->
throw
IllegalStateException
(
"Raw FIR building phase does not have a transformer"
)
ANNOTATIONS_FOR_PLUGINS
->
FirPluginAnnotationsResolveProcessor
(
session
,
scopeSession
)
CLASS_GENERATION
->
FirDummyTransformerBasedProcessor
(
session
,
scopeSession
)
// TODO: remove
IMPORTS
->
FirImportResolveProcessor
(
session
,
scopeSession
)
SUPER_TYPES
->
FirSupertypeResolverProcessor
(
session
,
scopeSession
)
SEALED_CLASS_INHERITORS
->
FirLegacySealedClassInheritorsProcessor
(
session
,
scopeSession
)
TYPES
->
FirTypeResolveProcessor
(
session
,
scopeSession
)
ARGUMENTS_OF_PLUGIN_ANNOTATIONS
->
FirAnnotationArgumentsResolveProcessor
(
session
,
scopeSession
)
EXTENSION_STATUS_UPDATE
->
FirTransformerBasedExtensionStatusProcessor
(
session
,
scopeSession
)
STATUS
->
FirStatusResolveProcessor
(
session
,
scopeSession
)
CONTRACTS
->
FirContractResolveProcessor
(
session
,
scopeSession
)
NEW_MEMBERS_GENERATION
->
FirDummyTransformerBasedProcessor
(
session
,
scopeSession
)
// TODO: remove
IMPLICIT_TYPES_BODY_RESOLVE
->
FirImplicitTypeBodyResolveProcessor
(
session
,
scopeSession
)
BODY_RESOLVE
->
FirBodyResolveProcessor
(
session
,
scopeSession
)
}
}
private
class
FirDummyTransformerBasedProcessor
(
session
:
FirSession
,
scopeSession
:
ScopeSession
)
:
FirTransformerBasedResolveProcessor
(
session
,
scopeSession
)
{
...
...
generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt
浏览文件 @
a0b901b2
...
...
@@ -79,7 +79,6 @@ import org.jetbrains.kotlin.idea.editor.backspaceHandler.AbstractBackspaceHandle
import
org.jetbrains.kotlin.idea.editor.quickDoc.AbstractQuickDocProviderTest
import
org.jetbrains.kotlin.idea.filters.AbstractKotlinExceptionFilterTest
import
org.jetbrains.kotlin.idea.fir.AbstractKtDeclarationAndFirDeclarationEqualityChecker
import
org.jetbrains.kotlin.idea.fir.low.level.api.*
import
org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirLazyDeclarationResolveTest
import
org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirLazyResolveTest
import
org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirMultiModuleLazyResolveTest
...
...
@@ -1063,9 +1062,6 @@ fun main(args: Array<String>) {
testClass
<
AbstractFirMultiModuleLazyResolveTest
>
{
model
(
"multiModuleLazyResolve"
,
recursive
=
false
,
extension
=
null
)
}
testClass
<
AbstractFirSealedInheritorsTest
>
{
model
(
"resolveSealed"
,
recursive
=
false
,
extension
=
null
)
}
testClass
<
AbstractFirLazyDeclarationResolveTest
>
{
model
(
"lazyResolve"
)
}
...
...
idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/FirIdeSealedHierarchyProcessor.kt
已删除
100644 → 0
浏览文件 @
4ed341b1
/*
* 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.idea.fir.low.level.api
import
com.intellij.openapi.module.Module
import
com.intellij.psi.JavaDirectoryService
import
com.intellij.psi.PsiPackage
import
com.intellij.psi.search.GlobalSearchScope
import
com.intellij.psi.search.PackageScope
import
com.intellij.psi.search.SearchScope
import
com.intellij.psi.search.searches.ClassInheritorsSearch
import
org.jetbrains.kotlin.asJava.KotlinAsJavaSupport
import
org.jetbrains.kotlin.asJava.toLightClass
import
org.jetbrains.kotlin.fir.FirElement
import
org.jetbrains.kotlin.fir.FirSession
import
org.jetbrains.kotlin.fir.declarations.*
import
org.jetbrains.kotlin.fir.psi
import
org.jetbrains.kotlin.fir.resolve.ScopeSession
import
org.jetbrains.kotlin.fir.resolve.transformers.FirSealedClassInheritorsProcessor
import
org.jetbrains.kotlin.fir.resolve.transformers.FirTransformerBasedResolveProcessor
import
org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
import
org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
import
org.jetbrains.kotlin.fir.visitors.FirTransformer
import
org.jetbrains.kotlin.fir.visitors.compose
import
org.jetbrains.kotlin.idea.util.classIdIfNonLocal
import
org.jetbrains.kotlin.idea.util.module
import
org.jetbrains.kotlin.name.ClassId
import
org.jetbrains.kotlin.psi.KtClass
import
org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade
class
FirIdeSealedHierarchyProcessor
(
session
:
FirSession
,
scopeSession
:
ScopeSession
)
:
FirTransformerBasedResolveProcessor
(
session
,
scopeSession
)
{
override
val
transformer
:
FirTransformer
<
Nothing
?
>
=
SealedClassInheritorsTransformer
private
object
SealedClassInheritorsTransformer
:
FirTransformer
<
Nothing
?
>()
{
override
fun
<
E
:
FirElement
>
transformElement
(
element
:
E
,
data
:
Nothing
?):
CompositeTransformResult
<
E
>
{
throw
IllegalStateException
(
"Should not be there"
)
}
override
fun
transformFile
(
file
:
FirFile
,
data
:
Nothing
?):
CompositeTransformResult
<
FirDeclaration
>
{
val
sealedClassInheritorsMap
=
mutableMapOf
<
FirRegularClass
,
MutableList
<
ClassId
>>()
file
.
accept
(
SealedInheritorsCollector
,
sealedClassInheritorsMap
)
if
(
sealedClassInheritorsMap
.
isEmpty
())
return
file
.
compose
()
return
file
.
transform
(
FirSealedClassInheritorsProcessor
.
InheritorsTransformer
(
sealedClassInheritorsMap
),
null
)
}
}
private
object
SealedInheritorsCollector
:
FirDefaultVisitor
<
Unit
,
MutableMap
<
FirRegularClass
,
MutableList
<
ClassId
>>>()
{
override
fun
visitElement
(
element
:
FirElement
,
data
:
MutableMap
<
FirRegularClass
,
MutableList
<
ClassId
>>)
{}
override
fun
visitFile
(
file
:
FirFile
,
data
:
MutableMap
<
FirRegularClass
,
MutableList
<
ClassId
>>)
{
file
.
declarations
.
forEach
{
it
.
accept
(
this
,
data
)
}
}
override
fun
visitRegularClass
(
regularClass
:
FirRegularClass
,
data
:
MutableMap
<
FirRegularClass
,
MutableList
<
ClassId
>>)
{
if
(!
regularClass
.
isSealed
)
{
regularClass
.
acceptChildren
(
this
,
data
)
return
}
val
sealedKtClass
=
regularClass
.
psi
as
?
KtClass
?:
return
val
module
=
sealedKtClass
.
module
?:
return
val
containingPackage
=
regularClass
.
classId
.
packageFqName
val
psiPackage
=
KotlinJavaPsiFacade
.
getInstance
(
sealedKtClass
.
project
)
.
findPackage
(
containingPackage
.
asString
(),
GlobalSearchScope
.
moduleScope
(
module
))
?:
getPackageViaDirectoryService
(
sealedKtClass
)
?:
return
val
kotlinAsJavaSupport
=
KotlinAsJavaSupport
.
getInstance
(
sealedKtClass
.
project
)
val
lightClass
=
sealedKtClass
.
toLightClass
()
?:
kotlinAsJavaSupport
.
getFakeLightClass
(
sealedKtClass
)
val
searchScope
:
SearchScope
=
getSearchScope
(
module
,
psiPackage
)
val
searchParameters
=
ClassInheritorsSearch
.
SearchParameters
(
lightClass
,
searchScope
,
false
,
true
,
false
)
val
subclasses
=
ClassInheritorsSearch
.
search
(
searchParameters
)
.
mapNotNull
{
it
.
classIdIfNonLocal
()
}
.
toMutableList
()
data
[
regularClass
]
=
subclasses
}
private
fun
getSearchScope
(
module
:
Module
,
psiPackage
:
PsiPackage
):
GlobalSearchScope
{
val
packageScope
=
PackageScope
(
psiPackage
,
false
,
false
)
// MPP multiple common modules are not supported!!
return
module
.
moduleScope
.
intersectWith
(
packageScope
)
}
}
}
private
fun
getPackageViaDirectoryService
(
ktClass
:
KtClass
):
PsiPackage
?
{
val
directory
=
ktClass
.
containingFile
.
containingDirectory
?:
return
null
return
JavaDirectoryService
.
getInstance
().
getPackage
(
directory
)
}
\ No newline at end of file
idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/FirPhaseRunner.kt
浏览文件 @
a0b901b2
...
...
@@ -5,17 +5,10 @@
package
org.jetbrains.kotlin.idea.fir.low.level.api
import
org.jetbrains.kotlin.fir.FirSession
import
org.jetbrains.kotlin.fir.declarations.FirFile
import
org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import
org.jetbrains.kotlin.fir.resolve.ScopeSession
import
org.jetbrains.kotlin.fir.resolve.transformers.*
import
org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirBodyResolveProcessor
import
org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirImplicitTypeBodyResolveProcessor
import
org.jetbrains.kotlin.fir.resolve.transformers.contracts.FirContractResolveProcessor
import
org.jetbrains.kotlin.fir.resolve.transformers.plugin.FirAnnotationArgumentsResolveProcessor
import
org.jetbrains.kotlin.fir.resolve.transformers.plugin.FirPluginAnnotationsResolveProcessor
import
org.jetbrains.kotlin.fir.resolve.transformers.plugin.FirTransformerBasedExtensionStatusProcessor
import
org.jetbrains.kotlin.fir.resolve.transformers.createTransformerBasedProcessorByPhase
import
org.jetbrains.kotlin.idea.fir.low.level.api.lazy.resolve.FirLazyBodiesCalculator
import
org.jetbrains.kotlin.idea.fir.low.level.api.util.executeWithoutPCE
import
java.util.concurrent.locks.ReentrantLock
...
...
@@ -62,6 +55,7 @@ internal class FirPhaseRunner {
}
}
private
fun
runPhaseWithoutLock
(
firFile
:
FirFile
,
phase
:
FirResolvePhase
,
scopeSession
:
ScopeSession
)
{
val
phaseProcessor
=
phase
.
createTransformerBasedProcessorByPhase
(
firFile
.
session
,
scopeSession
)
executeWithoutPCE
{
...
...
@@ -70,25 +64,3 @@ internal class FirPhaseRunner {
}
}
}
internal
fun
FirResolvePhase
.
createTransformerBasedProcessorByPhase
(
session
:
FirSession
,
scopeSession
:
ScopeSession
):
FirTransformerBasedResolveProcessor
{
return
when
(
this
)
{
FirResolvePhase
.
RAW_FIR
->
throw
IllegalStateException
(
"Raw FIR building phase does not have a transformer"
)
FirResolvePhase
.
ANNOTATIONS_FOR_PLUGINS
->
FirPluginAnnotationsResolveProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
CLASS_GENERATION
->
FirDummyTransformerBasedProcessor
(
session
,
scopeSession
)
// TODO: remove
FirResolvePhase
.
IMPORTS
->
FirImportResolveProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
SUPER_TYPES
->
FirSupertypeResolverProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
SEALED_CLASS_INHERITORS
->
FirIdeSealedHierarchyProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
TYPES
->
FirTypeResolveProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
ARGUMENTS_OF_PLUGIN_ANNOTATIONS
->
FirAnnotationArgumentsResolveProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
EXTENSION_STATUS_UPDATE
->
FirTransformerBasedExtensionStatusProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
STATUS
->
FirStatusResolveProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
CONTRACTS
->
FirContractResolveProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
NEW_MEMBERS_GENERATION
->
FirDummyTransformerBasedProcessor
(
session
,
scopeSession
)
// TODO: remove
FirResolvePhase
.
IMPLICIT_TYPES_BODY_RESOLVE
->
FirImplicitTypeBodyResolveProcessor
(
session
,
scopeSession
)
FirResolvePhase
.
BODY_RESOLVE
->
FirBodyResolveProcessor
(
session
,
scopeSession
)
}
}
\ No newline at end of file
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/anotherModule/AnotherModuleSamePackageDeclarations.kt
已删除
100644 → 0
浏览文件 @
4ed341b1
class
ClassAnotherModuleInheritorA
:
SealedClass
()
class
ClassAnotherModuleInheritorB
:
SealedClass
()
class
InterfaceAnotherModuleInheritorA
:
SealedInterface
class
InterfaceAnotherModuleInheritorB
:
SealedInterface
\ No newline at end of file
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/expected.txt
已删除
100644 → 0
浏览文件 @
4ed341b1
ClassSameFileInheritorA
ClassSameFileInheritorB
ClassSameFileInheritorC
ClassSamePackageInheritorA
ClassSamePackageInheritorB
InterfaceSameFileInheritorA
InterfaceSameFileInheritorB
InterfaceSameFileInheritorC
InterfaceSamePackageInheritorA
InterfaceSamePackageInheritorB
NonSealedClass.NestedSealedInheritorA
NonSealedClass.NestedSealedInheritorB
SealedClass.NestedInheritorA
SealedClass.NestedInheritorA.NestedNestedInheritorA
SealedClass.NestedInheritorA.NestedNestedInheritorB
SealedInterface.NestedInheritorA
SealedInterface.NestedInheritorA.NestedNestedInheritorA
SealedInterface.NestedInheritorA.NestedNestedInheritorB
\ No newline at end of file
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/main/SamePackageDeclarations.kt
已删除
100644 → 0
浏览文件 @
4ed341b1
class
ClassSamePackageInheritorA
:
SealedClass
()
class
ClassSamePackageInheritorB
:
SealedClass
()
class
InterfaceSamePackageInheritorA
:
SealedInterface
class
InterfaceSamePackageInheritorB
:
SealedInterface
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/main/anotherpackage/AnotherPackageDeclarations.kt
已删除
100644 → 0
浏览文件 @
4ed341b1
package
anotherpackage
class
ClassAnotherPackageInheritorA
:
SealedClass
()
class
ClassAnotherPackageInheritorB
:
SealedClass
()
class
InterfaceAnotherPackageInheritorA
:
SealedInterface
class
InterfaceAnotherPackageInheritorB
:
SealedInterface
\ No newline at end of file
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/main/main.kt
已删除
100644 → 0
浏览文件 @
4ed341b1
sealed
class
SealedClass
{
// (1): top level sealed class
class
NestedInheritorA
:
SealedClass
()
{
class
NestedNestedInheritorA
:
SealedClass
()
object
NestedNestedInheritorB
:
SealedClass
()
}
}
class
ClassSameFileInheritorA
:
SealedClass
()
class
ClassSameFileInheritorB
:
SealedClass
()
object
ClassSameFileInheritorC
:
SealedClass
()
sealed
interface
SealedInterface
{
// (2): top level sealed interface
class
NestedInheritorA
:
SealedInterface
{
interface
NestedNestedInheritorA
:
SealedInterface
object
NestedNestedInheritorB
:
SealedInterface
}
}
class
InterfaceSameFileInheritorA
:
SealedInterface
class
InterfaceSameFileInheritorB
:
SealedInterface
object
InterfaceSameFileInheritorC
:
SealedInterface
class
NonSealedClass
{
sealed
class
NestedSealedClass
// (3): nested sealed class
sealed
interface
NestedSealedInterface
// (4): nested sealed interface
class
NestedSealedInheritorA
:
NestedSealedClass
()
class
NestedSealedInheritorB
:
NestedSealedInterface
}
\ No newline at end of file
idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/structure.json
已删除
100644 → 0
浏览文件 @
4ed341b1
{
"modules"
:
[
{
"name"
:
"main"
,
"dependsOn"
:
[
"anotherModule"
]
},
{
"name"
:
"anotherModule"
}
],
"fileToResolve"
:
{
"module"
:
"main"
,
"file"
:
"main.kt"
}
}
\ No newline at end of file
idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirMultiModuleLazyResolveTest.kt
浏览文件 @
a0b901b2
...
...
@@ -9,10 +9,8 @@ import com.google.gson.JsonElement
import
com.google.gson.JsonObject
import
com.intellij.openapi.vfs.VirtualFileManager
import
com.intellij.psi.PsiManager
import
org.jetbrains.kotlin.executeOnPooledThreadInReadAction
import
org.jetbrains.kotlin.fir.declarations.FirFile
import
org.jetbrains.kotlin.fir.render
import
org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFir
OfType
import
org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFir
import
org.jetbrains.kotlin.idea.fir.low.level.api.api.getResolveState
import
org.jetbrains.kotlin.idea.jsonUtils.getString
import
org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest
...
...
@@ -49,9 +47,8 @@ abstract class AbstractFirMultiModuleLazyResolveTest : AbstractMultiModuleTest()
val
fails
=
testStructure
.
fails
try
{
val
fir
=
executeOnPooledThreadInReadAction
{
ktFileToAnalyse
.
getOrBuildFirOfType
<
FirFile
>(
resolveState
)
}
?:
throw
AssertionError
(
"Can't build FirFile from ${ktFileToAnalyse.virtualFilePath}"
)
checkFirFile
(
fir
,
path
)
val
fir
=
ktFileToAnalyse
.
getOrBuildFir
(
resolveState
)
KotlinTestUtils
.
assertEqualsToFile
(
File
(
"$path/expected.txt"
),
fir
.
render
())
}
catch
(
e
:
Throwable
)
{
if
(!
fails
)
throw
e
return
...
...
@@ -60,10 +57,6 @@ abstract class AbstractFirMultiModuleLazyResolveTest : AbstractMultiModuleTest()
throw
AssertionError
(
"Looks like test is passing, please remove `\"fails\": true` from structure.json"
)
}
}
protected
open
fun
checkFirFile
(
firFile
:
FirFile
,
path
:
String
)
{
KotlinTestUtils
.
assertEqualsToFile
(
File
(
"$path/expected.txt"
),
firFile
.
render
())
}
}
private
data class
FileToResolve
(
val
moduleName
:
String
,
val
relativeFilePath
:
String
)
{
...
...
idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirMultiModuleResolveTest.kt
浏览文件 @
a0b901b2
...
...
@@ -11,17 +11,16 @@ import com.intellij.psi.PsiFile
import
com.intellij.psi.PsiManager
import
com.intellij.psi.search.FileTypeIndex
import
org.jetbrains.kotlin.fir.FirRenderer
import
org.jetbrains.kotlin.fir.FirSession
import
org.jetbrains.kotlin.fir.builder.RawFirBuilder
import
org.jetbrains.kotlin.fir.declarations.FirFile
import
org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import
org.jetbrains.kotlin.fir.dependenciesWithoutSelf
import
org.jetbrains.kotlin.fir.java.*
import
org.jetbrains.kotlin.fir.psi
import
org.jetbrains.kotlin.fir.resolve.ScopeSession
import
org.jetbrains.kotlin.fir.resolve.firProvider
import
org.jetbrains.kotlin.fir.resolve.providers.impl.FirProviderImpl
import
org.jetbrains.kotlin.fir.resolve.transformers.*
import
org.jetbrains.kotlin.fir.resolve.transformers.FirTransformerBasedResolveProcessor
import
org.jetbrains.kotlin.fir.resolve.transformers.createAllTransformerBasedResolveProcessors
import
org.jetbrains.kotlin.fir.session.FirSessionFactory
import
org.jetbrains.kotlin.idea.KotlinFileType
import
org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo
...
...
@@ -156,15 +155,5 @@ abstract class AbstractFirMultiModuleResolveTest : AbstractMultiModuleTest() {
// KotlinTestUtils.assertEqualsToFile(File("$dirPath/extraDump.java.txt"), javaFirDump)
// }
}
private
fun
createAllTransformerBasedResolveProcessors
(
session
:
FirSession
,
scopeSession
:
ScopeSession
?
=
null
,
pluginPhasesEnabled
:
Boolean
=
false
,
):
List
<
FirTransformerBasedResolveProcessor
>
{
return
createAllResolveProcessors
(
scopeSession
,
pluginPhasesEnabled
)
{
createTransformerBasedProcessorByPhase
(
session
,
it
)
}
}
}
idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirSealedInheritorsTest.kt
已删除
100644 → 0
浏览文件 @
4ed341b1
/*
* Copyright 2010-2020 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.idea.fir.low.level.api
import
org.jetbrains.kotlin.fir.declarations.*
import
org.jetbrains.kotlin.test.KotlinTestUtils
import
org.jetbrains.kotlin.test.util.KtTestUtil
import
org.jetbrains.kotlin.types.typeUtil.closure
import
org.jetbrains.kotlin.utils.addToStdlib.flatMapToNullable
import
java.io.File
/**
* The idea behind this test is to check that [FirIdeSealedHierarchyProcessor] finds all direct inheritors of sealed classes and interfaces.
* We use the fact that [SealedClassInheritorsKt#getSealedInheritors] property gets its value thanks to the class activity.
*
* Inheritors are collected for every sealed declaration of the 'fileToResolve' (see test data 'structure.json'). Resulting collection is
* compared with 'expected.txt'.
*/
abstract
class
AbstractFirSealedInheritorsTest
:
AbstractFirMultiModuleLazyResolveTest
()
{
override
fun
getTestDataPath
():
String
=
"${KtTestUtil.getHomeDirectory()}/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/"
override
fun
checkFirFile
(
firFile
:
FirFile
,
path
:
String
)
{
val
allClasses
=
firFile
.
listNestedClasses
().
closure
{
it
.
listNestedClasses
()
}
val
inheritorNames
=
allClasses
.
flatMap
{
it
.
sealedInheritors
?:
emptyList
()
}.
map
{
it
.
asString
()
}.
sorted
()
KotlinTestUtils
.
assertEqualsToFile
(
File
(
"$path/expected.txt"
),
inheritorNames
.
joinToString
(
"\n"
))
}
}
private
fun
FirDeclaration
.
listNestedClasses
():
List
<
FirRegularClass
>
{
return
when
(
this
)
{
is
FirFile
->
declarations
.
filterIsInstance
<
FirRegularClass
>()
is
FirRegularClass
->
declarations
.
filterIsInstance
<
FirRegularClass
>()
else
->
emptyList
()
}
}
\ No newline at end of file
idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/FirSealedInheritorsTestGenerated.java
已删除
100644 → 0
浏览文件 @
4ed341b1
/*
* 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.idea.fir.low.level.api
;
import
com.intellij.testFramework.TestDataPath
;
import
org.jetbrains.kotlin.test.JUnit3RunnerWithInners
;
import
org.jetbrains.kotlin.test.KotlinTestUtils
;
import
org.jetbrains.kotlin.test.util.KtTestUtil
;
import
org.jetbrains.kotlin.test.TestMetadata
;
import
org.junit.runner.RunWith
;
import
java.io.File
;
import
java.util.regex.Pattern
;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings
(
"all"
)
@TestMetadata
(
"idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
class
FirSealedInheritorsTestGenerated
extends
AbstractFirSealedInheritorsTest
{
private
void
runTest
(
String
testDataFilePath
)
throws
Exception
{
KotlinTestUtils
.
runTest
(
this
::
doTest
,
this
,
testDataFilePath
);
}
public
void
testAllFilesPresentInResolveSealed
()
throws
Exception
{
KtTestUtil
.
assertAllTestsPresentByMetadataWithExcluded
(
this
.
getClass
(),
new
File
(
"idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed"
),
Pattern
.
compile
(
"^([^\\.]+)$"
),
null
,
false
);
}
@TestMetadata
(
"directInheritors"
)
public
void
testDirectInheritors
()
throws
Exception
{
runTest
(
"idea/idea-frontend-fir/idea-fir-low-level-api/testdata/resolveSealed/directInheritors/"
);
}
}
idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirTypeProvider.kt
浏览文件 @
a0b901b2
...
...
@@ -42,7 +42,7 @@ internal class KtFirTypeProvider(
override
fun
buildSelfClassType
(
symbol
:
KtClassOrObjectSymbol
):
KtType
{
require
(
symbol
is
KtFirClassOrObjectSymbol
)
val
type
=
symbol
.
firRef
.
withFir
(
FirResolvePhase
.
SUPER_
TYPES
)
{
firClass
->
val
type
=
symbol
.
firRef
.
withFir
(
FirResolvePhase
.
TYPES
)
{
firClass
->
ConeClassLikeTypeImpl
(
firClass
.
symbol
.
toLookupTag
(),
firClass
.
typeParameters
.
map
{
ConeTypeParameterTypeImpl
(
it
.
symbol
.
toLookupTag
(),
isNullable
=
false
)
}.
toTypedArray
(),
...
...
idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/util/psiUtils.kt
浏览文件 @
a0b901b2
...
...
@@ -5,14 +5,11 @@
package
org.jetbrains.kotlin.idea.util
import
com.intellij.psi.PsiClass
import
com.intellij.psi.PsiElement
import
com.intellij.psi.PsiElementVisitor
import
com.intellij.psi.PsiJavaFile
import
com.intellij.psi.impl.source.tree.LeafPsiElement
import
com.intellij.psi.util.parentOfType
import
com.intellij.psi.util.parentsOfType
import
org.jetbrains.kotlin.asJava.classes.KtLightClass
import
org.jetbrains.kotlin.cfg.containingDeclarationForPseudocode
import
org.jetbrains.kotlin.name.ClassId
import
org.jetbrains.kotlin.name.FqName
...
...
@@ -48,15 +45,3 @@ fun KtClassOrObject.classIdIfNonLocal(): ClassId? {
return
ClassId
(
packageName
,
FqName
(
classesNames
.
joinToString
(
separator
=
"."
)),
/*local=*/
false
)
}
fun
PsiClass
.
classIdIfNonLocal
():
ClassId
?
{
if
(
this
is
KtLightClass
)
{
return
this
.
kotlinOrigin
?.
classIdIfNonLocal
()
}
val
packageName
=
(
containingFile
as
?
PsiJavaFile
)
?.
packageName
?:
return
null
val
packageFqName
=
FqName
(
packageName
)
val
classesNames
=
parentsOfType
<
KtDeclaration
>().
map
{
it
.
name
}.
toList
().
asReversed
()
if
(
classesNames
.
any
{
it
==
null
})
return
null
return
ClassId
(
packageFqName
,
FqName
(
classesNames
.
joinToString
(
separator
=
"."
)),
false
)
}
idea/resources-fir/META-INF/plugin.xml
浏览文件 @
a0b901b2
...
...
@@ -262,7 +262,7 @@ The Kotlin FIR plugin provides language support in IntelliJ IDEA and Android Stu
<definitionsScopedSearch
implementation=
"org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinDefinitionsSearcher"
/>
<methodReferencesSearch
implementation=
"org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinOverridingMethodReferenceSearcher"
/>
<methodReferencesSearch
implementation=
"org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinPropertyAccessorsReferenceSearcher"
/>
<
directClassInheritorsSearch
implementation=
"org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinDirectInheritorsSearcher"
/
>
<
!-- <directClassInheritorsSearch implementation="org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinDirectInheritorsSearcher"/>--
>
<!-- <overridingMethodsSearch implementation="org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinOverridingMethodsWithGenericsSearcher"/>-->
<!-- <annotatedElementsSearch implementation="org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinAnnotatedElementsSearcher"/>-->
<!-- <classesWithAnnotatedMembersSearch implementation="org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinClassesWithAnnotatedMembersSearcher"/>-->
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录