|
| 1 | +private import AstNodes |
| 2 | +private import Expr |
| 3 | +private import Idents |
| 4 | +private import Literals |
| 5 | + |
| 6 | +private import internal.ResourceDeclaration |
| 7 | +private import internal.ObjectProperty |
| 8 | +private import internal.Object |
| 9 | + |
| 10 | +/** |
| 11 | + * A Object unknown AST node. |
| 12 | + */ |
| 13 | +class Object extends Expr instanceof ObjectImpl { |
| 14 | + ObjectProperty getProperties() { result = ObjectImpl.super.getProperties() } |
| 15 | + |
| 16 | + ObjectProperty getProp(int i) { result = ObjectImpl.super.getProperty(i) } |
| 17 | + |
| 18 | + Expr getProperty(string name) { |
| 19 | + exists(ObjectProperty property | |
| 20 | + property = this.getProperties() and |
| 21 | + property.getName().getName() = name |
| 22 | + | |
| 23 | + result = property.getValue() |
| 24 | + ) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * A ObjectProperty unknown AST node. |
| 30 | + */ |
| 31 | +class ObjectProperty extends Expr instanceof ObjectPropertyImpl { |
| 32 | + Idents getName() { result = ObjectPropertyImpl.super.getName() } |
| 33 | + |
| 34 | + Expr getValue() { result = ObjectPropertyImpl.super.getValue() } |
| 35 | +} |
| 36 | + |
| 37 | +/** |
| 38 | + * A ResourceDeclaration unknown AST node. |
| 39 | + */ |
| 40 | +class ResourceDeclaration extends AstNode instanceof ResourceDeclarationImpl { |
| 41 | + /** |
| 42 | + * The name of the resource instance |
| 43 | + */ |
| 44 | + Idents getIdentifier() { result = ResourceDeclarationImpl.super.getIdentifier() } |
| 45 | + |
| 46 | + /** |
| 47 | + * The name of the resource instance. |
| 48 | + */ |
| 49 | + Literals getName() { result = ResourceDeclarationImpl.super.getName() } |
| 50 | + |
| 51 | + /** |
| 52 | + * The object that represents the resource. |
| 53 | + */ |
| 54 | + Object getBody() { result = ResourceDeclarationImpl.super.getObject() } |
| 55 | + |
| 56 | + ObjectProperty getProperties() { result = this.getBody().getProperties() } |
| 57 | + |
| 58 | + Expr getProperty(string name) { result = this.getBody().getProperty(name) } |
| 59 | +} |
| 60 | + |
| 61 | +// Resource resolveResource(Expr expr) { |
| 62 | +// exists(Resource resource | |
| 63 | +// // Object having an id property needs to be resolved |
| 64 | +// // {resource.id}.id |
| 65 | +// exists(MemberExpr memexpr | |
| 66 | +// memexpr = expr.(Object).getProperty("id") and |
| 67 | +// memexpr.getObject().(Identifier).getName() = resource.getIdentifier().(Identifier).getName() |
| 68 | +// | |
| 69 | +// result = resource |
| 70 | +// ) |
| 71 | +// or |
| 72 | +// exists(Identifier ident | |
| 73 | +// ident = expr and |
| 74 | +// ident.getName() = resource.getIdentifier().(Identifier).getName() |
| 75 | +// | |
| 76 | +// result = resource |
| 77 | +// ) |
| 78 | +// ) |
| 79 | +// } |
| 80 | + |
| 81 | + |
| 82 | +class Resource extends TResource { |
| 83 | + private ResourceDeclaration resource; |
| 84 | + |
| 85 | + Resource() { this = TResourceDeclaration(resource) } |
| 86 | + |
| 87 | + string getResourceType() { |
| 88 | + exists(StringLiteral sl | sl = resource.getName() | result = sl.getValue()) |
| 89 | + } |
| 90 | + |
| 91 | + Expr getProperty(string name) { |
| 92 | + result = resource.getProperty(name) |
| 93 | + } |
| 94 | + |
| 95 | + string toString() { result = "Resource[" + resource.getIdentifier().getName() + "]" } |
| 96 | + |
| 97 | + string getAPrimaryQlClass() { result = "Resource" } |
| 98 | +} |
| 99 | + |
| 100 | +cached |
| 101 | +private module Cached { |
| 102 | + cached |
| 103 | + newtype TResource = TResourceDeclaration(ResourceDeclaration rd) |
| 104 | +} |
| 105 | + |
| 106 | +private import Cached |
0 commit comments