Skip to content

Commit 1c84455

Browse files
authored
Merge pull request #5003 from hvitved/csharp/remove-getaqlclass
C#: Remove uses of `getAQlClass()`
2 parents 1b3d69d + c235462 commit 1c84455

File tree

10 files changed

+146
-162
lines changed

10 files changed

+146
-162
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/IRType.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ module IRTypeConsistency {
341341
query predicate multipleIRTypes(Language::LanguageType type, string message) {
342342
strictcount(type.getIRType()) > 1 and
343343
message =
344-
"`LanguageType` " + type.getAQlClass() + " has multiple `IRType`s: " +
344+
"`LanguageType` " + type + " has multiple `IRType`s: " +
345345
concat(type.getIRType().toString(), ", ")
346346
}
347347

csharp/ql/src/experimental/ir/implementation/IRType.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ module IRTypeConsistency {
341341
query predicate multipleIRTypes(Language::LanguageType type, string message) {
342342
strictcount(type.getIRType()) > 1 and
343343
message =
344-
"`LanguageType` " + type.getAQlClass() + " has multiple `IRType`s: " +
344+
"`LanguageType` " + type + " has multiple `IRType`s: " +
345345
concat(type.getIRType().toString(), ", ")
346346
}
347347

csharp/ql/src/semmle/code/cil/ConsistencyChecks.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class InvalidOverride extends MethodViolation {
473473
InvalidOverride() {
474474
base = getMethod().getOverriddenMethod() and
475475
not getMethod().getDeclaringType().getABaseType+() = base.getDeclaringType() and
476-
base.getDeclaringType().isSourceDeclaration() // Bases classes of constructed types aren't extracted properly.
476+
base.getDeclaringType().isUnboundDeclaration() // Bases classes of constructed types aren't extracted properly.
477477
}
478478

479479
override string getMessage() {
@@ -664,7 +664,7 @@ class MissingCilDeclaration extends ConsistencyViolation, MissingCSharpCheck {
664664
override string getMessage() {
665665
result =
666666
"Cannot locate CIL for " + getDeclaration().toStringWithTypes() + " of class " +
667-
getDeclaration().getAQlClass()
667+
getDeclaration().getAPrimaryQlClass()
668668
}
669669

670670
override string toString() { result = getDeclaration().toStringWithTypes() }
@@ -753,7 +753,7 @@ class DeclarationWithMultipleLabels extends DeclarationViolation {
753753
class DeclarationWithoutLabel extends DeclarationViolation {
754754
DeclarationWithoutLabel() {
755755
exists(Declaration d | this = DeclarationCheck(d) |
756-
d.isSourceDeclaration() and
756+
d.isUnboundDeclaration() and
757757
not d instanceof TypeParameter and
758758
not exists(d.getLabel()) and
759759
(d instanceof Callable or d instanceof Type)

csharp/ql/src/semmle/code/csharp/Element.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,4 @@ class Element extends DotNet::Element, @element {
4848
* other children (zero-based).
4949
*/
5050
int getIndex() { exists(Element parent | parent.getChild(result) = this) }
51-
52-
/**
53-
* Gets the name of a primary CodeQL class to which this element belongs.
54-
*
55-
* For most elements, this is simply the most precise syntactic category to
56-
* which they belong; for example, `AddExpr` is a primary class, but
57-
* `BinaryOperation` is not.
58-
*
59-
* This predicate always has a result. If no primary class can be
60-
* determined, the result is `"???"`. If multiple primary classes match,
61-
* this predicate can have multiple results.
62-
*/
63-
string getAPrimaryQlClass() { result = "???" }
6451
}

csharp/ql/src/semmle/code/dotnet/Element.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ class Element extends @dotnet_element {
3636

3737
/** Gets the full textual representation of this element, including type information. */
3838
string toStringWithTypes() { result = this.toString() }
39+
40+
/**
41+
* Gets the name of a primary CodeQL class to which this element belongs.
42+
*
43+
* For most elements, this is simply the most precise syntactic category to
44+
* which they belong; for example, `AddExpr` is a primary class, but
45+
* `BinaryOperation` is not.
46+
*
47+
* This predicate always has a result. If no primary class can be
48+
* determined, the result is `"???"`. If multiple primary classes match,
49+
* this predicate can have multiple results.
50+
*/
51+
string getAPrimaryQlClass() { result = "???" }
3952
}
4053

4154
/** An element that has a name. */

csharp/ql/test/library-tests/comments/Comments.expected

Lines changed: 86 additions & 83 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
import csharp
22

3-
from CommentBlock c, CommentLine l
4-
where l.getParent() = c
5-
select c, c.getNumLines(), l, l.getText(), l.getRawText(), l.getAQlClass()
3+
private predicate commentLine(
4+
CommentBlock c, CommentLine l, int numLines, string text, string rawText
5+
) {
6+
l.getParent() = c and
7+
numLines = c.getNumLines() and
8+
text = l.getText() and
9+
rawText = l.getRawText()
10+
}
11+
12+
query predicate singlelineComment(
13+
CommentBlock c, SinglelineComment l, int numLines, string text, string rawText
14+
) {
15+
commentLine(c, l, numLines, text, rawText)
16+
}
17+
18+
query predicate multilineComment(
19+
CommentBlock c, MultilineComment l, int numLines, string text, string rawText
20+
) {
21+
commentLine(c, l, numLines, text, rawText)
22+
}
23+
24+
query predicate xmlComment(CommentBlock c, XmlComment l, int numLines, string text, string rawText) {
25+
commentLine(c, l, numLines, text, rawText)
26+
}
Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,14 @@
1-
| VisualStudio.cs:9:11:9:21 | MyTestSuite | TestClass | LeafType |
2-
| VisualStudio.cs:9:11:9:21 | MyTestSuite | TestClass | VSTestClass |
3-
| VisualStudio.cs:12:21:12:25 | Test1 | TestMethod | CallableTree |
4-
| VisualStudio.cs:12:21:12:25 | Test1 | TestMethod | CfgScope |
5-
| VisualStudio.cs:12:21:12:25 | Test1 | TestMethod | InstanceCallable |
6-
| VisualStudio.cs:12:21:12:25 | Test1 | TestMethod | VSTestMethod |
7-
| VisualStudio.cs:17:21:17:25 | Test2 | TestMethod | CallableTree |
8-
| VisualStudio.cs:17:21:17:25 | Test2 | TestMethod | CfgScope |
9-
| VisualStudio.cs:17:21:17:25 | Test2 | TestMethod | InstanceCallable |
10-
| VisualStudio.cs:17:21:17:25 | Test2 | TestMethod | VSTestMethod |
11-
| XUnit.cs:22:11:22:21 | MyTestSuite | TestClass | LeafType |
12-
| XUnit.cs:22:11:22:21 | MyTestSuite | TestClass | XUnitTestClass |
13-
| XUnit.cs:25:21:25:25 | Test1 | TestMethod | CallableTree |
14-
| XUnit.cs:25:21:25:25 | Test1 | TestMethod | CfgScope |
15-
| XUnit.cs:25:21:25:25 | Test1 | TestMethod | InstanceCallable |
16-
| XUnit.cs:25:21:25:25 | Test1 | TestMethod | XUnitTestMethod |
17-
| XUnit.cs:30:21:30:25 | Test2 | TestMethod | CallableTree |
18-
| XUnit.cs:30:21:30:25 | Test2 | TestMethod | CfgScope |
19-
| XUnit.cs:30:21:30:25 | Test2 | TestMethod | InstanceCallable |
20-
| XUnit.cs:30:21:30:25 | Test2 | TestMethod | XUnitTestMethod |
21-
| nunit.cs:75:11:75:21 | MyTestSuite | TestClass | LeafType |
22-
| nunit.cs:75:11:75:21 | MyTestSuite | TestClass | NUnitFixture |
23-
| nunit.cs:85:21:85:25 | Test1 | TestMethod | CallableTree |
24-
| nunit.cs:85:21:85:25 | Test1 | TestMethod | CfgScope |
25-
| nunit.cs:85:21:85:25 | Test1 | TestMethod | InstanceCallable |
26-
| nunit.cs:85:21:85:25 | Test1 | TestMethod | NUnitTestMethod |
27-
| nunit.cs:90:21:90:25 | Test2 | TestMethod | CallableTree |
28-
| nunit.cs:90:21:90:25 | Test2 | TestMethod | CfgScope |
29-
| nunit.cs:90:21:90:25 | Test2 | TestMethod | InstanceCallable |
30-
| nunit.cs:90:21:90:25 | Test2 | TestMethod | NUnitTestMethod |
31-
| nunit.cs:95:21:95:25 | Test3 | TestMethod | CallableTree |
32-
| nunit.cs:95:21:95:25 | Test3 | TestMethod | CfgScope |
33-
| nunit.cs:95:21:95:25 | Test3 | TestMethod | InstanceCallable |
34-
| nunit.cs:95:21:95:25 | Test3 | TestMethod | NUnitTestMethod |
35-
| nunit.cs:100:21:100:25 | Test4 | TestMethod | CallableTree |
36-
| nunit.cs:100:21:100:25 | Test4 | TestMethod | CfgScope |
37-
| nunit.cs:100:21:100:25 | Test4 | TestMethod | InstanceCallable |
38-
| nunit.cs:100:21:100:25 | Test4 | TestMethod | NUnitTestMethod |
39-
| nunit.cs:105:21:105:25 | Test5 | TestMethod | CallableTree |
40-
| nunit.cs:105:21:105:25 | Test5 | TestMethod | CfgScope |
41-
| nunit.cs:105:21:105:25 | Test5 | TestMethod | InstanceCallable |
42-
| nunit.cs:105:21:105:25 | Test5 | TestMethod | NUnitTestMethod |
1+
testClass
2+
| VisualStudio.cs:9:11:9:21 | MyTestSuite |
3+
| XUnit.cs:22:11:22:21 | MyTestSuite |
4+
| nunit.cs:75:11:75:21 | MyTestSuite |
5+
testMethod
6+
| VisualStudio.cs:12:21:12:25 | Test1 |
7+
| VisualStudio.cs:17:21:17:25 | Test2 |
8+
| XUnit.cs:25:21:25:25 | Test1 |
9+
| XUnit.cs:30:21:30:25 | Test2 |
10+
| nunit.cs:85:21:85:25 | Test1 |
11+
| nunit.cs:90:21:90:25 | Test2 |
12+
| nunit.cs:95:21:95:25 | Test3 |
13+
| nunit.cs:100:21:100:25 | Test4 |
14+
| nunit.cs:105:21:105:25 | Test5 |
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
import csharp
22
import semmle.code.csharp.frameworks.Test
33

4-
from Element e, string type, string framework
5-
where
6-
(
7-
framework = e.(TestClass).getAQlClass() and type = "TestClass"
8-
or
9-
framework = e.(TestMethod).getAQlClass() and type = "TestMethod"
10-
) and
11-
not framework = "NonNestedType" and
12-
not framework = "UnboundDeclarationType" and
13-
not framework = "SourceDeclarationCallable" and
14-
not framework = "SourceDeclarationMethod" and
15-
not framework = "NonConstructedMethod" and
16-
not framework = "RuntimeInstanceMethod" and
17-
not framework = "SummarizableMethod"
18-
select e, type, framework
4+
query predicate testClass(TestClass c) { any() }
5+
6+
query predicate testMethod(TestMethod m) { any() }

csharp/ql/test/library-tests/generics/ConsistencyChecks.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ import semmle.code.csharp.commons.ConsistencyChecks
66

77
from Element e, string m
88
where consistencyFailure(e, m)
9-
select e, "Element class " + e.getAQlClass() + " has consistency check failed: " + m
9+
select e, "Element class " + e.getAPrimaryQlClass() + " has consistency check failed: " + m

0 commit comments

Comments
 (0)