]> source.dussan.org Git - sonarqube.git/commitdiff
Replace unmodifiableSets with ImmutableSets
authorDavid Gageot <david@gageot.net>
Tue, 17 Jul 2012 19:40:44 +0000 (21:40 +0200)
committerDavid Gageot <david@gageot.net>
Tue, 17 Jul 2012 19:40:44 +0000 (21:40 +0200)
sonar-colorizer/pom.xml
sonar-colorizer/src/main/java/org/sonar/colorizer/GroovyKeywords.java
sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java
sonar-colorizer/src/main/java/org/sonar/colorizer/JavaKeywords.java

index 13aebf419fc6238e3fa1a0b59ccf5eceb0282abc..29fd845dd4633dd4456e3ccd7fb01d6c5a9b2af7 100644 (file)
@@ -16,8 +16,8 @@
 
   <dependencies>
     <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
     </dependency>
     <dependency>
       <groupId>org.codehaus.sonar</groupId>
index e12f8558dfde1cee9324be370c656c914d5adb23..f2c7c41e2fb5e3e28f94445bec8a3eb2801f5cf5 100644 (file)
  */
 package org.sonar.colorizer;
 
-import java.util.Collections;
-import java.util.HashSet;
+import com.google.common.collect.ImmutableSet;
+
 import java.util.Set;
 
 public final class GroovyKeywords {
-
-  private static final Set<String> KEYWORDS = new HashSet<String>();
-
-  private static final String[] GROOVY_KEYWORDS = {
-    "as", "assert", "break", "case", "catch", "class", "continue", "def",
-    "default", "do", "else", "extends", "finally", "for", "if", "in", "implements", "import", "instanceof", "interface", "new", "package",
-    "property", "return", "switch", "throw", "throws", "try", "while"};
-
-  static {
-    Collections.addAll(KEYWORDS, GROOVY_KEYWORDS);
-  }
+  private static final Set<String> KEYWORDS = ImmutableSet.of(
+      "as", "assert", "break", "case", "catch", "class", "continue", "def",
+      "default", "do", "else", "extends", "finally", "for", "if", "in", "implements", "import", "instanceof", "interface", "new", "package",
+      "property", "return", "switch", "throw", "throws", "try", "while");
 
   private GroovyKeywords() {
   }
 
   public static Set<String> get() {
-    return Collections.unmodifiableSet(KEYWORDS);
+    return KEYWORDS;
   }
 }
index 8c830560047e5c2e72c13762ab6354f804bfa2ab..2dd6482a03440a8d2f155013501897f9e93d3de9 100644 (file)
@@ -19,7 +19,8 @@
  */
 package org.sonar.colorizer;
 
-import org.apache.commons.io.IOUtils;
+import com.google.common.io.ByteStreams;
+import com.google.common.io.Closeables;
 import org.sonar.channel.CodeReader;
 
 import java.io.IOException;
@@ -44,7 +45,7 @@ public class HtmlDecorator extends Tokenizer {
     StringBuilder sb = new StringBuilder();
     if (options.isGenerateHtmlHeader()) {
       sb.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
-          + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><style type=\"text/css\">");
+        + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><style type=\"text/css\">");
       sb.append(getCss());
       sb.append("</style></head><body>");
     }
@@ -91,13 +92,13 @@ public class HtmlDecorator extends Tokenizer {
     InputStream input = null;
     try {
       input = HtmlRenderer.class.getResourceAsStream(CSS_PATH);
-      return IOUtils.toString(input);
+      return new String(ByteStreams.toByteArray(input));
 
     } catch (IOException e) {
       throw new SynhtaxHighlightingException("Sonar Colorizer CSS file not found: " + CSS_PATH, e);
 
     } finally {
-      IOUtils.closeQuietly(input);
+      Closeables.closeQuietly(input);
     }
   }
 }
index 3057db57679273a4ccb2e12e0767fd8c0b9a038d..418cd1b0028a6297ccbbc58208492d85d118deb9 100644 (file)
  */
 package org.sonar.colorizer;
 
-import java.util.Collections;
-import java.util.HashSet;
+import com.google.common.collect.ImmutableSet;
+
 import java.util.Set;
 
 public final class JavaKeywords {
 
-  private static final Set<String> KEYWORDS = new HashSet<String>();
-
-  private static final String[] JAVA_KEYWORDS = {
-    "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char",
-    "class", "const", "continue", "default",
-    "do", "double", "else", "enum", "extends", "false", "final", "finally", "float", "for",
-    "goto", "if", "implements", "import", "instanceof",
-    "int", "interface", "long", "native", "new", "null", "package", "private",
-    "protected", "public", "return", "short", "static", "strictfp",
-    "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"};
-
-  static {
-    Collections.addAll(KEYWORDS, JAVA_KEYWORDS);
-  }
+  private static final Set<String> KEYWORDS = ImmutableSet.of(
+      "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char",
+      "class", "const", "continue", "default",
+      "do", "double", "else", "enum", "extends", "false", "final", "finally", "float", "for",
+      "goto", "if", "implements", "import", "instanceof",
+      "int", "interface", "long", "native", "new", "null", "package", "private",
+      "protected", "public", "return", "short", "static", "strictfp",
+      "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while");
 
   private JavaKeywords() {
   }
 
   public static Set<String> get() {
-    return Collections.unmodifiableSet(KEYWORDS);
+    return KEYWORDS;
   }
 }