|
| 1 | +/** |
| 2 | + * Provides classes and predicates for working with the Play framework. |
| 3 | + */ |
| 4 | + |
| 5 | +import java |
| 6 | + |
| 7 | +/** |
| 8 | + * The `play.mvc.Result` class. |
| 9 | + */ |
| 10 | +class PlayMvcResultClass extends Class { |
| 11 | + PlayMvcResultClass() { this.hasQualifiedName("play.mvc", "Result") } |
| 12 | +} |
| 13 | + |
| 14 | +/** |
| 15 | + * The `play.mvc.Results` class. |
| 16 | + */ |
| 17 | +class PlayMvcResultsClass extends Class { |
| 18 | + PlayMvcResultsClass() { this.hasQualifiedName("play.mvc", "Results") } |
| 19 | +} |
| 20 | + |
| 21 | +/** |
| 22 | + * The `play.mvc.Http$RequestHeader` class. |
| 23 | + */ |
| 24 | +class PlayMvcHttpRequestHeader extends RefType { |
| 25 | + PlayMvcHttpRequestHeader() { this.hasQualifiedName("play.mvc", "Http$RequestHeader") } |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * A `play.mvc.BodyParser<>$Of` annotation. |
| 30 | + */ |
| 31 | +class PlayBodyParserAnnotation extends Annotation { |
| 32 | + PlayBodyParserAnnotation() { this.getType().hasQualifiedName("play.mvc", "BodyParser<>$Of") } |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * A `play.filters.csrf.AddCSRFToken` annotation. |
| 37 | + */ |
| 38 | +class PlayAddCsrfTokenAnnotation extends Annotation { |
| 39 | + PlayAddCsrfTokenAnnotation() { |
| 40 | + this.getType().hasQualifiedName("play.filters.csrf", "AddCSRFToken") |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +/** |
| 45 | + * The type `play.libs.F.Promise<Result>`. |
| 46 | + */ |
| 47 | +class PlayAsyncResultPromise extends Member { |
| 48 | + PlayAsyncResultPromise() { |
| 49 | + exists(Class c | |
| 50 | + c.hasQualifiedName("play.libs", "F") and |
| 51 | + this = c.getAMember() and |
| 52 | + this.getQualifiedName() = "F.Promise<Result>" |
| 53 | + ) |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +/** |
| 58 | + * The type `java.util.concurrent.CompletionStage<Result>`. |
| 59 | + */ |
| 60 | +class PlayAsyncResultCompletionStage extends Type { |
| 61 | + PlayAsyncResultCompletionStage() { |
| 62 | + this.hasName("CompletionStage<Result>") and |
| 63 | + this.getCompilationUnit().getPackage().hasName("java.util.concurrent") |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * The class `play.mvc.Controller` or a class that transitively extends it. |
| 69 | + */ |
| 70 | +class PlayController extends Class { |
| 71 | + PlayController() { |
| 72 | + this.extendsOrImplements*(any(Class t | t.hasQualifiedName("play.mvc", "Controller"))) |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +/** |
| 77 | + * A Play framework controller action method. These are mappings to route files. |
| 78 | + * |
| 79 | + * Sample Route - `POST /login @com.company.Application.login()`. |
| 80 | + * |
| 81 | + * Example - class gets `index` and `login` as valid action methods. |
| 82 | + * ```java |
| 83 | + * public class Application extends Controller { |
| 84 | + * public Result index(String username, String password) { |
| 85 | + * return ok("It works!"); |
| 86 | + * } |
| 87 | + * |
| 88 | + * public Result login() { |
| 89 | + * return ok("Log me In!"); |
| 90 | + * } |
| 91 | + * } |
| 92 | + * ``` |
| 93 | + */ |
| 94 | +class PlayControllerActionMethod extends Method { |
| 95 | + PlayControllerActionMethod() { |
| 96 | + this = any(PlayController c).getAMethod() and |
| 97 | + ( |
| 98 | + this.getReturnType() instanceof PlayAsyncResultPromise or |
| 99 | + this.getReturnType() instanceof PlayMvcResultClass or |
| 100 | + this.getReturnType() instanceof PlayAsyncResultCompletionStage |
| 101 | + ) |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +/** |
| 106 | + * A Play framework action method parameter. These are a source of user input. |
| 107 | + * |
| 108 | + * Example - `username` and `password` are action method parameters. |
| 109 | + * ```java |
| 110 | + * public class Application extends Controller { |
| 111 | + * public Result index(String username, String password) { |
| 112 | + * return ok("It works!"); |
| 113 | + * } |
| 114 | + * } |
| 115 | + * ``` |
| 116 | + */ |
| 117 | +class PlayActionMethodQueryParameter extends Parameter { |
| 118 | + PlayActionMethodQueryParameter() { |
| 119 | + exists(PlayControllerActionMethod a | |
| 120 | + a.isPublic() and |
| 121 | + this = a.getAParameter() |
| 122 | + ) |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +/** |
| 127 | + * A PlayFramework HttpRequestHeader method, some of these are `headers`, `getQueryString`, `getHeader`. |
| 128 | + */ |
| 129 | +class PlayMvcHttpRequestHeaderMethods extends Method { |
| 130 | + PlayMvcHttpRequestHeaderMethods() { this.getDeclaringType() instanceof PlayMvcHttpRequestHeader } |
| 131 | + |
| 132 | + /** |
| 133 | + * Gets a reference to the `getQueryString` method. |
| 134 | + */ |
| 135 | + MethodAccess getAQueryStringAccess() { |
| 136 | + this.hasName("getQueryString") and result = this.getAReference() |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +/** |
| 141 | + * A PlayFramework results method, some of these are `ok`, `status`, `redirect`. |
| 142 | + */ |
| 143 | +class PlayMvcResultsMethods extends Method { |
| 144 | + PlayMvcResultsMethods() { this.getDeclaringType() instanceof PlayMvcResultsClass } |
| 145 | + |
| 146 | + /** |
| 147 | + * Gets a reference to the `play.mvc.Results.ok` method. |
| 148 | + */ |
| 149 | + MethodAccess getAnOkAccess() { this.hasName("ok") and result = this.getAReference() } |
| 150 | + |
| 151 | + /** |
| 152 | + * Gets a reference to the `play.mvc.Results.redirect` method. |
| 153 | + */ |
| 154 | + MethodAccess getARedirectAccess() { this.hasName("redirect") and result = this.getAReference() } |
| 155 | +} |
0 commit comments