Skip to content

Commit 7791ec3

Browse files
authored
Merge pull request #4618 from hvitved/csharp/get-source-decl-rename
C#: Rename `getSourceDeclaration()` to `getUnboundDeclaration()`
2 parents cafe55f + 129deb0 commit 7791ec3

File tree

68 files changed

+306
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+306
-254
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lgtm,codescanning
2+
* The predicate `Declaration::getSourceDeclaration/0` has been renamed to `Declaration::getUnboundDeclaration/0`.
3+
This is to avoid confusion, as it has nothing to do with declarations from source code (as opposed to declarations
4+
in assemblies), but instead has to do with generics.

csharp/ql/examples/snippets/null_argument.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ where
1717
add.hasName("Add") and
1818
add
1919
.getDeclaringType()
20-
.getSourceDeclaration()
20+
.getUnboundDeclaration()
2121
.hasQualifiedName("System.Collections.Generic.ICollection<>") and
2222
call.getAnArgument() instanceof NullLiteral
2323
select call

csharp/ql/src/API Abuse/Dispose.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class LocalScopeDisposableCreation extends Call {
5656
exists(Method create | this.getTarget() = create |
5757
create.hasName("Create") and
5858
create.isStatic() and
59-
create.getDeclaringType().getSourceDeclaration() = t.getSourceDeclaration()
59+
create.getDeclaringType().getUnboundDeclaration() = t.getUnboundDeclaration()
6060
)
6161
)
6262
}

csharp/ql/src/API Abuse/NonOverridingMethod.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ predicate nonOverridingMethod(Method m, Method vm) {
2828
not m.overrides() and
2929
not m.isOverride() and
3030
not m.isNew() and
31-
m = m.getSourceDeclaration() and
31+
m.isUnboundDeclaration() and
3232
m.getNumberOfParameters() = vm.getNumberOfParameters() and
3333
forall(int i, Parameter p1, Parameter p2 | p1 = m.getParameter(i) and p2 = vm.getParameter(i) |
3434
p1.getType() = p2.getType()
@@ -41,4 +41,4 @@ where
4141
m.fromSource() and
4242
nonOverridingMethod(m, vm)
4343
select m, "Method '" + m.getName() + "' looks like it should override $@ but does not do so.",
44-
vm.getSourceDeclaration(), vm.getQualifiedName()
44+
vm.getUnboundDeclaration(), vm.getQualifiedName()

csharp/ql/src/API Abuse/NullArgumentToEquals.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import semmle.code.csharp.frameworks.System
1515

1616
from MethodCall c, EqualsMethod equals
1717
where
18-
c.getTarget().getSourceDeclaration() = equals and
18+
c.getTarget().getUnboundDeclaration() = equals and
1919
c.getArgument(0) instanceof NullLiteral and
2020
not c.getQualifier().getType() instanceof NullableType
2121
select c, "Equality test with 'null' will never be true, but may throw a 'NullReferenceException'."

csharp/ql/src/API Abuse/UncheckedReturnValue.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ predicate important(Method m) {
3232
/** Holds if the return type of `m` is an instantiated type parameter from `m`. */
3333
predicate methodHasGenericReturnType(ConstructedMethod cm) {
3434
exists(UnboundGenericMethod ugm |
35-
ugm = cm.getSourceDeclaration() and
35+
ugm = cm.getUnboundGeneric() and
3636
ugm.getReturnType() = ugm.getATypeParameter()
3737
)
3838
}
@@ -46,16 +46,16 @@ predicate dubious(Method m, int percentage) {
4646
// Suppress on methods designed for chaining
4747
not designedForChaining(m) and
4848
exists(int used, int total, Method target |
49-
target = m.getSourceDeclaration() and
49+
target = m.getUnboundDeclaration() and
5050
used =
5151
count(MethodCall mc |
52-
mc.getTarget().getSourceDeclaration() = target and
52+
mc.getTarget().getUnboundDeclaration() = target and
5353
not mc instanceof DiscardedMethodCall and
5454
(methodHasGenericReturnType(m) implies m.getReturnType() = mc.getTarget().getReturnType())
5555
) and
5656
total =
5757
count(MethodCall mc |
58-
mc.getTarget().getSourceDeclaration() = target and
58+
mc.getTarget().getUnboundDeclaration() = target and
5959
(methodHasGenericReturnType(m) implies m.getReturnType() = mc.getTarget().getReturnType())
6060
) and
6161
used != total and

csharp/ql/src/Architecture/Refactoring Opportunities/FeatureEnvy.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import csharp
1616

1717
Member getAUsedMember(Method m) {
1818
exists(MemberAccess ma | ma.getEnclosingCallable() = m |
19-
result = ma.getTarget().getSourceDeclaration()
19+
result = ma.getTarget().getUnboundDeclaration()
2020
)
2121
or
22-
exists(Call c | c.getEnclosingCallable() = m | result = c.getTarget().getSourceDeclaration())
22+
exists(Call c | c.getEnclosingCallable() = m | result = c.getTarget().getUnboundDeclaration())
2323
}
2424

2525
int dependencyCount(Method source, RefType target) {
@@ -50,8 +50,8 @@ predicate query(Method m, RefType targetType, int selfCount, int depCount) {
5050
not m instanceof ExtensionMethod and
5151
// Do not move up/down the class hierarchy
5252
not (
53-
sourceType.getABaseType*().getSourceDeclaration() = targetType or
54-
targetType.getABaseType*().getSourceDeclaration() = sourceType
53+
sourceType.getABaseType*().getUnboundDeclaration() = targetType or
54+
targetType.getABaseType*().getUnboundDeclaration() = sourceType
5555
) and
5656
// Do not move between nested types
5757
not (sourceType.getDeclaringType*() = targetType or targetType.getDeclaringType*() = sourceType) and

csharp/ql/src/Bad Practices/Implementation Hiding/AbstractToConcreteCollection.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class CollectionInterface extends Interface {
2222
CollectionInterface() {
2323
exists(Interface i | i = this.getABaseInterface*() |
2424
i instanceof SystemCollectionsICollectionInterface or
25-
i.getSourceDeclaration() instanceof SystemCollectionsGenericICollectionInterface or
25+
i.getUnboundDeclaration() instanceof SystemCollectionsGenericICollectionInterface or
2626
i instanceof SystemCollectionsIEnumerableInterface or
27-
i.getSourceDeclaration() instanceof SystemCollectionsGenericIEnumerableTInterface
27+
i.getUnboundDeclaration() instanceof SystemCollectionsGenericIEnumerableTInterface
2828
)
2929
}
3030
}

csharp/ql/src/Bad Practices/Implementation Hiding/ExposeRepresentation.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import semmle.code.csharp.commons.Collections
1515
import DataFlow
1616

1717
predicate storesCollection(Callable c, Parameter p, Field f) {
18-
f.getDeclaringType() = c.getDeclaringType().getABaseType*().getSourceDeclaration() and
18+
f.getDeclaringType() = c.getDeclaringType().getABaseType*().getUnboundDeclaration() and
1919
f.getType() instanceof CollectionType and
2020
p = c.getAParameter() and
2121
f.getAnAssignedValue() = p.getAnAccess() and
2222
not c.(Modifiable).isStatic()
2323
}
2424

2525
predicate returnsCollection(Callable c, Field f) {
26-
f.getDeclaringType() = c.getDeclaringType().getABaseType*().getSourceDeclaration() and
26+
f.getDeclaringType() = c.getDeclaringType().getABaseType*().getUnboundDeclaration() and
2727
f.getType() instanceof CollectionType and
2828
c.canReturn(f.getAnAccess()) and
2929
not c.(Modifiable).isStatic()

csharp/ql/src/Dead Code/DeadCode.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Expr getAnAccessByDynamicCall(Method m) {
3636
Expr getAMethodAccess(Method m) {
3737
result = getAnAccessByDynamicCall(m) or
3838
result = getAnAccessByReflection(m) or
39-
result.(MethodCall).getTarget().getSourceDeclaration() = m or
40-
result.(MethodAccess).getTarget().getSourceDeclaration() = m
39+
result.(MethodCall).getTarget().getUnboundDeclaration() = m or
40+
result.(MethodAccess).getTarget().getUnboundDeclaration() = m
4141
}
4242

4343
predicate potentiallyAccessedByForEach(Method m) {
@@ -63,7 +63,7 @@ predicate isRecursivelyLiveMethod(Method m) {
6363
or
6464
potentiallyAccessedByForEach(m)
6565
or
66-
isRecursivelyLiveMethod(m.(ConstructedMethod).getSourceDeclaration())
66+
isRecursivelyLiveMethod(m.(ConstructedMethod).getUnboundDeclaration())
6767
or
6868
nunitValueSource(m)
6969
or
@@ -78,7 +78,7 @@ predicate nunitValueSource(Method m) {
7878
}
7979

8080
predicate nunitTestCaseSource(Declaration f) {
81-
exists(TestCaseSourceAttribute attribute | attribute.getSourceDeclaration() = f)
81+
exists(TestCaseSourceAttribute attribute | attribute.getUnboundDeclaration() = f)
8282
}
8383

8484
predicate isDeadMethod(Method m) {
@@ -89,9 +89,9 @@ predicate isDeadMethod(Method m) {
8989
predicate isDeadField(Field f) {
9090
f.isPrivate() and
9191
not f.getDeclaringType() instanceof AnonymousClass and
92-
f.getSourceDeclaration() = f and
92+
f.getUnboundDeclaration() = f and
9393
not nunitTestCaseSource(f) and
94-
forall(FieldAccess fc | fc.getTarget().getSourceDeclaration() = f |
94+
forall(FieldAccess fc | fc.getTarget().getUnboundDeclaration() = f |
9595
isDeadMethod(fc.getEnclosingCallable())
9696
or
9797
not fc instanceof FieldRead and not fc.isRefArgument()

0 commit comments

Comments
 (0)