Commit Graph

1420 Commits

Author SHA1 Message Date
Tamas Vajk
8b1a7c845c Fix return type of <clinit> methods 2022-05-12 22:37:06 +01:00
Tamas Vajk
59581439dd Fix colliding property accessor and function names 2022-05-12 22:37:06 +01:00
Tamas Vajk
857a74cf14 Adjust class label generation to handle classes in field initializers 2022-05-12 22:37:06 +01:00
Chris Smowton
2600dcd182 Fix extracting type accesses relating to proprerty getters/setters and SAM-converted methods
These should be handled the same as regular methods: extract type accesses for parameters and methods only if we're extracting "from source", i.e. at some point we're descended from extractFileContents.
2022-05-12 22:37:06 +01:00
Chris Smowton
301fa11450 Only extract parameter and method type-accesses once
Previously we extracted them whenever something was non-external, but this led to re-extraction when an instance of a generic type defined in source was extracted multiple times.
2022-05-12 22:37:06 +01:00
Chris Smowton
8d970a3cbd Don't extract private members of instantiated or external classes
This is both consistent with the Java extractor's behaviour, and prevents us from trying to refer to anonymous types (e.g. anonymous objects that directly initialize properties) out of scope.
2022-05-12 22:37:06 +01:00
Tamas Vajk
fbae0f5053 Revert dataflow changes, extract actual iterator function 2022-05-12 22:37:06 +01:00
Chris Smowton
7e17074b41 Allow arithmetic functions not mapping to Java equivalents 2022-05-12 22:36:28 +01:00
Chris Smowton
b1849f5f0a Expand error message 2022-05-12 22:36:28 +01:00
Chris Smowton
16af811b69 Allow imprecise matching for Kotlin -> Java method translation
This allows the particular case of Collection.toArray(IntFunction<T>) to match, since both Java and Kotlin functions take an IntFunction<T> but they use different function-local type variables.

This would also allow toArray(Array<T>) to work similarly.
2022-05-12 22:36:28 +01:00
Chris Smowton
71d2e7be3e Don't replace own callables, and use a more exact replacement-finding test 2022-05-12 22:36:28 +01:00
Chris Smowton
ce87a89009 Replace Map and similar functions with their Java cousins
This didn't appear to be necessary because the Kotlin and Java versions of Map (for example) are designed to be compatible, but in certain cases their functions have the same erasure but not the same type (e.g. Map.getOrDefault(K, V) vs. Map.getOrDefault(Object, V).

These have different erasures which was leading to callable-binding inconsistencies.
2022-05-12 22:36:28 +01:00
Tamas Vajk
fa0bd0366c Fix extension property labels 2022-05-12 22:36:28 +01:00
Tamas Vajk
25fce5f6bb Identify data classes during extraction 2022-05-12 22:36:28 +01:00
Chris Smowton
1e78f2893c Add test for special method getters 2022-05-12 22:36:28 +01:00
Chris Smowton
12e3401ae0 Map special getters onto their correct JVM names
These include Collection.size() for example, which has a Kotlin property called `size` but whose getter is not named `getSize()`.

These would normally be accounted for using `@JvmName`, but some core methods are lowered by a special compiler pass instead.
2022-05-12 22:36:27 +01:00
Chris Smowton
cb6941d212 Account for JVM type equivalency when recognising unspecialised types
(As before, these are not really unspecialised, they are instantiated by their own type parameters, but this replicates the behaviour of the Java extractor)
2022-05-12 22:36:27 +01:00
Ian Lynagh
02101fab6a Kotlin: Don't use capture_output or text
Older python versions don't support them
2022-05-12 14:08:19 +01:00
Tamas Vajk
e8b3bf55fa Code quality improvements 2022-05-10 19:51:30 +01:00
Tamas Vajk
465a85bb8c Explicitly check if a when expression is in the expected &&/|| form 2022-05-10 19:51:30 +01:00
Tamas Vajk
3af8273620 Modify extraction of &&/|| to resugar it from when expression 2022-05-10 19:51:30 +01:00
Tamas Vajk
b66a3141f6 Extract functions using their name from JvmName annotation 2022-05-10 19:51:30 +01:00
Tamas Vajk
a24753f552 Extract final modifier on local variables 2022-05-10 19:51:30 +01:00
Tamas Vajk
4efb87a7dd Extract enum entry initializers 2022-05-10 19:51:30 +01:00
Tamas Vajk
fc5229a0a5 Extract type access expression for static field access in initializer 2022-05-10 19:51:29 +01:00
Tamas Vajk
c6a75957e9 Fix expected files, fix type access extraction of file level static declarations 2022-05-10 19:51:29 +01:00
Tamas Vajk
1e529b2563 Add missing type access expression for static field accesses 2022-05-10 19:51:29 +01:00
Tamas Vajk
f43296a157 Extract type access for enum value access 2022-05-10 19:51:29 +01:00
Tamas Vajk
b5c8d29e40 Extract enum field declarations 2022-05-10 19:51:29 +01:00
Tamas Vajk
d6cbcdc847 Extract type access expression for parameter types 2022-05-10 19:51:29 +01:00
Tamas Vajk
f557719fe5 Extract type access expression for function return types 2022-05-10 19:51:29 +01:00
Chris Smowton
23e3bbea73 Fix: don't treat local classes as unspecialised
This shouldn't matter either way since they can't be subject to external references
2022-05-10 19:51:29 +01:00
Chris Smowton
4477482990 Share a class instance, not just a label 2022-05-10 19:51:29 +01:00
Chris Smowton
d63124a761 Extract a generic specialisation using its own type parameters in the same order like an unbound type
This replicates an oddity in the Java extractor that it doesn't differentiate a specialisation Generic<T1, T2, ...> from the unbound type, if T1, T2, ... are Generic's declared type variables occurring in the same order. For example, in `class MyList<T> { void addAll(MyList<T> param) { ... } }`, the type of `param` is an instantiated type, but
gets extracted as an unbound type. This commit can be reverted (except for the improvement to isUnspecialised) if/when that is fixed.
2022-05-10 19:51:29 +01:00
Chris Smowton
375199508e Always extract static initializers if a class has static members
This may not be necessary for anonymous objects, but it is certainly unrelated to `init { ... }` blocks.
2022-05-10 19:51:29 +01:00
Chris Smowton
e21a60bb4b Only extract anonymous init blocks in an instance initializer context 2022-05-10 19:51:29 +01:00
Chris Smowton
a317dc4246 Extract field initializers 2022-05-10 19:51:29 +01:00
Chris Smowton
5219ead4d4 Plugin version selection: fix test polarity and use integer not string comparison
(Otherwise we'll think that 1.6.10 comes before 1.6.9, for example.) This now implements the desired test: pick a version that exactly matches major and minor versions and which is the least patchlevel that is >= the target compiler.
2022-05-10 19:51:28 +01:00
Chris Smowton
d8b163a589 Fix running on patchlevel versions below the highest of that minor version
(For example, picking 1.6.10 to match the host kotlinc when both 1.6.10 and 1.6.20 are available)
2022-05-10 19:51:28 +01:00
Chris Smowton
bfe3722018 Extract synthetic coroutine classes 2022-05-10 19:51:28 +01:00
Chris Smowton
a740ead56d Populate files table once per file, per trap file
Otherwise there's a chance the other trap file we're relying upon to populate the files table on our behalf gets overwritten (e.g. superceded by a newer .class file or more appropriate extractor) and we end up with a dangling reference.

This adds only populating the tables when the label is new, to avoid emitting files entries every single time a generic class specialisation is mentioned.
2022-05-10 19:51:28 +01:00
Tamas Vajk
cdc7ed0e14 Extract container of adapter function as compiler generated 2022-05-10 19:51:28 +01:00
Tamas Vajk
fc66b73e3b Extract override modifier for lambda and reflection-like constructs 2022-05-10 19:51:28 +01:00
Tamas Vajk
505ccbbcf6 Extract override modifier 2022-05-10 19:51:28 +01:00
Tamas Vajk
ca99cb4999 Code quality improvements 2022-05-10 19:51:27 +01:00
Ian Lynagh
400654d326 Kotlin: Add latest-url to kotlin_plugin_versions.py 2022-05-10 19:51:27 +01:00
Tamas Vajk
4e93134225 Add 1.6.20 support 2022-05-10 19:51:27 +01:00
Ian Lynagh
c1629530e5 Kotlin: Fix build on Windows 2022-05-10 19:51:27 +01:00
Chris Smowton
239aab67b6 Populate the files table for generic class instances
This is because different instances might see the code in different locations (e.g., the class file exists in more than one jar) or with no location (seen as a .java file passed to kotlinc).

While I'm there, improve the order of checks and fix a trivial bug in withFileOfClass
2022-05-10 19:51:26 +01:00
Chris Smowton
db9ab22437 Erasure: produce raw types, not unbound types
This affects the trap labels for methods, and therefore consistency with the Java extractor.

TODO: check whether we can unify `erase` and `toRawType` entirely.
2022-05-10 19:51:26 +01:00