From 954c6f7a6b5f95b33887279c7e664d58f2494bdd Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Tue, 17 Dec 2024 13:50:11 +0100 Subject: [PATCH 1/3] Java: Add the MyBatisMappeXML module. --- java/lib/semmle/code/xml/MyBatisMapperXML.qll | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 java/lib/semmle/code/xml/MyBatisMapperXML.qll diff --git a/java/lib/semmle/code/xml/MyBatisMapperXML.qll b/java/lib/semmle/code/xml/MyBatisMapperXML.qll new file mode 100644 index 00000000..529a627e --- /dev/null +++ b/java/lib/semmle/code/xml/MyBatisMapperXML.qll @@ -0,0 +1,116 @@ +/** + * Provides classes for working with MyBatis mapper xml files and their content. + */ + +import java + +/** + * MyBatis Mapper XML file. + */ +class MyBatisMapperXmlFile extends XmlFile { + MyBatisMapperXmlFile() { + count(XmlElement e | e = this.getAChild()) = 1 and + this.getAChild().getName() = "mapper" + } +} + +/** + * An XML element in a `MyBatisMapperXMLFile`. + */ +class MyBatisMapperXmlElement extends XmlElement { + MyBatisMapperXmlElement() { this.getFile() instanceof MyBatisMapperXmlFile } + + /** + * Gets the value for this element, with leading and trailing whitespace trimmed. + */ + string getValue() { result = this.allCharactersString().trim() } + + /** + * Gets the reference type bound to MyBatis Mapper XML File. + */ + RefType getNamespaceRefType() { + result.getQualifiedName() = this.getAttribute("namespace").getValue() + } +} + +/** + * An MyBatis Mapper sql operation element. + */ +abstract class MyBatisMapperSqlOperation extends MyBatisMapperXmlElement { + /** + * Gets the value of the `id` attribute of MyBatis Mapper sql operation element. + */ + string getId() { result = this.getAttribute("id").getValue() } + + /** + * Gets the `` element in a `MyBatisMapperSqlOperation`. + */ + MyBatisMapperInclude getInclude() { result = this.getAChild*() } + + /** + * Gets the method bound to MyBatis Mapper XML File. + */ + Method getMapperMethod() { + result.getName() = this.getId() and + result.getDeclaringType() = this.getParent().(MyBatisMapperXmlElement).getNamespaceRefType() + } +} + +/** + * A `` element in a `MyBatisMapperSqlOperation`. + */ +class MyBatisMapperInsert extends MyBatisMapperSqlOperation { + MyBatisMapperInsert() { this.getName() = "insert" } +} + +/** + * A `` element in a `MyBatisMapperSqlOperation`. + */ +class MyBatisMapperUpdate extends MyBatisMapperSqlOperation { + MyBatisMapperUpdate() { this.getName() = "update" } +} + +/** + * A `` element in a `MyBatisMapperSqlOperation`. + */ +class MyBatisMapperDelete extends MyBatisMapperSqlOperation { + MyBatisMapperDelete() { this.getName() = "delete" } +} + +/** + * A `