Fix false positive on UnsynchronizedStaticFormatterRule

This commit is contained in:
Juan Martín Sotuyo Dodero
2019-07-18 19:35:09 -03:00
parent ca34d4fa1c
commit cb62b7e472

View File

@ -77,14 +77,7 @@ public class UnsynchronizedStaticFormatterRule extends AbstractJavaRule {
continue;
}
if (getProperty(ALLOW_METHOD_LEVEL_SYNC)) {
ASTMethodDeclaration method = n.getFirstParentOfType(ASTMethodDeclaration.class);
if (method != null && (!method.isSynchronized() || !method.isStatic())) {
addViolation(data, node);
}
continue;
}
// is there a block-level synch?
ASTSynchronizedStatement syncStatement = n.getFirstParentOfType(ASTSynchronizedStatement.class);
if (syncStatement != null) {
ASTExpression expression = syncStatement.getFirstChildOfType(ASTExpression.class);
@ -95,6 +88,15 @@ public class UnsynchronizedStaticFormatterRule extends AbstractJavaRule {
}
}
}
// method level synch enabled and used?
if (getProperty(ALLOW_METHOD_LEVEL_SYNC)) {
ASTMethodDeclaration method = n.getFirstParentOfType(ASTMethodDeclaration.class);
if (method != null && method.isSynchronized() && method.isStatic()) {
continue;
}
}
addViolation(data, n);
}
return data;