package org.sonar.java.ast.check;
-import java.util.Arrays;
-import java.util.List;
-
-import org.sonar.check.IsoCategory;
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.java.ast.visitor.AstUtils;
import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceFile;
-import com.puppycrawl.tools.checkstyle.api.DetailAST;
-import com.puppycrawl.tools.checkstyle.api.TokenTypes;
+import java.util.Arrays;
+import java.util.List;
@Rule(
key = "AvoidBreakOutsideSwitch",
name = "Avoid using 'break' branching statement outside a 'switch' statement",
- isoCategory = IsoCategory.Maintainability,
priority = Priority.MAJOR,
description = "<p>The use of the 'break' branching statement increases the essential complexity of the source code and "
+ "so prevents any refactoring of this source code to replace all well structured control structures with a single statement.</p>"
- + "<p>For instance, with the following java program fragment, it's not possible to apply the 'extract method' refactoring pattern :</p>"
+ + "<p>For instance, with the following java program fragment, it's not possible to apply "
+ + "the 'extract method' refactoring pattern :</p>"
+ "<pre>"
+ "mylabel : for (int i = 0 ; i< 3; i++) {\n"
+ " for (int j = 0; j < 4 ; j++) {\n"
package org.sonar.java.ast.check;
-import java.util.Arrays;
-import java.util.List;
-
-import org.sonar.check.IsoCategory;
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceCode;
import org.sonar.squid.api.SourceFile;
-import com.puppycrawl.tools.checkstyle.api.DetailAST;
-import com.puppycrawl.tools.checkstyle.api.TokenTypes;
+import java.util.Arrays;
+import java.util.List;
-@Rule(key = "AvoidContinueStatement", name = "Avoid using 'continue' branching statement", isoCategory = IsoCategory.Maintainability,
+@Rule(key = "AvoidContinueStatement", name = "Avoid using 'continue' branching statement",
priority = Priority.MAJOR, description = "<p>The use of the 'continue' branching statement increase the essential complexity "
+ "of the source code and so prevent any refactoring of this source code to replace all well structured control structures "
+ "with a single statement.</p><p>For instance, in the following java program fragment, it's not possible to apply "
package org.sonar.java.ast.check;
-import java.util.List;
-
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.WildcardPattern;
-import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.java.PatternUtils;
import org.sonar.java.ast.visitor.PublicApiVisitor;
-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 org.sonar.squid.api.*;
-import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import java.util.List;
-@Rule(key = "UndocumentedApi", name = "Undocumented API", isoCategory = IsoCategory.Usability, priority = Priority.MAJOR,
+@Rule(key = "UndocumentedApi", name = "Undocumented API", priority = Priority.MAJOR,
description = "<p>Check that each public class, interface, method and constructor has a Javadoc comment. "
+ "The following public methods/constructors are not concerned by this rule :</p>" + "<ul><li>Getter / Setter</li>"
+ "<li>Method with @Override annotation</li>" + "<li>Empty constructor</li></ul>")
import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.WildcardPattern;
import org.sonar.check.Cardinality;
-import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import java.util.Map;
@Rule(key = "ArchitecturalConstraint", name = "Architectural constraint", cardinality = Cardinality.MULTIPLE,
- isoCategory = IsoCategory.Portability, priority = Priority.MAJOR,
+ priority = Priority.MAJOR,
description = "<p>A source code comply to an architectural model when it fully adheres to a set of architectural constraints. " +
"A constraint allows to deny references between classes by pattern.</p>" +
"<p>You can for instance use this rule to :</p>" +
public void visitEdge(AsmEdge edge) {
if (asmClass != null && edge != null) {
String internalNameTargetClass = edge.getTargetAsmClass().getInternalName();
- if ( !internalNames.containsKey(internalNameTargetClass)) {
+ if (!internalNames.containsKey(internalNameTargetClass)) {
if (WildcardPattern.match(getToPatterns(), internalNameTargetClass)) {
int sourceLineNumber = getSourceLineNumber(edge);
logMessage(asmClass.getInternalName(), internalNameTargetClass, sourceLineNumber);
*/
package org.sonar.java.bytecode.check;
-import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.java.bytecode.asm.AsmClass;
import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceFile;
-@Rule(key = "CallToDeprecatedMethod", name = "Avoid use of deprecated method", isoCategory = IsoCategory.Portability,
- priority = Priority.MINOR, description = "<p>Once deprecated, a method should no longer be used as it means that "
+@Rule(key = "CallToDeprecatedMethod", name = "Avoid use of deprecated method", priority = Priority.MINOR,
+ description = "<p>Once deprecated, a method should no longer be used as it means that "
+ "the method might be removed sooner or later.</p>")
public class CallToDeprecatedMethodCheck extends BytecodeCheck {
*/
package org.sonar.java.bytecode.check;
-import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.java.bytecode.asm.AsmClass;
import org.sonar.squid.api.SourceFile;
import org.sonar.squid.api.SourceMethod;
-@Rule(key = "UnusedPrivateMethod", name = "Unused private method", isoCategory = IsoCategory.Maintainability,
+@Rule(key = "UnusedPrivateMethod", name = "Unused private method",
priority = Priority.MAJOR, description = "<p>Private methods that are never executed are dead code. " +
"Dead code means unnecessary, inoperative code that should be removed. " +
"This helps in maintenance by decreasing the maintained code size, " +
@Override
public void visitMethod(AsmMethod asmMethod) {
- if ( !asmMethod.isUsed() && asmMethod.isPrivate() && !asmMethod.isDefaultConstructor() && !SerializableContract.methodMatch(asmMethod)) {
+ if (!asmMethod.isUsed() && asmMethod.isPrivate() && !asmMethod.isDefaultConstructor() && !SerializableContract.methodMatch(asmMethod)) {
CheckMessage message = new CheckMessage(this, "Private method '" + asmMethod.getName() + "(...)' is never used.");
SourceMethod sourceMethod = getSourceMethod(asmMethod);
if (sourceMethod != null) {
*/
package org.sonar.java.bytecode.check;
-import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.java.bytecode.asm.AsmClass;
import org.sonar.squid.api.SourceFile;
import org.sonar.squid.api.SourceMethod;
-@Rule(key = "UnusedProtectedMethod", name = "Unused protected method", isoCategory = IsoCategory.Maintainability,
+@Rule(key = "UnusedProtectedMethod", name = "Unused protected method",
priority = Priority.MAJOR, description = "<p>Protected methods that are never used by any classes " +
"in the same project are strongly suspected to be dead code. "
+ "Dead code means unnecessary, inoperative code that should be removed. "
@Override
public void visitMethod(AsmMethod asmMethod) {
- if ( !asmMethod.isUsed() && asmMethod.isProtected() && !asmClass.isAbstract() && !SerializableContract.methodMatch(asmMethod)
+ if (!asmMethod.isUsed() && asmMethod.isProtected() && !asmClass.isAbstract() && !SerializableContract.methodMatch(asmMethod)
&& !asmMethod.isInherited()) {
CheckMessage message = new CheckMessage(this, "Protected method '" + asmMethod.getName() + "(...)' is never used.");
SourceMethod sourceMethod = getSourceMethod(asmMethod);
package org.sonar.java.squid.check;
-import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.squid.api.SourceFile;
import org.sonar.squid.measures.Metric;
-@Rule(key = "ClassCyclomaticComplexity", name = "Avoid too complex class", isoCategory = IsoCategory.Maintainability,
+@Rule(key = "ClassCyclomaticComplexity", name = "Avoid too complex class",
priority = Priority.MAJOR, description = "<p>The Cyclomatic Complexity is measured by the number of (&&, ||) operators "
+ "and (if, while, do, for, ?:, catch, switch, case, return, throw) statements in the body of a class plus one for "
+ "each constructor, method (but not getter/setter), static initializer, or instance initializer in the class. "
package org.sonar.java.squid.check;
-import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.squid.api.SourceFile;
import org.sonar.squid.measures.Metric;
-@Rule(key = "MaximumInheritanceDepth", name = "Avoid too deep inheritance tree", isoCategory = IsoCategory.Maintainability,
+@Rule(key = "MaximumInheritanceDepth", name = "Avoid too deep inheritance tree",
priority = Priority.MAJOR, description = "<p>Inheritance is certainly one of the most valuable concept of object-oriented "
+ "programming. It's a way to compartmentalize and reuse code by creating collections of attributes and behaviors called "
+ "classes which can be based on previously created classes. But abusing of this concept by creating a deep inheritance tree "
package org.sonar.java.squid.check;
-import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.squid.api.SourceMethod;
import org.sonar.squid.measures.Metric;
-@Rule(key = "MethodCyclomaticComplexity", name = "Avoid too complex method", isoCategory = IsoCategory.Maintainability,
+@Rule(key = "MethodCyclomaticComplexity", name = "Avoid too complex method",
priority = Priority.MAJOR, description = "<p>The Cyclomatic Complexity is measured by the number of (&&, ||) operators "
+ "and (if, while, do, for, ?:, catch, switch, case, return, throw) statements in the body of a constructor, "
+ "method, static initializer, or instance initializer. "
package org.sonar.java.squid.check;
-import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceFile;
-@Rule(key = "NoSonar", name = "Avoid use of //NOSONAR marker", isoCategory = IsoCategory.Reliability, priority = Priority.INFO,
+@Rule(key = "NoSonar", name = "Avoid use of //NOSONAR marker", priority = Priority.INFO,
description = "<p>Any violation to quality rule can be deactivated with the //NOSONAR marker. This marker is pretty useful to exclude "
+ "false-positive results but sometimes it can abusively be used to hide real quality flaws.</p>"
+ "<p>This rule allows to track and/or forbid use of this marker</p>")
/**
* Will probably be deprecated and replaced by tags
+ *
+ * @deprecated since 2.5. See http://jira.codehaus.org/browse/SONAR-2007
*/
IsoCategory isoCategory() default IsoCategory.NONE;