Compare commits

...

235 Commits

Author SHA1 Message Date
Raluca Sauciuc
be42b8094b Expand the fix from commit 6c274cecff to cover AndroidX
Android Studio users who migrated to AndroidX are running into the
databinding deadlock again: https://issuetracker.google.com/111788726
2018-09-14 19:58:20 +03:00
Yan Zhulanow
44ecfb2fb8 Android Extensions: Check the backing 'virtualFile' validity before calling 'findFile()' (EA-124028) 2018-08-29 17:10:01 +03:00
Alexey Sedunov
5c26b0ea6f Misc: Fix bug introduced after compatibility-related changes 2018-08-22 12:35:22 +03:00
Vyacheslav Gerasimov
feb5a3040f as33c4: Add missing GooglePluginUpdateVerifier 2018-08-21 15:40:07 +03:00
Alexander Udalov
31c113e7ee Add ChangeLog for 1.2.61 2018-08-17 17:48:41 +02:00
Sergey Rostov
b520c72efe Revert "Use separate files for JS and JVM global cache in JPS"
This reverts commit c411521
2018-08-16 12:30:13 +03:00
Alexey Tsvetkov
c411521b7e Use separate files for JS and JVM global cache in JPS
#KT-26072 fixed
2018-08-16 11:26:03 +03:00
Sergey Rostov
3a54e120b5 Kotlin facet UI, JS: Hide "Enable incremental compilation (experimental)".
This option is project-wide only, so it should be visible only in project settings.
#KT-26095 Fixed.
2018-08-16 10:48:26 +03:00
Pavel V. Talanov
386e9b6f6c Run/test line markers: aggregate results across implementing modules
#KT-20363 Fixed
2018-08-15 12:51:01 +02:00
Nicolay Mitropolsky
46f1e271bf Uast: KotlinUAnnotation.uastAnchor uses nameReferenceElement as javaPsi
because `nameReferenceElement` is not-null in LightAnnotations, but `referenceNameElement` violates `javaPsi` contract

(cherry picked from commit cd047b9605)
2018-08-14 20:19:07 +03:00
Nicolay Mitropolsky
923f51cd01 KtLightPsiJavaCodeReferenceElement reference getting made lazy (KT-26036, EA-125884)
Collecting references from contributors could be expensive and even recursive (EA-125884)

(cherry picked from commit 9db2b6ffba)
2018-08-14 20:18:56 +03:00
Nicolay Mitropolsky
1f6ecc2f42 KtLightPsiJavaCodeReferenceElement delegate made nullable (KT-26036, EA-124029)
(cherry picked from commit 2ba2d360c2)
2018-08-14 20:18:40 +03:00
Yan Zhulanow
5133ac21f8 Kapt: Ignore annotation-processing-gradle compiler plugin we got from Gradle (KT-24714)
Cause it's built for the shaded Kotlin compiler and won't work with JPS.
2018-08-13 03:05:17 +03:00
Yan Zhulanow
b09f3a36c4 Parcelize: Fix infinite recursive loop for zero-parameter Parcelable classes (KT-25839) 2018-08-13 03:02:49 +03:00
Alexander Udalov
c9d4aab352 Run classifier usage checkers on function types
(cherry picked from commit fe2251bfca)
2018-08-07 13:59:55 +02:00
Natalia Selezneva
ca34e2085e Wraps syncPublisher() call in KotlinCompilerSettings in a dispose check
Fix ConfigureKotlinTest
2018-08-07 11:15:08 +03:00
Alexey Sedunov
10ce84990b Minor: Fix compilation in AS3.3 bunch 2018-08-03 20:13:54 +03:00
Nikolay Krasko
cbe3d00dfe Render flexible types with enhancement as enhanced in IDE (KT-25622)
Main targets for the fix is completion, parameters info, inlay hints and
override/implement.

Other IDE functions might be affected.

 #KT-24911 Fixed
 #KT-25616 Fixed
 #KT-25622 Fixed
2018-08-03 16:09:11 +03:00
Nikolay Krasko
403ae3f837 Option for rendering types with enhancement 2018-08-03 16:09:10 +03:00
Nikolay Krasko
db12e36ec5 Extend list of annotations ignored in parameter info (KT-24911, KT-25622)
#KT-24911 Fixed
2018-08-03 16:09:09 +03:00
Nikolay Krasko
503d911601 Skip main file while configuring extra files in parameter info test 2018-08-03 16:09:08 +03:00
Nikolay Krasko
fdfaeae21f Allow kotlin extra files in parameter info tests 2018-08-03 16:09:07 +03:00
Alexey Sedunov
375c785694 Misc: Add bunch files to fix compatibility with AS3.3C4 2018-08-03 15:28:14 +03:00
Alexey Tsvetkov
4c9eb5ef1c JS IC: track lookups from libraries
Otherwise we don't track lookups from other modules

    #KT-25540 fixed
2018-08-02 18:07:49 +03:00
Alexander Udalov
80763879ef Update ChangeLog for 1.2.60
Remove a not very interesting feature
2018-08-01 18:56:49 +02:00
Alexander Udalov
aa83ea22f3 Update ChangeLog for 1.2.60 2018-08-01 13:24:31 +02:00
Pavel V. Talanov
d8cddb29ef Do not throw on using kotlin resolve via light classes in dumb mode
Fix an exception when kotlin resolve was invoked when searching
    for tests while indexing (probably many other cases)
Does not actually fix the behaviour, the test will not be found
    resulting in undesired behaviour
Full-blown infrastructure for resolving Kotlin in dumb mode is needed
    to fix the behaviour

 #KT-24979 Fixed
2018-07-27 20:51:07 +02:00
Alexander Udalov
4d3cf043d8 Add ChangeLog for 1.2.60 2018-07-26 19:39:37 +02:00
Vyacheslav Gerasimov
2b2c6a68db as33c4: Update build range for AS 3.3 plugin to match C4 and further releases 2018-07-25 16:15:37 +03:00
Vyacheslav Gerasimov
ddea4a8458 as32: Update build range for AS 3.2 plugin to match RC1 and further releases 2018-07-25 16:15:34 +03:00
Vyacheslav Gerasimov
2ae0d752d1 as33c4: Remove accidentally commited KotlinCompilerVersion.java 2018-07-24 18:27:23 +03:00
Vyacheslav Gerasimov
f787a414ff Update build range for AS 3.3 plugin to match only AS 3.3 C3 2018-07-24 14:51:59 +03:00
Vyacheslav Gerasimov
5d3663316a Update build range for AS 3.2 plugin to match next AS 3.2 releases 2018-07-24 14:51:16 +03:00
Vyacheslav Gerasimov
eb5767bad5 as33c4: Remove registration of AndroidGradleOrderEnumerationHandler from gradle-java.xml 2018-07-24 13:07:03 +03:00
Vyacheslav Gerasimov
b5d3ed2bbe as33c4: Fix compatibility with AS 3.3 C4 2018-07-24 11:43:58 +03:00
Vyacheslav Gerasimov
2df5edb7d0 as33c4: Remove KotlinExplicitMovementProvider.kt
compilation fails against git4idea bundled in AS, wrong version probably
2018-07-24 11:43:58 +03:00
Vyacheslav Gerasimov
82eb0bcfd4 as33c4: Update versions for AS 3.3 C4 2018-07-24 11:43:58 +03:00
Vyacheslav Gerasimov
9f98e596c3 as33c4: *TEMP* Build against AS 3.3 C4 2018-07-24 11:43:58 +03:00
Vyacheslav Gerasimov
a1c1c42924 Add as33c4 bunch derived from 182 2018-07-24 11:43:58 +03:00
Nikolay Krasko
c62e788936 Show popup about too old bundled compiler in Gradle and Maven (KT-25546) 2018-07-24 03:42:02 +03:00
Alexey Tsvetkov
9a04e1938c Minor: fix 173 patchset 2018-07-23 23:12:17 +03:00
Alexey Tsvetkov
95af90e281 Minor: fix 172 patchset 2018-07-23 23:11:25 +03:00
Alexey Tsvetkov
add6664045 Report info message when JS IC is enabled in JPS 2018-07-23 15:45:22 +03:00
Alexey Tsvetkov
1f6d7d9873 Add setting to enable JS IC for JPS
#KT-25565 fixed
2018-07-23 15:45:17 +03:00
Alexey Tsvetkov
8007d78401 Use separate system properties to control IC for JVM and JS
Also this commit effectively disables JS IC by default

     #KT-25563 fixed
2018-07-23 15:45:11 +03:00
Yan Zhulanow
d303b4cb13 PrePush hook (temporary): Do nothing on a download failure 2018-07-20 22:16:23 +03:00
Yan Zhulanow
621acd3457 Kapt: Fix "Unknown option: infoAsWarnings" (#KT-25396)
(cherry picked from commit 02ee3aef3f)
2018-07-20 22:13:42 +03:00
Yan Zhulanow
418389a125 Kapt: Do not add JDK jars if the 'no-jdk' option is set (KT-25258)
(cherry picked from commit 1eb69a6960)
2018-07-20 22:13:26 +03:00
Dmitry Savvinov
f403b99d34 Deprecate visibility of static members inherited from Java
Now they are not visible by short name through companion objects, just
like classifiers in KT-21515

^KT-25333 In progress
2018-07-19 13:36:29 +03:00
Ilya Chernikov
51da66fb39 Do not throw on incompatible cli scripting plugin
More reliably fixes #KT-24946, #KT-24438 and alike
2018-07-18 15:08:12 +02:00
Nicolay Mitropolsky
2cb03f9097 Uast: implicit receiver for local function calls (KT-25524)
(cherry picked from commit a616f6cca9)
2018-07-18 14:09:13 +03:00
Nicolay Mitropolsky
cf07348abe Uast: implicit receiver for function variables calls (KT-25524)
(cherry picked from commit 5212728a82)
2018-07-18 14:08:26 +03:00
Denis Zharkov
8caf1ae593 Fix test data after 89d99e3989 2018-07-18 12:26:36 +03:00
Nikolay Krasko
94ac895de2 Stop reporting "using default platform" messages to log (KT-15300)
#KT-15300 Fixed

(cherry picked from commit 752cdedfe2)
2018-07-17 21:13:25 +03:00
Pavel V. Talanov
27f15a74b0 Do not try inexact resolve on scripts
Script light psi depends on script definition
    which is costly to compute correctly

 #KT-25395 Fixed
2018-07-17 13:42:06 +02:00
Dmitry Savvinov
fe26547cd7 Make warning about usage of -XX-flags less scary 2018-07-17 12:09:05 +03:00
Denis Zharkov
1960587512 Refine diagnostics for nullability migration warnings
#KT-24911 Fixed
2018-07-16 10:50:31 +03:00
Nicolay Mitropolsky
8d1690ca00 lightAnnotations: check element validity before resolving call
(cherry picked from commit 3c71761cf3)
2018-07-13 20:24:22 +03:00
Nicolay Mitropolsky
ca04d5933c lightAnnotations: proper parents for KtLightAnnotationsValues
(cherry picked from commit cedc6821c3)
2018-07-13 20:22:58 +03:00
Alexander Udalov
b0991596fe Minor, improve wording in exception message
(cherry picked from commit dec003af71)
2018-07-13 18:46:32 +02:00
Alexander Udalov
c4ec46b3c5 Fix regression in reflection on looking up equals/hashCode/toString in interface
Caused by 4266e50be8 and 8ccbbf71ec. Previously it worked because we
used hardcoded signatures of equals/hashCode/toString and always looked
them up in java.lang.Object

 #KT-25404 Fixed

(cherry picked from commit 66b383349f)
2018-07-13 18:46:30 +02:00
Natalia Selezneva
c1fe8f31f0 Add quickfix to adding kotlin-script-runtime.jar to classpath
(cherry picked from commit e395a32734)
^KT-25402 Fixed
2018-07-12 14:01:47 +03:00
Natalia Selezneva
52af70f887 Fix deadlock in ScriptTemplatesFromCompilerSettingsProvider
(cherry picked from commit d241c092e2)
^KT-25373 Fixed
2018-07-11 16:27:40 +03:00
Alexey Sedunov
290805100c Misc: Make LibraryEffectiveKindProvider cache an instance property
(cherry picked from commit fc93f00c7b)
2018-07-11 15:14:29 +03:00
Ilya Gorbunov
4f54b01820 Fix incorrect parameter order in TestNG asserter
#KT-25351 Fixed

(cherry picked from commit 5e5b9e5)
2018-07-10 19:18:17 +03:00
Natalia Selezneva
cb9692834e Fix AbstractScriptConfigurationTest
Add dependency on script runtime for module.
Provide default test script template thought template-classpath.
2018-07-10 16:47:07 +02:00
Natalia Selezneva
56f2e469fc Add LightProjectDescriptor with script-runtime dependency. Use it in PsiChecker tests. 2018-07-10 16:46:50 +02:00
Natalia Selezneva
37374f5617 Fix testdata fo IdeaModuleInfoTest: for script in module IdeaModuleInfo is created instead of ScriptModuleInfo.ForFile 2018-07-10 16:46:34 +02:00
Nicolay Mitropolsky
bd18a115a7 172: KotlinUastApiTest.kt compilation fix 2018-07-10 09:03:43 +03:00
Ilya Gorbunov
35170f5b3f Report more diagnostics when JDK8PlatformImplementations can't be cast to base type
#EA-120914 - CCE: PlatformImplementationsKt.<clinit>

(cherry picked from commit b7d3382)
2018-07-09 22:35:54 +03:00
Ilya Gorbunov
42d4597480 Fix overflow in empty progressions' last element
#KT-24204 Fixed

(cherry picked from commit 35beb96)
2018-07-09 22:35:42 +03:00
Ilya Gorbunov
92f008db5e Add failing tests for overflow in empty progressions KT-24204
(cherry picked from commit be8cb94)
2018-07-09 22:35:30 +03:00
Nicolay Mitropolsky
19fe1a57ee Uast: ULambdaExpression returns proper functionalInterfaceType for SamAdapterExtensionFunctionDescriptor (KT-25297)
(cherry picked from commit dd0e3cd135)
2018-07-09 19:44:38 +03:00
Nicolay Mitropolsky
0eaebcaf9e Uast: properly handling explicit SAM (KT-25297)
(cherry picked from commit 2c7687195c)
2018-07-09 19:44:19 +03:00
Nicolay Mitropolsky
43d195f3e2 Uast: create KotlinULambdaExpression for in-place lambdas (KT-25297)
and provide appropriate functionalInterface

(cherry picked from commit 38e2d474b7)
2018-07-09 19:44:06 +03:00
Mikhael Bogdanov
34fc43ae02 Generate sam wrappers in inlined lambda in same way as in inline function
#KT-24825 Fixed

(cherry picked from commit 66e68fbb53)
2018-07-09 15:54:03 +02:00
Ilya Chernikov
42fc117900 Fix script templates tests after updating definitions selection logic 2018-07-09 15:40:35 +02:00
Ilya Chernikov
bcb74bf5bb Fix testdata 2018-07-09 15:40:35 +02:00
Ilya Chernikov
679d49b8f2 Drop support of KOTLIN_HOME environment variable in the command-line compiler
it is proved to be fragile and seems unnecessary at the moment
2018-07-09 15:40:35 +02:00
Ilya Chernikov
e8377e6b22 Fixes after review 2018-07-09 15:40:35 +02:00
Ilya Chernikov
2a04236902 Fix configurations chaining in the script compiler 2018-07-09 15:40:35 +02:00
Ilya Chernikov
5de77d1404 Take path to scripting plugin libs only from compiler jar path...
ignoring all "kotlin home" settings, since we need to load a compatible
plugin. Fixes #KT-24946
2018-07-09 15:40:35 +02:00
Ilya Chernikov
c860d8b0d6 Allow multiple same jsr305 options in the command-line
do not report duplicate jsr305 entries if options are the same
2018-07-09 15:40:35 +02:00
Ilya Chernikov
f8f3cd435a Add kts to supported file extensions to the DirtySourceFilesHolder as well
allows jps to compile scripts along with sources,
finally fixes #KT-22611
2018-07-09 15:40:35 +02:00
Ilya Chernikov
2a70d61a9f Drop half-backed support of "dynamic" annotations on scripts...
leaving it in the history so it could be restored and finished, if needed
2018-07-09 15:40:35 +02:00
Ilya Chernikov
be5a711e78 Add script constructor annotations inheritance 2018-07-09 15:40:35 +02:00
Ilya Chernikov
b69b9e2a9f Add script class annotations generation from the base class 2018-07-09 15:40:35 +02:00
Ilya Chernikov
956514c87e Refactor script definitions loading and discovery:
Improve logic, code reuse and readability
Add support for more corner cases
Improve reporting
Add definitions loading test
2018-07-09 15:40:35 +02:00
Ilya Chernikov
7e833239e8 Fix list of script definitions recognized by the asm-based loading:
fix of the previous fix to #KT-24926
2018-07-09 15:40:35 +02:00
Ilya Chernikov
6fdbae2aa4 Fix explicit custom scripting definitions choice logic:
add standard script def after custom defs are processed
2018-07-09 15:40:35 +02:00
Ilya Chernikov
47d62d9019 Improve automatic scripting plugin picking logic 2018-07-09 15:40:35 +02:00
Ilya Chernikov
16d0ec4980 Fix script definition discovery logic:
for cases when directory-based dependencies are passed and directories
with resources are different from directories with classes
Significant refactoring to make code prettier
2018-07-09 15:40:35 +02:00
Ilya Chernikov
d479f0ebd5 Fix default configuration refinement in scripts 2018-07-09 15:40:35 +02:00
Ilya Chernikov
0b42d17c83 Return script instance from the evaluation in the basic jvm evaluator 2018-07-09 15:40:35 +02:00
Pavel Talanov
7b5c88ed7c Implement support for static resolving to scripts in source roots in IDEA 2018-07-09 15:40:35 +02:00
Ilya Chernikov
b0fb1d85ff Create proper constructor in script descriptor
allows to resolve calls to scripts in compiler (but not in the IDE yet)
Some refactorings on the way
2018-07-09 15:40:35 +02:00
Alexey Tsvetkov
5859c5ec25 Test for KT-25051 2018-07-09 16:31:45 +03:00
Alexey Tsvetkov
d24b7b0a62 Remove redundant test
`testMultiModuleICNonAndroidModuleIsChanged` already tested
android and non-android change
2018-07-09 16:31:45 +03:00
Alexey Tsvetkov
85fe6508f6 Register kotlin_module as output of all files
Previously kotlin_module was registered as output
only for files containing top-level declarations
2018-07-09 16:31:45 +03:00
Alexey Tsvetkov
a6d7485f37 Always generate kotlin_module
#KT-25133 fixed
    #KT-25051 fixed
2018-07-09 16:31:45 +03:00
Yan Zhulanow
f50b00a3d6 Minor: Do not report stack traces about PCE to the debug log 2018-07-09 15:37:13 +03:00
Yan Zhulanow
349d703232 Minor: Move safeSourceName to utils, make it a function 2018-07-09 15:37:13 +03:00
Yan Zhulanow
26eb425bdb Kapt: Do not add imports for overloaded callables (#KT-25071) 2018-07-09 15:37:13 +03:00
Yan Zhulanow
1507ce4081 Minor: Fix the "Could not find installation home path" terminal warning 2018-07-09 15:37:12 +03:00
Yan Zhulanow
9edd9847a6 Debugger: Check if the class instance is not yet collected before usage (EA-118758) 2018-07-09 15:37:12 +03:00
Yan Zhulanow
2950465277 Evaluator: Support when expressions (EA-119639) 2018-07-09 15:37:12 +03:00
Yan Zhulanow
66c564ec7a Debugger: Add a missing read action (EA-119592) 2018-07-09 15:37:12 +03:00
Yan Zhulanow
f92588ce9c Check if the stackFrame we use is valid (EA-120312)
Unfortunately, the 'isValid' is a private field in StackFrameImpl so we have to catch an exception with an empty catch block.
2018-07-09 15:37:12 +03:00
Yan Zhulanow
3325a13974 Add a number of runReadAction() in debugger (EA-120985) 2018-07-09 15:37:12 +03:00
Yan Zhulanow
559282b6da Uast: Do not try to evaluate error values (EA-121947) 2018-07-09 15:37:12 +03:00
Yan Zhulanow
67c1b4918f Eval4J: Do not report certain kinds of exceptions to EA 2018-07-09 15:37:12 +03:00
Yan Zhulanow
9c00f62c6d Minor: Fix exception message 2018-07-09 15:37:11 +03:00
Yan Zhulanow
93afdb29ef Evaluator: Do not report division by zero (EA-122365) 2018-07-09 15:37:11 +03:00
Yan Zhulanow
6512ed882f Debugger: Add a missing read action (EA-123238) 2018-07-09 15:37:11 +03:00
Yan Zhulanow
195b35e638 Kapt: Ensure we collect .java files from the unique directories (#KT-24963) 2018-07-09 15:37:11 +03:00
Yan Zhulanow
41439dd708 Pill: Allow '18x-SNAPSHOT' versions 2018-07-09 15:37:11 +03:00
Yan Zhulanow
0368b4be03 Debugger: Exclude inline callable usages inside itself (EA-117459) 2018-07-09 15:37:11 +03:00
Yan Zhulanow
d871511a18 Kapt: Allow to disable info->warning mapping in logger (#KT-24985) 2018-07-09 15:37:11 +03:00
Yan Zhulanow
89863a712f as32: Kapt: 'kapt.kotlin.generated' is not marked as source root in Android Studio (#KT-24449) 2018-07-09 15:37:11 +03:00
Yan Zhulanow
b9867d3091 Remove Gradle(Java) Kotlin configurator in Android modules (#KT-17946) 2018-07-09 15:37:10 +03:00
Yan Zhulanow
eb056eb469 Uast: Move all IDE-related code to uast-idea, get rid of the 'idea' dependency
Uast is used in the CLI version of Android Lint so 'uast-kotlin' should run correctly even without IDE.
2018-07-09 15:37:10 +03:00
Yan Zhulanow
3adcb27b24 Kapt: Allow to disable warning for 'annotationProcessor' dependencies (#KT-24883) 2018-07-09 15:37:10 +03:00
Yan Zhulanow
2d4b8f57f7 Pill: Support Android Studio bunches in "IDEA" run configuration 2018-07-09 15:37:10 +03:00
Yan Zhulanow
76f294fc0f Extract refactoring: Make an extracted function 'inline' if any of its type parameters are reified (#KT-23983) 2018-07-09 15:37:10 +03:00
Yan Zhulanow
57d08e74c9 Minor: Fix test data for Parcelize annotation checker 2018-07-09 15:37:10 +03:00
Yan Zhulanow
0c5b8caa43 Parcelize: Recognize '@IgnoredOnParcel' with @get: use-site annotation target 2018-07-09 15:37:10 +03:00
Yan Zhulanow
e679d60fd4 Parcelize: Generate non-final 'writeToParcel()' and 'describeContents()' (#KT-24720) 2018-07-09 15:37:09 +03:00
Yan Zhulanow
f8862690eb Parcelize: Fix Parcelize box tests 2018-07-09 15:37:09 +03:00
Yan Zhulanow
b2fd7d06da Parcelize: Check @IgnoredOnParcel annotation usage (#KT-24459) 2018-07-09 15:37:09 +03:00
Yan Zhulanow
39d1eaeb2c Parcelize: Serialize primitive arrays correctly when the custom parceler is provided.
This fixes failing 'customSerializerBoxing' test.
2018-07-09 15:37:09 +03:00
Yan Zhulanow
11ebc67b9b Parcelize: Always map primitive array element types as boxed types for Array<T> (#KT-23808) 2018-07-09 15:37:09 +03:00
Yan Zhulanow
94f5d0419a Parcelize: Support objects and enums (#KT-22576) 2018-07-09 15:37:09 +03:00
Alexander Podkhalyuzin
fe92eeb6ca Do not stop recursive visitor with return
#KT-23627 Fixed

(cherry picked from commit 04fd4ef9de)
2018-07-09 15:32:17 +03:00
Natalia Selezneva
b21b425d7e Run script dependencies update on editor focus change
(cherry picked from commit 4b1ce15619)

^KT-24588 Fixed
2018-07-06 12:01:50 +03:00
Sergey Rostov
20820baa48 Fix StringIndexOutOfBoundsException in KotlinConsoleFilterProvider.kt (EA-118757)
(cherry picked from commit 7408504356)
2018-07-06 11:46:54 +03:00
Denis Zharkov
2bae870b43 Optimize KotlinPropertyAccessorsReferenceSearcher for case of no kt-files
Property names by accessors can be computed without resolving
java descriptors

 #KT-11477 Fixed
 #KT-23844 Fixed
2018-07-06 10:29:56 +03:00
Denis Zharkov
c7a3be0083 Optimize SyntheticJavaPropertyDescriptor.Companion::findByGetterOrSetter
Do not force getContributedDescriptors call when we need to request
at most three names
2018-07-06 10:28:16 +03:00
Denis Zharkov
8e824defaf Reformat SyntheticJavaPropertiesScope.kt 2018-07-06 10:28:08 +03:00
Denis Zharkov
0765850907 Load Java overrides of Kotlin suspend functions as suspend, too
There's still some blind spots:
- Covariant overrides in Java (KT-25036)
- Current implementation assumes that when language version is 1.3 every suspend function
reference only release-coroutines-package Continuation
(we need to check if it's a correct statement)

 #KT-24848 Fixed
 #KT-25036 Open
2018-07-06 10:26:52 +03:00
Denis Zharkov
3f2fabb655 Minor. Reformat LazyJavaClassMemberScope.kt 2018-07-06 10:26:48 +03:00
Denis Zharkov
0bbe975baa Add postfix template for listOf/setOf/etc
#KT-25239 Fixed
2018-07-06 10:16:34 +03:00
Denis Zharkov
f07eb3121a Minor. Reformat org.jetbrains.kotlin.idea.codeInsight.postfix 2018-07-06 10:16:34 +03:00
Denis Zharkov
c880337f3e Implement quickfix wrapping elements in collection literal calls
#KT-25238 Fixed
2018-07-06 10:16:34 +03:00
Alexey Tsvetkov
96d2896831 Temporarily ignore Kapt3WorkersAndroid32IT 2018-07-05 18:23:20 +03:00
Alexey Tsvetkov
c1083a103e Allow overriding default Gradle version per test class 2018-07-05 18:23:16 +03:00
Alexey Tsvetkov
31b987cf27 Add SDK jars to compile classpath for Kapt Workers task 2018-07-05 18:23:13 +03:00
Alexey Tsvetkov
26141ab16c Close kapt context 2018-07-05 18:23:10 +03:00
Alexey Tsvetkov
d97e98f4a8 Test kapt with workers 2018-07-05 18:23:07 +03:00
Alexey Tsvetkov
6e9bcf3929 Update android tools versions in Gradle plugin tests 2018-07-05 18:23:04 +03:00
Alexey Tsvetkov
eaf4d2a5ac Remove projectDir input from KaptWithoutKotlincTask
It is redundant since the task would be restarted when project dir changes,
because paths of sources would also change
2018-07-05 18:23:01 +03:00
Alexey Tsvetkov
c402630348 Fix getting plugin version for kotlinKaptWorkerDependencies configuration
Previously the configuration would not work for non-android projects,
because it looked only at KotlinAndroidPluginWrapper for plugin version
2018-07-05 18:22:58 +03:00
Alexey Tsvetkov
67334ae9e9 Create kotlinKaptWorkerDependencies only once
#KT-25124 fixed
2018-07-05 18:22:54 +03:00
Alexey Tsvetkov
fa10c32ffa Do not load annotation processors when generating stubs
#KT-25131 fixed
2018-07-05 18:22:51 +03:00
Alexey Tsvetkov
78a25c33fd Fix compilation of plugin projects in JPS
#KT-25218 fixed
2018-07-05 18:22:47 +03:00
Nicolay Mitropolsky
c49df7fee6 Uast: converting Unit to void on type mapping (KT-25249)
(cherry picked from commit 5d9807ac36)
2018-07-05 17:06:03 +03:00
Nikolay Krasko
4ae13e29fb Show kotlin internal information only in internal builds 2018-07-05 16:23:54 +03:00
Alexander Udalov
c4ea50b357 Retain optional expected annotations when compiling platform code
After this change, optional expected annotations will be compiled to
physical class files on JVM, and stored to metadata on other platforms,
to allow their usages from dependent platform modules. For example:

    @OptionalExpectation
    expect annotation class A

When compiling this code on JVM, A.class will be produced as if the
class A did neither have the 'expect' modifier, nor had it been
annotated with OptionalExpectation. Note that if there's no actual
annotation class for A, then usages (which can only be usages as
annotation entries) are simply skipped.

Class A will be public from Kotlin's point of view (since it should
be possible to use it in Kotlin sources), but _package-private_ in Java
to disallow its usages outside of the declaring module.

 #KT-18882 Fixed
 #KT-24617 Fixed

(cherry picked from commit 1951d38f40)
2018-07-05 14:34:46 +02:00
Alexander Udalov
0df72aaf15 Pass BindingContext to CodegenUtil.getActualDeclarations
Will be used in a subsequent commit. Also rename getActualDeclarations
-> getDeclarationsToGenerate

(cherry picked from commit 4e217b180a)
2018-07-05 14:34:40 +02:00
Ilya Chernikov
a6718a6086 Add 1.2.51 issues to changelog
(cherry picked from commit db73ed1d0c)
2018-07-05 13:09:38 +02:00
Alexey Sedunov
bdc02571c7 JS: Fix detection of run configuration with preconfigured Mocha
#KT-25253 Fixed

(cherry picked from commit 2efd467c42)
2018-07-04 18:22:03 +03:00
Alexey Sedunov
acbd5e7fae Misc: Fix SOE due to wrong overloaded method call
#KT-25247 Fixed

(cherry picked from commit 5f69eebe66)
2018-07-03 22:14:02 +03:00
Yan Zhulanow
8efd490c5c as33: Remove AndroidGradleOrderEnumerationHandler (should be moved to the Android plugin) 2018-07-03 16:15:48 +03:00
Alexey Sedunov
ea32314468 Search Everywhere: Recover original behavior for non-functions
#KT-25189 Fixed

(cherry picked from commit 03ed4e39e3)
2018-07-02 22:50:42 +03:00
Alexey Sedunov
c2251e8ca9 Test Support: KT-22306
Do not show run markers in JS modules when no relevant run configurations are available

 #KT-22306 Fixed

(cherry picked from commit b52b07ec79)
2018-07-02 22:50:13 +03:00
Alexey Sedunov
bb97b70373 Rename: Fix processing of references to synthetic Java properties
Fixes for non-master-bunch plugin.xml

(cherry picked from commit 3e91346240)
2018-07-02 22:49:53 +03:00
Vyacheslav Gerasimov
2c3e02bc8c UAST: Fix possible TypeCastException when creating KotlinUNamedExpression
(cherry picked from commit a829251690)
2018-07-02 21:44:52 +03:00
Vyacheslav Gerasimov
ffd673bbda Check if module disposed when getting modules with kotlin files
(cherry picked from commit 23ee463053)
2018-07-02 21:44:44 +03:00
Vyacheslav Gerasimov
34b04d8ec4 Reformat ConfigureKotlinInProjectUtils
(cherry picked from commit 16b4d25c1d)
2018-07-02 21:44:37 +03:00
Vyacheslav Gerasimov
e1b7142454 UAST: Do not log PCE in DeclarationDescriptor.toSource
(cherry picked from commit 62c0d37d45)
2018-07-02 21:44:29 +03:00
Yan Zhulanow
70230564fb Add support for Android Studio 3.3 Canary 1 2018-07-02 21:16:09 +03:00
Yan Zhulanow
371ee9f1f7 Minor: Make plugin.xml and build files more consistent with the main bunch 2018-07-02 21:16:08 +03:00
Yan Zhulanow
20d5c78e5d Make source set empty for Android modules of deleting the resulting JAR files in 'ideaPlugin' task 2018-07-02 21:07:58 +03:00
Raluca Sauciuc
1a25aefc94 as33: Android dependency reversal
(cherry picked from commit be781f4f462f74ca0efcc91b5c07a5b3756ba5b2)
2018-07-02 21:07:58 +03:00
Alexander Udalov
b021fea545 Improve reflection error message when function/property is not found 2018-07-02 19:05:05 +02:00
Alexander Udalov
b20b34224d Load all resources in RuntimePackagePartProvider; optimize code
The issue was reproducible when the same package is present in different
modules with the same -module-name (which is a popular case of src/test
roots in simple IDEA projects). The problem was in the fact that several
resource files containing package name mapping with the same name were
present in the classpath, but RuntimePackagePartProvider only considered
the first one. The fix is to use getResources instead of
getResourceAsStream and handle each returned resource.

Also, optimize internal representation to store the mapping in the form
which is the most convenient for findPackageParts, which should be
faster than registerModule because in theory, it's called more often.

 #KT-21973 Fixed
 #KT-24651
2018-07-02 19:05:05 +02:00
Alexander Udalov
42caa688de Remove obsolete BuiltInFunction and mapIntrinsicFunctionSignature
This is now fully covered by the JVM signature mapping, introduced in
the previous commit. The change in KDeclarationContainerImpl.methodOwner
is needed because primitive classes have no methods on JVM; and when
we're looking for "Int.equals", we'll now look it up in the Class object
for java.lang.Integer, not for the primitive int.
2018-07-02 19:05:05 +02:00
Alexander Udalov
a8f31de2f5 Use manual type mapping in reflection for members from built-ins
There are cases when members deserialized from JVM classes have no JVM
signature in the proto. For example, if a member is inherited from a
built-in class (such as Map.getOrDefault in some Map implementations),
or if a member is synthesized in the compiler front-end and back-end
separately (such as enum values/valueOf). In these cases, we'll use the
naive type mapping to try to recover the signature.

 #KT-16616 Fixed
 #KT-17542 Fixed
2018-07-02 19:05:05 +02:00
Alexander Udalov
f6488f7c4a Reformat module reflection.jvm, fix inspections/warnings 2018-07-02 19:04:07 +02:00
Alexander Udalov
34677658b3 Catch SecurityException when reading system property in BitEncoding
This does not fix KT-15167 though because the exception from KT-20575 is
thrown shortly afterwards

 #KT-15167
2018-07-02 19:04:06 +02:00
Alexander Udalov
fca612bcf8 Improve diagnostic for missing BuiltInsLoader implementation
Also initialize it lazily to avoid wrapping the exception into
ExceptionInInitializerError

 #KT-20575
2018-07-02 19:04:06 +02:00
Alexander Udalov
d2908c3894 Do not serialize constructors for anonymous objects
The only client of this data is reflection, and since anonymous objects
do not have constructors in the source code, they shouldn't in
reflection as well

 #KT-20442 Fixed
2018-07-02 19:04:06 +02:00
Alexander Udalov
00c292fe77 Do not create primary constructor for enum entry synthetic class
The change in DescriptorSerializer is needed so that serialized protos
of enum entry classes which are resolved in sources
(LazyClassDescriptor) and are deserialized from binaries
(EnumEntrySyntheticClassDescriptor) are the same. There are tests on
incremental compilation in JS that check that the serialized proto is
exactly the same after rebuild and after an incremental build.

 #KT-22048 Fixed
2018-07-02 19:04:06 +02:00
Alexey Sedunov
899de0eb0f Misc: Configure stdlib in failing tests
(cherry picked from commit 22d7427)
2018-07-02 19:11:47 +03:00
Alexey Sedunov
d4c2b33c39 Misc: Fix test assertion
(cherry picked from commit 65dad5e)
2018-07-02 19:11:47 +03:00
Vyacheslav Gerasimov
60c4308186 Allow plugin installation on Android Studio 3.2 Beta 2 2018-06-29 22:13:10 +03:00
Alexey Sedunov
e3e7eaec7b Misc: Restore utility functions misplaced in a previous commit
(cherry picked from commit a63aa5b)
2018-06-29 20:29:24 +03:00
Alexey Sedunov
feeedf7c02 Configuration: Use soft references to keep library kind cache
#KT-24943 Fixed

(cherry picked from commit 76ac65f)
2018-06-29 20:29:00 +03:00
Alexey Sedunov
c08aefbf80 PSI: Do not delete package directive for file in default package
#KT-24968 Fixed

(cherry picked from commit 60583e5)
2018-06-29 20:28:43 +03:00
Alexey Sedunov
4d141fbd6c Misc: Add "refactoring exit" message
This allows executing mandatory code at the end of particular refactoring.
Also this fixes memory leak due to listener not being disposed

 #KT-17235 Fixed

(cherry picked from commit e2a632e)
2018-06-29 20:28:27 +03:00
Alexey Sedunov
2dac33d3d1 Introduce Parameter: Fix exceptions caused by write actions in dialogs
#KT-24992 Fixed

(cherry picked from commit ba2f287)
2018-06-29 20:28:06 +03:00
Alexey Sedunov
02869ab0c7 Extract Function: Make compliant with PublicApiImplicitTypeInspection
(cherry picked from commit ed597e2)
2018-06-29 20:27:45 +03:00
Alexey Sedunov
a007784439 Misc: Use KtToken to represent visibility in ExtractableCodeDescriptor
(cherry picked from commit 633c67e)
2018-06-29 20:26:42 +03:00
Alexey Sedunov
c3b3ad53b2 Search Everywhere: Update renderer to reflect changes in IDEA
#KT-24812 Fixed

(cherry picked from commit 8374501)
2018-06-29 20:24:53 +03:00
Alexey Sedunov
e1e0a61572 Search Everywhere: Use Kotlin renderer for Kotlin elements only
(cherry picked from commit 31d248c)
2018-06-29 20:24:35 +03:00
Alexey Sedunov
79681ce425 Extract Interface: Fix type import when converting parameter to property
#KT-18736 Fixed

(cherry picked from commit bede2e1)
2018-06-29 20:24:09 +03:00
Alexey Sedunov
8fa29e4857 Extract Superclass: Report private members used in abstracted members
#KT-16284 Fixed

(cherry picked from commit 9b7450c)
2018-06-29 20:23:38 +03:00
Alexey Sedunov
0e04e74d7f Extract Superclass: Fix visibility lifting when moving to interface
#KT-16281 Fixed

(cherry picked from commit bd88e02)
2018-06-29 20:23:22 +03:00
Alexey Sedunov
e1286f221f Extract Superclass: Allow extraction to existing file
#KT-15351 Fixed

(cherry picked from commit b0e0460)
2018-06-29 20:23:06 +03:00
Alexey Sedunov
7380d1e3a1 Extract Superclass: Run refactoring inside of transaction
#KT-18555 Fixed

(cherry picked from commit 5ef54a2)
2018-06-29 20:22:46 +03:00
Nicolay Mitropolsky
a620a94d7b 182: IDEA sdk set to 182.3458.5
(cherry picked from commit 80f022c3d5)
2018-06-29 16:45:43 +03:00
Mikhail Glukhikh
c4e6cb3232 Add actual: handle (incorrect) case with expect function with body
So #KT-23326 Fixed

(cherry picked from commit fdc0335b4a)
2018-06-29 15:21:07 +03:00
Mikhail Glukhikh
ef32ee409a Add actual: handle parameters with val/var as compatible with property
So #KT-23762 Fixed

(cherry picked from commit 0fb183e302)
2018-06-29 15:20:52 +03:00
Mikhail Glukhikh
68c6c79be9 Add actual: handle primary & secondary constructors as compatible
So #KT-23686 Fixed

(cherry picked from commit dd0b267531)
2018-06-29 15:20:13 +03:00
Mikhail Glukhikh
ba0f3277c5 Reformat: AddActualFix
(cherry picked from commit 082c3e6767)
2018-06-29 15:19:59 +03:00
Mikhail Glukhikh
d254acc980 Create actual: do not generate default parameter values
So #KT-23105 Fixed

(cherry picked from commit 16c6d63b10)
2018-06-29 15:19:46 +03:00
Mikhail Glukhikh
1f4d43da55 Safe delete: add dialog asking about expect / actual declarations
Related to KT-15666

(cherry picked from commit b13e4535f5)
2018-06-29 15:19:26 +03:00
Mikhail Glukhikh
e5dc807427 Safe delete: when invoking on actual, delete expect & actual neighbors
So #KT-15666 Fixed

(cherry picked from commit aac71bf904)
2018-06-29 15:19:11 +03:00
Mikhail Glukhikh
536e0583a4 Safe delete: when invoking on expect, delete also relevant actual
Partial fix of KT-15666

(cherry picked from commit 50e70e4638)
2018-06-29 15:18:57 +03:00
Mikhail Glukhikh
4830afe183 Safe delete: search for actual declarations more accurately
(cherry picked from commit 465d5c077e)
2018-06-29 15:18:43 +03:00
Mikhail Glukhikh
26e6c8ed16 Cleanup: KotlinSafeDeleteProcessor
(cherry picked from commit 5bdaef4983)
2018-06-29 15:18:28 +03:00
Nicolay Mitropolsky
b5350da727 Uast: fix for creating an UClass for invalid object-literals (EA-122644, KT-20056)
(cherry picked from commit 698096f13e)
2018-06-28 10:42:22 +03:00
Lucas Smaira
c576bc8fba Find Kotlin class with alternative resolve enabled
Kotlin run configurations are failing non-deterministically in Android
Studio due to not finding the class while in dumb mode (while AS invokes
Gradle build or in indexing after that).

Fix that by finding class in KotlinRunConfiguration with alternative
resolve enabled.

(cherry picked from commit 5820656aae)
2018-06-27 16:50:21 +03:00
Nikolay Krasko
87eb155795 as32: Minor: use full sentences for reasons
(cherry picked from commit 8ea19eda73)
2018-06-27 16:32:08 +03:00
Nikolay Krasko
80a94a7efb as32: Use full sentences for reasons
(cherry picked from commit 17d4961760)
2018-06-27 16:31:59 +03:00
Nikolay Krasko
1457cfd8a8 Move isEap and isDev utility functions to idea module
(cherry picked from commit 099f3f3ddf)
2018-06-27 16:31:49 +03:00
Nikolay Krasko
d874ed4869 Make disabled verification visible in UI
(cherry picked from commit 54bb09a5fb)
2018-06-27 16:31:39 +03:00
Sergey Igushkin
214463e6f7 Fix Android ap option providers as Kapt task nested inputs
1) Exclude the providers arguments from the kapt inputs, as the values
may contain absolute paths, may be output properties etc. The providers
should correctly annotate their inputs.

2) Fix the options passed to kapt as 'value=option' (leading to all the
options collapse into one with the null key), use 'key=option' instead
to make Kapt pass them as '-Aoption'.

Issue #KT-23866 Fixed
Issue #KT-25027 Fixed

(cherry picked from commit dbd72ae53b)
2018-06-27 14:04:04 +03:00
Nicolay Mitropolsky
f8e171c9f5 Uast: proper identifiers for KotlinUBinaryExpression (KT-25092)
(cherry picked from commit bef3d4ace2)
2018-06-27 11:31:18 +03:00
Nikolay Krasko
08a544b1a2 Fobid installation for Android Studio 3.3 2018-06-26 17:51:34 +03:00
Mikhail Glukhikh
cff73d5309 Unused symbol: don't suggest actual declaration used in another platform
Related to KT-17512
Related to KT-15666

(cherry picked from commit eb92b7ed7f)
2018-06-26 15:59:13 +03:00
Mikhail Glukhikh
2c37746a28 Do not mark kotlin.test.Test annotated declarations as unused
So #KT-20523 Fixed

(cherry picked from commit 30327aa9cc)
2018-06-26 15:58:55 +03:00
Mikhail Glukhikh
e5de325629 Unused symbol: remove forced "used" from actual declarations
Now we really check whether actual declaration has usages
(in expect or actual code) or not
Related to KT-17512
Related to KT-15666

(cherry picked from commit 7e0e7dc983)
2018-06-26 15:58:40 +03:00
Mikhail Glukhikh
a2e33996a6 Implement search from expect element in KotlinReferenceSearcher
So mostly #KT-17512 Fixed

(cherry picked from commit e885e54233)
2018-06-26 15:58:25 +03:00
Mikhail Glukhikh
0ce12e4b17 Find property usages dialog: rename all check-boxes as in other dialogs
(cherry picked from commit 97d158d833)
2018-06-26 15:58:11 +03:00
Mikhail Glukhikh
01ae6515b1 Add find usages option: search expected
(cherry picked from commit abbfea357a)
2018-06-26 15:57:58 +03:00
Mikhail Glukhikh
62206740f5 KotlinFindMemberUsagesHandler: get rid of deprecation
(cherry picked from commit 69e420991a)
2018-06-26 15:57:44 +03:00
Mikhail Glukhikh
a27e2b0d1e Cleanup: KotlinReferenceSearcher
(cherry picked from commit 0a36edcf20)
2018-06-26 15:57:30 +03:00
Mikhail Glukhikh
68c5f701d5 Cleanup: findUsagesOptions
(cherry picked from commit ea7db42af6)
2018-06-26 15:57:16 +03:00
Mikhail Glukhikh
569a0a63d8 Cleanup: KotlinFindMemberUsagesHandler
(cherry picked from commit a46e4f3142)
2018-06-26 15:57:03 +03:00
Mikhail Glukhikh
67ac21fca6 Test for KT-17512 (yet with incorrect results)
(cherry picked from commit cc2869988f)
2018-06-26 15:56:49 +03:00
Mikhail Zarechenskiy
5dcd4c86e1 Fix internal compiler error on importing invisible fake reference
Note that this is not relevant for LOCAL/INHERITED visibilities:
  - for LOCAL visibility it's impossible to have a qualifier
  - INHERITED is an intermediate visibility, we enhance it later
    (see resolveUnknownVisibilityForMember)

 #KT-20356 Fixed
2018-06-26 15:39:32 +03:00
Yan Zhulanow
019e2212b8 Android Extensions, minor: Fix a compilation problem 2018-06-25 17:47:55 +03:00
Raluca Sauciuc
b135fd279d Android Extensions: make synthetic import resolution more resilient
In commit ec0abb0 (Fix EA-79206: Process only valid layout.xml...) we
started to drop layouts with invalid PsiFiles during resolution of
(synthetic) package fragments.

In Android Studio we run into invalid files quite often, and it seems
to be caused by a race with some invokeLater'ed code from android-ndk;
this has the side effect of now showing all the corresponding symbols
as unresolved, and the imports themselves are suggested for removal.

As a temporary fix I propose we try again to get a valid PsiFile.

Bug: https://issuetracker.google.com/78547457
(cherry picked from commit 3e8789225bd653caaedeca7f761a6442d48214b0)
2018-06-25 14:11:58 +03:00
Raluca Sauciuc
4e95d27f7b Recognize Instant Apps plugin
Tested with sample project and Studio 3.2 Canary 18:
https://github.com/googlesamples/android-instant-apps/tree/master/hello-kotlin

(cherry picked from commit 528d66d5840cc8f584270c516e85da1a632df8b8)
2018-06-25 14:11:58 +03:00
Yan Zhulanow
c9751c2eeb Revert "Android Extensions: Allow to access library project resources in Gradle setup (#KT-22430)"
This reverts commit a70707b
2018-06-25 14:11:58 +03:00
941 changed files with 22726 additions and 9230 deletions

4
.bunch
View File

@@ -3,4 +3,6 @@
172_173
as31_173
as32
182
182
as33_as32
as33c4_182

File diff suppressed because it is too large Load Diff

View File

@@ -35,9 +35,8 @@ class CacheVersion(
private val whenVersionChanged: CacheVersion.Action,
private val whenTurnedOn: CacheVersion.Action,
private val whenTurnedOff: CacheVersion.Action,
isEnabled: ()->Boolean
private val isEnabled: Boolean
) {
private val isEnabled by lazy(isEnabled)
private val actualVersion: Int?
get() = try {
@@ -95,18 +94,18 @@ class CacheVersion(
}
}
fun normalCacheVersion(dataRoot: File, enabled: Boolean? = null): CacheVersion =
fun normalCacheVersion(dataRoot: File, enabled: Boolean): CacheVersion =
CacheVersion(ownVersion = NORMAL_VERSION,
versionFile = File(dataRoot, NORMAL_VERSION_FILE_NAME),
whenVersionChanged = CacheVersion.Action.REBUILD_CHUNK,
whenTurnedOn = CacheVersion.Action.REBUILD_CHUNK,
whenTurnedOff = CacheVersion.Action.CLEAN_NORMAL_CACHES,
isEnabled = { enabled ?: IncrementalCompilation.isEnabled() })
isEnabled = enabled)
fun dataContainerCacheVersion(dataRoot: File, enabled: Boolean? = null): CacheVersion =
fun dataContainerCacheVersion(dataRoot: File, enabled: Boolean): CacheVersion =
CacheVersion(ownVersion = DATA_CONTAINER_VERSION,
versionFile = File(dataRoot, DATA_CONTAINER_VERSION_FILE_NAME),
whenVersionChanged = CacheVersion.Action.REBUILD_ALL_KOTLIN,
whenTurnedOn = CacheVersion.Action.REBUILD_ALL_KOTLIN,
whenTurnedOff = CacheVersion.Action.CLEAN_DATA_CONTAINER,
isEnabled = { enabled ?: IncrementalCompilation.isEnabled() })
isEnabled = enabled)

View File

@@ -23,6 +23,7 @@ import com.intellij.util.io.EnumeratorStringDescriptor
import gnu.trove.THashSet
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.build.GeneratedJvmClass
import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.incremental.storage.*
import org.jetbrains.kotlin.inline.inlineFunctionsJvmNames
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
@@ -264,7 +265,7 @@ open class IncrementalJvmCache(
override fun clean() {
super.clean()
normalCacheVersion(targetDataRoot).clean()
normalCacheVersion(targetDataRoot, IncrementalCompilation.isEnabledForJvm()).clean()
}
private inner class ProtoMap(storageFile: File) : BasicStringMap<ProtoMapValue>(storageFile, ProtoMapValueExternalizer) {

View File

@@ -78,7 +78,7 @@ class KotlinModuleXmlBuilder {
directoriesToFilterOut: Set<File>) {
p.println("<!-- Classpath -->")
for (file in files) {
val isOutput = directoriesToFilterOut.contains(file) && !IncrementalCompilation.isEnabled()
val isOutput = directoriesToFilterOut.contains(file) && !IncrementalCompilation.isEnabledForJvm()
if (isOutput) {
// For IDEA's make (incremental compilation) purposes, output directories of the current module and its dependencies
// appear on the class path, so we are at risk of seeing the results of the previous build, i.e. if some class was

View File

@@ -1,94 +0,0 @@
buildscript {
val buildSrcKotlinVersion: String by extra(findProperty("buildSrc.kotlin.version")?.toString() ?: embeddedKotlinVersion)
val buildSrcKotlinRepo: String? by extra(findProperty("buildSrc.kotlin.repo") as String?)
extra["versions.shadow"] = "2.0.2"
extra["versions.native-platform"] = "0.14"
repositories {
buildSrcKotlinRepo?.let {
maven(url = it)
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$buildSrcKotlinVersion")
classpath("org.jetbrains.kotlin:kotlin-sam-with-receiver:$buildSrcKotlinVersion")
}
}
logger.info("buildSrcKotlinVersion: " + extra["buildSrcKotlinVersion"])
logger.info("buildSrc kotlin compiler version: " + org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION)
logger.info("buildSrc stdlib version: " + KotlinVersion.CURRENT)
apply {
plugin("kotlin")
plugin("kotlin-sam-with-receiver")
}
plugins {
`kotlin-dsl`
`java-gradle-plugin`
}
gradlePlugin {
(plugins) {
"pill-configurable" {
id = "pill-configurable"
implementationClass = "org.jetbrains.kotlin.pill.PillConfigurablePlugin"
}
"jps-compatible" {
id = "jps-compatible"
implementationClass = "org.jetbrains.kotlin.pill.JpsCompatiblePlugin"
}
}
}
fun Project.getBooleanProperty(name: String): Boolean? = this.findProperty(name)?.let {
val v = it.toString()
if (v.isBlank()) true
else v.toBoolean()
}
rootProject.apply {
from(rootProject.file("../versions.gradle.kts"))
}
val isTeamcityBuild = project.hasProperty("teamcity") || System.getenv("TEAMCITY_VERSION") != null
val intellijUltimateEnabled by extra(project.getBooleanProperty("intellijUltimateEnabled") ?: isTeamcityBuild)
val intellijSeparateSdks by extra(project.getBooleanProperty("intellijSeparateSdks") ?: false)
extra["intellijRepo"] = "https://www.jetbrains.com/intellij-repository"
extra["intellijReleaseType"] = "snapshots" // or "snapshots"
extra["versions.androidDxSources"] = "5.0.0_r2"
extra["customDepsOrg"] = "kotlin.build.custom.deps"
repositories {
extra["buildSrcKotlinRepo"]?.let {
maven(url = it)
}
maven(url = "https://repo.gradle.org/gradle/ext-releases-local") // for native-platform
jcenter()
}
dependencies {
compile("net.rubygrapefruit:native-platform:${property("versions.native-platform")}")
compile("net.rubygrapefruit:native-platform-windows-amd64:${property("versions.native-platform")}")
compile("net.rubygrapefruit:native-platform-windows-i386:${property("versions.native-platform")}")
compile("com.jakewharton.dex:dex-method-list:3.0.0")
// TODO: adding the dep to the plugin breaks the build unexpectedly, resolve and uncomment
// compile("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["bootstrap_kotlin_version"]}")
// Shadow plugin is used in many projects of the main build. Once it's no longer used in buildSrc, please move this dependency to the root project
compile("com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}")
compile("org.ow2.asm:asm-all:6.0_BETA")
}
samWithReceiver {
annotation("org.gradle.api.HasImplicitReceiver")
}
fun Project.`samWithReceiver`(configure: org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverExtension.() -> Unit): Unit =
extensions.configure("samWithReceiver", configure)
tasks["build"].dependsOn(":prepare-deps:android-dx:build", ":prepare-deps:intellij-sdk:build")

View File

@@ -0,0 +1,9 @@
org.gradle.daemon=true
org.gradle.parallel=false
org.gradle.configureondemand=false
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx1600m
#buildSrc.kotlin.repo=https://jcenter.bintray.com
#buildSrc.kotlin.version=1.1.50
intellijUltimateEnabled=false

View File

@@ -0,0 +1,298 @@
@file:Suppress("PropertyName")
import org.gradle.api.publish.ivy.internal.artifact.DefaultIvyArtifact
import org.gradle.api.publish.ivy.internal.publication.DefaultIvyConfiguration
import org.gradle.api.publish.ivy.internal.publication.DefaultIvyPublicationIdentity
import org.gradle.api.publish.ivy.internal.publisher.IvyDescriptorFileGenerator
import java.io.File
import org.gradle.internal.os.OperatingSystem
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}")
}
}
val intellijUltimateEnabled: Boolean by rootProject.extra
val intellijRepo: String by rootProject.extra
val intellijReleaseType: String by rootProject.extra
val intellijVersion = rootProject.extra["versions.intellijSdk"] as String
val androidStudioRelease = rootProject.findProperty("versions.androidStudioRelease") as String?
val androidStudioBuild = rootProject.findProperty("versions.androidStudioBuild") as String?
val intellijSeparateSdks: Boolean by rootProject.extra
val installIntellijCommunity = !intellijUltimateEnabled || intellijSeparateSdks
val installIntellijUltimate = intellijUltimateEnabled
val intellijVersionDelimiterIndex = intellijVersion.indexOfAny(charArrayOf('.', '-'))
if (intellijVersionDelimiterIndex == -1) {
error("Invalid IDEA version $intellijVersion")
}
val platformBaseVersion = intellijVersion.substring(0, intellijVersionDelimiterIndex)
logger.info("intellijUltimateEnabled: $intellijUltimateEnabled")
logger.info("intellijVersion: $intellijVersion")
logger.info("androidStudioRelease: $androidStudioRelease")
logger.info("androidStudioBuild: $androidStudioBuild")
logger.info("intellijSeparateSdks: $intellijSeparateSdks")
logger.info("installIntellijCommunity: $installIntellijCommunity")
logger.info("installIntellijUltimate: $installIntellijUltimate")
val studioOs by lazy {
when {
OperatingSystem.current().isWindows -> "windows"
OperatingSystem.current().isMacOsX -> "mac"
OperatingSystem.current().isLinux -> "linux"
else -> {
logger.error("Unknown operating system for android tools: ${OperatingSystem.current().name}")
""
}
}
}
repositories {
if (androidStudioRelease != null) {
ivy {
artifactPattern("https://dl.google.com/dl/android/studio/ide-zips/$androidStudioRelease/[artifact]-[revision]-$studioOs.zip")
metadataSources {
artifact()
}
}
ivy {
artifactPattern("https://dl.bintray.com/kotlin/as/[artifact]-[revision].zip")
credentials {
username = System.getenv("AS_BINTRAY_USER_NAME")
password = System.getenv("AS_BINTRAY_API_KEY")
}
metadataSources {
artifact()
}
}
}
maven { setUrl("$intellijRepo/$intellijReleaseType") }
maven { setUrl("https://plugins.jetbrains.com/maven") }
// github returns broken pipe =(
// ivy {
// artifactPattern("https://raw.github.com/JetBrains/intellij-community/[revision]/lib/src/[artifact].zip")
// metadataSources {
// artifact()
// }
// }
}
val intellij by configurations.creating
val intellijUltimate by configurations.creating
val sources by configurations.creating
val `asm-shaded-sources` by configurations.creating
val `jps-standalone` by configurations.creating
val `jps-build-test` by configurations.creating
val `intellij-core` by configurations.creating
val `plugins-NodeJS` by configurations.creating
val customDepsRepoDir = File(buildDir, "repo")
val customDepsOrg: String by rootProject.extra
val customDepsRevision = intellijVersion
val customDepsRepoModulesDir = File(customDepsRepoDir, "$customDepsOrg/$customDepsRevision")
val repoDir = customDepsRepoModulesDir
dependencies {
if (androidStudioRelease != null) {
intellij("google:android-studio-ide:$androidStudioBuild")
} else {
if (installIntellijCommunity) {
intellij("com.jetbrains.intellij.idea:ideaIC:$intellijVersion")
}
if (installIntellijUltimate) {
intellijUltimate("com.jetbrains.intellij.idea:ideaIU:$intellijVersion")
}
}
sources("com.jetbrains.intellij.idea:ideaIC:$intellijVersion:sources@jar")
// if (platformBaseVersion == "182") {
// // There is no asm sources for 182 yet
// `asm-shaded-sources`("asmsources:asm-src:181@zip")
// } else {
// `asm-shaded-sources`("asmsources:asm-src:$platformBaseVersion@zip")
// }
`jps-standalone`("com.jetbrains.intellij.idea:jps-standalone:$intellijVersion")
`jps-build-test`("com.jetbrains.intellij.idea:jps-build-test:$intellijVersion")
`intellij-core`("com.jetbrains.intellij.idea:intellij-core:$intellijVersion")
if (intellijUltimateEnabled) {
`plugins-NodeJS`("com.jetbrains.plugins:NodeJS:${rootProject.extra["versions.idea.NodeJS"]}@zip")
}
}
fun Task.configureExtractFromConfigurationTask(sourceConfig: Configuration,
pathRemap: (String) -> String = { it },
extractor: (Configuration) -> Any) {
dependsOn(sourceConfig)
inputs.files(sourceConfig)
val targetDir = File(repoDir, sourceConfig.name)
outputs.dirs(targetDir)
doFirst {
project.copy {
from(extractor(sourceConfig))
into(targetDir)
eachFile {
path = pathRemap(path)
}
}
}
}
fun removePathPrefix(path: String): String {
if (androidStudioRelease == null) return path
val slashes = 2 // if (studioOs == "mac") 2 else 1
var result = path
repeat(slashes) {
result = result.substringAfter('/')
}
return result
}
val unzipIntellijSdk by tasks.creating {
configureExtractFromConfigurationTask(intellij, pathRemap = { removePathPrefix(it) }) {
zipTree(it.singleFile).matching {
exclude("**/plugins/Kotlin/**")
}
}
}
val unzipIntellijUltimateSdk by tasks.creating {
configureExtractFromConfigurationTask(intellijUltimate) {
zipTree(it.singleFile).matching {
exclude("plugins/Kotlin/**")
}
}
}
val unzipIntellijCore by tasks.creating { configureExtractFromConfigurationTask(`intellij-core`) { zipTree(it.singleFile) } }
val unzipJpsStandalone by tasks.creating { configureExtractFromConfigurationTask(`jps-standalone`) { zipTree(it.singleFile) } }
//val copyAsmShadedSources by tasks.creating(Copy::class.java) {
// from(`asm-shaded-sources`)
// rename(".zip", ".jar")
// destinationDir = File(repoDir, `asm-shaded-sources`.name)
//}
val copyIntellijSdkSources by tasks.creating(ShadowJar::class.java) {
// from(copyAsmShadedSources)
from(sources)
baseName = "ideaIC"
version = intellijVersion
classifier = "sources"
destinationDir = File(repoDir, sources.name)
}
val copyJpsBuildTest by tasks.creating { configureExtractFromConfigurationTask(`jps-build-test`) { it.singleFile } }
val unzipNodeJSPlugin by tasks.creating { configureExtractFromConfigurationTask(`plugins-NodeJS`) { zipTree(it.singleFile) } }
fun writeIvyXml(moduleName: String, fileName: String, jarFiles: FileCollection, baseDir: File, sourcesJar: File?) {
with(IvyDescriptorFileGenerator(DefaultIvyPublicationIdentity(customDepsOrg, moduleName, intellijVersion))) {
addConfiguration(DefaultIvyConfiguration("default"))
addConfiguration(DefaultIvyConfiguration("sources"))
jarFiles.asFileTree.files.forEach {
if (it.isFile && it.extension == "jar") {
val relativeName = it.toRelativeString(baseDir).removeSuffix(".jar")
addArtifact(DefaultIvyArtifact(it, relativeName, "jar", "jar", null).also { it.conf = "default" })
}
}
if (sourcesJar != null) {
val sourcesArtifactName = sourcesJar.name.removeSuffix(".jar").substringBefore("-")
addArtifact(DefaultIvyArtifact(sourcesJar, sourcesArtifactName, "jar", "sources", "sources").also { it.conf = "sources" })
}
writeTo(File(customDepsRepoModulesDir, "$fileName.ivy.xml"))
}
}
val prepareIvyXmls by tasks.creating {
dependsOn(unzipIntellijCore, unzipJpsStandalone, copyIntellijSdkSources, copyJpsBuildTest/*, copyAsmShadedSources */)
val intellijSdkDir = File(repoDir, intellij.name)
val intellijUltimateSdkDir = File(repoDir, intellijUltimate.name)
if (installIntellijCommunity) {
dependsOn(unzipIntellijSdk)
inputs.dir(intellijSdkDir)
outputs.file(File(repoDir, "${intellij.name}.ivy.xml"))
}
if (installIntellijUltimate) {
dependsOn(unzipIntellijUltimateSdk)
inputs.dir(intellijUltimateSdkDir)
outputs.file(File(repoDir, "${intellijUltimate.name}.ivy.xml"))
}
val flatDeps = listOf(`intellij-core`, `jps-standalone`, `jps-build-test`, `asm-shaded-sources`)
flatDeps.forEach {
inputs.dir(File(repoDir, it.name))
outputs.file(File(repoDir, "${it.name}.ivy.xml"))
}
inputs.dir(File(repoDir, sources.name))
if (intellijUltimateEnabled) {
dependsOn(unzipNodeJSPlugin)
inputs.dir(File(repoDir, `plugins-NodeJS`.name))
outputs.file(File(repoDir, "${`plugins-NodeJS`.name}.ivy.xml"))
}
doFirst {
val sourcesFile = if (sources.isEmpty) null else File(repoDir, "${sources.name}/${sources.singleFile.name}")
if (installIntellijCommunity) {
val libDir = File(intellijSdkDir, "lib")
writeIvyXml(intellij.name,
intellij.name,
fileTree(libDir).filter {
it.parentFile == libDir && !it.name.startsWith("kotlin-")
},
libDir,
sourcesFile)
File(intellijSdkDir, "plugins").listFiles { it: File -> it.isDirectory }.forEach {
writeIvyXml(it.name, "intellij.plugin.${it.name}", files("$it/lib/"), File(it, "lib"), sourcesFile)
}
}
if (installIntellijUltimate) {
val libDir = File(intellijUltimateSdkDir, "lib")
writeIvyXml(intellij.name, // important! the module name should be "intellij"
intellijUltimate.name,
fileTree(libDir).filter {
it.parentFile == libDir && !it.name.startsWith("kotlin-")
},
libDir,
sourcesFile)
File(intellijUltimateSdkDir, "plugins").listFiles { it: File -> it.isDirectory }.forEach {
writeIvyXml(it.name, "intellijUltimate.plugin.${it.name}", files("$it/lib/"), File(it, "lib"), sourcesFile)
}
}
flatDeps.forEach {
writeIvyXml(it.name, it.name, files("$repoDir/${it.name}"), File(repoDir, it.name), sourcesFile)
}
if (intellijUltimateEnabled) {
val nodeJsBaseDir = "${`plugins-NodeJS`.name}/NodeJS/lib"
writeIvyXml("NodeJS", `plugins-NodeJS`.name, files("$repoDir/$nodeJsBaseDir"), File(repoDir, nodeJsBaseDir), sourcesFile)
}
}
}
val build by tasks.creating {
dependsOn(prepareIvyXmls)
}
val clean by tasks.creating(Delete::class) {
delete(customDepsRepoModulesDir)
delete(buildDir)
}

View File

@@ -97,13 +97,16 @@ class JpsCompatiblePlugin : Plugin<Project> {
private lateinit var platformVersion: String
private lateinit var platformBaseNumber: String
private lateinit var platformDir: File
private var isAndroidStudioPlatform: Boolean = false
private fun initEnvironment(project: Project) {
projectDir = project.projectDir
platformVersion = project.extensions.extraProperties.get("versions.intellijSdk").toString()
platformBaseNumber = platformVersion.substringBefore(".", "").takeIf { it.isNotEmpty() }
?: error("Invalid platform version: $platformVersion")
?: platformVersion.substringBefore("-", "").takeIf { it.isNotEmpty() }
?: error("Invalid platform version: $platformVersion")
platformDir = IntellijRootUtils.getIntellijRootDir(project)
isAndroidStudioPlatform = project.extensions.extraProperties.has("versions.androidStudioRelease")
}
private fun pill(rootProject: Project) {
@@ -165,12 +168,19 @@ class JpsCompatiblePlugin : Plugin<Project> {
val runConfigurationsDir = File(projectDir, "buildSrc/src/main/resources/runConfigurations")
val targetDir = File(projectDir, ".idea/runConfigurations")
val platformDirProjectRelative = "\$PROJECT_DIR\$/" + platformDir.toRelativeString(projectDir)
val additionalIdeaArgs = if (isAndroidStudioPlatform) "-Didea.platform.prefix=AndroidStudio" else ""
targetDir.mkdirs()
fun substitute(text: String): String {
return text
.replace("\$IDEA_HOME_PATH\$", platformDirProjectRelative)
.replace("\$ADDITIONAL_IDEA_ARGS\$", additionalIdeaArgs)
}
runConfigurationsDir.listFiles()
.filter { it.extension == "xml" }
.map { it.name to it.readText().replace("\$IDEA_HOME_PATH\$", platformDirProjectRelative) }
.map { it.name to substitute(it.readText()) }
.forEach { File(targetDir, it.first).writeText(it.second) }
}

View File

@@ -3,7 +3,7 @@
<log_file alias="idea.log" path="$PROJECT_DIR$/ideaSDK/system-idea/log/idea.log" />
<option name="MAIN_CLASS_NAME" value="com.intellij.idea.Main" />
<module name="idea-runner" />
<option name="VM_PARAMETERS" value="-Xmx1250m -XX:ReservedCodeCacheSize=240m -XX:+HeapDumpOnOutOfMemoryError -ea -Didea.is.internal=true -Didea.debug.mode=true -Didea.system.path=$PROJECT_DIR$/local/ideaSandbox -Didea.config.path=$PROJECT_DIR$/local/ideaSandbox/config -Dapple.laf.useScreenMenuBar=true -Dapple.awt.graphics.UseQuartz=true -Dsun.io.useCanonCaches=false -Dplugin.path=$PROJECT_DIR$/out/artifacts/Kotlin -Dkotlin.internal.mode.enabled=true" />
<option name="VM_PARAMETERS" value="-Xmx1250m -XX:ReservedCodeCacheSize=240m -XX:+HeapDumpOnOutOfMemoryError -ea -Didea.is.internal=true -Didea.debug.mode=true -Didea.system.path=$PROJECT_DIR$/local/ideaSandbox -Didea.config.path=$PROJECT_DIR$/local/ideaSandbox/config -Dapple.laf.useScreenMenuBar=true -Dapple.awt.graphics.UseQuartz=true -Dsun.io.useCanonCaches=false -Dplugin.path=$PROJECT_DIR$/out/artifacts/Kotlin -Dkotlin.internal.mode.enabled=true $ADDITIONAL_IDEA_ARGS$" />
<option name="WORKING_DIRECTORY" value="file://$IDEA_HOME_PATH$" />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="" />

View File

@@ -3,7 +3,7 @@
<log_file alias="idea.log" path="$PROJECT_DIR$/ideaSDK/system-idea/log/idea.log" />
<option name="MAIN_CLASS_NAME" value="com.intellij.idea.Main" />
<module name="idea-runner" />
<option name="VM_PARAMETERS" value="-Xmx1250m -XX:ReservedCodeCacheSize=240m -XX:+HeapDumpOnOutOfMemoryError -ea -Didea.is.internal=true -Didea.debug.mode=true -Didea.system.path=$PROJECT_DIR$/local/ideaSandbox -Didea.config.path=$PROJECT_DIR$/local/ideaSandbox/config -Dapple.laf.useScreenMenuBar=true -Dapple.awt.graphics.UseQuartz=true -Dsun.io.useCanonCaches=false -Dplugin.path=$PROJECT_DIR$/out/artifacts/Kotlin -Dkotlin.internal.mode.enabled=true -Didea.ProcessCanceledException=disabled" />
<option name="VM_PARAMETERS" value="-Xmx1250m -XX:ReservedCodeCacheSize=240m -XX:+HeapDumpOnOutOfMemoryError -ea -Didea.is.internal=true -Didea.debug.mode=true -Didea.system.path=$PROJECT_DIR$/local/ideaSandbox -Didea.config.path=$PROJECT_DIR$/local/ideaSandbox/config -Dapple.laf.useScreenMenuBar=true -Dapple.awt.graphics.UseQuartz=true -Dsun.io.useCanonCaches=false -Dplugin.path=$PROJECT_DIR$/out/artifacts/Kotlin -Dkotlin.internal.mode.enabled=true -Didea.ProcessCanceledException=disabled $ADDITIONAL_IDEA_ARGS$" />
<option name="WORKING_DIRECTORY" value="file://$IDEA_HOME_PATH$" />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="" />

View File

@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
import org.jetbrains.kotlin.resolve.multiplatform.ExpectedActualResolver
import org.jetbrains.kotlin.types.KotlinType
@@ -167,9 +168,24 @@ object CodegenUtil {
return KtPsiFactory(project, markGenerated = false).createExpression(fakeFunctionCall) as KtCallExpression
}
/**
* Returns declarations in the given [file] which should be generated by the back-end. This includes all declarations
* minus all expected declarations (except annotation classes annotated with @OptionalExpectation).
*/
@JvmStatic
fun getActualDeclarations(file: KtFile): List<KtDeclaration> =
file.declarations.filterNot(KtDeclaration::hasExpectModifier)
fun getDeclarationsToGenerate(file: KtFile, bindingContext: BindingContext): List<KtDeclaration> =
file.declarations.filter(fun(declaration: KtDeclaration): Boolean {
if (!declaration.hasExpectModifier()) return true
if (declaration is KtClass) {
val descriptor = bindingContext.get(BindingContext.CLASS, declaration)
if (descriptor != null && ExpectedActualDeclarationChecker.shouldGenerateExpectClass(descriptor)) {
return true
}
}
return false
})
@JvmStatic
fun findExpectedFunctionForActual(descriptor: FunctionDescriptor): FunctionDescriptor? {

View File

@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.AnnotationChecker;
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker;
import org.jetbrains.kotlin.resolve.constants.*;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.types.FlexibleType;
@@ -300,7 +301,10 @@ public abstract class AnnotationCodegen {
return null;
}
if (classDescriptor.isExpect()) {
// We do not generate annotations whose classes are optional (annotated with `@OptionalExpectation`) because if an annotation entry
// is resolved to the expected declaration, this means that annotation has no actual class, and thus should not be generated.
// (Otherwise we would've resolved the entry to the actual annotation class.)
if (ExpectedActualDeclarationChecker.isOptionalAnnotationClass(classDescriptor)) {
return null;
}

View File

@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt;
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker;
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType;
@@ -278,6 +279,9 @@ public class AsmUtil {
if (descriptor instanceof SyntheticClassDescriptorForLambda) {
return getVisibilityAccessFlagForAnonymous(descriptor);
}
if (ExpectedActualDeclarationChecker.isOptionalAnnotationClass(descriptor)) {
return NO_FLAG_PACKAGE_PRIVATE;
}
if (descriptor.getVisibility() == Visibilities.PUBLIC ||
descriptor.getVisibility() == Visibilities.PROTECTED ||
// TODO: should be package private, but for now Kotlin's reflection can't access members of such classes

View File

@@ -62,7 +62,7 @@ public class ClassFileFactory implements OutputFileCollection {
private boolean isDone = false;
private final Set<File> packagePartSourceFiles = new HashSet<>();
private final Set<File> sourceFiles = new HashSet<>();
private final Map<String, PackageParts> partsGroupedByPackage = new LinkedHashMap<>();
public ClassFileFactory(@NotNull GenerationState state, @NotNull ClassBuilderFactory builderFactory) {
@@ -121,9 +121,8 @@ public class ClassFileFactory implements OutputFileCollection {
}
JvmModuleProtoBuf.Module moduleProto = builder.build();
if (moduleProto.getSerializedSize() == 0) return;
generators.put(outputFilePath, new OutAndSourceFileList(CollectionsKt.toList(packagePartSourceFiles)) {
generators.put(outputFilePath, new OutAndSourceFileList(CollectionsKt.toList(sourceFiles)) {
@Override
public byte[] asBytes(ClassBuilderFactory factory) {
return ModuleMappingKt.serializeToByteArray(moduleProto, JvmMetadataVersion.INSTANCE.toArray());
@@ -227,14 +226,14 @@ public class ClassFileFactory implements OutputFileCollection {
@NotNull
public PackageCodegen forPackage(@NotNull FqName fqName, @NotNull Collection<KtFile> files) {
assert !isDone : "Already done!";
registerPackagePartSourceFiles(files);
registerSourceFiles(files);
return state.getCodegenFactory().createPackageCodegen(state, files, fqName, buildNewPackagePartRegistry(fqName));
}
@NotNull
public MultifileClassCodegen forMultifileClass(@NotNull FqName facadeFqName, @NotNull Collection<KtFile> files) {
assert !isDone : "Already done!";
registerPackagePartSourceFiles(files);
registerSourceFiles(files);
return state.getCodegenFactory().createMultifileClassCodegen(state, files, facadeFqName, buildNewPackagePartRegistry(facadeFqName.parent()));
}
@@ -246,8 +245,8 @@ public class ClassFileFactory implements OutputFileCollection {
};
}
private void registerPackagePartSourceFiles(Collection<KtFile> files) {
packagePartSourceFiles.addAll(toIoFilesIgnoringNonPhysical(PackagePartClassUtils.getFilesWithCallables(files)));
private void registerSourceFiles(Collection<KtFile> files) {
sourceFiles.addAll(toIoFilesIgnoringNonPhysical(files));
}
@NotNull

View File

@@ -16,17 +16,42 @@
package org.jetbrains.kotlin.codegen;
import kotlin.collections.CollectionsKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.backend.common.output.OutputFile;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.Base64;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.Manifest;
public class GeneratedClassLoader extends URLClassLoader {
private static final URLStreamHandler FAKE_BASE64_URL_HANDLER = new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL url) {
return new URLConnection(url) {
@Override
public void connect() {
}
@Override
public InputStream getInputStream() {
return new ByteArrayInputStream(Base64.getDecoder().decode(url.getPath()));
}
};
}
};
private ClassFileFactory factory;
public GeneratedClassLoader(@NotNull ClassFileFactory factory, ClassLoader parentClassLoader, URL... urls) {
@@ -43,6 +68,39 @@ public class GeneratedClassLoader extends URLClassLoader {
return super.getResourceAsStream(name);
}
@Override
public Enumeration<URL> findResources(String name) throws IOException {
Enumeration<URL> fromParent = super.findResources(name);
URL url = createFakeURLForResource(name);
if (url == null) return fromParent;
List<URL> fromMe = Collections.singletonList(url);
List<URL> result = fromParent.hasMoreElements()
? CollectionsKt.plus(fromMe, Collections.list(fromParent))
: fromMe;
return Collections.enumeration(result);
}
@Override
public URL findResource(String name) {
URL url = createFakeURLForResource(name);
return url != null ? url : super.findResource(name);
}
@Nullable
private URL createFakeURLForResource(@NotNull String name) {
try {
OutputFile outputFile = factory.get(name);
// Encode the byte array in the URL path to prevent creating unneeded temporary files
return outputFile == null
? null
: new URL(null, "bytes:" + Base64.getEncoder().encodeToString(outputFile.asByteArray()), FAKE_BASE64_URL_HANDLER);
} catch (IOException e) {
throw ExceptionUtilsKt.rethrow(e);
}
}
@NotNull
@Override
protected Class<?> findClass(@NotNull String name) throws ClassNotFoundException {

View File

@@ -85,7 +85,7 @@ class MultifileClassCodegenImpl(
private val partInternalNamesSorted = run {
val partInternalNamesSet = hashSetOf<String>()
for (file in files) {
if (file.hasDeclarationsForPartClass()) {
if (file.hasDeclarationsForPartClass(state.bindingContext)) {
partInternalNamesSet.add(JvmFileClassUtil.getFileClassInternalName(file))
}
}
@@ -122,7 +122,7 @@ class MultifileClassCodegenImpl(
val singleSourceFile =
if (previouslyCompiledCallables.isEmpty())
files.singleOrNull { it.hasDeclarationsForPartClass() }
files.singleOrNull { it.hasDeclarationsForPartClass(state.bindingContext) }
else
null
@@ -209,7 +209,9 @@ class MultifileClassCodegenImpl(
generateNonPartClassDeclarations(file, partContext)
if (!state.generateDeclaredClassFilter.shouldGeneratePackagePart(file) || !file.hasDeclarationsForPartClass()) return
if (!state.generateDeclaredClassFilter.shouldGeneratePackagePart(file) ||
!file.hasDeclarationsForPartClass(state.bindingContext)
) return
packagePartRegistry.addPart(partType.internalName, facadeClassType.internalName)
@@ -243,7 +245,7 @@ class MultifileClassCodegenImpl(
private fun addDelegateGenerationTasksForDeclarationsInFile(file: KtFile, packageFragment: PackageFragmentDescriptor, partType: Type) {
val facadeContext = state.rootContext.intoMultifileClass(packageFragment, facadeClassType, partType)
val memberCodegen = createCodegenForDelegatesInMultifileFacade(facadeContext)
for (declaration in CodegenUtil.getActualDeclarations(file)) {
for (declaration in CodegenUtil.getDeclarationsToGenerate(file, state.bindingContext)) {
if (declaration is KtNamedFunction || declaration is KtProperty || declaration is KtTypeAlias) {
val descriptor = state.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
if (descriptor !is MemberDescriptor) {
@@ -375,13 +377,13 @@ class MultifileClassCodegenImpl(
return fragments.firstOrNull()
}
private fun KtFile.hasDeclarationsForPartClass() =
CodegenUtil.getActualDeclarations(this).any { it is KtProperty || it is KtFunction || it is KtTypeAlias }
private fun KtFile.hasDeclarationsForPartClass(bindingContext: BindingContext) =
CodegenUtil.getDeclarationsToGenerate(this, bindingContext).any { it is KtProperty || it is KtFunction || it is KtTypeAlias }
private fun getCompiledPackageFragment(
facadeFqName: FqName, state: GenerationState
): IncrementalPackageFragmentProvider.IncrementalMultifileClassPackageFragment? {
if (!IncrementalCompilation.isEnabled()) return null
if (!IncrementalCompilation.isEnabledForJvm()) return null
val packageFqName = facadeFqName.parent()

View File

@@ -132,7 +132,7 @@ class MultifileClassPartCodegen(
}
override fun generateBody() {
for (declaration in CodegenUtil.getActualDeclarations(element)) {
for (declaration in CodegenUtil.getDeclarationsToGenerate(element, state.bindingContext)) {
if (declaration is KtNamedFunction || declaration is KtProperty || declaration is KtTypeAlias) {
genSimpleMember(declaration)
}

View File

@@ -98,7 +98,7 @@ public class PackageCodegenImpl implements PackageCodegen {
List<KtClassOrObject> classOrObjects = new ArrayList<>();
for (KtDeclaration declaration : CodegenUtil.getActualDeclarations(file)) {
for (KtDeclaration declaration : CodegenUtil.getDeclarationsToGenerate(file, state.getBindingContext())) {
if (isFilePartDeclaration(declaration)) {
generatePackagePart = true;
}

View File

@@ -90,7 +90,7 @@ public class PackagePartCodegen extends MemberCodegen<KtFile> {
@Override
protected void generateBody() {
for (KtDeclaration declaration : CodegenUtil.getActualDeclarations(element)) {
for (KtDeclaration declaration : CodegenUtil.getDeclarationsToGenerate(element, state.getBindingContext())) {
if (declaration instanceof KtNamedFunction || declaration instanceof KtProperty || declaration instanceof KtTypeAlias) {
genSimpleMember(declaration);
}
@@ -123,7 +123,8 @@ public class PackagePartCodegen extends MemberCodegen<KtFile> {
@NotNull Type packagePartType
) {
BindingContext bindingContext = codegen.bindingContext;
List<DeclarationDescriptor> members = CollectionsKt.mapNotNull(CodegenUtil.getActualDeclarations(codegen.element), declaration -> {
List<KtDeclaration> allDeclarations = CodegenUtil.getDeclarationsToGenerate(codegen.element, bindingContext);
List<DeclarationDescriptor> members = CollectionsKt.mapNotNull(allDeclarations, declaration -> {
if (declaration instanceof KtNamedFunction) {
return bindingContext.get(BindingContext.FUNCTION, declaration);
}

View File

@@ -16,7 +16,8 @@
package org.jetbrains.kotlin.codegen
import org.jetbrains.annotations.NotNull
import org.jetbrains.kotlin.codegen.context.CodegenContext
import org.jetbrains.kotlin.codegen.context.InlineLambdaContext
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.psi.KtFile
@@ -35,9 +36,19 @@ class SamWrapperClasses(private val state: GenerationState) {
expressionCodegen: ExpressionCodegen,
contextDescriptor: CallableMemberDescriptor
): Type {
val isInsideInline = InlineUtil.isInlineOrContainingInline(expressionCodegen.context.contextDescriptor)
val isInsideInline = InlineUtil.isInlineOrContainingInline(expressionCodegen.context.contextDescriptor) ||
isInsideInlineLambdaContext(expressionCodegen.context, state)
return samInterfaceToWrapperClass.getOrPut(WrapperKey(samType, file, isInsideInline)) {
SamWrapperCodegen(state, samType, expressionCodegen.parentCodegen, isInsideInline).genWrapper(file, contextDescriptor)
}
}
private fun isInsideInlineLambdaContext(context: CodegenContext<*>, state: GenerationState):Boolean {
var parent: CodegenContext<*>? = context
while (parent != null && parent != state.rootContext) {
if (parent is InlineLambdaContext) return true
parent = parent.parentContext
}
return false
}
}

View File

@@ -193,8 +193,10 @@ public class SamWrapperCodegen {
@NotNull KtFile containingFile,
CallableMemberDescriptor contextDescriptor
) {
boolean hasPackagePartClass =
CollectionsKt.any(CodegenUtil.getActualDeclarations(containingFile), PackageCodegenImpl::isFilePartDeclaration);
boolean hasPackagePartClass = CollectionsKt.any(
CodegenUtil.getDeclarationsToGenerate(containingFile, state.getBindingContext()),
PackageCodegenImpl::isFilePartDeclaration
);
FqName filePartFqName = JvmFileClassUtil.getFileClassInfoNoResolve(containingFile).getFileClassFqName();
FqName outermostOwner;

View File

@@ -44,6 +44,7 @@ class ScriptCodegen private constructor(
typeMapper.mapSupertype(scriptDescriptor.getSuperClassOrAny().defaultType, null).internalName,
mapSupertypesNames(typeMapper, scriptDescriptor.getSuperInterfaces(), null)
)
AnnotationCodegen.forClass(v.visitor, this, typeMapper).genAnnotations(scriptDescriptor, null)
}
override fun generateBody() {
@@ -75,10 +76,9 @@ class ScriptCodegen private constructor(
val jvmSignature = typeMapper.mapScriptSignature(
scriptDescriptor,
scriptContext.earlierScripts,
scriptDefinition.implicitReceivers,
scriptDefinition.environmentVariables
scriptContext.earlierScripts
)
val asmMethod = jvmSignature.asmMethod
if (state.replSpecific.shouldGenerateScriptResultValue) {
val resultFieldInfo = scriptContext.resultFieldInfo
@@ -94,6 +94,8 @@ class ScriptCodegen private constructor(
OtherOrigin(scriptDeclaration, scriptDescriptor.unsubstitutedPrimaryConstructor),
ACC_PUBLIC, jvmSignature.asmMethod.name, jvmSignature.asmMethod.descriptor, null, null)
FunctionCodegen.generateMethodAnnotations(scriptDescriptor.unsubstitutedPrimaryConstructor, asmMethod, mv, this, typeMapper)
if (state.classBuilderMode.generateBodies) {
mv.visitCode()
@@ -104,48 +106,15 @@ class ScriptCodegen private constructor(
val superclass = scriptDescriptor.getSuperClassNotAny()
// TODO: throw if class is not found)
if (superclass == null) {
iv.load(0, classType)
iv.invokespecial("java/lang/Object", "<init>", "()V", false)
}
else {
val ctorDesc = superclass.unsubstitutedPrimaryConstructor
?: throw RuntimeException("Primary constructor not found for script template " + superclass.toString())
iv.load(0, classType)
fun Int.incrementIf(cond: Boolean): Int = if (cond) plus(1) else this
val valueParamStart = 1
.incrementIf(scriptContext.earlierScripts.isNotEmpty())
.incrementIf(scriptDefinition.implicitReceivers.isNotEmpty())
.incrementIf(scriptDefinition.environmentVariables.isNotEmpty())
val valueParameters = scriptDescriptor.unsubstitutedPrimaryConstructor.valueParameters
for (superclassParam in ctorDesc.valueParameters) {
val valueParam = valueParameters.first { it.name == superclassParam.name }
iv.load(valueParam!!.index + valueParamStart, typeMapper.mapType(valueParam.type))
}
val ctorMethod = typeMapper.mapToCallableMethod(ctorDesc, false)
val sig = ctorMethod.getAsmMethod().descriptor
iv.invokespecial(
typeMapper.mapSupertype(superclass.defaultType, null).internalName,
"<init>", sig, false)
}
iv.load(0, classType)
val frameMap = FrameMap()
frameMap.enterTemp(OBJECT_TYPE)
fun genFieldFromArrayElement(descriptor: ClassDescriptor, paramIndex: Int, elementIndex: Int, name: String) {
val elementClassType = typeMapper.mapClass(descriptor)
iv.load(0, classType)
iv.load(paramIndex, elementClassType)
iv.aconst(elementIndex)
iv.aload(OBJECT_TYPE)
iv.checkcast(elementClassType)
iv.putfield(classType.internalName, name, elementClassType.descriptor)
val array = StackValue.local(paramIndex, AsmUtil.getArrayType(OBJECT_TYPE))
val value = StackValue.arrayElement(OBJECT_TYPE, null, array, StackValue.constant(elementIndex, Type.INT_TYPE))
val field = StackValue.field(elementClassType, classType, name, false, StackValue.local(0, classType))
field.store(value, iv)
}
if (!scriptContext.earlierScripts.isEmpty()) {
@@ -157,6 +126,37 @@ class ScriptCodegen private constructor(
}
}
if (superclass == null) {
iv.load(0, classType)
iv.invokespecial("java/lang/Object", "<init>", "()V", false)
} else {
val ctorDesc = superclass.unsubstitutedPrimaryConstructor
?: throw RuntimeException("Primary constructor not found for script template " + superclass.toString())
iv.load(0, classType)
fun Int.incrementIf(cond: Boolean): Int = if (cond) plus(1) else this
val valueParamStart = 1
.incrementIf(scriptContext.earlierScripts.isNotEmpty())
val valueParameters = scriptDescriptor.unsubstitutedPrimaryConstructor.valueParameters
for (superclassParam in ctorDesc.valueParameters) {
val valueParam = valueParameters.first { it.name == superclassParam.name }
val paramType = typeMapper.mapType(valueParam.type)
iv.load(valueParam!!.index + valueParamStart, paramType)
frameMap.enterTemp(paramType)
}
val ctorMethod = typeMapper.mapToCallableMethod(ctorDesc, false)
val sig = ctorMethod.getAsmMethod().descriptor
iv.invokespecial(
typeMapper.mapSupertype(superclass.defaultType, null).internalName,
"<init>", sig, false
)
}
iv.load(0, classType)
if (scriptDefinition.implicitReceivers.isNotEmpty()) {
val receiversParamIndex = frameMap.enterTemp(AsmUtil.getArrayType(OBJECT_TYPE))

View File

@@ -19,8 +19,8 @@ import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.codegen.topLevelClassAsmType
import org.jetbrains.kotlin.codegen.topLevelClassInternalName
import org.jetbrains.kotlin.coroutines.isSuspendLambda
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.coroutines.isSuspendLambda
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
@@ -240,7 +240,7 @@ fun <D : FunctionDescriptor> getOrCreateJvmSuspendFunctionView(
setReturnType(function.builtIns.nullableAnyType)
setValueParameters(it.valueParameters + continuationParameter)
if (dropSuspend) {
setDropSuspend()
setIsSuspend(false)
}
putUserData(INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION, it)
}
@@ -475,4 +475,4 @@ fun FunctionDescriptor.isSuspendLambdaOrLocalFunction() = this.isSuspend && when
is AnonymousFunctionDescriptor -> this.isSuspendLambda
is SimpleFunctionDescriptor -> this.visibility == Visibilities.LOCAL
else -> false
}
}

View File

@@ -1607,9 +1607,7 @@ public class KotlinTypeMapper {
@NotNull
public JvmMethodSignature mapScriptSignature(
@NotNull ScriptDescriptor script,
@NotNull List<ScriptDescriptor> importedScripts,
List<? extends KType> implicitReceivers,
List<? extends Pair<String, ? extends KType>> environmentVariables
@NotNull List<ScriptDescriptor> importedScripts
) {
JvmSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
@@ -1619,14 +1617,6 @@ public class KotlinTypeMapper {
writeParameter(sw, DescriptorUtilsKt.getModule(script).getBuiltIns().getArray().getDefaultType(), null);
}
if (implicitReceivers.size() > 0) {
writeParameter(sw, DescriptorUtilsKt.getModule(script).getBuiltIns().getArray().getDefaultType(), null);
}
if (environmentVariables.size() > 0) {
writeParameter(sw, DescriptorUtilsKt.getModule(script).getBuiltIns().getMap().getDefaultType(), null);
}
for (ValueParameterDescriptor valueParameter : script.getUnsubstitutedPrimaryConstructor().getValueParameters()) {
writeParameter(sw, valueParameter.getType(), /* callableDescriptor = */ null);
}

View File

@@ -37,19 +37,21 @@ class Jsr305Parser(private val collector: MessageCollector) {
item.startsWith("@") -> {
val (name, state) = parseJsr305UserDefined(item) ?: return@forEach
val current = userDefined[name]
if (current != null) {
if (current == null) {
userDefined[name] = state
} else if (current != state) {
reportDuplicateJsr305("@$name:${current.description}", item)
return@forEach
}
userDefined[name] = state
}
item.startsWith("under-migration") -> {
if (migration != null) {
val state = parseJsr305UnderMigration(item)
if (migration == null) {
migration = state
} else if (migration != state) {
reportDuplicateJsr305("under-migration:${migration?.description}", item)
return@forEach
}
migration = parseJsr305UnderMigration(item)
}
item == "enable" -> {
collector.report(
@@ -61,11 +63,12 @@ class Jsr305Parser(private val collector: MessageCollector) {
global = ReportLevel.STRICT
}
else -> {
if (global != null) {
if (global == null) {
global = ReportLevel.findByDescription(item)
} else if (global!!.description != item) {
reportDuplicateJsr305(global!!.description, item)
return@forEach
}
global = ReportLevel.findByDescription(item)
}
}
}

View File

@@ -50,7 +50,6 @@ import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
public abstract class CLICompiler<A extends CommonCompilerArguments> extends CLITool<A> {
public static String KOTLIN_HOME_PROPERTY = "kotlin.home";
public static String KOTLIN_HOME_ENV_VAR = "KOTLIN_HOME";
// Used in CompilerRunnerUtil#invokeExecMethod, in Eclipse plugin (KotlinCLICompiler) and in kotlin-gradle-plugin (GradleCompilerRunner)
@NotNull
@@ -165,16 +164,13 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> extends CLI
CommonConfigurationKeysKt.setLanguageVersionSettings(configuration, arguments.configureLanguageVersionSettings(collector));
}
private static final String kotlinHomeEnvVar = System.getenv(KOTLIN_HOME_ENV_VAR);
@Nullable
private static KotlinPaths computeKotlinPaths(@NotNull MessageCollector messageCollector, @NotNull CommonCompilerArguments arguments) {
KotlinPaths paths;
String kotlinHomeProperty = System.getProperty(KOTLIN_HOME_PROPERTY);
File kotlinHome =
arguments.getKotlinHome() != null ? new File(arguments.getKotlinHome()) :
kotlinHomeProperty != null ? new File(kotlinHomeProperty) :
kotlinHomeEnvVar != null ? new File(kotlinHomeEnvVar)
kotlinHomeProperty != null ? new File(kotlinHomeProperty)
: null;
if (kotlinHome != null) {
if (kotlinHome.isDirectory()) {

View File

@@ -135,7 +135,7 @@ abstract class CLITool<A : CommonToolArguments> {
"ATTENTION!\n" +
"This build uses internal compiler arguments:\n" +
arguments.internalArguments.joinToString(prefix = "\n", postfix = "\n\n", separator = "\n") +
"This mode is strictly prohibited for production use,\n" +
"This mode is not recommended for production use,\n" +
"as no stability/compatibility guarantees are given on\n" +
"compiler or generated code. Use it at your own risk!\n"
)

View File

@@ -68,7 +68,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
configuration.put(JVMConfigurationKeys.DISABLE_STANDARD_SCRIPT_DEFINITION, true)
}
val pluginLoadResult = loadPlugins(paths, arguments, configuration)
val pluginLoadResult = loadPlugins(arguments, configuration)
if (pluginLoadResult != ExitCode.OK) return pluginLoadResult
if (!arguments.script && arguments.buildFile == null) {
@@ -217,13 +217,13 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
override fun getPerformanceManager(): CommonCompilerPerformanceManager = performanceManager
private fun loadPlugins(paths: KotlinPaths?, arguments: K2JVMCompilerArguments, configuration: CompilerConfiguration): ExitCode {
private fun loadPlugins(arguments: K2JVMCompilerArguments, configuration: CompilerConfiguration): ExitCode {
var pluginClasspaths: Iterable<String> = arguments.pluginClasspaths?.asIterable() ?: emptyList()
val pluginOptions = arguments.pluginOptions?.toMutableList() ?: ArrayList()
if (!arguments.disableDefaultScriptingPlugin) {
val explicitOrLoadedScriptingPlugin =
pluginClasspaths.any { File(it).name == PathUtil.KOTLIN_SCRIPTING_COMPILER_PLUGIN_JAR } ||
pluginClasspaths.any { File(it).name.startsWith(PathUtil.KOTLIN_SCRIPTING_COMPILER_PLUGIN_NAME) } ||
try {
PluginCliParser::class.java.classLoader.loadClass("org.jetbrains.kotlin.extensions.ScriptingCompilerConfigurationExtension")
true
@@ -233,7 +233,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
// if scripting plugin is not enabled explicitly (probably from another path) and not in the classpath already,
// try to find and enable it implicitly
if (!explicitOrLoadedScriptingPlugin) {
val libPath = paths?.libPath?.takeIf { it.exists() } ?: File(".")
val libPath = PathUtil.kotlinPathsForCompiler.libPath.takeIf { it.exists() && it.isDirectory } ?: File(".")
with(PathUtil) {
val jars = arrayOf(
KOTLIN_SCRIPTING_COMPILER_PLUGIN_JAR, KOTLIN_SCRIPTING_COMMON_JAR,
@@ -302,7 +302,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
override fun setupPlatformSpecificArgumentsAndServices(
configuration: CompilerConfiguration, arguments: K2JVMCompilerArguments, services: Services
) {
if (IncrementalCompilation.isEnabled()) {
if (IncrementalCompilation.isEnabledForJvm()) {
services.get(LookupTracker::class.java)?.let {
configuration.put(CommonConfigurationKeys.LOOKUP_TRACKER, it)
}

View File

@@ -183,13 +183,20 @@ class KotlinCoreEnvironment private constructor(
JsSyntheticTranslateExtension.registerExtensionPoint(project)
CompilerConfigurationExtension.registerExtensionPoint(project)
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
for (registrar in configuration.getList(ComponentRegistrar.PLUGIN_COMPONENT_REGISTRARS)) {
try {
registrar.registerProjectComponents(project, configuration)
} catch (e: AbstractMethodError) {
throw IllegalStateException(
"The provided plugin ${registrar.javaClass.name} is not compatible with this version of compiler", e
)
val message = "The provided plugin ${registrar.javaClass.name} is not compatible with this version of compiler"
// Since the scripting plugin is often discovered in the compiler environment, it is often taken from the incompatible
// location, and in many cases this is not a fatal error, therefore strong warning is generated instead of exception
if (registrar.javaClass.simpleName == "ScriptingCompilerConfigurationComponentRegistrar") {
messageCollector?.report(STRONG_WARNING, "Default scripting plugin is disabled: $message")
} else {
throw IllegalStateException(message, e)
}
}
}
@@ -200,7 +207,6 @@ class KotlinCoreEnvironment private constructor(
registerProjectServicesForCLI(projectEnvironment)
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
registerProjectServices(projectEnvironment, messageCollector)
for (extension in CompilerConfigurationExtension.getInstances(project)) {
@@ -212,6 +218,13 @@ class KotlinCoreEnvironment private constructor(
}
sourceFiles.sortBy { it.virtualFile.path }
// If not disabled explicitly, we should always support at least the standard script definition
if (!configuration.getBoolean(JVMConfigurationKeys.DISABLE_STANDARD_SCRIPT_DEFINITION) &&
StandardScriptDefinition !in configuration.getList(JVMConfigurationKeys.SCRIPT_DEFINITIONS)
) {
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, StandardScriptDefinition)
}
val scriptDefinitionProvider = ScriptDefinitionProvider.getInstance(project) as? CliScriptDefinitionProvider
if (scriptDefinitionProvider != null) {
scriptDefinitionProvider.setScriptDefinitionsSources(configuration.getList(JVMConfigurationKeys.SCRIPT_DEFINITIONS_SOURCES))
@@ -416,12 +429,6 @@ class KotlinCoreEnvironment private constructor(
parentDisposable: Disposable, configuration: CompilerConfiguration, configFiles: EnvironmentConfigFiles
): KotlinCoreEnvironment {
setCompatibleBuild()
// If not disabled explicitly, we should always support at least the standard script definition
if (!configuration.getBoolean(JVMConfigurationKeys.DISABLE_STANDARD_SCRIPT_DEFINITION) &&
StandardScriptDefinition !in configuration.getList(JVMConfigurationKeys.SCRIPT_DEFINITIONS)
) {
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, StandardScriptDefinition)
}
val appEnv = getOrCreateApplicationEnvironmentForProduction(configuration)
// Disposing of the environment is unsafe in production then parallel builds are enabled, but turning it off universally
// breaks a lot of tests, therefore it is disabled for production and enabled for tests
@@ -458,12 +465,6 @@ class KotlinCoreEnvironment private constructor(
parentDisposable: Disposable, initialConfiguration: CompilerConfiguration, extensionConfigs: EnvironmentConfigFiles
): KotlinCoreEnvironment {
val configuration = initialConfiguration.copy()
// in tests we assume that standard definition should only be added if no other explicit defs are already added
if (!configuration.getBoolean(JVMConfigurationKeys.DISABLE_STANDARD_SCRIPT_DEFINITION) &&
configuration.getList(JVMConfigurationKeys.SCRIPT_DEFINITIONS).isEmpty()
) {
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, StandardScriptDefinition)
}
// Tests are supposed to create a single project and dispose it right after use
return KotlinCoreEnvironment(
parentDisposable,

View File

@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.cli.js.K2JSCompiler
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler
import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.daemon.report.CompileServicesFacadeMessageCollector
@@ -469,7 +470,7 @@ class CompileServiceImpl(
}
val workingDir = incrementalCompilationOptions.workingDir
val versions = commonCacheVersions(workingDir) +
val versions = commonCacheVersions(workingDir, enabled = true) +
customCacheVersion(incrementalCompilationOptions.customCacheVersion,
incrementalCompilationOptions.customCacheVersionFileName,
workingDir,
@@ -519,7 +520,7 @@ class CompileServiceImpl(
}
val workingDir = incrementalCompilationOptions.workingDir
val versions = commonCacheVersions(workingDir) +
val versions = commonCacheVersions(workingDir, enabled = true) +
customCacheVersion(incrementalCompilationOptions.customCacheVersion,
incrementalCompilationOptions.customCacheVersionFileName,
workingDir,

View File

@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.load.java.InternalFlexibleTypeTransformer
import org.jetbrains.kotlin.load.java.JavaClassFinderImpl
import org.jetbrains.kotlin.load.java.JavaClassesTracker
import org.jetbrains.kotlin.load.java.components.*
import org.jetbrains.kotlin.load.java.lazy.JavaResolverSettings
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver
import org.jetbrains.kotlin.load.kotlin.DeserializationComponentsForJava
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinderFactory
@@ -115,6 +116,9 @@ fun createContainerForLazyResolveWithJava(
}
useInstance(javaClassTracker ?: JavaClassesTracker.Default)
useInstance(
JavaResolverSettings.create(isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines))
)
targetEnvironment.configure(this)

View File

@@ -148,7 +148,7 @@ public class SingleAbstractMethodUtils {
// Otherwise android data binding can cause resolve re-entrance
// For details see KT-18687, KT-16149
// TODO: prevent resolve re-entrance on architecture level, or (alternatively) ask data binding owners not to do it
if (DescriptorUtilsKt.getFqNameSafe(klass).asString().equals("android.databinding.DataBindingComponent")) {
if (DescriptorUtilsKt.getFqNameSafe(klass).asString().endsWith(".databinding.DataBindingComponent")) {
return null;
}

View File

@@ -45,8 +45,8 @@ class JavaNullabilityChecker : AdditionalTypeChecker {
c.expectedType,
{ c.dataFlowValueFactory.createDataFlowValue(expression, expressionType, c) } ,
c.dataFlowInfo
) { expectedMustNotBeNull, actualMayBeNull ->
c.trace.report(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(expression, expectedMustNotBeNull, actualMayBeNull))
) { expectedType, actualType ->
c.trace.report(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(expression, expectedType, actualType))
}
when (expression) {
@@ -121,12 +121,15 @@ class JavaNullabilityChecker : AdditionalTypeChecker {
receiverParameter.type,
{ dataFlowValue },
c.dataFlowInfo
) { expectedMustNotBeNull,
actualMayBeNull ->
val reportOn = (receiverArgument as? ExpressionReceiver)?.expression ?: (c.call.calleeExpression ?: c.call.callElement)
c.trace.report(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(
reportOn, expectedMustNotBeNull, actualMayBeNull
))
) { expectedType,
actualType ->
val receiverExpression = (receiverArgument as? ExpressionReceiver)?.expression
if (receiverExpression != null) {
c.trace.report(ErrorsJvm.RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(receiverExpression, actualType))
} else {
val reportOn = c.call.calleeExpression ?: c.call.callElement
c.trace.report(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(reportOn, expectedType, actualType))
}
}
}
@@ -135,22 +138,21 @@ class JavaNullabilityChecker : AdditionalTypeChecker {
expectedType: KotlinType,
dataFlowValue: () -> DataFlowValue,
dataFlowInfo: DataFlowInfo,
reportWarning: (expectedMustNotBeNull: ErrorsJvm.NullabilityInformationSource, actualMayBeNull: ErrorsJvm.NullabilityInformationSource) -> Unit
reportWarning: (expectedType: KotlinType, actualType: KotlinType) -> Unit
) {
if (TypeUtils.noExpectedType(expectedType)) {
return
}
val expectedMustNotBeNull = expectedType.mustNotBeNull()
val actualMayBeNull = expressionType.mayBeNull()
if (expectedMustNotBeNull == ErrorsJvm.NullabilityInformationSource.KOTLIN && actualMayBeNull == ErrorsJvm.NullabilityInformationSource.KOTLIN) {
val expectedMustNotBeNull = expectedType.mustNotBeNull() ?: return
val actualMayBeNull = expressionType.mayBeNull() ?: return
if (expectedMustNotBeNull.isFromKotlin && actualMayBeNull.isFromKotlin) {
// a type mismatch error will be reported elsewhere
return
}
if (expectedMustNotBeNull != null && actualMayBeNull != null &&
dataFlowInfo.getStableNullability(dataFlowValue()) != Nullability.NOT_NULL) {
reportWarning(expectedMustNotBeNull, actualMayBeNull)
if (dataFlowInfo.getStableNullability(dataFlowValue()) != Nullability.NOT_NULL) {
reportWarning(expectedMustNotBeNull.enhancedType, actualMayBeNull.enhancedType)
}
}
@@ -159,23 +161,30 @@ class JavaNullabilityChecker : AdditionalTypeChecker {
dataFlowValue: () -> DataFlowValue,
c: ResolutionContext<*>,
body: () -> T
) = if (type.mustNotBeNull() == ErrorsJvm.NullabilityInformationSource.JAVA &&
) = if (type.mustNotBeNull()?.isFromJava == true &&
c.dataFlowInfo.getStableNullability(dataFlowValue()).canBeNull())
body()
else
null
private fun KotlinType.mustNotBeNull(): ErrorsJvm.NullabilityInformationSource? = when {
!isError && !isFlexible() && !TypeUtils.acceptsNullable(this) -> ErrorsJvm.NullabilityInformationSource.KOTLIN
isFlexible() && !TypeUtils.acceptsNullable(asFlexibleType().upperBound) -> ErrorsJvm.NullabilityInformationSource.KOTLIN
this is TypeWithEnhancement && enhancement.mustNotBeNull() != null -> ErrorsJvm.NullabilityInformationSource.JAVA
private class EnhancedNullabilityInfo(val enhancedType: KotlinType, val isFromJava: Boolean) {
val isFromKotlin get() = !isFromJava
}
private fun KotlinType.enhancementFromKotlin() = EnhancedNullabilityInfo(this, isFromJava = false)
private fun TypeWithEnhancement.enhancementFromJava() = EnhancedNullabilityInfo(enhancement, isFromJava = true)
private fun KotlinType.mustNotBeNull(): EnhancedNullabilityInfo? = when {
!isError && !isFlexible() && !TypeUtils.acceptsNullable(this) -> enhancementFromKotlin()
isFlexible() && !TypeUtils.acceptsNullable(asFlexibleType().upperBound) -> enhancementFromKotlin()
this is TypeWithEnhancement && enhancement.mustNotBeNull() != null -> enhancementFromJava()
else -> null
}
private fun KotlinType.mayBeNull(): ErrorsJvm.NullabilityInformationSource? = when {
!isError && !isFlexible() && TypeUtils.acceptsNullable(this) -> ErrorsJvm.NullabilityInformationSource.KOTLIN
isFlexible() && TypeUtils.acceptsNullable(asFlexibleType().lowerBound) -> ErrorsJvm.NullabilityInformationSource.KOTLIN
this is TypeWithEnhancement && enhancement.mayBeNull() != null -> ErrorsJvm.NullabilityInformationSource.JAVA
private fun KotlinType.mayBeNull(): EnhancedNullabilityInfo? = when {
!isError && !isFlexible() && TypeUtils.acceptsNullable(this) -> enhancementFromKotlin()
isFlexible() && TypeUtils.acceptsNullable(asFlexibleType().lowerBound) -> enhancementFromKotlin()
this is TypeWithEnhancement && enhancement.mayBeNull() != null -> enhancementFromJava()
else -> null
}
}

View File

@@ -87,8 +87,10 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
MAP.put(INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER, "Interfaces can call default methods via super only within @JvmDefault members. Please annotate the containing interface member with @JvmDefault");
MAP.put(SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC, "Using non-JVM static members protected in the superclass companion is unsupported yet");
MAP.put(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS,
"Expected type does not accept nulls in {0}, but the value may be null in {1}", Renderers.TO_STRING, Renderers.TO_STRING);
MAP.put(NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, "Type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE);
MAP.put(RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS,
"Unsafe use of a nullable receiver of type {0}", RENDER_TYPE);
MAP.put(WHEN_ENUM_CAN_BE_NULL_IN_JAVA, "Enum argument can be null in Java, but exhaustive when contains no null branch");
MAP.put(JAVA_CLASS_ON_COMPANION,

View File

@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.resolve.jvm.diagnostics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.diagnostics.*;
import org.jetbrains.kotlin.name.FqName;
@@ -123,26 +122,12 @@ public interface ErrorsJvm {
DiagnosticFactory0<KtDeclaration> NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
enum NullabilityInformationSource {
KOTLIN {
@NotNull
@Override
public String toString() {
return "Kotlin";
}
},
JAVA {
@NotNull
@Override
public String toString() {
return "Java";
}
}
}
DiagnosticFactory2<KtElement, NullabilityInformationSource, NullabilityInformationSource> NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
DiagnosticFactory2<KtElement, KotlinType, KotlinType> NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
= DiagnosticFactory2.create(WARNING);
DiagnosticFactory1<KtElement, KotlinType> RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
= DiagnosticFactory1.create(WARNING);
@SuppressWarnings("UnusedDeclaration")
Object _initializer = new Object() {
{

View File

@@ -58,31 +58,50 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
val classDescriptorOwner = getterOrSetter.containingDeclaration as? ClassDescriptor ?: return null
val originalGetterOrSetter = getterOrSetter.original
return syntheticScopes.collectSyntheticExtensionProperties(listOf(classDescriptorOwner.defaultType))
.filterIsInstance<SyntheticJavaPropertyDescriptor>()
.firstOrNull { originalGetterOrSetter == it.getMethod || originalGetterOrSetter == it.setMethod }
val names = propertyNamesByAccessorName(name)
return names
.flatMap {
syntheticScopes.collectSyntheticExtensionProperties(
listOf(classDescriptorOwner.defaultType),
it,
NoLookupLocation.FROM_SYNTHETIC_SCOPE
)
}.filterIsInstance<SyntheticJavaPropertyDescriptor>()
.firstOrNull { originalGetterOrSetter == it.getMethod || originalGetterOrSetter == it.setMethod }
}
fun propertyNamesByAccessorName(name: Name): List<Name> = listOfNotNull(
propertyNameByGetMethodName(name),
propertyNameBySetMethodName(name, withIsPrefix = true),
propertyNameBySetMethodName(name, withIsPrefix = false)
)
fun findByGetterOrSetter(getterOrSetter: FunctionDescriptor, syntheticScope: SyntheticScope) =
findByGetterOrSetter(getterOrSetter,
object : SyntheticScopes {
override val scopes: Collection<SyntheticScope> = listOf(syntheticScope)
})
findByGetterOrSetter(getterOrSetter,
object : SyntheticScopes {
override val scopes: Collection<SyntheticScope> = listOf(syntheticScope)
})
fun propertyNameByGetMethodName(methodName: Name): Name?
= org.jetbrains.kotlin.load.java.propertyNameByGetMethodName(methodName)
fun propertyNameByGetMethodName(methodName: Name): Name? = org.jetbrains.kotlin.load.java.propertyNameByGetMethodName(methodName)
fun propertyNameBySetMethodName(methodName: Name, withIsPrefix: Boolean): Name?
= org.jetbrains.kotlin.load.java.propertyNameBySetMethodName(methodName, withIsPrefix)
fun propertyNameBySetMethodName(methodName: Name, withIsPrefix: Boolean): Name? =
org.jetbrains.kotlin.load.java.propertyNameBySetMethodName(methodName, withIsPrefix)
}
}
class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val lookupTracker: LookupTracker) : SyntheticScope {
private val syntheticPropertyInClass = storageManager.createMemoizedFunction<Pair<ClassDescriptor, Name>, SyntheticPropertyHolder> { pair ->
syntheticPropertyInClassNotCached(pair.first, pair.second)
}
private val syntheticPropertyInClass =
storageManager.createMemoizedFunction<Pair<ClassDescriptor, Name>, SyntheticPropertyHolder> { pair ->
syntheticPropertyInClassNotCached(pair.first, pair.second)
}
private fun getSyntheticPropertyAndRecordLookups(classifier: ClassDescriptor, name: Name, location: LookupLocation): PropertyDescriptor? {
private fun getSyntheticPropertyAndRecordLookups(
classifier: ClassDescriptor,
name: Name,
location: LookupLocation
): PropertyDescriptor? {
val (descriptor, lookedNames) = syntheticPropertyInClass(Pair(classifier, name))
if (location !is NoLookupLocation) {
@@ -119,15 +138,15 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
val possibleGetMethodNames = possibleGetMethodNames(name)
val getMethod = possibleGetMethodNames
.flatMap { memberScope.getContributedFunctions(it, NoLookupLocation.FROM_SYNTHETIC_SCOPE) }
.singleOrNull {
it.hasJavaOriginInHierarchy() && isGoodGetMethod(it)
} ?: return result(null, possibleGetMethodNames)
.flatMap { memberScope.getContributedFunctions(it, NoLookupLocation.FROM_SYNTHETIC_SCOPE) }
.singleOrNull {
it.hasJavaOriginInHierarchy() && isGoodGetMethod(it)
} ?: return result(null, possibleGetMethodNames)
val setMethodName = setMethodName(getMethod.name)
val setMethod = memberScope.getContributedFunctions(setMethodName, NoLookupLocation.FROM_SYNTHETIC_SCOPE)
.singleOrNull { isGoodSetMethod(it, getMethod) }
.singleOrNull { isGoodSetMethod(it, getMethod) }
val propertyType = getMethod.returnType!!
@@ -140,8 +159,8 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
if (returnType.isUnit()) return false
return descriptor.valueParameters.isEmpty()
&& descriptor.typeParameters.isEmpty()
&& descriptor.visibility.isVisibleOutside()
&& descriptor.typeParameters.isEmpty()
&& descriptor.visibility.isVisibleOutside()
}
private fun isGoodSetMethod(descriptor: FunctionDescriptor, getMethod: FunctionDescriptor): Boolean {
@@ -150,14 +169,14 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
if (!TypeUtils.equalTypes(parameter.type, propertyType)) {
if (!propertyType.isSubtypeOf(parameter.type)) return false
if (descriptor.findOverridden {
val baseProperty = SyntheticJavaPropertyDescriptor.findByGetterOrSetter(it, this)
baseProperty?.getMethod?.name == getMethod.name
} == null) return false
val baseProperty = SyntheticJavaPropertyDescriptor.findByGetterOrSetter(it, this)
baseProperty?.getMethod?.name == getMethod.name
} == null) return false
}
return parameter.varargElementType == null
&& descriptor.typeParameters.isEmpty()
&& descriptor.visibility.isVisibleOutside()
&& descriptor.typeParameters.isEmpty()
&& descriptor.visibility.isVisibleOutside()
}
private fun FunctionDescriptor.findOverridden(condition: (FunctionDescriptor) -> Boolean): FunctionDescriptor? {
@@ -168,7 +187,11 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return null
}
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
override fun getSyntheticExtensionProperties(
receiverTypes: Collection<KotlinType>,
name: Name,
location: LookupLocation
): Collection<PropertyDescriptor> {
var result: SmartList<PropertyDescriptor>? = null
val processedTypes: MutableSet<TypeConstructor>? = if (receiverTypes.size > 1) HashSet<TypeConstructor>() else null
for (type in receiverTypes) {
@@ -181,22 +204,25 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
}
}
override fun getSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor>
= emptyList()
override fun getSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> =
emptyList()
override fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor>
= emptyList()
override fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> =
emptyList()
override fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection<FunctionDescriptor>
= emptyList()
override fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection<FunctionDescriptor> = emptyList()
override fun getSyntheticConstructors(scope: ResolutionScope): Collection<FunctionDescriptor>
= emptyList()
override fun getSyntheticConstructors(scope: ResolutionScope): Collection<FunctionDescriptor> = emptyList()
override fun getSyntheticConstructor(constructor: ConstructorDescriptor): ConstructorDescriptor?
= null
override fun getSyntheticConstructor(constructor: ConstructorDescriptor): ConstructorDescriptor? = null
private fun collectSyntheticPropertiesByName(result: SmartList<PropertyDescriptor>?, type: TypeConstructor, name: Name, processedTypes: MutableSet<TypeConstructor>?, location: LookupLocation): SmartList<PropertyDescriptor>? {
private fun collectSyntheticPropertiesByName(
result: SmartList<PropertyDescriptor>?,
type: TypeConstructor,
name: Name,
processedTypes: MutableSet<TypeConstructor>?,
location: LookupLocation
): SmartList<PropertyDescriptor>? {
if (processedTypes != null && !processedTypes.add(type)) return result
@Suppress("NAME_SHADOWING")
@@ -205,8 +231,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
val classifier = type.declarationDescriptor
if (classifier is ClassDescriptor) {
result = result.add(getSyntheticPropertyAndRecordLookups(classifier, name, location))
}
else {
} else {
type.supertypes.forEach { result = collectSyntheticPropertiesByName(result, it.constructor, name, processedTypes, location) }
}
@@ -220,7 +245,10 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return result
}
private fun MutableList<PropertyDescriptor>.collectSyntheticProperties(type: TypeConstructor, processedTypes: MutableSet<TypeConstructor>) {
private fun MutableList<PropertyDescriptor>.collectSyntheticProperties(
type: TypeConstructor,
processedTypes: MutableSet<TypeConstructor>
) {
if (!processedTypes.add(type)) return
val classifier = type.declarationDescriptor
@@ -231,8 +259,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
addIfNotNull(syntheticPropertyInClass(Pair(classifier, propertyName)).descriptor)
}
}
}
else {
} else {
type.supertypes.forEach { collectSyntheticProperties(it.constructor, processedTypes) }
}
}
@@ -244,7 +271,12 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return list
}
override fun getSyntheticMemberFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
override fun getSyntheticMemberFunctions(
receiverTypes: Collection<KotlinType>,
name: Name,
location: LookupLocation
): Collection<FunctionDescriptor> = emptyList()
override fun getSyntheticMemberFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> = emptyList()
private data class SyntheticPropertyHolder(val descriptor: PropertyDescriptor?, val lookedNames: List<Name>) {
@@ -254,19 +286,19 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
}
private class MyPropertyDescriptor(
containingDeclaration: DeclarationDescriptor,
original: PropertyDescriptor?,
annotations: Annotations,
modality: Modality,
visibility: Visibility,
isVar: Boolean,
name: Name,
kind: CallableMemberDescriptor.Kind,
source: SourceElement
containingDeclaration: DeclarationDescriptor,
original: PropertyDescriptor?,
annotations: Annotations,
modality: Modality,
visibility: Visibility,
isVar: Boolean,
name: Name,
kind: CallableMemberDescriptor.Kind,
source: SourceElement
) : SyntheticJavaPropertyDescriptor, PropertyDescriptorImpl(
containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, source,
/* lateInit = */ false, /* isConst = */ false, /* isExpect = */ false, /* isActual = */ false, /* isExternal = */ false,
/* isDelegated = */ false
containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, source,
/* lateInit = */ false, /* isConst = */ false, /* isExpect = */ false, /* isActual = */ false, /* isExternal = */ false,
/* isDelegated = */ false
) {
override var getMethod: FunctionDescriptor by Delegates.notNull()
@@ -276,51 +308,64 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
private set
companion object {
fun create(ownerClass: ClassDescriptor, getMethod: FunctionDescriptor, setMethod: FunctionDescriptor?, name: Name, type: KotlinType): MyPropertyDescriptor {
fun create(
ownerClass: ClassDescriptor,
getMethod: FunctionDescriptor,
setMethod: FunctionDescriptor?,
name: Name,
type: KotlinType
): MyPropertyDescriptor {
val visibility = syntheticVisibility(getMethod, isUsedForExtension = true)
val descriptor = MyPropertyDescriptor(DescriptorUtils.getContainingModule(ownerClass),
null,
Annotations.EMPTY,
Modality.FINAL,
visibility,
setMethod != null,
name,
CallableMemberDescriptor.Kind.SYNTHESIZED,
SourceElement.NO_SOURCE)
val descriptor = MyPropertyDescriptor(
DescriptorUtils.getContainingModule(ownerClass),
null,
Annotations.EMPTY,
Modality.FINAL,
visibility,
setMethod != null,
name,
CallableMemberDescriptor.Kind.SYNTHESIZED,
SourceElement.NO_SOURCE
)
descriptor.getMethod = getMethod
descriptor.setMethod = setMethod
val classTypeParams = ownerClass.typeConstructor.parameters
val typeParameters = ArrayList<TypeParameterDescriptor>(classTypeParams.size)
val typeSubstitutor = DescriptorSubstitutor.substituteTypeParameters(classTypeParams, TypeSubstitution.EMPTY, descriptor, typeParameters)
val typeSubstitutor =
DescriptorSubstitutor.substituteTypeParameters(classTypeParams, TypeSubstitution.EMPTY, descriptor, typeParameters)
val propertyType = typeSubstitutor.safeSubstitute(type, Variance.INVARIANT)
val receiverType = typeSubstitutor.safeSubstitute(ownerClass.defaultType, Variance.INVARIANT)
descriptor.setType(propertyType, typeParameters, null, receiverType)
val getter = PropertyGetterDescriptorImpl(descriptor,
getMethod.annotations,
Modality.FINAL,
visibility,
false,
getMethod.isExternal,
false,
CallableMemberDescriptor.Kind.SYNTHESIZED,
null,
SourceElement.NO_SOURCE)
val getter = PropertyGetterDescriptorImpl(
descriptor,
getMethod.annotations,
Modality.FINAL,
visibility,
false,
getMethod.isExternal,
false,
CallableMemberDescriptor.Kind.SYNTHESIZED,
null,
SourceElement.NO_SOURCE
)
getter.initialize(null)
val setter = if (setMethod != null)
PropertySetterDescriptorImpl(descriptor,
setMethod.annotations,
Modality.FINAL,
syntheticVisibility(setMethod, isUsedForExtension = true),
false,
setMethod.isExternal,
false,
CallableMemberDescriptor.Kind.SYNTHESIZED,
null,
SourceElement.NO_SOURCE)
PropertySetterDescriptorImpl(
descriptor,
setMethod.annotations,
Modality.FINAL,
syntheticVisibility(setMethod, isUsedForExtension = true),
false,
setMethod.isExternal,
false,
CallableMemberDescriptor.Kind.SYNTHESIZED,
null,
SourceElement.NO_SOURCE
)
else
null
setter?.initializeDefault()
@@ -332,12 +377,12 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
}
override fun createSubstitutedCopy(
newOwner: DeclarationDescriptor,
newModality: Modality,
newVisibility: Visibility,
original: PropertyDescriptor?,
kind: CallableMemberDescriptor.Kind,
newName: Name
newOwner: DeclarationDescriptor,
newModality: Modality,
newVisibility: Visibility,
original: PropertyDescriptor?,
kind: CallableMemberDescriptor.Kind,
newName: Name
): PropertyDescriptorImpl {
return MyPropertyDescriptor(newOwner, this, annotations, newModality, newVisibility, isVar, newName, kind, source).apply {
getMethod = this@MyPropertyDescriptor.getMethod
@@ -357,8 +402,8 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
}
val classParametersSubstitutor = TypeConstructorSubstitution.createByConstructorsMap(
substitutionMap,
approximateCapturedTypes = true
substitutionMap,
approximateCapturedTypes = true
).buildSubstitutor()
descriptor.getMethod = getMethod.substitute(classParametersSubstitutor) ?: return null

View File

@@ -20,10 +20,9 @@ import org.jetbrains.kotlin.descriptors.NotFoundClasses
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.findNonGenericClassAcrossDependencies
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.lazy.descriptors.script.classId
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.*
import kotlin.reflect.KClass
@@ -33,19 +32,15 @@ import kotlin.reflect.KVariance
import kotlin.reflect.full.primaryConstructor
fun KotlinScriptDefinition.getScriptParameters(scriptDescriptor: ScriptDescriptor): List<ScriptParameter> =
template.primaryConstructor?.parameters
?.map { ScriptParameter(Name.identifier(it.name!!), getKotlinTypeByKType(scriptDescriptor, it.type)) }
?: emptyList()
template.primaryConstructor?.parameters
?.map { ScriptParameter(Name.identifier(it.name!!), getKotlinTypeByKType(scriptDescriptor, it.type)) }
?: emptyList()
fun getKotlinTypeByKClass(scriptDescriptor: ScriptDescriptor, kClass: KClass<out Any>): KotlinType =
getKotlinTypeByFqName(scriptDescriptor,
kClass.qualifiedName ?: throw RuntimeException("Cannot get FQN from $kClass"))
private fun getKotlinTypeByFqName(scriptDescriptor: ScriptDescriptor, fqName: String): KotlinType =
scriptDescriptor.module.findNonGenericClassAcrossDependencies(
ClassId.topLevel(FqName(fqName)),
NotFoundClasses(LockBasedStorageManager.NO_LOCKS, scriptDescriptor.module)
).defaultType
scriptDescriptor.module.findNonGenericClassAcrossDependencies(
kClass.classId,
NotFoundClasses(LockBasedStorageManager.NO_LOCKS, scriptDescriptor.module)
).defaultType
// TODO: support star projections
// TODO: support annotations on types and type parameters

View File

@@ -98,6 +98,7 @@ public interface Errors {
DiagnosticFactory2<PsiElement, String, String> API_NOT_AVAILABLE = DiagnosticFactory2.create(ERROR);
DiagnosticFactory1<PsiElement, FqName> MISSING_DEPENDENCY_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, String> MISSING_SCRIPT_BASE_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, String> MISSING_SCRIPT_RECEIVER_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, String> MISSING_SCRIPT_ENVIRONMENT_PROPERTY_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, String> PRE_RELEASE_CLASS = DiagnosticFactory1.create(ERROR);

View File

@@ -357,6 +357,7 @@ public class DefaultErrorMessages {
MAP.put(API_NOT_AVAILABLE, "This declaration is only available since Kotlin {0} and cannot be used with the specified API version {1}", STRING, STRING);
MAP.put(MISSING_DEPENDENCY_CLASS, "Cannot access class ''{0}''. Check your module classpath for missing or conflicting dependencies", TO_STRING);
MAP.put(MISSING_SCRIPT_BASE_CLASS, "Cannot access script base class ''{0}''. Check your module classpath for missing or conflicting dependencies", TO_STRING);
MAP.put(MISSING_SCRIPT_RECEIVER_CLASS, "Cannot access implicit script receiver class ''{0}''. Check your module classpath for missing or conflicting dependencies", TO_STRING);
MAP.put(MISSING_SCRIPT_ENVIRONMENT_PROPERTY_CLASS, "Cannot access script environment property class ''{0}''. Check your module classpath for missing or conflicting dependencies", TO_STRING);
MAP.put(PRE_RELEASE_CLASS, "{0} is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler", TO_STRING);

View File

@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
@@ -596,6 +597,8 @@ internal fun reportResolvedUsingDeprecatedVisibility(
val descriptorToLookup: DeclarationDescriptor = when (candidateDescriptor) {
is ClassConstructorDescriptor -> candidateDescriptor.containingDeclaration
is FakeCallableDescriptorForObject -> candidateDescriptor.classDescriptor
is SyntheticMemberDescriptor<*> -> candidateDescriptor.baseDescriptorForSynthetic
is PropertyDescriptor, is FunctionDescriptor -> candidateDescriptor
else -> error(
"Unexpected candidate descriptor of resolved call with " +
"ResolvedUsingDeprecatedVisibility-diagnostic: $candidateDescriptor\n" +

View File

@@ -18,11 +18,12 @@ package org.jetbrains.kotlin.resolve.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.DeprecationResolver
@@ -62,7 +63,19 @@ fun checkClassifierUsages(
}
}
private fun runCheckersWithTarget(target: ClassifierDescriptor, expression: KtReferenceExpression) {
override fun visitFunctionType(type: KtFunctionType) {
super.visitFunctionType(type)
val kotlinType = context.trace.get(BindingContext.TYPE, type.parent as? KtTypeReference ?: return)
if (kotlinType != null) {
val descriptor = kotlinType.constructor.declarationDescriptor
if (descriptor is ClassifierDescriptor) {
runCheckersWithTarget(descriptor, type)
}
}
}
private fun runCheckersWithTarget(target: ClassifierDescriptor, expression: KtElement) {
for (checker in checkers) {
checker.check(target, expression, context)
}

View File

@@ -92,8 +92,25 @@ object ExpectedActualDeclarationChecker : DeclarationChecker {
}
}
internal fun isOptionalAnnotationClass(descriptor: DeclarationDescriptor): Boolean {
return descriptor.annotations.hasAnnotation(OPTIONAL_EXPECTATION_FQ_NAME)
@JvmStatic
fun isOptionalAnnotationClass(descriptor: DeclarationDescriptor): Boolean =
descriptor is ClassDescriptor &&
descriptor.kind == ClassKind.ANNOTATION_CLASS &&
descriptor.isExpect &&
descriptor.annotations.hasAnnotation(OPTIONAL_EXPECTATION_FQ_NAME)
// TODO: move to some other place which is accessible both from backend-common and js.serializer
@JvmStatic
fun shouldGenerateExpectClass(descriptor: ClassDescriptor): Boolean {
assert(descriptor.isExpect) { "Not an expected class: $descriptor" }
if (ExpectedActualDeclarationChecker.isOptionalAnnotationClass(descriptor)) {
with(ExpectedActualResolver) {
return descriptor.findCompatibleActualForExpected(descriptor.module).isEmpty()
}
}
return false
}
private fun ExpectActualTracker.reportExpectActual(expected: MemberDescriptor, actualMembers: Sequence<MemberDescriptor>) {

View File

@@ -22,9 +22,11 @@ import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
import org.jetbrains.kotlin.script.ScriptHelper
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
class LazyScriptClassMemberScope(
resolveSession: ResolveSession,
@@ -33,34 +35,67 @@ class LazyScriptClassMemberScope(
trace: BindingTrace
) : LazyClassMemberScope(resolveSession, declarationProvider, scriptDescriptor, trace) {
override fun resolvePrimaryConstructor(): ClassConstructorDescriptor? {
val constructor = ClassConstructorDescriptorImpl.create(
scriptDescriptor,
Annotations.EMPTY,
true,
SourceElement.NO_SOURCE
)
constructor.initialize(
createScriptParameters(constructor),
Visibilities.PUBLIC
)
setDeferredReturnType(constructor)
return constructor
private val scriptPrimaryConstructor: () -> ClassConstructorDescriptorImpl? = resolveSession.storageManager.createNullableLazyValue {
val baseClass = scriptDescriptor.baseClassDescriptor()
val baseConstructorDescriptor = baseClass?.unsubstitutedPrimaryConstructor
if (baseConstructorDescriptor != null) {
val builtIns = scriptDescriptor.builtIns
val implicitReceiversParamType =
if (scriptDescriptor.scriptDefinition().implicitReceivers.isEmpty()) null
else {
"implicitReceivers" to builtIns.array.substitute(builtIns.anyType)!!
}
val environmentVarsParamType =
if (scriptDescriptor.scriptDefinition().environmentVariables.isEmpty()) null
else {
"environmentVariables" to builtIns.map.substitute(builtIns.stringType, builtIns.nullableAnyType)!!
}
val annotations = baseConstructorDescriptor.annotations
val constructorDescriptor = ClassConstructorDescriptorImpl.create(
scriptDescriptor, annotations, baseConstructorDescriptor.isPrimary, scriptDescriptor.source
)
var paramsIndexBase = baseConstructorDescriptor.valueParameters.lastIndex + 1
val syntheticParameters =
listOf(implicitReceiversParamType, environmentVarsParamType).mapNotNull { param: Pair<String, KotlinType>? ->
if (param == null) null
else ValueParameterDescriptorImpl(
constructorDescriptor,
null,
paramsIndexBase++,
Annotations.EMPTY,
Name.identifier(param.first),
param.second,
false, false, false, null, SourceElement.NO_SOURCE
)
}
val parameters = baseConstructorDescriptor.valueParameters.map { it.copy(constructorDescriptor, it.name, it.index) } +
syntheticParameters
constructorDescriptor.initialize(parameters, baseConstructorDescriptor.visibility)
constructorDescriptor.returnType = scriptDescriptor.defaultType
constructorDescriptor
} else {
null
}
}
private fun createScriptParameters(constructor: ClassConstructorDescriptorImpl): List<ValueParameterDescriptor> {
return ScriptHelper.getInstance().getScriptParameters(scriptDescriptor.scriptDefinition, scriptDescriptor)
.mapIndexed { index, (name, type) ->
ValueParameterDescriptorImpl(
constructor, null, index, Annotations.EMPTY, name, type,
/* declaresDefaultValue = */ false,
/* isCrossinline = */ false,
/* isNoinline = */ false,
null, SourceElement.NO_SOURCE
override fun resolvePrimaryConstructor(): ClassConstructorDescriptor? {
val constructor = scriptPrimaryConstructor()
?: ClassConstructorDescriptorImpl.create(
scriptDescriptor,
Annotations.EMPTY,
true,
SourceElement.NO_SOURCE
).initialize(
emptyList(),
Visibilities.PUBLIC
)
}
setDeferredReturnType(constructor)
return constructor
}
override fun createPropertiesFromPrimaryConstructorParameters(name: Name, result: MutableSet<PropertyDescriptor>) {
}
}
private fun ClassDescriptor.substitute(vararg types: KotlinType): KotlinType? =
KotlinTypeFactory.simpleType(this.defaultType, arguments = types.map { it.asTypeProjection() })

View File

@@ -18,10 +18,10 @@ package org.jetbrains.kotlin.resolve.lazy.descriptors
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.*
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
@@ -31,14 +31,15 @@ import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.data.KtScriptInfo
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
import org.jetbrains.kotlin.resolve.lazy.descriptors.script.ScriptEnvironmentDescriptor
import org.jetbrains.kotlin.resolve.scopes.*
import org.jetbrains.kotlin.resolve.lazy.descriptors.script.classId
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.script.KotlinScriptDefinition
import org.jetbrains.kotlin.script.ScriptHelper
import org.jetbrains.kotlin.script.ScriptPriorities
import org.jetbrains.kotlin.script.getScriptDefinition
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.utils.ifEmpty
import kotlin.reflect.KClass
import kotlin.reflect.KType
@@ -66,11 +67,10 @@ class LazyScriptDescriptor(
override fun getPriority() = priority
val scriptDefinition: KotlinScriptDefinition
by lazy {
val file = scriptInfo.script.containingKtFile
getScriptDefinition(file) ?: throw RuntimeException("file ${file.name} is not a script")
}
val scriptDefinition: () -> KotlinScriptDefinition = resolveSession.storageManager.createLazyValue {
val file = scriptInfo.script.containingKtFile
getScriptDefinition(file) ?: throw RuntimeException("file ${file.name} is not a script")
}
override fun substitute(substitutor: TypeSubstitutor) = this
@@ -88,28 +88,39 @@ class LazyScriptDescriptor(
override fun getUnsubstitutedPrimaryConstructor() = super.getUnsubstitutedPrimaryConstructor()!!
override fun computeSupertypes() =
listOf(ScriptHelper.getInstance().getKotlinType(this, scriptDefinition.template)).ifEmpty { listOf(builtIns.anyType) }
internal val baseClassDescriptor: () -> ClassDescriptor? = resolveSession.storageManager.createNullableLazyValue {
findTypeDescriptor(scriptDefinition().template, Errors.MISSING_SCRIPT_BASE_CLASS)
}
override fun computeSupertypes() = listOf(baseClassDescriptor()?.defaultType ?: builtIns.anyType)
private val scriptImplicitReceivers: () -> List<ClassDescriptor> = resolveSession.storageManager.createLazyValue {
scriptDefinition.implicitReceivers.mapNotNull { receiver ->
scriptDefinition().implicitReceivers.mapNotNull { receiver ->
findTypeDescriptor(receiver, Errors.MISSING_SCRIPT_RECEIVER_CLASS)
}
}
internal fun findTypeDescriptor(type: KType, errorDiagnostic: DiagnosticFactory1<PsiElement, String>): ClassDescriptor? {
val receiverClassId = type.classId
return receiverClassId?.let {
module.findClassAcrossModuleDependencies(it)
} ?: also {
internal fun findTypeDescriptor(kClass: KClass<*>, errorDiagnostic: DiagnosticFactory1<PsiElement, String>?): ClassDescriptor? =
findTypeDescriptor(kClass.classId, kClass.toString(), errorDiagnostic)
internal fun findTypeDescriptor(type: KType, errorDiagnostic: DiagnosticFactory1<PsiElement, String>?): ClassDescriptor? =
findTypeDescriptor(type.classId, type.toString(), errorDiagnostic)
internal fun findTypeDescriptor(
classId: ClassId?, typeName: String,
errorDiagnostic: DiagnosticFactory1<PsiElement, String>?
): ClassDescriptor? {
val typeDescriptor = classId?.let { module.findClassAcrossModuleDependencies(it) }
if (typeDescriptor == null && errorDiagnostic != null) {
// TODO: use PositioningStrategies to highlight some specific place in case of error, instead of treating the whole file as invalid
resolveSession.trace.report(
errorDiagnostic.on(
scriptInfo.script,
receiverClassId?.asSingleFqName()?.toString() ?: type.toString()
classId?.asSingleFqName()?.toString() ?: typeName
)
)
}
return typeDescriptor
}
override fun getImplicitReceivers(): List<ClassDescriptor> = scriptImplicitReceivers()
@@ -123,7 +134,7 @@ class LazyScriptDescriptor(
private val scriptOuterScope: () -> LexicalScope = resolveSession.storageManager.createLazyValue {
var outerScope = super.getOuterScope()
val outerScopeReceivers = implicitReceivers.let {
if (scriptDefinition.environmentVariables.isEmpty()) {
if (scriptDefinition().environmentVariables.isEmpty()) {
it
} else {
it + ScriptEnvironmentDescriptor(this)
@@ -142,12 +153,17 @@ class LazyScriptDescriptor(
}
override fun getOuterScope(): LexicalScope = scriptOuterScope()
private val scriptClassAnnotations: () -> Annotations = resolveSession.storageManager.createLazyValue {
baseClassDescriptor()?.annotations?.let { ann ->
FilteredAnnotations(ann) { fqname ->
val shortName = fqname.shortName().identifier
// TODO: consider more precise annotation filtering
!shortName.startsWith("KotlinScript") && !shortName.startsWith("ScriptTemplate")
}
} ?: super.annotations
}
override val annotations: Annotations
get() = scriptClassAnnotations()
}
private val KClass<*>.classId: ClassId
get() = this.java.enclosingClass?.kotlin?.classId?.createNestedClassId(Name.identifier(simpleName!!))
?: ClassId.topLevel(FqName(qualifiedName!!))
private val KType.classId: ClassId?
get() = classifier?.let { it as? KClass<*> }?.classId

View File

@@ -43,7 +43,7 @@ class ScriptEnvironmentDescriptor(script: LazyScriptDescriptor) :
override fun getUnsubstitutedMemberScope(): MemberScope = memberScope()
val properties: () -> List<ScriptEnvironmentPropertyDescriptor> = script.resolveSession.storageManager.createLazyValue {
script.scriptDefinition.environmentVariables.mapNotNull { (name, type) ->
script.scriptDefinition().environmentVariables.mapNotNull { (name, type) ->
script.findTypeDescriptor(type, Errors.MISSING_SCRIPT_ENVIRONMENT_PROPERTY_CLASS)?.let {
name to it
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright 2010-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.lazy.descriptors.script
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import kotlin.reflect.KClass
import kotlin.reflect.KType
val KClass<*>.classId: ClassId
get() = this.java.enclosingClass?.kotlin?.classId?.createNestedClassId(Name.identifier(simpleName!!))
?: ClassId.topLevel(FqName(qualifiedName!!))
val KType.classId: ClassId?
get() = classifier?.let { it as? KClass<*> }?.classId

View File

@@ -37,7 +37,8 @@ fun makeJsIncrementally(
messageCollector: MessageCollector = MessageCollector.NONE,
reporter: ICReporter = EmptyICReporter
) {
val versions = commonCacheVersions(cachesDir) + standaloneCacheVersion(cachesDir)
val isIncremental = IncrementalCompilation.isEnabledForJs()
val versions = commonCacheVersions(cachesDir, isIncremental) + standaloneCacheVersion(cachesDir, isIncremental)
val allKotlinFiles = sourceRoots.asSequence().flatMap { it.walk() }
.filter { it.isFile && it.extension.equals("kt", ignoreCase = true) }.toList()
@@ -47,14 +48,13 @@ fun makeJsIncrementally(
}
}
inline fun <R> withJsIC(fn: ()->R): R {
inline fun <R> withJsIC(fn: () -> R): R {
val isJsEnabledBackup = IncrementalCompilation.isEnabledForJs()
IncrementalCompilation.setIsEnabledForJs(true)
try {
return withIC { fn() }
}
finally {
return fn()
} finally {
IncrementalCompilation.setIsEnabledForJs(isJsEnabledBackup)
}
}
@@ -70,7 +70,7 @@ class IncrementalJsCompilerRunner(
reporter
) {
override fun isICEnabled(): Boolean =
IncrementalCompilation.isEnabled() && IncrementalCompilation.isEnabledForJs()
IncrementalCompilation.isEnabledForJs()
override fun createCacheManager(args: K2JSCompilerArguments): IncrementalJsCachesManager =
IncrementalJsCachesManager(cacheDirectory, reporter)

View File

@@ -56,7 +56,8 @@ fun makeIncrementally(
messageCollector: MessageCollector = MessageCollector.NONE,
reporter: ICReporter = EmptyICReporter
) {
val versions = commonCacheVersions(cachesDir) + standaloneCacheVersion(cachesDir)
val isIncremental = IncrementalCompilation.isEnabledForJvm()
val versions = commonCacheVersions(cachesDir, isIncremental) + standaloneCacheVersion(cachesDir, isIncremental)
val kotlinExtensions = listOf("kt", "kts")
val allExtensions = kotlinExtensions + listOf("java")
@@ -86,7 +87,7 @@ object EmptyICReporter : ICReporter {
}
inline fun <R> withIC(enabled: Boolean = true, fn: ()->R): R {
val isEnabledBackup = IncrementalCompilation.isEnabled()
val isEnabledBackup = IncrementalCompilation.isEnabledForJvm()
IncrementalCompilation.setIsEnabled(enabled)
try {
@@ -114,7 +115,7 @@ class IncrementalJvmCompilerRunner(
localStateDirs = localStateDirs
) {
override fun isICEnabled(): Boolean =
IncrementalCompilation.isEnabled()
IncrementalCompilation.isEnabledForJvm()
override fun createCacheManager(args: K2JVMCompilerArguments): IncrementalJvmCachesManager =
IncrementalJvmCachesManager(cacheDirectory, File(args.destination), reporter)

View File

@@ -21,8 +21,8 @@ import java.io.File
internal const val STANDALONE_CACHE_VERSION = 2
internal const val STANDALONE_VERSION_FILE_NAME = "standalone-ic-format-version.txt"
fun standaloneCacheVersion(dataRoot: File): CacheVersion =
customCacheVersion(STANDALONE_CACHE_VERSION, STANDALONE_VERSION_FILE_NAME, dataRoot, enabled = true)
fun standaloneCacheVersion(dataRoot: File, enabled: Boolean): CacheVersion =
customCacheVersion(STANDALONE_CACHE_VERSION, STANDALONE_VERSION_FILE_NAME, dataRoot, enabled)
fun customCacheVersion(version: Int, fileName: String, dataRoot: File, enabled: Boolean): CacheVersion =
CacheVersion(ownVersion = version,
@@ -30,8 +30,7 @@ fun customCacheVersion(version: Int, fileName: String, dataRoot: File, enabled:
whenVersionChanged = CacheVersion.Action.REBUILD_ALL_KOTLIN,
whenTurnedOn = CacheVersion.Action.REBUILD_ALL_KOTLIN,
whenTurnedOff = CacheVersion.Action.REBUILD_ALL_KOTLIN,
isEnabled = { enabled })
isEnabled = enabled)
fun commonCacheVersions(cachesDir: File): List<CacheVersion> =
listOf(normalCacheVersion(cachesDir),
dataContainerCacheVersion(cachesDir))
fun commonCacheVersions(cachesDir: File, enabled: Boolean): List<CacheVersion> =
listOf(normalCacheVersion(cachesDir, enabled), dataContainerCacheVersion(cachesDir, enabled))

View File

@@ -11,6 +11,7 @@ import com.intellij.psi.impl.LanguageConstantExpressionEvaluator
import com.intellij.psi.impl.light.LightIdentifier
import com.intellij.psi.impl.light.LightTypeElement
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
@@ -22,7 +23,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class KtLightPsiArrayInitializerMemberValue(
override val kotlinOrigin: KtElement,
val lightParent: PsiElement,
val arguments: (KtLightPsiArrayInitializerMemberValue) -> List<PsiAnnotationMemberValue>
private val arguments: (KtLightPsiArrayInitializerMemberValue) -> List<PsiAnnotationMemberValue>
) : KtLightElementBase(lightParent), PsiArrayInitializerMemberValue {
override fun getInitializers(): Array<PsiAnnotationMemberValue> = arguments(this).toTypedArray()
@@ -82,6 +83,7 @@ private fun psiType(kotlinType: KotlinType, context: PsiElement): PsiType? {
"kotlin.Char" -> PsiType.CHAR
"kotlin.Double" -> PsiType.DOUBLE
"kotlin.Float" -> PsiType.FLOAT
"kotlin.Unit" -> PsiType.VOID
"kotlin.String" -> PsiType.getJavaLangString(context.manager, context.resolveScope)
else -> PsiType.getTypeByName(typeFqName, context.project, context.resolveScope)
}
@@ -90,11 +92,16 @@ private fun psiType(kotlinType: KotlinType, context: PsiElement): PsiType? {
class KtLightPsiNameValuePair private constructor(
override val kotlinOrigin: KtElement,
val valueArgument: KtValueArgument,
lightParent: PsiElement
lightParent: PsiElement,
private val argument: (KtLightPsiNameValuePair) -> PsiAnnotationMemberValue?
) : KtLightElementBase(lightParent),
PsiNameValuePair {
constructor(valueArgument: KtValueArgument, lightParent: PsiElement) : this(valueArgument.asElement(), valueArgument, lightParent)
constructor(
valueArgument: KtValueArgument,
lightParent: PsiElement,
argument: (KtLightPsiNameValuePair) -> PsiAnnotationMemberValue?
) : this(valueArgument.asElement(), valueArgument, lightParent, argument)
override fun setValue(newValue: PsiAnnotationMemberValue): PsiAnnotationMemberValue =
throw UnsupportedOperationException("can't modify KtLightPsiNameValuePair")
@@ -103,8 +110,9 @@ class KtLightPsiNameValuePair private constructor(
override fun getName(): String? = valueArgument.getArgumentName()?.asName?.asString()
override fun getValue(): PsiAnnotationMemberValue? =
valueArgument.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(this, it) }
private val _value: PsiAnnotationMemberValue? by lazyPub { argument(this) }
override fun getValue(): PsiAnnotationMemberValue? = _value
override fun getLiteralValue(): String? = (getValue() as? PsiLiteralExpression)?.value?.toString()

View File

@@ -11,6 +11,7 @@ import com.intellij.psi.impl.LanguageConstantExpressionEvaluator
import com.intellij.psi.impl.light.LightIdentifier
import com.intellij.psi.impl.light.LightTypeElement
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
@@ -22,7 +23,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class KtLightPsiArrayInitializerMemberValue(
override val kotlinOrigin: KtElement,
val lightParent: PsiElement,
val arguments: (KtLightPsiArrayInitializerMemberValue) -> List<PsiAnnotationMemberValue>
private val arguments: (KtLightPsiArrayInitializerMemberValue) -> List<PsiAnnotationMemberValue>
) : KtLightElementBase(lightParent), PsiArrayInitializerMemberValue {
override fun getInitializers(): Array<PsiAnnotationMemberValue> = arguments(this).toTypedArray()
@@ -72,16 +73,17 @@ class KtLightPsiClassObjectAccessExpression(override val kotlinOrigin: KtClassLi
}
private fun psiType(kotlinType: KotlinType, context: PsiElement): PsiType? {
val typeFqName = kotlinType.constructor.declarationDescriptor?.fqNameSafe?.asString() ?: return null
return when (typeFqName) {
"kotlin.Int" -> PsiType.INT
"kotlin.Long" -> PsiType.LONG
"kotlin.Short" -> PsiType.SHORT
"kotlin.Boolean" -> PsiType.BOOLEAN
"kotlin.Byte" -> PsiType.BYTE
"kotlin.Char" -> PsiType.CHAR
"kotlin.Double" -> PsiType.DOUBLE
"kotlin.Float" -> PsiType.FLOAT
val typeFqName = kotlinType.constructor.declarationDescriptor?.fqNameSafe?.asString() ?: return null
return when (typeFqName) {
"kotlin.Int" -> PsiType.INT
"kotlin.Long" -> PsiType.LONG
"kotlin.Short" -> PsiType.SHORT
"kotlin.Boolean" -> PsiType.BOOLEAN
"kotlin.Byte" -> PsiType.BYTE
"kotlin.Char" -> PsiType.CHAR
"kotlin.Double" -> PsiType.DOUBLE
"kotlin.Float" -> PsiType.FLOAT
"kotlin.Unit" -> PsiType.VOID
"kotlin.String" -> PsiType.getJavaLangString(context.manager, context.resolveScope)
else -> PsiType.getTypeByName(typeFqName, context.project, context.resolveScope)
}
@@ -90,11 +92,16 @@ private fun psiType(kotlinType: KotlinType, context: PsiElement): PsiType? {
class KtLightPsiNameValuePair private constructor(
override val kotlinOrigin: KtElement,
val valueArgument: KtValueArgument,
lightParent: PsiElement
lightParent: PsiElement,
private val argument: (KtLightPsiNameValuePair) -> PsiAnnotationMemberValue?
) : KtLightElementBase(lightParent),
PsiNameValuePair {
constructor(valueArgument: KtValueArgument, lightParent: PsiElement) : this(valueArgument.asElement(), valueArgument, lightParent)
constructor(
valueArgument: KtValueArgument,
lightParent: PsiElement,
argument: (KtLightPsiNameValuePair) -> PsiAnnotationMemberValue?
) : this(valueArgument.asElement(), valueArgument, lightParent, argument)
override fun setValue(newValue: PsiAnnotationMemberValue): PsiAnnotationMemberValue =
throw UnsupportedOperationException("can't modify KtLightPsiNameValuePair")
@@ -103,8 +110,9 @@ class KtLightPsiNameValuePair private constructor(
override fun getName(): String? = valueArgument.getArgumentName()?.asName?.asString()
override fun getValue(): PsiAnnotationMemberValue? =
valueArgument.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(this, it) }
private val _value: PsiAnnotationMemberValue? by lazyPub { argument(this) }
override fun getValue(): PsiAnnotationMemberValue? = _value
override fun getLiteralValue(): String? = (getValue() as? PsiLiteralExpression)?.value?.toString()

View File

@@ -5,38 +5,72 @@
package org.jetbrains.kotlin.asJava.elements
import com.intellij.openapi.util.TextRange
import com.intellij.psi.*
import com.intellij.psi.scope.PsiScopeProcessor
import com.intellij.util.IncorrectOperationException
import org.jetbrains.kotlin.asJava.classes.lazyPub
class KtLightPsiJavaCodeReferenceElement(
private val ktElement: PsiElement,
private val reference: PsiReference,
private val clsDelegateProvider: () -> PsiJavaCodeReferenceElement
reference: () -> PsiReference?,
clsDelegateProvider: () -> PsiJavaCodeReferenceElement?
) :
PsiElement by ktElement,
PsiReference by reference,
PsiReference by LazyPsiReferenceDelegate(ktElement, reference),
PsiJavaCodeReferenceElement {
private val delegate by lazyPub { clsDelegateProvider() }
private val delegate by lazyPub(clsDelegateProvider)
override fun advancedResolve(incompleteCode: Boolean): JavaResolveResult = delegate.advancedResolve(incompleteCode)
override fun advancedResolve(incompleteCode: Boolean): JavaResolveResult =
delegate?.advancedResolve(incompleteCode) ?: JavaResolveResult.EMPTY
override fun getReferenceNameElement(): PsiElement? = ktElement
override fun getTypeParameters(): Array<PsiType> = delegate.typeParameters
override fun getTypeParameters(): Array<PsiType> = delegate?.typeParameters ?: emptyArray()
override fun getReferenceName(): String? = delegate.referenceName
override fun getReferenceName(): String? = delegate?.referenceName
override fun isQualified(): Boolean = delegate.isQualified
override fun isQualified(): Boolean = delegate?.isQualified ?: false
override fun processVariants(processor: PsiScopeProcessor) = delegate.processVariants(processor)
override fun processVariants(processor: PsiScopeProcessor) {
delegate?.processVariants(processor)
}
override fun multiResolve(incompleteCode: Boolean): Array<JavaResolveResult> = delegate.multiResolve(incompleteCode)
override fun multiResolve(incompleteCode: Boolean): Array<JavaResolveResult> = delegate?.multiResolve(incompleteCode) ?: emptyArray()
override fun getQualifiedName(): String = delegate.qualifiedName
override fun getQualifiedName(): String? = delegate?.qualifiedName
override fun getQualifier(): PsiElement? = delegate.qualifier
override fun getQualifier(): PsiElement? = delegate?.qualifier
override fun getParameterList(): PsiReferenceParameterList? = delegate.parameterList
override fun getParameterList(): PsiReferenceParameterList? = delegate?.parameterList
}
private class LazyPsiReferenceDelegate(
private val psiElement: PsiElement,
referenceProvider: () -> PsiReference?
) : PsiReference {
private val delegate by lazyPub(referenceProvider)
override fun getElement(): PsiElement = psiElement
override fun resolve(): PsiElement? = delegate?.resolve()
override fun getRangeInElement(): TextRange = delegate?.rangeInElement ?: psiElement.textRange
override fun getCanonicalText(): String = delegate?.canonicalText ?: "<no-text>"
@Throws(IncorrectOperationException::class)
override fun handleElementRename(newElementName: String): PsiElement = delegate?.handleElementRename(newElementName) ?: element
@Throws(IncorrectOperationException::class)
override fun bindToElement(element: PsiElement): PsiElement =
delegate?.bindToElement(element) ?: throw IncorrectOperationException("can't rename LazyPsiReferenceDelegate")
override fun isSoft(): Boolean = delegate?.isSoft ?: false
override fun isReferenceTo(element: PsiElement): Boolean = delegate?.isReferenceTo(element) ?: false
override fun getVariants(): Array<Any> = delegate?.variants ?: emptyArray()
}

View File

@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
import org.jetbrains.kotlin.psi.*
@@ -40,6 +41,7 @@ import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.kotlin.resolve.descriptorUtil.declaresOrInheritsDefaultValue
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmOverloadsAnnotation
import org.jetbrains.kotlin.resolve.source.getPsi
@@ -96,28 +98,17 @@ class KtLightAnnotationForSourceEntry(
override fun findDeclaredAttributeValue(name: String?): PsiAnnotationMemberValue? = getAttributeValue(name, false)
private fun getCallEntry(name: String): MutableMap.MutableEntry<ValueParameterDescriptor, ResolvedValueArgument>? {
val resolvedCall = kotlinOrigin.getResolvedCall() ?: return null
return resolvedCall.valueArguments.entries.find { (param, _) -> param.name.asString() == name } ?: return null
}
private fun getAttributeValue(name: String?, useDefault: Boolean): PsiAnnotationMemberValue? {
val name = name ?: "value"
val callEntry = getCallEntry(name) ?: return null
val resolvedCall = kotlinOrigin.getResolvedCall() ?: return null
val callEntry = resolvedCall.valueArguments.entries.find { (param, _) -> param.name.asString() == name } ?: return null
val valueArguments = callEntry.value.arguments
val valueArgument = valueArguments.firstOrNull()
val argument = valueArgument?.getArgumentExpression()
if (argument != null) {
val arrayExpected = callEntry.key?.type?.let { KotlinBuiltIns.isArray(it) } ?: false
if (arrayExpected && (argument is KtStringTemplateExpression || argument is KtConstantExpression || getAnnotationName(argument) != null))
return KtLightPsiArrayInitializerMemberValue(
PsiTreeUtil.findCommonParent(valueArguments.map { it.getArgumentExpression() }) as KtElement,
this,
{ self ->
valueArguments.mapNotNull {
it.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
})
val valueArgument = callEntry.value.arguments.firstOrNull()
if (valueArgument != null) {
ktLightAnnotationParameterList.attributes.find { (it as KtLightPsiNameValuePair).valueArgument === valueArgument }?.let {
return it.value
}
@@ -136,15 +127,14 @@ class KtLightAnnotationForSourceEntry(
}
override fun getNameReferenceElement(): PsiJavaCodeReferenceElement? {
val reference = (kotlinOrigin as? KtAnnotationEntry)?.typeReference?.reference
override fun getNameReferenceElement(): PsiJavaCodeReferenceElement? = KtLightPsiJavaCodeReferenceElement(
kotlinOrigin.navigationElement,
{
(kotlinOrigin as? KtAnnotationEntry)?.typeReference?.reference
?: (kotlinOrigin.calleeExpression?.nameReference)?.references?.firstOrNull()
?: return null
return KtLightPsiJavaCodeReferenceElement(
kotlinOrigin.navigationElement,
reference,
{ super.getNameReferenceElement()!! })
}
},
{ super.getNameReferenceElement() }
)
private val ktLightAnnotationParameterList by lazyPub { KtLightAnnotationParameterList() }
@@ -153,13 +143,40 @@ class KtLightAnnotationForSourceEntry(
inner class KtLightAnnotationParameterList() : KtLightElementBase(this),
PsiAnnotationParameterList {
override val kotlinOrigin get() = null
override val kotlinOrigin: KtElement? get() = null
private val _attributes: Array<PsiNameValuePair> by lazyPub {
this@KtLightAnnotationForSourceEntry.kotlinOrigin.valueArguments.map { KtLightPsiNameValuePair(it as KtValueArgument, this) }
this@KtLightAnnotationForSourceEntry.kotlinOrigin.valueArguments.map { makeLightPsiNameValuePair(it as KtValueArgument) }
.toTypedArray<PsiNameValuePair>()
}
private fun makeArrayInitializerIfExpected(pair: KtLightPsiNameValuePair): PsiAnnotationMemberValue? {
val valueArgument = pair.valueArgument
val name = valueArgument.name ?: "value"
val callEntry = getCallEntry(name) ?: return null
val valueArguments = callEntry.value.arguments
val argument = valueArguments.firstOrNull()?.getArgumentExpression() ?: return null
if (!callEntry.key.type.let { KotlinBuiltIns.isArray(it) }) return null
if (argument !is KtStringTemplateExpression && argument !is KtConstantExpression && getAnnotationName(argument) == null) {
return null
}
val parent = PsiTreeUtil.findCommonParent(valueArguments.map { it.getArgumentExpression() }) as KtElement
return KtLightPsiArrayInitializerMemberValue(parent, pair) { self ->
valueArguments.mapNotNull {
it.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
}
}
private fun makeLightPsiNameValuePair(valueArgument: KtValueArgument) = KtLightPsiNameValuePair(valueArgument, this) { self ->
makeArrayInitializerIfExpected(self)
?: self.valueArgument.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
override fun getAttributes(): Array<PsiNameValuePair> = _attributes
}
@@ -323,6 +340,7 @@ private val backendNullabilityAnnotations = arrayOf(Nullable::class.java.name, N
private fun KtElement.analyze(): BindingContext = LightClassGenerationSupport.getInstance(this.project).analyze(this)
private fun KtElement.getResolvedCall(): ResolvedCall<out CallableDescriptor>? {
if (!isValid) return null
val context = analyze()
return this.getResolvedCall(context)
}

View File

@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
import org.jetbrains.kotlin.psi.*
@@ -40,6 +41,7 @@ import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.kotlin.resolve.descriptorUtil.declaresOrInheritsDefaultValue
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmOverloadsAnnotation
import org.jetbrains.kotlin.resolve.source.getPsi
@@ -98,28 +100,17 @@ class KtLightAnnotationForSourceEntry(
override fun findDeclaredAttributeValue(name: String?): PsiAnnotationMemberValue? = getAttributeValue(name, false)
private fun getCallEntry(name: String): MutableMap.MutableEntry<ValueParameterDescriptor, ResolvedValueArgument>? {
val resolvedCall = kotlinOrigin.getResolvedCall() ?: return null
return resolvedCall.valueArguments.entries.find { (param, _) -> param.name.asString() == name } ?: return null
}
private fun getAttributeValue(name: String?, useDefault: Boolean): PsiAnnotationMemberValue? {
val name = name ?: "value"
val callEntry = getCallEntry(name) ?: return null
val resolvedCall = kotlinOrigin.getResolvedCall() ?: return null
val callEntry = resolvedCall.valueArguments.entries.find { (param, _) -> param.name.asString() == name } ?: return null
val valueArguments = callEntry.value.arguments
val valueArgument = valueArguments.firstOrNull()
val argument = valueArgument?.getArgumentExpression()
if (argument != null) {
val arrayExpected = callEntry.key?.type?.let { KotlinBuiltIns.isArray(it) } ?: false
if (arrayExpected && (argument is KtStringTemplateExpression || argument is KtConstantExpression || getAnnotationName(argument) != null))
return KtLightPsiArrayInitializerMemberValue(
PsiTreeUtil.findCommonParent(valueArguments.map { it.getArgumentExpression() }) as KtElement,
this,
{ self ->
valueArguments.mapNotNull {
it.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
})
val valueArgument = callEntry.value.arguments.firstOrNull()
if (valueArgument != null) {
ktLightAnnotationParameterList.attributes.find { (it as KtLightPsiNameValuePair).valueArgument === valueArgument }?.let {
return it.value
}
@@ -138,15 +129,14 @@ class KtLightAnnotationForSourceEntry(
}
override fun getNameReferenceElement(): PsiJavaCodeReferenceElement? {
val reference = (kotlinOrigin as? KtAnnotationEntry)?.typeReference?.reference
override fun getNameReferenceElement(): PsiJavaCodeReferenceElement? = KtLightPsiJavaCodeReferenceElement(
kotlinOrigin.navigationElement,
{
(kotlinOrigin as? KtAnnotationEntry)?.typeReference?.reference
?: (kotlinOrigin.calleeExpression?.nameReference)?.references?.firstOrNull()
?: return null
return KtLightPsiJavaCodeReferenceElement(
kotlinOrigin.navigationElement,
reference,
{ super.getNameReferenceElement()!! })
}
},
{ super.getNameReferenceElement() }
)
private val ktLightAnnotationParameterList by lazyPub { KtLightAnnotationParameterList() }
@@ -155,13 +145,40 @@ class KtLightAnnotationForSourceEntry(
inner class KtLightAnnotationParameterList() : KtLightElementBase(this),
PsiAnnotationParameterList {
override val kotlinOrigin get() = null
override val kotlinOrigin: KtElement? get() = null
private val _attributes: Array<PsiNameValuePair> by lazyPub {
this@KtLightAnnotationForSourceEntry.kotlinOrigin.valueArguments.map { KtLightPsiNameValuePair(it as KtValueArgument, this) }
this@KtLightAnnotationForSourceEntry.kotlinOrigin.valueArguments.map { makeLightPsiNameValuePair(it as KtValueArgument) }
.toTypedArray<PsiNameValuePair>()
}
private fun makeArrayInitializerIfExpected(pair: KtLightPsiNameValuePair): PsiAnnotationMemberValue? {
val valueArgument = pair.valueArgument
val name = valueArgument.name ?: "value"
val callEntry = getCallEntry(name) ?: return null
val valueArguments = callEntry.value.arguments
val argument = valueArguments.firstOrNull()?.getArgumentExpression() ?: return null
if (!callEntry.key.type.let { KotlinBuiltIns.isArray(it) }) return null
if (argument !is KtStringTemplateExpression && argument !is KtConstantExpression && getAnnotationName(argument) == null) {
return null
}
val parent = PsiTreeUtil.findCommonParent(valueArguments.map { it.getArgumentExpression() }) as KtElement
return KtLightPsiArrayInitializerMemberValue(parent, pair) { self ->
valueArguments.mapNotNull {
it.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
}
}
private fun makeLightPsiNameValuePair(valueArgument: KtValueArgument) = KtLightPsiNameValuePair(valueArgument, this) { self ->
makeArrayInitializerIfExpected(self)
?: self.valueArgument.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
override fun getAttributes(): Array<PsiNameValuePair> = _attributes
}
@@ -325,6 +342,7 @@ private val backendNullabilityAnnotations = arrayOf(Nullable::class.java.name, N
private fun KtElement.analyze(): BindingContext = LightClassGenerationSupport.getInstance(this.project).analyze(this)
private fun KtElement.getResolvedCall(): ResolvedCall<out CallableDescriptor>? {
if (!isValid) return null
val context = analyze()
return this.getResolvedCall(context)
}
@@ -385,7 +403,7 @@ private fun unwrapCall(callee: KtExpression): KtExpression = when (callee) {
private fun getAnnotationName(callee: KtExpression): String? {
val callee = unwrapCall(callee)
val resultingDescriptor = callee.getResolvedCall()?.resultingDescriptor
val resultingDescriptor = callee.getResolvedCall()?.resultingDescriptor
if (resultingDescriptor is ClassConstructorDescriptor) {
val ktClass = resultingDescriptor.constructedClass.source.getPsi() as? KtClass
if (ktClass?.isAnnotation() == true) return ktClass.fqName?.toString()

View File

@@ -119,7 +119,10 @@ public class KtPackageDirective extends KtModifierListOwnerStub<KotlinPlaceHolde
public void setFqName(@NotNull FqName fqName) {
if (fqName.isRoot()) {
delete();
if (!getFqName().isRoot()) {
//noinspection ConstantConditions
replace(new KtPsiFactory(getProject()).createFile("").getPackageDirective());
}
return;
}

View File

@@ -23,6 +23,8 @@ import com.intellij.psi.*
import com.intellij.psi.stubs.StubElement
import com.intellij.psi.tree.TokenSet
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.lexer.KotlinLexer
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
@@ -33,6 +35,7 @@ import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.stubs.KotlinClassOrObjectStub
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import java.lang.IllegalArgumentException
import java.util.*
// NOTE: in this file we collect only Kotlin-specific methods working with PSI and not modifying it
@@ -430,6 +433,8 @@ val KtModifierListOwner.isPublic: Boolean
fun KtModifierListOwner.visibilityModifierType(): KtModifierKeywordToken? =
visibilityModifier()?.node?.elementType as KtModifierKeywordToken?
fun KtModifierListOwner.visibilityModifierTypeOrDefault(): KtModifierKeywordToken = visibilityModifierType() ?: KtTokens.DEFAULT_VISIBILITY_KEYWORD
fun KtDeclaration.modalityModifier() = modifierFromTokenSet(MODALITY_MODIFIERS)
fun KtStringTemplateExpression.isPlain() = entries.all { it is KtLiteralStringTemplateEntry }
@@ -591,4 +596,14 @@ fun isTopLevelInFileOrScript(element: PsiElement): Boolean {
is KtBlockExpression -> parent.parent is KtScript
else -> false
}
}
fun KtModifierKeywordToken.toVisibility(): Visibility {
return when (this) {
KtTokens.PUBLIC_KEYWORD -> Visibilities.PUBLIC
KtTokens.PRIVATE_KEYWORD -> Visibilities.PRIVATE
KtTokens.PROTECTED_KEYWORD -> Visibilities.PROTECTED
KtTokens.INTERNAL_KEYWORD -> Visibilities.INTERNAL
else -> throw IllegalArgumentException("Unknown visibility modifier:$this")
}
}

View File

@@ -58,6 +58,10 @@ open class KotlinScriptDefinition(open val template: KClass<out Any>) : UserData
open val implicitReceivers: List<KType> get() = emptyList()
open val environmentVariables: List<Pair<String, KType>> get() = emptyList()
open val targetClassAnnotations: List<Annotation> get() = emptyList()
open val targetMethodAnnotations: List<Annotation> get() = emptyList()
}
object StandardScriptDefinition : KotlinScriptDefinition(ScriptTemplateWithArgs::class)

View File

@@ -222,13 +222,20 @@ internal open class ScopeBasedTowerLevel protected constructor(
private val resolutionScope: ResolutionScope
) : AbstractScopeTowerLevel(scopeTower) {
val deprecationDiagnosticOfThisScope: ResolutionDiagnostic? =
if (resolutionScope is DeprecatedLexicalScope) ResolvedUsingDeprecatedVisibility(resolutionScope, location) else null
internal constructor(scopeTower: ImplicitScopeTower, lexicalScope: LexicalScope) : this(scopeTower, lexicalScope as ResolutionScope)
override fun getVariables(
name: Name,
extensionReceiver: ReceiverValueWithSmartCastInfo?
): Collection<CandidateWithBoundDispatchReceiver> = resolutionScope.getContributedVariables(name, location).map {
createCandidateDescriptor(it, dispatchReceiver = null)
createCandidateDescriptor(
it,
dispatchReceiver = null,
specialError = deprecationDiagnosticOfThisScope
)
}
override fun getObjects(
@@ -249,8 +256,13 @@ internal open class ScopeBasedTowerLevel protected constructor(
): Collection<CandidateWithBoundDispatchReceiver> {
val result: ArrayList<CandidateWithBoundDispatchReceiver> = ArrayList()
resolutionScope.getContributedFunctionsAndConstructors(name, location, scopeTower.syntheticScopes)
.mapTo(result) { createCandidateDescriptor(it, dispatchReceiver = null) }
resolutionScope.getContributedFunctionsAndConstructors(name, location, scopeTower.syntheticScopes).mapTo(result) {
createCandidateDescriptor(
it,
dispatchReceiver = null,
specialError = deprecationDiagnosticOfThisScope
)
}
// Add constructors of deprecated classifier with an additional diagnostic
val descriptorWithDeprecation = resolutionScope.getContributedClassifierIncludeDeprecated(name, location)

View File

@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve.scopes.utils
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name
@@ -91,8 +92,20 @@ fun DeclarationDescriptor.canBeResolvedWithoutDeprecation(
location: LookupLocation
): Boolean {
for (scope in scopeForResolution.parentsWithSelf) {
val (descriptorFromCurrentScope, isDeprecated) = scope.getContributedClassifierIncludeDeprecated(name, location) ?: continue
if (descriptorFromCurrentScope == this && !isDeprecated) return true
val hasNonDeprecatedSuitableCandidate = when (this) {
// Looking for classifier: fair check via special method in ResolutionScope
is ClassifierDescriptor -> scope.getContributedClassifierIncludeDeprecated(name, location)
?.let { it.descriptor == this && !it.isDeprecated }
// Looking for member: heuristically check only one case, when another descriptor visible through explicit import
is VariableDescriptor -> (scope as? ImportingScope)?.getContributedVariables(name, location)?.any { it == this }
is FunctionDescriptor -> (scope as? ImportingScope)?.getContributedFunctions(name, location)?.any { it == this }
else -> null
}
if (hasNonDeprecatedSuitableCandidate == true) return true
}
return false

View File

@@ -89,8 +89,10 @@ class DescriptorSerializer private constructor(
}
}
for (descriptor in classDescriptor.constructors) {
builder.addConstructor(constructorProto(descriptor))
if (!DescriptorUtils.isAnonymousObject(classDescriptor) && classDescriptor.kind != ClassKind.ENUM_ENTRY) {
for (descriptor in classDescriptor.constructors) {
builder.addConstructor(constructorProto(descriptor))
}
}
val callableMembers =

View File

@@ -3,7 +3,7 @@ This build uses internal compiler arguments:
-XXLanguage:-InlineClasses
This mode is strictly prohibited for production use,
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!

View File

@@ -3,7 +3,7 @@ This build uses internal compiler arguments:
-XXLanguage:+
This mode is strictly prohibited for production use,
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!

View File

@@ -3,7 +3,7 @@ This build uses internal compiler arguments:
-XXLanguage:+InlineClasses
This mode is strictly prohibited for production use,
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!

View File

@@ -3,7 +3,7 @@ This build uses internal compiler arguments:
-XXLanguage:InlineClasses
This mode is strictly prohibited for production use,
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!

View File

@@ -3,7 +3,7 @@ This build uses internal compiler arguments:
-XXLanguage:+UnknownFeature
This mode is strictly prohibited for production use,
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!

View File

@@ -3,7 +3,7 @@ This build uses internal compiler arguments:
-XXLanguage:+SoundSmartCastsAfterTry
This mode is strictly prohibited for production use,
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!

View File

@@ -5,4 +5,9 @@ public class Annotated {
public void bar(@MyMigrationNonnull String x) {
}
}
@MyNullable
public String nullable() {
return null;
}
}

View File

@@ -0,0 +1,15 @@
import javax.annotation.*;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.annotation.meta.TypeQualifierNickname;
import javax.annotation.meta.When;
@Documented
@TypeQualifierNickname
@Nonnull(when = When.MAYBE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyNullable {
}

View File

@@ -1,5 +1,5 @@
warning: argument -Xjsr305-annotations is deprecated. Please use -Xjsr305 instead
compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin
compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: type mismatch: inferred type is Nothing? but String was expected
a.foo(null)
^
OK

View File

@@ -1,4 +1,5 @@
fun test(annotated: Annotated) {
annotated.foo(null)
annotated.bar(null)
}
annotated.nullable().length
}

View File

@@ -1,4 +1,7 @@
compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin
compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: type mismatch: inferred type is Nothing? but String was expected
annotated.foo(null)
^
compiler/testData/cli/jvm/jsr305Migration.kt:4:5: warning: unsafe use of a nullable receiver of type String?
annotated.nullable().length
^
OK

View File

@@ -1,4 +1,7 @@
compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin
compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: type mismatch: inferred type is Nothing? but String was expected
annotated.foo(null)
^
compiler/testData/cli/jvm/jsr305Migration.kt:4:5: warning: unsafe use of a nullable receiver of type String?
annotated.nullable().length
^
OK

View File

@@ -1,7 +1,10 @@
compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin
compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: type mismatch: inferred type is Nothing? but String was expected
annotated.foo(null)
^
compiler/testData/cli/jvm/jsr305Migration.kt:3:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin
compiler/testData/cli/jvm/jsr305Migration.kt:3:19: warning: type mismatch: inferred type is Nothing? but String was expected
annotated.bar(null)
^
compiler/testData/cli/jvm/jsr305Migration.kt:4:5: warning: unsafe use of a nullable receiver of type String?
annotated.nullable().length
^
OK

View File

@@ -1,4 +1,4 @@
compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin
compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: type mismatch: inferred type is Nothing? but String was expected
a.foo(null)
^
OK

View File

@@ -1,4 +1,4 @@
compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin
compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: type mismatch: inferred type is Nothing? but String was expected
a.foo(null)
^
OK

View File

@@ -1,2 +1,2 @@
error: specify path to the script file (.kts) as the first argument
error: specify path to the script file as the first argument
COMPILATION_ERROR

View File

@@ -1,2 +1,2 @@
error: specify path to the script file (.kts) as the first argument
error: specify path to the script file as the first argument
COMPILATION_ERROR

View File

@@ -6,7 +6,9 @@ $TEMP_DIR$
-Xjsr305=@hello\:warning
-Xjsr305=@hello\:warn
-Xjsr305=@hello\:ignore
-Xjsr305=@hello\:warn
-Xjsr305=strict
-Xjsr305=ignore
-Xjsr305=under-migration\:ignore
-Xjsr305=under-migration\:strict
-Xjsr305=under-migration\:ignore

View File

@@ -2,7 +2,6 @@ warning: option 'enable' for -Xjsr305 flag is deprecated. Please use 'strict' in
error: unrecognized -Xjsr305 value: under-migration:stct
error: unrecognized -Xjsr305 value: @hello:warning
error: conflict duplicating -Xjsr305 value: @hello:warn, @hello:ignore
error: conflict duplicating -Xjsr305 value: strict, strict
error: conflict duplicating -Xjsr305 value: strict, ignore
error: conflict duplicating -Xjsr305 value: under-migration:ignore, under-migration:strict
COMPILATION_ERROR

View File

@@ -0,0 +1,49 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// WITH_COROUTINES
// COMMON_COROUTINES_TEST
// FILE: I.kt
interface I {
suspend fun foo(x: Int): String
suspend fun bar(x: Int): String
}
// FILE: JavaClass.java
public class JavaClass implements I {
@Override
public String foo(int x, COROUTINES_PACKAGE.Continuation<? super String> continuation) {
return "O";
}
@Override
public Object bar(int x, COROUTINES_PACKAGE.Continuation<? super String> continuation) {
return foo(x, continuation);
}
}
// FILE: main.kt
import helpers.*
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
class K : JavaClass() {
override suspend fun foo(x: Int): String = super.foo(x) + suspendCoroutine { it.resume("K") }
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = "fail"
builder {
// Changing the call to 'K().bar(1)' doesn't work because of KT-25036
result = K().foo(1)
}
return result
}

View File

@@ -0,0 +1,39 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// WITH_COROUTINES
// COMMON_COROUTINES_TEST
// FILE: I.kt
interface I {
suspend fun foo(x: Int): String
}
// FILE: JavaClass.java
public class JavaClass implements I {
@Override
public Object foo(int x, COROUTINES_PACKAGE.Continuation<? super String> continuation) {
continuation.resume("OK");
return COROUTINES_PACKAGE.intrinsics.IntrinsicsKt.getCOROUTINE_SUSPENDED();
}
}
// FILE: main.kt
import helpers.*
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = "fail"
builder {
result = JavaClass().foo(1)
}
return result
}

View File

@@ -1,49 +1,34 @@
// !LANGUAGE: +MultiPlatformProjects
// !USE_EXPERIMENTAL: kotlin.ExperimentalMultiplatform
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JS_IR
// WITH_RUNTIME
// FILE: common.kt
// MODULE: library
// FILE: expected.kt
package a
@OptionalExpectation
expect annotation class Anno(val s: String)
expect annotation class A(val x: Int)
// FILE: jvm.kt
@OptionalExpectation
expect annotation class B(val s: String)
import java.lang.reflect.AnnotatedElement
// FILE: actual.kt
@Anno("Foo")
class Foo @Anno("<init>") constructor(@Anno("x") x: Int) {
@Anno("bar")
fun bar() {}
package a
@Anno("getX")
var x = x
@Anno("setX")
set
actual annotation class A(actual val x: Int)
@Anno("Nested")
interface Nested
}
// MODULE: main(library)
// FILE: main.kt
private fun check(element: AnnotatedElement) {
check(element.annotations)
}
package usage
private fun check(annotations: Array<Annotation>) {
val filtered = annotations.filterNot { it.annotationClass.java.name == "kotlin.Metadata" }
if (filtered.isNotEmpty()) {
throw AssertionError("Annotations should be empty: $filtered")
}
}
import a.A
import a.B
@A(42)
@B("OK")
fun box(): String {
val foo = Foo::class.java
check(foo)
check(Foo.Nested::class.java)
check(foo.declaredMethods.single { it.name == "bar" })
check(foo.declaredMethods.single { it.name == "getX" })
check(foo.declaredMethods.single { it.name == "setX" })
check(foo.constructors.single())
check(foo.constructors.single().parameterAnnotations.single())
return "OK"
}

View File

@@ -0,0 +1,49 @@
// !LANGUAGE: +MultiPlatformProjects
// !USE_EXPERIMENTAL: kotlin.ExperimentalMultiplatform
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: common.kt
@OptionalExpectation
expect annotation class Anno(val s: String)
// FILE: jvm.kt
import java.lang.reflect.AnnotatedElement
@Anno("Foo")
class Foo @Anno("<init>") constructor(@Anno("x") x: Int) {
@Anno("bar")
fun bar() {}
@Anno("getX")
var x = x
@Anno("setX")
set
@Anno("Nested")
interface Nested
}
private fun check(element: AnnotatedElement) {
check(element.annotations)
}
private fun check(annotations: Array<Annotation>) {
val filtered = annotations.filterNot { it.annotationClass.java.name == "kotlin.Metadata" }
if (filtered.isNotEmpty()) {
throw AssertionError("Annotations should be empty: $filtered")
}
}
fun box(): String {
val foo = Foo::class.java
check(foo)
check(Foo.Nested::class.java)
check(foo.declaredMethods.single { it.name == "bar" })
check(foo.declaredMethods.single { it.name == "getX" })
check(foo.declaredMethods.single { it.name == "setX" })
check(foo.constructors.single())
check(foo.constructors.single().parameterAnnotations.single())
return "OK"
}

View File

@@ -0,0 +1,47 @@
// TODO: muted automatically, investigate should it be ran for JS_IR or not
// IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
import java.lang.Integer.MAX_VALUE as MaxI
import java.lang.Integer.MIN_VALUE as MinI
import java.lang.Byte.MAX_VALUE as MaxB
import java.lang.Byte.MIN_VALUE as MinB
import java.lang.Short.MAX_VALUE as MaxS
import java.lang.Short.MIN_VALUE as MinS
import java.lang.Long.MAX_VALUE as MaxL
import java.lang.Long.MIN_VALUE as MinL
import java.lang.Character.MAX_VALUE as MaxC
import java.lang.Character.MIN_VALUE as MinC
fun box(): String {
val list1 = ArrayList<Int>()
val range1 = 0 downTo MaxI step 3
for (i in range1) {
list1.add(i)
if (list1.size > 23) break
}
if (list1 != listOf<Int>()) {
return "Wrong elements for 0 downTo MaxI step 3: $list1"
}
val list2 = ArrayList<Long>()
val range2 = 0 downTo MaxL step 3
for (i in range2) {
list2.add(i)
if (list2.size > 23) break
}
if (list2 != listOf<Long>()) {
return "Wrong elements for 0 downTo MaxL step 3: $list2"
}
return "OK"
}

View File

@@ -0,0 +1,47 @@
// TODO: muted automatically, investigate should it be ran for JS_IR or not
// IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
import java.lang.Integer.MAX_VALUE as MaxI
import java.lang.Integer.MIN_VALUE as MinI
import java.lang.Byte.MAX_VALUE as MaxB
import java.lang.Byte.MIN_VALUE as MinB
import java.lang.Short.MAX_VALUE as MaxS
import java.lang.Short.MIN_VALUE as MinS
import java.lang.Long.MAX_VALUE as MaxL
import java.lang.Long.MIN_VALUE as MinL
import java.lang.Character.MAX_VALUE as MaxC
import java.lang.Character.MIN_VALUE as MinC
fun box(): String {
val list1 = ArrayList<Int>()
val range1 = 0..MinI step 3
for (i in range1) {
list1.add(i)
if (list1.size > 23) break
}
if (list1 != listOf<Int>()) {
return "Wrong elements for 0..MinI step 3: $list1"
}
val list2 = ArrayList<Long>()
val range2 = 0L..MinL step 3
for (i in range2) {
list2.add(i)
if (list2.size > 23) break
}
if (list2 != listOf<Long>()) {
return "Wrong elements for 0L..MinL step 3: $list2"
}
return "OK"
}

View File

@@ -0,0 +1,45 @@
// TODO: muted automatically, investigate should it be ran for JS_IR or not
// IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
import java.lang.Integer.MAX_VALUE as MaxI
import java.lang.Integer.MIN_VALUE as MinI
import java.lang.Byte.MAX_VALUE as MaxB
import java.lang.Byte.MIN_VALUE as MinB
import java.lang.Short.MAX_VALUE as MaxS
import java.lang.Short.MIN_VALUE as MinS
import java.lang.Long.MAX_VALUE as MaxL
import java.lang.Long.MIN_VALUE as MinL
import java.lang.Character.MAX_VALUE as MaxC
import java.lang.Character.MIN_VALUE as MinC
fun box(): String {
val list1 = ArrayList<Int>()
for (i in 0 downTo MaxI step 3) {
list1.add(i)
if (list1.size > 23) break
}
if (list1 != listOf<Int>()) {
return "Wrong elements for 0 downTo MaxI step 3: $list1"
}
val list2 = ArrayList<Long>()
for (i in 0 downTo MaxL step 3) {
list2.add(i)
if (list2.size > 23) break
}
if (list2 != listOf<Long>()) {
return "Wrong elements for 0 downTo MaxL step 3: $list2"
}
return "OK"
}

View File

@@ -0,0 +1,45 @@
// TODO: muted automatically, investigate should it be ran for JS_IR or not
// IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
import java.lang.Integer.MAX_VALUE as MaxI
import java.lang.Integer.MIN_VALUE as MinI
import java.lang.Byte.MAX_VALUE as MaxB
import java.lang.Byte.MIN_VALUE as MinB
import java.lang.Short.MAX_VALUE as MaxS
import java.lang.Short.MIN_VALUE as MinS
import java.lang.Long.MAX_VALUE as MaxL
import java.lang.Long.MIN_VALUE as MinL
import java.lang.Character.MAX_VALUE as MaxC
import java.lang.Character.MIN_VALUE as MinC
fun box(): String {
val list1 = ArrayList<Int>()
for (i in 0..MinI step 3) {
list1.add(i)
if (list1.size > 23) break
}
if (list1 != listOf<Int>()) {
return "Wrong elements for 0..MinI step 3: $list1"
}
val list2 = ArrayList<Long>()
for (i in 0L..MinL step 3) {
list2.add(i)
if (list2.size > 23) break
}
if (list2 != listOf<Long>()) {
return "Wrong elements for 0L..MinL step 3: $list2"
}
return "OK"
}

View File

@@ -1,12 +1,11 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JVM_IR, JS_IR, JS, NATIVE
// WITH_REFLECT
// FULL_JDK
// See KT-11258 Incorrect resolution sequence for Java field
//SHOULD BE deleted after KT-16616 fix
// See KT-11258, KT-16616
import java.util.*
import kotlin.test.assertEquals
fun box(): String {
listOf(
@@ -22,5 +21,8 @@ fun box(): String {
).map {
it.members.map(Any::toString)
}
assertEquals(1, Collection<Any>::size.getter(listOf(1)))
return "OK"
}

View File

@@ -0,0 +1,13 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE
// WITH_REFLECT
import kotlin.test.assertEquals
enum class E { X, Y, Z }
fun box(): String {
assertEquals(11, E::class.members.size)
assertEquals("Y", E::name.call(E.Y))
assertEquals(2, E::ordinal.call(E.Z))
return "OK"
}

View File

@@ -0,0 +1,10 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE
// WITH_REFLECT
import kotlin.test.assertEquals
fun box(): String {
String::class.members
assertEquals(2, String::length.call("OK"))
return "OK"
}

View File

@@ -17,6 +17,7 @@ fun box(): String {
assertTrue(Interface::class.constructors.isEmpty())
assertTrue(Obj::class.constructors.isEmpty())
assertTrue(C.Companion::class.constructors.isEmpty())
assertTrue(object {}::class.constructors.isEmpty())
return "OK"
}

View File

@@ -0,0 +1,24 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE
// WITH_REFLECT
import kotlin.test.assertEquals
enum class TestEnum(val id: String? = null) {
ENUM1(id = "enum1_id"),
ENUM2(id = "enum2_id") {
override fun test() {
ENUM1.test()
}
};
open fun test() {
}
}
fun box(): String {
assertEquals(listOf("fun <init>(kotlin.String?): TestEnum"), TestEnum.ENUM1::class.constructors.map { it.toString() })
assertEquals(listOf(), TestEnum.ENUM2::class.constructors.map { it.toString() })
return "OK"
}

View File

@@ -48,11 +48,13 @@ fun box(): String {
val p4 = TwoSecondaries::class.primaryConstructor
assertNull(p4)
assertNotNull(En::class.primaryConstructor) // TODO: maybe primaryConstructor should be null for enum classes
assertNotNull(En::class.primaryConstructor)
assertNull(I::class.primaryConstructor)
assertNull(O::class.primaryConstructor)
assertNull(C.Companion::class.primaryConstructor)
assertNull(object {}::class.primaryConstructor)
return "OK"
}

View File

@@ -0,0 +1,15 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE
// WITH_REFLECT
import kotlin.test.assertEquals
enum class E { X, Y, Z }
fun box(): String {
assertEquals("fun values(): kotlin.Array<E>", E::values.toString())
assertEquals(listOf(E.X, E.Y, E.Z), E::values.call().toList())
assertEquals("fun valueOf(kotlin.String): E", E::valueOf.toString())
assertEquals(E.Y, E::valueOf.call("Y"))
return "OK"
}

View File

@@ -0,0 +1,37 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.KClass
import kotlin.reflect.full.memberFunctions
import kotlin.reflect.jvm.javaMethod
import kotlin.test.assertEquals
annotation class A
interface I
class C
interface MyCustomMembers {
fun equals(): Boolean
fun hashCode(hehe: Int): Int
fun toString(hehe: String): Any
}
interface MyCloneable : Cloneable
fun KClass<*>.functions() = memberFunctions.map { it.javaMethod!!.name }.sorted()
fun box(): String {
assertEquals(listOf("equals", "hashCode", "toString"), A::class.functions())
assertEquals(listOf("equals", "hashCode", "toString"), I::class.functions())
assertEquals(listOf("equals", "hashCode", "toString"), C::class.functions())
assertEquals(
listOf("equals", "equals", "hashCode", "hashCode", "toString", "toString"),
MyCustomMembers::class.functions()
)
// TODO: KT-22923
// assertEquals(listOf("clone", "equals", "hashCode", "toString"), MyCloneable::class.functions())
return "OK"
}

View File

@@ -0,0 +1,25 @@
// IGNORE_BACKEND: JVM_IR, JS_IR, JS, NATIVE
// FULL_JDK
// WITH_REFLECT
import kotlin.test.assertEquals
import java.util.*
fun assertToString(s: String, x: Any) {
assertEquals(s, x.toString())
}
fun box(): String {
assertToString("fun kotlin.collections.Map<K, V>.getOrDefault(K, V): V", Map<*, *>::getOrDefault)
assertToString("fun java.util.HashMap<K, V>.getOrDefault(K, V): V", HashMap<*, *>::getOrDefault)
// TODO: uncomment once KT-11754 is fixed
// assertToString("", MutableList<*>::removeAt)
assertToString("fun kotlin.collections.Collection<E>.contains(E): kotlin.Boolean", Collection<*>::contains)
assertToString("fun kotlin.collections.Set<E>.contains(E): kotlin.Boolean", Set<*>::contains)
assertToString("fun kotlin.collections.Collection<E>.isEmpty(): kotlin.Boolean", Collection<*>::isEmpty)
return "OK"
}

View File

@@ -1,29 +0,0 @@
// IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// WITH_REFLECT
// FULL_JDK
// See KT-11258 Incorrect resolution sequence for Java field
// TODO: enable this test on JVM, see KT-16616
// IGNORE_BACKEND: JVM
import java.util.*
fun box(): String {
listOf(
ArrayList::class,
LinkedList::class,
AbstractList::class,
HashSet::class,
TreeSet::class,
HashMap::class,
TreeMap::class,
AbstractMap::class,
AbstractMap.SimpleEntry::class
).map {
it.members.map(Any::toString)
}
return "OK"
}

View File

@@ -0,0 +1,39 @@
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: JavaClass.java
public class JavaClass {
public static void run(Runnable l) {
l.run();
}
public static void s(Runnable a, Runnable onError) {
a.run();
}
}
// FILE: main.kt
var state = ""
fun unit() {}
class B {
val s = mutableListOf<Unit>()
init {
s.add(JavaClass.s({ state += "O" }, ::unit))
Any().apply {
JavaClass.run {
s.add(JavaClass.s({ state += "K" }, ::unit))
}
}
}
}
fun box(): String {
B()
return state
}

View File

@@ -1,3 +1,10 @@
@java.lang.annotation.Retention
@kotlin.Metadata
@kotlin.OptionalExpectation
annotation class Anno {
public abstract method s(): java.lang.String
}
@kotlin.Metadata
public interface Foo$Nested {
inner class Foo$Nested

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