import java.util.List;
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.SourceCode;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
-@Rule(key = "AvoidUsageOfContinue", name = "AvoidUsageOfContinue", isoCategory = IsoCategory.Maintainability)
+@Rule(key = "AvoidContinueStatement", name = "Avoid using 'continue' branching statement", isoCategory = IsoCategory.Maintainability,
+ 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 "
+ + "the 'extract method' refactoring pattern :</p>"
+ + "<pre>"
+ + "mylabel : for(int i = 0 ; i< 3; i++) {\n"
+ + " for (int j = 0; j < 4 ; j++) {\n"
+ + " doSomething();\n"
+ + " if (checkSomething()) {\n"
+ + " continue mylabel;\n"
+ + " }\n"
+ + " }\n"
+ + "}\n"
+ + "</pre>")
public class ContinueCheck extends JavaAstCheck {
@Override
@Override
public void visitToken(DetailAST ast) {
SourceCode currentResource = peekSourceCode();
- CheckMessage message = new CheckMessage(this, "Avoid usage of continue");
+ CheckMessage message = new CheckMessage(this,
+ "The 'continue' branching statement prevent refactoring the source code to reduce the complexity.");
message.setLine(ast.getLineNo());
SourceFile sourceFile = currentResource.getParent(SourceFile.class);
sourceFile.log(message);