Commit Graph

104 Commits

Author SHA1 Message Date
Yan Zhulanow 1b7d1dd08a [Analysis API] Simplify 'getNotUnderContentRootModule()'
In the resulting implementation of dangling file modules,
'getNotUnderContentRootModule()' is never called with a not-null file.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 452d22e14f [Analysis API] Add IGNORE_SELF dangling file resolution mode
In the 'IGNORE_SELF' mode, dangling files don't have their own
declarations in providers. As a result, all references there resolve to
declarations of the original file. It is conceptually similar to that we
had in on-air resolve, however, now it's possible to work with the whole
content of the in-memory 'FirFile'.

As it can be seen in 'ProjectStructureProvider.kt'
(KtFile.danglingFileResolutionMode), the 'IGNORE_SELF' mode is
automatically applied for non-physical files with an original file being
set. For other scenarios, now there is a new 'analyzeCopy()' function
that allows to pass the analysis mode explicitly.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 2899822102 [Analysis API] Extract dangling file module computation
Use the same code for creating dangling file modules inside tests,
the stand-alone API, and in the IDE.
2024-01-05 16:04:14 +00:00
Yan Zhulanow a614d0325f [Analysis API] Move test-only project provider closer to tests 2024-01-05 16:04:14 +00:00
Yan Zhulanow 5179462632 [Analysis API] Support non-JVM platforms in code fragments
The 'evalJs' test is not available, as there is no proper support for
klib loading in non-standalone Analysis API yet.

^KT-64197 Fixed
2024-01-05 16:04:14 +00:00
Yan Zhulanow 75abae23d8 [Analysis API] Fix WITH_STDLIB for common modules in Analysis API tests
The previous implementation in 'TestModuleStructureFactory' had very
custom and redundant logic for binary dependency collection.
In particular, JDK and kotlin-stdlib were specifically computed,
although both already were in the module classpath, which was handled in
'createLibrariesByCompilerConfigurators()'. In addition, there was no
support for common modules.

The new behavior is much closer to what happens in production.
2024-01-05 16:04:14 +00:00
Dmitrii Gridin 6c7d1babf0 [Analysis API] support Java compilation in tests
Previously we just skipped Java sources.
The order of classes in light classes test data is changed due to
differences in implementations of `compileLibraryToJar` and `runJvmCompiler`

^KT-62892
2024-01-03 21:35:12 +00:00
Dmitrii Gridin 8de9d42b0d [Analysis API] use createSearchScopeByLibraryRoots for test libraries
As it is more similar to production. Also, fixed scope search for klib.
Now we register main binary modules before to avoid duplication with
libraries from createLibrariesByCompilerConfigurators as now we can
have a declared library and regular sources

^KT-62888
^KT-62651
2024-01-03 13:39:42 +00:00
Dmitrii Gridin 02d99769ff [Analysis API] Use library name in result jar
^KT-62888
^KT-62651
2024-01-03 13:39:41 +00:00
Dmitrii Gridin 282cd82539 [Analysis API] AnalysisApiFirSourceTestConfigurator: supports mixed multi-module tests
^KT-64468
2023-12-21 19:48:22 +00:00
Dmitrii Gridin c0b333dfc1 [Analysis API] AbstractAnalysisApiBasedTest: exit from ignored tests before any analysis
It is possible that `prepareToTheAnalysis` will throw an exception for
ignored test

^KT-64468
2023-12-21 19:48:22 +00:00
Dmitrii Gridin 00db7fdaeb [Analysis API] mark MODULE_KIND directive as module-level
^KT-64468
2023-12-21 19:48:22 +00:00
Dmitrii Gridin d1cb9ab060 [Analysis API] TestModuleKind: introduce moduleKind util
^KT-64468
2023-12-21 19:48:22 +00:00
Marco Pennekamp d3d21b3f34 [AA] Support multi-module tests with mixed KtModule kinds
- This commit adds a `MODULE_KIND` directive to Analysis API tests which
  can be used to change a test module's `KtModule` kind from the default
  determined by the test's registered `KtModuleFactory` (which in turn
  depends on the `moduleKind` configured during test generation).
- The most important use case is the ability to have multi-module tests
  where a main module references symbols from a binary library module.
  This use case requires source configurations to compile libraries,
  which requires additional setup. This will be implemented in a
  following commit.

^KT-64468 Fixed
2023-12-21 19:48:22 +00:00
Marco Pennekamp bba5447b12 [Test/AA] Pass project disposable to getOrCreateApplicationEnvironment instead of application disposable
- The disposable passed to `getOrCreateApplicationEnvironment` should
  not actually be the application environment's disposable, which is
  created inside the function. Instead, it should be the project's
  disposable, which is used to track how many projects still rely on the
  shared application environment.
- This issue wasn't apparent before because there is no visible
  consequence when an application isn't disposed after all projects have
  been disposed (during tests). However, the solution for KT-63650
  relies on application environments being disposed after all projects
  are disposed, so that a new application environment with a different
  configuration can be created. (Only one shared application environment
  may be active at the same time.)

^KT-63650
2023-12-19 11:12:23 +00:00
Jinseong Jeon 10c9b81c79 AA standalone: introduce multi-module binary dependency test 2023-12-19 07:03:29 +00:00
Ilya Gorbunov d2aae67e03 Replace kotlin-test project dependencies in the project
Use dependency helper function that chooses whether to take them
from the bootstrap repository or from a configuration of kotlin-test

KT-61969
2023-12-13 15:40:25 +00:00
Sergej Jaskiewicz f844a86057 [utils] Introduce the bind function and use it throughout 2023-12-13 10:04:45 +00:00
Pavel Kirpichenkov fb9bf1782e [AA] Fall back to JVM stdlib dependencies in common test modules
Returns the old test behavior, until KT-63769 is implemented.
2023-12-01 18:12:23 +00:00
Pavel Kirpichenkov 0eb1a63a2f [AA] Add symbol tests for symbols from JS klibs
Use test compiler runner to compile JS libraries. Determine compiler
by the specified TARGET_PLATFORM. Add tests for dynamic type and
JS-specific .proto extensions.

Refactor the code for mock library compilation to make the switch
between platforms more straightforward.

KTIJ-27566
KT-63217
2023-12-01 18:12:23 +00:00
Artem Olkov 54c2339dfb [Analysis API] [Test Infra] move (de)compilation services
move (de)compilation services from static dependencies into DI
This is done for allowing different (de)compile strategies in the future


Merge-request: KT-MR-13213
Merged-by: Artem Olkov <artem.olkov@jetbrains.com>
2023-11-24 10:58:49 +00:00
Marco Pennekamp 1870189e47 [AA] Fix write access configuration in unit test application environments
- We cannot configure the application's write action accessibility on a
  per-test basis because (1) the application may be shared across
  concurrent tests and (2) the application is usually cached, so the
  configuration will be missed entirely.
- There is actually a much easier solution to allow write access
  selectively: We can enable it in `runWriteAction` blocks, and keep it
  in a thread local to support concurrent test runs. As Analysis API
  tests never call `runWriteAction`, there will be no "analyze cannot be
  called from a write action" error, and if `analyze` is somehow called
  from a write action, it will now be caught.

^KT-63560 fixed
2023-11-20 16:29:26 +00:00
Marco Pennekamp 03a7162f37 [AA] Enable test-specific configuration of write access permissions
- In general, Analysis API tests forbid write access because the
  Analysis API should not be used from write actions. However, in some
  cases we might want tests to e.g. modify PSI, which requires write
  access. This change allows `AnalysisApiTestConfigurator`s to enable
  write access for the specific test.
2023-11-16 19:50:51 +00:00
Marco Pennekamp 6189d68c3c [AA] Refactoring: Provide default implementations for functions of AnalysisApiTestServiceRegistrar
- Most inheritors of `AnalysisApiTestServiceRegistrar` only need to
  override one or two functions.
2023-11-16 19:50:51 +00:00
Ilya Kirillov a18c49d795 [LL FIR] retrieve Kotlin/Native KLib dependencies for compiled based tests
Previously, all tests were considered as JVM-only
from the library dependencies point of view.

^KT-62910
2023-11-10 06:41:03 +00:00
Ilya Kirillov d2b9b487c7 [Analysis API] add test for resolution into declarations with the kotlin. package
^KT-63223
2023-11-08 17:32:49 +00:00
Ilya Kirillov 063d73fa73 [Analysis] migrate analysis modules to use cliArgument helper instead of hardcoded CLI argument names
^KT-63294
2023-11-08 17:32:48 +00:00
Dmitrii Gridin 8e623ee73a [LL FIR] support script tests 2023-10-24 19:32:54 +00:00
Dmitrii Gridin 0771b60777 [Analysis API] support multiplatform test cases
^KT-62345
2023-10-17 17:19:40 +00:00
Dmitrii Gridin 2cac922cd0 [FIR] add tests on external annotations
Tests are excluded in COMPILED_JAVA mode because in this
mode external annotations are not present at all

^KT-62310
2023-10-13 12:16:12 +00:00
Brian Norman 365ce2a6a5 [FIR] Implement checker for missing dependency supertypes
#KT-60778 Fixed
2023-10-04 21:57:43 +00:00
Alexander.Likhachev 6eaccc997f [Build] Fix the typo junit jupyter -> jupiter 2023-09-06 22:47:34 +00:00
Alexander.Likhachev 6f96be0b76 [Build] Get rid of the testApiJUnit5 method
#KTI-1349 In Progress
2023-09-06 22:47:34 +00:00
Ilya Kirillov 97a7c0b6ff [Analysis API Standalone] extract functions for getting GlobalSearchScope by roots to utils
^KT-60884
2023-09-06 07:36:11 +00:00
Dmitrii Gridin 2421d3cdf1 [LL FIR] ClassId: add more tests
^KTIJ-26848
^KTIJ-26896
^KTIJ-26902
2023-09-05 12:58:50 +00:00
Yan Zhulanow dbb7e788b2 [LL API] Provide customizable default language version settings 2023-08-30 06:38:44 +00:00
Dmitrii Gridin 5557ea690d [AA] add generated tests for scripts
^KT-61431
2023-08-28 15:02:24 +00:00
Dmitrii Gridin bef5f89f61 [AA] add configurator for scripts
^KT-61431
2023-08-28 15:02:24 +00:00
Ilya Kirillov 1b0034b6e7 [Analysis API] allow AbstractSingleSymbolByPsi to accept <expr>-based section in addition to <caret>-based 2023-08-17 13:01:02 +00:00
Ilya Kirillov 729bae4a2a [Analysis API] refactoring, add utilities to ExpressionMarkersSourceFilePreprocessor which return null in a case caret/selected expression are not found 2023-08-17 13:01:02 +00:00
Dmitrii Gridin d19a23aae5 [LL FIR] implement tests on dependent copy session analyze
^KT-60987
2023-08-09 15:22:57 +00:00
Yan Zhulanow a09c2a485e [LL API] Add basic tests for 'ContextCollector' 2023-08-07 16:22:02 +00:00
Marco Pennekamp 7fd8e4d0fd [AA] Standalone Analysis API: Introduce KtStaticProjectStructureProvider
- `registerServicesForProjectEnvironment` relied on lists of all modules
  and source files, which the standalone project structure providers
  would have already been able to provide with the right interface.
- In `StandaloneAnalysisAPISessionBuilder.build`, to get all modules and
  source files, `projectStructureProvider` had to be hard-casted to
  `KtModuleProviderImpl`.
- This commit introduces `KtStaticProjectStructureProvider`, a shared
  interface for project structure providers with static module
  structures that know about their modules and source files.
2023-07-31 15:58:00 +00:00
Marco Pennekamp 0c94a3131c [AA] KT-58257 Add API for subscription-directed invalidation
- The commit refactors some modification trackers previously provided by
  `KotlinModificationTrackerFactory` to a subscription-directed
  mechanism implemented via `MessageBus` and `KotlinTopics`. The
  following modification trackers are affected:
  - Module out-of-block modification: The FE10 Analysis API doesn't use
    these modification trackers, so the effect is limited to LL FIR.
  - Module state: Likewise, FE10 doesn't use this modification tracker,
    so again the effect is limited to LL FIR.
- Project and library modifications trackers remain, because many small
  objects in e.g. light classes depend on these trackers (making
  listener management unfeasible), and they are not relevant for
  `LLFirSession` invalidation.
- This new API paves the way for a session invalidation service to
  subscribe to out-of-block and module state changes as events. This
  removes the need to iterate through modification trackers.
  - Also note that the out-of-block modification provided by the new
    subscription mechanism is intended to work for _any_ `KtModule`, as
    long as it makes sense to have out-of-block modifications. For
    example, the subscription should work for script modules. The OOB
    modification tracker previously only supported `KtSourceModule`s,
    which required separate single-file modification trackers for script
    and not-under-content-root modules.
- `MessageBus` is a general utility provided by IntelliJ, but usually it
  is retrieved from `project`. To keep these two concerns decoupled,
  `project.messageBus` should not be used directly. Instead, the commit
  adds a `KotlinMessageBusProvider`, which for now just provides the
  project message bus with its standard implementation, but allows
  swapping out the message bus implementation later.
- Global changes are also supported by the new subscription API. Such
  global changes may for example occur during cache invalidation in
  tests, on global PSI tree changes, or when an SDK is removed.
- Test-only invalidation has been moved from
  `KotlinModificationTrackerFactory` to a new
  `KotlinGlobalModificationService`. This creates one central service
  for invalidation between tests, which is easier from an implementation
  and a usage perspective than calling multiple scattered services and
  providers.
2023-07-31 15:58:00 +00:00
Dmitrii Gridin c01c113af4 [AA] implement infrastructure for scripts
^KT-60728
2023-07-27 12:02:04 +00:00
Dmitrii Gridin e5cd674f33 [AA] split KtSourceModuleImpl on separate files
^KT-60728
2023-07-27 12:02:04 +00:00
Dmitrii Gridin c2fd245ca1 [LL FIR] getSelectedElement should return PsiElement
^KT-60518
2023-07-19 10:32:10 +00:00
Dmitriy Novozhilov 73b580572b [FE] Move @PrivateForInline optIn into :core:compiler.common
This is needed to be able to use it in backend modules too
2023-07-17 21:02:40 +00:00
Pavel Kirpichenkov 630c8e9df6 [AA, tests] Limit scopes of test libraries to their roots, add JDK_HOME
Without the fix, all libraries share the global scope for all project
libraries. JDK_HOME was used implicitly for things such as providing
Record support, but was not included as a test library/sdk.

KT-59637
2023-06-27 10:29:22 +00:00
Jinseong Jeon 799aadfacf AA: add an option to create Application env for production v.s. test mode
...and use production mode by default for AA standalone

^KT-59511 Fixed
2023-06-22 11:32:29 +02:00