Java: Autoformat.

This commit is contained in:
Anders Schack-Mulligen
2018-10-11 10:02:20 +02:00
parent 766b07ba59
commit 62ef811169
8 changed files with 165 additions and 156 deletions

View File

@@ -37,9 +37,7 @@ class InstanceFieldWrite extends FieldWrite {
*/
class ImpureStmt extends Stmt {
ImpureStmt() {
exists(Expr e |
e.getEnclosingStmt() = this
|
exists(Expr e | e.getEnclosingStmt() = this |
// Only permit calls to set of whitelisted targets.
(
e instanceof Call and
@@ -57,12 +55,12 @@ class ImpureStmt extends Stmt {
*/
private Stmt getANestedStmt(Block block) {
// Any non-block statement
not result instanceof Block and result = block.getAStmt() or
not result instanceof Block and result = block.getAStmt()
or
// Or any statement nested in a block
result = getANestedStmt(block.getAStmt())
}
/**
* A class whose loading and construction by Spring does not have any side-effects outside the class.
*
@@ -73,12 +71,8 @@ class SpringPureClass extends Class {
(
// The only permitted statement in static initializers is the initialization of a static
// final or effectively final logger fields, or effectively immutable types.
forall(Stmt s |
s = getANestedStmt(getAMember().(StaticInitializer).getBody())
|
exists(Field f |
f = s.(ExprStmt).getExpr().(AssignExpr).getDest().(FieldWrite).getField()
|
forall(Stmt s | s = getANestedStmt(getAMember().(StaticInitializer).getBody()) |
exists(Field f | f = s.(ExprStmt).getExpr().(AssignExpr).getDest().(FieldWrite).getField() |
(
// A logger field
f.getName().toLowerCase() = "logger" or
@@ -88,11 +82,7 @@ class SpringPureClass extends Class {
) and
f.isStatic() and
// Only written to in this statement e.g. final or effectively final
forall(FieldWrite fw |
fw = f.getAnAccess()
|
fw.getEnclosingStmt() = s
)
forall(FieldWrite fw | fw = f.getAnAccess() | fw.getEnclosingStmt() = s)
)
)
) and
@@ -103,20 +93,23 @@ class SpringPureClass extends Class {
c = getAMember()
) and
impureStmt.getEnclosingCallable() = c
|
c instanceof InstanceInitializer or
c instanceof Constructor or
|
c instanceof InstanceInitializer
or
c instanceof Constructor
or
// afterPropertiesSet() method called after bean initialization
c = this.(InitializingBeanClass).getAfterPropertiesSet() or
c = this.(InitializingBeanClass).getAfterPropertiesSet()
or
// Init and setter methods must be pure, because they are called when the bean is initialized
exists(SpringBean bean |
this = bean.getClass()
|
exists(SpringBean bean | this = bean.getClass() |
c = bean.getInitMethod() or
c = bean.getAProperty().getSetterMethod()
) or
)
or
// Setter method by autowiring, either in the XML or by annotation
c = this.getAMethod().(SpringBeanAutowiredCallable) or
c = this.getAMethod().(SpringBeanAutowiredCallable)
or
c = this.getAMethod().(SpringBeanXMLAutowiredSetterMethod)
)
}
@@ -130,7 +123,6 @@ class SpringBeanFactory extends ClassOrInterface {
getAnAncestor().hasQualifiedName("org.springframework.beans.factory", "BeanFactory")
}
/**
* Get a bean constructed by a call to this bean factory.
*/
@@ -139,7 +131,7 @@ class SpringBeanFactory extends ClassOrInterface {
getBean.hasName("getBean") and
call.getMethod() = getBean and
getBean.getDeclaringType() = this
|
|
result.getBeanIdentifier() = call.getArgument(0).(CompileTimeConstantExpr).getStringValue()
)
}
@@ -158,7 +150,8 @@ class LiveSpringBean extends SpringBean {
not isLazyInit() and
// or has no side-effects when constructed
not getClass() instanceof SpringPureClass
) or
)
or
(
// If the class does not exist for this bean, or the class is not a source bean, then this is
// likely to be a definition using a library class, in which case we should consider it to be
@@ -170,43 +163,45 @@ class LiveSpringBean extends SpringBean {
// A live child bean implies this bean is live
exists(LiveSpringBean child | this = child.getBeanParent()) or
// Beans constructed by a bean factory are considered live
exists(SpringBeanFactory beanFactory |
this = beanFactory.getAConstructedBean()
)
) or
exists(SpringBeanFactory beanFactory | this = beanFactory.getAConstructedBean())
)
or
(
// Referenced by a live bean, either as a property or argument in the XML
exists(LiveSpringBean other |
this = other.getAConstructorArg().getArgRefBean() or
this = other.getAProperty().getPropertyRefBean()
) or
)
or
// Referenced as a factory bean
exists(LiveSpringBean springBean |
this = springBean.getFactoryBean()
) or
exists(LiveSpringBean springBean | this = springBean.getFactoryBean())
or
// Injected by @Autowired annotation
exists(SpringBeanAutowiredCallable autowiredCallable |
// The callable must be in a live class
autowiredCallable.getEnclosingSpringBean() instanceof LiveSpringBean or
autowiredCallable.getEnclosingSpringComponent().isLive()
|
|
// This bean is injected into it
this = autowiredCallable.getAnInjectedBean()
) or
)
or
// Injected by @Autowired annotation on field
exists(SpringBeanAutowiredField autowiredField |
// The field must be in a live class
autowiredField.getEnclosingSpringBean() instanceof LiveSpringBean or
autowiredField.getEnclosingSpringComponent().isLive()
|
|
// This bean is injected into it
this = autowiredField.getInjectedBean()
) or
)
or
// Injected by autowired specified in XML
exists(SpringBeanXMLAutowiredSetterMethod setterMethod |
// The config method must be on a live bean
setterMethod.getDeclaringType().(SpringBeanRefType).getSpringBean() instanceof LiveSpringBean
|
setterMethod.getDeclaringType().(SpringBeanRefType).getSpringBean() instanceof
LiveSpringBean
|
// This bean is injected into it
this = setterMethod.getInjectedBean()
)
@@ -218,9 +213,7 @@ class LiveSpringBean extends SpringBean {
* A `SpringBean` that can be safely removed from the program without changing overall behavior.
*/
class UnusedSpringBean extends SpringBean {
UnusedSpringBean() {
not this instanceof LiveSpringBean
}
UnusedSpringBean() { not this instanceof LiveSpringBean }
}
from UnusedSpringBean unused