Fixed some major sonar issues 42/27042/6
authorIgor Foltin <igor.foltin@pantheon.sk>
Wed, 16 Sep 2015 10:58:27 +0000 (12:58 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 23 Sep 2015 07:36:06 +0000 (07:36 +0000)
in checkstyle-logging and
yang-data-util.

Change-Id: Ie2e9753964c5e39d0288861e6f4301cd03d59de0
Signed-off-by: Igor Foltin <igor.foltin@pantheon.sk>
common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/CheckLoggingUtil.java
common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/LogMessagePlaceholderCountCheck.java
common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/LoggerMustBeSlf4jCheck.java
common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/LoggerVariableModifiersCheck.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AugmentationContextNode.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/DataSchemaContextTree.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/XpathStringParsingPathArgumentBuilder.java

index d19555b52abb3d49cc997c57f437e73a6ce7b456..2ff30eb19660d1c60a7bfdd9b4cc2ff7e961790d 100644 (file)
@@ -18,14 +18,16 @@ import com.puppycrawl.tools.checkstyle.api.FullIdent;
 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
 import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
 
-public class CheckLoggingUtil {
+public final class CheckLoggingUtil {
 
     public static final String LOGGER_TYPE_NAME = Logger.class.getSimpleName();
     public static final String LOGGER_TYPE_FULL_NAME = Logger.class.getName();
     public static final String LOGGER_VAR_NAME = "LOG";
     private static final List<String> LOG_METHODS = Lists.newArrayList("LOG.debug", "LOG.info", "LOG.error", "LOG.warn", "LOG.trace");
 
-    private CheckLoggingUtil() {}
+    private CheckLoggingUtil() {
+        throw new UnsupportedOperationException("Utility class should not be instantiated!");
+    }
 
     public static String getTypeName(final DetailAST aAST) {
         final FullIdent ident = CheckUtils.createFullType(aAST.findFirstToken(TokenTypes.TYPE));
index bb28bccf07c8b7c59073829bc74b02bd5e965450..4735b1b1e4980b0a9a88b422fbc4b880fe8bc87f 100644 (file)
@@ -26,15 +26,16 @@ public class LogMessagePlaceholderCountCheck extends Check {
     @Override
     public void visitToken(DetailAST aAST) {
         final String methodName = CheckLoggingUtil.getMethodName(aAST);
-        if(CheckLoggingUtil.isLogMethod(methodName)) {
+        if (CheckLoggingUtil.isLogMethod(methodName)) {
             final String logMessage = aAST.findFirstToken(TokenTypes.ELIST).getFirstChild().getFirstChild().getText();
             int placeholdersCount = placeholdersCount(logMessage);
             int argumentsCount = aAST.findFirstToken(TokenTypes.ELIST).getChildCount(TokenTypes.EXPR) - 1;
             final String lastArg = aAST.findFirstToken(TokenTypes.ELIST).getLastChild().getFirstChild().getText();
-            if(hasCatchBlockParentWithArgument(lastArg, aAST) || hasMethodDefinitionWithExceptionArgument(lastArg, aAST)) {
+            if (hasCatchBlockParentWithArgument(lastArg, aAST) || hasMethodDefinitionWithExceptionArgument(lastArg,
+                    aAST)) {
                 argumentsCount--;
             }
-            if(placeholdersCount > argumentsCount) {
+            if (placeholdersCount > argumentsCount) {
                 log(aAST.getLineNo(), LOG_MESSAGE);
             }
         }
@@ -49,11 +50,10 @@ public class LogMessagePlaceholderCountCheck extends Check {
         while(parent != null && parent.getType() != TokenTypes.LITERAL_CATCH) {
             parent = parent.getParent();
         }
-        if(parent != null) {
-            if(parent.findFirstToken(TokenTypes.PARAMETER_DEF) != null &&
-                    parent.findFirstToken(TokenTypes.PARAMETER_DEF).findFirstToken(TokenTypes.IDENT).getText().equals(argumentName)) {
-                return true;
-            }
+        if (parent != null && parent.findFirstToken(TokenTypes.PARAMETER_DEF) != null &&
+                parent.findFirstToken(TokenTypes.PARAMETER_DEF).findFirstToken(TokenTypes.IDENT).getText().equals
+                        (argumentName)) {
+            return true;
         }
         return false;
     }
@@ -63,29 +63,28 @@ public class LogMessagePlaceholderCountCheck extends Check {
         while(parent != null && parent.getType() != TokenTypes.METHOD_DEF) {
             parent = parent.getParent();
         }
-        if(parent != null) {
-            if(parent.findFirstToken(TokenTypes.PARAMETERS).findFirstToken(TokenTypes.PARAMETER_DEF) != null) {
-                DetailAST paramDef = parent.findFirstToken(TokenTypes.PARAMETERS).getFirstChild();
-                while(paramDef != null) {
-                    if(paramDef.getType() == TokenTypes.PARAMETER_DEF) {
-                        final String paramName = paramDef.findFirstToken(TokenTypes.IDENT).getText();
-                        if(paramName.equals(argumentName) && isExceptionType(paramDef)) {
-                            return true;
-                        }
+        if (parent != null && parent.findFirstToken(TokenTypes.PARAMETERS).findFirstToken(TokenTypes.PARAMETER_DEF)
+                != null) {
+            DetailAST paramDef = parent.findFirstToken(TokenTypes.PARAMETERS).getFirstChild();
+            while(paramDef != null) {
+                if (paramDef.getType() == TokenTypes.PARAMETER_DEF) {
+                    final String paramName = paramDef.findFirstToken(TokenTypes.IDENT).getText();
+                    if (paramName.equals(argumentName) && isExceptionType(paramDef)) {
+                        return true;
                     }
-                    paramDef = paramDef.getNextSibling();
                 }
+                paramDef = paramDef.getNextSibling();
             }
         }
         return false;
     }
 
     private boolean isExceptionType(final DetailAST parameterDef) {
-        if(parameterDef != null) {
+        if (parameterDef != null) {
             final DetailAST type = parameterDef.findFirstToken(TokenTypes.TYPE);
-            if(type != null && type.findFirstToken(TokenTypes.IDENT) != null) {
+            if (type != null && type.findFirstToken(TokenTypes.IDENT) != null) {
                 final String argumentType = type.findFirstToken(TokenTypes.IDENT).getText();
-                if(argumentType.contains(EXCEPTION_TYPE)) {
+                if (argumentType.contains(EXCEPTION_TYPE)) {
                     return true;
                 }
             }
index 1f814d659e4a29724fb346d47c8b0eda33661929..2ddcdddfe4357d5758d34b462922f346fbc48c6d 100644 (file)
@@ -27,18 +27,18 @@ public class LoggerMustBeSlf4jCheck extends Check {
 
     @Override
     public void visitToken(DetailAST aAST) {
-        if(aAST.getType() == TokenTypes.VARIABLE_DEF) {
+        if (aAST.getType() == TokenTypes.VARIABLE_DEF) {
             if (CheckLoggingUtil.isAFieldVariable(aAST)) {
                 final String typeName = CheckLoggingUtil.getTypeName(aAST);
                 if (typeName.contains("." + LOGGER_TYPE_NAME) && !typeName.equals(LOGGER_TYPE_FULL_NAME)) {
                     log(aAST.getLineNo(), LOG_MESSAGE);
                 }
             }
-        } else if(aAST.getType() == TokenTypes.IMPORT) {
+        } else if (aAST.getType() == TokenTypes.IMPORT) {
             final String importType = aAST.getFirstChild().findFirstToken(TokenTypes.IDENT).getText();
-            if(importType.equals(CheckLoggingUtil.LOGGER_TYPE_NAME)) {
+            if (importType.equals(CheckLoggingUtil.LOGGER_TYPE_NAME)) {
                 final String importIdent = aAST.getFirstChild().getFirstChild().getLastChild().getText();
-                if(!importIdent.equals(SLF4J)) {
+                if (!importIdent.equals(SLF4J)) {
                     log(aAST.getLineNo(), LOG_MESSAGE);
                 }
             }
index 63249cba40f2aaf92931982b56de8d64903c0573..126041b47fe8ff4da5b34c95a40f4d42da68591b 100644 (file)
@@ -23,18 +23,17 @@ public class LoggerVariableModifiersCheck extends Check {
 
     @Override
     public void visitToken(DetailAST aAST) {
-        if (CheckLoggingUtil.isAFieldVariable(aAST) && CheckLoggingUtil.isLoggerType(aAST) && !hasPrivatStaticFinalModifier(aAST)) {
+        if (CheckLoggingUtil.isAFieldVariable(aAST) && CheckLoggingUtil.isLoggerType(aAST)
+                && !hasPrivatStaticFinalModifier(aAST)) {
             log(aAST.getLineNo(), LOG_MESSAGE);
         }
     }
 
     private boolean hasPrivatStaticFinalModifier(DetailAST aAST) {
         DetailAST modifiers = aAST.findFirstToken(TokenTypes.MODIFIERS);
-        if(modifiers != null) {
-            if(modifiers.branchContains(TokenTypes.LITERAL_PRIVATE) && modifiers.branchContains(TokenTypes.LITERAL_STATIC)
-                    && modifiers.branchContains(TokenTypes.FINAL)) {
-                return true;
-            }
+        if (modifiers != null && modifiers.branchContains(TokenTypes.LITERAL_PRIVATE) && modifiers.branchContains
+                    (TokenTypes.LITERAL_STATIC) && modifiers.branchContains(TokenTypes.FINAL)) {
+            return true;
         }
         return false;
     }
index a2393ca0e7a2e9b97c1fa62c222013dd4d2db4c2..8b682fde77e7a1209b311d8fc0cb2deb1a2633f6 100644 (file)
@@ -19,7 +19,6 @@ final class AugmentationContextNode extends
         DataContainerContextNode<AugmentationIdentifier> {
 
     public AugmentationContextNode(final AugmentationSchema augmentation, final DataNodeContainer schema) {
-        // super();
         super(augmentationIdentifierFrom(augmentation), augmentationProxy(augmentation, schema), null);
     }
 
index 27224b49a00867044a7682a8ce8257420b85fd2f..d11efb4f84ce708081b67b05585d537e6e1152e0 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class DataSchemaContextTree {
+public final class DataSchemaContextTree {
 
     private static final LoadingCache<SchemaContext, DataSchemaContextTree> TREES = CacheBuilder.newBuilder()
             .weakKeys()
index 2d1de449122cc4209ea5fc58990d59cb5d8301cf..133df37c1cc023f7791123a399c428091e9c8eaf 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import java.util.LinkedList;
+import java.util.List;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.concepts.Builder;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -70,7 +71,7 @@ class XpathStringParsingPathArgumentBuilder implements Builder<Iterable<PathArgu
     private final AbstractStringInstanceIdentifierCodec codec;
     private final String data;
 
-    private final LinkedList<PathArgument> product = new LinkedList<>();
+    private final List<PathArgument> product = new LinkedList<>();
 
     private DataSchemaContextNode<?> current;
     private int offset;