diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-04-12 17:42:06 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-04-12 17:42:06 +0200 |
commit | 5d445ea4f67e0467b796267f0768eccd4e6141f5 (patch) | |
tree | cd737ef422512d84afb17ead32befdbe42d617bd /plugins | |
parent | 31349321b04541dbfd57c0162a3ce0ec4946641e (diff) | |
download | sonarqube-5d445ea4f67e0467b796267f0768eccd4e6141f5.tar.gz sonarqube-5d445ea4f67e0467b796267f0768eccd4e6141f5.zip |
Slight refactoring of squid
Diffstat (limited to 'plugins')
3 files changed, 14 insertions, 27 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java index fe512777008..389401bfb3d 100644 --- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java +++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java @@ -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(); diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/recognizer/JavaFootprint.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/recognizer/JavaFootprint.java index 5990b6d9148..2c180c0aa57 100644 --- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/recognizer/JavaFootprint.java +++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/recognizer/JavaFootprint.java @@ -19,24 +19,19 @@ */ 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 diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java index f67fa24820b..7a430efbc9a 100644 --- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java +++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java @@ -19,12 +19,7 @@ */ 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 |