56 Commits

Author SHA1 Message Date
Marco Pennekamp 48229f7faa [AA Standalone] Implement getRefinementDependents
^KT-66013
2024-03-18 21:14:36 +00:00
Marco Pennekamp 2060709c03 [AA] Turn KtModuleWithFiles into KtTestModule (AA test framework)
- `KtModuleWithFiles` isn't actually used in a production Standalone API
  context, but it was exposed via `analysis-api-standalone-base`. In
  current production usages, the project structure is built with the
  module builder DSL.
- Hence, `KtModuleWithFiles` is only relevant for tests. This commit
  moves `KtModuleWithFiles` to the Analysis API test framework and
  renames it to `KtTestModule`. This removes any risk that an outside
  user could start using `KtModuleWithFiles` and completely uncouples
  the test project structure from production APIs.
- In addition, we can add the `TestModule` to `KtTestModule`, allowing
  tests to quickly access the original test module, for example to check
  the test module kind.
- The commit also removes the data class status of `KtTestModule` and
  `KtTestModuleProjectStructure` to avoid issues with destructuring when
  properties are added or removed.

^KT-65960
2024-02-26 21:57:23 +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 b7c774b9e5 [Analysis API] Generify 'KtCodeFragmentModule' to support ordinary files
This commit introduces dangling file modules, which may be either
code fragments or ordinary Kotlin files. As before, code fragments are
analyzed against some context element, however ordinary files only
have a context module.

Code fragments can also have a dangling file module as a contextual one,
including other code fragment. This is done to support potential usages
in completion, intentions and refactorings.
2024-01-05 16:04:14 +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
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
strangepleasures 9670de74f1 [AA] KT-61776 Use an implementation of library scope that is immune to Jar cache invalidations
Merge-request: KT-MR-13356
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
2023-12-12 14:05:53 +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
Jaebaek Seo a6c432587f K2: Add extension point for additional KDoc resolution
Similar to K1 KDocLinkResolutionService used by Fe10KDocReference (to
support additional KDoc resolution), this commit adds K2 counterpart
AdditionalKDocResolutionProvider and uses it for KDocReferenceResolver.

^KT-62187
2023-10-12 15:17:31 +00:00
Yan Zhulanow 715f7d1a35 [LL API] Analyze code fragment in a separate 'FirSession'
Before, `KtCodeFragment`/`FirCodeFragment` was analyzed as a part of
its context `KtModule`. This has the following complications:

- In non-source sessions, diagnostic reporting is globally disabled.
  For code fragments, however, checking the code before passing it to
  the backend is essential.

- Special treatment for call ambiguities in libraries
  (`LLLibraryScopeAwareCallConflictResolverFactory`) becomes complicated
  as the conflict resolver has to be applied to a library module.

- `KtCodeFragment`s usually have a shorter lifetime than their own
  context. Caching may potentially be implemented differently for them.

^KT-61783 Fixed
2023-09-22 12:20:05 +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
Ilya Kirillov 714cb67254 [decompiler] add tests for generated psi text by builtin decompiler 2023-08-30 14:45:15 +00:00
Ilya Kirillov e8db349f24 [decompiler] extract builtin VirtualFile creation to a separate service for further reuse
^KTIJ-26760
2023-08-30 14:45:14 +00:00
Yan Zhulanow dbb7e788b2 [LL API] Provide customizable default language version settings 2023-08-30 06:38:44 +00:00
Yan Zhulanow 6413294f3f [Analysis API] Fix module provider for files from dependent sessions
Files coming from dependent sessions might be fully virtual, so there
won't be any backing 'VirtualFile'. However, they generally belong to
their original file's module.
2023-08-07 16:22:02 +00:00
Marco Pennekamp 027fd5600f [AA] KT-58257 Implement KtStaticModuleDependentsProvider (standalone) 2023-07-31 15:58:00 +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
Jinseong Jeon 5596c3ae80 AA: better error message for file w/o containing module
...instead of throwing NoSuchElementException
2023-07-13 11:51:23 +02:00
Jinseong Jeon 0d19a5b3ea AA: make paths platform-independent before using JRT file system
^KT-59697 Fixed
2023-06-28 22:13:16 +02: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
Pavel Mikhailovskii 89c8392255 Make it possible to instantiate StandaloneAnalysisAPISession with a custom clasloader 2023-06-13 13:34:11 +00:00
Ilya Kirillov 78f09409b7 [Analysis API] move ClsKotlinBinaryClassCache/FileAttributeService service registration to StandaloneProjectFactory 2023-06-02 09:16:47 +00:00
Ilya Kirillov fbcf73eb42 [Analysis API Standalone] commonize logic for Analysis API FIR service registration between standalone and tests 2023-06-02 09:16:47 +00:00
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
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
Yan Zhulanow c90d094af6 [LL API] Pass a contextual module to ProjectStructureProvider
In certain cases, it's impossible to determine which module owns a
particular file without knowing the analysis context. For instance,
the file might be a part of a physical module, and be also included into
a virtual ad-hoc module (to be analyzed in separate, e.g. a VCS diff).

The new API allows to pass a contextual module. Basically it means
"give me a module for this element, implying that we are now analyzing a
contextual module".

^KT-57559 Fixed
2023-05-16 08:42:57 +00: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
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
Roman Golyshev d4cffb8a5a [213] Switch to 213 platform
KTI-1114
2023-04-21 13:19:04 +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
Dmitriy Novozhilov b6a41c6d93 [CLI] Extract classes of compiler configuration from :compiler:cli to the separate module
Those classes mainly include KotlinCoreEnvironment and its dependencies

This change is needed for two reasons:
1. Splitting of some common configuration of compiler from logic of CLI
    makes code structure more clean
2. There is a need to add dependency on `:analysis:analysis-api-standalone`
    to `:compiler:cli`, because FIR analogue of AnalysysHandlerExtension uses
    services from it. But the problems is that standalone AA itself depends
    on classes for compiler configuration, which leads to circular
    dependency between those modules. Extracting configuration to
    `:compiler:cli-base` solves the problem
2023-03-16 15:16:32 +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
Marco Pennekamp a777ffcd8a [AA] KT-55566 StandaloneProjectFactory: Setup JDK default module roots
- Setup JDK default module roots in `StandaloneProjectFactory` (compare
  with `KotlinCoreEnvironment`). The implementation is a distilled
  version of `ClasspathRootsResolver`'s default module handling.
- This fixes an issue where some LL FIR tests with JDK 17 and 11 had
  mismatched types between Kotlin and Java sources.

^KT-55566 fixed
2023-01-04 11:46:11 +00:00
Marco Pennekamp e68111c218 [AA] KT-55566 StandaloneProjectFactory: Setup Java language level before Java files are parsed
- LL FIR tests with Java `record` classes and other new syntax features
  failed because `file.packageName` in `findJvmRootsForJavaFiles`
  caused the Java file to be parsed before the Java language level was
  configured. The Java language level is now set up in
  `registerJavaPsiFacade`, which is early enough.
2023-01-04 11:46:10 +00:00
Jinseong Jeon 5bf333f6f5 AA: look up built-ins module for deserialized declarations from built-ins 2022-09-17 16:43:10 +02:00
Jinseong Jeon 1b79ee89ba AA: drop ProjectStructureProvider#getKtBinaryModules
Instead, provide an option to register PSI declaration provider inside
Analysis API session builder where we can retrieve all necessary pieces,
including CoreJarFileSystem, PackagePartProvider, and binary modules
from internal project structure provider.
2022-08-17 19:16:18 +02:00
Ilya Kirillov dd00062559 [analysis] introduce KtBuiltinsModule and remove hacks related to the stdlib module search 2022-07-19 17:17:33 +02:00
Ilya Kirillov dc4527462f [LL FIR] create separate library session for each library 2022-07-19 17:17:33 +02:00
Jinseong Jeon 20d618c0a8 AA: populate CorePackageIndex
so that annotations in package-info.java can be propagated properly
2022-06-28 11:44:41 +02:00
Jinseong Jeon 4af2fcd633 AA: handle lib directory as a binary root 2022-06-21 11:34:09 +02:00
Jinseong Jeon 814920b344 AA: restore JavaRoot from binary roots in JDK module 2022-06-21 11:34:09 +02:00
Jinseong Jeon abdc2cf85e AA: populate SingleJavaFileRootsIndex properly 2022-06-16 22:14:18 +02:00
Jinseong Jeon 5c147c1ded AA: fail-safe binary root lookup 2022-06-09 10:35:17 +02:00
Jinseong Jeon c1b2469e51 AA: register CoreJavaFileManager
in a similar way
KotlinCoreEnvironment.ProjectEnvironment.registerJavaPsiFacade does
2022-06-09 10:35:17 +02:00
Jinseong Jeon af053fd8f3 AA: fail-safe JvmRoot lookup 2022-06-09 10:35:17 +02:00
Jinseong Jeon aef3df0336 AA: introduce AA session and builder 2022-06-09 10:35:16 +02:00
Jinseong Jeon 5585d84808 AA: make utils in StandaloneProjectFactory more general 2022-06-09 10:35:16 +02:00