mirror of https://github.com/alibaba/p3c.git
add rules
[Recommended] The total number of lines for a method should not be more than 80 [Recommended] Avoid using the negation operator '!' [Mandatory] When doing date formatting, "y" should be written in lowercase for "year" in a pattern statement and some bug fixpull/328/head
parent
1cc0a0c2a0
commit
b948c7e62b
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2017 Alibaba Group.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.alibaba.p3c.pmd.lang.java.rule.other;
|
||||||
|
|
||||||
|
import com.alibaba.p3c.pmd.I18nResources;
|
||||||
|
import com.alibaba.p3c.pmd.lang.java.rule.AbstractAliRule;
|
||||||
|
import com.alibaba.p3c.pmd.lang.java.util.ViolationUtils;
|
||||||
|
|
||||||
|
import net.sourceforge.pmd.lang.ast.Node;
|
||||||
|
import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
|
||||||
|
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
|
||||||
|
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||||
|
import net.sourceforge.pmd.lang.java.ast.Token;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [Recommended] The total number of lines for a method should not be more than 80.
|
||||||
|
* Note: The total number of lines, including the method signature, closing brace, codes, comments,
|
||||||
|
* blank lines, line breaks and any invisible lines, should not be more than 80.
|
||||||
|
*
|
||||||
|
* @author keriezhang
|
||||||
|
* @date 2018/1/9
|
||||||
|
*/
|
||||||
|
public class MethodTooLongRule extends AbstractAliRule {
|
||||||
|
|
||||||
|
private static final int MAX_LINE_COUNT = 80;
|
||||||
|
private static final String ANNOTATION_PREFIX = "@";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object visit(ASTMethodDeclaration node, Object data) {
|
||||||
|
// Include method modifiers.
|
||||||
|
ASTClassOrInterfaceBodyDeclaration classOrInterfaceBodyDecl =
|
||||||
|
(ASTClassOrInterfaceBodyDeclaration)node.jjtGetParent();
|
||||||
|
|
||||||
|
int startLine = classOrInterfaceBodyDecl.getBeginLine();
|
||||||
|
int endLine = classOrInterfaceBodyDecl.getEndLine();
|
||||||
|
|
||||||
|
Node firstChild = classOrInterfaceBodyDecl.jjtGetChild(0);
|
||||||
|
// Method has annotation
|
||||||
|
if (firstChild instanceof ASTAnnotation) {
|
||||||
|
Token firstToken = (Token)classOrInterfaceBodyDecl.jjtGetFirstToken();
|
||||||
|
// If annotation is before modifier, exclude the annotation.
|
||||||
|
if (ANNOTATION_PREFIX.equals(firstToken.image)) {
|
||||||
|
ASTAnnotation annotation = (ASTAnnotation)firstChild;
|
||||||
|
Token lastToken = (Token)annotation.jjtGetLastToken();
|
||||||
|
|
||||||
|
// First token after annotation. The same line or next line after annotation.
|
||||||
|
Token next = lastToken.next;
|
||||||
|
startLine = next.beginLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endLine - startLine + 1 > MAX_LINE_COUNT) {
|
||||||
|
ViolationUtils.addViolationWithPrecisePosition(this, node, data,
|
||||||
|
I18nResources.getMessage("java.other.MethodTooLongRule.violation.msg", node.getName()));
|
||||||
|
}
|
||||||
|
return super.visit(node, data);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.alibaba.p3c.pmd.lang.java.rule.other;
|
||||||
|
|
||||||
|
import com.alibaba.p3c.pmd.testframework.ExtendRuleTst;
|
||||||
|
|
||||||
|
import net.sourceforge.pmd.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author huawen.phw
|
||||||
|
* @date 2018/2/1
|
||||||
|
* Description:
|
||||||
|
*/
|
||||||
|
public class UseRightCaseForDateFormatRuleTest extends ExtendRuleTst {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExam1() {
|
||||||
|
String ruleName = "UseRightCaseForDateFormatRule";
|
||||||
|
String examFilePath = "java/" + ruleName + "Exam.java";
|
||||||
|
String expectedVioLineNumbers = "16,26,32,34,36";
|
||||||
|
|
||||||
|
Rule rule = findRule(OtherRulesTest.RULESET, ruleName);
|
||||||
|
runTest(rule, examFilePath, expectedVioLineNumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
package com.alibaba.p3c.pmd.testframework;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.sourceforge.pmd.Rule;
|
||||||
|
import net.sourceforge.pmd.testframework.RuleTst;
|
||||||
|
import net.sourceforge.pmd.testframework.TestDescriptor;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author huawen.phw
|
||||||
|
* @date 2018/2/1
|
||||||
|
* Description:
|
||||||
|
*/
|
||||||
|
public class ExtendRuleTst extends RuleTst {
|
||||||
|
|
||||||
|
|
||||||
|
public void runTest(Rule rule, String examFilePath, String expectedVioLineNumbers) {
|
||||||
|
TestDescriptor descriptor = extractTestsFromJavaFile(rule, examFilePath
|
||||||
|
, expectedVioLineNumbers);
|
||||||
|
if (descriptor != null) {
|
||||||
|
runTest(descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param rule
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public TestDescriptor extractTestsFromJavaFile(Rule rule) {
|
||||||
|
return extractTestsFromJavaFile(rule, "java/" + getCleanRuleName(rule) + ".java");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param rule
|
||||||
|
* @param javaFilePath
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public TestDescriptor extractTestsFromJavaFile(Rule rule, String javaFilePath) {
|
||||||
|
return extractTestsFromJavaFile(rule, javaFilePath, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestDescriptor extractTestsFromJavaFile(Rule rule, String javaFilePath, String expectedLineNumbers) {
|
||||||
|
if (StringUtils.isEmpty(javaFilePath)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//append file suffix
|
||||||
|
if (!javaFilePath.toLowerCase().endsWith(".java")) {
|
||||||
|
javaFilePath = javaFilePath + ".java";
|
||||||
|
}
|
||||||
|
InputStream inputStream = getClass().getResourceAsStream(javaFilePath);
|
||||||
|
if (inputStream == null) {
|
||||||
|
throw new RuntimeException("Couldn't find " + javaFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileContents = null;
|
||||||
|
try {
|
||||||
|
fileContents = IOUtils.toString(inputStream, Charset.defaultCharset());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileContents == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<Integer> expectedLineNumber = getExpectedLineNumbers(expectedLineNumbers);
|
||||||
|
TestDescriptor descriptor = new TestDescriptor(fileContents, rule.getDescription(),
|
||||||
|
expectedLineNumber.size(), rule);
|
||||||
|
descriptor.setExpectedLineNumbers(expectedLineNumber);
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getExpectedLineNumbers(String lineNumbers) {
|
||||||
|
List<Integer> expectedLineNumbers = new ArrayList<>();
|
||||||
|
for (String n : lineNumbers.split(" *, *")) {
|
||||||
|
try {
|
||||||
|
expectedLineNumbers.add(Integer.valueOf(n));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expectedLineNumbers;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<test-data>
|
||||||
|
<code-fragment id="unnecessary-not-expression">
|
||||||
|
<![CDATA[
|
||||||
|
public class Example {
|
||||||
|
public int foo(int a, int b) {
|
||||||
|
if (!(a > b)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!(a == b)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!(a != b)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!(a > 0 && b > 0)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!(a == 0 && b >= 0)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</code-fragment>
|
||||||
|
<test-code>
|
||||||
|
<description>unnecessary not operator can be removed</description>
|
||||||
|
<expected-problems>3</expected-problems>
|
||||||
|
<expected-linenumbers>3,6,9</expected-linenumbers>
|
||||||
|
<code-ref id="unnecessary-not-expression"/>
|
||||||
|
</test-code>
|
||||||
|
</test-data>
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.alibaba.p3c.pmd.lang.java.rule.other.java;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author huawen.phw
|
||||||
|
* @date 2018/2/1
|
||||||
|
* Description:
|
||||||
|
*/
|
||||||
|
public class UseRightCaseForDateFormatRuleExam {
|
||||||
|
|
||||||
|
private static final String PATTERN= "yyyyMMdd";
|
||||||
|
|
||||||
|
public void exam1() {
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("YYYYMMDD"); //vio
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("yyyy/MM/dd");
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("yyyymmdd");
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("yyyy-MM-DD");
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss"); //p2 error
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //right
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("yy-MM-DD");
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("YY-MM-DD");//vio
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("YY-md");//vio
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("Yy-md"); //vio
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("yyy-md"); //not checked
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("Y-md"); // not checked
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("y-md"); // not checked
|
||||||
|
|
||||||
|
format = new SimpleDateFormat("dd/MM-YYYY"); //not checked
|
||||||
|
|
||||||
|
exam_2(PATTERN);//can not checked
|
||||||
|
|
||||||
|
exam_2("YYYmmDD");//can not checked
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exam2(String formatStr) {
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat(PATTERN);//can not checked
|
||||||
|
|
||||||
|
format = new SimpleDateFormat(formatStr);//can not checked
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exam3(){
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,407 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<test-data>
|
||||||
|
|
||||||
|
<code-fragment id="method-equal-to-80-lines"><![CDATA[
|
||||||
|
public class MethodTooLongRule {
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
// 77 lines of comment
|
||||||
|
int i = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</code-fragment>
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>Method equal to 80 lines</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code-ref id="method-equal-to-80-lines" />
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
|
||||||
|
<code-fragment id="method-more-than-80-lines"><![CDATA[
|
||||||
|
public class MethodTooLongRule {
|
||||||
|
public void test() {
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
// 78 lines of comment
|
||||||
|
int i = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</code-fragment>
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>Method more than 80 lines</description>
|
||||||
|
<expected-problems>1</expected-problems>
|
||||||
|
<expected-linenumbers>2</expected-linenumbers>
|
||||||
|
<code-ref id="method-more-than-80-lines" />
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
|
||||||
|
<code-fragment id="method-less-than-80-lines"><![CDATA[
|
||||||
|
public class MethodTooLongRule {
|
||||||
|
public void test() {
|
||||||
|
int i = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</code-fragment>
|
||||||
|
<test-code>
|
||||||
|
<description>Method less than 80 lines</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code-ref id="method-less-than-80-lines" />
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
<code-fragment id="interface-method"><![CDATA[
|
||||||
|
interface printable{
|
||||||
|
void print();
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</code-fragment>
|
||||||
|
<test-code>
|
||||||
|
<description>Interface method</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code-ref id="interface-method" />
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
|
||||||
|
<code-fragment id="method-signature-multi-lines"><![CDATA[
|
||||||
|
public class MethodTooLongRule {
|
||||||
|
public
|
||||||
|
void
|
||||||
|
test() {
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
int i = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</code-fragment>
|
||||||
|
<test-code>
|
||||||
|
<description>Method signature multi lines</description>
|
||||||
|
<expected-problems>1</expected-problems>
|
||||||
|
<expected-linenumbers>4</expected-linenumbers>
|
||||||
|
<code-ref id="method-signature-multi-lines" />
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
|
||||||
|
<code-fragment id="method-signature-with-annotation-multi-lines"><![CDATA[
|
||||||
|
public class MethodTooLongRule {
|
||||||
|
@Test public
|
||||||
|
void
|
||||||
|
test() {
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
// 76 lines of comment
|
||||||
|
int i = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</code-fragment>
|
||||||
|
<test-code>
|
||||||
|
<description>Method signature with annotation multi lines</description>
|
||||||
|
<expected-problems>1</expected-problems>
|
||||||
|
<expected-linenumbers>4</expected-linenumbers>
|
||||||
|
<code-ref id="method-signature-with-annotation-multi-lines" />
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
</test-data>
|
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<test-data>
|
||||||
|
|
||||||
|
<code-fragment id="use-right-case-for-date-format"><![CDATA[
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
class DateFormatTest {
|
||||||
|
public void test(){
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("YYYYMMDD"); //vio
|
||||||
|
format = new SimpleDateFormat("yyyy/MM/dd");
|
||||||
|
format = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
format = new SimpleDateFormat("yyyymmdd");
|
||||||
|
format = new SimpleDateFormat("yyyy-MM-DD");
|
||||||
|
format = new SimpleDateFormat("yy-MM-DD");
|
||||||
|
format = new SimpleDateFormat("YY-MM-DD");
|
||||||
|
format = new SimpleDateFormat("YYmd");
|
||||||
|
format = new SimpleDateFormat("YYYY-M-d");
|
||||||
|
format = new SimpleDateFormat("YYYY-dd");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</code-fragment>
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>Use right case to format date</description>
|
||||||
|
<expected-problems>5</expected-problems>
|
||||||
|
<expected-linenumbers>4,10,11,12,13</expected-linenumbers>
|
||||||
|
<code-ref id="use-right-case-for-date-format" />
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
</test-data>
|
Loading…
Reference in New Issue