Commit Graph

277 Commits

Author SHA1 Message Date
Yan Zhulanow 834cbaac5a [LL API] Run fir2ir separately for files in different modules
Each module may have its own compiler configuration.

^KTIJ-27061 Fixed
2023-09-21 06:19:15 +00:00
Marco Pennekamp 3add7f9db5 [AA] Support enum entry initializers in member scope tests
- Now that the enum entry initializer provides a member scope, not the
  enum entry, we need a way to get to the enum entry initializer in
  tests. This can only be done via the enum entry's name, because the
  initializer is anonymous.

^KT-61425
2023-09-08 11:13:28 +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 1f290828e5 [Analysis API Standalone] use the full version of jdk root finding from IJ
partial ones only work for jdk >= 9

^KT-60884
2023-09-06 07:36:11 +00:00
Ilya Kirillov 8f824dcff9 [Analysis API Standalone] copy JdkClassFinder from IntelliJ sources
^KT-60884
2023-09-06 07:36:11 +00:00
Ilya Kirillov 56910b70a3 [Analysis API] fix "KotlinIllegalStateExceptionWithAttachments: expected as maximum one expect for the actual"
^KT-61597 fixed
2023-08-31 15:19:29 +00:00
Yan Zhulanow b96c1a644f [LL API] Fix code fragment compilation in library sources (KT-61383)
In complex projects, there might be several library copies (with the
same or different versions). As there is no way to build a reliable
dependency graph between libraries, a project library depends on all
other libraries. As a result, there might be several declarations in the
classpath with the same name and signature.

Normally, K2 issues a 'resolution ambiguity' error on calls to such
libraries. It is acceptable for resolution, as resolution errors are
never shown in the library code. However, the backend, to which
'evaluate expression' needs to pass FIR afterwards, is not designed for
compiling ambiguous (and non-completed) calls.
2023-08-30 06:38:44 +00:00
Yan Zhulanow 4b80c2197f [Analysis API] Run code fragment compilation tests against libraries 2023-08-30 06:38:44 +00:00
Dmitrii Gridin adc853ebd0 [AA] extend SymbolData API to support scripts
^KT-61431
2023-08-28 15:02:24 +00:00
aleksandrina-streltsova aa0eca6d6d [AA] Provide KtCallableSymbol for static Java members
^KTIJ-25126 Fixed
2023-08-24 22:17:48 +03:00
Roman Golyshev 10df37ba8e KTIJ-26423 [AA] Return more info from KtFirImportOptimizer
Deprecate `unusedImports`, since they are supposed to be computed
on the IDE side from now on based on the information from
Analysis API

Currently the `unusedImports` property is not removed completely
so it can still be used by the Kotlin side import optimizer
tests; they should be moved/adapted to the intellij repository
also
2023-08-21 10:46:58 +00:00
Ilya Kirillov 2ce324f1fc [Analysis API] rename AbstractSingleSymbolByPsi -> AbstractSingleSymbolByPsiTest
to match test naming convention
2023-08-17 13:01:02 +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
Pavel Kirpichenkov c0c234e1d2 Minor: rename files to source files in configurators for standalone mode
KT-59793
2023-08-17 12:03:10 +00:00
Pavel Kirpichenkov ef6375f627 [LL] Use package provider to check for existing package
KT-59793
2023-08-17 12:03:08 +00:00
Yan Zhulanow 5a67b0d7dc [LL API] Correct used IR symbols in code fragments
As 'FirCodeFragments' are converted to IR independently of its context,
in some cases duplicate (and not quite correct) symbols for local
classes and functions are created.

Until properly fixed in fir2ir, here we replace such duplicates with
original symbols.
2023-08-08 17:26:39 +00:00
Yan Zhulanow e1db3c88cf [LL API] Support code fragment compilation 2023-08-07 16:22:01 +00:00
Yan Zhulanow 02af189066 [LL API] Support code fragment analysis 2023-08-07 16:22:01 +00:00
Marco Pennekamp e3d803de8b [AA] KT-58257 Prepare KtResolveExtension API for active invalidation
- `KtResolveExtension`s need to participate in active invalidation,
  because LL FIR sessions depend on changes in resolve extension files.
- The resolve extension will simply be able to use the
  `KotlinModificationSubscriptionService`, which is part of the Analysis
  API surface for **API implementors**, to publish modification events.
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
Yan Zhulanow 7821ef0414 [Analysis API] Make 'KtCompiledFileForOutputFile' an internal API 2023-07-27 10:23:42 +00:00
Yan Zhulanow 0f6f22d76b [Analysis API] Add API for code compilation
The API replaces 'KotlinCompilerIde' in the IntelliJ IDEA plugin.
Code moved to Analysis API as its K2 implementation severely depends on
the internal compiler API (FIR).

The API is going to be used in the JVM debugger evaluator, and in
the Bytecode Tool Window.

In this commit, only ordinary Kotlin are supported.
In later commits, there will be also support for 'KtCodeFragment' files,
as well as some test coverage.
2023-07-27 10:23:42 +00:00
Pavel Kirpichenkov b316aa7d1d [AA] stub-based library symbol providers for non-JVM platforms
Use existing stub-based JVM library symbol provider for .knm and
.kotlin_metadata files. The only real difference is the scope filtering
by file types

KT-58769
2023-07-25 09:15:29 +00:00
aleksandrina-streltsova ca25162574 [AA] implement isExpect/isActual for KtClassLikeSymbol
KT-54846
2023-07-24 17:24:41 +00:00
Anna Kozlova 40a6c81d97 [AA] retrieve overridden symbols for parameter from generated property
Merge-request: KT-MR-11215
Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
2023-07-24 11:09:56 +00:00
Roman Golyshev b8052761db KT-60341 [Analysis API] Provide a type for a FirNameReference only when it refers to an actual property/variable
We cannot always return null, because in such case some expressions
would become not fully explorable from the types perspective (see
the documentation on the `getCorrespondingTypeIfPossible`)

`FirNamedReference` might appear when resolving method references (like
`foo::bar`), but also when IJ Platform tries to resolve other parts of
the Kotlin PSI, notably a `KtNameReferenceExpression` in a
function call (`bar` in `foo.bar(baz)` expression).

N.B. FE10 implementation does not support returning `null` as a type -
currently it always returns `Unit` type in case it cannot figure out
the actual type. This issue should probably be tackled together with
KT-60166, so that both implementations are more or less aligned

^KT-60341 Fixed
^KT-59077 Fixed
^KTIJ-25745 Fixed
2023-07-19 22:01:37 +00:00
Dmitrii Gridin c2fd245ca1 [LL FIR] getSelectedElement should return PsiElement
^KT-60518
2023-07-19 10:32:10 +00:00
Ilya Kirillov 08400d930f [Analysis API, FIR] migrate ::class.java -> ::class inside error messages
They seem to provide similar results and the `.java` part is redundant
2023-07-18 11:49:21 +00:00
Ilya Kirillov 4b523825be [Analysis API] forbid providing custom KtLifetimeToken for every analyze call
^KT-60488 fixed
2023-07-18 08:47:34 +00:00
Justin Paupore 9f85739599 [AA] Add KtResolveExtensionInfoProvider to AA.
This provider is responsible for answering queries related to resolve
extensions. At the moment, this includes retrieving a KtScope with all REx
top-level declarations (moved from KtSymbolFromResolveExtensionProvider), and
retrieving information necessary to supply a GeneratedSourcesFilter for REx
generated code. Future REx-related functions can be added to this interface.

^KT-59329
2023-07-14 19:32:09 +02:00
Justin Paupore fa0209a322 [AA] Expand functionality of TestScopeRenderer.
- Add package and constructor listings
- Add single-scope renderForTests() implementation, including a lambda
  to provide additional information about each symbol
- Remove special handling for empty scopes (interfered with single-scope
  rendering)

^KT-59329
2023-07-14 19:32:08 +02:00
Justin Paupore f01b824751 [AA] Show symbol origins in REx tests.
This is in preparation for adding a separate KtSymbolOrigin for
resolve extension symbols.

^KT-59351
2023-07-14 19:32:08 +02:00
Justin Paupore 734b87b97e [AA] Allow specifying REx file contents in testdata.
Tests can now specify the code generated by a resolve extension from
within the test's testdata. Module-level directives control whether
resolve extensions are enabled for that module, as well as package names
and source shadowing regexes. File-level directives allow a `// FILE:`
block within the testdata to be converted into a KtResolveExtensionFile
and removed from the module as a whole. (This requires a new
`ModuleStructureTransformer`, because we need to be able to entirely
remove the files in question.)

Any test can add support for these directives by calling
`KtResolveExtensionTestSupport.configure` from within their
`configureTest` stanza. This allows this functionality to be used in
conjuction with any test base class.

^KT-59329
2023-07-14 19:32:08 +02:00
Egor Kulikov 27f4b53570 [FIR] Do not expect builtin imports to be always resolved
Merge-request: KT-MR-10886
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-07-05 14:02:50 +00:00
aleksandrina-streltsova 88f2bf85eb [AA] Test shortener for the whole file with different options 2023-07-04 16:34:51 +00:00
aleksandrina-streltsova 67c3849538 [Analysis API] Shortener: enable shortening in KDoc
^KTIJ-21103
2023-07-04 16:34:51 +00:00
Ilya Kirillov 8b0eb0488f [Analysis API] add method for implicit companion object reference detection
Add a new method `isImplicitReferenceToCompanion` to determine
if the given reference is an implicit reference to a companion object.

The method is needed for the rename refactoring in IJ.

^KTIJ-25863
2023-06-30 13:43:30 +00: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
Anna Kozlova ce76db1636 [AA] introduce KtKeywordsRenderer to support nonmodifier keywords filter 2023-06-26 16:21:20 +00:00
Jinseong Jeon e0fc0d96e5 AA: handle PsiType conversion for recursive type parameter case
^KT-59598 Fixed
2023-06-23 16:31:47 +02:00
Vladimir Dolzhenko d0477a6a30 Provide equals/hashCode based on original PSI to avoid potential PCEs
#KT-59445
2023-06-22 14:14:18 +00:00
Roman Golyshev ac92c129bf KT-59093 [Analysis API] Remove unnecessary resolveCall overloads from KtCallResolverMixIn
^KT-58161 Fixed
2023-06-21 20:40:22 +00:00
Mikhail Glukhikh 7fd441f16a Analysis API: add normal FE10 import optimizer (taken from plugin code) 2023-06-21 12:04:31 +02:00
Anna Kozlova f80ed4592d [AA] Handle KtTypeReference children in CompileTimeConstantProvider
CompileTimeConstantProvider could receive a reference expression,
whose grandparent is KtTypeReference (seen that in UAST inspection).
FIR would not contain anything explicit for this reference,
FirResolvedTypeRef would be received as the nearest parent.
Of course, in this case, there could be no compile time constant anyway.
2023-06-15 07:06:41 +00:00
Dmitrii Gridin 7631e90f12 [LL FIR, Java] fix resolve contract violation from java symbol provider from permits
To create a smart psi type pointer, IJ Platform uses resolve
We cannot use resolve from JavaSymbolProvider,
as it may lead to resolve contract violation

^KT-59243 Fixed
2023-06-14 09:25:26 +00:00
Dmitrii Gridin 6992a707dc [LL FIR, Java] fix resolve contract violation from java symbol provider from supertypes
To create a smart psi type pointer, IJ Platform uses resolve
We cannot use resolve from JavaSymbolProvider,
as it may lead to resolve contract violation

^KT-59240 Fixed
2023-06-12 16:41:26 +00:00
Ilya Kirillov 95cf892eec [Analysis API] extract the data from the ShortenCommandImpl to the base class
^KT-58992
2023-06-09 14:45:23 +00:00
Ilya Kirillov b8f15cbbb3 [LL FIR, Java] fix resolve contract violation from java symbol provider
To create a smart psi type pointer, IJ Platform uses resolve.
We cannot use resolve from JavaSymbolProvider, as it may lead to resolve contract violation.

^KT-59133 fixed
2023-06-08 14:13:30 +00:00