Compare commits

...

190 Commits

Author SHA1 Message Date
Yan Zhulanow
3f71d364d5 Update Changelog for Kotlin 1.2.31 2018-03-23 14:45:20 +03:00
Natalia Selezneva
f4049e630c Fix compatibility with LivePlugin
^KT-23371 Fixed

(cherry picked from commit c7513b5)
2018-03-22 17:21:58 +03:00
Renaud Paquay
ad38c3e226 Hitting breakpoint in Kotlin sometimes doesn't work (KT-22205)
Fix KT-22205 and https://issuetracker.google.com/issues/71556313

Hitting breakpoints in Kotlin JUnit test with an Android Gradle
project sometimes(*) does not work in Android Studio 3.1 beta.

(*) The issue is related to various threads running concurrently
with "dumb" mode background code, so the issue reproduces only
on certain configurations.

In a nutshell, the issue is as follows

* On one hand, gradle build finishes, fires an event ("buildFinished")
  that is processed "later" and that causes the IDE to enter "dumb" mode
  for a shot amount of time (about 300-500 msec on a somewhat up to date
  multi-core computer).

* On the other hand, once the JVM of the debuggee is started, breakpoints
  need to be resolved (on the debugger thread, through a call to
  com.intellij.debugger.engine.CompoundPositionManager.createPrepareRequests.
  This code calls into the "KotlinPositionManager.createPrepareRequests",
  which in turns calls into "PerFileAnalysisCache.analyze". That method
  returns "AnalysisResult.EMPTY" is the project is in dumb mode.
  This return value prevents callers from successfully resolving
  the source location into a breakpoint.

Given that the 2 code paths above execute on separate threads without
explicit synchronization, the "failed to resolve breakpoint" issue
occurs sporadically, to the point it happens 100% of the time on
certain configuration.

The fix is so wrap the kotlin breakpoint resolution code inside
a "runReadActionInSmartMode" so that the debugger thread "waits"
for "dumb" mode to terminates before trying to resolve breakpoint
locations.

 #KT-22205 Fixed

(cherry picked from commit 94ee78c)
2018-03-22 11:18:39 +03:00
Vyacheslav Gerasimov
8ddcd36770 Build: add maven.repository.mirror property
May be used to add additional repository to all projects
2018-03-21 14:01:06 +03:00
Natalia Selezneva
ec490af6ee Restore old package for ScriptTemplatesProvider.
Note that this is EP used in another plugins (ex. LivePlugin https://plugins.jetbrains.com/plugin/7282-liveplugin)

(cherry picked from commit 82481b4)
2018-03-21 12:40:33 +03:00
Alexander Podkhalyuzin
0a92d9ccce Fixed broken exception reporter
(cherry picked from commit 7d72fe0)
2018-03-21 12:29:05 +03:00
Dmitry Savvinov
e43175b16f Add changelog for 1.2.31 2018-03-16 13:12:05 +03:00
Denis Zharkov
3d798b4cd3 Regenerate tests for androidx support annotations 2018-03-14 15:33:51 +03:00
Denis Zharkov
c425e02dff Add a reference to third-party/annotations/androidx in license 2018-03-14 15:33:51 +03:00
Jake Wharton
7150fc0d8f Add support for nullability annotations in androidx package. 2018-03-14 15:33:51 +03:00
Sergey Igushkin
f100e83ec3 Fix binary incompatibility with Android Gradle plugin 3.2.0-alpha06
Remove a non-reflective usage of the ResourceSet class, which has been
moved to a different package between versions. Access it through
reflection instead. This is a workaround. We can introduce a proper
fix once we have a public API in the Android plugin.

The test case that could detect the compatibility issue is
`testAndroidExtensionsManyVariants` (it uses experimental Android
extensions), but we did not run it with 3.2.0-alpha6. This commit
adds a test class with the same tests for 3.2.0-alpha6.

Issue #KT-23192 Fixed

(cherry picked from commit 0039be6)
2018-03-14 04:36:45 +03:00
Alexey Sedunov
715431535a Remove Redundant Backticks: Fix inspection applicability
#KT-22804 Fixed

(cherry picked from commit a194eb9)
2018-03-13 19:48:08 +03:00
Alexander Podkhalyuzin
f5d8479635 Kotlin SDK auto-creation is disabled now #KT-23059 Fixed 2018-02-28 12:25:43 +03:00
Alexey Sedunov
2619dc5e0d Minor: Fix NPE
#KT-22724 Fixed

(cherry picked from commit 1bc6f5c)
2018-02-26 12:14:00 +03:00
Ilya Gorbunov
97848dd194 Update paths of the moved sources for building the documentation 2018-02-26 11:25:58 +03:00
Stanislav Erokhin
814858a2b7 Move runtime.jvm sources to stdlib/jvm/runtime
Update path in kotlin-runtime
Update path in kotlin-mock-runtime-for-tests
2018-02-26 11:25:57 +03:00
Simon Ogorodnik
8acc3c0b97 Propose convert to string template as inspection more frequent 2018-02-22 20:06:20 +03:00
Zalim Bashorov
0a829be3db Add missed references to license/README.md 2018-02-22 20:06:19 +03:00
Denis Zharkov
5a0d10464a Convert SwitchCodegen to Kotlin, prettify and optimize codegen 2018-02-22 11:47:41 +03:00
Mikhail Glukhikh
559e0848d8 Downgrade LoopToCallChainInspection to INFORMATION level
(cherry picked from commit fda4072)
2018-02-21 14:30:24 +03:00
Dmitry Jemerov
44d21c0db5 Fix ISE in KotlinPairMatcher.getCodeConstructStart()
(cherry picked from commit 9e30ede)
2018-02-21 10:59:38 +01:00
Yan Zhulanow
e50c18bbd6 Evaluator: Send class bytecode array in loop with a limited chunk size (#KT-22967)
JDI in Android has a limited byte buffer size (8192), and we must not exceed it.
2018-02-20 23:17:18 +03:00
Yan Zhulanow
8719796d97 Use thread-safe WeakHashMap implementation in annotation-based IDE plugins (#KT-22514) 2018-02-20 23:17:17 +03:00
Nicolay Mitropolsky
d2ff212b43 LightAnnotations: wrapping all PsiLiterals (not only Strings)
(cherry picked from commit bc543b4)
2018-02-20 18:02:59 +03:00
Denis Zharkov
fbaf90bc60 Add @SinceKotlin("1.2") to kotlin.suspend 2018-02-20 12:00:32 +03:00
Dmitry Petrov
88f8102bed Turn off intrinsics for 'withIndex' in 1.2.3x 2018-02-20 08:49:52 +03:00
Ilya Chernikov
c7533b91f9 Add missing reflect dependency to the gradle plugin
fixes #KT-22895
2018-02-19 17:19:16 +01:00
Denis Zharkov
f4c2f5d164 Prohibit labeled returns inside kotlin.suspend argument lambdas
Probably, it would be more correct to skip such lambdas when resolving
the returns' references, but it'd be more complicated and still useless
since non-local returns are impossible in such lambdas
(relevant parameter is noinline)

 #KT-22900 Fixed
2018-02-19 17:31:38 +03:00
Mikhail Zarechenskiy
fb940cec71 Improve message for exception about absence of common supertype
Relates to #KT-16253
2018-02-19 17:18:23 +03:00
Mikhael Bogdanov
25a136aeb2 Revert "Don't generate hash in sam wrapper class name"
This reverts commit 08f7829
2018-02-19 14:13:24 +01:00
Nikolay Krasko
9a00dc3355 Expression can be parenthesized on replace with if (KT-22874, EA-91186)
#KT-22874 Fixed
2018-02-19 13:00:33 +03:00
Nikolay Krasko
fbc01468dc Fix class cast exception in KotlinFunctionParameterInfoHandler (EA-91186) 2018-02-19 13:00:22 +03:00
Nikolay Krasko
fc43cb4767 Disable outdate runtime check for developers builds
We can't update them properly anyway.
2018-02-19 13:00:12 +03:00
Nikolay Krasko
7ffb405968 Fix isModified check in Kotlin compiler tab (KT-22851)
outputPostfix and outputPrefix is saved with nullize in apply, but
modification check was without it.

 #KT-22851 Fixed
2018-02-19 13:00:01 +03:00
Denis Zharkov
cd95e7ae16 Fix CCE caused by KotlinPackageSourcesMemberNamesIndex
FileContentImpl::getPsiFile is not-nullable and at the same time
it contains an explicit case of its fileType to LanguageFileType
that leads to the following exception in case when kt-file is marked as plain text:

java.lang.ClassCastException: com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeFactory$1 cannot be cast to com.intellij.openapi.fileTypes.LanguageFileType
	at com.intellij.util.indexing.FileContentImpl.createFileFromText(FileContentImpl.java:135)
	at com.intellij.util.indexing.FileContentImpl.getPsiFile(FileContentImpl.java:104)

 #EA-114338 Fixed
2018-02-19 10:32:25 +03:00
Ilya Gorbunov
cb0d27ca0d kotlin-test-testng: change actual package name for test annotation typealiases
to avoid potential split package situation

(cherry picked from commit 8c8caa4)
2018-02-14 23:52:32 +03:00
Alexey Tsvetkov
f75a5ff905 Avoid removing target/classes dir during IC in Maven
#KT-21581 fixed
2018-02-14 18:17:19 +03:00
Dmitry Savvinov
fee60f4f40 Update changelog for 1.2.30 2018-02-14 13:10:03 +03:00
Vyacheslav Karpukhin
64c1e9d345 Do not use hardcoded plugin ID for update checks
When Kotlin plugin is bundled into another plugin, there won't be a plugin with ID org.jetbrains.kotlin registered in PluginManager, which leads to runtime exceptions. To fix that let's determine the plugin ID dynamically instead.
2018-02-12 17:53:23 +03:00
Nikolay Krasko
3c61760a70 Collect statistics of used defaults set in formatting (KT-22252)
^KT-22252 In Progress
2018-02-12 17:53:22 +03:00
Anton Bannykh
9a8f283d6b JS: fix corner case in when translation (fix crash in KT-22544)
(cherry picked from commit cd3a797f2a)
2018-02-12 17:18:53 +03:00
Ilya Gorbunov
e089919ab8 Remove configureDist call not yet available in this branch 2018-02-12 15:36:55 +03:00
Alexey Sedunov
73eb07b6c4 Gradle: Fix dependency import when "module per sourceset" is disabled
#KT-22360 Fixed

(cherry picked from commit b315e0c)
2018-02-12 15:22:56 +03:00
Alexey Sedunov
8abc113f14 Configuration: Set up Kotlin SDK (if necessary) on plugin startup
#KT-22590 Fixed

(cherry picked from commit e1aec46)
2018-02-12 15:22:19 +03:00
Ilya Gorbunov
66177fb184 Add documentation for kotlin-test-testng artifact
(cherry picked from commit 0f130a0)
2018-02-12 08:27:32 +03:00
Ilya Gorbunov
6875bb4628 Select the asserter based on test framework presence in classpath
Simplify asserter lookup: enumerate all AsserterContributors when
the file class with lookupAsserter function is initialized.

It's assumed that AsserterContributor initialization should be fast.

#KT-21154 Fixed

(cherry picked from commit 5e3edf4)
2018-02-12 08:27:32 +03:00
Ilya Gorbunov
30945b8081 Include kotlin-test-testng into dist, setup JDK 7 required to run tests
(cherry picked from commit 9dfa54e)
2018-02-12 08:27:32 +03:00
Ilya Gorbunov
5a0dced10f Minor: kotlin-test reformat sources, fix test package names
(cherry picked from commit d1f00a9)
2018-02-12 08:27:32 +03:00
Valeriy Zhirnov
a2a340dd74 TestNG support in kotlin.test #KT-22620
(cherry picked from commit ad77019)
2018-02-12 08:27:32 +03:00
Nikolay Krasko
b42592c947 Store selected set of defaults in code style settings (KT-22252)
#KT-22252 In Progress

(cherry picked from commit 1e56743)
2018-02-11 22:18:53 +03:00
Nikolay Krasko
c903ce5d00 Control serialize/deserialize of CommonCodeStyleSettings
(cherry picked from commit 5d25b8b)
2018-02-11 22:17:35 +03:00
Nikolay Krasko
ce09e4cbbb Collect statistics about used Kotlin formatter
(cherry picked from commit 5a9ea89)
2018-02-11 22:16:54 +03:00
Nikolay Krasko
682c8723a6 Fix testInGlobalPropertyWithGetter test in 173 branch
Workaround for IDEA-185462. It was introduced in 173 idea and
fixed in 181.

(cherry picked from commit d1e6a61)
2018-02-11 22:13:42 +03:00
Mikhail Zarechenskiy
18bdede561 Fix type parameters indexes of MockClassDescriptor
Exception was thrown during mapping of arguments to parameters in `computeSupertypeProjections`

 #KT-18522 Fixed
2018-02-11 16:31:29 +03:00
Yan Zhulanow
d8b400a725 REPL, minor: Ignore empty lines (#KT-21611)
(cherry picked from commit 310ee67c35)
2018-02-09 19:26:41 +03:00
Yan Zhulanow
7c6641ae8c Kapt: Allow Kotlin @Repeatable annotations (KT-22451)
We don't generate a wrapper for repeatable annotations, and Javac complains to it.

(cherry picked from commit edcf0aef53)
2018-02-09 19:11:49 +03:00
Alexey Sedunov
233b0627c5 Configuration: Show Koltin plugin path as "home path" of Kotlin SDK
#KT-22640 Fixed

(cherry picked from commit e5e583e)
2018-02-09 15:07:30 +03:00
Alexey Sedunov
b5fc34be29 Create from Usage: Support target directory selection for "Create class"
#KT-22152 Fixed

(cherry picked from commit 84fed80)
2018-02-09 15:07:30 +03:00
Alexey Sedunov
592dc00fb4 Rename: Support retargeting/shadowing conflict checking for functions
#KT-22564 Fixed

(cherry picked from commit 695a2a4)
2018-02-09 15:07:29 +03:00
Alexey Sedunov
71bb9326b6 Rename: Fix qualified expression replacement for the case 'invoke' <-> 'get'
#KT-22705 Fixed

(cherry picked from commit 5c6bba9)
2018-02-09 15:07:29 +03:00
Alexey Sedunov
68fac8bc2d Refactor: Move canMoveLambdaOutsideParentheses() function to idea-core module
(cherry picked from commit fffd74f)
2018-02-09 15:07:29 +03:00
Alexey Sedunov
594fa29d0f J2K: KtArrayAccessReference
(cherry picked from commit 4870586)
2018-02-09 15:07:29 +03:00
Alexey Sedunov
556dcc53b6 J2K: KtArrayAccessReference (rename to .kt)
(cherry picked from commit 9150322)
2018-02-09 15:07:28 +03:00
Alexey Sedunov
e4eabfa961 Rename: Add quotes to declaration name if necessary
#KT-22708 Fixed

(cherry picked from commit e88f146)
2018-02-09 15:07:28 +03:00
Alexey Sedunov
d16ad96a41 Refactor: Move 'isIdentifier' and 'quoteIfNeeded' functions to frontend
(cherry picked from commit 428b086)
2018-02-09 15:07:28 +03:00
kenji tomita
62dc54b449 Inspection to get rid of unnecessary ticks in references #KT-18124 Fixed
(cherry picked from commit 1875d12)
2018-02-09 15:07:27 +03:00
Alexey Sedunov
6465536491 Change Signature: Support implicit calls of 'invoke' and 'get'
Also drop 'operator' keyword when necessary

 #KT-22718 Fixed

(cherry picked from commit fddfbf2)
2018-02-09 15:07:27 +03:00
Alexey Sedunov
e37f801aeb Slicer: Sort tree nodes to produce stable test data
(cherry picked from commit c602c51)
2018-02-09 15:07:27 +03:00
Alexey Sedunov
5bb938331b Rename: Substitute synthetic expression parent before analysis
This fixes rename conflicts test

(cherry picked from commit adca8eb)
2018-02-09 15:07:26 +03:00
Alexey Sedunov
4221ca0f8a Rename: Update test data (follow-up for unnecessary reformatting fix)
(cherry picked from commit 049439c)
2018-02-09 15:07:26 +03:00
Alexey Sedunov
e4cabda82d Rename: Make improvements for "by-convention" calls
- Convert between conventions call for 'get' and 'invoke'
- Drop 'operator' when converting 'get'/'invoke' to something other than
  'invoke'/'get' respectively

 #KT-12365 Fixed

(cherry picked from commit f35af11)
2018-02-09 15:07:25 +03:00
Alexey Sedunov
f3d9c09340 Rename: Replace name identifiers via AST to prevent unwanted reformatting
#KT-8563 Fixed

(cherry picked from commit caeb594)
2018-02-09 15:07:25 +03:00
Alexey Sedunov
4e41040dd7 Rename: Support KtTypeAlias in RenameKotlinClassProcessor
#KT-21719 Fixed

(cherry picked from commit 58bf42c)
2018-02-09 15:07:25 +03:00
Alexey Sedunov
6785341ab1 Loop to Call Chain: Do not generate lambda with double wrapping block
#KT-22476 Fixed

(cherry picked from commit 90392a8)
2018-02-09 15:07:24 +03:00
Alexey Sedunov
17b17ed90e Move Class to Top Leve: Suggest file name based on new class name
#KT-17977 Fixed

(cherry picked from commit 8c9c160)
2018-02-09 15:07:24 +03:00
Alexey Sedunov
73c0ee4035 Kotlin Ultimate: Support NodeJS CLI run configuration
#KT-16710 Fixed

(cherry picked from commit 4d52bf0)
2018-02-09 15:07:24 +03:00
Alexey Sedunov
4da7a0b3b1 Gradle: Import production output path for JavaScript modules
(cherry picked from commit 1f7fab8)
2018-02-09 15:07:24 +03:00
Alexey Sedunov
b09803c65e Kotlin Ultimate: Add "Build" action to JS run configurations
#KT-20522 Fixed

(cherry picked from commit 80887a8)
2018-02-09 15:07:23 +03:00
Alexey Sedunov
1d36a4601a Kotlin Ultimate: Support Jest run configurations for Kotlin sources
#KT-21531 Fixed

(cherry picked from commit 82a997e)
2018-02-09 15:07:23 +03:00
Alexey Sedunov
e6126e399e JS: Drop obsolete "Kotlin (JavaScript)" run configuration
#KT-21312 Fixed

(cherry picked from commit 2c0af79)
2018-02-09 15:07:23 +03:00
Sergey Igushkin
e04c32ca4d Delay kapt dependencies resolution from configuration phase
Store kapt configurations instead of classpath files in the tasks
Delay wrapping kapt subplugin options to task execution (when the
classpath can be safely resovled)

Issue #KT-18821 Fixed

(cherry picked from commit e8cd8b5)
2018-02-09 14:56:34 +03:00
Ilya Chernikov
5b4844b11e Pass previous dependencies to the legacy script dependency resolvers
fixes #KT-22753

(cherry picked from commit e38d539)
2018-02-09 11:06:45 +01:00
Rodrigo B. de Oliveira
e12052d6eb Make Kotlin Idea plugin aware of the Gradle initscript template
See gradle/kotlin-dsl#662

(cherry picked from commit de57951)
2018-02-09 11:06:24 +01:00
Dmitry Jemerov
df53bee809 Indent default parameter values
#KT-22508 Fixed

(cherry picked from commit 3aaad0c)
2018-02-09 10:51:15 +01:00
Dmitry Jemerov
8923464bb6 No space between label and lambda in labeled expressions
#KT-22301 Fixed

(cherry picked from commit 5bb195d)
2018-02-09 10:51:04 +01:00
Dmitry Jemerov
a9124635aa Do not indent closing bracket of array access expression
#KT-22641 Fixed

(cherry picked from commit 8f9b818)
2018-02-09 10:50:53 +01:00
Dmitry Jemerov
55f35404e1 Call chain indentation logic that actually makes sense
#KT-22346 Fixed

(cherry picked from commit 36f5525)
2018-02-09 10:50:43 +01:00
Dmitry Jemerov
15129e6e0b Group all call chain-related tests in a single directory
(cherry picked from commit 2c88b26)
2018-02-09 10:50:26 +01:00
Mikhail Glukhikh
e7eec55da0 Redundant object type check: fix problem highlighting #KT-22484 Fixed
(cherry picked from commit d554a42)
2018-02-09 11:08:29 +03:00
Mikhail Glukhikh
65f5c6d8ef Redundant object type check: use referential equality, forbid for when
So #KT-22538 Fixed

(cherry picked from commit 901ae08)
2018-02-09 11:08:11 +03:00
Mikhail Glukhikh
3874facce0 Reformat: RedundantObjectTypeCheckInspection
(cherry picked from commit fbe6929)
2018-02-09 11:07:55 +03:00
Mikhail Glukhikh
5f4943fd6b Detect library kind in Gradle if name looks like non-JVM
Related to KT-20971

(cherry picked from commit 198b054)
2018-02-09 11:07:40 +03:00
Mikhail Glukhikh
c690b8d9db Search for source of platform binary also in common sources
So #KT-20971 Fixed

(cherry picked from commit dcbb29e)
2018-02-09 11:07:23 +03:00
Mikhail Glukhikh
b7f87cf76e SourceNavigationHelper: reformat + style fix
(cherry picked from commit 76976f7)
2018-02-09 11:07:07 +03:00
Denis Zharkov
35c1d06dbc Minor. Remove irrelevant JAVAC_EXPECTED_FILE directive in tests
This change fixes these tests
2018-02-09 10:55:52 +03:00
Yan Zhulanow
620fdf3881 REPL: Fix crash on trying to :load with incorrect filename (KT-12037)
(cherry picked from commit 0238575a36)
2018-02-08 20:46:10 +03:00
Yan Zhulanow
e39e8632ac Debugger: (EA-112731) Do not crash miserably if we don't know the anonymous class name
Continue to log the exception, avoid breaking UX

(cherry picked from commit a25e93d82a)
2018-02-08 19:39:04 +03:00
Yan Zhulanow
2c3a3bd5c4 Kapt: Register additional source directories without modifying the raw Gradle model
Unfortunately, this works only for the newer Android Studio versions, so we need to keep the old code until IDEA will migrate at least to AS 3.1.

(cherry picked from commit 2a3bab0a0f)
2018-02-08 19:39:04 +03:00
Yan Zhulanow
5e65b6eca1 Kapt: Enums inside enum values should be forbidden (KT-22582)
(cherry picked from commit 6c4a2db34b)
2018-02-08 19:39:03 +03:00
Yan Zhulanow
447f796066 Android Extensions: Support '.', '-' and ':' in View identifiers (KT-22700)
(cherry picked from commit 510d5ece0f)
2018-02-08 19:39:03 +03:00
Yan Zhulanow
82ba00112b Kapt: Forbid using the deprecated (original) kapt
(cherry picked from commit ba61a93dc7)
2018-02-08 19:39:03 +03:00
Yan Zhulanow
6542559311 Kapt: Mute Java 9 tests temporarily on Windows
(cherry picked from commit bdd7ab3a09)
2018-02-08 19:39:03 +03:00
Yan Zhulanow
1e0589299a Uast: Fix an exception while converting type alias KotlinType to PsiType (KT-21874)
(cherry picked from commit 03a20384ef)
2018-02-08 19:39:03 +03:00
Yan Zhulanow
0493f3c864 Kapt: Map URLs to absolute file paths properly, also add some logging 2018-02-08 19:39:03 +03:00
Alexander Udalov
5cd5b83d05 Add test on experimental const val in annotation argument
This test checks that a usage inside an annotation argument is a
signature usage, which may be too restricting but easier to support at
the moment (and the restriction can be lifted in the future)
2018-02-08 17:38:05 +01:00
Alexander Udalov
978003eadf Always consider container's experimentality in ExperimentalUsageChecker
This results in more diagnostics usually, but allows library authors to
avoid annotating everything in each experimental class with the marker
(only the class needs to be annotated now)

 #KT-22759
2018-02-08 17:38:05 +01:00
Alexander Udalov
100e148db8 Add getExtensionOrNull utility for protobuf messages 2018-02-08 17:38:05 +01:00
Alexander Udalov
8da4550f95 Add test on Experimental in scripts 2018-02-08 17:38:05 +01:00
Alexander Udalov
d5a49d7c7d Load module annotations in IDE
#KT-22759 Fixed
2018-02-08 17:38:05 +01:00
Alexander Udalov
2d589dec43 Load module annotations for JVM and JS modules in compiler
#KT-22759 In Progress
2018-02-08 17:38:04 +01:00
Alexander Udalov
be1439f5fe JS: write/read module annotation FQ names to/from metadata
#KT-22759 In Progress
2018-02-08 17:38:04 +01:00
Alexander Udalov
3f3c6a9f71 Write/read module annotation FQ names to/from metadata on JVM
#KT-22759 In Progress
2018-02-08 17:38:04 +01:00
Alexander Udalov
005669a935 Add packageProto/nameResolver to JvmPackagePartSource
May be useful for loading platform-specific protobuf extensions (such as
package_module_name on JVM) when analyzing deserialized top level
members
2018-02-08 17:38:04 +01:00
Alexander Udalov
0a66b5c4de Check experimental API markers for deprecation
#KT-22759 In Progress
2018-02-08 17:38:04 +01:00
Alexander Udalov
af8f232bbf Support -Xexperimental/-Xuse-experimental in ExperimentalUsageChecker
#KT-22759 In Progress
2018-02-08 17:38:04 +01:00
Alexander Udalov
e5f2c2580c Support -Xexperimental and -Xuse-experimental, validate their values
#KT-22759 In Progress
2018-02-08 17:38:04 +01:00
Alexander Udalov
3463d5a0d1 Report diagnostic on overrides of experimental members
Unless they're experimental themselves

 #KT-22759 In Progress
2018-02-08 17:38:04 +01:00
Alexander Udalov
e6bb1610ec Do not require experimental propagation for body usages in same module
Unless it's a usage inside the body of an effectively public inline
function

 #KT-22759 In Progress
2018-02-08 17:38:03 +01:00
Alexander Udalov
1471f08731 Add some validation for Experimental/UseExperimental usages
#KT-22759 In Progress
2018-02-08 17:38:03 +01:00
Alexander Udalov
af7bb3f36b Introduce Experimental and UseExperimental annotations
#KT-22759 In Progress
2018-02-08 17:38:03 +01:00
Alexander Udalov
2dbae78a6c Remove unneeded constructor parameters in CallCheckerContext
(cherry picked from commit 0ad3872d1b)
2018-02-08 17:38:03 +01:00
Ilmir Usmanov
14561feada Take coroutineContext into account in RedundantSuspendModifierInspection
#KT-22651: Fixed
2018-02-08 19:34:55 +03:00
Alexander Podkhalyuzin
12f1f521d0 Ask just extensions, not in some area #KT-21978 Fixed
(cherry picked from commit 09d167e)
2018-02-08 19:15:04 +03:00
Denis Zharkov
8778433836 Add @RequireKotlin(1.2.30) for kotlin.suspend
#KT-22562 Fixed
2018-02-08 17:53:27 +03:00
Alexander Udalov
dada8a4207 Support patch versions in RequireKotlin with kind=COMPILER_VERSION 2018-02-08 17:53:27 +03:00
Denis Zharkov
82ce8649c8 Highlight callees resolved to kotlin.suspend as a keywords
#KT-22562 In Progress
2018-02-08 17:53:27 +03:00
Denis Zharkov
9620eb928f Add call checks related to suspend lambda modifier's introduction
- Prohibit non-modifier-like calls on kotlin.suspend
- Add warning on modifier-like calls to anything but kotlin.suspend

 #KT-22766 In Progress
 #KT-22562 In Progress
2018-02-08 17:49:34 +03:00
Denis Zharkov
2ead25467c Imitate support for suspend modifier on parameterless lambdas
#KT-22766 In Progress
2018-02-08 17:48:47 +03:00
Denis Zharkov
99892f352f Minor. Make function private 2018-02-08 17:48:47 +03:00
Denis Zharkov
fba0ababb4 Minor. Inline parameters 2018-02-08 17:48:47 +03:00
Denis Zharkov
c65e3e33cb Ignore @Nullable annotation for vararg parameter
See the comment in code for clarification

 #KT-19786 Fixed
2018-02-08 13:37:06 +03:00
Denis Zharkov
e2e6b1af85 Minor. Reformat signatureEnhancement.kt 2018-02-08 13:36:55 +03:00
Denis Zharkov
68d8c65242 Use extension registry when unpacking serialized type alias
It's funny here that "extension" here means protobuf extensions
while initial issue is about extension function types

 #Fixed KT-22728
2018-02-08 12:39:54 +03:00
Alexander Udalov
047dc8e8cc Update bootstrap to 1.2.40-dev-165
(cherry picked from commit bb013ec2bf)
2018-02-08 10:19:28 +01:00
Alexander Udalov
852a0a07e0 Rename JvmPackageTable -> JvmModuleProtoBuf, PackageTable -> Module
This protobuf message is going to contain more information about the
module than just the table of package parts

(cherry picked from commit ba5cc65792)
2018-02-08 10:19:27 +01:00
Mikhael Bogdanov
08f78291f3 Don't generate hash in sam wrapper class name
#KT-17091 Fixed

(cherry picked from commit 0954d1a)
2018-02-08 10:14:11 +01:00
Nicolay Mitropolsky
cfbb13f4c2 Uast: KotlinUNestedAnnotation with light annotation (IDEA-185890)
(cherry picked from commit 91a4bbe)
2018-02-07 12:56:35 +03:00
Nicolay Mitropolsky
c107ead158 LightAnnotations: wrapping nested annotations with KtLightAnnotationForSourceEntry
(cherry picked from commit cb05baa)
2018-02-07 12:53:39 +03:00
Nicolay Mitropolsky
0061312f8e Uast: KotlinUNestedAnnotation for processing nested annotations (IDEA-185890)
(cherry picked from commit 48ea52d)
2018-02-07 12:51:02 +03:00
Nicolay Mitropolsky
b5987627c7 Uast: support for Kotlin array literals
(cherry picked from commit 8ac95b5)
2018-02-07 12:48:17 +03:00
Mikhail Glukhikh
4020ee6a85 Fix a pack of broken IDE action tests
Related to KT-20281.
For Java resolve we can use also resolve with 'null' platform,
which is possible situation in tests.

(cherry picked from commit 81122ed)
2018-02-07 10:52:27 +03:00
Mikhail Glukhikh
b37a44ca07 Introduce inspection for redundant not-null extension receiver of inline
Related to KT-22303

(cherry picked from commit 7995ae0)
2018-02-07 10:52:00 +03:00
Yan Zhulanow
5c681d6cb5 Kapt: Fix compilation errors when the referenced class has '$' in the beginning of its name (KT-22493) 2018-02-06 22:25:18 +03:00
Yan Zhulanow
196acfb6fe Kapt: Escape nested comments in doc comments (KT-22469) 2018-02-06 22:25:08 +03:00
Yan Zhulanow
db9bbc8202 Kapt: Remove comments inside enum values (KT-22350) 2018-02-06 22:24:57 +03:00
Yan Zhulanow
5e80e1721b Fix "Illegal Android Identifier" inspection reports non-instrumentation unit tests (KT-22168) 2018-02-06 22:24:48 +03:00
Yan Zhulanow
fcdbe482e2 Kapt: Fix array of anonymous type handling (KT-22468) 2018-02-06 22:24:38 +03:00
Yan Zhulanow
90ce7369e8 Minor: Get rid of duplicating option descriptions in Kapt plugin 2018-02-06 22:24:27 +03:00
Yan Zhulanow
aa8a6b1936 Evaluate: Fix compiling evaluator issues led to improper expression caching
1. Do not save a ClassLoader reference inside the context, as we don't use it anyway after evaluation.
This is to avoid custom ClassLoader nesting.

2. Do not use 'findClass()' as it caches the loaded classes and always returns the first evaluated class if it's in cache.
2018-02-06 22:24:17 +03:00
Yan Zhulanow
4eb6071140 Evaluate: Support dex in newer Android build tools 2018-02-06 22:23:23 +03:00
Yan Zhulanow
eea6fa5f19 Kapt: Disable location mapping by default, allow to enable it manually 2018-02-06 22:23:13 +03:00
Yan Zhulanow
8e1222df83 Kapt: Replace original Javac diagnostic messages with those with Kotlin location mapped
There is no Messages dialog in newer versions of IDEA/Android Studio in which the error messages were mapped before. The new Build window shows only the original locations, so now we need to replace Java file diagnostics with ones mapped to Kotlin source files.

The side effect is that diagnostics on the same locations are automatically merged.
2018-02-06 22:23:02 +03:00
Yan Zhulanow
b36a0e6ea8 Kapt: Move line metadata to .kaptMetadata external files (KT-22386)
Placing location table inside .java file triggers annotation processor to run on each line table modification (even when the stub declarations themselves are the same). So we move it to the separate file.
2018-02-06 22:22:52 +03:00
Yan Zhulanow
3960dacde9 Parcelable: Fix 'Simple' test (new boolean serializer) 2018-02-06 22:22:40 +03:00
Yan Zhulanow
cb6a7b556a Parcelable: Add CREATOR field (and other generated declarations) in light classes (KT-19300, KT-19853) 2018-02-06 22:22:30 +03:00
Ilmir Usmanov
1aa9766ae1 Fix continuaion retrieval on generated coroutineContext intrinsic code
Use fake continuation instead on real one in JVM BE.
Pass continuation parameter to closure generator in JS BE.

 #KT-22577: Fixed
2018-02-06 21:19:10 +03:00
Ilmir Usmanov
7a94dadf17 Reformat coroutineContext related code 2018-02-06 21:19:01 +03:00
Mikhail Glukhikh
304d21be91 Show expect / actual gutter even for incomplete compatibility
So #KT-18445 Fixed
So #KT-21115 Fixed

(cherry picked from commit 3ba6b70)
2018-02-06 10:19:36 +03:00
Mikhail Glukhikh
1ba5a7e733 JVM facade: for Java resolve, always use JvmPlatform resolver
So #KT-20281 Fixed

(cherry picked from commit 19beaf5)
2018-02-06 10:16:38 +03:00
Mikhail Glukhikh
d4e5052bfc Introduce inspection for nullable extension receiver of inline function
So #KT-22303 Fixed

(cherry picked from commit c90056f)
2018-02-06 10:16:17 +03:00
Denis Zharkov
6a43ff2a9d Make precise java classes tracking in Gradle enabled by default
#KT-22192 Fixed
2018-02-05 11:56:37 +03:00
Anton Bannykh
0824ea9ad5 JS: fix callable reference with implicit extension receiver (KT-22638 fixed)
(cherry picked from commit 3ead464671)
2018-02-02 14:39:00 +03:00
Ilmir Usmanov
f42c282f90 Move coroutineContext to correct package
from kotlin.coroutines.experimental.instrinsics to kotlin.coroutines.experimental

 #KT-22400
2018-02-01 20:49:24 +03:00
Pavel V. Talanov
8c1dee41e8 JavaResolveExtension: create facade by original element
Fixes semantic difference erroneously introduced in c030a047aa
 #KT-22593 Fixed
2018-01-31 20:23:04 +03:00
Nicolay Mitropolsky
3ddeec6f3b Revert "Light annotations made strictly non-physical (KT-22565)"
This reverts commit 99746b5
It looks like it could bring some issues in IDEA 173, so moving to 181 only
2018-01-31 20:07:18 +03:00
Nicolay Mitropolsky
99746b5094 Light annotations made strictly non-physical (KT-22565)
(cherry picked from commit cf6e21d)
2018-01-31 16:55:15 +03:00
Mikhail Glukhikh
34e8a720df Fix completion test (companion object is allowed in annotation scope)
(cherry picked from commit babcea9)
2018-01-31 14:48:00 +03:00
Mikhail Glukhikh
17d4e92e6c Fix "create enum constant" test (create type alias is no longer here)
(cherry picked from commit 00ceac5)
2018-01-31 14:01:21 +03:00
Nikolay Krasko
5871a5e8e7 Set better defaults on Imports tab in Code Style -> Kotlin (KT-22575)
"Top level symbols" and "Java Statics and Enum Members" are always
returned to 2 after saving to not-number option

 #KT-22575 Fixed
2018-01-31 13:56:24 +03:00
Nikolay Krasko
f99907977e Can't add import for using with '*' in settings (KT-22570)
#KT-22570 Fixed
2018-01-31 13:56:23 +03:00
Nikolay Krasko
1e0b0aa5ce Fix modification check for Kotlin import settings (KT-22557)
#KT-22557 Fixed
2018-01-31 13:56:22 +03:00
Nikolay Krasko
93d8b2b9dc Lost IF_RPAREN_ON_NEW_LINE settings from Kotlin code style 2018-01-31 13:56:21 +03:00
Nikolay Krasko
8cdababa48 Add ability to customize and save IF_RPAREN_ON_NEW_LINE setting 2018-01-31 13:56:20 +03:00
Ilya Chernikov
50f34dbad0 Detect new activity after delayed shutdown correctly
fixes #KT-22549, test
2018-01-31 10:12:32 +01:00
Mikhail Glukhikh
026df68206 Fix two psi checker tests (related to annotation diagnostic / parsing)
(cherry picked from commit f46fa26)
2018-01-31 12:00:06 +03:00
Mikhail Glukhikh
6e75ff5b6b KtVisitor: delegate constructors to KtNamedDeclaration
In particular, enables back "Unused symbol" on constructors

(cherry picked from commit 86f25bf)
2018-01-31 11:59:34 +03:00
Mikhail Glukhikh
0fa5bf7e58 Fix testAnnotation in "member visibility can be private"
(cherry picked from commit 899da99)
2018-01-31 11:58:50 +03:00
Mikhail Glukhikh
6045110e94 Fix parcelize delete creator field test (companion is retained now)
(cherry picked from commit 98b0f91)
2018-01-31 11:58:22 +03:00
Mikhail Glukhikh
f0141571b1 Fix J2K 'testAnnotationInterface3' (annotation diagnostic changed)
(cherry picked from commit 294dcf3)
2018-01-31 11:58:02 +03:00
Mikhail Glukhikh
b5b355eac7 Fix testAnnotationInterface3 in J2K (error message)
(cherry picked from commit 4606885)
2018-01-31 11:57:39 +03:00
Toshiaki Kameyama
08536661bd KT-22167 "Add annotation target" quick fix does nothing and disappears from menu
(cherry picked from commit 677b05c)
2018-01-31 11:56:35 +03:00
Mikhail Glukhikh
05183068c2 Delete companion manually during pull up
(cherry picked from commit d88b574)
2018-01-30 16:35:20 +03:00
Mikhail Glukhikh
1abf134c8f Delete companion manually during callable inlining
(cherry picked from commit 6181ba4)
2018-01-30 16:34:22 +03:00
Mikhail Glukhikh
c462a74d35 Retain empty companion in KtNamedDeclarationStub.remove
(cherry picked from commit 9b1f323)
2018-01-30 16:34:12 +03:00
Mikhail Glukhikh
36f796dfb9 Create actual fix: handle companions correctly #KT-21114 Fixed
(cherry picked from commit 5abb9dd)
2018-01-30 16:34:01 +03:00
Dmitry Savvinov
d2833ccae1 Add changelog for 1.2.30 2018-01-30 11:21:02 +03:00
Mikhail Glukhikh
05849b0ea3 Redundant Unit expression: simplify code a bit
(cherry picked from commit 1298ef7)
2018-01-30 11:19:59 +03:00
Mikhail Glukhikh
a4d7488391 getParentOfTypesAndPredicate: Class<T> -> Class<out T>
(cherry picked from commit cd9e298)
2018-01-30 11:19:48 +03:00
Toshiaki Kameyama
a21fb3f2e0 Redundant Unit inspection: fix false positive for single expression
So #KT-22097 Fixed

(cherry picked from commit 18de0f7)
2018-01-30 11:19:34 +03:00
Toshiaki Kameyama
074429ff50 Correct report of "redundant setter" for override & empty block cases
So #KT-22364 Fixed

(cherry picked from commit 69f3f04)
2018-01-30 10:00:53 +03:00
996 changed files with 20218 additions and 9901 deletions

View File

@@ -63,6 +63,7 @@
<option name="CONTINUATION_INDENT_IN_SUPERTYPE_LISTS" value="false" />
<option name="CONTINUATION_INDENT_IN_IF_CONDITIONS" value="false" />
<option name="WRAP_EXPRESSION_BODY_FUNCTIONS" value="1" />
<option name="IF_RPAREN_ON_NEW_LINE" value="true" />
</JetCodeStyleSettings>
<MarkdownNavigatorCodeStyleSettings>
<option name="RIGHT_MARGIN" value="72" />

View File

@@ -3,6 +3,8 @@
<words>
<w>checkcast</w>
<w>coroutine</w>
<w>experimentalities</w>
<w>experimentality</w>
<w>insn</w>
<w>liveness</w>
</words>

File diff suppressed because it is too large Load Diff

View File

@@ -19,12 +19,16 @@ package org.jetbrains.kotlin.incremental
import com.intellij.util.io.DataExternalizer
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl
import org.jetbrains.kotlin.incremental.js.TranslationResultValue
import org.jetbrains.kotlin.incremental.storage.*
import org.jetbrains.kotlin.incremental.storage.BasicStringMap
import org.jetbrains.kotlin.incremental.storage.DirtyClassesFqNameMap
import org.jetbrains.kotlin.incremental.storage.SourceToFqNameMap
import org.jetbrains.kotlin.incremental.storage.StringToLongMapExternalizer
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.NameResolverImpl
import org.jetbrains.kotlin.serialization.deserialization.getExtensionOrNull
import org.jetbrains.kotlin.serialization.js.JsProtoBuf
import org.jetbrains.kotlin.serialization.js.JsSerializerProtocol
import java.io.DataInput
@@ -177,11 +181,7 @@ fun getProtoData(sourceFile: File, metadata: ByteArray): Map<ClassId, ProtoData>
}
proto.`package`.apply {
val packageFqName = if (hasExtension(JsProtoBuf.packageFqName)) {
nameResolver.getPackageFqName(getExtension(JsProtoBuf.packageFqName))
}
else FqName.ROOT
val packageFqName = getExtensionOrNull(JsProtoBuf.packageFqName)?.let(nameResolver::getPackageFqName) ?: FqName.ROOT
val packagePartClassId = ClassId(packageFqName, Name.identifier(sourceFile.nameWithoutExtension.capitalize() + "Kt"))
classes[packagePartClassId] = PackagePartProtoData(this, nameResolver, packageFqName)
}

View File

@@ -1,15 +1,15 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: core/descriptors.jvm/src/jvm_package_table.debug.proto
// source: core/descriptors.jvm/src/jvm_module.debug.proto
package org.jetbrains.kotlin.serialization.jvm;
public final class DebugJvmPackageTable {
private DebugJvmPackageTable() {}
public final class DebugModuleProtoBuf {
private DebugModuleProtoBuf() {}
public static void registerAllExtensions(
org.jetbrains.kotlin.protobuf.ExtensionRegistry registry) {
}
public interface PackageTableOrBuilder extends
// @@protoc_insertion_point(interface_extends:org.jetbrains.kotlin.serialization.jvm.PackageTable)
public interface ModuleOrBuilder extends
// @@protoc_insertion_point(interface_extends:org.jetbrains.kotlin.serialization.jvm.Module)
org.jetbrains.kotlin.protobuf.MessageOrBuilder {
/**
@@ -19,7 +19,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts>
java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts>
getPackagePartsList();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts package_parts = 1;</code>
@@ -28,7 +28,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts getPackageParts(int index);
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts getPackageParts(int index);
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts package_parts = 1;</code>
*
@@ -44,7 +44,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>
java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>
getPackagePartsOrBuilderList();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts package_parts = 1;</code>
@@ -53,7 +53,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder getPackagePartsOrBuilder(
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder getPackagePartsOrBuilder(
int index);
/**
@@ -63,7 +63,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts>
java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts>
getMetadataPartsList();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts metadata_parts = 2;</code>
@@ -72,7 +72,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts getMetadataParts(int index);
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts getMetadataParts(int index);
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts metadata_parts = 2;</code>
*
@@ -88,7 +88,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>
java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>
getMetadataPartsOrBuilderList();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts metadata_parts = 2;</code>
@@ -97,7 +97,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder getMetadataPartsOrBuilder(
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder getMetadataPartsOrBuilder(
int index);
/**
@@ -140,25 +140,25 @@ public final class DebugJvmPackageTable {
getJvmPackageNameBytes(int index);
}
/**
* Protobuf type {@code org.jetbrains.kotlin.serialization.jvm.PackageTable}
* Protobuf type {@code org.jetbrains.kotlin.serialization.jvm.Module}
*/
public static final class PackageTable extends
public static final class Module extends
org.jetbrains.kotlin.protobuf.GeneratedMessage implements
// @@protoc_insertion_point(message_implements:org.jetbrains.kotlin.serialization.jvm.PackageTable)
PackageTableOrBuilder {
// Use PackageTable.newBuilder() to construct.
private PackageTable(org.jetbrains.kotlin.protobuf.GeneratedMessage.Builder<?> builder) {
// @@protoc_insertion_point(message_implements:org.jetbrains.kotlin.serialization.jvm.Module)
ModuleOrBuilder {
// Use Module.newBuilder() to construct.
private Module(org.jetbrains.kotlin.protobuf.GeneratedMessage.Builder<?> builder) {
super(builder);
this.unknownFields = builder.getUnknownFields();
}
private PackageTable(boolean noInit) { this.unknownFields = org.jetbrains.kotlin.protobuf.UnknownFieldSet.getDefaultInstance(); }
private Module(boolean noInit) { this.unknownFields = org.jetbrains.kotlin.protobuf.UnknownFieldSet.getDefaultInstance(); }
private static final PackageTable defaultInstance;
public static PackageTable getDefaultInstance() {
private static final Module defaultInstance;
public static Module getDefaultInstance() {
return defaultInstance;
}
public PackageTable getDefaultInstanceForType() {
public Module getDefaultInstanceForType() {
return defaultInstance;
}
@@ -168,7 +168,7 @@ public final class DebugJvmPackageTable {
getUnknownFields() {
return this.unknownFields;
}
private PackageTable(
private Module(
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
@@ -193,18 +193,18 @@ public final class DebugJvmPackageTable {
}
case 10: {
if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
packageParts_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts>();
packageParts_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts>();
mutable_bitField0_ |= 0x00000001;
}
packageParts_.add(input.readMessage(org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.PARSER, extensionRegistry));
packageParts_.add(input.readMessage(org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.PARSER, extensionRegistry));
break;
}
case 18: {
if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
metadataParts_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts>();
metadataParts_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts>();
mutable_bitField0_ |= 0x00000002;
}
metadataParts_.add(input.readMessage(org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.PARSER, extensionRegistry));
metadataParts_.add(input.readMessage(org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.PARSER, extensionRegistry));
break;
}
case 26: {
@@ -239,33 +239,33 @@ public final class DebugJvmPackageTable {
}
public static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
getDescriptor() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_descriptor;
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_Module_descriptor;
}
protected org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_fieldAccessorTable
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_Module_fieldAccessorTable
.ensureFieldAccessorsInitialized(
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable.class, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable.Builder.class);
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module.class, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module.Builder.class);
}
public static org.jetbrains.kotlin.protobuf.Parser<PackageTable> PARSER =
new org.jetbrains.kotlin.protobuf.AbstractParser<PackageTable>() {
public PackageTable parsePartialFrom(
public static org.jetbrains.kotlin.protobuf.Parser<Module> PARSER =
new org.jetbrains.kotlin.protobuf.AbstractParser<Module>() {
public Module parsePartialFrom(
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return new PackageTable(input, extensionRegistry);
return new Module(input, extensionRegistry);
}
};
@java.lang.Override
public org.jetbrains.kotlin.protobuf.Parser<PackageTable> getParserForType() {
public org.jetbrains.kotlin.protobuf.Parser<Module> getParserForType() {
return PARSER;
}
public static final int PACKAGE_PARTS_FIELD_NUMBER = 1;
private java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> packageParts_;
private java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> packageParts_;
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts package_parts = 1;</code>
*
@@ -273,7 +273,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> getPackagePartsList() {
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> getPackagePartsList() {
return packageParts_;
}
/**
@@ -283,7 +283,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>
public java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>
getPackagePartsOrBuilderList() {
return packageParts_;
}
@@ -304,7 +304,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts getPackageParts(int index) {
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts getPackageParts(int index) {
return packageParts_.get(index);
}
/**
@@ -314,13 +314,13 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder getPackagePartsOrBuilder(
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder getPackagePartsOrBuilder(
int index) {
return packageParts_.get(index);
}
public static final int METADATA_PARTS_FIELD_NUMBER = 2;
private java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> metadataParts_;
private java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> metadataParts_;
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts metadata_parts = 2;</code>
*
@@ -328,7 +328,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> getMetadataPartsList() {
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> getMetadataPartsList() {
return metadataParts_;
}
/**
@@ -338,7 +338,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>
public java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>
getMetadataPartsOrBuilderList() {
return metadataParts_;
}
@@ -359,7 +359,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts getMetadataParts(int index) {
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts getMetadataParts(int index) {
return metadataParts_.get(index);
}
/**
@@ -369,7 +369,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder getMetadataPartsOrBuilder(
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder getMetadataPartsOrBuilder(
int index) {
return metadataParts_.get(index);
}
@@ -500,53 +500,53 @@ public final class DebugJvmPackageTable {
return super.writeReplace();
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseFrom(
org.jetbrains.kotlin.protobuf.ByteString data)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseFrom(
org.jetbrains.kotlin.protobuf.ByteString data,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseFrom(byte[] data)
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseFrom(byte[] data)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseFrom(
byte[] data,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseFrom(java.io.InputStream input)
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseFrom(
java.io.InputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseFrom(input, extensionRegistry);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseDelimitedFrom(java.io.InputStream input)
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseDelimitedFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseDelimitedFrom(
java.io.InputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input, extensionRegistry);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseFrom(
org.jetbrains.kotlin.protobuf.CodedInputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parseFrom(
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
@@ -555,7 +555,7 @@ public final class DebugJvmPackageTable {
public static Builder newBuilder() { return Builder.create(); }
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder(org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable prototype) {
public static Builder newBuilder(org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module prototype) {
return newBuilder().mergeFrom(prototype);
}
public Builder toBuilder() { return newBuilder(this); }
@@ -567,25 +567,25 @@ public final class DebugJvmPackageTable {
return builder;
}
/**
* Protobuf type {@code org.jetbrains.kotlin.serialization.jvm.PackageTable}
* Protobuf type {@code org.jetbrains.kotlin.serialization.jvm.Module}
*/
public static final class Builder extends
org.jetbrains.kotlin.protobuf.GeneratedMessage.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:org.jetbrains.kotlin.serialization.jvm.PackageTable)
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTableOrBuilder {
// @@protoc_insertion_point(builder_implements:org.jetbrains.kotlin.serialization.jvm.Module)
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.ModuleOrBuilder {
public static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
getDescriptor() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_descriptor;
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_Module_descriptor;
}
protected org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_fieldAccessorTable
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_Module_fieldAccessorTable
.ensureFieldAccessorsInitialized(
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable.class, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable.Builder.class);
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module.class, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module.Builder.class);
}
// Construct using org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable.newBuilder()
// Construct using org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
@@ -630,23 +630,23 @@ public final class DebugJvmPackageTable {
public org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_descriptor;
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_Module_descriptor;
}
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable getDefaultInstanceForType() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable.getDefaultInstance();
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module getDefaultInstanceForType() {
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module.getDefaultInstance();
}
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable build() {
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable result = buildPartial();
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module build() {
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable buildPartial() {
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable result = new org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable(this);
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module buildPartial() {
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module result = new org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module(this);
int from_bitField0_ = bitField0_;
if (packagePartsBuilder_ == null) {
if (((bitField0_ & 0x00000001) == 0x00000001)) {
@@ -676,16 +676,16 @@ public final class DebugJvmPackageTable {
}
public Builder mergeFrom(org.jetbrains.kotlin.protobuf.Message other) {
if (other instanceof org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable) {
return mergeFrom((org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable)other);
if (other instanceof org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module) {
return mergeFrom((org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable other) {
if (other == org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable.getDefaultInstance()) return this;
public Builder mergeFrom(org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module other) {
if (other == org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module.getDefaultInstance()) return this;
if (packagePartsBuilder_ == null) {
if (!other.packageParts_.isEmpty()) {
if (packageParts_.isEmpty()) {
@@ -772,11 +772,11 @@ public final class DebugJvmPackageTable {
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable parsedMessage = null;
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageTable) e.getUnfinishedMessage();
parsedMessage = (org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.Module) e.getUnfinishedMessage();
throw e;
} finally {
if (parsedMessage != null) {
@@ -787,17 +787,17 @@ public final class DebugJvmPackageTable {
}
private int bitField0_;
private java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> packageParts_ =
private java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> packageParts_ =
java.util.Collections.emptyList();
private void ensurePackagePartsIsMutable() {
if (!((bitField0_ & 0x00000001) == 0x00000001)) {
packageParts_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts>(packageParts_);
packageParts_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts>(packageParts_);
bitField0_ |= 0x00000001;
}
}
private org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder> packagePartsBuilder_;
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder> packagePartsBuilder_;
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts package_parts = 1;</code>
@@ -806,7 +806,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> getPackagePartsList() {
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> getPackagePartsList() {
if (packagePartsBuilder_ == null) {
return java.util.Collections.unmodifiableList(packageParts_);
} else {
@@ -834,7 +834,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts getPackageParts(int index) {
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts getPackageParts(int index) {
if (packagePartsBuilder_ == null) {
return packageParts_.get(index);
} else {
@@ -849,7 +849,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder setPackageParts(
int index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts value) {
int index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts value) {
if (packagePartsBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
@@ -870,7 +870,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder setPackageParts(
int index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder builderForValue) {
int index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder builderForValue) {
if (packagePartsBuilder_ == null) {
ensurePackagePartsIsMutable();
packageParts_.set(index, builderForValue.build());
@@ -887,7 +887,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public Builder addPackageParts(org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts value) {
public Builder addPackageParts(org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts value) {
if (packagePartsBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
@@ -908,7 +908,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder addPackageParts(
int index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts value) {
int index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts value) {
if (packagePartsBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
@@ -929,7 +929,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder addPackageParts(
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder builderForValue) {
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder builderForValue) {
if (packagePartsBuilder_ == null) {
ensurePackagePartsIsMutable();
packageParts_.add(builderForValue.build());
@@ -947,7 +947,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder addPackageParts(
int index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder builderForValue) {
int index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder builderForValue) {
if (packagePartsBuilder_ == null) {
ensurePackagePartsIsMutable();
packageParts_.add(index, builderForValue.build());
@@ -965,7 +965,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder addAllPackageParts(
java.lang.Iterable<? extends org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> values) {
java.lang.Iterable<? extends org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> values) {
if (packagePartsBuilder_ == null) {
ensurePackagePartsIsMutable();
org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
@@ -1017,7 +1017,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder getPackagePartsBuilder(
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder getPackagePartsBuilder(
int index) {
return getPackagePartsFieldBuilder().getBuilder(index);
}
@@ -1028,7 +1028,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder getPackagePartsOrBuilder(
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder getPackagePartsOrBuilder(
int index) {
if (packagePartsBuilder_ == null) {
return packageParts_.get(index); } else {
@@ -1042,7 +1042,7 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>
public java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>
getPackagePartsOrBuilderList() {
if (packagePartsBuilder_ != null) {
return packagePartsBuilder_.getMessageOrBuilderList();
@@ -1057,9 +1057,9 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder addPackagePartsBuilder() {
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder addPackagePartsBuilder() {
return getPackagePartsFieldBuilder().addBuilder(
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.getDefaultInstance());
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.getDefaultInstance());
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts package_parts = 1;</code>
@@ -1068,10 +1068,10 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder addPackagePartsBuilder(
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder addPackagePartsBuilder(
int index) {
return getPackagePartsFieldBuilder().addBuilder(
index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.getDefaultInstance());
index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.getDefaultInstance());
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts package_parts = 1;</code>
@@ -1080,16 +1080,16 @@ public final class DebugJvmPackageTable {
* Names of .class files for each package
* </pre>
*/
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder>
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder>
getPackagePartsBuilderList() {
return getPackagePartsFieldBuilder().getBuilderList();
}
private org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>
getPackagePartsFieldBuilder() {
if (packagePartsBuilder_ == null) {
packagePartsBuilder_ = new org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>(
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>(
packageParts_,
((bitField0_ & 0x00000001) == 0x00000001),
getParentForChildren(),
@@ -1099,17 +1099,17 @@ public final class DebugJvmPackageTable {
return packagePartsBuilder_;
}
private java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> metadataParts_ =
private java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> metadataParts_ =
java.util.Collections.emptyList();
private void ensureMetadataPartsIsMutable() {
if (!((bitField0_ & 0x00000002) == 0x00000002)) {
metadataParts_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts>(metadataParts_);
metadataParts_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts>(metadataParts_);
bitField0_ |= 0x00000002;
}
}
private org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder> metadataPartsBuilder_;
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder> metadataPartsBuilder_;
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts metadata_parts = 2;</code>
@@ -1118,7 +1118,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> getMetadataPartsList() {
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> getMetadataPartsList() {
if (metadataPartsBuilder_ == null) {
return java.util.Collections.unmodifiableList(metadataParts_);
} else {
@@ -1146,7 +1146,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts getMetadataParts(int index) {
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts getMetadataParts(int index) {
if (metadataPartsBuilder_ == null) {
return metadataParts_.get(index);
} else {
@@ -1161,7 +1161,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder setMetadataParts(
int index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts value) {
int index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts value) {
if (metadataPartsBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
@@ -1182,7 +1182,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder setMetadataParts(
int index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder builderForValue) {
int index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder builderForValue) {
if (metadataPartsBuilder_ == null) {
ensureMetadataPartsIsMutable();
metadataParts_.set(index, builderForValue.build());
@@ -1199,7 +1199,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public Builder addMetadataParts(org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts value) {
public Builder addMetadataParts(org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts value) {
if (metadataPartsBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
@@ -1220,7 +1220,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder addMetadataParts(
int index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts value) {
int index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts value) {
if (metadataPartsBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
@@ -1241,7 +1241,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder addMetadataParts(
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder builderForValue) {
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder builderForValue) {
if (metadataPartsBuilder_ == null) {
ensureMetadataPartsIsMutable();
metadataParts_.add(builderForValue.build());
@@ -1259,7 +1259,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder addMetadataParts(
int index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder builderForValue) {
int index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder builderForValue) {
if (metadataPartsBuilder_ == null) {
ensureMetadataPartsIsMutable();
metadataParts_.add(index, builderForValue.build());
@@ -1277,7 +1277,7 @@ public final class DebugJvmPackageTable {
* </pre>
*/
public Builder addAllMetadataParts(
java.lang.Iterable<? extends org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts> values) {
java.lang.Iterable<? extends org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts> values) {
if (metadataPartsBuilder_ == null) {
ensureMetadataPartsIsMutable();
org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
@@ -1329,7 +1329,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder getMetadataPartsBuilder(
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder getMetadataPartsBuilder(
int index) {
return getMetadataPartsFieldBuilder().getBuilder(index);
}
@@ -1340,7 +1340,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder getMetadataPartsOrBuilder(
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder getMetadataPartsOrBuilder(
int index) {
if (metadataPartsBuilder_ == null) {
return metadataParts_.get(index); } else {
@@ -1354,7 +1354,7 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>
public java.util.List<? extends org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>
getMetadataPartsOrBuilderList() {
if (metadataPartsBuilder_ != null) {
return metadataPartsBuilder_.getMessageOrBuilderList();
@@ -1369,9 +1369,9 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder addMetadataPartsBuilder() {
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder addMetadataPartsBuilder() {
return getMetadataPartsFieldBuilder().addBuilder(
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.getDefaultInstance());
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.getDefaultInstance());
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts metadata_parts = 2;</code>
@@ -1380,10 +1380,10 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder addMetadataPartsBuilder(
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder addMetadataPartsBuilder(
int index) {
return getMetadataPartsFieldBuilder().addBuilder(
index, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.getDefaultInstance());
index, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.getDefaultInstance());
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.jvm.PackageParts metadata_parts = 2;</code>
@@ -1392,16 +1392,16 @@ public final class DebugJvmPackageTable {
* Names of .kotlin_metadata files for each package
* </pre>
*/
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder>
public java.util.List<org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder>
getMetadataPartsBuilderList() {
return getMetadataPartsFieldBuilder().getBuilderList();
}
private org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>
getMetadataPartsFieldBuilder() {
if (metadataPartsBuilder_ == null) {
metadataPartsBuilder_ = new org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder>(
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder>(
metadataParts_,
((bitField0_ & 0x00000002) == 0x00000002),
getParentForChildren(),
@@ -1549,15 +1549,15 @@ public final class DebugJvmPackageTable {
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.jvm.PackageTable)
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.jvm.Module)
}
static {
defaultInstance = new PackageTable(true);
defaultInstance = new Module(true);
defaultInstance.initFields();
}
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.serialization.jvm.PackageTable)
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.serialization.jvm.Module)
}
public interface PackagePartsOrBuilder extends
@@ -1919,14 +1919,14 @@ public final class DebugJvmPackageTable {
}
public static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
getDescriptor() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_descriptor;
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_descriptor;
}
protected org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_fieldAccessorTable
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_fieldAccessorTable
.ensureFieldAccessorsInitialized(
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.class, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder.class);
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.class, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder.class);
}
public static org.jetbrains.kotlin.protobuf.Parser<PackageParts> PARSER =
@@ -2353,53 +2353,53 @@ public final class DebugJvmPackageTable {
return super.writeReplace();
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseFrom(
org.jetbrains.kotlin.protobuf.ByteString data)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseFrom(
org.jetbrains.kotlin.protobuf.ByteString data,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseFrom(byte[] data)
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseFrom(byte[] data)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseFrom(
byte[] data,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseFrom(java.io.InputStream input)
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseFrom(
java.io.InputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseFrom(input, extensionRegistry);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseDelimitedFrom(java.io.InputStream input)
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseDelimitedFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseDelimitedFrom(
java.io.InputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input, extensionRegistry);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseFrom(
org.jetbrains.kotlin.protobuf.CodedInputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
}
public static org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parseFrom(
public static org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parseFrom(
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
@@ -2408,7 +2408,7 @@ public final class DebugJvmPackageTable {
public static Builder newBuilder() { return Builder.create(); }
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder(org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts prototype) {
public static Builder newBuilder(org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts prototype) {
return newBuilder().mergeFrom(prototype);
}
public Builder toBuilder() { return newBuilder(this); }
@@ -2425,20 +2425,20 @@ public final class DebugJvmPackageTable {
public static final class Builder extends
org.jetbrains.kotlin.protobuf.GeneratedMessage.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:org.jetbrains.kotlin.serialization.jvm.PackageParts)
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackagePartsOrBuilder {
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackagePartsOrBuilder {
public static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
getDescriptor() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_descriptor;
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_descriptor;
}
protected org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_fieldAccessorTable
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_fieldAccessorTable
.ensureFieldAccessorsInitialized(
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.class, org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.Builder.class);
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.class, org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.Builder.class);
}
// Construct using org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.newBuilder()
// Construct using org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
@@ -2479,23 +2479,23 @@ public final class DebugJvmPackageTable {
public org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_descriptor;
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_descriptor;
}
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts getDefaultInstanceForType() {
return org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.getDefaultInstance();
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts getDefaultInstanceForType() {
return org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.getDefaultInstance();
}
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts build() {
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts result = buildPartial();
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts build() {
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts buildPartial() {
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts result = new org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts(this);
public org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts buildPartial() {
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts result = new org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts(this);
int from_bitField0_ = bitField0_;
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
@@ -2533,16 +2533,16 @@ public final class DebugJvmPackageTable {
}
public Builder mergeFrom(org.jetbrains.kotlin.protobuf.Message other) {
if (other instanceof org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts) {
return mergeFrom((org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts)other);
if (other instanceof org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts) {
return mergeFrom((org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts other) {
if (other == org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts.getDefaultInstance()) return this;
public Builder mergeFrom(org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts other) {
if (other == org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts.getDefaultInstance()) return this;
if (other.hasPackageFqName()) {
bitField0_ |= 0x00000001;
packageFqName_ = other.packageFqName_;
@@ -2614,11 +2614,11 @@ public final class DebugJvmPackageTable {
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts parsedMessage = null;
org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (org.jetbrains.kotlin.serialization.jvm.DebugJvmPackageTable.PackageParts) e.getUnfinishedMessage();
parsedMessage = (org.jetbrains.kotlin.serialization.jvm.DebugModuleProtoBuf.PackageParts) e.getUnfinishedMessage();
throw e;
} finally {
if (parsedMessage != null) {
@@ -3361,10 +3361,10 @@ public final class DebugJvmPackageTable {
}
private static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_descriptor;
internal_static_org_jetbrains_kotlin_serialization_jvm_Module_descriptor;
private static
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable
internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_fieldAccessorTable;
internal_static_org_jetbrains_kotlin_serialization_jvm_Module_fieldAccessorTable;
private static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_descriptor;
private static
@@ -3379,21 +3379,20 @@ public final class DebugJvmPackageTable {
descriptor;
static {
java.lang.String[] descriptorData = {
"\n6core/descriptors.jvm/src/jvm_package_t" +
"able.debug.proto\022&org.jetbrains.kotlin.s" +
"erialization.jvm\"\303\001\n\014PackageTable\022K\n\rpac" +
"kage_parts\030\001 \003(\01324.org.jetbrains.kotlin." +
"serialization.jvm.PackageParts\022L\n\016metada" +
"ta_parts\030\002 \003(\01324.org.jetbrains.kotlin.se" +
"rialization.jvm.PackageParts\022\030\n\020jvm_pack" +
"age_name\030\003 \003(\t\"\366\001\n\014PackageParts\022\027\n\017packa" +
"ge_fq_name\030\001 \002(\t\022\030\n\020short_class_name\030\002 \003" +
"(\t\022*\n\036multifile_facade_short_name_id\030\003 \003",
"(\005B\002\020\001\022#\n\033multifile_facade_short_name\030\004 " +
"\003(\t\022.\n&class_with_jvm_package_name_short" +
"_name\030\005 \003(\t\0222\n&class_with_jvm_package_na" +
"me_package_id\030\006 \003(\005B\002\020\001B\026B\024DebugJvmPacka" +
"geTable"
"\n/core/descriptors.jvm/src/jvm_module.de" +
"bug.proto\022&org.jetbrains.kotlin.serializ" +
"ation.jvm\"\275\001\n\006Module\022K\n\rpackage_parts\030\001 " +
"\003(\01324.org.jetbrains.kotlin.serialization" +
".jvm.PackageParts\022L\n\016metadata_parts\030\002 \003(" +
"\01324.org.jetbrains.kotlin.serialization.j" +
"vm.PackageParts\022\030\n\020jvm_package_name\030\003 \003(" +
"\t\"\366\001\n\014PackageParts\022\027\n\017package_fq_name\030\001 " +
"\002(\t\022\030\n\020short_class_name\030\002 \003(\t\022*\n\036multifi" +
"le_facade_short_name_id\030\003 \003(\005B\002\020\001\022#\n\033mul",
"tifile_facade_short_name\030\004 \003(\t\022.\n&class_" +
"with_jvm_package_name_short_name\030\005 \003(\t\0222" +
"\n&class_with_jvm_package_name_package_id" +
"\030\006 \003(\005B\002\020\001B\025B\023DebugModuleProtoBuf"
};
org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -3407,11 +3406,11 @@ public final class DebugJvmPackageTable {
.internalBuildGeneratedFileFrom(descriptorData,
new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor[] {
}, assigner);
internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_descriptor =
internal_static_org_jetbrains_kotlin_serialization_jvm_Module_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_fieldAccessorTable = new
internal_static_org_jetbrains_kotlin_serialization_jvm_Module_fieldAccessorTable = new
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_org_jetbrains_kotlin_serialization_jvm_PackageTable_descriptor,
internal_static_org_jetbrains_kotlin_serialization_jvm_Module_descriptor,
new java.lang.String[] { "PackageParts", "MetadataParts", "JvmPackageName", });
internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_descriptor =
getDescriptor().getMessageTypes().get(1);

View File

@@ -9,9 +9,12 @@ import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
buildscript {
extra["defaultSnapshotVersion"] = "1.2-SNAPSHOT"
kotlinBootstrapFrom(BootstrapOption.TeamCity("1.2.30-dev-441", onlySuccessBootstrap = false))
kotlinBootstrapFrom(BootstrapOption.TeamCity("1.2.40-dev-165", onlySuccessBootstrap = false))
val mirrorRepo: String? = findProperty("maven.repository.mirror")?.toString()
val repos = listOfNotNull(
mirrorRepo,
bootstrapKotlinRepo,
"https://jcenter.bintray.com/",
"https://plugins.gradle.org/m2")
@@ -162,6 +165,7 @@ val coreLibProjects = listOf(
":kotlin-test:kotlin-test-common",
":kotlin-test:kotlin-test-jvm",
":kotlin-test:kotlin-test-junit",
":kotlin-test:kotlin-test-testng",
":kotlin-test:kotlin-test-js",
":kotlin-reflect"
)
@@ -230,13 +234,15 @@ allprojects {
// - some tests (in particular js and binary-compatibility-validator depend on the fixed (default) location
// - idea seems unable to exclude common builddir from indexing
// therefore it is disabled by default
// buildDir = File(commonBuildDir, project.name)
// buildDir = File(commonBuildDir, project.name)
val repos: List<String> by rootProject.extra
repositories {
for (repo in (rootProject.extra["repos"] as List<String>)) {
maven { setUrl(repo) }
for (repo in repos) {
maven(repo)
}
}
configureJvmProject(javaHome!!, jvmTarget!!)
val commonCompilerArgs = listOf("-Xallow-kotlin-package")

View File

@@ -22,7 +22,9 @@ import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorEquivalenceForOverrides
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils.COROUTINES_INTRINSICS_PACKAGE_FQ_NAME
import org.jetbrains.kotlin.resolve.calls.checkers.COROUTINE_CONTEXT_1_2_20_FQ_NAME
import org.jetbrains.kotlin.resolve.calls.checkers.COROUTINE_CONTEXT_FQ_NAME
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.module
@@ -30,17 +32,14 @@ val SUSPEND_COROUTINE_OR_RETURN_NAME = Name.identifier("suspendCoroutineOrReturn
val INTERCEPTED_NAME = Name.identifier("intercepted")
val COROUTINE_SUSPENDED_NAME = Name.identifier("COROUTINE_SUSPENDED")
val COROUTINES_INTRINSICS_PACKAGE_FQ_NAME = DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("intrinsics"))
val COROUTINE_CONTEXT_FQ_NAME = COROUTINES_INTRINSICS_PACKAGE_FQ_NAME.child(Name.identifier("coroutineContext"))
val SUSPEND_COROUTINE_UNINTERCEPTED_OR_RETURN_NAME = Name.identifier("suspendCoroutineUninterceptedOrReturn")
fun FunctionDescriptor.isBuiltInIntercepted(): Boolean {
if (name != INTERCEPTED_NAME) return false
val original =
module.getPackage(COROUTINES_INTRINSICS_PACKAGE_FQ_NAME).memberScope
.getContributedFunctions(INTERCEPTED_NAME, NoLookupLocation.FROM_BACKEND)
.singleOrNull() as CallableDescriptor
module.getPackage(COROUTINES_INTRINSICS_PACKAGE_FQ_NAME).memberScope
.getContributedFunctions(INTERCEPTED_NAME, NoLookupLocation.FROM_BACKEND)
.singleOrNull() as CallableDescriptor
return DescriptorEquivalenceForOverrides.areEquivalent(original, this)
}
@@ -50,22 +49,19 @@ fun FunctionDescriptor.isBuiltInSuspendCoroutineOrReturn(): Boolean {
val originalDeclaration = getBuiltInSuspendCoroutineOrReturn() ?: return false
return DescriptorEquivalenceForOverrides.areEquivalent(
originalDeclaration, this
originalDeclaration, this
)
}
fun FunctionDescriptor.getBuiltInSuspendCoroutineOrReturn() =
module.getPackage(COROUTINES_INTRINSICS_PACKAGE_FQ_NAME).memberScope
.getContributedFunctions(SUSPEND_COROUTINE_OR_RETURN_NAME, NoLookupLocation.FROM_BACKEND)
.singleOrNull()
fun FunctionDescriptor.isBuiltInCoroutineContext() =
(this as? PropertyGetterDescriptor)?.correspondingProperty?.fqNameSafe == COROUTINE_CONTEXT_FQ_NAME
module.getPackage(COROUTINES_INTRINSICS_PACKAGE_FQ_NAME).memberScope
.getContributedFunctions(SUSPEND_COROUTINE_OR_RETURN_NAME, NoLookupLocation.FROM_BACKEND)
.singleOrNull()
fun FunctionDescriptor.isBuiltInSuspendCoroutineUninterceptedOrReturn(): Boolean {
if (name != SUSPEND_COROUTINE_UNINTERCEPTED_OR_RETURN_NAME) return false
val original = module.getPackage(COROUTINES_INTRINSICS_PACKAGE_FQ_NAME).memberScope
.getContributedFunctions(SUSPEND_COROUTINE_UNINTERCEPTED_OR_RETURN_NAME, NoLookupLocation.FROM_BACKEND)
.singleOrNull() as CallableDescriptor
.getContributedFunctions(SUSPEND_COROUTINE_UNINTERCEPTED_OR_RETURN_NAME, NoLookupLocation.FROM_BACKEND)
.singleOrNull() as CallableDescriptor
return DescriptorEquivalenceForOverrides.areEquivalent(original, this)
}

View File

@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.codegen;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import kotlin.Pair;
import kotlin.collections.CollectionsKt;
import kotlin.io.FilesKt;
import org.jetbrains.annotations.NotNull;
@@ -26,14 +27,23 @@ import org.jetbrains.annotations.TestOnly;
import org.jetbrains.kotlin.backend.common.output.OutputFile;
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.config.AnalysisFlag;
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.DescriptorUtilKt;
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.load.kotlin.ModuleMapping;
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
import org.jetbrains.kotlin.load.kotlin.PackageParts;
import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
import org.jetbrains.kotlin.serialization.jvm.JvmPackageTable;
import org.jetbrains.kotlin.serialization.ProtoBuf;
import org.jetbrains.kotlin.serialization.StringTableImpl;
import org.jetbrains.kotlin.serialization.jvm.JvmModuleProtoBuf;
import org.jetbrains.org.objectweb.asm.Type;
import java.io.File;
@@ -95,19 +105,25 @@ public class ClassFileFactory implements OutputFileCollection {
}
private void writeModuleMappings() {
JvmPackageTable.PackageTable.Builder builder = JvmPackageTable.PackageTable.newBuilder();
JvmModuleProtoBuf.Module.Builder builder = JvmModuleProtoBuf.Module.newBuilder();
String outputFilePath = getMappingFileName(state.getModuleName());
for (PackageParts part : ClassFileUtilsKt.addCompiledPartsAndSort(partsGroupedByPackage.values(), state)) {
part.addTo(builder);
}
if (builder.getPackagePartsCount() == 0) return;
List<String> experimental = state.getLanguageVersionSettings().getFlag(AnalysisFlag.getExperimental());
if (!experimental.isEmpty()) {
writeExperimentalMarkers(state.getModule(), builder, experimental);
}
JvmModuleProtoBuf.Module moduleProto = builder.build();
if (moduleProto.getSerializedSize() == 0) return;
generators.put(outputFilePath, new OutAndSourceFileList(CollectionsKt.toList(packagePartSourceFiles)) {
@Override
public byte[] asBytes(ClassBuilderFactory factory) {
return ClassFileUtilsKt.serializeToByteArray(builder);
return ClassFileUtilsKt.serializeToByteArray(moduleProto);
}
@Override
@@ -122,6 +138,29 @@ public class ClassFileFactory implements OutputFileCollection {
});
}
private static void writeExperimentalMarkers(
@NotNull ModuleDescriptor module,
@NotNull JvmModuleProtoBuf.Module.Builder builder,
@NotNull List<String> experimental
) {
StringTableImpl stringTable = new StringTableImpl();
for (String fqName : experimental) {
ClassDescriptor descriptor =
DescriptorUtilKt.resolveClassByFqName(module, new FqName(fqName), NoLookupLocation.FOR_ALREADY_TRACKED);
if (descriptor != null) {
ProtoBuf.Annotation.Builder annotation = ProtoBuf.Annotation.newBuilder();
ClassId classId = DescriptorUtilsKt.getClassId(descriptor);
if (classId != null) {
annotation.setId(stringTable.getClassIdIndex(classId));
builder.addAnnotation(annotation);
}
}
}
Pair<ProtoBuf.StringTable, ProtoBuf.QualifiedNameTable> tables = stringTable.buildProto();
builder.setStringTable(tables.getFirst());
builder.setQualifiedNameTable(tables.getSecond());
}
@NotNull
@Override
public List<OutputFile> asList() {

View File

@@ -384,10 +384,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (context.closure != null)
genClosureFields(context.closure, v, typeMapper);
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
for (ExpressionCodegenExtension extension : ExpressionCodegenExtension.Companion.getInstances(state.getProject())) {
extension.generateClassSyntheticParts(this);
if (state.getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES
|| extension.getShouldGenerateClassSyntheticPartsInLightClassesMode()
) {
extension.generateClassSyntheticParts(this);
}
}
}

View File

@@ -95,23 +95,33 @@ public class CodegenBinding {
@NotNull
public static Type asmTypeForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull KtElement expression) {
Type result = asmTypeForAnonymousClassOrNull(bindingContext, expression);
if (result == null) {
throw new IllegalStateException("Type must not be null: " + expression.getText());
}
return result;
}
@Nullable
public static Type asmTypeForAnonymousClassOrNull(@NotNull BindingContext bindingContext, @NotNull KtElement expression) {
if (expression instanceof KtObjectLiteralExpression) {
expression = ((KtObjectLiteralExpression) expression).getObjectDeclaration();
}
ClassDescriptor descriptor = bindingContext.get(CLASS, expression);
if (descriptor != null) {
return getAsmType(bindingContext, descriptor);
return bindingContext.get(ASM_TYPE, descriptor);
}
SimpleFunctionDescriptor functionDescriptor = bindingContext.get(FUNCTION, expression);
if (functionDescriptor != null) {
return asmTypeForAnonymousClass(bindingContext, functionDescriptor);
return asmTypeForAnonymousClassOrNull(bindingContext, functionDescriptor);
}
VariableDescriptor variableDescriptor = bindingContext.get(VARIABLE, expression);
if (variableDescriptor != null) {
return asmTypeForAnonymousClass(bindingContext, variableDescriptor);
return asmTypeForAnonymousClassOrNull(bindingContext, variableDescriptor);
}
throw new KotlinExceptionWithAttachments("Couldn't compute ASM type for expression")
@@ -120,7 +130,17 @@ public class CodegenBinding {
@NotNull
public static Type asmTypeForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull CallableDescriptor descriptor) {
return getAsmType(bindingContext, anonymousClassForCallable(bindingContext, descriptor));
Type result = asmTypeForAnonymousClassOrNull(bindingContext, descriptor);
if (result == null) {
throw new IllegalStateException("Type must not be null: " + descriptor);
}
return result;
}
@Nullable
public static Type asmTypeForAnonymousClassOrNull(@NotNull BindingContext bindingContext, @NotNull CallableDescriptor descriptor) {
return bindingContext.get(ASM_TYPE, anonymousClassForCallable(bindingContext, descriptor));
}
public static boolean canHaveOuter(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor classDescriptor) {
@@ -216,7 +236,9 @@ public class CodegenBinding {
@NotNull
public static Type getAsmType(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor klass) {
Type type = bindingContext.get(ASM_TYPE, klass);
assert type != null : "Type is not yet recorded for " + klass;
if (type == null) {
throw new IllegalStateException("Type is not yet recorded for " + klass);
}
return type;
}

View File

@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
import org.jetbrains.kotlin.load.kotlin.PackageParts
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.serialization.jvm.JvmPackageTable
import org.jetbrains.kotlin.serialization.jvm.JvmModuleProtoBuf
import java.io.ByteArrayOutputStream
fun ClassFileFactory.getClassFiles(): Iterable<OutputFile> {
@@ -57,7 +57,7 @@ private fun Iterable<PackageParts>.addCompiledParts(state: GenerationState): Lis
}
}
fun JvmPackageTable.PackageTable.Builder.serializeToByteArray(): ByteArray {
fun JvmModuleProtoBuf.Module.serializeToByteArray(): ByteArray {
val moduleMapping = ByteArrayOutputStream(4096)
val out = DataOutputStream(moduleMapping)
val version = JvmMetadataVersion.INSTANCE.toArray()
@@ -65,7 +65,7 @@ fun JvmPackageTable.PackageTable.Builder.serializeToByteArray(): ByteArray {
for (number in version) {
out.writeInt(number)
}
build().writeTo(out)
writeTo(out)
out.flush()
return moduleMapping.toByteArray()
}

View File

@@ -22,10 +22,7 @@ import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.codegen.ClassBuilder
import org.jetbrains.kotlin.codegen.StackValue
import org.jetbrains.kotlin.codegen.TransformationMethodVisitor
import org.jetbrains.kotlin.codegen.inline.MaxStackFrameSizeAndLocalsCalculator
import org.jetbrains.kotlin.codegen.inline.isAfterSuspendMarker
import org.jetbrains.kotlin.codegen.inline.isBeforeSuspendMarker
import org.jetbrains.kotlin.codegen.inline.isInlineMarker
import org.jetbrains.kotlin.codegen.inline.*
import org.jetbrains.kotlin.codegen.optimization.DeadCodeEliminationMethodTransformer
import org.jetbrains.kotlin.codegen.optimization.common.*
import org.jetbrains.kotlin.codegen.optimization.fixStack.FixStackMethodTransformer
@@ -81,6 +78,13 @@ class CoroutineTransformerMethodVisitor(
ReturnUnitMethodTransformer.transform(containingClassInternalName, methodNode)
if (allSuspensionPointsAreTailCalls(containingClassInternalName, methodNode, suspensionPoints)) {
continuationIndex =
if (isStatic(methodNode.access))
Type.getArgumentTypes(methodNode.desc).size - 1
else
Type.getArgumentTypes(methodNode.desc).size
replaceFakeContinuationsWithRealOnes(methodNode, continuationIndex)
dropSuspensionMarkers(methodNode, suspensionPoints)
return
}
@@ -99,6 +103,8 @@ class CoroutineTransformerMethodVisitor(
// Actual max stack might be increased during the previous phases
updateMaxStack(methodNode)
replaceFakeContinuationsWithRealOnes(methodNode, continuationIndex)
// Remove unreachable suspension points
// If we don't do this, then relevant frames will not be analyzed, that is unexpected from point of view of next steps (e.g. variable spilling)
removeUnreachableSuspensionPointsAndExitPoints(methodNode, suspensionPoints)
@@ -153,6 +159,14 @@ class CoroutineTransformerMethodVisitor(
methodNode.removeEmptyCatchBlocks()
}
private fun replaceFakeContinuationsWithRealOnes(methodNode: MethodNode, continuationIndex: Int) {
val fakeContinuations = methodNode.instructions.asSequence().filter(::isFakeContinuationMarker)
for (fakeContinuation in fakeContinuations) {
methodNode.instructions.removeAll(listOf(fakeContinuation.previous.previous, fakeContinuation.previous))
methodNode.instructions.set(fakeContinuation, VarInsnNode(Opcodes.ALOAD, continuationIndex))
}
}
private fun createInsnForReadingLabel() =
if (isForNamedFunction)
MethodInsnNode(

View File

@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.backend.common.*
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
import org.jetbrains.kotlin.codegen.StackValue
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
import org.jetbrains.kotlin.codegen.inline.addFakeContinuationMarker
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.codegen.topLevelClassAsmType
import org.jetbrains.kotlin.codegen.topLevelClassInternalName
@@ -32,6 +33,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.checkers.isBuiltInCoroutineContext
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
@@ -59,22 +61,23 @@ const val EXCEPTION_FIELD_NAME = "exception"
@JvmField
val COROUTINES_JVM_INTERNAL_PACKAGE_FQ_NAME =
DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("jvm")).child(Name.identifier("internal"))
DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("jvm")).child(Name.identifier("internal"))
@JvmField
val CONTINUATION_ASM_TYPE = DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME.topLevelClassAsmType()
@JvmField
val COROUTINE_CONTEXT_ASM_TYPE = DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineContext")).topLevelClassAsmType()
val COROUTINE_CONTEXT_ASM_TYPE =
DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineContext")).topLevelClassAsmType()
@JvmField
val COROUTINE_IMPL_ASM_TYPE = COROUTINES_JVM_INTERNAL_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineImpl")).topLevelClassAsmType()
private val COROUTINES_INTRINSICS_FILE_FACADE_INTERNAL_NAME =
COROUTINES_INTRINSICS_PACKAGE_FQ_NAME.child(Name.identifier("IntrinsicsKt")).topLevelClassAsmType()
DescriptorUtils.COROUTINES_INTRINSICS_PACKAGE_FQ_NAME.child(Name.identifier("IntrinsicsKt")).topLevelClassAsmType()
private val INTERNAL_COROUTINE_INTRINSICS_OWNER_INTERNAL_NAME =
COROUTINES_JVM_INTERNAL_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineIntrinsics")).topLevelClassInternalName()
COROUTINES_JVM_INTERNAL_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineIntrinsics")).topLevelClassInternalName()
private val NORMALIZE_CONTINUATION_METHOD_NAME = "normalizeContinuation"
private val GET_CONTEXT_METHOD_NAME = "getContext"
@@ -94,41 +97,42 @@ val INITIAL_SUSPEND_DESCRIPTOR_FOR_DO_RESUME = object : FunctionDescriptor.UserD
// So this function returns resolved call with descriptor looking like `fun <V> await(f: CompletableFuture<V>, machine: Continuation<V>): Unit`
// and fake `this` expression that used as argument for second parameter
fun ResolvedCall<*>.replaceSuspensionFunctionWithRealDescriptor(
project: Project,
bindingContext: BindingContext
project: Project,
bindingContext: BindingContext
): ResolvedCallWithRealDescriptor? {
if (this is VariableAsFunctionResolvedCall) {
val replacedFunctionCall =
functionCall.replaceSuspensionFunctionWithRealDescriptor(project, bindingContext)
?: return null
functionCall.replaceSuspensionFunctionWithRealDescriptor(project, bindingContext)
?: return null
@Suppress("UNCHECKED_CAST")
return replacedFunctionCall.copy(
VariableAsFunctionResolvedCallImpl(
replacedFunctionCall.resolvedCall as MutableResolvedCall<FunctionDescriptor>,
variableCall.asMutableResolvedCall(bindingContext)
)
VariableAsFunctionResolvedCallImpl(
replacedFunctionCall.resolvedCall as MutableResolvedCall<FunctionDescriptor>,
variableCall.asMutableResolvedCall(bindingContext)
)
)
}
val function = candidateDescriptor as? FunctionDescriptor ?: return null
if (!function.isSuspend || function.getUserData(INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION) != null) return null
val newCandidateDescriptor =
when (function) {
is FunctionImportedFromObject ->
getOrCreateJvmSuspendFunctionView(function.callableFromObject, bindingContext).asImportedFromObject()
is SimpleFunctionDescriptor ->
getOrCreateJvmSuspendFunctionView(function, bindingContext)
else ->
throw AssertionError("Unexpected suspend function descriptor: $function")
}
when (function) {
is FunctionImportedFromObject ->
getOrCreateJvmSuspendFunctionView(function.callableFromObject, bindingContext).asImportedFromObject()
is SimpleFunctionDescriptor ->
getOrCreateJvmSuspendFunctionView(function, bindingContext)
else ->
throw AssertionError("Unexpected suspend function descriptor: $function")
}
val newCall = ResolvedCallImpl(
call,
newCandidateDescriptor,
dispatchReceiver, extensionReceiver, explicitReceiverKind,
null, DelegatingBindingTrace(BindingTraceContext().bindingContext, "Temporary trace for unwrapped suspension function"),
TracingStrategy.EMPTY, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY))
call,
newCandidateDescriptor,
dispatchReceiver, extensionReceiver, explicitReceiverKind,
null, DelegatingBindingTrace(BindingTraceContext().bindingContext, "Temporary trace for unwrapped suspension function"),
TracingStrategy.EMPTY, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY)
)
this.valueArguments.forEach {
newCall.recordValueArgument(newCandidateDescriptor.valueParameters[it.key.index], it.value)
@@ -138,15 +142,17 @@ fun ResolvedCall<*>.replaceSuspensionFunctionWithRealDescriptor(
val arguments = psiFactory.createCallArguments("(this)").arguments.single()
val thisExpression = arguments.getArgumentExpression()!!
newCall.recordValueArgument(
newCandidateDescriptor.valueParameters.last(),
ExpressionValueArgument(arguments))
newCandidateDescriptor.valueParameters.last(),
ExpressionValueArgument(arguments)
)
val newTypeArguments = newCandidateDescriptor.typeParameters.map {
Pair(it, typeArguments[candidateDescriptor.typeParameters[it.index]]!!.asTypeProjection())
}.toMap()
newCall.setResultingSubstitutor(
TypeConstructorSubstitution.createByParametersMap(newTypeArguments).buildSubstitutor())
TypeConstructorSubstitution.createByParametersMap(newTypeArguments).buildSubstitutor()
)
return ResolvedCallWithRealDescriptor(newCall, thisExpression)
}
@@ -161,19 +167,19 @@ private fun ResolvedCall<VariableDescriptor>.asMutableResolvedCall(bindingContex
private fun NewResolvedCallImpl<VariableDescriptor>.asDummyOldResolvedCall(bindingContext: BindingContext): ResolvedCallImpl<VariableDescriptor> {
return ResolvedCallImpl(
call,
candidateDescriptor,
dispatchReceiver, extensionReceiver, explicitReceiverKind,
null, DelegatingBindingTrace(bindingContext, "Trace for old call"),
TracingStrategy.EMPTY, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY)
call,
candidateDescriptor,
dispatchReceiver, extensionReceiver, explicitReceiverKind,
null, DelegatingBindingTrace(bindingContext, "Trace for old call"),
TracingStrategy.EMPTY, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY)
)
}
fun ResolvedCall<*>.isSuspendNoInlineCall() =
resultingDescriptor.safeAs<FunctionDescriptor>()
?.let {
it.isSuspend && (!it.isInline || it.isBuiltInSuspendCoroutineOrReturnInJvm() || it.isBuiltInSuspendCoroutineUninterceptedOrReturnInJvm())
} == true
resultingDescriptor.safeAs<FunctionDescriptor>()
?.let {
it.isSuspend && (!it.isInline || it.isBuiltInSuspendCoroutineOrReturnInJvm() || it.isBuiltInSuspendCoroutineUninterceptedOrReturnInJvm())
} == true
fun CallableDescriptor.isSuspendFunctionNotSuspensionView(): Boolean {
if (this !is FunctionDescriptor) return false
@@ -193,14 +199,14 @@ fun <D : FunctionDescriptor> getOrCreateJvmSuspendFunctionView(function: D, bind
bindingContext?.get(CodegenBinding.SUSPEND_FUNCTION_TO_JVM_VIEW, function)?.let { return it as D }
val continuationParameter = ValueParameterDescriptorImpl(
function, null, function.valueParameters.size, Annotations.EMPTY, Name.identifier("continuation"),
// Add j.l.Object to invoke(), because that is the type of parameters we have in FunctionN+1
if (function.containingDeclaration.safeAs<ClassDescriptor>()?.defaultType?.isBuiltinFunctionalType == true)
function.builtIns.nullableAnyType
else
function.getContinuationParameterTypeOfSuspendFunction(),
/* declaresDefaultValue = */ false, /* isCrossinline = */ false,
/* isNoinline = */ false, /* varargElementType = */ null, SourceElement.NO_SOURCE
function, null, function.valueParameters.size, Annotations.EMPTY, Name.identifier("continuation"),
// Add j.l.Object to invoke(), because that is the type of parameters we have in FunctionN+1
if (function.containingDeclaration.safeAs<ClassDescriptor>()?.defaultType?.isBuiltinFunctionalType == true)
function.builtIns.nullableAnyType
else
function.getContinuationParameterTypeOfSuspendFunction(),
/* declaresDefaultValue = */ false, /* isCrossinline = */ false,
/* isNoinline = */ false, /* varargElementType = */ null, SourceElement.NO_SOURCE
)
return function.createCustomCopy {
@@ -213,18 +219,18 @@ fun <D : FunctionDescriptor> getOrCreateJvmSuspendFunctionView(function: D, bind
}
typealias FunctionDescriptorCopyBuilderToFunctionDescriptorCopyBuilder =
FunctionDescriptor.CopyBuilder<out FunctionDescriptor>.(FunctionDescriptor)
FunctionDescriptor.CopyBuilder<out FunctionDescriptor>.(FunctionDescriptor)
-> FunctionDescriptor.CopyBuilder<out FunctionDescriptor>
fun <D : FunctionDescriptor> D.createCustomCopy(
copySettings: FunctionDescriptorCopyBuilderToFunctionDescriptorCopyBuilder
copySettings: FunctionDescriptorCopyBuilderToFunctionDescriptorCopyBuilder
): D {
val newOriginal =
if (original !== this)
original.createCustomCopy(copySettings)
else
null
if (original !== this)
original.createCustomCopy(copySettings)
else
null
val result = newCopyBuilder().copySettings(this).setOriginal(newOriginal).build()!!
@@ -235,52 +241,52 @@ fun <D : FunctionDescriptor> D.createCustomCopy(
}
private fun FunctionDescriptor.getContinuationParameterTypeOfSuspendFunction() =
module.getContinuationOfTypeOrAny(returnType!!)
module.getContinuationOfTypeOrAny(returnType!!)
fun ModuleDescriptor.getContinuationOfTypeOrAny(kotlinType: KotlinType) =
module.findContinuationClassDescriptorOrNull(NoLookupLocation.FROM_BACKEND)?.defaultType?.let {
KotlinTypeFactory.simpleType(
it,
arguments = listOf(kotlinType.asTypeProjection())
)
} ?: module.builtIns.nullableAnyType
module.findContinuationClassDescriptorOrNull(NoLookupLocation.FROM_BACKEND)?.defaultType?.let {
KotlinTypeFactory.simpleType(
it,
arguments = listOf(kotlinType.asTypeProjection())
)
} ?: module.builtIns.nullableAnyType
fun FunctionDescriptor.isBuiltInSuspendCoroutineOrReturnInJvm() =
getUserData(INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION)?.isBuiltInSuspendCoroutineOrReturn() == true
getUserData(INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION)?.isBuiltInSuspendCoroutineOrReturn() == true
fun createMethodNodeForSuspendCoroutineOrReturn(
functionDescriptor: FunctionDescriptor,
typeMapper: KotlinTypeMapper
functionDescriptor: FunctionDescriptor,
typeMapper: KotlinTypeMapper
): MethodNode {
assert(functionDescriptor.isBuiltInSuspendCoroutineOrReturnInJvm()) {
"functionDescriptor must be kotlin.coroutines.intrinsics.suspendOrReturn"
}
val node =
MethodNode(
Opcodes.ASM5,
Opcodes.ACC_STATIC,
"fake",
typeMapper.mapAsmMethod(functionDescriptor).descriptor, null, null
)
MethodNode(
Opcodes.ASM5,
Opcodes.ACC_STATIC,
"fake",
typeMapper.mapAsmMethod(functionDescriptor).descriptor, null, null
)
node.visitVarInsn(Opcodes.ALOAD, 0)
node.visitVarInsn(Opcodes.ALOAD, 1)
node.visitMethodInsn(
Opcodes.INVOKESTATIC,
INTERNAL_COROUTINE_INTRINSICS_OWNER_INTERNAL_NAME,
NORMALIZE_CONTINUATION_METHOD_NAME,
Type.getMethodDescriptor(CONTINUATION_ASM_TYPE, CONTINUATION_ASM_TYPE),
false
Opcodes.INVOKESTATIC,
INTERNAL_COROUTINE_INTRINSICS_OWNER_INTERNAL_NAME,
NORMALIZE_CONTINUATION_METHOD_NAME,
Type.getMethodDescriptor(CONTINUATION_ASM_TYPE, CONTINUATION_ASM_TYPE),
false
)
node.visitMethodInsn(
Opcodes.INVOKEINTERFACE,
typeMapper.mapType(functionDescriptor.valueParameters[0]).internalName,
OperatorNameConventions.INVOKE.identifier,
"(${AsmTypes.OBJECT_TYPE})${AsmTypes.OBJECT_TYPE}",
true
Opcodes.INVOKEINTERFACE,
typeMapper.mapType(functionDescriptor.valueParameters[0]).internalName,
OperatorNameConventions.INVOKE.identifier,
"(${AsmTypes.OBJECT_TYPE})${AsmTypes.OBJECT_TYPE}",
true
)
node.visitInsn(Opcodes.ARETURN)
node.visitMaxs(2, 2)
@@ -289,32 +295,32 @@ fun createMethodNodeForSuspendCoroutineOrReturn(
}
fun FunctionDescriptor.isBuiltInSuspendCoroutineUninterceptedOrReturnInJvm() =
getUserData(INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION)?.isBuiltInSuspendCoroutineUninterceptedOrReturn() == true
getUserData(INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION)?.isBuiltInSuspendCoroutineUninterceptedOrReturn() == true
fun createMethodNodeForIntercepted(
functionDescriptor: FunctionDescriptor,
typeMapper: KotlinTypeMapper
functionDescriptor: FunctionDescriptor,
typeMapper: KotlinTypeMapper
): MethodNode {
assert(functionDescriptor.isBuiltInIntercepted()) {
"functionDescriptor must be kotlin.coroutines.intrinsics.intercepted"
}
val node =
MethodNode(
Opcodes.ASM5,
Opcodes.ACC_STATIC,
"fake",
typeMapper.mapAsmMethod(functionDescriptor).descriptor, null, null
)
MethodNode(
Opcodes.ASM5,
Opcodes.ACC_STATIC,
"fake",
typeMapper.mapAsmMethod(functionDescriptor).descriptor, null, null
)
node.visitVarInsn(Opcodes.ALOAD, 0)
node.visitMethodInsn(
Opcodes.INVOKESTATIC,
INTERNAL_COROUTINE_INTRINSICS_OWNER_INTERNAL_NAME,
NORMALIZE_CONTINUATION_METHOD_NAME,
Type.getMethodDescriptor(CONTINUATION_ASM_TYPE, CONTINUATION_ASM_TYPE),
false
Opcodes.INVOKESTATIC,
INTERNAL_COROUTINE_INTRINSICS_OWNER_INTERNAL_NAME,
NORMALIZE_CONTINUATION_METHOD_NAME,
Type.getMethodDescriptor(CONTINUATION_ASM_TYPE, CONTINUATION_ASM_TYPE),
false
)
node.visitInsn(Opcodes.ARETURN)
node.visitMaxs(1, 1)
@@ -328,24 +334,25 @@ fun createMethodNodeForCoroutineContext(functionDescriptor: FunctionDescriptor):
}
val node =
MethodNode(
Opcodes.ASM5,
Opcodes.ACC_STATIC,
"fake",
Type.getMethodDescriptor(COROUTINE_CONTEXT_ASM_TYPE, CONTINUATION_ASM_TYPE),
null, null
)
node.visitVarInsn(Opcodes.ALOAD, 0)
node.visitMethodInsn(
Opcodes.INVOKEINTERFACE,
CONTINUATION_ASM_TYPE.internalName,
GET_CONTEXT_METHOD_NAME,
MethodNode(
Opcodes.ASM5,
Opcodes.ACC_STATIC,
"fake",
Type.getMethodDescriptor(COROUTINE_CONTEXT_ASM_TYPE),
true
null, null
)
val v = InstructionAdapter(node)
addFakeContinuationMarker(v)
v.invokeinterface(
CONTINUATION_ASM_TYPE.internalName,
GET_CONTEXT_METHOD_NAME,
Type.getMethodDescriptor(COROUTINE_CONTEXT_ASM_TYPE)
)
node.visitInsn(Opcodes.ARETURN)
v.areturn(COROUTINE_CONTEXT_ASM_TYPE)
node.visitMaxs(1, 1)
return node
@@ -353,30 +360,30 @@ fun createMethodNodeForCoroutineContext(functionDescriptor: FunctionDescriptor):
fun createMethodNodeForSuspendCoroutineUninterceptedOrReturn(
functionDescriptor: FunctionDescriptor,
typeMapper: KotlinTypeMapper
functionDescriptor: FunctionDescriptor,
typeMapper: KotlinTypeMapper
): MethodNode {
assert(functionDescriptor.isBuiltInSuspendCoroutineUninterceptedOrReturnInJvm()) {
"functionDescriptor must be kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn"
}
val node =
MethodNode(
Opcodes.ASM5,
Opcodes.ACC_STATIC,
"fake",
typeMapper.mapAsmMethod(functionDescriptor).descriptor, null, null
)
MethodNode(
Opcodes.ASM5,
Opcodes.ACC_STATIC,
"fake",
typeMapper.mapAsmMethod(functionDescriptor).descriptor, null, null
)
node.visitVarInsn(Opcodes.ALOAD, 0)
node.visitVarInsn(Opcodes.ALOAD, 1)
node.visitMethodInsn(
Opcodes.INVOKEINTERFACE,
typeMapper.mapType(functionDescriptor.valueParameters[0]).internalName,
OperatorNameConventions.INVOKE.identifier,
"(${AsmTypes.OBJECT_TYPE})${AsmTypes.OBJECT_TYPE}",
true
Opcodes.INVOKEINTERFACE,
typeMapper.mapType(functionDescriptor.valueParameters[0]).internalName,
OperatorNameConventions.INVOKE.identifier,
"(${AsmTypes.OBJECT_TYPE})${AsmTypes.OBJECT_TYPE}",
true
)
node.visitInsn(Opcodes.ARETURN)
node.visitMaxs(2, 2)
@@ -386,21 +393,21 @@ fun createMethodNodeForSuspendCoroutineUninterceptedOrReturn(
@Suppress("UNCHECKED_CAST")
fun <D : CallableDescriptor?> D.unwrapInitialDescriptorForSuspendFunction(): D =
this.safeAs<SimpleFunctionDescriptor>()?.getUserData(INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION) as D ?: this
this.safeAs<SimpleFunctionDescriptor>()?.getUserData(INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION) as D ?: this
fun FunctionDescriptor.getOriginalSuspendFunctionView(bindingContext: BindingContext): FunctionDescriptor =
if (isSuspend)
getOrCreateJvmSuspendFunctionView(unwrapInitialDescriptorForSuspendFunction().original, bindingContext)
else
this
if (isSuspend)
getOrCreateJvmSuspendFunctionView(unwrapInitialDescriptorForSuspendFunction().original, bindingContext)
else
this
fun InstructionAdapter.loadCoroutineSuspendedMarker() {
invokestatic(
COROUTINES_INTRINSICS_FILE_FACADE_INTERNAL_NAME.internalName,
"get$COROUTINE_SUSPENDED_NAME",
Type.getMethodDescriptor(AsmTypes.OBJECT_TYPE),
false
COROUTINES_INTRINSICS_FILE_FACADE_INTERNAL_NAME.internalName,
"get$COROUTINE_SUSPENDED_NAME",
Type.getMethodDescriptor(AsmTypes.OBJECT_TYPE),
false
)
}
@@ -411,12 +418,12 @@ fun InstructionAdapter.invokeDoResumeWithUnit(thisName: String) {
aconst(null)
invokevirtual(
thisName,
DO_RESUME_METHOD_NAME,
Type.getMethodDescriptor(AsmTypes.OBJECT_TYPE, AsmTypes.OBJECT_TYPE, AsmTypes.JAVA_THROWABLE_TYPE),
false
thisName,
DO_RESUME_METHOD_NAME,
Type.getMethodDescriptor(AsmTypes.OBJECT_TYPE, AsmTypes.OBJECT_TYPE, AsmTypes.JAVA_THROWABLE_TYPE),
false
)
}
fun Method.getImplForOpenMethod(ownerInternalName: String) =
Method("$name\$suspendImpl", returnType, arrayOf(Type.getObjectType(ownerInternalName)) + argumentTypes)
Method("$name\$suspendImpl", returnType, arrayOf(Type.getObjectType(ownerInternalName)) + argumentTypes)

View File

@@ -47,4 +47,7 @@ interface ExpressionCodegenExtension {
fun applyFunction(receiver: StackValue, resolvedCall: ResolvedCall<*>, c: Context): StackValue? = null
fun generateClassSyntheticParts(codegen: ImplementationBodyCodegen) {}
val shouldGenerateClassSyntheticPartsInLightClassesMode: Boolean
get() = false
}

View File

@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.codegen.inline
import com.intellij.psi.PsiElement
import com.intellij.util.ArrayUtil
import org.jetbrains.kotlin.backend.common.isBuiltInCoroutineContext
import org.jetbrains.kotlin.backend.common.isBuiltInIntercepted
import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment
import org.jetbrains.kotlin.codegen.*
@@ -41,6 +40,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCallWithAssert
import org.jetbrains.kotlin.resolve.calls.checkers.isBuiltInCoroutineContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.inline.InlineUtil
import org.jetbrains.kotlin.resolve.inline.InlineUtil.isInlinableParameterExpression
@@ -265,9 +265,6 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
addInlineMarker(codegen.v, true)
}
if (functionDescriptor.isBuiltInCoroutineContext())
invocationParamBuilder.addNextValueParameter(CONTINUATION_ASM_TYPE, false, continuationValue(), 0)
val parameters = invocationParamBuilder.buildParameters()
val info = RootInliningContext(

View File

@@ -91,7 +91,8 @@ private const val INLINE_MARKER_FINALLY_START = "finallyStart"
private const val INLINE_MARKER_FINALLY_END = "finallyEnd"
private const val INLINE_MARKER_BEFORE_SUSPEND_ID = 0
private const val INLINE_MARKER_AFTER_SUSPEND_ID = 1
private const val INLINE_MARKET_RETURNS_UNIT = 2
private const val INLINE_MARKER_RETURNS_UNIT = 2
private const val INLINE_MARKER_FAKE_CONTINUATION = 3
private val INTRINSIC_ARRAY_CONSTRUCTOR_TYPE = AsmUtil.asmTypeByClassId(classId)
internal fun getMethodNode(
@@ -421,7 +422,7 @@ internal fun addSuspendMarker(v: InstructionAdapter, isStartNotEnd: Boolean) {
}
private fun addReturnsUnitMarker(v: InstructionAdapter) {
v.iconst(INLINE_MARKET_RETURNS_UNIT)
v.iconst(INLINE_MARKER_RETURNS_UNIT)
v.visitMethodInsn(
Opcodes.INVOKESTATIC, INLINE_MARKER_CLASS_NAME,
"mark",
@@ -429,9 +430,26 @@ private fun addReturnsUnitMarker(v: InstructionAdapter) {
)
}
/* There are contexts when the continuation does not yet exist, for example, in inline lambdas, which are going to
* be inlined into suspendable functions.
* In such cases we just generate the marker which is going to be replaced with real continuation on generating state machine.
* See [CoroutineTransformerMethodVisitor] for more info.
*/
internal fun addFakeContinuationMarker(v: InstructionAdapter) {
v.iconst(INLINE_MARKER_FAKE_CONTINUATION)
v.invokestatic(
INLINE_MARKER_CLASS_NAME,
"mark",
"(I)V", false
)
v.aconst(null)
}
internal fun isBeforeSuspendMarker(insn: AbstractInsnNode) = isSuspendMarker(insn, INLINE_MARKER_BEFORE_SUSPEND_ID)
internal fun isAfterSuspendMarker(insn: AbstractInsnNode) = isSuspendMarker(insn, INLINE_MARKER_AFTER_SUSPEND_ID)
internal fun isReturnsUnitMarker(insn: AbstractInsnNode) = isSuspendMarker(insn, INLINE_MARKET_RETURNS_UNIT)
internal fun isReturnsUnitMarker(insn: AbstractInsnNode) = isSuspendMarker(insn, INLINE_MARKER_RETURNS_UNIT)
internal fun isFakeContinuationMarker(insn: AbstractInsnNode) =
insn.previous != null && isSuspendMarker(insn.previous, INLINE_MARKER_FAKE_CONTINUATION) && insn.opcode == Opcodes.ACONST_NULL
private fun isSuspendMarker(insn: AbstractInsnNode, id: Int) =
isInlineMarker(insn, "mark") && insn.previous.intConstant == id

View File

@@ -126,14 +126,6 @@ private fun ExpressionCodegen.createIntrinsifiedRangeValueOrNull(rangeCall: Reso
CollectionIndicesRangeValue(rangeCall)
isCharSequenceIndices(rangeCallee) ->
CharSequenceIndicesRangeValue(rangeCall)
isArrayOrPrimitiveArrayWithIndex(rangeCallee) ->
ArrayWithIndexRangeValue(rangeCall)
isIterableWithIndex(rangeCallee) ->
IterableWithIndexRangeValue(rangeCall)
isSequenceWithIndex(rangeCallee) ->
SequenceWithIndexRangeValue(rangeCall)
isCharSequenceWithIndex(rangeCallee) ->
CharSequenceWithIndexRangeValue(rangeCall)
isComparableRangeTo(rangeCallee) ->
ComparableRangeLiteralRangeValue(this, rangeCall)
isPrimitiveProgressionReverse(rangeCallee) ->

View File

@@ -1,236 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.codegen.when;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.codegen.ExpressionCodegen;
import org.jetbrains.kotlin.codegen.FrameMap;
import org.jetbrains.kotlin.psi.KtWhenEntry;
import org.jetbrains.kotlin.psi.KtWhenExpression;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.NullValue;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.org.objectweb.asm.Label;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import java.util.*;
abstract public class SwitchCodegen {
protected final KtWhenExpression expression;
protected final boolean isStatement;
protected final boolean isExhaustive;
protected final ExpressionCodegen codegen;
protected final BindingContext bindingContext;
protected final Type subjectType;
protected final Type resultType;
protected final InstructionAdapter v;
protected final NavigableMap<Integer, Label> transitionsTable = new TreeMap<>();
protected final List<Label> entryLabels = new ArrayList<>();
protected Label elseLabel = new Label();
protected Label endLabel = new Label();
protected Label defaultLabel;
protected final SwitchCodegenProvider switchCodegenProvider;
public SwitchCodegen(
@NotNull KtWhenExpression expression, boolean isStatement,
boolean isExhaustive, @NotNull ExpressionCodegen codegen,
@Nullable Type subjectType
) {
this.expression = expression;
this.isStatement = isStatement;
this.isExhaustive = isExhaustive;
this.codegen = codegen;
this.bindingContext = codegen.getBindingContext();
this.switchCodegenProvider = new SwitchCodegenProvider(codegen);
this.subjectType = subjectType != null ? subjectType : codegen.expressionType(expression.getSubjectExpression());
resultType = isStatement ? Type.VOID_TYPE : codegen.expressionType(expression);
v = codegen.v;
}
/**
* Generates bytecode for entire when expression
*/
public void generate() {
prepareConfiguration();
boolean hasElse = expression.getElseExpression() != null;
// if there is no else-entry and it's statement then default --- endLabel
defaultLabel = (hasElse || !isStatement || isExhaustive) ? elseLabel : endLabel;
generateSubject();
generateSwitchInstructionByTransitionsTable();
generateEntries();
// there is no else-entry but this is not statement, so we should return Unit
if (!hasElse && (!isStatement || isExhaustive)) {
v.visitLabel(elseLabel);
codegen.putUnitInstanceOntoStackForNonExhaustiveWhen(expression, isStatement);
}
codegen.markLineNumber(expression, isStatement);
v.mark(endLabel);
}
/**
* Sets up transitionsTable and maybe something else needed in a special case
* Behaviour may be changed by overriding processConstant
*/
private void prepareConfiguration() {
for (KtWhenEntry entry : expression.getEntries()) {
Label entryLabel = new Label();
for (ConstantValue<?> constant : switchCodegenProvider.getConstantsFromEntry(entry)) {
if (constant instanceof NullValue) continue;
processConstant(constant, entryLabel);
}
if (entry.isElse()) {
elseLabel = entryLabel;
}
entryLabels.add(entryLabel);
}
}
abstract protected void processConstant(
@NotNull ConstantValue<?> constant,
@NotNull Label entryLabel
);
protected void putTransitionOnce(int value, @NotNull Label entryLabel) {
if (!transitionsTable.containsKey(value)) {
transitionsTable.put(value, entryLabel);
}
}
/**
* Should generate int subject on top of the stack
* Default implementation just run codegen for actual subject of expression
* May also gen nullability check if needed
*/
protected void generateSubject() {
codegen.gen(expression.getSubjectExpression(), subjectType);
}
protected void generateNullCheckIfNeeded() {
assert expression.getSubjectExpression() != null : "subject expression can't be null";
KotlinType subjectJetType = bindingContext.getType(expression.getSubjectExpression());
assert subjectJetType != null : "subject type can't be null (i.e. void)";
if (TypeUtils.isNullableType(subjectJetType)) {
int nullEntryIndex = findNullEntryIndex(expression);
Label nullLabel = nullEntryIndex == -1 ? defaultLabel : entryLabels.get(nullEntryIndex);
Label notNullLabel = new Label();
v.dup();
v.ifnonnull(notNullLabel);
v.pop();
v.goTo(nullLabel);
v.visitLabel(notNullLabel);
}
}
private int findNullEntryIndex(@NotNull KtWhenExpression expression) {
int entryIndex = 0;
for (KtWhenEntry entry : expression.getEntries()) {
for (ConstantValue<?> constant : switchCodegenProvider.getConstantsFromEntry(entry)) {
if (constant instanceof NullValue) {
return entryIndex;
}
}
entryIndex++;
}
return -1;
}
private void generateSwitchInstructionByTransitionsTable() {
int[] keys = new int[transitionsTable.size()];
Label[] labels = new Label[transitionsTable.size()];
int i = 0;
for (Map.Entry<Integer, Label> transition : transitionsTable.entrySet()) {
keys[i] = transition.getKey();
labels[i] = transition.getValue();
i++;
}
int nlabels = keys.length;
int hi = keys[nlabels - 1];
int lo = keys[0];
/*
* Heuristic estimation if it's better to use tableswitch or lookupswitch.
* From OpenJDK sources
*/
long table_space_cost = 4 + ((long) hi - lo + 1); // words
long table_time_cost = 3; // comparisons
long lookup_space_cost = 3 + 2 * (long) nlabels;
//noinspection UnnecessaryLocalVariable
long lookup_time_cost = nlabels;
boolean useTableSwitch = nlabels > 0 &&
table_space_cost + 3 * table_time_cost <=
lookup_space_cost + 3 * lookup_time_cost;
if (!useTableSwitch) {
v.lookupswitch(defaultLabel, keys, labels);
return;
}
Label[] sparseLabels = new Label[hi - lo + 1];
Arrays.fill(sparseLabels, defaultLabel);
for (i = 0; i < keys.length; i++) {
sparseLabels[keys[i] - lo] = labels[i];
}
v.tableswitch(lo, hi, defaultLabel, sparseLabels);
}
protected void generateEntries() {
// resolving entries' entryLabels and generating entries' code
Iterator<Label> entryLabelsIterator = entryLabels.iterator();
for (KtWhenEntry entry : expression.getEntries()) {
v.visitLabel(entryLabelsIterator.next());
FrameMap.Mark mark = codegen.myFrameMap.mark();
codegen.gen(entry.getExpression(), resultType);
mark.dropTo();
if (!entry.isElse()) {
v.goTo(endLabel);
}
}
}
}

View File

@@ -0,0 +1,181 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen.`when`
import org.jetbrains.kotlin.codegen.ExpressionCodegen
import org.jetbrains.kotlin.psi.KtWhenExpression
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.constants.NullValue
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.org.objectweb.asm.Label
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import java.util.*
abstract class SwitchCodegen(
@JvmField
protected val expression: KtWhenExpression,
protected val isStatement: Boolean,
private val isExhaustive: Boolean,
@JvmField
protected val codegen: ExpressionCodegen,
subjectType: Type?
) {
protected val bindingContext: BindingContext = codegen.bindingContext
@JvmField
protected val subjectType = subjectType ?: codegen.expressionType(expression.subjectExpression)
protected val resultType: Type = if (isStatement) Type.VOID_TYPE else codegen.expressionType(expression)
@JvmField
protected val v: InstructionAdapter = codegen.v
@JvmField
protected val transitionsTable: NavigableMap<Int, Label> = TreeMap()
private val entryLabels: MutableList<Label> = ArrayList()
private var elseLabel = Label()
private var endLabel = Label()
protected lateinit var defaultLabel: Label
private val switchCodegenProvider = SwitchCodegenProvider(codegen)
/**
* Generates bytecode for entire when expression
*/
open fun generate() {
prepareConfiguration()
val hasElse = expression.elseExpression != null
// if there is no else-entry and it's statement then default --- endLabel
defaultLabel = if (hasElse || !isStatement || isExhaustive) elseLabel else endLabel
generateSubject()
generateSwitchInstructionByTransitionsTable()
generateEntries()
// there is no else-entry but this is not statement, so we should return Unit
if (!hasElse && (!isStatement || isExhaustive)) {
v.visitLabel(elseLabel)
codegen.putUnitInstanceOntoStackForNonExhaustiveWhen(expression, isStatement)
}
codegen.markLineNumber(expression, isStatement)
v.mark(endLabel)
}
/**
* Sets up transitionsTable and maybe something else needed in a special case
* Behaviour may be changed by overriding processConstant
*/
private fun prepareConfiguration() {
for (entry in expression.entries) {
val entryLabel = Label()
for (constant in switchCodegenProvider.getConstantsFromEntry(entry)) {
if (constant is NullValue || constant == null) continue
processConstant(constant, entryLabel)
}
if (entry.isElse) {
elseLabel = entryLabel
}
entryLabels.add(entryLabel)
}
}
protected abstract fun processConstant(
constant: ConstantValue<*>,
entryLabel: Label
)
protected fun putTransitionOnce(value: Int, entryLabel: Label) {
if (!transitionsTable.containsKey(value)) {
transitionsTable[value] = entryLabel
}
}
/**
* Should generate int subject on top of the stack
* Default implementation just run codegen for actual subject of expression
* May also gen nullability check if needed
*/
protected open fun generateSubject() {
codegen.gen(expression.subjectExpression, subjectType)
}
protected fun generateNullCheckIfNeeded() {
assert(expression.subjectExpression != null) { "subject expression can't be null" }
val subjectJetType = bindingContext.getType(expression.subjectExpression!!) ?: error("subject type can't be null (i.e. void)")
if (TypeUtils.isNullableType(subjectJetType)) {
val nullEntryIndex = findNullEntryIndex(expression)
val nullLabel = if (nullEntryIndex == -1) defaultLabel else entryLabels[nullEntryIndex]
val notNullLabel = Label()
with(v) {
dup()
ifnonnull(notNullLabel)
pop()
goTo(nullLabel)
visitLabel(notNullLabel)
}
}
}
private fun findNullEntryIndex(expression: KtWhenExpression) =
expression.entries.withIndex().firstOrNull { (_, entry) ->
switchCodegenProvider.getConstantsFromEntry(entry).any { it is NullValue }
}?.index ?: -1
private fun generateSwitchInstructionByTransitionsTable() {
val keys = transitionsTable.keys.toIntArray()
val labelsNumber = keys.size
val maxValue = keys.last()
val minValue = keys.first()
val rangeLength = maxValue.toLong() - minValue.toLong() + 1L
// In modern JVM implementations it shouldn't matter very much for runtime performance
// whether to choose lookupswitch or tableswitch.
// The only metric that really matters is bytecode size and here we can estimate:
// - lookupswitch: ~ 2 * labelsNumber
// - tableswitch: ~ rangeLength
if (rangeLength > 2L * labelsNumber || rangeLength > Int.MAX_VALUE) {
val labels = transitionsTable.values.toTypedArray()
v.lookupswitch(defaultLabel, keys, labels)
return
}
val sparseLabels = Array(rangeLength.toInt()) { index ->
transitionsTable[index + minValue] ?: defaultLabel
}
v.tableswitch(minValue, maxValue, defaultLabel, *sparseLabels)
}
protected open fun generateEntries() {
// resolving entries' entryLabels and generating entries' code
val entryLabelsIterator = entryLabels.iterator()
for (entry in expression.entries) {
v.visitLabel(entryLabelsIterator.next())
val mark = codegen.myFrameMap.mark()
codegen.gen(entry.expression, resultType)
mark.dropTo()
if (!entry.isElse) {
v.goTo(endLabel)
}
}
}
}

View File

@@ -123,7 +123,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
value = "-Xlegacy-smart-cast-after-try",
description = "Allow var smart casts despite assignment in try block"
)
var legacySmartCastAfterTry by FreezableVar(false)
var legacySmartCastAfterTry: Boolean by FreezableVar(false)
@Argument(
value = "-Xeffect-system",
@@ -137,11 +137,27 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
)
var readDeserializedContracts: Boolean by FreezableVar(false)
@Argument(
value = "-Xexperimental",
valueDescription = "<fq.name>",
description = "Enable and propagate usages of experimental API for marker annotation with the given fully qualified name"
)
var experimental: Array<String>? by FreezableVar(null)
@Argument(
value = "-Xuse-experimental",
valueDescription = "<fq.name>",
description = "Enable usages of COMPILATION-affecting experimental API for marker annotation with the given fully qualified name"
)
var useExperimental: Array<String>? by FreezableVar(null)
open fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
return HashMap<AnalysisFlag<*>, Any>().apply {
put(AnalysisFlag.skipMetadataVersionCheck, skipMetadataVersionCheck)
put(AnalysisFlag.multiPlatformDoNotCheckActual, noCheckActual)
put(AnalysisFlag.allowKotlinPackage, allowKotlinPackage)
put(AnalysisFlag.experimental, experimental?.toList().orEmpty())
put(AnalysisFlag.useExperimental, useExperimental?.toList().orEmpty())
}
}

View File

@@ -22,6 +22,7 @@ import kotlin.reflect.KMutableProperty1
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.memberProperties
@Target(AnnotationTarget.PROPERTY)
annotation class Argument(
val value: String,
val shortName: String = "",

View File

@@ -31,6 +31,10 @@ class GenericReplCompilingEvaluator(val compiler: ReplCompiler,
override fun createState(lock: ReentrantReadWriteLock): IReplStageState<*> = AggregatedReplStageState(compiler.createState(lock), evaluator.createState(lock), lock)
override fun compileAndEval(state: IReplStageState<*>, codeLine: ReplCodeLine, scriptArgs: ScriptArgsWithTypes?, invokeWrapper: InvokeWrapper?): ReplEvalResult {
if (codeLine.code.trim().isEmpty()) {
return ReplEvalResult.UnitResult()
}
return state.lock.write {
val aggregatedState = state.asState(AggregatedReplStageState::class.java)
val compiled = compiler.compile(state, codeLine)

View File

@@ -35,7 +35,7 @@
interface="org.jetbrains.kotlin.idea.core.script.ScriptDefinitionContributor"
area="IDEA_PROJECT"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.scriptTemplatesProvider"
interface="org.jetbrains.kotlin.idea.core.script.ScriptTemplatesProvider"
interface="org.jetbrains.kotlin.script.ScriptTemplatesProvider"
area="IDEA_PROJECT"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.facetConfigurationExtension"
interface="org.jetbrains.kotlin.idea.facet.KotlinFacetConfigurationExtension"/>

View File

@@ -23,6 +23,7 @@ import com.intellij.psi.util.PsiFormatUtil
import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
import org.jetbrains.kotlin.codegen.state.IncompatibleClassTrackerImpl
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.diagnostics.*
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils.sortedDiagnostics
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
@@ -33,12 +34,16 @@ import org.jetbrains.kotlin.resolve.AnalyzingUtils
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.resolve.jvm.JvmBindingContextSlices
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData
class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector) {
class AnalyzerWithCompilerReport(
private val messageCollector: MessageCollector,
private val languageVersionSettings: LanguageVersionSettings
) {
lateinit var analysisResult: AnalysisResult
private fun reportIncompleteHierarchies() {
@@ -94,6 +99,11 @@ class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector)
fun analyzeAndReport(files: Collection<KtFile>, analyze: () -> AnalysisResult) {
analysisResult = analyze()
ExperimentalUsageChecker.checkCompilerArguments(
analysisResult.moduleDescriptor, languageVersionSettings,
reportError = { message -> messageCollector.report(ERROR, message) },
reportWarning = { message -> messageCollector.report(WARNING, message) }
)
reportSyntaxErrors(files)
reportDiagnostics(analysisResult.bindingContext.diagnostics, messageCollector)
reportIncompleteHierarchies()

View File

@@ -222,7 +222,9 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
return COMPILATION_ERROR;
}
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(messageCollector);
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(
messageCollector, CommonConfigurationKeysKt.getLanguageVersionSettings(configuration)
);
analyzerWithCompilerReport.analyzeAndReport(sourcesFiles, () -> TopDownAnalyzerFacadeForJS.analyzeFiles(sourcesFiles, config));
if (analyzerWithCompilerReport.hasErrors()) {
return COMPILATION_ERROR;

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.cli.jvm.compiler
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PackagePartProvider
import org.jetbrains.kotlin.js.resolve.getAnnotationsOnContainingJsModule
import org.jetbrains.kotlin.load.kotlin.getJvmModuleNameForDeserializedDescriptor
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.ModuleAnnotationsResolver
class CliModuleAnnotationsResolver : ModuleAnnotationsResolver {
private val packagePartProviders = mutableListOf<PackagePartProvider>()
fun addPackagePartProvider(packagePartProvider: PackagePartProvider) {
packagePartProviders += packagePartProvider
}
override fun getAnnotationsOnContainingModule(descriptor: DeclarationDescriptor): List<ClassId> {
getAnnotationsOnContainingJsModule(descriptor)?.let { return it }
val moduleName = getJvmModuleNameForDeserializedDescriptor(descriptor) ?: return emptyList()
return packagePartProviders.flatMap { it.getAnnotationsOnBinaryModule(moduleName) }
}
}

View File

@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.PackagePartProvider
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
import org.jetbrains.kotlin.load.kotlin.PackageParts
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration
import java.io.EOFException
@@ -31,7 +32,7 @@ class JvmPackagePartProvider(
languageVersionSettings: LanguageVersionSettings,
private val scope: GlobalSearchScope
) : PackagePartProvider {
private data class ModuleMappingInfo(val root: VirtualFile, val mapping: ModuleMapping)
private data class ModuleMappingInfo(val root: VirtualFile, val mapping: ModuleMapping, val name: String)
private val deserializationConfiguration = CompilerDeserializationConfiguration(languageVersionSettings)
@@ -68,6 +69,12 @@ class JvmPackagePartProvider(
return result
}
override fun getAnnotationsOnBinaryModule(moduleName: String): List<ClassId> {
return loadedModules.mapNotNull { (_, mapping, name) ->
if (name == moduleName) mapping.moduleData.annotations else null
}.flatten()
}
fun addRoots(roots: List<JavaRoot>) {
for ((root, type) in roots) {
if (type != JavaRoot.RootType.BINARY) continue
@@ -83,7 +90,7 @@ class JvmPackagePartProvider(
catch (e: EOFException) {
throw RuntimeException("Error on reading package parts from $moduleFile in $root", e)
}
loadedModules.add(ModuleMappingInfo(root, mapping))
loadedModules.add(ModuleMappingInfo(root, mapping, moduleFile.nameWithoutExtension))
}
}
}

View File

@@ -29,8 +29,6 @@ import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.lang.MetaLanguage
import com.intellij.lang.java.JavaParserDefinition
import com.intellij.lang.jvm.facade.JvmElementProvider
import com.intellij.lang.jvm.facade.JvmFacade
import com.intellij.lang.jvm.facade.JvmFacadeImpl
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.TransactionGuard
import com.intellij.openapi.application.TransactionGuardImpl
@@ -100,6 +98,7 @@ import org.jetbrains.kotlin.load.kotlin.VirtualFileFinderFactory
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
import org.jetbrains.kotlin.resolve.ModuleAnnotationsResolver
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
import org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
@@ -276,6 +275,7 @@ class KotlinCoreEnvironment private constructor(
return JvmPackagePartProvider(configuration.languageVersionSettings, scope).apply {
addRoots(initialRoots)
packagePartProviders += this
(ModuleAnnotationsResolver.getInstance(project) as CliModuleAnnotationsResolver).addPackagePartProvider(this)
}
}
@@ -566,6 +566,7 @@ class KotlinCoreEnvironment private constructor(
registerService(ScriptDependenciesProvider::class.java, CliScriptDependenciesProvider(projectEnvironment.project, scriptDefinitionProvider))
registerService(KotlinJavaPsiFacade::class.java, KotlinJavaPsiFacade(this))
registerService(KtLightClassForFacade.FacadeStubCache::class.java, KtLightClassForFacade.FacadeStubCache(this))
registerService(ModuleAnnotationsResolver::class.java, CliModuleAnnotationsResolver())
if (messageCollector != null) {
registerService(ScriptReportSink::class.java, CliScriptReportSink(messageCollector))
}

View File

@@ -43,10 +43,7 @@ import org.jetbrains.kotlin.cli.jvm.config.*
import org.jetbrains.kotlin.codegen.*
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.codegen.state.GenerationStateEventCallback
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.config.addKotlinSourceRoots
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
import org.jetbrains.kotlin.idea.MainFunctionDetector
import org.jetbrains.kotlin.javac.JavacWrapper
@@ -364,7 +361,7 @@ object KotlinToJVMBytecodeCompiler {
val collector = environment.messageCollector
val analysisStart = PerformanceCounter.currentTime()
val analyzerWithCompilerReport = AnalyzerWithCompilerReport(collector)
val analyzerWithCompilerReport = AnalyzerWithCompilerReport(collector, environment.configuration.languageVersionSettings)
analyzerWithCompilerReport.analyzeAndReport(sourceFiles) {
val project = environment.project
val moduleOutputs = environment.configuration.get(JVMConfigurationKeys.MODULES)?.mapNotNullTo(hashSetOf()) { module ->

View File

@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.cli.jvm.repl.messages.unescapeLineBreaks
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import java.io.File
import java.io.IOException
import java.io.PrintWriter
import java.util.*
import java.util.concurrent.Callable
@@ -140,8 +141,12 @@ class ReplFromTerminal(
}
else if (split.size >= 2 && split[0] == "load") {
val fileName = split[1]
val scriptText = FileUtil.loadFile(File(fileName))
eval(scriptText)
try {
val scriptText = FileUtil.loadFile(File(fileName))
eval(scriptText)
} catch (e: IOException) {
writer.outputCompileError("Can not load script: ${e.message}")
}
return true
}
else {

View File

@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.serialization.DescriptorSerializer
import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment.Companion.DOT_METADATA_FILE_EXTENSION
import org.jetbrains.kotlin.serialization.jvm.JvmPackageTable
import org.jetbrains.kotlin.serialization.jvm.JvmModuleProtoBuf
import java.io.ByteArrayOutputStream
import java.io.DataOutputStream
import java.io.File
@@ -62,7 +62,7 @@ open class MetadataSerializer(private val dependOnOldBuiltIns: Boolean) {
return
}
val analyzer = AnalyzerWithCompilerReport(messageCollector)
val analyzer = AnalyzerWithCompilerReport(messageCollector, configuration.languageVersionSettings)
analyzer.analyzeAndReport(files) {
CommonAnalyzerFacade.analyzeFiles(files, moduleName, dependOnOldBuiltIns, configuration.languageVersionSettings) { _, content ->
environment.createPackagePartProvider(content.moduleContentScope)
@@ -121,11 +121,11 @@ open class MetadataSerializer(private val dependOnOldBuiltIns: Boolean) {
}
val kotlinModuleFile = File(destDir, JvmCodegenUtil.getMappingFileName(JvmCodegenUtil.getModuleName(module)))
val packageTableBytes = JvmPackageTable.PackageTable.newBuilder().apply {
val packageTableBytes = JvmModuleProtoBuf.Module.newBuilder().apply {
for (table in packageTable.values) {
table.addTo(this)
}
}.serializeToByteArray()
}.build().serializeToByteArray()
kotlinModuleFile.parentFile.mkdirs()
kotlinModuleFile.writeBytes(packageTableBytes)

View File

@@ -137,6 +137,8 @@ class CompileServiceImpl(
private val sessions: MutableMap<Int, ClientOrSessionProxy<Any>> = hashMapOf()
private val sessionsIdCounter = AtomicInteger(0)
val lastSessionId get() = sessionsIdCounter.get()
fun<T: Any> leaseSession(session: ClientOrSessionProxy<T>): Int = lock.write {
val newId = getValidId(sessionsIdCounter) {
it != CompileService.NO_SESSION && !sessions.containsKey(it)
@@ -182,8 +184,13 @@ class CompileServiceImpl(
val aliveClientsCount: Int get() = clientProxies.size
private val _clientsCounter = AtomicInteger(0)
val clientsCounter get() = _clientsCounter.get()
fun addClient(aliveFlagPath: String?) {
clientsLock.write {
_clientsCounter.incrementAndGet()
clientProxies.add(ClientOrSessionProxy(aliveFlagPath))
}
}
@@ -352,70 +359,72 @@ class CompileServiceImpl(
servicesFacade: CompilerServicesFacadeBase,
compilationResults: CompilationResults?
): CompileService.CallResult<Int> = ifAlive {
val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions)
val daemonReporter = DaemonMessageReporter(servicesFacade, compilationOptions)
val targetPlatform = compilationOptions.targetPlatform
log.info("Starting compilation with args: " + compilerArguments.joinToString(" "))
withValidClientOrSessionProxy(sessionId) {
val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions)
val daemonReporter = DaemonMessageReporter(servicesFacade, compilationOptions)
val targetPlatform = compilationOptions.targetPlatform
log.info("Starting compilation with args: " + compilerArguments.joinToString(" "))
@Suppress("UNCHECKED_CAST")
val compiler = when (targetPlatform) {
CompileService.TargetPlatform.JVM -> K2JVMCompiler()
CompileService.TargetPlatform.JS -> K2JSCompiler()
CompileService.TargetPlatform.METADATA -> K2MetadataCompiler()
} as CLICompiler<CommonCompilerArguments>
@Suppress("UNCHECKED_CAST")
val compiler = when (targetPlatform) {
CompileService.TargetPlatform.JVM -> K2JVMCompiler()
CompileService.TargetPlatform.JS -> K2JSCompiler()
CompileService.TargetPlatform.METADATA -> K2MetadataCompiler()
} as CLICompiler<CommonCompilerArguments>
val k2PlatformArgs = compiler.createArguments()
parseCommandLineArguments(compilerArguments.asList(), k2PlatformArgs)
val argumentParseError = validateArguments(k2PlatformArgs.errors)
if (argumentParseError != null) {
messageCollector.report(CompilerMessageSeverity.ERROR, argumentParseError)
CompileService.CallResult.Good(ExitCode.COMPILATION_ERROR.code)
}
else when (compilationOptions.compilerMode) {
CompilerMode.JPS_COMPILER -> {
val jpsServicesFacade = servicesFacade as JpsCompilerServicesFacade
withIC(enabled = servicesFacade.hasIncrementalCaches()) {
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
val services = createCompileServices(jpsServicesFacade, eventManger, profiler)
compiler.exec(messageCollector, services, k2PlatformArgs)
}
}
val k2PlatformArgs = compiler.createArguments()
parseCommandLineArguments(compilerArguments.asList(), k2PlatformArgs)
val argumentParseError = validateArguments(k2PlatformArgs.errors)
if (argumentParseError != null) {
messageCollector.report(CompilerMessageSeverity.ERROR, argumentParseError)
CompileService.CallResult.Good(ExitCode.COMPILATION_ERROR.code)
}
CompilerMode.NON_INCREMENTAL_COMPILER -> {
doCompile(sessionId, daemonReporter, tracer = null) { _, _ ->
compiler.exec(messageCollector, Services.EMPTY, k2PlatformArgs)
}
}
CompilerMode.INCREMENTAL_COMPILER -> {
val gradleIncrementalArgs = compilationOptions as IncrementalCompilationOptions
val gradleIncrementalServicesFacade = servicesFacade as IncrementalCompilerServicesFacade
else when (compilationOptions.compilerMode) {
CompilerMode.JPS_COMPILER -> {
val jpsServicesFacade = servicesFacade as JpsCompilerServicesFacade
when (targetPlatform) {
CompileService.TargetPlatform.JVM -> {
val k2jvmArgs = k2PlatformArgs as K2JVMCompilerArguments
withIC {
doCompile(sessionId, daemonReporter, tracer = null) { _, _ ->
execIncrementalCompiler(k2jvmArgs, gradleIncrementalArgs, gradleIncrementalServicesFacade, compilationResults!!,
messageCollector, daemonReporter)
}
withIC(enabled = servicesFacade.hasIncrementalCaches()) {
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
val services = createCompileServices(jpsServicesFacade, eventManger, profiler)
compiler.exec(messageCollector, services, k2PlatformArgs)
}
}
CompileService.TargetPlatform.JS -> {
val k2jsArgs = k2PlatformArgs as K2JSCompilerArguments
}
CompilerMode.NON_INCREMENTAL_COMPILER -> {
doCompile(sessionId, daemonReporter, tracer = null) { _, _ ->
compiler.exec(messageCollector, Services.EMPTY, k2PlatformArgs)
}
}
CompilerMode.INCREMENTAL_COMPILER -> {
val gradleIncrementalArgs = compilationOptions as IncrementalCompilationOptions
val gradleIncrementalServicesFacade = servicesFacade as IncrementalCompilerServicesFacade
withJsIC {
doCompile(sessionId, daemonReporter, tracer = null) { _, _ ->
execJsIncrementalCompiler(k2jsArgs, gradleIncrementalArgs, gradleIncrementalServicesFacade, compilationResults!!, messageCollector)
when (targetPlatform) {
CompileService.TargetPlatform.JVM -> {
val k2jvmArgs = k2PlatformArgs as K2JVMCompilerArguments
withIC {
doCompile(sessionId, daemonReporter, tracer = null) { _, _ ->
execIncrementalCompiler(k2jvmArgs, gradleIncrementalArgs, gradleIncrementalServicesFacade, compilationResults!!,
messageCollector, daemonReporter)
}
}
}
}
else -> throw IllegalStateException("Incremental compilation is not supported for target platform: $targetPlatform")
CompileService.TargetPlatform.JS -> {
val k2jsArgs = k2PlatformArgs as K2JSCompilerArguments
withJsIC {
doCompile(sessionId, daemonReporter, tracer = null) { _, _ ->
execJsIncrementalCompiler(k2jsArgs, gradleIncrementalArgs, gradleIncrementalServicesFacade, compilationResults!!, messageCollector)
}
}
}
else -> throw IllegalStateException("Incremental compilation is not supported for target platform: $targetPlatform")
}
}
else -> throw IllegalStateException("Unknown compilation mode ${compilationOptions.compilerMode}")
}
else -> throw IllegalStateException("Unknown compilation mode ${compilationOptions.compilerMode}")
}
}
@@ -801,18 +810,23 @@ class CompileServiceImpl(
private fun shutdownWithDelay() {
state.delayedShutdownQueued.set(true)
val currentClientsCount = state.clientsCounter
val currentSessionId = state.sessions.lastSessionId
val currentCompilationsCount = compilationsCounter.get()
log.info("Delayed shutdown in ${daemonOptions.shutdownDelayMilliseconds}ms")
timer.schedule(daemonOptions.shutdownDelayMilliseconds) {
state.delayedShutdownQueued.set(false)
if (currentCompilationsCount == compilationsCounter.get()) {
if (currentClientsCount == state.clientsCounter &&
currentCompilationsCount == compilationsCounter.get() &&
currentSessionId == state.sessions.lastSessionId)
{
ifAliveExclusiveUnit(minAliveness = Aliveness.LastSession) {
log.fine("Execute delayed shutdown")
shutdownNow()
}
}
else {
log.info("Cancel delayed shutdown due to new client")
log.info("Cancel delayed shutdown due to a new activity")
}
}
}

View File

@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
import org.jetbrains.kotlin.serialization.deserialization.getExtensionOrNull
import org.jetbrains.kotlin.serialization.jvm.BitEncoding
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.JvmMethodSignature
@@ -62,8 +63,8 @@ private fun inlineAccessorsJvmNames(properties: List<ProtoBuf.Property>, nameRes
}
val inlineAccessors = arrayListOf<JvmMethodSignature>()
propertiesWithInlineAccessors.forEach { proto ->
if (proto.hasExtension(JvmProtoBuf.propertySignature)) {
val signature = proto.getExtension(JvmProtoBuf.propertySignature)
val signature = proto.getExtensionOrNull(JvmProtoBuf.propertySignature)
if (signature != null) {
if (proto.hasGetterFlags() && Flags.IS_INLINE_ACCESSOR.get(proto.getterFlags)) {
inlineAccessors.add(signature.getter)
}

View File

@@ -90,7 +90,9 @@ class IncrementalPackageFragmentProvider(
DeserializedPackageMemberScope(
this, packageProto, nameResolver,
JvmPackagePartSource(partName, facadeName, knownJvmBinaryClass = jvmBinaryClass),
JvmPackagePartSource(
partName, facadeName, packageProto, nameResolver, knownJvmBinaryClass = jvmBinaryClass
),
deserializationComponents, classNames = { emptyList() }
)
}

View File

@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.load.kotlin.incremental
import org.jetbrains.kotlin.descriptors.PackagePartProvider
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
import org.jetbrains.kotlin.storage.StorageManager
@@ -42,4 +43,8 @@ class IncrementalPackagePartProvider(
// TODO
override fun findMetadataPackageParts(packageFqName: String): List<String> = TODO()
override fun getAnnotationsOnBinaryModule(moduleName: String): List<ClassId> {
return parent.getAnnotationsOnBinaryModule(moduleName)
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.load.kotlin
import org.jetbrains.kotlin.descriptors.ClassOrPackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberDescriptor
import org.jetbrains.kotlin.serialization.deserialization.getExtensionOrNull
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
fun getJvmModuleNameForDeserializedDescriptor(descriptor: DeclarationDescriptor): String? {
val parent = DescriptorUtils.getParentOfType(descriptor, ClassOrPackageFragmentDescriptor::class.java, false)
when {
parent is DeserializedClassDescriptor -> {
val classProto = parent.classProto
val nameResolver = parent.c.nameResolver
return classProto.getExtensionOrNull(JvmProtoBuf.classModuleName)
?.let(nameResolver::getString)
?: JvmAbi.DEFAULT_MODULE_NAME
}
descriptor is DeserializedMemberDescriptor -> {
val source = descriptor.containerSource
if (source is JvmPackagePartSource) {
val packageProto = source.packageProto
val nameResolver = source.nameResolver
return packageProto.getExtensionOrNull(JvmProtoBuf.packageModuleName)
?.let(nameResolver::getString)
?: JvmAbi.DEFAULT_MODULE_NAME
}
}
}
return null
}

View File

@@ -70,7 +70,9 @@ object JvmAnalyzerFacade : AnalyzerFacade() {
@Suppress("UNCHECKED_CAST")
val resolverForReferencedModule = referencedClassModule?.let { resolverForProject.tryGetResolverForModule(it as M) }
val resolverForModule = resolverForReferencedModule ?: run {
val resolverForModule = resolverForReferencedModule?.takeIf {
referencedClassModule.platform == JvmPlatform || referencedClassModule.platform == null
} ?: run {
// in case referenced class lies outside of our resolver, resolve the class as if it is inside our module
// this leads to java class being resolved several times
resolverForProject.resolverForModule(moduleInfo)

View File

@@ -31,6 +31,9 @@ interface LegacyResolverWrapper
internal class LegacyPackageDependencyResolverWrapper(
val legacyResolver: ScriptDependenciesResolver
) : kotlin.script.experimental.dependencies.DependenciesResolver, LegacyResolverWrapper {
private var previousDependencies: org.jetbrains.kotlin.script.KotlinScriptExternalDependencies? = null
override fun resolve(
scriptContents: kotlin.script.dependencies.ScriptContents,
environment: Environment
@@ -45,7 +48,8 @@ internal class LegacyPackageDependencyResolverWrapper(
environment,
{ sev, msg, pos ->
reports.add(ScriptReport(msg, sev.convertSeverity(), pos?.convertPosition()))
}, null
},
previousDependencies
).get() ?: return DependenciesResolver.ResolveResult.Failure(reports)
val dependencies = ScriptDependencies(
@@ -55,6 +59,7 @@ internal class LegacyPackageDependencyResolverWrapper(
sources = legacyDeps.sources.toList(),
scripts = legacyDeps.scripts.toList()
)
previousDependencies = legacyDeps
return DependenciesResolver.ResolveResult.Success(dependencies, reports)
}
@@ -73,6 +78,9 @@ internal class ApiChangeDependencyResolverWrapper(
) : kotlin.script.experimental.dependencies.DependenciesResolver,
DependencyResolverWrapper<kotlin.script.dependencies.ScriptDependenciesResolver>,
LegacyResolverWrapper {
private var previousDependencies: kotlin.script.dependencies.KotlinScriptExternalDependencies? = null
override fun resolve(
scriptContents: kotlin.script.dependencies.ScriptContents,
environment: Environment
@@ -83,7 +91,8 @@ internal class ApiChangeDependencyResolverWrapper(
environment,
{ sev, msg, pos ->
reports.add(ScriptReport(msg, sev.convertSeverity(), pos?.convertPosition()))
}, null
},
previousDependencies
).get() ?: return DependenciesResolver.ResolveResult.Failure(reports)
val dependencies = ScriptDependencies(
@@ -93,6 +102,7 @@ internal class ApiChangeDependencyResolverWrapper(
sources = legacyDeps.sources.toList(),
scripts = legacyDeps.scripts.toList()
)
previousDependencies = legacyDeps
return DependenciesResolver.ResolveResult.Success(dependencies, reports)
}

View File

@@ -238,6 +238,18 @@ public interface Errors {
DiagnosticFactory1<PsiElement, FqName> ILLEGAL_KOTLIN_VERSION_STRING_VALUE = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, String> NEWER_VERSION_IN_SINCE_KOTLIN = DiagnosticFactory1.create(WARNING);
DiagnosticFactory2<PsiElement, FqName, Boolean> EXPERIMENTAL_API_USAGE = DiagnosticFactory2.create(WARNING);
DiagnosticFactory2<PsiElement, FqName, Boolean> EXPERIMENTAL_API_USAGE_ERROR = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<PsiElement, FqName, DeclarationDescriptor> EXPERIMENTAL_OVERRIDE = DiagnosticFactory2.create(WARNING);
DiagnosticFactory2<PsiElement, FqName, DeclarationDescriptor> EXPERIMENTAL_OVERRIDE_ERROR = DiagnosticFactory2.create(ERROR);
DiagnosticFactory0<KtAnnotationEntry> USE_EXPERIMENTAL_WITHOUT_ARGUMENTS = DiagnosticFactory0.create(WARNING);
DiagnosticFactory1<KtAnnotationEntry, FqName> USE_EXPERIMENTAL_ARGUMENT_IS_NOT_MARKER = DiagnosticFactory1.create(WARNING);
DiagnosticFactory1<KtAnnotationEntry, FqName> USE_EXPERIMENTAL_ARGUMENT_HAS_NON_COMPILATION_IMPACT = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<KtAnnotationEntry> EXPERIMENTAL_ANNOTATION_WITH_NO_IMPACT = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<KtAnnotationEntry, String> EXPERIMENTAL_ANNOTATION_WITH_WRONG_TARGET = DiagnosticFactory1.create(ERROR);
// Const
DiagnosticFactory0<PsiElement> CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> CONST_VAL_WITH_GETTER = DiagnosticFactory0.create(ERROR);
@@ -984,6 +996,9 @@ public interface Errors {
DiagnosticFactory1<PsiElement, CallableDescriptor> ILLEGAL_SUSPEND_FUNCTION_CALL = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, CallableDescriptor> ILLEGAL_SUSPEND_PROPERTY_ACCESS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<PsiElement> ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> NON_MODIFIER_FORM_FOR_BUILT_IN_SUSPEND = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtReturnExpression> RETURN_FOR_BUILT_IN_SUSPEND = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND = DiagnosticFactory0.create(WARNING);
DiagnosticFactory1<PsiElement, RenderedDiagnostic<?>> PLUGIN_ERROR = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, RenderedDiagnostic<?>> PLUGIN_WARNING = DiagnosticFactory1.create(WARNING);

View File

@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.config.LanguageVersion;
import org.jetbrains.kotlin.diagnostics.Diagnostic;
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory;
import org.jetbrains.kotlin.diagnostics.Errors;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.resolve.VarianceConflictDiagnosticData;
import org.jetbrains.kotlin.serialization.deserialization.descriptors.VersionRequirement;
import org.jetbrains.kotlin.types.KotlinTypeKt;
@@ -33,6 +34,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.AddToStdlibKt;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.ServiceLoader;
@@ -149,6 +151,27 @@ public class DefaultErrorMessages {
MAP.put(ILLEGAL_KOTLIN_VERSION_STRING_VALUE, "Invalid @{0} annotation value (should be ''major.minor'' or ''major.minor.patch'')", TO_STRING);
MAP.put(NEWER_VERSION_IN_SINCE_KOTLIN, "The version is greater than the specified API version {0}", STRING);
RenderingContext.Key<FqName> getExperimentalFqName = new RenderingContext.Key<FqName>("getExperimentalFqName") {
@Override
public FqName compute(@NotNull Collection<?> objectsToRender) {
return (FqName) CollectionsKt.first(objectsToRender);
}
};
DiagnosticParameterRenderer<Boolean> renderUseExperimental = (useExperimentalAllowed, c) ->
useExperimentalAllowed ? " or ''@UseExperimental(" + c.get(getExperimentalFqName) + "::class)''" : "";
MAP.put(EXPERIMENTAL_API_USAGE, "This declaration is experimental and its usage should be marked with ''@{0}''{1}", TO_STRING, renderUseExperimental);
MAP.put(EXPERIMENTAL_API_USAGE_ERROR, "This declaration is experimental and its usage must be marked with ''@{0}''{1}", TO_STRING, renderUseExperimental);
MAP.put(EXPERIMENTAL_OVERRIDE, "This declaration overrides experimental member of supertype ''{1}'' and should be annotated with ''@{0}''", TO_STRING, NAME);
MAP.put(EXPERIMENTAL_OVERRIDE_ERROR, "This declaration overrides experimental member of supertype ''{1}'' and must be annotated with ''@{0}''", TO_STRING, NAME);
MAP.put(USE_EXPERIMENTAL_WITHOUT_ARGUMENTS, "@UseExperimental without any arguments has no effect");
MAP.put(USE_EXPERIMENTAL_ARGUMENT_IS_NOT_MARKER, "Annotation ''{0}'' is not an experimental API marker, therefore its usage in @UseExperimental is ignored", TO_STRING);
MAP.put(USE_EXPERIMENTAL_ARGUMENT_HAS_NON_COMPILATION_IMPACT,
"Experimental annotation ''{0}'' has impact other than COMPILATION, therefore its usage in @UseExperimental is forbidden", TO_STRING);
MAP.put(EXPERIMENTAL_ANNOTATION_WITH_NO_IMPACT, "Experimental annotation with changesMayBreak = [] is not allowed");
MAP.put(EXPERIMENTAL_ANNOTATION_WITH_WRONG_TARGET, "Experimental annotation cannot be used on the following code elements: {0}. Please remove these targets", STRING);
MAP.put(REDUNDANT_MODIFIER, "Modifier ''{0}'' is redundant because ''{1}'' is present", TO_STRING, TO_STRING);
MAP.put(REDUNDANT_OPEN_IN_INTERFACE, "Modifier 'open' is redundant for abstract interface members");
MAP.put(REDUNDANT_MODIFIER_IN_GETTER, "Visibility modifiers are redundant in getter");
@@ -873,6 +896,9 @@ public class DefaultErrorMessages {
MAP.put(ILLEGAL_SUSPEND_FUNCTION_CALL, "Suspend function ''{0}'' should be called only from a coroutine or another suspend function", NAME);
MAP.put(ILLEGAL_SUSPEND_PROPERTY_ACCESS, "Suspend property ''{0}'' should be accessed only from a coroutine or suspend function", NAME);
MAP.put(ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL, "Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope");
MAP.put(NON_MODIFIER_FORM_FOR_BUILT_IN_SUSPEND, "''suspend'' function can only be called in a form of modifier of a lambda: suspend { ... }");
MAP.put(RETURN_FOR_BUILT_IN_SUSPEND, "Using implicit label for this lambda is prohibited");
MAP.put(MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND, "Calls having a form of ''suspend {}'' are deprecated because ''suspend'' in the context will have a meaning of a modifier. Add empty argument list to the call: ''suspend() { ... }''");
MAP.put(PLUGIN_ERROR, "{0}", (d, c) -> d.getText());
MAP.put(PLUGIN_WARNING, "{0}", (d, c) -> d.getText());

View File

@@ -29,17 +29,12 @@ sealed class RenderingContext {
class Impl(private val objectsToRender: Collection<Any?>) : RenderingContext() {
private val data = linkedMapOf<Key<*>, Any?>()
@Suppress("UNCHECKED_CAST")
override fun <T> get(key: Key<T>): T {
if (!data.containsKey(key)) {
val result = key.compute(objectsToRender)
data[key] = result
return result
}
return data[key] as T
return data[key] as? T ?: key.compute(objectsToRender).also { data[key] = it }
}
}
object Empty : RenderingContext() {
override fun <T> get(key: Key<T>): T {
return key.compute(emptyList())
@@ -65,4 +60,4 @@ sealed class RenderingContext {
return Impl(parameters)
}
}
}
}

View File

@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.tower.KotlinResolutionStatelessCallbacksImpl
import org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker
import org.jetbrains.kotlin.resolve.lazy.*
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
@@ -63,6 +64,10 @@ fun StorageComponentContainer.configureModule(
private fun StorageComponentContainer.configurePlatformIndependentComponents() {
useImpl<SupertypeLoopCheckerImpl>()
useImpl<KotlinResolutionStatelessCallbacksImpl>()
useImpl<ExperimentalUsageChecker>()
useImpl<ExperimentalUsageChecker.Overrides>()
useImpl<ExperimentalUsageChecker.ClassifierUsage>()
}
fun StorageComponentContainer.configureModule(

View File

@@ -19,14 +19,12 @@ package org.jetbrains.kotlin.psi;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceService;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.idea.KotlinLanguage;
import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt;
public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
public KtElementImpl(@NotNull ASTNode node) {
@@ -96,4 +94,10 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
public KtElement getPsiOrParent() {
return this;
}
@Override
public PsiElement getParent() {
PsiElement substitute = KtPsiUtilKt.getParentSubstitute(this);
return substitute != null ? substitute : super.getParent();
}
}

View File

@@ -26,6 +26,7 @@ import com.intellij.psi.stubs.StubElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.idea.KotlinLanguage;
import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementType;
import java.util.Arrays;
@@ -117,4 +118,10 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
public KtElement getPsiOrParent() {
return this;
}
@Override
public PsiElement getParent() {
PsiElement substitute = KtPsiUtilKt.getParentSubstitute(this);
return substitute != null ? substitute : super.getParent();
}
}

View File

@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.psi;
import com.google.common.collect.ImmutableSet;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.search.LocalSearchScope;
@@ -32,6 +33,9 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt;
import org.jetbrains.kotlin.psi.stubs.KotlinStubWithFqName;
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
import org.jetbrains.kotlin.util.OperatorNameConventions;
import java.util.Set;
import static org.jetbrains.kotlin.psi.KtPsiFactoryKt.KtPsiFactory;
@@ -78,21 +82,32 @@ abstract class KtNamedDeclarationStub<T extends KotlinStubWithFqName<?>> extends
return findChildByType(KtTokens.IDENTIFIER);
}
private static final Set<String> FUNCTIONLIKE_CONVENTIONS = ImmutableSet.of(
OperatorNameConventions.INVOKE.asString(),
OperatorNameConventions.GET.asString()
);
private static boolean shouldDropOperatorKeyword(String oldName, String newName) {
return !OperatorConventions.isConventionName(Name.identifier(newName)) ||
FUNCTIONLIKE_CONVENTIONS.contains(oldName) != FUNCTIONLIKE_CONVENTIONS.contains(newName);
}
@Override
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
PsiElement identifier = getNameIdentifier();
if (identifier == null) return null;
KtModifierList modifierList = getModifierList();
if (modifierList != null &&
modifierList.hasModifier(KtTokens.OPERATOR_KEYWORD) &&
!OperatorConventions.isConventionName(Name.identifier(name))) {
removeModifier(KtTokens.OPERATOR_KEYWORD);
if (modifierList != null && modifierList.hasModifier(KtTokens.OPERATOR_KEYWORD)) {
if (shouldDropOperatorKeyword(getName(), name)) {
removeModifier(KtTokens.OPERATOR_KEYWORD);
}
}
PsiElement newIdentifier = KtPsiFactory(this).createNameIdentifierIfPossible(name);
PsiElement newIdentifier =
KtPsiFactory(this).createNameIdentifierIfPossible(KtPsiUtilKt.quoteIfNeeded(name));
if (newIdentifier != null) {
identifier.replace(newIdentifier);
KtPsiUtilKt.astReplace(identifier, newIdentifier);
}
else {
identifier.delete();
@@ -157,17 +172,4 @@ abstract class KtNamedDeclarationStub<T extends KotlinStubWithFqName<?>> extends
}
return KtNamedDeclarationUtil.getFQName(this);
}
@Override
public void delete() throws IncorrectOperationException {
KtClassOrObject classOrObject = KtPsiUtilKt.getContainingClassOrObject(this);
super.delete();
if (classOrObject instanceof KtObjectDeclaration
&& ((KtObjectDeclaration) classOrObject).isCompanion()
&& classOrObject.getDeclarations().isEmpty()) {
classOrObject.delete();
}
}
}

View File

@@ -179,7 +179,11 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m
}
fun createCompanionObject(): KtObjectDeclaration {
return createClass("class A {\n companion object{\n}\n}").companionObjects.first()
return createCompanionObject("companion object {\n}")
}
fun createCompanionObject(text: String): KtObjectDeclaration {
return createClass("class A {\n $text\n}").companionObjects.first()
}
fun createFileAnnotation(annotationText: String): KtAnnotationEntry {

View File

@@ -920,6 +920,11 @@ public class KtPsiUtil {
return null;
}
public static boolean isLabeledFunctionLiteral(@NotNull KtFunctionLiteral functionLiteral) {
// KtFunctionLiteral -> KtLambdaExpression -> KtLabeledExpression
return functionLiteral.getParent().getParent() instanceof KtLabeledExpression;
}
@Nullable
public static KtExpression getLastElementDeparenthesized(
@Nullable KtExpression expression,

View File

@@ -42,11 +42,11 @@ public class KtVisitor<R, D> extends PsiElementVisitor {
}
public R visitSecondaryConstructor(@NotNull KtSecondaryConstructor constructor, D data) {
return visitDeclaration(constructor, data);
return visitNamedDeclaration(constructor, data);
}
public R visitPrimaryConstructor(@NotNull KtPrimaryConstructor constructor, D data) {
return visitDeclaration(constructor, data);
return visitNamedDeclaration(constructor, data);
}
public R visitNamedFunction(@NotNull KtNamedFunction function, D data) {

View File

@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.psi.psiUtil
import com.intellij.extapi.psi.StubBasedPsiElementBase
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiParameter
@@ -27,6 +28,7 @@ import com.intellij.psi.tree.TokenSet
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.lexer.KotlinLexer
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.Name
@@ -154,6 +156,9 @@ fun KtExpression.getQualifiedExpressionForReceiverOrThis(): KtExpression {
fun KtExpression.isDotReceiver(): Boolean =
(parent as? KtDotQualifiedExpression)?.receiverExpression == this
fun KtExpression.getPossiblyQualifiedCallExpression(): KtCallExpression? =
((this as? KtQualifiedExpression)?.selectorExpression ?: this) as? KtCallExpression
// ---------- Block expression -------------------------------------------------------------------------------------------------------------
fun KtElement.blockExpressionsOrSingle(): Sequence<KtElement> =
@@ -568,4 +573,20 @@ fun KtExpression.getLabeledParent(labelName: String): KtLabeledExpression? {
}
}
return null
}
}
fun PsiElement.astReplace(newElement: PsiElement) = parent.node.replaceChild(node, newElement.node)
var KtElement.parentSubstitute: PsiElement? by UserDataProperty(Key.create<PsiElement>("PARENT_SUBSTITUTE"))
fun String?.isIdentifier(): Boolean {
if (this == null || isEmpty()) return false
val lexer = KotlinLexer()
lexer.start(this, 0, length)
if (lexer.tokenType !== KtTokens.IDENTIFIER) return false
lexer.advance()
return lexer.tokenType == null
}
fun String.quoteIfNeeded(): String = if (this.isIdentifier()) this else "`$this`"

View File

@@ -95,7 +95,7 @@ fun PsiElement.nextLeaf(filter: (PsiElement) -> Boolean): PsiElement? {
}
fun <T : PsiElement> PsiElement.getParentOfTypesAndPredicate(
strict: Boolean = false, vararg parentClasses: Class<T>, predicate: (T) -> Boolean
strict: Boolean = false, vararg parentClasses: Class<out T>, predicate: (T) -> Boolean
): T? {
var element = if (strict) parent else this
while (element != null) {

View File

@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget.*
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getAnnotationEntries
import org.jetbrains.kotlin.resolve.constants.ArrayValue
@@ -193,6 +194,8 @@ class AnnotationChecker(
}
companion object {
private val TARGET_ALLOWED_TARGETS = Name.identifier("allowedTargets")
private fun applicableTargetSet(entry: KtAnnotationEntry, trace: BindingTrace): Set<KotlinTarget> {
val descriptor = trace.get(BindingContext.ANNOTATION, entry) ?: return KotlinTarget.DEFAULT_TARGET_SET
// For descriptor with error type, all targets are considered as possible
@@ -207,10 +210,12 @@ class AnnotationChecker(
}
fun applicableTargetSet(classDescriptor: ClassDescriptor): Set<KotlinTarget>? {
val targetEntryDescriptor = classDescriptor.annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.target)
?: return null
val valueArguments = targetEntryDescriptor.allValueArguments
val valueArgument = valueArguments.entries.firstOrNull()?.value as? ArrayValue ?: return null
val targetEntryDescriptor = classDescriptor.annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.target) ?: return null
return loadAnnotationTargets(targetEntryDescriptor)
}
fun loadAnnotationTargets(targetEntryDescriptor: AnnotationDescriptor): Set<KotlinTarget>? {
val valueArgument = targetEntryDescriptor.allValueArguments[TARGET_ALLOWED_TARGETS] as? ArrayValue ?: return null
return valueArgument.value.filterIsInstance<EnumValue>().mapNotNull {
KotlinTarget.valueOrNull(it.enumEntryName.asString())
}.toSet()

View File

@@ -227,7 +227,7 @@ class LazyTopDownAnalyzer(
checkClassifierUsages(
declarations, classifierUsageCheckers,
ClassifierUsageCheckerContext(trace, languageVersionSettings, deprecationResolver)
ClassifierUsageCheckerContext(trace, languageVersionSettings, deprecationResolver, moduleDescriptor)
)
return c

View File

@@ -278,8 +278,9 @@ public class ModifiersChecker {
public void runDeclarationCheckers(@NotNull KtDeclaration declaration, @NotNull DeclarationDescriptor descriptor) {
DeclarationCheckerContext context =
new DeclarationCheckerContext(trace, languageVersionSettings, deprecationResolver, expectActualTracker);
DeclarationCheckerContext context = new DeclarationCheckerContext(
trace, languageVersionSettings, deprecationResolver, moduleDescriptor, expectActualTracker
);
for (DeclarationChecker checker : declarationCheckers) {
checker.check(declaration, descriptor, context);
}
@@ -301,19 +302,22 @@ public class ModifiersChecker {
private final LanguageVersionSettings languageVersionSettings;
private final ExpectActualTracker expectActualTracker;
private final DeprecationResolver deprecationResolver;
private final ModuleDescriptor moduleDescriptor;
public ModifiersChecker(
@NotNull AnnotationChecker annotationChecker,
@NotNull Iterable<DeclarationChecker> declarationCheckers,
@NotNull LanguageVersionSettings languageVersionSettings,
@NotNull ExpectActualTracker expectActualTracker,
@NotNull DeprecationResolver deprecationResolver
@NotNull DeprecationResolver deprecationResolver,
@NotNull ModuleDescriptor moduleDescriptor
) {
this.annotationChecker = annotationChecker;
this.declarationCheckers = declarationCheckers;
this.languageVersionSettings = languageVersionSettings;
this.expectActualTracker = expectActualTracker;
this.deprecationResolver = deprecationResolver;
this.moduleDescriptor = moduleDescriptor;
}
@NotNull

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.name.ClassId
interface ModuleAnnotationsResolver {
fun getAnnotationsOnContainingModule(descriptor: DeclarationDescriptor): List<ClassId>
companion object {
fun getInstance(project: Project): ModuleAnnotationsResolver =
ServiceManager.getService(project, ModuleAnnotationsResolver::class.java)
}
}

View File

@@ -100,12 +100,16 @@ private val DEFAULT_CALL_CHECKERS = listOf(
ConstructorHeaderCallChecker, ProtectedConstructorCallChecker, ApiVersionCallChecker,
CoroutineSuspendCallChecker, BuilderFunctionsCallChecker, DslScopeViolationCallChecker, MissingDependencyClassChecker,
CallableReferenceCompatibilityChecker(), LateinitIntrinsicApplicabilityChecker,
UnderscoreUsageChecker, AssigningNamedArgumentToVarargChecker()
UnderscoreUsageChecker, AssigningNamedArgumentToVarargChecker(),
LambdaWithSuspendModifierCallChecker
)
private val DEFAULT_TYPE_CHECKERS = emptyList<AdditionalTypeChecker>()
private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf(
DeprecatedClassifierUsageChecker(), ApiVersionClassifierUsageChecker, MissingDependencyClassChecker.ClassifierUsage
)
private val DEFAULT_ANNOTATION_CHECKERS = listOf<AdditionalAnnotationChecker>(
ExperimentalMarkerDeclarationAnnotationChecker
)
abstract class PlatformConfigurator(
@@ -114,7 +118,7 @@ abstract class PlatformConfigurator(
additionalCallCheckers: List<CallChecker>,
additionalTypeCheckers: List<AdditionalTypeChecker>,
additionalClassifierUsageCheckers: List<ClassifierUsageChecker>,
private val additionalAnnotationCheckers: List<AdditionalAnnotationChecker>,
additionalAnnotationCheckers: List<AdditionalAnnotationChecker>,
private val identifierChecker: IdentifierChecker,
private val overloadFilter: OverloadFilter,
private val platformToKotlinClassMap: PlatformToKotlinClassMap,
@@ -127,6 +131,7 @@ abstract class PlatformConfigurator(
private val typeCheckers: List<AdditionalTypeChecker> = DEFAULT_TYPE_CHECKERS + additionalTypeCheckers
private val classifierUsageCheckers: List<ClassifierUsageChecker> =
DEFAULT_CLASSIFIER_USAGE_CHECKERS + additionalClassifierUsageCheckers
private val annotationCheckers: List<AdditionalAnnotationChecker> = DEFAULT_ANNOTATION_CHECKERS + additionalAnnotationCheckers
abstract fun configureModuleComponents(container: StorageComponentContainer)
@@ -136,7 +141,7 @@ abstract class PlatformConfigurator(
callCheckers.forEach { useInstance(it) }
typeCheckers.forEach { useInstance(it) }
classifierUsageCheckers.forEach { useInstance(it) }
additionalAnnotationCheckers.forEach { useInstance(it) }
annotationCheckers.forEach { useInstance(it) }
useInstance(identifierChecker)
useInstance(overloadFilter)
useInstance(platformToKotlinClassMap)

View File

@@ -16,13 +16,12 @@
package org.jetbrains.kotlin.resolve.calls
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
import org.jetbrains.kotlin.builtins.isFunctionType
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.contracts.EffectSystem
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.BindingContext.CONSTRAINT_SYSTEM_COMPLETER
@@ -48,7 +47,6 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsImpl
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
@@ -61,8 +59,7 @@ class CallCompleter(
private val candidateResolver: CandidateResolver,
private val dataFlowAnalyzer: DataFlowAnalyzer,
private val callCheckers: Iterable<CallChecker>,
private val builtIns: KotlinBuiltIns,
private val languageVersionSettings: LanguageVersionSettings,
private val moduleDescriptor: ModuleDescriptor,
private val deprecationResolver: DeprecationResolver,
private val effectSystem: EffectSystem
) {
@@ -90,7 +87,7 @@ class CallCompleter(
if (calleeExpression != null && !calleeExpression.isFakeElement) calleeExpression
else resolvedCall.call.callElement
val callCheckerContext = CallCheckerContext(context, languageVersionSettings, deprecationResolver)
val callCheckerContext = CallCheckerContext(context, deprecationResolver, moduleDescriptor)
for (callChecker in callCheckers) {
callChecker.check(resolvedCall, reportOn, callCheckerContext)
@@ -205,7 +202,7 @@ class CallCompleter(
updateSystemIfNeeded { builder ->
val returnTypeInSystem = builder.typeInSystem(returnType)
if (returnTypeInSystem != null) {
builder.addSubtypeConstraint(returnTypeInSystem, builtIns.unitType, EXPECTED_TYPE_POSITION.position())
builder.addSubtypeConstraint(returnTypeInSystem, moduleDescriptor.builtIns.unitType, EXPECTED_TYPE_POSITION.position())
val system = builder.build()
if (system.status.isSuccessful()) system else null
} else null

View File

@@ -185,11 +185,11 @@ class CallExpressionResolver(
}
fun getCallExpressionTypeInfo(
callExpression: KtCallExpression, receiver: ReceiverValue?,
callOperationNode: ASTNode?, context: ExpressionTypingContext
callExpression: KtCallExpression,
context: ExpressionTypingContext
): KotlinTypeInfo {
val typeInfo = getCallExpressionTypeInfoWithoutFinalTypeCheck(
callExpression, receiver, callOperationNode, context, context.dataFlowInfo
callExpression, null, null, context, context.dataFlowInfo
)
if (context.contextDependency == INDEPENDENT) {
dataFlowAnalyzer.checkType(typeInfo.type, callExpression, context)

View File

@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.DeprecationResolver
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
@@ -36,11 +37,11 @@ interface CallChecker {
fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext)
}
class CallCheckerContext(
class CallCheckerContext @JvmOverloads constructor(
val resolutionContext: ResolutionContext<*>,
override val trace: BindingTrace,
override val languageVersionSettings: LanguageVersionSettings,
override val deprecationResolver: DeprecationResolver
override val deprecationResolver: DeprecationResolver,
override val moduleDescriptor: ModuleDescriptor,
override val trace: BindingTrace = resolutionContext.trace
) : CheckerContext {
val scope: LexicalScope
get() = resolutionContext.scope
@@ -51,11 +52,8 @@ class CallCheckerContext(
val isAnnotationContext: Boolean
get() = resolutionContext.isAnnotationContext
constructor(
c: ResolutionContext<*>,
languageVersionSettings: LanguageVersionSettings,
deprecationResolver: DeprecationResolver
) : this(c, c.trace, languageVersionSettings, deprecationResolver)
override val languageVersionSettings: LanguageVersionSettings
get() = resolutionContext.languageVersionSettings
}
// Use this utility to avoid premature computation of deferred return type of a resolved callable descriptor.

View File

@@ -0,0 +1,61 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.calls.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.Call
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtLambdaExpression
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInfixCall
import org.jetbrains.kotlin.resolve.calls.callUtil.isCallableReference
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
object LambdaWithSuspendModifierCallChecker : CallChecker {
@JvmField
val KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME = FqName("kotlin.suspend")
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
val descriptor = resolvedCall.candidateDescriptor
val call = resolvedCall.call
val callName = call.referencedName()
if (callName != "suspend" && descriptor.name.asString() != "suspend") return
when (descriptor.fqNameOrNull()) {
KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME -> {
if (!call.hasFormOfSuspendModifierForLambda() || call.explicitReceiver != null) {
context.trace.report(Errors.NON_MODIFIER_FORM_FOR_BUILT_IN_SUSPEND.on(reportOn))
}
}
else -> {
if (call.hasFormOfSuspendModifierForLambda()) {
context.trace.report(Errors.MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND.on(reportOn))
}
}
}
}
private fun Call.hasFormOfSuspendModifierForLambda() =
referencedName() == "suspend"
&& !isCallableReference()
&& typeArguments.isEmpty()
&& (hasNoArgumentListButDanglingLambdas() || isInfixWithRightLambda())
private fun Call.referencedName() =
calleeExpression?.safeAs<KtSimpleNameExpression>()?.getReferencedName()
private fun Call.hasNoArgumentListButDanglingLambdas() =
valueArgumentList?.leftParenthesis == null && functionLiteralArguments.isNotEmpty()
private fun Call.isInfixWithRightLambda() =
isInfixCall(this)
&& callElement.safeAs<KtBinaryExpression>()?.right is KtLambdaExpression
}

View File

@@ -23,12 +23,15 @@ import org.jetbrains.kotlin.coroutines.hasSuspendFunctionType
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtThisExpression
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.hasRestrictsSuspensionAnnotation
@@ -43,15 +46,28 @@ import org.jetbrains.kotlin.types.typeUtil.supertypes
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
val COROUTINE_CONTEXT_1_2_20_FQ_NAME = DescriptorUtils.COROUTINES_INTRINSICS_PACKAGE_FQ_NAME.child(Name.identifier("coroutineContext"))
val COROUTINE_CONTEXT_FQ_NAME = DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("coroutineContext"))
fun FqName.isBuiltInCorouineContext() =
this == COROUTINE_CONTEXT_1_2_20_FQ_NAME || this == COROUTINE_CONTEXT_FQ_NAME
fun FunctionDescriptor.isBuiltInCoroutineContext() =
(this as? PropertyGetterDescriptor)?.correspondingProperty?.fqNameSafe?.isBuiltInCorouineContext() == true
fun PropertyDescriptor.isBuiltInCoroutineContext() = this.fqNameSafe.isBuiltInCorouineContext()
object CoroutineSuspendCallChecker : CallChecker {
private val ALLOWED_SCOPE_KINDS = setOf(LexicalScopeKind.FUNCTION_INNER_SCOPE, LexicalScopeKind.FUNCTION_HEADER_FOR_DESTRUCTURING)
private val COROUTINE_CONTEXT_FQ_NAME = FqName("kotlin.coroutines.experimental.intrinsics.coroutineContext")
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
val descriptor = resolvedCall.candidateDescriptor
when (descriptor) {
is FunctionDescriptor -> if (!descriptor.isSuspend) return
is PropertyDescriptor -> if (descriptor.fqNameSafe != COROUTINE_CONTEXT_FQ_NAME) return
is PropertyDescriptor -> when (descriptor.fqNameSafe) {
COROUTINE_CONTEXT_1_2_20_FQ_NAME, COROUTINE_CONTEXT_FQ_NAME -> {}
else -> return
}
else -> return
}

View File

@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.contracts.EffectSystem
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
@@ -59,10 +57,8 @@ import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.util.*
class KotlinToResolvedCallTransformer(
private val callCheckers: Iterable<CallChecker>,
private val languageFeatureSettings: LanguageVersionSettings,
private val dataFlowAnalyzer: DataFlowAnalyzer,
private val argumentTypeResolver: ArgumentTypeResolver,
private val constantExpressionEvaluator: ConstantExpressionEvaluator,
@@ -70,9 +66,8 @@ class KotlinToResolvedCallTransformer(
private val expressionTypingServices: ExpressionTypingServices,
private val doubleColonExpressionResolver: DoubleColonExpressionResolver,
private val additionalDiagnosticReporter: AdditionalDiagnosticReporter,
private val effectSystem: EffectSystem
private val moduleDescriptor: ModuleDescriptor
) {
companion object {
private val REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC
get() = false
@@ -103,9 +98,8 @@ class KotlinToResolvedCallTransformer(
CallResolutionResult.Type.ERROR, CallResolutionResult.Type.COMPLETED -> {
val resultSubstitutor = baseResolvedCall.constraintSystem.buildResultingSubstitutor()
val ktPrimitiveCompleter = ResolvedAtomCompleter(
resultSubstitutor, context.trace, context, this,
expressionTypingServices, argumentTypeResolver, doubleColonExpressionResolver,
languageFeatureSettings, deprecationResolver
resultSubstitutor, context.trace, context, this, expressionTypingServices, argumentTypeResolver,
doubleColonExpressionResolver, deprecationResolver, moduleDescriptor
)
for (subKtPrimitive in candidate.subResolvedAtoms) {

View File

@@ -17,9 +17,9 @@
package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.builtins.replaceReturnType
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl
import org.jetbrains.kotlin.psi.KtElement
@@ -50,15 +50,14 @@ class ResolvedAtomCompleter(
private val resultSubstitutor: NewTypeSubstitutor,
private val trace: BindingTrace,
private val topLevelCallContext: BasicCallResolutionContext,
private val kotlinToResolvedCallTransformer: KotlinToResolvedCallTransformer,
private val expressionTypingServices: ExpressionTypingServices,
private val argumentTypeResolver: ArgumentTypeResolver,
private val doubleColonExpressionResolver: DoubleColonExpressionResolver,
languageVersionSettings: LanguageVersionSettings,
deprecationResolver: DeprecationResolver
deprecationResolver: DeprecationResolver,
moduleDescriptor: ModuleDescriptor
) {
private val callCheckerContext = CallCheckerContext(topLevelCallContext, languageVersionSettings, deprecationResolver)
private val callCheckerContext = CallCheckerContext(topLevelCallContext, deprecationResolver, moduleDescriptor)
private fun complete(resolvedAtom: ResolvedAtom) {
when (resolvedAtom) {

View File

@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve.checkers
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.DeprecationResolver
@@ -26,4 +27,6 @@ interface CheckerContext {
val languageVersionSettings: LanguageVersionSettings
val deprecationResolver: DeprecationResolver
val moduleDescriptor: ModuleDescriptor
}

View File

@@ -35,7 +35,8 @@ interface ClassifierUsageChecker {
class ClassifierUsageCheckerContext(
override val trace: BindingTrace,
override val languageVersionSettings: LanguageVersionSettings,
override val deprecationResolver: DeprecationResolver
override val deprecationResolver: DeprecationResolver,
override val moduleDescriptor: ModuleDescriptor
) : CheckerContext

View File

@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.checkers
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.resolve.BindingTrace
@@ -31,5 +32,6 @@ class DeclarationCheckerContext(
override val trace: BindingTrace,
override val languageVersionSettings: LanguageVersionSettings,
override val deprecationResolver: DeprecationResolver,
override val moduleDescriptor: ModuleDescriptor,
val expectActualTracker: ExpectActualTracker
) : CheckerContext

View File

@@ -222,7 +222,7 @@ object ExpectedActualDeclarationChecker : DeclarationChecker {
else -> true
}
private fun findExpectedForActual(
fun findExpectedForActual(
actual: MemberDescriptor,
commonModule: ModuleDescriptor
): Map<Compatibility, List<MemberDescriptor>>? {

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.checkers
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.resolve.AdditionalAnnotationChecker
import org.jetbrains.kotlin.resolve.AnnotationChecker
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.constants.ArrayValue
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.constants.KClassValue
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
object ExperimentalMarkerDeclarationAnnotationChecker : AdditionalAnnotationChecker {
private val WRONG_TARGETS_FOR_MARKER = setOf(KotlinTarget.EXPRESSION, KotlinTarget.FILE)
override fun checkEntries(entries: List<KtAnnotationEntry>, actualTargets: List<KotlinTarget>, trace: BindingTrace) {
var isAnnotatedWithExperimental = false
for (entry in entries) {
val annotation = trace.bindingContext.get(BindingContext.ANNOTATION, entry)
when (annotation?.fqName) {
ExperimentalUsageChecker.USE_EXPERIMENTAL_FQ_NAME -> {
val annotationClasses =
(annotation.allValueArguments[ExperimentalUsageChecker.USE_EXPERIMENTAL_ANNOTATION_CLASS] as? ArrayValue)?.value.orEmpty()
checkUseExperimentalUsage(annotationClasses, trace, entry)
}
ExperimentalUsageChecker.EXPERIMENTAL_FQ_NAME -> {
val impact = (annotation.allValueArguments[ExperimentalUsageChecker.IMPACT] as? ArrayValue)?.value
checkExperimentalUsage(impact, trace, entry)
isAnnotatedWithExperimental = true
}
}
}
if (isAnnotatedWithExperimental) {
checkMarkerTargets(entries, trace)
}
}
private fun checkUseExperimentalUsage(annotationClasses: List<ConstantValue<*>>, trace: BindingTrace, entry: KtAnnotationEntry) {
if (annotationClasses.isEmpty()) {
trace.report(Errors.USE_EXPERIMENTAL_WITHOUT_ARGUMENTS.on(entry))
return
}
for (annotationClass in annotationClasses) {
val classDescriptor =
(annotationClass as? KClassValue)?.value?.constructor?.declarationDescriptor as? ClassDescriptor
?: continue
val experimentality = with(ExperimentalUsageChecker) {
classDescriptor.loadExperimentalityForMarkerAnnotation()
}
if (experimentality == null) {
trace.report(Errors.USE_EXPERIMENTAL_ARGUMENT_IS_NOT_MARKER.on(entry, classDescriptor.fqNameSafe))
} else if (!experimentality.isCompilationOnly) {
trace.report(Errors.USE_EXPERIMENTAL_ARGUMENT_HAS_NON_COMPILATION_IMPACT.on(entry, experimentality.annotationFqName))
}
}
}
private fun checkExperimentalUsage(impact: List<ConstantValue<*>>?, trace: BindingTrace, entry: KtAnnotationEntry) {
if (impact != null && impact.isEmpty()) {
trace.report(Errors.EXPERIMENTAL_ANNOTATION_WITH_NO_IMPACT.on(entry))
}
}
private fun checkMarkerTargets(entries: List<KtAnnotationEntry>, trace: BindingTrace) {
val targetEntry =
entries.associate { entry -> entry to trace.bindingContext.get(BindingContext.ANNOTATION, entry) }
.entries
.firstOrNull { (_, descriptor) -> descriptor != null && descriptor.fqName == KotlinBuiltIns.FQ_NAMES.target }
?: return
val (entry, descriptor) = targetEntry
val allowedTargets = AnnotationChecker.loadAnnotationTargets(descriptor!!) ?: return
val wrongTargets = allowedTargets.intersect(WRONG_TARGETS_FOR_MARKER)
if (wrongTargets.isNotEmpty()) {
trace.report(
Errors.EXPERIMENTAL_ANNOTATION_WITH_WRONG_TARGET.on(entry, wrongTargets.joinToString(transform = KotlinTarget::description))
)
}
}
}

View File

@@ -0,0 +1,343 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.checkers
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.AnalysisFlag
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.constants.ArrayValue
import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.resolve.constants.KClassValue
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.utils.SmartSet
import org.jetbrains.kotlin.utils.addIfNotNull
class ExperimentalUsageChecker(project: Project) : CallChecker {
private val moduleAnnotationsResolver = ModuleAnnotationsResolver.getInstance(project)
internal data class Experimentality(
val markerDescriptor: ClassDescriptor,
val annotationFqName: FqName,
val severity: Severity,
val impact: List<Impact>
) {
val isCompilationOnly: Boolean get() = impact.all(Impact.COMPILATION::equals)
enum class Severity { WARNING, ERROR }
enum class Impact { COMPILATION, LINKAGE_OR_RUNTIME }
companion object {
val DEFAULT_SEVERITY = Severity.ERROR
val DEFAULT_IMPACT = listOf(Impact.COMPILATION, Impact.LINKAGE_OR_RUNTIME)
}
}
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
checkExperimental(resolvedCall.resultingDescriptor, reportOn, context, moduleAnnotationsResolver)
}
companion object {
internal val EXPERIMENTAL_FQ_NAME = FqName("kotlin.Experimental")
internal val USE_EXPERIMENTAL_FQ_NAME = FqName("kotlin.UseExperimental")
internal val USE_EXPERIMENTAL_ANNOTATION_CLASS = Name.identifier("markerClass")
private val LEVEL = Name.identifier("level")
private val WARNING_LEVEL = Name.identifier("WARNING")
private val ERROR_LEVEL = Name.identifier("ERROR")
internal val IMPACT = Name.identifier("changesMayBreak")
private val COMPILATION_IMPACT = Name.identifier("COMPILATION")
private val LINKAGE_IMPACT = Name.identifier("LINKAGE")
private val RUNTIME_IMPACT = Name.identifier("RUNTIME")
private fun checkExperimental(
descriptor: DeclarationDescriptor,
element: PsiElement,
context: CheckerContext,
moduleAnnotationsResolver: ModuleAnnotationsResolver
) {
val experimentalities = descriptor.loadExperimentalities(moduleAnnotationsResolver)
if (experimentalities.isNotEmpty()) {
checkExperimental(
experimentalities, element, context.trace.bindingContext, context.languageVersionSettings,
context.moduleDescriptor
) { experimentality, isBodyUsageOfSourceOnlyExperimentality ->
val diagnostic = when (experimentality.severity) {
Experimentality.Severity.WARNING -> Errors.EXPERIMENTAL_API_USAGE
Experimentality.Severity.ERROR -> Errors.EXPERIMENTAL_API_USAGE_ERROR
}
context.trace.report(diagnostic.on(element, experimentality.annotationFqName, isBodyUsageOfSourceOnlyExperimentality))
}
}
}
private fun checkExperimental(
experimentalities: Collection<Experimentality>,
element: PsiElement,
bindingContext: BindingContext,
languageVersionSettings: LanguageVersionSettings,
module: ModuleDescriptor,
report: (experimentality: Experimentality, isBodyUsageOfCompilationExperimentality: Boolean) -> Unit
) {
val isBodyUsageExceptPublicInline = element.isBodyUsage(bindingContext, allowPublicInline = false)
val isBodyUsage = isBodyUsageExceptPublicInline || element.isBodyUsage(bindingContext, allowPublicInline = true)
for (experimentality in experimentalities) {
val isBodyUsageOfCompilationExperimentality =
experimentality.isCompilationOnly && isBodyUsage
val isBodyUsageInSameModule =
experimentality.markerDescriptor.module == module && isBodyUsageExceptPublicInline
val annotationFqName = experimentality.annotationFqName
val isExperimentalityAccepted =
isBodyUsageInSameModule ||
(isBodyUsageOfCompilationExperimentality &&
element.hasContainerAnnotatedWithUseExperimental(annotationFqName, bindingContext, languageVersionSettings)) ||
element.propagates(annotationFqName, bindingContext, languageVersionSettings)
if (!isExperimentalityAccepted) {
report(experimentality, isBodyUsageOfCompilationExperimentality)
}
}
}
private fun DeclarationDescriptor.loadExperimentalities(
moduleAnnotationsResolver: ModuleAnnotationsResolver
): Set<Experimentality> {
val result = SmartSet.create<Experimentality>()
for (annotation in annotations) {
result.addIfNotNull(annotation.annotationClass?.loadExperimentalityForMarkerAnnotation())
}
val container = containingDeclaration
if (container is ClassDescriptor && this !is ConstructorDescriptor) {
result.addAll(container.loadExperimentalities(moduleAnnotationsResolver))
}
for (moduleAnnotationClassId in moduleAnnotationsResolver.getAnnotationsOnContainingModule(this)) {
val annotationClass = module.findClassAcrossModuleDependencies(moduleAnnotationClassId)
result.addIfNotNull(annotationClass?.loadExperimentalityForMarkerAnnotation())
}
return result
}
internal fun ClassDescriptor.loadExperimentalityForMarkerAnnotation(): Experimentality? {
val experimental = annotations.findAnnotation(EXPERIMENTAL_FQ_NAME) ?: return null
val severity = when ((experimental.allValueArguments[LEVEL] as? EnumValue)?.enumEntryName) {
WARNING_LEVEL -> Experimentality.Severity.WARNING
ERROR_LEVEL -> Experimentality.Severity.ERROR
else -> Experimentality.DEFAULT_SEVERITY
}
val impact = (experimental.allValueArguments[IMPACT] as? ArrayValue)?.value?.mapNotNull { impact ->
when ((impact as? EnumValue)?.enumEntryName) {
COMPILATION_IMPACT -> Experimentality.Impact.COMPILATION
LINKAGE_IMPACT, RUNTIME_IMPACT -> Experimentality.Impact.LINKAGE_OR_RUNTIME
else -> null
}
} ?: Experimentality.DEFAULT_IMPACT
return Experimentality(this, fqNameSafe, severity, impact)
}
// Returns true if this element appears in the body of some function and is not visible in any non-local declaration signature.
// If that's the case, one can opt-in to using the corresponding experimental API by annotating this element (or any of its
// enclosing declarations) with @UseExperimental(X::class), not requiring propagation of the experimental annotation to the call sites.
// (Note that this is allowed only if X's impact is [COMPILATION].)
private fun PsiElement.isBodyUsage(bindingContext: BindingContext, allowPublicInline: Boolean): Boolean {
return anyParentMatches { element, parent ->
element == (parent as? KtDeclarationWithBody)?.bodyExpression?.takeIf {
allowPublicInline || !parent.isPublicInline(bindingContext)
} ||
element == (parent as? KtDeclarationWithInitializer)?.initializer ||
element == (parent as? KtClassInitializer)?.body ||
element == (parent as? KtParameter)?.defaultValue ||
element == (parent as? KtSuperTypeCallEntry)?.valueArgumentList ||
element == (parent as? KtDelegatedSuperTypeEntry)?.delegateExpression ||
element == (parent as? KtPropertyDelegate)?.expression
}
}
private fun PsiElement.isPublicInline(bindingContext: BindingContext): Boolean {
val descriptor = when (this) {
is KtFunction -> bindingContext.get(BindingContext.FUNCTION, this)
is KtPropertyAccessor -> bindingContext.get(BindingContext.PROPERTY_ACCESSOR, this)
else -> null
}
return descriptor != null && descriptor.isInline && descriptor.effectiveVisibility().let {
it == EffectiveVisibility.Public ||
it == EffectiveVisibility.ProtectedBound ||
it is EffectiveVisibility.Protected
}
}
// Checks whether any of the non-local enclosing declarations is annotated with annotationFqName, effectively requiring
// propagation for the experimental annotation to the call sites
private fun PsiElement.propagates(
annotationFqName: FqName,
bindingContext: BindingContext,
languageVersionSettings: LanguageVersionSettings
): Boolean =
annotationFqName.asString() in languageVersionSettings.getFlag(AnalysisFlag.experimental) ||
anyParentMatches { element, _ ->
if (element is KtDeclaration) {
val descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
descriptor != null && !DescriptorUtils.isLocal(descriptor) &&
descriptor.annotations.hasAnnotation(annotationFqName)
} else false
}
// Checks whether there's an element lexically above the tree, that is annotated with `@UseExperimental(X::class)`
// where annotationFqName is the FQ name of X
private fun PsiElement.hasContainerAnnotatedWithUseExperimental(
annotationFqName: FqName,
bindingContext: BindingContext,
languageVersionSettings: LanguageVersionSettings
): Boolean =
annotationFqName.asString() in languageVersionSettings.getFlag(AnalysisFlag.useExperimental) ||
anyParentMatches { element, _ ->
element is KtAnnotated && element.annotationEntries.any { entry ->
bindingContext.get(BindingContext.ANNOTATION, entry)?.isUseExperimental(annotationFqName) == true
}
}
private inline fun PsiElement.anyParentMatches(predicate: (element: PsiElement, parent: PsiElement?) -> Boolean): Boolean {
var element = this
while (true) {
val parent = element.parent
if (predicate(element, parent)) return true
element = parent ?: return false
}
}
private fun AnnotationDescriptor.isUseExperimental(annotationFqName: FqName): Boolean {
if (fqName != USE_EXPERIMENTAL_FQ_NAME) return false
val annotationClasses = allValueArguments[USE_EXPERIMENTAL_ANNOTATION_CLASS]
return annotationClasses is ArrayValue && annotationClasses.value.any { annotationClass ->
(annotationClass as? KClassValue)?.value?.constructor?.declarationDescriptor?.fqNameSafe == annotationFqName
}
}
fun checkCompilerArguments(
module: ModuleDescriptor,
languageVersionSettings: LanguageVersionSettings,
reportError: (String) -> Unit,
reportWarning: (String) -> Unit
) {
// Ideally, we should run full resolution (with all classifier usage checkers) on classifiers used in "-Xexperimental" and
// "-Xuse-experimental" arguments. However, it's not easy to do this. This should be solved in the future with the support of
// module annotations. For now, we only check deprecations because this is needed to correctly retire unneeded compiler arguments.
val deprecationResolver = DeprecationResolver(LockBasedStorageManager(), languageVersionSettings)
fun checkAnnotation(fqName: String, allowNonCompilationImpact: Boolean): Boolean {
val descriptor = module.resolveClassByFqName(FqName(fqName), NoLookupLocation.FOR_NON_TRACKED_SCOPE)
val experimentality = descriptor?.loadExperimentalityForMarkerAnnotation()
val message = when {
descriptor == null ->
"Experimental API marker $fqName is unresolved. " +
"Please make sure it's present in the module dependencies"
experimentality == null ->
"Class $fqName is not an experimental API marker annotation"
!allowNonCompilationImpact && !experimentality.impact.all(Experimentality.Impact.COMPILATION::equals) ->
"Experimental API marker $fqName has impact other than COMPILATION, " +
"therefore it can't be used with -Xuse-experimental"
else -> {
for (deprecation in deprecationResolver.getDeprecations(descriptor)) {
val report = when (deprecation.deprecationLevel) {
DeprecationLevelValue.WARNING -> reportWarning
DeprecationLevelValue.ERROR, DeprecationLevelValue.HIDDEN -> reportError
}
report("Experimental API marker $fqName is deprecated" + deprecation.message?.let { ". $it" }.orEmpty())
}
return true
}
}
reportError(message)
return false
}
val validExperimental =
languageVersionSettings.getFlag(AnalysisFlag.experimental)
.filter { checkAnnotation(it, allowNonCompilationImpact = true) }
val validUseExperimental =
languageVersionSettings.getFlag(AnalysisFlag.useExperimental)
.filter { checkAnnotation(it, allowNonCompilationImpact = false) }
for (fqName in validExperimental.intersect(validUseExperimental)) {
reportError("'-Xuse-experimental=$fqName' has no effect because '-Xexperimental=$fqName' is used")
}
}
}
class ClassifierUsage(project: Project) : ClassifierUsageChecker {
private val moduleAnnotationsResolver = ModuleAnnotationsResolver.getInstance(project)
override fun check(targetDescriptor: ClassifierDescriptor, element: PsiElement, context: ClassifierUsageCheckerContext) {
checkExperimental(targetDescriptor, element, context, moduleAnnotationsResolver)
}
}
class Overrides(project: Project) : DeclarationChecker {
private val moduleAnnotationsResolver = ModuleAnnotationsResolver.getInstance(project)
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
if (descriptor !is CallableMemberDescriptor) return
val experimentalOverridden = descriptor.overriddenDescriptors.flatMap { member ->
member.loadExperimentalities(moduleAnnotationsResolver).map { experimentality -> experimentality to member }
}.toMap()
val module = descriptor.module
for ((experimentality, member) in experimentalOverridden) {
checkExperimental(
listOf(experimentality), declaration, context.trace.bindingContext, context.languageVersionSettings, module
) { _, _ ->
val diagnostic = when (experimentality.severity) {
Experimentality.Severity.WARNING -> Errors.EXPERIMENTAL_OVERRIDE
Experimentality.Severity.ERROR -> Errors.EXPERIMENTAL_OVERRIDE_ERROR
}
val reportOn = (declaration as? KtNamedDeclaration)?.nameIdentifier ?: declaration
context.trace.report(diagnostic.on(reportOn, experimentality.annotationFqName, member.containingDeclaration))
}
}
}
}
}

View File

@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
@@ -200,10 +201,8 @@ class DeprecationResolver(
descriptor.checkSinceKotlinVersionAccessibility(languageVersionSettings)
}
fun getDeprecations(
descriptor: DeclarationDescriptor
) = deprecations(descriptor.original)
fun getDeprecations(descriptor: DeclarationDescriptor): List<Deprecation> =
deprecations(descriptor.original)
fun isDeprecatedHidden(descriptor: DeclarationDescriptor): Boolean =
getDeprecations(descriptor).any { it.deprecationLevel == HIDDEN }
@@ -301,7 +300,7 @@ class DeprecationResolver(
ProtoBuf.VersionRequirement.VersionKind.API_VERSION ->
languageVersionSettings.apiVersion
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION ->
ApiVersion.LATEST_STABLE
KotlinCompilerVersion.getVersion()?.let((ApiVersion)::parse)
else -> null
}
if (currentVersion != null && currentVersion < requiredVersion) {

View File

@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.types;
@@ -24,11 +13,13 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
import org.jetbrains.kotlin.utils.DFS;
import java.util.*;
import java.util.stream.Collectors;
import static org.jetbrains.kotlin.types.Variance.IN_VARIANCE;
import static org.jetbrains.kotlin.types.Variance.OUT_VARIANCE;
@@ -147,7 +138,23 @@ public class CommonSupertypes {
}
commonSupertypes = computeCommonRawSupertypes(merge);
}
assert !commonSupertypes.isEmpty() : commonSupertypes + " <- " + types;
if (commonSupertypes.isEmpty()) {
StringBuilder info = new StringBuilder();
for (SimpleType type : types) {
String superTypes = type.getConstructor().getSupertypes().stream()
.map(CommonSupertypes::renderTypeFully)
.collect(Collectors.joining(", "));
info
.append("Info about ").append(renderTypeFully(type)).append(": ").append('\n')
.append("- Supertypes: ").append(superTypes).append('\n')
.append("- DeclarationDescriptor class: ").append(classOfDeclarationDescriptor(type)).append('\n')
.append("- TypeConstructor class: ").append(type.getConstructor().getClass()).append('\n')
.append('\n');
}
throw new IllegalStateException("There is no common supertype for: " + types + " \n" + info.toString());
}
// constructor of the supertype -> all of its instantiations occurring as supertypes
Map.Entry<TypeConstructor, Set<SimpleType>> entry = commonSupertypes.entrySet().iterator().next();
@@ -157,6 +164,21 @@ public class CommonSupertypes {
return TypeUtils.makeNullableIfNeeded(result, nullable);
}
@NotNull
private static String renderTypeFully(@NotNull KotlinType type) {
return DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(type);
}
@Nullable
private static Class<?> classOfDeclarationDescriptor(@NotNull KotlinType type) {
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
if (descriptor != null) {
return descriptor.getClass();
}
return null;
}
// Raw supertypes are superclasses w/o type arguments
// @return TypeConstructor -> all instantiations of this constructor occurring as supertypes
@NotNull

View File

@@ -713,7 +713,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
@Override
public KotlinTypeInfo visitCallExpression(@NotNull KtCallExpression expression, ExpressionTypingContext context) {
CallExpressionResolver callExpressionResolver = components.callExpressionResolver;
return callExpressionResolver.getCallExpressionTypeInfo(expression, null, null, context);
return callExpressionResolver.getCallExpressionTypeInfo(expression, context);
}
@Override
@@ -939,7 +939,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
// Call must be validated with the actual, not temporary trace in order to report operator diagnostic
// Only unary assignment expressions (++, --) and +=/... must be checked, normal assignments have the proper trace
CallCheckerContext callCheckerContext =
new CallCheckerContext(context, trace, components.languageVersionSettings, components.deprecationResolver);
new CallCheckerContext(context, components.deprecationResolver, components.moduleDescriptor, trace);
for (CallChecker checker : components.callCheckers) {
checker.check(resolvedCall, expression, callCheckerContext);
}
@@ -1016,7 +1016,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
@NotNull
private CallCheckerContext createCallCheckerContext(@NotNull ExpressionTypingContext context) {
return new CallCheckerContext(context, components.languageVersionSettings, components.deprecationResolver);
return new CallCheckerContext(context, components.deprecationResolver, components.moduleDescriptor);
}
@Override

View File

@@ -31,6 +31,8 @@ import org.jetbrains.kotlin.resolve.BindingContextUtils;
import org.jetbrains.kotlin.resolve.ModifierCheckerCore;
import org.jetbrains.kotlin.resolve.ModifiersChecker;
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
import org.jetbrains.kotlin.resolve.calls.checkers.LambdaWithSuspendModifierCallChecker;
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
@@ -55,6 +57,7 @@ import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import static org.jetbrains.kotlin.diagnostics.Errors.*;
import static org.jetbrains.kotlin.resolve.BindingContext.*;
@@ -663,6 +666,22 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
context.trace.report(RETURN_NOT_ALLOWED.on(expression));
resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE);
}
else if (labelTargetElement instanceof KtFunctionLiteral
&& Objects.equals(expression.getLabelName(), "suspend")) {
KtExpression callExpression = KtPsiUtil.getParentCallIfPresent((KtFunction) labelTargetElement);
ResolvedCall<? extends CallableDescriptor> resolvedCall =
CallUtilKt.getResolvedCall(callExpression, context.trace.getBindingContext());
if (resolvedCall != null &&
!KtPsiUtil.isLabeledFunctionLiteral((KtFunctionLiteral) labelTargetElement) &&
Objects.equals(
DescriptorUtilsKt.fqNameOrNull(resolvedCall.getResultingDescriptor()),
LambdaWithSuspendModifierCallChecker.KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME
)
) {
context.trace.report(RETURN_FOR_BUILT_IN_SUSPEND.on(expression));
}
}
}
}

View File

@@ -113,7 +113,7 @@ sealed class KtLightFieldImpl<D : PsiField>(
fun lazy(
dummyDelegate: PsiField,
origin: LightMemberOriginForDeclaration,
origin: LightMemberOriginForDeclaration?,
containingClass: KtLightClass,
computeRealDelegate: () -> PsiField
): KtLightField {

View File

@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
import org.jetbrains.kotlin.asJava.classes.cannotModify
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
@@ -36,6 +37,7 @@ import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument
import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.TypeUtils
@@ -174,7 +176,7 @@ class KtLightAnnotationForSourceEntry(
override fun getType(): PsiType? = delegate.type
}
inner class LightStringLiteral(
inner class LightPsiLiteral(
delegate: PsiLiteralExpression,
parent: PsiElement,
valueOrigin: AnnotationValueOrigin
@@ -201,6 +203,9 @@ class KtLightAnnotationForSourceEntry(
wrapAnnotationValue(memberValue, this, {
originalExpression.let { ktOrigin ->
when {
ktOrigin is KtCallExpression
&& memberValue is PsiAnnotation
&& isAnnotationConstructorCall(ktOrigin, memberValue) -> ktOrigin
ktOrigin is KtValueArgumentList -> ktOrigin.arguments.getOrNull(i)?.getArgumentExpression()
ktOrigin is KtCallElement -> ktOrigin.valueArguments.getOrNull(i)?.getArgumentExpression()
ktOrigin is KtCollectionLiteralExpression -> ktOrigin.getInnerExpressions().getOrNull(i)
@@ -225,7 +230,7 @@ class KtLightAnnotationForSourceEntry(
private fun wrapAnnotationValue(value: PsiAnnotationMemberValue, parent: PsiElement, ktOrigin: AnnotationValueOrigin): PsiAnnotationMemberValue =
when {
value is PsiLiteralExpression && value.value is String -> LightStringLiteral(value, parent, ktOrigin)
value is PsiLiteralExpression -> LightPsiLiteral(value, parent, ktOrigin)
value is PsiClassObjectAccessExpression -> LightClassLiteral(value, parent, ktOrigin)
value is PsiExpression -> LightExpressionValue(value, parent, ktOrigin)
value is PsiArrayInitializerMemberValue -> LightArrayInitializerValue(value, parent, ktOrigin)
@@ -256,6 +261,25 @@ class KtLightAnnotationForSourceEntry(
override fun findDeclaredAttributeValue(name: String?) = clsDelegate.findDeclaredAttributeValue(name)?.let { wrapAnnotationValue(it) }
override fun getParameterList(): PsiAnnotationParameterList = KtLightAnnotationParameterList(super.getParameterList())
inner class KtLightAnnotationParameterList(private val list: PsiAnnotationParameterList) : KtLightElementBase(this),
PsiAnnotationParameterList {
override val kotlinOrigin get() = null
override fun getAttributes(): Array<PsiNameValuePair> = list.attributes.map { KtLightPsiNameValuePair(it) }.toTypedArray()
inner class KtLightPsiNameValuePair(private val psiNameValuePair: PsiNameValuePair) : KtLightElementBase(this),
PsiNameValuePair {
override fun setValue(newValue: PsiAnnotationMemberValue): PsiAnnotationMemberValue = psiNameValuePair.setValue(newValue)
override fun getNameIdentifier(): PsiIdentifier? = psiNameValuePair.nameIdentifier
override fun getLiteralValue(): String? = (value as? PsiLiteralValue)?.value?.toString()
override val kotlinOrigin: KtElement? = null
override fun getValue(): PsiAnnotationMemberValue? = psiNameValuePair.value?.let { wrapAnnotationValue(it) }
}
}
override fun delete() = kotlinOrigin.delete()
override fun toString() = "@$qualifiedName"
@@ -338,6 +362,9 @@ private fun KtElement.getResolvedCall(): ResolvedCall<out CallableDescriptor>? {
return this.getResolvedCall(context)
}
private fun isAnnotationConstructorCall(callExpression: KtCallExpression, psiAnnotation: PsiAnnotation) =
(callExpression.getResolvedCall()?.resultingDescriptor as? ClassConstructorDescriptor)?.constructedClass?.fqNameUnsafe?.toString() == psiAnnotation.qualifiedName
private fun PsiElement.asKtCall(): KtCallElement? = (this as? KtElement)?.getResolvedCall()?.call?.callElement as? KtCallElement
private fun psiReport(psiElement: PsiElement?): String {

View File

@@ -164,15 +164,31 @@ private val DEFAULT_IMPLS_CLASS_NAME = Name.identifier(JvmAbi.DEFAULT_IMPLS_CLAS
fun FqName.defaultImplsChild() = child(DEFAULT_IMPLS_CLASS_NAME)
@Suppress("unused")
fun KtAnnotationEntry.toLightAnnotation(): PsiAnnotation? {
fun KtElement.toLightAnnotation(): PsiAnnotation? {
val ktDeclaration = getStrictParentOfType<KtModifierList>()?.parent as? KtDeclaration ?: return null
for (lightElement in ktDeclaration.toLightElements()) {
if (lightElement !is PsiModifierListOwner) continue
lightElement.modifierList?.annotations?.firstOrNull { it is KtLightAnnotationForSourceEntry && it.kotlinOrigin == this }?.let { return it }
for (rootAnnotation in lightElement.modifierList?.annotations ?: continue) {
for (annotation in rootAnnotation.withNestedAnnotations()) {
if (annotation is KtLightAnnotationForSourceEntry && annotation.kotlinOrigin == this)
return annotation
}
}
}
return null
}
private fun PsiAnnotation.withNestedAnnotations(): Sequence<PsiAnnotation> {
fun handleValue(memberValue: PsiAnnotationMemberValue?): Sequence<PsiAnnotation> =
when (memberValue) {
is PsiArrayInitializerMemberValue ->
memberValue.initializers.asSequence().flatMap { handleValue(it) }
is PsiAnnotation -> memberValue.withNestedAnnotations()
else -> emptySequence()
}
return sequenceOf(this) + parameterList.attributes.asSequence().flatMap { handleValue(it.value) }
}
fun propertyNameByAccessor(name: String, accessor: KtLightMethod): String? {
val toRename = accessor.kotlinOrigin ?: return null
if (toRename !is KtProperty && toRename !is KtParameter) return null

View File

@@ -94,7 +94,7 @@ class TowerResolver {
name: Name
): Collection<C> = scopeTower.run(processor, AllCandidatesCollector(), false, name)
fun <C : Candidate> ImplicitScopeTower.run(
private fun <C : Candidate> ImplicitScopeTower.run(
processor: ScopeTowerProcessor<C>,
resultCollector: ResultCollector<C>,
useOrder: Boolean,

View File

@@ -7,6 +7,7 @@ where advanced options include:
-Xcoroutines={enable|warn|error}
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
-Xeffect-system Enable experimental language feature: effect system
-Xexperimental=<fq.name> Enable and propagate usages of experimental API for marker annotation with the given fully qualified name
-Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
-Xlegacy-smart-cast-after-try Allow var smart casts despite assignment in try block
-Xmulti-platform Enable experimental language support for multi-platform projects
@@ -18,6 +19,7 @@ where advanced options include:
-Xrepeat=<count> Repeat compilation (for performance analysis)
-Xreport-output-files Report source to output files mapping
-Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes)
-Xuse-experimental=<fq.name> Enable usages of COMPILATION-affecting experimental API for marker annotation with the given fully qualified name
Advanced options are non-standard and may be changed or removed without any notice.
OK

View File

@@ -0,0 +1,8 @@
$TESTDATA_DIR$/experimentalAndUseExperimentalWithSameAnnotation.kt
-d
$TEMP_DIR$
-Xskip-runtime-version-check
-language-version
1.3
-Xexperimental=org.test.ExperimentalAPI
-Xuse-experimental=org.test.ExperimentalAPI

View File

@@ -0,0 +1,4 @@
package org.test
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.COMPILATION])
annotation class ExperimentalAPI

View File

@@ -0,0 +1,3 @@
warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features
error: '-Xuse-experimental=org.test.ExperimentalAPI' has no effect because '-Xexperimental=org.test.ExperimentalAPI' is used
COMPILATION_ERROR

View File

@@ -0,0 +1,10 @@
$TESTDATA_DIR$/experimentalDeprecated.kt
-d
$TEMP_DIR$
-Xskip-runtime-version-check
-language-version
1.3
-Xexperimental=org.test.BinaryError
-Xexperimental=org.test.BinaryHidden
-Xuse-experimental=org.test.SourceError
-Xuse-experimental=org.test.SourceHidden

View File

@@ -0,0 +1,17 @@
package org.test
@Deprecated("BinaryError", level = DeprecationLevel.ERROR)
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.RUNTIME])
annotation class BinaryError
@Deprecated("BinaryHidden", level = DeprecationLevel.HIDDEN)
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.RUNTIME])
annotation class BinaryHidden
@Deprecated("SourceError", level = DeprecationLevel.ERROR)
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.COMPILATION])
annotation class SourceError
@Deprecated("SourceHidden", level = DeprecationLevel.HIDDEN)
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.COMPILATION])
annotation class SourceHidden

View File

@@ -0,0 +1,6 @@
warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features
error: experimental API marker org.test.BinaryError is deprecated. BinaryError
error: experimental API marker org.test.BinaryHidden is deprecated. BinaryHidden
error: experimental API marker org.test.SourceError is deprecated. SourceError
error: experimental API marker org.test.SourceHidden is deprecated. SourceHidden
COMPILATION_ERROR

View File

@@ -0,0 +1,8 @@
$TESTDATA_DIR$/experimentalDeprecatedWarning.kt
-d
$TEMP_DIR$
-Xskip-runtime-version-check
-language-version
1.3
-Xuse-experimental=org.test.SourceWarning
-Xexperimental=org.test.BinaryWarning

View File

@@ -0,0 +1,9 @@
package org.test
@Deprecated("BinaryWarning", level = DeprecationLevel.WARNING)
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.RUNTIME])
annotation class BinaryWarning
@Deprecated("SourceWarning", level = DeprecationLevel.WARNING)
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.COMPILATION])
annotation class SourceWarning

View File

@@ -0,0 +1,4 @@
warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features
warning: experimental API marker org.test.BinaryWarning is deprecated. BinaryWarning
warning: experimental API marker org.test.SourceWarning is deprecated. SourceWarning
OK

View File

@@ -0,0 +1,5 @@
$TESTDATA_DIR$/experimentalIsNotAnnotation.kt
-d
$TEMP_DIR$
-Xexperimental=org.test.NotAnAnnotation1
-Xuse-experimental=org.test.NotAnAnnotation2

View File

@@ -0,0 +1,4 @@
package org.test
enum class NotAnAnnotation1
interface NotAnAnnotation2

View File

@@ -0,0 +1,3 @@
error: class org.test.NotAnAnnotation1 is not an experimental API marker annotation
error: class org.test.NotAnAnnotation2 is not an experimental API marker annotation
COMPILATION_ERROR

View File

@@ -0,0 +1,5 @@
$TESTDATA_DIR$/experimentalIsNotMarker.kt
-d
$TEMP_DIR$
-Xexperimental=org.test.NotAMarker1
-Xuse-experimental=org.test.NotAMarker2

View File

@@ -0,0 +1,4 @@
package org.test
annotation class NotAMarker1
annotation class NotAMarker2

View File

@@ -0,0 +1,3 @@
error: class org.test.NotAMarker1 is not an experimental API marker annotation
error: class org.test.NotAMarker2 is not an experimental API marker annotation
COMPILATION_ERROR

View File

@@ -0,0 +1,7 @@
$TESTDATA_DIR$/experimentalNested.kt
-d
$TEMP_DIR$
-Xskip-runtime-version-check
-language-version
1.3
-Xexperimental=org.test.Outer.Nested

View File

@@ -0,0 +1,9 @@
package org.test
class Outer {
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.LINKAGE])
annotation class Nested
}
@Outer.Nested
fun foo() {}

View File

@@ -0,0 +1,2 @@
warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features
OK

View File

@@ -0,0 +1,8 @@
$TESTDATA_DIR$/experimentalRuntimeScope.kt
-d
$TEMP_DIR$
-Xskip-runtime-version-check
-language-version
1.3
-Xexperimental=org.test.Experimental1
-Xuse-experimental=org.test.Experimental2

View File

@@ -0,0 +1,7 @@
package org.test
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.LINKAGE])
annotation class Experimental1
@Experimental(Experimental.Level.ERROR, [Experimental.Impact.RUNTIME])
annotation class Experimental2

View File

@@ -0,0 +1,3 @@
warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features
error: experimental API marker org.test.Experimental2 has impact other than COMPILATION, therefore it can't be used with -Xuse-experimental
COMPILATION_ERROR

Some files were not shown because too many files have changed in this diff Show More