Commit Graph

223 Commits

Author SHA1 Message Date
Ilya Kirillov feaf9acd1d [Analysis API] move KotlinFakeClsStubsCache service registration to StandaloneProjectFactory
so it can be used from standalone mode
2023-06-02 09:16:47 +00:00
Ilya Kirillov 452844ffc6 [Analysis API] move KotlinReferenceProvidersService service registration to StandaloneProjectFactory
so it can be used from standalone mode
2023-06-02 09:16:47 +00:00
Ilya Kirillov 9f2d750f98 [Analysis API] move KtResolveExtensionProvider EP registration to common code
so it can be used from standalone mode
2023-06-02 09:16:47 +00:00
Marco Pennekamp a50e839660 [LL FIR] Add multi-module resolve extension reference resolve tests
- To test the reference resolution of declarations provided through
  resolve extensions of module dependencies, we need support for
  multimodule resolve extension tests.
2023-05-31 18:34:42 +00:00
Marco Pennekamp 915c412929 [AA] KT-58580 Add KotlinDeclarationProviderMerger
- A proper merging strategy for declaration providers is required for
  cases where the main declaration provider created by
  `createDeclarationProvider` can't provide all declarations that the
  original declaration providers can provide. Then, only a sublist of
  the declaration providers should be merged, while keeping the
  unmergeable declaration providers intact.

^KT-58580 fixed
2023-05-31 18:34:42 +00:00
Ilya Kirillov 9829a2bf98 [LL FIR] fix contract violation exception from Java Resolution
When we create `SmartTypePointer` directly inside `JavaSymbolProvider`,
the Java resolution is called which is forbidden inside the
`JavaSymbolProvider`.

Instead, the lazy `JavaElementTypeSource` for JavaType is created,
which creates a `SmartTypePointer` outside `JavaSymbolProvider`.

^KT-58194
2023-05-31 13:01:19 +00:00
Ilya Kirillov 2d08d29dac [Java Resolution] use a smart psi pointer to store PSI in JavaElement for IDE
`JavaElement`s are reused between read actions, so underlying PSI elements might be invalidated when using hard PSI references

^KT-58194 fixed
2023-05-31 13:01:19 +00:00
Ilya Kirillov f8ddf204e2 [Analysis API] add KtTypeScope.getCallableSignatures/getClassifierSymbols overloads which accept a candidate name set
This is needed for the cases when a candidate name set is known
to avoid retrieving a set with all possible names when processing the scope.

Similar to KtScope.

^KT-58653
2023-05-19 11:53:15 +00:00
Ilya Kirillov ee1fd9f6e9 [Analysis API] optimize composite scope
Do not create KtCompositeScope for empty or single scopes
2023-05-19 11:53:15 +00:00
Ilya Kirillov 41976a2932 [Analysis API] optimize scope members processing when a candidate name set is known
Use KtScope.getCallableSymbols/getClassifier symbols overloads which accept a candidate name set.

^KT-58653
2023-05-19 11:53:15 +00:00
Ilya Kirillov 29be88e3c9 [Analysis API] add KtScope.getCallableSymbols/getClassifier symbols overloads which accept a candidate name set
This is needed for the cases when a candidate name set is known
 to avoid retrieving a set with all possible names when processing the scope.

^KT-58653 fixed
2023-05-19 11:53:15 +00:00
Yan Zhulanow c6d8876f9f [LL API] Pass the project instance to ProjectStructureProvider
Eliminate unnecessary PSI tree traversal by providing the 'Project'
instance explicitly.
2023-05-16 08:42:57 +00:00
Yan Zhulanow e9c077220f [LL API] Migrate 'getKtModule()' usages to 'ProjectStructureProvider'
Ensure the contextual module is passed wherever possible.

^KT-57559 Fixed
2023-05-16 08:42:57 +00:00
Ilya Kirillov 4c69f2fbcb [Analysis API] fix "Unexpected class FirTypeProjectionWithVarianceImpl" exception
from KtFirExpressionTypeProvider.getKtExpressionType

^KTIJ-23432 fixed
2023-05-11 20:44:31 +02:00
Anna Kozlova 5ca052f87b [LL] [cls] use stubBased symbol provider for builtins
this gives the following benefits:
1. no protobuf in memory, all data is already present in stubs
2. given that symbol provider for libraries is already stub based,
we can get rid of complicated code to find source psi by deserialized fir
3. it's also possible to reduce number of index access,
when fir is requested for given ktElement
2023-05-09 07:36:09 +00:00
Ilya Kirillov ba3a3915c7 [Analysis API] tests: use tagged caret to find declaration to analyze in the air against
We cannot use a KtFile as analysis context.

^KT-55527
2023-05-04 15:26:50 +00:00
Ilya Kirillov eeac3f53b4 [Analysis API] add tests for getImportingScopeContext
^KT-57966
2023-05-04 15:26:50 +00:00
Ilya Kirillov 254092a267 [Analysis API FIR] tests: add ability to ignore specific scope kind in TestScopeRenderer
^KT-57966
2023-05-04 15:26:50 +00:00
Ilya Kirillov 67041851fc [LL FIR] tests: extract scope rendering utilities to a separate object
For further reuse

^KT-57966
2023-05-04 15:26:50 +00:00
Ilya Kirillov e9f75b1350 [LL FIR] add test which checks reference shortening for the whole file
^KT-57966
2023-05-04 15:26:50 +00:00
Ilya Kirillov bb7037aa8e [LL FIR] extract shortening rendering for tests to a separate file
So it can be reused from other tests

^KT-57966 fixed
2023-05-04 15:26:50 +00:00
Nikolay Krasko 3caa1d1349 Refactoring: fix usages of @TestOnly ExtensionsArea.registerExtensionPoint 2023-04-28 08:25:19 +00:00
Anna Kozlova d59d66e876 [AA, LL] use stubs to build deserialized Fir elements in IDE
^KTIJ-24638

Notice on `DebugSymbolRenderer`:
stub based deserializer sets source directly,
but it's available in IDE mode only.
Thus, standalone and IDE tests have different results.
In order to avoid this, sources for compiled code are explicitly ignored

Notice on distinct callables:
for a file which belong to multiple libraries, decompiled code would be build per library.
In order to avoid ambiguity errors for members in that file,
we need to distinct provided elements by origins
failed test from IJ repo:
 FirReferenceResolveWithCrossLibTestGenerated#testSetWithTypeParameters
2023-04-27 11:37:28 +00:00
aleksandrina-streltsova 2cc3b542fd [Analysis API FIR] Initialize properties of KtCallableSignature lazily 2023-04-27 10:59:30 +00:00
Roman Golyshev d4cffb8a5a [213] Switch to 213 platform
KTI-1114
2023-04-21 13:19:04 +00:00
Dmitrii Gridin d66b919c12 [AA] introduce tests on annotation stability
^KT-57849
2023-04-21 10:14:05 +00:00
Ilya Kirillov 0d0b1b7945 [Analysis API] add ability for a custom element navigation for a KtResolveExtensionFile
^KT-57930
2023-04-19 16:09:05 +00:00
Ilya Kirillov 51eaa3f9cf [Analysis API] provide tests for the KtResolveExtensionProvider
^KT-57930
2023-04-19 16:09:05 +00:00
Ilya Kirillov d68587de77 [Analysis API] implement API to extend Kotlin resolution by generated declarations
^KT-57930 fixed
2023-04-19 16:09:04 +00:00
aleksandrina-streltsova e8272fa02e [Analysis API] Move testdata for scope provider 2023-03-20 22:04:48 +00:00
aleksandrina-streltsova 4b7164a557 [Analysis API] Allow handling scopes from KtScopeContext separately
^KT-55527
2023-03-20 22:04:48 +00:00
Yan Zhulanow c33bedb417 [LL API] Simplify 'KtFirAnalysisSessionProvider'
The 'CachingKtAnalysisSessionProvider' was only used in
'KtFirAnalysisSessionProvider', and reasons why it was created
(reusing code between FE10 and K2 session provider implementations)
is not actual anymore.
2023-03-14 09:46:37 +00:00
aleksandrina-streltsova 3d0bca5ca1 [Analysis API] Handle missed cases in PsiElement.getExpectedType()
^KTIJ-24256
2023-03-09 09:19:00 +00:00
Artem Vasilev 564d44b16d [FIR] Test for duplicate filtering for overrides from Java 2023-03-03 11:06:19 +00:00
Ilya Kirillov 4944b454c5 [Analysis API] optimize KotlinPackageProvider.getSubPackageFqNames
Previously, we queried heavy kotlin package provider two times which affected performance
Now it's being queries only a single time

Also, the commit introduces separation for KotlinPackageProvider between kotlin and platform-specific packages

^KTIJ-24640
2023-02-28 13:38:23 +00:00
Jiaxiang Chen 7ce2f64c18 AA: apply java type enhancement to declaredMemberScope.
* added getDeclaredMemberScope to JavaScopeProvider.
2023-02-24 19:57:10 +01:00
Jinseong Jeon 5455942859 AA: handle underscore as type arguments
^KTIJ-24742 Fixed
2023-02-23 13:02:34 +01:00
Ilya Kirillov 803c3b88ac [Analysis API] fix exception on symbol restore when symbol cannot be seen from the use-site module
^KT-56763 fixed
2023-02-20 11:01:32 +00:00
Ilya Kirillov ee1b018c9a [Analysis API] introduce a helper test function to get carets at multimodal tests 2023-02-20 11:01:31 +00:00
Ilya Kirillov 769fb835f9 [Analysis API] introduce a KotlinResolutionScopeProvider to optimize the resolutions scope in the IDE 2023-02-13 11:35:24 +01:00
Ting-Yuan Huang 42b08d411b [FIR] Pass container when creating FunctionType
so that it can be resolved when type annotations are demanded.
2023-02-08 19:43:24 +00:00
Jaebaek Seo a09d0aa1cf Handle SHORTEN_IF_ALEADY_IMPORTED case of KtFirReferenceShortener
For the following example, when we run the reference shortener, it
drops `a.b.c` qualifier, because it matches "FOURTH".
```
package a.b.c

fun <T, E, D> foo(a: T, b: E, c: D) = a.hashCode() + b.hashCode() + c.hashCode() // FIRST
fun <E> E.foo() = hashCode() // SECOND

object Receiver {
    fun <T, E, D> foo(a: T, b: E, c: D) = a.hashCode() + b.hashCode() + c.hashCode() // THIRD
    fun foo(a: Int, b: Boolean, c: String) = a.hashCode() + b.hashCode() + c.hashCode() // FOURTH
    fun test(): Int {
        fun foo(a: Int, b: Boolean, c: Int) = a + b.hashCode() + c // FIFTH
        return <expr>a.b.c.foo(1, false, "bar")</expr>
    }
}
```

As shown in the above example, when SHORTEN_IF_ALEADY_IMPORTED option is
given from a user, the reference shortener has to check whether it can
drop the qualifier without changing the referenced symbol and if it is
possible to do that without adding a new import directive, it deletes
the qualifier.

It needs two steps:
 1. Collect all candidate symbols matching the signature e.g., function
    arguments / type arguments
 2. Determine whether the referenced symbol has the highest reference
    priority when we drops the qualifier depending on scopes

This commit uses `AllCandidatesResolver(shorteningContext.analysisSession.useSiteSession).
getAllCandidates( .. fake FIR call/property-access ..)` for step1.
For step2, we use a heuristic based on scopes of candidates. If a
candidate symbol is under the same scope with the target expression, it
has a `FirLocalScope` which has the high priority. So when we have a
candidate under a `FirLocalScope` and the actual referenced symbol is
different from the candidate, we must avoid dropping its qualifier
because the shortening will change its semantics i.e., reference.

The order of scopes depending on their scope types is:
 1. FirLocalScope
 2. FirClassUseSiteMemberScope / FirNestedClassifierScope
 3. FirExplicitSimpleImportingScope
 4. FirPackageMemberScope
 5. others

Note that for "others" the above rule can be wrong. Please update it if
you find other scopes that have a priority higher than the specified
scopes.

One of non-trivial parts is the priority among multiple
FirClassUseSiteMemberScope and FirNestedClassifierScope. They are
basically scopes for class declarations. We decide their priorities
based on the distance of class declaration from the target expression.

Note that we take a strict approach to reject all false positive. For
example, when we are not sure, we don't shorten it to avoid changing its
semantics.

TODO: One corner case is handling receivers. We have to update
```
private fun shortenIfAlreadyImported(
    firQualifiedAccess: FirQualifiedAccess,
    calledSymbol: FirCallableSymbol<*>,
    expressionInScope: KtExpression,
): Boolean
```

The current implementation cannot handle the following example:
```
package foo
class Foo {
    fun test() {
        // It references FIRST. Removing `foo` lets it reference SECOND.
        <caret>foo.myRun {
            42
        }
    }
}
inline fun <R> myRun(block: () -> R): R = block()         // FIRST
inline fun <T, R> T.myRun(block: T.() -> R): R = block()  // SECOND
```

Tests related to TODO:
 - analysis/analysis-api/testData/components/referenceShortener/referenceShortener/receiver2.kt
 - analysis/analysis-api/testData/components/referenceShortener/referenceShortener/receiver3.kt
2023-02-08 18:39:12 +00:00
Dmitrii Gridin 93232a23df [AA] introduce AnnotationUseSiteTargetFilter to simplify API
^KT-56046
2023-02-03 19:49:01 +00:00
Dmitrii Gridin 6e25b45f7d [AA] introduce KtAnnotationApplication
^KT-56046
2023-02-03 19:49:01 +00:00
Dmitrii Gridin 3a7602a38f [AA] KtAnnotationsList: introduce 'annotationOverviews'
it provides a solution for several problems with redundant resolve.
It is a more powerful tool than 'annotationClassIds'

^KT-56046
2023-02-03 19:48:57 +00:00
Dmitriy Novozhilov 89c42e20c9 [FIR] Consistently use _function_ instead of _functional_ in names of classes and functions 2023-02-02 08:24:52 +00:00
Dmitriy Novozhilov 67aa80562d [FE] Completely replace FunctionClassKind with FunctionalTypeKind
FunctionalTypeKind can be used in FE 1.0 too, so there is no need to
  keep both classes. Also, removal of FunctionClassKind simplifies work
  with FunctionalTypeKind in common code, like Analysis Api
2023-02-02 08:24:50 +00:00
Anna Kozlova 30fd34c2d7 [CLI] free cached values
^ KTIJ-24447
2023-02-02 08:03:05 +00:00
Anna Kozlova b415aa7446 [FIR] take ready implicit unit type instead of return type calculation
and assert that symbol is not a substitution/intersection override
in the `compute` method otherwise.

Because `fakeOverrideSubstitution` should be calculated for all real
implicit types, no call to this method should actually happen.

Otherwise, it can be problematic to create a session
which would contain the full designation path:
`provider.getFirCallableContainerFile(symbol)`
returns `firFile` of a super class which might be from module `a`,
when declaration and its outer classes are from module `b`.

^KTIJ-24105
2023-01-31 11:21:17 +00:00
Yan Zhulanow f6f667c387 [LL API] Adjust services required by LLFirBuiltinsSessionFactory
As 'initialiseVirtualFileFinderServices()' that is run during
test initialization collects transitive dependencies, all of them
must be ready. However, 'KtNotUnderContentRootModuleForTest' has a
built-in dependency provided by 'LLFirBuiltinsSessionFactory'.
2023-01-25 08:04:40 +00:00