Commit Graph

103 Commits

Author SHA1 Message Date
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
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 3b9318bd3a [SLC] LazyAnnotationsBox: drop redundant synchronization
We can use less strict rule for produced annotations:
* Previously: the same annotations from `findAnnotation` and `annotations`
have the same identity
* Now: the same annotations from `findAnnotation` and `annotations`
are equals by 'equals'

^KT-56046
2023-02-03 19:49:03 +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 562952080e [LL API] Add tests for 'FileBasedKotlinDeclarationProvider' 2023-01-25 08:04:39 +00:00
Yan Zhulanow f1edbc1a14 [LL API] Add tests for 'out of content root' analysis mode 2023-01-25 08:04:36 +00: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
Marco Pennekamp 88ac5727cc [LL FIR] KT-50732 Add support for LL FIR-specific tests (.ll.kt)
- `.ll.kt` test data can be added in cases where LL FIR resolution
  legally diverges from K2 compiler results.
- Each `.ll.kt` test is prefixed with an `LL_FIR_DIVERGENCE` directive
  which must explain why the test may diverge from K2 compiler results.
  - `LLFirDivergenceCommentChecker` ensures that each `.ll.kt` file
    contains an `LL_FIR_DIVERGENCE` directive.
- `LLFirIdenticalChecker` results in an assertion error if the `.ll.kt`
  test and its base test are completely identical, including in their
  meta info (but ignoring `LL_FIR_DIVERGENCE`).
  - The checker additionally ensures that the base source file and the
    `.ll.kt` source file have identical Kotlin source code (ignoring
    meta info and `LL_FIR_DIVERGENCE`). This ensures that both tests
    test the exact same thing.
- `.ll.kt` files are ignored by select test generators, in addition to
  `.fir.kt` files.
2023-01-16 15:20:50 +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
Justin Paupore fbcde11b04 [AA] Add meta-annotation test for analysis API.
This test ensures that annotations on other annotations are properly
handled, even if those annotations are defined in Java rather than in
Kotlin.

Note that this functionality only works on FIR, and currently has bugs
that mean the result is an error type. Follow-on changes will fix the
error-type bug, and restore proper functionality for FIR.
2023-01-12 19:48:21 +09:00
Ilya Kirillov 20b81464be [Analysis API] fix IndexOutOfRangeException
Previously, the `KtFirUsualClassType.qualifiers` was empty for the local classes

The reason was a RawFirBuilder setting up a containingClassForLocalAttr
to the outer non-local class for the local class. It should be a null instead,
see the localClassType.kt as an example

^KT-55510 fixed
2023-01-10 12:54:18 +00:00
Anna Kozlova d7179d929f [LC] add isEquivalentTo implementation so LC can be referenced from java
otherwise references from java to ktElements won't be treated as references,
cause java references resolve to light elements and search can/should be called
on ktElements
2023-01-09 18:43:57 +00:00
Dmitrii Gridin 6db0aaef35 [SLC] rename test classes according to new directories 2023-01-02 15:05:45 +00:00
Dmitrii Gridin 3e36e51920 [LC] merge ultraLightFacades tests to lightClassByPsi 2023-01-02 15:05:42 +00:00
Dmitrii Gridin 0731780865 [LC] rename ultraLightClasses to lightClassByPsi 2023-01-02 15:05:38 +00:00
Dmitrii Gridin 742c3de112 [LC] rename lightClasses/lightClasses to lightClasses/lightClassByFqName 2023-01-02 15:05:37 +00:00
Dmitrii Gridin eb3ad7e6b1 [LC] move light class related tests to one directory 2023-01-02 15:05:36 +00:00
Dmitrii Gridin b2c0a37050 [SLC] implement infrastructure for light class hierarchy tests 2022-12-13 16:54:25 +00:00
Ilya Kirillov 2378437b30 [Analysis API FIR] do not create resolved KtTypes for unresolved ones 2022-11-11 12:00:00 +01:00
Jinseong Jeon c9a2e10dd7 AA: merge single/multi modules tests for PsiTypeProvider
...because single-module test is also multi-module test
2022-11-02 17:38:16 +01:00
Jinseong Jeon d98081dce2 AA: introduce MPP tests for PsiTypeProvider 2022-11-02 17:38:16 +01:00
Ilya Kirillov e2416f48fe [Analysis API] add tests for containing declaration for delegated member scope 2022-10-26 19:19:04 +00:00
Ilya Kirillov 97df0a0902 [Analysis API] rework containing declaration provider
now it should work for non-source declarations
2022-10-26 19:19:00 +00:00
Dmitrii Gridin b8a64d20ac [AA] restore Fe10IdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated
^KT-54311
^KT-54385
2022-10-17 14:59:50 +00:00
Kristoffer Andersen f765457e51 [K2] isUsedAsExpression analysis 2022-10-05 15:06:52 +00:00
Ilya Kirillov 49f2f85927 [Low Level FIR] fix exception when creating symbol by invalid code 2022-10-04 12:56:07 +00:00
Ilya Kirillov 2d7218b542 [Analysis API FIR] fix test generation 2022-10-03 16:02:23 +02:00
Ilya Kirillov cd5b9d6356 [Analysis API] do not generate standalone tests which use compiler plugin 2022-09-21 09:44:24 +02:00
Jinseong Jeon e50da634bc AA: add tests for resolution to built-ins 2022-09-17 16:43:12 +02:00
Vladimir Sukharev c8864369fd Use main class as test generator name
Merge-request: KT-MR-7031
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2022-09-09 12:51:18 +00:00
Jinseong Jeon 846ab7d97b AA: revamp standalone-mode tests 2022-08-17 19:16:17 +02:00
Ilya Kirillov 8856977c78 [Symbol LC] add test for declaration parents 2022-08-10 22:49:12 +02:00
Jinseong Jeon 199219483e FIR LC: set modifier list as a parent of light annotations
^KTIJ-22354 Fixed
2022-08-03 08:57:37 +02:00
Ilya Kirillov 36f370f501 [Analysis API] add tests for KtTypeScope 2022-06-22 09:31:47 +02:00
Ilya Kirillov b9907963fe [Analysis API] add tests for KtSubstitutor 2022-06-22 09:31:47 +02:00
Ilya Kirillov f966959615 [Analysis API] disable not passing new Analysis API tests for FE10 2022-06-22 09:31:46 +02:00
Ilya Kirillov dafb132a17 [Analysis API] add few tests which checks contracts of signature substitutions 2022-06-22 09:31:43 +02:00
Ilya Kirillov 3525e42f11 [Analysis API] introduce substitutor builder 2022-06-22 09:31:43 +02:00
Ilya Kirillov c95ac9f845 [Analysis API] add some basic tests for symbol substitution 2022-06-22 09:31:42 +02:00
Ilya Kirillov a47880a98b [stubs] add test which checks consistency between cls and decompiled stubs 2022-06-20 19:09:44 +02:00
Jinseong Jeon b18999be82 FIR/LC: filter out scripts for facade creation
^KTIJ-22016 Fixed
2022-06-20 17:38:50 +02:00
Mikhail Glukhikh 8fce239209 Generate even more FE10 analysis API tests 2022-05-31 11:34:47 +00:00
Ilya Kirillov b511e449d2 [analysis api] temporary mute Fe10IdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated 2022-05-27 15:37:39 +02:00
Mikhail Glukhikh 049cab5207 Generate more FE10 analysis API tests 2022-05-25 12:04:54 +00:00
Ilya Kirillov 329e495b63 [analysis api, tests] generate analysis api in a separate tests-gen folder 2022-04-13 12:53:14 +02:00
Ilya Kirillov 22918ac2f4 [analysis api, tests] generate standalone tests 2022-04-13 12:53:08 +02:00
Ilya Kirillov 037c50c26b [analysis api, tests] move test classes to corresponding packages 2022-04-13 12:53:06 +02:00
Ilya Kirillov 78685e93d1 [analysis api, tests] move resolve call tests to separate package 2022-04-13 12:53:05 +02:00