Java/Kotlin: Add File.is{,Java,Kotlin}SourceFile()

This commit is contained in:
Ian Lynagh
2021-12-08 15:40:29 +00:00
parent 70708d69bf
commit 7c03ed99dc
8 changed files with 21 additions and 12 deletions

View File

@@ -181,6 +181,15 @@ class File extends Container, @file {
override string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
override string getAPrimaryQlClass() { result = "File" }
/** Holds if this is a (Java or Kotlin) source file. */
predicate isSourceFile() { this.isJavaSourceFile() or this.isKotlinSourceFile() }
/** Holds if this is a Java source file. */
predicate isJavaSourceFile() { this.getExtension() = "java" }
/** Holds if this is a Kotlin source file. */
predicate isKotlinSourceFile() { this.getExtension() = "kt" }
}
/**

View File

@@ -196,7 +196,7 @@ class Location extends @location {
}
private predicate hasSourceLocation(Top l, Location loc, File f) {
hasLocation(l, loc) and f = loc.getFile() and f.getExtension() = ["java", "kt"]
hasLocation(l, loc) and f = loc.getFile() and f.isSourceFile()
}
cached

View File

@@ -34,7 +34,7 @@ class Element extends @element, Top {
* Elements pertaining to source files may include generated elements
* not visible in source code, such as implicit default constructors.
*/
predicate fromSource() { this.getCompilationUnit().getExtension() = ["java", "kt"] }
predicate fromSource() { this.getCompilationUnit().isSourceFile() }
/** Gets the compilation unit that this element belongs to. */
CompilationUnit getCompilationUnit() { result = this.getFile() }