Repository navigation
Expand file tree
/
Copy pathGeneratedFiles.qll
More file actions
72 lines (64 loc) · 2.47 KB
/
Copy pathGeneratedFiles.qll
File metadata and controls
72 lines (64 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Provides classes and predicates for working with the most common types of generated files.
*/
overlay[local?]
module;
import Type
private import semmle.code.java.frameworks.JavaxAnnotations
/** A Java class that is detected as having been generated. */
abstract class GeneratedClass extends Class { }
/**
* A Java class annotated with a `@Generated` annotation.
*/
class AnnotatedGeneratedClass extends GeneratedClass {
AnnotatedGeneratedClass() { this.getAnAnnotation() instanceof GeneratedAnnotation }
}
/** A Java class generated by an ANTLR scanner or parser class. */
class AntlrGenerated extends GeneratedClass {
AntlrGenerated() {
exists(RefType t | this.getAStrictAncestor() = t |
// ANTLR v3
t.hasQualifiedName("org.antlr.runtime", "Lexer") or
t.hasQualifiedName("org.antlr.runtime", "Parser") or
t.hasQualifiedName("org.antlr.runtime.tree", "TreeParser") or
// ANTLR v2
t.hasQualifiedName("antlr", "TreeParser") or
t.hasQualifiedName("antlr", "CharScanner") or
t.hasQualifiedName("antlr", "LLkParser")
)
}
}
/** A generated callable is a callable declared in a generated class. */
class GeneratedCallable extends Callable {
GeneratedCallable() { this.getDeclaringType() instanceof GeneratedClass }
}
/**
* A file that is detected as having been generated.
*/
abstract class GeneratedFile extends File { }
/**
* A file detected as generated based on commonly-used marker comments.
*/
class MarkerCommentGeneratedFile extends GeneratedFile {
MarkerCommentGeneratedFile() { any(GeneratedFileMarker t).getFile() = this }
}
/**
* A marker comment that indicates that it is in a generated file.
*/
private class GeneratedFileMarker extends Top {
GeneratedFileMarker() {
exists(string msg | msg = this.(JavadocElement).getText() or msg = this.(KtComment).getText() |
msg.regexpMatch("(?i).*(" +
concat([
"\\bGenerated By\\b.*\\bDo not edit\\b",
"\\bThis (file|class|interface|art[ei]fact) (was|is|(has been)) (?:auto[ -]?)?gener(e?)ated",
"\\bAny modifications to this file will be lost\\b",
"\\bThis (file|class|interface|art[ei]fact) (was|is) (?:mechanically|automatically) generated\\b",
"\\bThe following code was (?:auto[ -]?)?generated (?:by|from)\\b",
"\\bAutogenerated by Thrift", "\\bGenerated By.*JavaCC",
"\\bGenerated from .* by ANTLR"
], "|"
) + ").*")
)
}
}