Fix code smells in checkstyle-logging 94/71794/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 4 May 2018 11:32:55 +0000 (13:32 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 4 May 2018 11:34:54 +0000 (13:34 +0200)
Simple code structure changes, which will also slightly improve
performance.

Change-Id: I44f78506af8d3b0fb544080e2f6a1b25c9b5e0a8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/AbstractLogMessageCheck.java
common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/LogMessagePlaceholderCountCheck.java

index 33e6feb5fcfd91d2f9ddd7ef6120fd60ad26b614..e480bf0ac655283d7197f7229e9455548fd3a4bf 100644 (file)
@@ -45,10 +45,8 @@ public abstract class AbstractLogMessageCheck extends AbstractCheck {
             ast = ast.getFirstChild();
             if (ast != null) {
                 ast = ast.getFirstChild();
-                if (ast != null) {
-                    if (ast.getType() == TokenTypes.STRING_LITERAL) {
-                        return Optional.ofNullable(ast.getText());
-                    }
+                if (ast != null && ast.getType() == TokenTypes.STRING_LITERAL) {
+                    return Optional.ofNullable(ast.getText());
                 }
             }
         }
index 17c14e0c4275351fd7275ee0ec3fae296efb52f7..3e34824ae089e7c54b89194f85a6e6492ae384b2 100644 (file)
@@ -39,10 +39,9 @@ public class LogMessagePlaceholderCountCheck extends AbstractLogMessageCheck {
         while (parent != null && parent.getType() != TokenTypes.LITERAL_CATCH) {
             parent = parent.getParent();
         }
-        if (parent != null && parent.findFirstToken(TokenTypes.PARAMETER_DEF) != null
-                && parent.findFirstToken(TokenTypes.PARAMETER_DEF).findFirstToken(TokenTypes.IDENT).getText()
-                        .equals(argumentName)) {
-            return true;
+        if (parent != null) {
+            final DetailAST def = parent.findFirstToken(TokenTypes.PARAMETER_DEF);
+            return def != null && def.findFirstToken(TokenTypes.IDENT).getText().equals(argumentName);
         }
         return false;
     }