|
| 1 | +/** |
| 2 | + * Provides classes for working with MyBatis mapper xml files and their content. |
| 3 | + */ |
| 4 | + |
| 5 | +import java |
| 6 | + |
| 7 | +/** |
| 8 | + * MyBatis Mapper XML file. |
| 9 | + */ |
| 10 | +class MyBatisMapperXmlFile extends XmlFile { |
| 11 | + MyBatisMapperXmlFile() { |
| 12 | + count(XmlElement e | e = this.getAChild()) = 1 and |
| 13 | + this.getAChild().getName() = "mapper" |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * An XML element in a `MyBatisMapperXMLFile`. |
| 19 | + */ |
| 20 | +class MyBatisMapperXmlElement extends XmlElement { |
| 21 | + MyBatisMapperXmlElement() { this.getFile() instanceof MyBatisMapperXmlFile } |
| 22 | + |
| 23 | + /** |
| 24 | + * Gets the value for this element, with leading and trailing whitespace trimmed. |
| 25 | + */ |
| 26 | + string getValue() { result = this.allCharactersString().trim() } |
| 27 | + |
| 28 | + /** |
| 29 | + * Gets the reference type bound to MyBatis Mapper XML File. |
| 30 | + */ |
| 31 | + RefType getNamespaceRefType() { |
| 32 | + result.getQualifiedName() = this.getAttribute("namespace").getValue() |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * An MyBatis Mapper sql operation element. |
| 38 | + */ |
| 39 | +abstract class MyBatisMapperSqlOperation extends MyBatisMapperXmlElement { |
| 40 | + /** |
| 41 | + * Gets the value of the `id` attribute of MyBatis Mapper sql operation element. |
| 42 | + */ |
| 43 | + string getId() { result = this.getAttribute("id").getValue() } |
| 44 | + |
| 45 | + /** |
| 46 | + * Gets the `<include>` element in a `MyBatisMapperSqlOperation`. |
| 47 | + */ |
| 48 | + MyBatisMapperInclude getInclude() { result = this.getAChild*() } |
| 49 | + |
| 50 | + /** |
| 51 | + * Gets the method bound to MyBatis Mapper XML File. |
| 52 | + */ |
| 53 | + Method getMapperMethod() { |
| 54 | + result.getName() = this.getId() and |
| 55 | + result.getDeclaringType() = this.getParent().(MyBatisMapperXmlElement).getNamespaceRefType() |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * A `<insert>` element in a `MyBatisMapperSqlOperation`. |
| 61 | + */ |
| 62 | +class MyBatisMapperInsert extends MyBatisMapperSqlOperation { |
| 63 | + MyBatisMapperInsert() { this.getName() = "insert" } |
| 64 | +} |
| 65 | + |
| 66 | +/** |
| 67 | + * A `<update>` element in a `MyBatisMapperSqlOperation`. |
| 68 | + */ |
| 69 | +class MyBatisMapperUpdate extends MyBatisMapperSqlOperation { |
| 70 | + MyBatisMapperUpdate() { this.getName() = "update" } |
| 71 | +} |
| 72 | + |
| 73 | +/** |
| 74 | + * A `<delete>` element in a `MyBatisMapperSqlOperation`. |
| 75 | + */ |
| 76 | +class MyBatisMapperDelete extends MyBatisMapperSqlOperation { |
| 77 | + MyBatisMapperDelete() { this.getName() = "delete" } |
| 78 | +} |
| 79 | + |
| 80 | +/** |
| 81 | + * A `<select>` element in a `MyBatisMapperSqlOperation`. |
| 82 | + */ |
| 83 | +class MyBatisMapperSelect extends MyBatisMapperSqlOperation { |
| 84 | + MyBatisMapperSelect() { this.getName() = "select" } |
| 85 | +} |
| 86 | + |
| 87 | +/** |
| 88 | + * A `<sql>` element in a `MyBatisMapperXMLElement`. |
| 89 | + */ |
| 90 | +class MyBatisMapperSql extends MyBatisMapperXmlElement { |
| 91 | + MyBatisMapperSql() { this.getName() = "sql" } |
| 92 | + |
| 93 | + /** |
| 94 | + * Gets the value of the `id` attribute of this `<sql>`. |
| 95 | + */ |
| 96 | + string getId() { result = this.getAttribute("id").getValue() } |
| 97 | +} |
| 98 | + |
| 99 | +/** |
| 100 | + * A `<include>` element in a `MyBatisMapperXMLElement`. |
| 101 | + */ |
| 102 | +class MyBatisMapperInclude extends MyBatisMapperXmlElement { |
| 103 | + MyBatisMapperInclude() { this.getName() = "include" } |
| 104 | + |
| 105 | + /** |
| 106 | + * Gets the value of the `refid` attribute of this `<include>`. |
| 107 | + */ |
| 108 | + string getRefid() { result = this.getAttribute("refid").getValue() } |
| 109 | +} |
| 110 | + |
| 111 | +/** |
| 112 | + * A `<foreach>` element in a `MyBatisMapperXMLElement`. |
| 113 | + */ |
| 114 | +class MyBatisMapperForeach extends MyBatisMapperXmlElement { |
| 115 | + MyBatisMapperForeach() { this.getName() = "foreach" } |
| 116 | +} |
0 commit comments