Commit Graph

199 Commits

Author SHA1 Message Date
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
Justin Paupore cd61f545a8 [AA] Clean up typos in KtTypeRenderer. 2023-01-24 14:39:55 +01:00
Justin Paupore eccbc66581 [AA] Add implementation for annotationApplicableTargets.
Adds implementation and tests for the new
KtClassOrObjectSymbol.annotationApplicableTargets property on
KtSymbolInfoProvider. This implementation delegates to the canonical
implementation in AnnotationChecker for FE1.0, and to the implementation
in FirAnnotationHelpers for FIR.

This change also includes direct tests for annotationApplicableTargets,
and a fix for FirClassLikeSymbol.getAllowedAnnotationTargets in
FirAnnotationHelpers.
2023-01-24 14:39:55 +01:00
Dmitrii Gridin 09a77d261d [AA] KtTypeInfoProvider: introduce fullyExpandedType extension
^KTIJ-23547
^KTIJ-24141
2023-01-19 10:53:03 +00:00
Anna Kozlova 6f9cfe1943 [AA] don't treat broken code as function type parameter
inspired by KTIJ-23940
2023-01-17 11:50:20 +00:00
Vladimir Dolzhenko ca31307941 [AA] Add expectForActual
#KT-54864

Merge-request: KT-MR-8222
Merged-by: Vladimir Dolzhenko <Vladimir.Dolzhenko@jetbrains.com>
2023-01-13 21:36:04 +00:00
Dmitriy Novozhilov a3b9f15ecc [AA LC] Create proper Psi types for types with errors inside 2023-01-12 17:45:08 +00:00
Dmitriy Novozhilov 3a536bb32f [AA LC] Approximate anonymous type to single supertype if possible
^KT-55780 Fixed
^KT-55778 Fixed
2023-01-12 17:45:07 +00:00
Justin Paupore 686551d1eb [AA] Add support for printing meta-annotations in annotation tests.
This functionality will be used in follow-on commits.
2023-01-12 19:48:21 +09:00
aleksandrina-streltsova 3a6e3290aa [FIR] KTIJ-24156: Add test data 2023-01-10 20:15:28 +00:00
Ilya Kirillov 61d8b91c89 [Analysis API] add tests for checking KtType internals 2023-01-10 12:54:17 +00:00
Dmitrii Gridin 5a74fec3ac [AA] KtAnnotated: split hasAnnotation to two extensions 2023-01-06 21:09:43 +00:00
Dmitrii Gridin 4626b19fce [AA] KtAnnotated: introduce more flexible search API 2023-01-06 21:09:40 +00:00
Dmitrii Gridin 13917887e0 [AA] KtSymbolPointer: introduce pointsToTheSameSymbolAs method
^KT-55191
2023-01-02 20:00:49 +00:00
Dmitrii Gridin e27ffada26 [AA] KtSymbol: add context receiver to 'createPointer'
^KT-54051
2022-11-29 13:33:46 +00:00
Dmitrii Gridin 55ca2d608b [AA] AbstractSymbolTest: add check for parameters
^KT-54826
2022-11-24 18:32:44 +00:00
Dmitrii Gridin 48e2e5cc87 [AA] AbstractSymbolTest: add type parameters check
^KT-54826
2022-11-24 18:32:43 +00:00
Dmitrii Gridin 771823c9e7 [AA] AbstractSymbolTest: improve implicit checks
^KT-54826
2022-11-24 18:32:42 +00:00
Dmitrii Gridin edd60cd204 [AA] improve symbol pointers for property accessors
Fe10:
* supported default setter
* support default getter
* support parameter from default setter

Fir:
* support java synthetic properties
* support parameter from default setter

^KT-54051
2022-11-24 18:32:41 +00:00
Jinseong Jeon c79d65536b Gracefully handle erroneous super type during local type approximation
^KTIJ-23528 Fixed
2022-11-22 20:16:40 +01:00
Ilya Kirillov f775778efa [Analysis API FIR] fix containing declaration for value parameter
now it should also work for non-source declarations
2022-11-22 18:25:30 +01:00
Dmitrii Gridin d0cc88ffe0 [AA] KtCallableSymbol: introduce receiverType extension
^KT-54417
2022-11-17 09:50:12 +00:00
Dmitrii Gridin 1ebfbc0ee9 [AA] KtCallableSymbol: rename receiver to receiverParameter
^KT-54417
2022-11-17 09:50:12 +00:00
Dmitrii Gridin 2741052db3 [AA] integrate KtReceiverParameterSymbol to KtCallableSymbol
^KT-54417
2022-11-17 09:50:10 +00:00
Yan Zhulanow 4d41ac09df [Analysis API] Treat inapplicable declarations safely (KTIJ-23458)
Make 'getClassOrObjectSymbol()' and 'getNamedClassOrObjectSymbol()'
return 'null' for inapplicable PSI declarations.
2022-11-11 11:28:38 +00:00