mirror of
https://github.com/SonarSource/sonarqube.git
synced 2024-08-03 08:18:00 +02:00
Slight refactoring of squid
This commit is contained in:
parent
31349321b0
commit
5d445ea4f6
@ -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();
|
||||
|
@ -19,24 +19,19 @@
|
||||
*/
|
||||
package org.sonar.java.recognizer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.sonar.squid.recognizer.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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;
|
||||
public final class JavaFootprint implements LanguageFootprint {
|
||||
|
||||
public 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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user