mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Java: Autoformat cookbook examples.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
import java
|
||||
|
||||
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
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* try
|
||||
* exception
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from CatchClause catch
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* constructor
|
||||
* new
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from ClassInstanceExpr new
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* test
|
||||
* boolean
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from EqualityTest eq
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* subtype
|
||||
* supertype
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from RefType type
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
* @tags field
|
||||
* read
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from Field f, FieldRead read
|
||||
where f.hasName("aField")
|
||||
and f.getDeclaringType().hasQualifiedName("com.example", "Class")
|
||||
and f = read.getField()
|
||||
where
|
||||
f.hasName("aField") and
|
||||
f.getDeclaringType().hasQualifiedName("com.example", "Class") and
|
||||
f = read.getField()
|
||||
select read
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @tags integer
|
||||
* literal
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from IntegerLiteral literal
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
* @tags call
|
||||
* method
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from MethodAccess call, Method method
|
||||
where call.getMethod() = method
|
||||
and method.hasName("methodName")
|
||||
and method.getDeclaringType().hasQualifiedName("com.example", "Class")
|
||||
where
|
||||
call.getMethod() = method and
|
||||
method.hasName("methodName") and
|
||||
method.getDeclaringType().hasQualifiedName("com.example", "Class")
|
||||
select call
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
import java
|
||||
|
||||
from Method m, Method n
|
||||
where exists(MethodAccess ma | ma.getCaller() = m and ma.getCallee() = n)
|
||||
and exists(MethodAccess ma | ma.getCaller() = n and ma.getCallee() = m)
|
||||
and m != n
|
||||
where
|
||||
exists(MethodAccess ma | ma.getCaller() = m and ma.getCallee() = n) and
|
||||
exists(MethodAccess ma | ma.getCaller() = n and ma.getCallee() = m) and
|
||||
m != n
|
||||
select m, n
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
* collection
|
||||
* add
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from MethodAccess call, Method add
|
||||
where call.getMethod().overrides*(add)
|
||||
and add.hasName("add")
|
||||
and add.getDeclaringType().getSourceDeclaration().hasQualifiedName("java.util", "Collection")
|
||||
and call.getAnArgument() instanceof NullLiteral
|
||||
where
|
||||
call.getMethod().overrides*(add) and
|
||||
add.hasName("add") and
|
||||
add.getDeclaringType().getSourceDeclaration().hasQualifiedName("java.util", "Collection") and
|
||||
call.getAnArgument() instanceof NullLiteral
|
||||
select call
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
* @tags method
|
||||
* override
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from Method override, Method base
|
||||
where base.hasName("baseMethod")
|
||||
and base.getDeclaringType().hasQualifiedName("com.example", "Class")
|
||||
and override.overrides+(base)
|
||||
where
|
||||
base.hasName("baseMethod") and
|
||||
base.getDeclaringType().hasQualifiedName("com.example", "Class") and
|
||||
override.overrides+(base)
|
||||
select override
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
import java
|
||||
|
||||
from SwitchStmt switch, EnumType enum, EnumConstant missing
|
||||
where switch.getExpr().getType() = enum
|
||||
and missing.getDeclaringType() = enum
|
||||
and not switch.getAConstCase().getValue() = missing.getAnAccess()
|
||||
and not exists(switch.getDefaultCase())
|
||||
where
|
||||
switch.getExpr().getType() = enum and
|
||||
missing.getDeclaringType() = enum and
|
||||
not switch.getAConstCase().getValue() = missing.getAnAccess() and
|
||||
not exists(switch.getDefaultCase())
|
||||
select switch
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
import java
|
||||
|
||||
from ConditionalExpr e
|
||||
where e.getTrueExpr().getType() != e.getFalseExpr().getType()
|
||||
and not e.getTrueExpr().getType() instanceof NullType
|
||||
and not e.getFalseExpr().getType() instanceof NullType
|
||||
where
|
||||
e.getTrueExpr().getType() != e.getFalseExpr().getType() and
|
||||
not e.getTrueExpr().getType() instanceof NullType and
|
||||
not e.getFalseExpr().getType() instanceof NullType
|
||||
select e
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @tags throw
|
||||
* exception
|
||||
*/
|
||||
|
||||
|
||||
import java
|
||||
|
||||
from ThrowStmt throw
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import java
|
||||
|
||||
from TryStmt t
|
||||
where exists(t.getFinally())
|
||||
and not exists(t.getACatchClause())
|
||||
where
|
||||
exists(t.getFinally()) and
|
||||
not exists(t.getACatchClause())
|
||||
select t
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
import java
|
||||
|
||||
from Method m
|
||||
where m.isPrivate()
|
||||
and not exists(m.getAReference())
|
||||
and not m instanceof InitializerMethod
|
||||
where
|
||||
m.isPrivate() and
|
||||
not exists(m.getAReference()) and
|
||||
not m instanceof InitializerMethod
|
||||
select m
|
||||
|
||||
Reference in New Issue
Block a user