Java: Autoformat cookbook examples.

This commit is contained in:
Anders Schack-Mulligen
2019-08-02 15:27:28 +02:00
parent 34cdf7c96b
commit 9b74e9c4a4
16 changed files with 50 additions and 40 deletions

View File

@@ -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

View File

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

View File

@@ -6,7 +6,7 @@
* constructor
* new
*/
import java
from ClassInstanceExpr new

View File

@@ -6,7 +6,7 @@
* test
* boolean
*/
import java
from EqualityTest eq

View File

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

View File

@@ -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

View File

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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

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

View File

@@ -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

View File

@@ -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