]> source.dussan.org Git - sonarqube.git/commitdiff
Fix violations
authorEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 3 Nov 2011 08:32:03 +0000 (12:32 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 3 Nov 2011 09:10:43 +0000 (13:10 +0400)
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/ComplexityVisitor.java
sonar-colorizer/src/main/java/org/sonar/colorizer/JavaAnnotationTokenizer.java
sonar-colorizer/src/main/java/org/sonar/colorizer/KeywordsTokenizer.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java

index 07b9e0b9c181401676394b191ff9c9703b3f9acd..60aef739ef9044ecd87470783b82492711298c2a 100644 (file)
@@ -32,7 +32,7 @@ public class ComplexityVisitor extends JavaAstVisitor {
 
   @Override
   public List<Integer> getWantedTokens() {
-    return wantedTokens;
+    return WANTED_TOKENS;
   }
 
   @Override
@@ -41,6 +41,6 @@ public class ComplexityVisitor extends JavaAstVisitor {
     res.setMeasure(Metric.COMPLEXITY, res.getInt(Metric.COMPLEXITY) + res.getInt(Metric.BRANCHES) + 1);
   }
 
-  private static final List<Integer> wantedTokens = Arrays.asList(TokenTypes.CTOR_DEF, TokenTypes.METHOD_DEF, TokenTypes.INSTANCE_INIT,
+  private static final List<Integer> WANTED_TOKENS = Arrays.asList(TokenTypes.CTOR_DEF, TokenTypes.METHOD_DEF, TokenTypes.INSTANCE_INIT,
       TokenTypes.STATIC_INIT);
 }
index 554e0613fac8ae0e230a35b8e110868810bbbc23..1a5489e75f5c0952e14d9c861310f1924996894a 100644 (file)
@@ -32,8 +32,7 @@ public class JavaAnnotationTokenizer extends Tokenizer {
     this.tagAfter = tagAfter;
   }
 
-  private static final EndMatcher endTokenMatcher = new EndMatcher() {
-
+  private static final EndMatcher END_TOKEN_MATCHER = new EndMatcher() {
     public boolean match(int endFlag) {
       return !Character.isJavaIdentifierPart(endFlag);
     }
@@ -43,7 +42,7 @@ public class JavaAnnotationTokenizer extends Tokenizer {
   public boolean consume(CodeReader code, HtmlCodeBuilder codeBuilder) {
     if (code.peek() == '@') {
       codeBuilder.appendWithoutTransforming(tagBefore);
-      code.popTo(endTokenMatcher, codeBuilder);
+      code.popTo(END_TOKEN_MATCHER, codeBuilder);
       codeBuilder.appendWithoutTransforming(tagAfter);
       return true;
     } else {
index 3152b41161f809c98ac035825b73f247b5ffb00e..9bf9225461cffc7e0fe7d2c18ce214fbd7e4b63e 100644 (file)
@@ -37,12 +37,12 @@ public class KeywordsTokenizer extends NotThreadSafeTokenizer {
   private boolean caseInsensitive = false;
   private Matcher matcher;
   private final StringBuilder tmpBuilder = new StringBuilder();
-  private final static String defaultRegex = "[a-zA-Z_][a-zA-Z0-9_]*+";
+  private final static String DEFAULT_REGEX = "[a-zA-Z_][a-zA-Z0-9_]*+";
 
   private Set<String> keywords = new HashSet<String>();
 
   public KeywordsTokenizer(String tagBefore, String tagAfter, Set<String> keywords) {
-    this(tagBefore, tagAfter, keywords, defaultRegex);
+    this(tagBefore, tagAfter, keywords, DEFAULT_REGEX);
   }
 
   public KeywordsTokenizer(String tagBefore, String tagAfter, Set<String> keywords, String regex) {
@@ -56,7 +56,7 @@ public class KeywordsTokenizer extends NotThreadSafeTokenizer {
     this.tagBefore = tagBefore;
     this.tagAfter = tagAfter;
     Collections.addAll(this.keywords, keywords);
-    this.matcher = Pattern.compile(defaultRegex).matcher("");
+    this.matcher = Pattern.compile(DEFAULT_REGEX).matcher("");
   }
 
   public boolean consume(CodeReader code, HtmlCodeBuilder codeBuilder) {
index e6bb142a5c2279c0897d666596a4a9819fecf174..268111244d49c4086555211f425243d7b29110a8 100644 (file)
@@ -53,7 +53,7 @@ import org.apache.commons.lang.StringUtils;
  * </p>
  * <p>
  * Another implementation, which is also based on Java Regular Expressions, can be found in
- * <a href="https://github.com/JetBrains/intellij-community/blob/59fa7d3aa565b01ecf0fb067a4336af2c174bf5b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java#L865">FileUtil</a>
+ * <a href="https://github.com/JetBrains/intellij-community/blob/idea/107.743/platform/util/src/com/intellij/openapi/util/io/FileUtil.java#L847">FileUtil</a>
  * from IntelliJ OpenAPI.
  * </p>
  * 
index 1980f870c3db6f0b2d4b831fb801fd11d184dde3..26c719cddd9e809624337c0d6232e998a982c9d8 100644 (file)
@@ -86,17 +86,9 @@ public final class CommandExecutor {
       throw new CommandException(command, e);
 
     } finally {
-      if (outputGobbler != null) {
-        waitUntilFinish(outputGobbler);
-      }
-
-      if (errorGobbler != null) {
-        waitUntilFinish(errorGobbler);
-      }
-
-      if (process != null) {
-        closeStreams(process);
-      }
+      waitUntilFinish(outputGobbler);
+      waitUntilFinish(errorGobbler);
+      closeStreams(process);
 
       if (executorService != null) {
         executorService.shutdown();
@@ -105,16 +97,20 @@ public final class CommandExecutor {
   }
 
   private void closeStreams(Process process) {
-    IOUtils.closeQuietly(process.getInputStream());
-    IOUtils.closeQuietly(process.getOutputStream());
-    IOUtils.closeQuietly(process.getErrorStream());
+    if (process != null) {
+      IOUtils.closeQuietly(process.getInputStream());
+      IOUtils.closeQuietly(process.getOutputStream());
+      IOUtils.closeQuietly(process.getErrorStream());
+    }
   }
 
   private void waitUntilFinish(StreamGobbler thread) {
-    try {
-      thread.join();
-    } catch (InterruptedException e) {
-      // ignore
+    if (thread != null) {
+      try {
+        thread.join();
+      } catch (InterruptedException e) {
+        // ignore
+      }
     }
   }