Skip to content

Commit f90b0fd

Browse files
committed
C#: Convert some multi-line comments
1 parent b81d2ca commit f90b0fd

File tree

23 files changed

+168
-264
lines changed

23 files changed

+168
-264
lines changed

csharp/ql/src/Bad Practices/Naming Conventions/ConfusingOverridesNames.ql

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,16 @@ predicate confusing(Method m1, Method m2) {
4343
)
4444
}
4545

46-
/*
47-
* Two method names are confusing if all of the following conditions hold:
48-
* They are both static methods or both instance methods.
49-
* They are not declared in the same class, and the superclass method is
50-
* not overridden in an intermediate class
51-
* They have different names.
52-
* They have the same names if case is ignored.
53-
* There is no method in the subclass that has the same name as
54-
* the superclass method
55-
* There is an additional check that only methods with names longer than one character
56-
* can be considered confusing.
57-
*/
58-
46+
// Two method names are confusing if all of the following conditions hold:
47+
// They are both static methods or both instance methods.
48+
// They are not declared in the same class, and the superclass method is
49+
// not overridden in an intermediate class
50+
// They have different names.
51+
// They have the same names if case is ignored.
52+
// There is no method in the subclass that has the same name as
53+
// the superclass method
54+
// There is an additional check that only methods with names longer than one character
55+
// can be considered confusing.
5956
from Method m1, Method m2
6057
where
6158
confusing(m1, m2) and

csharp/ql/src/Metrics/Files/FSelfContainedness.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import csharp
1414
import semmle.code.csharp.metrics.Coupling
1515

16-
/* Self-containedness on file level */
16+
// Self-containedness on file level
1717
from File f, float selfContaindness, int efferentSourceCoupling, int efferentCoupling
1818
where
1919
efferentSourceCoupling = count(File g |

csharp/ql/src/Security Features/CWE-352/MissingAntiForgeryTokenValidation.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ class AntiForgeryAuthorizationFilter extends AuthorizationFilter {
2626
* Holds if the project has a global anti forgery filter.
2727
*/
2828
predicate hasGlobalAntiForgeryFilter() {
29-
/*
30-
* A global filter added
31-
*/
32-
29+
// A global filter added
3330
exists(MethodCall addGlobalFilter |
3431
// addGlobalFilter adds a filter to the global filter collection
3532
addGlobalFilter.getTarget() = any(GlobalFilterCollection gfc).getAddMethod() and

csharp/ql/src/Security Features/CWE-451/MissingXFrameOptions.ql

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@ import semmle.code.csharp.frameworks.system.Web
1919
* Holds if there exists a `Web.config` file in the snapshot that adds an `X-Frame-Options` header.
2020
*/
2121
predicate hasWebConfigXFrameOptions() {
22-
/*
23-
* Looking for an entry in a Web.config file that looks like this:
24-
* ```
25-
* <system.webServer>
26-
* <httpProtocol>
27-
* <customHeaders>
28-
* <add name="X-Frame-Options" value="SAMEORIGIN" />
29-
* </customHeaders>
30-
* </httpProtocol>
31-
* </system.webServer>
32-
* ```
33-
*/
34-
22+
// Looking for an entry in a Web.config file that looks like this:
23+
// ```
24+
// <system.webServer>
25+
// <httpProtocol>
26+
// <customHeaders>
27+
// <add name="X-Frame-Options" value="SAMEORIGIN" />
28+
// </customHeaders>
29+
// </httpProtocol>
30+
// </system.webServer>
31+
// ```
3532
exists(XMLElement element |
3633
element = any(WebConfigXML webConfig)
3734
.getARootElement()

csharp/ql/src/Stubs/MinimalStubsFromSource.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/**
22
* Tool to generate C# stubs from a qltest snapshot.
33
*
44
* It finds all declarations used in the source code,

csharp/ql/src/semmle/code/asp/AspNet.qll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,12 @@ class PageDirective extends AspDirective {
184184
ValueOrRefType getInheritedType() { result.getQualifiedName() = getInheritedTypeQualifiedName() }
185185

186186
private string getInheritedTypeQualifiedName() {
187-
/*
188-
* Relevant attributes:
189-
* - `Inherits`: determines the class to inherit from, this is what we want
190-
* - `ClassName`: determines the name to use for the compiled class, can
191-
* provide a fallback namespace if `Inherits` does not have one
192-
* - `CodeBehindFile`/`CodeFile`: used by tooling, but not semantically
193-
* relevant at runtime
194-
*/
195-
187+
// Relevant attributes:
188+
// - `Inherits`: determines the class to inherit from, this is what we want
189+
// - `ClassName`: determines the name to use for the compiled class, can
190+
// provide a fallback namespace if `Inherits` does not have one
191+
// - `CodeBehindFile`/`CodeFile`: used by tooling, but not semantically
192+
// relevant at runtime
196193
exists(string inherits | inherits = getAttributeByName("Inherits").getBody() |
197194
if inherits.indexOf(".") != -1
198195
then result = inherits

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

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -307,24 +307,22 @@ private module Identity {
307307
private predicate convIdentityStrictConstructedType(
308308
IdentityConvertibleConstructedType fromType, IdentityConvertibleConstructedType toType
309309
) {
310-
/*
311-
* Semantically equivalent with
312-
* ```
313-
* ugt = fromType.getUnboundGeneric()
314-
* and
315-
* forex(int i |
316-
* i in [0 .. ugt.getNumberOfTypeParameters() - 1] |
317-
* exists(Type t1, Type t2 |
318-
* t1 = getTypeArgument(ugt, fromType, i, _) and
319-
* t2 = getTypeArgument(ugt, toType, i, _) |
320-
* convIdentity(t1, t2)
321-
* )
322-
* )
323-
* ```
324-
* but performance is improved by explicitly evaluating the `i`th argument
325-
* only when all preceding arguments are convertible.
326-
*/
327-
310+
// Semantically equivalent with
311+
// ```
312+
// ugt = fromType.getUnboundGeneric()
313+
// and
314+
// forex(int i |
315+
// i in [0 .. ugt.getNumberOfTypeParameters() - 1] |
316+
// exists(Type t1, Type t2 |
317+
// t1 = getTypeArgument(ugt, fromType, i, _) and
318+
// t2 = getTypeArgument(ugt, toType, i, _) |
319+
// convIdentity(t1, t2)
320+
// )
321+
// )
322+
// ```
323+
// but performance is improved by explicitly evaluating the `i`th argument
324+
// only when all preceding arguments are convertible.
325+
//
328326
fromType != toType and
329327
(
330328
convIdentitySingle(_, fromType, toType)
@@ -462,11 +460,8 @@ predicate convNullableType(ValueOrRefType fromType, NullableType toType) {
462460
)
463461
}
464462

465-
/*
466-
* This is a deliberate, small Cartesian product, so we have manually lifted it to force the
467-
* evaluator to evaluate it in its entirety, rather than trying to optimize it in context.
468-
*/
469-
463+
// This is a deliberate, small Cartesian product, so we have manually lifted it to force the
464+
// evaluator to evaluate it in its entirety, rather than trying to optimize it in context.
470465
pragma[noinline]
471466
private predicate defaultNullConversion(Type fromType, Type toType) {
472467
fromType instanceof NullType and convNullType(toType)
@@ -491,21 +486,15 @@ private predicate convRefTypeNonNull(Type fromType, Type toType) {
491486
convRefTypeParameter(fromType, toType)
492487
}
493488

494-
/*
495-
* This is a deliberate, small cartesian product, so we have manually lifted it to force the
496-
* evaluator to evaluate it in its entirety, rather than trying to optimize it in context.
497-
*/
498-
489+
// This is a deliberate, small cartesian product, so we have manually lifted it to force the
490+
// evaluator to evaluate it in its entirety, rather than trying to optimize it in context.
499491
pragma[noinline]
500492
private predicate defaultDynamicConversion(Type fromType, Type toType) {
501493
fromType instanceof RefType and toType instanceof DynamicType
502494
}
503495

504-
/*
505-
* This is a deliberate, small cartesian product, so we have manually lifted it to force the
506-
* evaluator to evaluate it in its entirety, rather than trying to optimize it in context.
507-
*/
508-
496+
// This is a deliberate, small cartesian product, so we have manually lifted it to force the
497+
// evaluator to evaluate it in its entirety, rather than trying to optimize it in context.
509498
pragma[noinline]
510499
private predicate defaultDelegateConversion(RefType fromType, RefType toType) {
511500
fromType instanceof DelegateType and toType = any(SystemDelegateClass c).getABaseType*()
@@ -525,11 +514,8 @@ private predicate convRefTypeRefType(RefType fromType, RefType toType) {
525514
)
526515
}
527516

528-
/*
529-
* This is a deliberate, small cartesian product, so we have manually lifted it to force the
530-
* evaluator to evaluate it in its entirety, rather than trying to optimize it in context.
531-
*/
532-
517+
// This is a deliberate, small cartesian product, so we have manually lifted it to force the
518+
// evaluator to evaluate it in its entirety, rather than trying to optimize it in context.
533519
pragma[noinline]
534520
private predicate defaultArrayConversion(Type fromType, RefType toType) {
535521
fromType instanceof ArrayType and toType = any(SystemArrayClass c).getABaseType*()
@@ -745,28 +731,25 @@ predicate convConversionOperator(Type fromType, Type toType) {
745731

746732
/** 13.1.3.2: Variance conversion. */
747733
private predicate convVariance(ConstructedType fromType, ConstructedType toType) {
748-
/*
749-
* Semantically equivalent with
750-
* ```
751-
* ugt = fromType.getUnboundGeneric()
752-
* and
753-
* forex(int i |
754-
* i in [0 .. ugt.getNumberOfTypeParameters() - 1] |
755-
* exists(Type t1, Type t2, TypeParameter tp |
756-
* t1 = getTypeArgument(ugt, fromType, i, tp) and
757-
* t2 = getTypeArgument(ugt, toType, i, tp) |
758-
* convIdentity(t1, t2)
759-
* or
760-
* convRefTypeNonNull(t1, t2) and tp.isOut()
761-
* or
762-
* convRefTypeNonNull(t2, t1) and tp.isIn()
763-
* )
764-
* )
765-
* ```
766-
* but performance is improved by explicitly evaluating the `i`th argument
767-
* only when all preceding arguments are convertible.
768-
*/
769-
734+
// Semantically equivalent with
735+
// ```
736+
// ugt = fromType.getUnboundGeneric()
737+
// and
738+
// forex(int i |
739+
// i in [0 .. ugt.getNumberOfTypeParameters() - 1] |
740+
// exists(Type t1, Type t2, TypeParameter tp |
741+
// t1 = getTypeArgument(ugt, fromType, i, tp) and
742+
// t2 = getTypeArgument(ugt, toType, i, tp) |
743+
// convIdentity(t1, t2)
744+
// or
745+
// convRefTypeNonNull(t1, t2) and tp.isOut()
746+
// or
747+
// convRefTypeNonNull(t2, t1) and tp.isIn()
748+
// )
749+
// )
750+
// ```
751+
// but performance is improved by explicitly evaluating the `i`th argument
752+
// only when all preceding arguments are convertible.
770753
Variance::convVarianceSingle(_, fromType, toType)
771754
or
772755
exists(UnboundGenericType ugt |

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ module Internal {
2727
*/
2828
cached
2929
predicate enclosingCallable(Stmt s, Callable c) {
30-
/*
31-
* Compute the enclosing callable for a statement. This walks up through
32-
* enclosing statements until it hits a callable. It's unambiguous, since
33-
* if a statement has no parent statement, it's either the method body
34-
* or the body of an anonymous function declaration, in each of which cases the
35-
* non-statement parent is in fact the enclosing callable.
36-
*/
37-
30+
// Compute the enclosing callable for a statement. This walks up through
31+
// enclosing statements until it hits a callable. It's unambiguous, since
32+
// if a statement has no parent statement, it's either the method body
33+
// or the body of an anonymous function declaration, in each of which cases the
34+
// non-statement parent is in fact the enclosing callable.
3835
c.getAChildStmt+() = s
3936
}
4037

@@ -50,13 +47,10 @@ module Internal {
5047
*/
5148
cached
5249
predicate enclosingStmt(Expr e, Stmt s) {
53-
/*
54-
* Compute the enclosing statement for an expression. Note that this need
55-
* not exist, since expressions can occur in contexts where they have no
56-
* enclosing statement (examples include field initialisers, both inline
57-
* and explicit on constructor definitions, and annotation arguments).
58-
*/
59-
50+
// Compute the enclosing statement for an expression. Note that this need
51+
// not exist, since expressions can occur in contexts where they have no
52+
// enclosing statement (examples include field initialisers, both inline
53+
// and explicit on constructor definitions, and annotation arguments).
6054
getAChildExpr+(s) = e
6155
}
6256

@@ -76,14 +70,11 @@ module Internal {
7670
*/
7771
cached
7872
predicate exprEnclosingCallable(Expr e, Callable c) {
79-
/*
80-
* Compute the enclosing callable of an expression. Note that expressions in
81-
* lambda functions should have the lambdas as enclosing callables, and their
82-
* enclosing statement may be the same as the enclosing statement of the
83-
* lambda; thus, it is *not* safe to go up to the enclosing statement and
84-
* take its own enclosing callable.
85-
*/
86-
73+
// Compute the enclosing callable of an expression. Note that expressions in
74+
// lambda functions should have the lambdas as enclosing callables, and their
75+
// enclosing statement may be the same as the enclosing statement of the
76+
// lambda; thus, it is *not* safe to go up to the enclosing statement and
77+
// take its own enclosing callable.
8778
childExprOfCallable(c, e)
8879
or
8980
not childExprOfCallable(_, e) and

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,20 @@ class TypeParameter extends DotNet::TypeParameter, Type, @type_parameter {
158158

159159
/** Gets a type that was supplied for this parameter. */
160160
Type getASuppliedType() {
161-
/*
162-
* A type parameter either comes from the source declaration
163-
* or from a partially constructed generic.
164-
*
165-
* When from a source declaration, return type arguments from all ConstructedGenerics,
166-
* and when from a partially constructed UnboundGeneric, return type arguments from
167-
* directly ConstructedGenerics.
168-
*
169-
* e.g.
170-
*
171-
* class A<T1> { class B<T2> { } }
172-
*
173-
* A<T1>.B<T2> is the UnboundGenericClass source declaration,
174-
* A<int>.B<T2> is a partially constructed UnboundGenericClass and
175-
* A<int>.B<int> is a ConstructedGenericClass.
176-
*/
177-
161+
// A type parameter either comes from the source declaration
162+
// or from a partially constructed generic.
163+
//
164+
// When from a source declaration, return type arguments from all ConstructedGenerics,
165+
// and when from a partially constructed UnboundGeneric, return type arguments from
166+
// directly ConstructedGenerics.
167+
//
168+
// For example:
169+
//
170+
// class A<T1> { class B<T2> { } }
171+
//
172+
// A<T1>.B<T2> is the UnboundGenericClass source declaration,
173+
// A<int>.B<T2> is a partially constructed UnboundGenericClass and
174+
// A<int>.B<int> is a ConstructedGenericClass.
178175
exists(ConstructedGeneric c, UnboundGeneric u, int tpi |
179176
this = u.getTypeParameter(tpi) and
180177
(u = c.getUnboundGeneric() or u = c.getSourceDeclaration()) and

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,8 @@ class Property extends DotNet::Property, DeclarationWithGetSetAccessors, @proper
178178
override Expr getAnAssignedValue() {
179179
result = DeclarationWithGetSetAccessors.super.getAnAssignedValue()
180180
or
181-
/*
182-
* For library types, we don't know about assignments in constructors. We instead assume that
183-
* arguments passed to parameters of constructors with suitable names.
184-
*/
185-
181+
// For library types, we don't know about assignments in constructors. We instead assume that
182+
// arguments passed to parameters of constructors with suitable names.
186183
getDeclaringType().fromLibrary() and
187184
exists(Parameter param, Constructor c, string propertyName |
188185
propertyName = getName() and

0 commit comments

Comments
 (0)