diff --git a/cpp/change-notes/2021-08-23-getPrimaryQlClasses.md b/cpp/change-notes/2021-08-23-getPrimaryQlClasses.md new file mode 100644 index 00000000000..6dbd956cafe --- /dev/null +++ b/cpp/change-notes/2021-08-23-getPrimaryQlClasses.md @@ -0,0 +1,2 @@ +lgtm,codescanning +* Added `Element.getPrimaryQlClasses()` predicate, which gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. diff --git a/cpp/ql/lib/semmle/code/cpp/Element.qll b/cpp/ql/lib/semmle/code/cpp/Element.qll index daa15e0f625..1f547adccaa 100644 --- a/cpp/ql/lib/semmle/code/cpp/Element.qll +++ b/cpp/ql/lib/semmle/code/cpp/Element.qll @@ -58,6 +58,11 @@ class ElementBase extends @element { /** DEPRECATED: use `getAPrimaryQlClass` instead. */ deprecated string getCanonicalQLClass() { result = this.getAPrimaryQlClass() } + /** + * Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. + */ + final string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") } + /** * Gets the name of a primary CodeQL class to which this element belongs. * diff --git a/csharp/change-notes/2021-08-23-getPrimaryQlClasses.md b/csharp/change-notes/2021-08-23-getPrimaryQlClasses.md new file mode 100644 index 00000000000..6dbd956cafe --- /dev/null +++ b/csharp/change-notes/2021-08-23-getPrimaryQlClasses.md @@ -0,0 +1,2 @@ +lgtm,codescanning +* Added `Element.getPrimaryQlClasses()` predicate, which gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. diff --git a/csharp/ql/lib/semmle/code/cil/ConsistencyChecks.qll b/csharp/ql/lib/semmle/code/cil/ConsistencyChecks.qll index 51b74b2463d..02cfd149886 100644 --- a/csharp/ql/lib/semmle/code/cil/ConsistencyChecks.qll +++ b/csharp/ql/lib/semmle/code/cil/ConsistencyChecks.qll @@ -670,7 +670,7 @@ class MissingCilDeclaration extends ConsistencyViolation, MissingCSharpCheck { override string getMessage() { result = "Cannot locate CIL for " + getDeclaration().toStringWithTypes() + " of class " + - getDeclaration().getAPrimaryQlClass() + getDeclaration().getPrimaryQlClasses() } override string toString() { result = getDeclaration().toStringWithTypes() } diff --git a/csharp/ql/lib/semmle/code/csharp/PrintAst.qll b/csharp/ql/lib/semmle/code/csharp/PrintAst.qll index 1cac4a5f238..a701c7bfbf3 100644 --- a/csharp/ql/lib/semmle/code/csharp/PrintAst.qll +++ b/csharp/ql/lib/semmle/code/csharp/PrintAst.qll @@ -61,7 +61,7 @@ private predicate isNotNeeded(Element e) { * Retrieves the canonical QL class(es) for entity `el` */ private string getQlClass(Element el) { - result = "[" + concat(el.getAPrimaryQlClass(), ",") + "] " + result = "[" + el.getPrimaryQlClasses() + "] " // Alternative implementation -- do not delete. It is useful for QL class discovery. // result = "["+ concat(el.getAQlClass(), ",") + "] " } diff --git a/csharp/ql/lib/semmle/code/dotnet/Element.qll b/csharp/ql/lib/semmle/code/dotnet/Element.qll index 0138766cc58..3b1955887f9 100644 --- a/csharp/ql/lib/semmle/code/dotnet/Element.qll +++ b/csharp/ql/lib/semmle/code/dotnet/Element.qll @@ -40,6 +40,11 @@ class Element extends @dotnet_element { /** Gets the full textual representation of this element, including type information. */ string toStringWithTypes() { result = this.toString() } + /** + * Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. + */ + final string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") } + /** * Gets the name of a primary CodeQL class to which this element belongs. * diff --git a/csharp/ql/test/library-tests/generics/ConsistencyChecks.ql b/csharp/ql/test/library-tests/generics/ConsistencyChecks.ql index def07f2c435..7052c6f697a 100644 --- a/csharp/ql/test/library-tests/generics/ConsistencyChecks.ql +++ b/csharp/ql/test/library-tests/generics/ConsistencyChecks.ql @@ -6,4 +6,4 @@ import semmle.code.csharp.commons.ConsistencyChecks from Element e, string m where consistencyFailure(e, m) -select e, "Element class " + e.getAPrimaryQlClass() + " has consistency check failed: " + m +select e, "Element class " + e.getPrimaryQlClasses() + " has consistency check failed: " + m diff --git a/java/change-notes/2021-08-23-getPrimaryQlClasses.md b/java/change-notes/2021-08-23-getPrimaryQlClasses.md new file mode 100644 index 00000000000..513cf51bcb0 --- /dev/null +++ b/java/change-notes/2021-08-23-getPrimaryQlClasses.md @@ -0,0 +1,2 @@ +lgtm,codescanning +* Added `Top.getPrimaryQlClasses()` predicate, which gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. diff --git a/java/ql/lib/semmle/code/Location.qll b/java/ql/lib/semmle/code/Location.qll index e9b808f6bba..9b3b0dbc2e0 100755 --- a/java/ql/lib/semmle/code/Location.qll +++ b/java/ql/lib/semmle/code/Location.qll @@ -100,6 +100,11 @@ class Top extends @top { cached string toString() { hasName(this, result) } + /** + * Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. + */ + final string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") } + /** * Gets the name of a primary CodeQL class to which this element belongs. * diff --git a/java/ql/lib/semmle/code/java/PrintAst.qll b/java/ql/lib/semmle/code/java/PrintAst.qll index 6a74c15316c..66f1ecc9449 100644 --- a/java/ql/lib/semmle/code/java/PrintAst.qll +++ b/java/ql/lib/semmle/code/java/PrintAst.qll @@ -89,7 +89,7 @@ private predicate duplicateMetadata(Field f) { * Retrieves the canonical QL class(es) for entity `el` */ private string getQlClass(Top el) { - result = "[" + concat(el.getAPrimaryQlClass(), ",") + "] " + result = "[" + el.getPrimaryQlClasses() + "] " // Alternative implementation -- do not delete. It is useful for QL class discovery. // result = "[" + concat(el.getAQlClass(), ",") + "] " } diff --git a/javascript/change-notes/2021-08-23-getPrimaryQlClasses.md b/javascript/change-notes/2021-08-23-getPrimaryQlClasses.md new file mode 100644 index 00000000000..c733328f1bd --- /dev/null +++ b/javascript/change-notes/2021-08-23-getPrimaryQlClasses.md @@ -0,0 +1,2 @@ +lgtm,codescanning +* Added `Locatable.getPrimaryQlClasses()` predicate, which gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. diff --git a/javascript/ql/src/semmle/javascript/Locations.qll b/javascript/ql/src/semmle/javascript/Locations.qll index a84bcd18308..bdf83fb395a 100644 --- a/javascript/ql/src/semmle/javascript/Locations.qll +++ b/javascript/ql/src/semmle/javascript/Locations.qll @@ -132,6 +132,11 @@ class Locatable extends @locatable { none() } + /** + * Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. + */ + final string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") } + /** * Gets the primary QL class for the Locatable. */ diff --git a/javascript/ql/src/semmle/javascript/PrintAst.qll b/javascript/ql/src/semmle/javascript/PrintAst.qll index 029cfd536fc..5fbcd4f4ec6 100644 --- a/javascript/ql/src/semmle/javascript/PrintAst.qll +++ b/javascript/ql/src/semmle/javascript/PrintAst.qll @@ -44,9 +44,9 @@ private predicate isNotNeeded(Locatable el) { * Retrieves the canonical QL class(es) for entity `el` */ private string getQlClass(Locatable el) { - result = "[" + concat(el.getAPrimaryQlClass(), ",") + "] " + result = "[" + el.getPrimaryQlClasses() + "] " // Alternative implementation -- do not delete. It is useful for QL class discovery. - // not el.getAPrimaryQlClass() = "???" and result = "[" + concat(el.getAPrimaryQlClass(), ",") + "] " or el.getAPrimaryQlClass() = "???" and result = "??[" + concat(el.getAQlClass(), ",") + "] " + // not el.getAPrimaryQlClass() = "???" and result = "[" + getPrimaryQlClasses() + "] " or el.getAPrimaryQlClass() = "???" and result = "??[" + concat(el.getAQlClass(), ",") + "] " } /**