]> source.dussan.org Git - sonarqube.git/commitdiff
Slight refactoring of squid
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 12 Apr 2011 15:42:06 +0000 (17:42 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 12 Apr 2011 15:42:06 +0000 (17:42 +0200)
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/recognizer/JavaFootprint.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java

index fe512777008ceb4d0d7ad684bb108a69a8803083..389401bfb3df81e33c1f63c739f9567463efc6dd 100644 (file)
@@ -42,8 +42,7 @@ public class PackageVisitor extends JavaAstVisitor {
 
   @Override
   public void visitFile(DetailAST ast) {
-    SourceCode packageRes = null;
-
+    SourceCode packageRes;
     if (ast == null) {
       // ast can be null for empty files (all the file is commented-out)
       packageRes = guessPackage();
index 5990b6d91482c1e2281339831b278bd763a01f70..2c180c0aa574c626343cf7be95503b1946e151dd 100644 (file)
  */
 package org.sonar.java.recognizer;
 
-import java.util.HashSet;
-import java.util.Set;
+import com.google.common.collect.Sets;
+import org.sonar.squid.recognizer.*;
 
-import org.sonar.squid.recognizer.CamelCaseDetector;
-import org.sonar.squid.recognizer.ContainsDetector;
-import org.sonar.squid.recognizer.Detector;
-import org.sonar.squid.recognizer.EndWithDetector;
-import org.sonar.squid.recognizer.KeywordsDetector;
-import org.sonar.squid.recognizer.LanguageFootprint;
+import java.util.Set;
 
-public class JavaFootprint implements LanguageFootprint {
+public final class JavaFootprint implements LanguageFootprint {
 
-  private final Set<Detector> detectors = new HashSet<Detector>();
+  private final Set<Detector> detectors = Sets.newHashSet();
 
   public JavaFootprint() {
     detectors.add(new EndWithDetector(0.95, '}', ';', '{')); // NOSONAR Magic number is suitable in that case
     detectors.add(new KeywordsDetector(0.7, "||", "&&")); // NOSONAR
-    detectors.add(new KeywordsDetector(0.3, "public", "abstract", "class", "implements", "extends", "return","throw",// NOSONAR
+    detectors.add(new KeywordsDetector(0.3, "public", "abstract", "class", "implements", "extends", "return", "throw",// NOSONAR
         "private", "protected", "enum", "continue", "assert", "package", "synchronized", "boolean", "this", "double", "instanceof",
         "final", "interface", "static", "void", "long", "int", "float", "super", "true", "case:"));
     detectors.add(new ContainsDetector(0.95, "++", "for(", "if(", "while(", "catch(", "switch(", "try{", "else{"));// NOSONAR
index f67fa24820b6cffe0918c5fd337786f913b7b2d7..7a430efbc9af0f152404a8c882861aca9f5b7581 100644 (file)
  */
 package org.sonar.java.ast.visitor;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.sonar.api.resources.InputFile;
 import org.sonar.java.ast.JavaAstScanner;
@@ -36,6 +31,9 @@ import org.sonar.squid.api.SourceFile;
 import org.sonar.squid.api.SourceProject;
 import org.sonar.squid.measures.Metric;
 
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.*;
+
 public class CommentVisitorTest {
 
   private Squid squid;
@@ -77,15 +75,10 @@ public class CommentVisitorTest {
   }
 
   @Test
-  @Ignore("TODO")
-  public void testCommentedOutFile() {
-    SourceProject res = scan("/metrics/commentedCode", "org/foo/CommentedOutFile.java");
-  }
-
-  @Test
-  @Ignore("TODO")
-  public void shouldGuessPackageOfcommentedOutFile() {
-    SourceProject res = scan("/metrics/commentedCode", "org/foo/CommentedOutFile.java");
+  public void shouldGetCommentedOutLinesOfEmptyFiles() {
+    scan("/metrics/commentedCode", "org/foo/CommentedOutFile.java");
+    SourceCode file = squid.search("org/foo/CommentedOutFile.java");
+    assertThat(file.getInt(Metric.COMMENTED_OUT_CODE_LINES), greaterThan(1));
   }
 
   @Test