C#: Autoformat cookbook examples.

This commit is contained in:
Anders Schack-Mulligen
2019-08-02 15:30:32 +02:00
parent d6e1ba6bed
commit 40f2cec0de
15 changed files with 49 additions and 38 deletions

View File

@@ -11,6 +11,7 @@
import csharp
from CastExpr c
where c.getExpr().getType() instanceof FloatingPointType
and c.getType() instanceof IntegralType
where
c.getExpr().getType() instanceof FloatingPointType and
c.getType() instanceof IntegralType
select c

View File

@@ -6,7 +6,7 @@
* try
* exception
*/
import csharp
from CatchClause catch

View File

@@ -6,7 +6,7 @@
* constructor
* new
*/
import csharp
from ObjectCreation new

View File

@@ -6,7 +6,7 @@
* test
* boolean
*/
import csharp
from EqualityOperation eq

View File

@@ -9,7 +9,7 @@
* subtype
* supertype
*/
import csharp
from RefType type

View File

@@ -5,11 +5,12 @@
* @tags field
* read
*/
import csharp
from Field f, FieldRead read
where f.hasName("VirtualAddress")
and f.getDeclaringType().hasQualifiedName("Mono.Cecil.PE.Section")
and f = read.getTarget()
where
f.hasName("VirtualAddress") and
f.getDeclaringType().hasQualifiedName("Mono.Cecil.PE.Section") and
f = read.getTarget()
select read

View File

@@ -5,7 +5,7 @@
* @tags integer
* literal
*/
import csharp
from IntegerLiteral literal

View File

@@ -5,11 +5,12 @@
* @tags call
* method
*/
import csharp
from MethodCall call, Method method
where call.getTarget() = method
and method.hasName("MethodName")
and method.getDeclaringType().hasQualifiedName("Company.Class")
where
call.getTarget() = method and
method.hasName("MethodName") and
method.getDeclaringType().hasQualifiedName("Company.Class")
select call

View File

@@ -9,8 +9,8 @@
import csharp
from Method m, Method n
where m.calls(n)
and n.calls(m)
and m != n
where
m.calls(n) and
n.calls(m) and
m != n
select m, n

View File

@@ -8,12 +8,16 @@
* collection
* add
*/
import csharp
from MethodCall call, Method add
where call.getTarget() = add.getAnUltimateImplementor*()
and add.hasName("Add")
and add.getDeclaringType().getSourceDeclaration().hasQualifiedName("System.Collections.Generic.ICollection<>")
and call.getAnArgument() instanceof NullLiteral
where
call.getTarget() = add.getAnUltimateImplementor*() and
add.hasName("Add") and
add
.getDeclaringType()
.getSourceDeclaration()
.hasQualifiedName("System.Collections.Generic.ICollection<>") and
call.getAnArgument() instanceof NullLiteral
select call

View File

@@ -5,11 +5,12 @@
* @tags method
* override
*/
import csharp
from Method override, Method base
where base.hasName("ToString")
and base.getDeclaringType().hasQualifiedName("System.Object")
and base.getAnOverrider() = override
where
base.hasName("ToString") and
base.getDeclaringType().hasQualifiedName("System.Object") and
base.getAnOverrider() = override
select override

View File

@@ -10,8 +10,9 @@
import csharp
from SwitchStmt switch, Enum enum, EnumConstant missing
where switch.getCondition().getType() = enum
and missing.getDeclaringType() = enum
and not switch.getAConstCase().getExpr() = missing.getAnAccess()
and not exists(switch.getDefaultCase())
where
switch.getCondition().getType() = enum and
missing.getDeclaringType() = enum and
not switch.getAConstCase().getExpr() = missing.getAnAccess() and
not exists(switch.getDefaultCase())
select switch

View File

@@ -10,7 +10,8 @@
import csharp
from ConditionalExpr e
where e.getThen().stripImplicitCasts() != e.getElse().stripImplicitCasts()
and not e.getThen().getType() instanceof NullType
and not e.getElse().getType() instanceof NullType
where
e.getThen().stripImplicitCasts() != e.getElse().stripImplicitCasts() and
not e.getThen().getType() instanceof NullType and
not e.getElse().getType() instanceof NullType
select e

View File

@@ -5,7 +5,7 @@
* @tags throw
* exception
*/
import csharp
from ThrowStmt throw

View File

@@ -11,6 +11,7 @@
import csharp
from TryStmt t
where exists(t.getFinally())
and not exists(t.getACatchClause())
where
exists(t.getFinally()) and
not exists(t.getACatchClause())
select t