Commit Graph

278 Commits

Author SHA1 Message Date
Ian Lynagh
1efecc099c Kotlin: Avoid infinite recursion when extracting recursive interfaces 2025-10-31 13:42:43 +00:00
Ian Lynagh
156ddd3fae Kotlin: Log our verbosity level
This happens at `info` level, which is logged by default.
2024-10-11 14:24:25 +01:00
Ian Lynagh
68f267798e Kotlin: Add support for path transformers 2024-02-01 18:07:47 +00:00
Ian Lynagh
bf611feab3 Kotlin: Reformat code
Using:
    java -jar ktfmt-0.46-jar-with-dependencies.jar --kotlinlang-style java/kotlin-extractor/**/*.kt
2024-01-09 15:33:41 +00:00
Ian Lynagh
95f336c05b Merge pull request #14393 from igfoo/igfoo/no1.4
Kotlin: Remove 1.4 compatibility
2024-01-09 12:20:15 +00:00
Ian Lynagh
0a0ce1f202 Kotlin: Log when we start and finish writing to TRAP files 2023-10-16 16:14:23 +01:00
Ian Lynagh
adb47399c7 Kotlin: Improve support for TRAP compression options
While you could control compression with
    CODEQL_EXTRACTOR_JAVA_OPTION_TRAP_COMPRESSION
before, most TRAP files used gzip regardless for compatibility with the
Java extractor. Now Java understands the option too we can use it for
shared TRAP files.
2023-10-12 18:13:06 +01:00
Ian Lynagh
d34b85cf03 Kotlin: Remove 1.4 compatibility
We now only build with >= 1.5
2023-10-06 15:17:32 +01:00
Ian Lynagh
4d3863461e Kotlin: Determine our compression method later
This way, we already have a logger at the point that we want to log a
warning.
2023-10-04 18:32:12 +01:00
Ian Lynagh
cc63bb55c2 Kotlin: Change how we handle not supporting Brotli
This removes the potential for impossible cases.
2023-10-04 18:32:11 +01:00
Ian Lynagh
c67cc23e07 Kotlin: Write usesK2 information to the database 2023-08-22 12:37:01 +01:00
Ian Lynagh
bfd0a19d85 Kotlin: Define DiagnosticTrapWriter, for type safety
In some cases, we were writing diagnostics to TRAP files where they
shouldn't be written. Such TRAP files don't define #compilation, so TRAP
import gave errors.

Now we use DiagnosticTrapWriter to get the type system to check that we
are writing diagnostics to the right place.
2023-06-21 18:38:27 +01:00
Chris Smowton
9e0eb56d77 Extract repeatable annotation container types, including synthetic containers 2022-12-09 10:33:03 +00:00
Ian Lynagh
7d54b542b5 Kotlin: Put extractor name in a resource rather than generating code 2022-11-11 14:04:14 +00:00
Ian Lynagh
2fb78565a7 Kotlin: Write version information to the database 2022-11-10 20:29:04 +00:00
Ian Lynagh
2e6d6e1538 Merge pull request #10894 from igfoo/igfoo/psi
Kotlin: Refactor PSI handling
2022-10-21 11:43:49 +01:00
Ian Lynagh
74a4061508 Kotlin: Refactor PSI handling
We were giving warnings about comments, when we were actually trying to
populate numlines.
2022-10-19 18:02:24 +01:00
Chris Smowton
7ba9a31766 Use US spelling 2022-10-19 10:41:29 +01:00
Josh Soref
0bc19506e7 spelling: reinitialised
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-10-19 04:59:16 -04:00
Ian Lynagh
f0eabd4675 Merge pull request #10759 from igfoo/igfoo/numlines2
kotlin: Populate numlines
2022-10-14 15:39:40 +01:00
Ian Lynagh
7d22bdb7e1 Windows fixes 2022-10-13 16:16:54 +01:00
Ian Lynagh
bca2586903 Kotlin: Populate numfiles 2022-10-10 19:00:05 +01:00
Chris Smowton
d3d3ce843a Kotlin: Implement JvmOverloads annotation
This generates functions that omit parameters with default values, rightmost first, such that Java can achieve a similar experience to Kotlin (which represents calls internally as if the default was supplied explicitly, and/or uses a $default method that supplies the needed arguments).

A complication: combining JvmOverloads with JvmStatic means that both the companion object and the surrounding class get overloads.
2022-10-03 15:28:55 +01:00
Ian Lynagh
2f8151d8d2 Kotlin: Remove a throw statement
We have a way to carry on here, so we may as well do so
2022-09-13 13:51:00 +01:00
Ian Lynagh
62779944e8 Kotlin: Compress TRAP files
The Kotlin extractor can now be told to write TRAP with no compression,
gzip compression or Brotli compression - although Brotli is not yet
supported and it will fall back to gzip.

The invocation TRAP file is a bit more complicated, as it's already been
started before the extractor starts. For now that continues to always be
uncompressed.
2022-08-19 12:47:10 +01:00
Tamas Vajk
c722921276 Kotlin: substitute fake Parcelize functions with their real equivalent ones 2022-06-15 10:35:48 +02:00
Ian Lynagh
d2cb1aa89c Merge pull request #9218 from igfoo/igfoo/geninst
Kotlin: Avoid "generic specialisation" label collisions
2022-05-20 11:42:22 +01:00
Ian Lynagh
e153f30c01 Kotlin: Avoid "generic specialisation" label collisions
We had a global set of labels for generic specialisations that we'd
extracted, but these labels could contain references to other labels,
and thus you can get false collisions between labels for different TRAP
files. We now only keep the set for a single TRAP file, and live with
the extra TRAP duplication that we get from that.
2022-05-19 17:29:41 +01:00
Ian Lynagh
9e3cde001a Kotlin: Tweak logging
Makes it easier to filter out the peak memory info
2022-05-19 16:59:52 +01:00
Ian Lynagh
9b40724dcb Kotlin: Log peak memory usge before and after extractor
Ideally this would be in a more JSON-friendly format, and also in the
database, but this at least makes the information available.
2022-05-19 13:36:11 +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
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
Ian Lynagh
270beecef5 Kotlin: Write diagnostics to the write TRAP file
When a TRAP writer wrote a warning, it was going to the wrong TRAP
file.
2022-05-10 19:51:23 +01:00
Ian Lynagh
62ce28eb68 Kotlin: Populate diagnostic_for 2022-05-10 19:51:23 +01:00
Ian Lynagh
47d8eb458e Kotlin: Improve top-level error handling 2022-05-10 19:51:23 +01:00
Ian Lynagh
a653054eb3 Kotlin: Make sure the context is empty when it should be 2022-05-10 19:51:23 +01:00
Ian Lynagh
43a92f60b2 Kotlin: Give context to diagnostics
We now get e.g.

[2022-03-09 13:59:04 K] [ERROR] Diagnostic(com.github.codeql.KotlinUsesExtractor.useSimpleType(KotlinUsesExtractor.kt:505)): Type alias ignored for <root>.Test<kotlin.String>{ <root>.Alias1<kotlin.String> }
  ...while extracting a function at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:7:1:7:41
  ...while extracting a function if real at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:7:1:7:41
  ...while extracting a declaration at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:7:1:7:41
  ...while extracting a file at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:1:1:8:0
2022-05-10 19:51:22 +01:00
Ian Lynagh
ea74803053 Kotlin: Add a comment 2022-05-10 19:51:22 +01:00
Ian Lynagh
84c7b2310a Kotlin: Catch all Throwables
We want to try to continue even if we hit a stack overflow or an
assertion error.
2022-05-10 19:51:21 +01:00
Chris Smowton
1835022c84 Extract external file declarations to individual trap files 2022-05-10 19:51:21 +01:00
Ian Lynagh
aad9e5601a Kotlin: Keep our own stack of extractor contexts
For now we only use its length, but in the future we might use this to
give more informatino about the cause of warnings.
2022-05-10 19:51:21 +01:00
Ian Lynagh
cffcff93a8 Kotlin: Add a log message 2022-05-10 19:51:21 +01:00
Ian Lynagh
af7d809b8a Kotlin: Log to a file, not stdout
We shouldn't interfere with a build's stdout
2022-05-10 19:51:20 +01:00
Ian Lynagh
a112e9ab5c Kotlin: Add conditional dumping 2022-05-10 19:51:20 +01:00
Ian Lynagh
cc0f5d8700 Kotlin: KotlinExtractorExtension tweaks
Added/fixed a load of comments.
Adjusted some function visibilities.
2022-05-10 19:51:20 +01:00
Chris Smowton
f3b92e7549 Explain why there is no syntheticToRealPropertyMap 2022-05-10 19:51:19 +01:00
Chris Smowton
110a2c7b87 Try our best to fix up the truncated class graph exposed by the Kotlin Android extensions plugin 2022-05-10 19:51:19 +01:00
Ian Lynagh
dc7f8a6a5a Kotlin: Refactor TrapWriter/Logger
It's now Tpossible for TrapWriter to log warnings. This required a
little juggling to break the dependency loop between the two classes.
2022-05-10 19:51:18 +01:00
Ian Lynagh
97793b58cd Kotlin: Tweak diagnostic writing
In particular, we now write full exception information, so we can
diagnose problems.

We were using `warn` to log errors in some cases, and generally using
lower-level functions than necessary. We now use the appropriate
functions. I've lost the distinction between e.g. ErrorHigh and ErrorSevere
in this, but we can add it back if it's important.
2022-05-10 19:51:16 +01:00
Chris Smowton
b9d8fe72f0 TRAP formatting: adopt Java's standards
* Encode dates with D"" strings
* Truncate exceedingly long string values
* Note that floats don't require any special handling
2022-05-10 19:51:16 +01:00