reformat, whitespaces
This commit is contained in:
@ -36,8 +36,8 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
|
||||
private static final Set<String> LOGGER_LEVELS;
|
||||
private static final String LOGGER_CLASS = "org.slf4j.Logger";
|
||||
static {
|
||||
LOGGER_LEVELS = Collections.unmodifiableSet(
|
||||
new HashSet<String>(Arrays.asList("trace", "debug", "info", "warn", "error")));
|
||||
LOGGER_LEVELS = Collections
|
||||
.unmodifiableSet(new HashSet<String>(Arrays.asList("trace", "debug", "info", "warn", "error")));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,8 +58,8 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
|
||||
final ASTPrimaryExpression parentNode = node.getFirstParentOfType(ASTPrimaryExpression.class);
|
||||
|
||||
// get the log level
|
||||
final String method = parentNode.getFirstChildOfType(ASTPrimaryPrefix.class)
|
||||
.getFirstChildOfType(ASTName.class).getImage().replace(nameDeclaration.getImage() + ".", "");
|
||||
final String method = parentNode.getFirstChildOfType(ASTPrimaryPrefix.class).getFirstChildOfType(ASTName.class)
|
||||
.getImage().replace(nameDeclaration.getImage() + ".", "");
|
||||
|
||||
// ignore if not a log level
|
||||
if (!LOGGER_LEVELS.contains(method)) {
|
||||
@ -106,13 +106,15 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
|
||||
|
||||
private void removeThrowableParam(final List<ASTPrimaryExpression> params) {
|
||||
// Throwable parameters are the last one in the list, if any.
|
||||
if (params.isEmpty()) return;
|
||||
if (params.isEmpty())
|
||||
return;
|
||||
int lastIndex = params.size() - 1;
|
||||
ASTPrimaryExpression last = params.get(lastIndex);
|
||||
|
||||
// in case a new exception is created or the exception class is mentioned.
|
||||
ASTClassOrInterfaceType classOrInterface = last.getFirstDescendantOfType(ASTClassOrInterfaceType.class);
|
||||
if (classOrInterface != null && classOrInterface.getType() != null && Throwable.class.isAssignableFrom(classOrInterface.getType())) {
|
||||
if (classOrInterface != null && classOrInterface.getType() != null
|
||||
&& Throwable.class.isAssignableFrom(classOrInterface.getType())) {
|
||||
params.remove(lastIndex);
|
||||
return;
|
||||
}
|
||||
@ -125,8 +127,9 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
|
||||
|
||||
// check the variable type, if there is a reference by name
|
||||
ASTName variable = last.getFirstDescendantOfType(ASTName.class);
|
||||
if (variable != null && variable.getNameDeclaration() != null && variable.getNameDeclaration() instanceof VariableNameDeclaration) {
|
||||
VariableNameDeclaration declaration = (VariableNameDeclaration)variable.getNameDeclaration();
|
||||
if (variable != null && variable.getNameDeclaration() != null
|
||||
&& variable.getNameDeclaration() instanceof VariableNameDeclaration) {
|
||||
VariableNameDeclaration declaration = (VariableNameDeclaration) variable.getNameDeclaration();
|
||||
if (declaration.getType() != null && Throwable.class.isAssignableFrom(declaration.getType())) {
|
||||
params.remove(lastIndex);
|
||||
return;
|
||||
@ -140,8 +143,8 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
|
||||
}
|
||||
|
||||
private String getExpectedMessage(final List<ASTPrimaryExpression> params, final int expectedArguments) {
|
||||
return " expected " + expectedArguments
|
||||
+ (expectedArguments > 1 ? " arguments " : " argument ") + "but have " + params.size();
|
||||
return " expected " + expectedArguments + (expectedArguments > 1 ? " arguments " : " argument ") + "but have "
|
||||
+ params.size();
|
||||
}
|
||||
|
||||
private int expectedArguments(final ASTPrimaryExpression node) {
|
||||
@ -173,8 +176,8 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
|
||||
|
||||
private int getAmountOfExpectedArguments(final String variableName, final List<ASTVariableDeclarator> variables) {
|
||||
for (final ASTVariableDeclarator astVariableDeclarator : variables) {
|
||||
if (astVariableDeclarator.getFirstChildOfType(ASTVariableDeclaratorId.class)
|
||||
.getImage().equals(variableName)) {
|
||||
if (astVariableDeclarator.getFirstChildOfType(ASTVariableDeclaratorId.class).getImage()
|
||||
.equals(variableName)) {
|
||||
return countPlaceholders(astVariableDeclarator);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user