summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-28 22:11:39 +0000
committerGodin <mandrikov@gmail.com>2010-10-28 22:11:39 +0000
commit34afe79711c94ffb59f3413066f9c0cb1d5c6fa0 (patch)
tree3b9791f0f798184e6fa036a554580596f112e014
parent0c700ae7431a1460d4e615c249299d88ba135768 (diff)
downloadsonarqube-34afe79711c94ffb59f3413066f9c0cb1d5c6fa0.tar.gz
sonarqube-34afe79711c94ffb59f3413066f9c0cb1d5c6fa0.zip
SONAR-1901: Add new rule to report on "Undocumented API"
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/UndocumentedApiCheck.java32
1 files changed, 32 insertions, 0 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
new file mode 100644
index 00000000000..df08d0471a3
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/UndocumentedApiCheck.java
@@ -0,0 +1,32 @@
+package org.sonar.java.ast.check;
+
+import org.sonar.check.IsoCategory;
+import org.sonar.check.Priority;
+import org.sonar.check.Rule;
+import org.sonar.java.ast.visitor.PublicApiVisitor;
+import org.sonar.squid.api.CheckMessage;
+import org.sonar.squid.api.CodeCheck;
+import org.sonar.squid.api.SourceCode;
+import org.sonar.squid.api.SourceFile;
+
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+
+@Rule(key = "UndocumentedApi", name = "Undocumented API", isoCategory = IsoCategory.Usability, priority = Priority.MAJOR, description = "")
+public class UndocumentedApiCheck extends PublicApiVisitor implements CodeCheck {
+
+ @Override
+ public void visitToken(DetailAST ast) {
+ if (isPublicApi(ast) && !isDocumentedApi(ast)) {
+ SourceCode currentResource = peekSourceCode();
+ SourceFile sourceFile = currentResource.getParent(SourceFile.class);
+ CheckMessage message = new CheckMessage(this, "Avoid undocumented API");
+ message.setLine(ast.getLineNo());
+ sourceFile.log(message);
+ }
+ }
+
+ public String getKey() {
+ return getClass().getSimpleName();
+ }
+
+}