All languages: Add getPrimaryQlClasses()

This is a non-overridable predicate that concatenates all the
getAPrimaryQlClass() results into a comma-separated string.
This commit is contained in:
Ian Lynagh
2021-08-23 13:12:47 +01:00
parent 0210d85ce8
commit a9db1c52e5
13 changed files with 34 additions and 6 deletions

View File

@@ -0,0 +1,2 @@
lgtm,codescanning
* Added `ElementBase.getPrimaryQlClasses()` predicate, which gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.

View File

@@ -58,6 +58,11 @@ class ElementBase extends @element {
/** DEPRECATED: use `getAPrimaryQlClass` instead. */ /** DEPRECATED: use `getAPrimaryQlClass` instead. */
deprecated string getCanonicalQLClass() { result = this.getAPrimaryQlClass() } 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. * Gets the name of a primary CodeQL class to which this element belongs.
* *

View File

@@ -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.

View File

@@ -670,7 +670,7 @@ class MissingCilDeclaration extends ConsistencyViolation, MissingCSharpCheck {
override string getMessage() { override string getMessage() {
result = result =
"Cannot locate CIL for " + getDeclaration().toStringWithTypes() + " of class " + "Cannot locate CIL for " + getDeclaration().toStringWithTypes() + " of class " +
getDeclaration().getAPrimaryQlClass() getDeclaration().getPrimaryQlClasses()
} }
override string toString() { result = getDeclaration().toStringWithTypes() } override string toString() { result = getDeclaration().toStringWithTypes() }

View File

@@ -61,7 +61,7 @@ private predicate isNotNeeded(Element e) {
* Retrieves the canonical QL class(es) for entity `el` * Retrieves the canonical QL class(es) for entity `el`
*/ */
private string getQlClass(Element 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. // Alternative implementation -- do not delete. It is useful for QL class discovery.
// result = "["+ concat(el.getAQlClass(), ",") + "] " // result = "["+ concat(el.getAQlClass(), ",") + "] "
} }

View File

@@ -40,6 +40,11 @@ class Element extends @dotnet_element {
/** Gets the full textual representation of this element, including type information. */ /** Gets the full textual representation of this element, including type information. */
string toStringWithTypes() { result = this.toString() } 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. * Gets the name of a primary CodeQL class to which this element belongs.
* *

View File

@@ -6,4 +6,4 @@ import semmle.code.csharp.commons.ConsistencyChecks
from Element e, string m from Element e, string m
where consistencyFailure(e, 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

View File

@@ -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.

View File

@@ -100,6 +100,11 @@ class Top extends @top {
cached cached
string toString() { hasName(this, result) } 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. * Gets the name of a primary CodeQL class to which this element belongs.
* *

View File

@@ -89,7 +89,7 @@ private predicate duplicateMetadata(Field f) {
* Retrieves the canonical QL class(es) for entity `el` * Retrieves the canonical QL class(es) for entity `el`
*/ */
private string getQlClass(Top 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. // Alternative implementation -- do not delete. It is useful for QL class discovery.
// result = "[" + concat(el.getAQlClass(), ",") + "] " // result = "[" + concat(el.getAQlClass(), ",") + "] "
} }

View File

@@ -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.

View File

@@ -132,6 +132,11 @@ class Locatable extends @locatable {
none() 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. * Gets the primary QL class for the Locatable.
*/ */

View File

@@ -44,9 +44,9 @@ private predicate isNotNeeded(Locatable el) {
* Retrieves the canonical QL class(es) for entity `el` * Retrieves the canonical QL class(es) for entity `el`
*/ */
private string getQlClass(Locatable 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. // 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(), ",") + "] "
} }
/** /**