|
| 1 | +import java |
| 2 | +import semmle.code.java.frameworks.JaxWS |
| 3 | +import TestUtilities.InlineExpectationsTest |
| 4 | + |
| 5 | +class JaxRsTest extends InlineExpectationsTest { |
| 6 | + JaxRsTest() { this = "JaxRsTest" } |
| 7 | + |
| 8 | + override string getARelevantTag() { |
| 9 | + result = |
| 10 | + [ |
| 11 | + "ResourceMethod", "RootResourceClass", "NonRootResourceClass", |
| 12 | + "ResourceMethodOnResourceClass", "InjectableConstructor", "InjectableField", |
| 13 | + "InjectionAnnotation", "ResponseDeclaration", "ResponseBuilderDeclaration", |
| 14 | + "ClientDeclaration", "BeanParamConstructor", "MessageBodyReaderDeclaration", |
| 15 | + "MessageBodyReaderReadFromCall", "MessageBodyReaderReadCall", "ProducesAnnotation", |
| 16 | + "ConsumesAnnotation" |
| 17 | + ] |
| 18 | + } |
| 19 | + |
| 20 | + override predicate hasActualResult(Location location, string element, string tag, string value) { |
| 21 | + tag = "ResourceMethod" and |
| 22 | + exists(JaxRsResourceMethod resourceMethod | |
| 23 | + resourceMethod.getLocation() = location and |
| 24 | + element = resourceMethod.toString() and |
| 25 | + if exists(resourceMethod.getProducesAnnotation()) |
| 26 | + then value = resourceMethod.getProducesAnnotation().getADeclaredContentType() |
| 27 | + else value = "" |
| 28 | + ) |
| 29 | + or |
| 30 | + tag = "RootResourceClass" and |
| 31 | + exists(JaxRsResourceClass resourceClass | |
| 32 | + resourceClass.isRootResource() and |
| 33 | + resourceClass.getLocation() = location and |
| 34 | + element = resourceClass.toString() and |
| 35 | + value = "" |
| 36 | + ) |
| 37 | + or |
| 38 | + tag = "NonRootResourceClass" and |
| 39 | + exists(JaxRsResourceClass resourceClass | |
| 40 | + not resourceClass.isRootResource() and |
| 41 | + resourceClass.getLocation() = location and |
| 42 | + element = resourceClass.toString() and |
| 43 | + value = "" |
| 44 | + ) |
| 45 | + or |
| 46 | + tag = "ResourceMethodOnResourceClass" and |
| 47 | + exists(JaxRsResourceMethod resourceMethod | |
| 48 | + resourceMethod = any(JaxRsResourceClass ResourceClass).getAResourceMethod() |
| 49 | + | |
| 50 | + resourceMethod.getLocation() = location and |
| 51 | + element = resourceMethod.toString() and |
| 52 | + value = "" |
| 53 | + ) |
| 54 | + or |
| 55 | + tag = "InjectableConstructor" and |
| 56 | + exists(Constructor cons | |
| 57 | + cons = any(JaxRsResourceClass resourceClass).getAnInjectableConstructor() |
| 58 | + | |
| 59 | + cons.getLocation() = location and |
| 60 | + element = cons.toString() and |
| 61 | + value = "" |
| 62 | + ) |
| 63 | + or |
| 64 | + tag = "InjectableField" and |
| 65 | + exists(Field field | field = any(JaxRsResourceClass resourceClass).getAnInjectableField() | |
| 66 | + field.getLocation() = location and |
| 67 | + element = field.toString() and |
| 68 | + value = "" |
| 69 | + ) |
| 70 | + or |
| 71 | + tag = "InjectionAnnotation" and |
| 72 | + exists(JaxRsInjectionAnnotation injectionAnnotation | |
| 73 | + injectionAnnotation.getLocation() = location and |
| 74 | + element = injectionAnnotation.toString() and |
| 75 | + value = "" |
| 76 | + ) |
| 77 | + or |
| 78 | + tag = "ResponseDeclaration" and |
| 79 | + exists(LocalVariableDecl decl | |
| 80 | + decl.getType() instanceof JaxRsResponse and |
| 81 | + decl.getLocation() = location and |
| 82 | + element = decl.toString() and |
| 83 | + value = "" |
| 84 | + ) |
| 85 | + or |
| 86 | + tag = "ResponseBuilderDeclaration" and |
| 87 | + exists(LocalVariableDecl decl | |
| 88 | + decl.getType() instanceof JaxRsResponseBuilder and |
| 89 | + decl.getLocation() = location and |
| 90 | + element = decl.toString() and |
| 91 | + value = "" |
| 92 | + ) |
| 93 | + or |
| 94 | + tag = "ClientDeclaration" and |
| 95 | + exists(LocalVariableDecl decl | |
| 96 | + decl.getType() instanceof JaxRsClient and |
| 97 | + decl.getLocation() = location and |
| 98 | + element = decl.toString() and |
| 99 | + value = "" |
| 100 | + ) |
| 101 | + or |
| 102 | + tag = "BeanParamConstructor" and |
| 103 | + exists(JaxRsBeanParamConstructor cons | |
| 104 | + cons.getLocation() = location and |
| 105 | + element = cons.toString() and |
| 106 | + value = "" |
| 107 | + ) |
| 108 | + or |
| 109 | + tag = "MessageBodyReaderDeclaration" and |
| 110 | + exists(LocalVariableDecl decl | |
| 111 | + decl.getType().(RefType).getSourceDeclaration() instanceof MessageBodyReader and |
| 112 | + decl.getLocation() = location and |
| 113 | + element = decl.toString() and |
| 114 | + value = "" |
| 115 | + ) |
| 116 | + or |
| 117 | + tag = "MessageBodyReaderReadFromCall" and |
| 118 | + exists(MethodAccess ma | |
| 119 | + ma.getMethod() instanceof MessageBodyReaderReadFrom and |
| 120 | + ma.getLocation() = location and |
| 121 | + element = ma.toString() and |
| 122 | + value = "" |
| 123 | + ) |
| 124 | + or |
| 125 | + tag = "MessageBodyReaderReadCall" and |
| 126 | + exists(MethodAccess ma | |
| 127 | + ma.getMethod() instanceof MessageBodyReaderRead and |
| 128 | + ma.getLocation() = location and |
| 129 | + element = ma.toString() and |
| 130 | + value = "" |
| 131 | + ) |
| 132 | + or |
| 133 | + tag = "ProducesAnnotation" and |
| 134 | + exists(JaxRSProducesAnnotation producesAnnotation | |
| 135 | + producesAnnotation.getLocation() = location and |
| 136 | + element = producesAnnotation.toString() and |
| 137 | + value = producesAnnotation.getADeclaredContentType() |
| 138 | + ) |
| 139 | + or |
| 140 | + tag = "ConsumesAnnotation" and |
| 141 | + exists(JaxRSConsumesAnnotation consumesAnnotation | |
| 142 | + consumesAnnotation.getLocation() = location and |
| 143 | + element = consumesAnnotation.toString() and |
| 144 | + value = "" |
| 145 | + ) |
| 146 | + } |
| 147 | +} |
0 commit comments