Kotlin: Recognize generated files

This commit is contained in:
Tamas Vajk
2022-10-07 09:32:00 +02:00
parent 0e6735b804
commit f51c13f0c1
7 changed files with 23 additions and 2 deletions

View File

@@ -51,9 +51,9 @@ library class MarkerCommentGeneratedFile extends GeneratedFile {
/**
* A marker comment that indicates that it is in a generated file.
*/
private class GeneratedFileMarker extends Top instanceof JavadocElement {
private class GeneratedFileMarker extends Top {
GeneratedFileMarker() {
exists(string msg | msg = this.getText() |
exists(string msg | msg = this.(JavadocElement).getText() or msg = this.(KtComment).getText() |
msg.regexpMatch("(?i).*\\bGenerated By\\b.*\\bDo not edit\\b.*") or
msg.regexpMatch("(?i).*\\bThis (file|class|interface|art[ei]fact) (was|is|(has been)) (?:auto[ -]?)?gener(e?)ated.*") or
msg.regexpMatch("(?i).*\\bAny modifications to this file will be lost\\b.*") or
@@ -65,3 +65,10 @@ private class GeneratedFileMarker extends Top instanceof JavadocElement {
)
}
}
/**
* A file detected as generated by the Kotlin Annotation Processing Tool (kapt). Detection is based on file path.
*/
private class KaptFile extends GeneratedFile {
KaptFile() { this.getRelativePath().matches("%/generated/source/kapt%") }
}

View File

@@ -0,0 +1,2 @@
| Generated.kt:0:0:0:0 | Generated |
| generated/source/kapt/Generated.kt:0:0:0:0 | Generated |

View File

@@ -0,0 +1,3 @@
// This file was auto generated by me
class B

View File

@@ -0,0 +1,4 @@
import java
from GeneratedFile f
select f

View File

@@ -0,0 +1,3 @@
// This file was not generated
class A