aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-squid-java-plugin/src
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-11-28 22:14:19 +0000
committerGodin <mandrikov@gmail.com>2010-11-28 22:14:19 +0000
commita28163d9dee455299869ee2729e1aacb871d0f8c (patch)
tree63e952c9614ea34f2e94ee5dffff8bd30e33d712 /plugins/sonar-squid-java-plugin/src
parent28654fbd5d119abae90049bb81c421dec4d9eacb (diff)
downloadsonarqube-a28163d9dee455299869ee2729e1aacb871d0f8c.tar.gz
sonarqube-a28163d9dee455299869ee2729e1aacb871d0f8c.zip
SONAR-2015: Fix inconsistency between Undocumented API measure and Undocumented API violations
Diffstat (limited to 'plugins/sonar-squid-java-plugin/src')
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/UndocumentedApiCheck.java7
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java8
2 files changed, 12 insertions, 3 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/UndocumentedApiCheck.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/UndocumentedApiCheck.java
index 221725b4786..b1dbeb316a2 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/UndocumentedApiCheck.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/UndocumentedApiCheck.java
@@ -34,6 +34,7 @@ import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceClass;
import org.sonar.squid.api.SourceCode;
import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.api.SourceMethod;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
@@ -44,7 +45,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
public class UndocumentedApiCheck extends JavaAstCheck {
@RuleProperty(description = "Optional. If this property is not defined, all classes should adhere to this constraint. Ex : **.api.**")
- private String forClasses = new String();
+ private String forClasses = "";
private WildcardPattern[] patterns;
@@ -58,6 +59,10 @@ public class UndocumentedApiCheck extends JavaAstCheck {
SourceCode currentResource = peekSourceCode();
SourceClass sourceClass = peekParentClass();
if (WildcardPattern.match(getPatterns(), sourceClass.getKey())) {
+ if (currentResource instanceof SourceMethod && ((SourceMethod) currentResource).isAccessor()) {
+ return;
+ }
+
if (PublicApiVisitor.isPublicApi(ast) && !PublicApiVisitor.isDocumentedApi(ast, getFileContents())) {
SourceFile sourceFile = currentResource.getParent(SourceFile.class);
CheckMessage message = new CheckMessage(this, "Avoid undocumented API.");
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java
index 019618df067..99163079ff3 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java
@@ -28,9 +28,11 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.java.ast.JavaAstScanner;
import org.sonar.java.squid.JavaSquidConfiguration;
+import org.sonar.java.squid.SquidScanner;
import org.sonar.squid.Squid;
import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.measures.Metric;
public class UndocumentedApiCheckTest {
@@ -41,14 +43,16 @@ public class UndocumentedApiCheckTest {
squid = new Squid(new JavaSquidConfiguration());
squid.registerVisitor(UndocumentedApiCheck.class);
squid.register(JavaAstScanner.class).scanFile(getFile("/rules/UndocumentedApi.java"));
+ squid.decorateSourceCodeTreeWith(Metric.values());
+ squid.register(SquidScanner.class).scan();
}
@Test
public void testUndocumentedApi() {
SourceFile file = (SourceFile) squid.search("UndocumentedApi.java");
+ assertThat(file.getInt(Metric.PUBLIC_API) - file.getInt(Metric.PUBLIC_DOC_API), is(1));
assertThat(file.getCheckMessages().size(), is(1));
CheckMessage message = file.getCheckMessages().iterator().next();
- assertThat(message.getLine(), is(6));
+ assertThat(message.getLine(), is(10));
}
-
}