pmd-cpp/pmd-java: checkstyle fixes

This commit is contained in:
Andreas Dangel
2016-12-16 15:48:53 +01:00
parent eb2d942ed4
commit e280151987
16 changed files with 70 additions and 76 deletions

View File

@ -55,13 +55,13 @@ public class CPPTokenizerTest {
}
@Test
public void testContinuation_IntraToken() {
public void testContinuationIntraToken() {
Tokens tokens = parse(TEST5);
assertEquals(7, tokens.size());
}
@Test
public void testContinuation_InterToken() {
public void testContinuationInterToken() {
Tokens tokens = parse(TEST6);
assertEquals(17, tokens.size());
}
@ -172,8 +172,4 @@ public class CPPTokenizerTest {
private static final String TEST7 = "asm void eSPI_boot()" + PMD.EOL + "{" + PMD.EOL + " // setup stack pointer"
+ PMD.EOL + " lis r1, _stack_addr@h" + PMD.EOL + " ori r1, r1, _stack_addr@l" + PMD.EOL + "}";
public static junit.framework.Test suite() {
return new junit.framework.JUnit4TestAdapter(CPPTokenizerTest.class);
}
}

View File

@ -1604,14 +1604,12 @@ void Name() :
* by a ".*" when used in the context of an "ImportDeclaration".
*/
{
StringBuffer s = new StringBuffer();
StringBuilder s = new StringBuilder();
Token t;
}
{
t=<IDENTIFIER>
{
jjtThis.testingOnly__setBeginLine( t.beginLine);
jjtThis.testingOnly__setBeginColumn( t.beginColumn);
s.append(t.image);
}
( LOOKAHEAD(2) "." t=<IDENTIFIER>

View File

@ -147,7 +147,7 @@ public class CouplingBetweenObjectsRule extends AbstractJavaRule {
}
/**
* Filters variable type - we don't want primatives, wrappers, strings, etc.
* Filters variable type - we don't want primitives, wrappers, strings, etc.
* This needs more work. I'd like to filter out super types and perhaps
* interfaces
*
@ -156,7 +156,7 @@ public class CouplingBetweenObjectsRule extends AbstractJavaRule {
* @return boolean true if variableType is not what we care about
*/
private boolean filterTypes(String variableType) {
return variableType != null && (variableType.startsWith("java.lang.") || variableType.equals("String")
return variableType != null && (variableType.startsWith("java.lang.") || "String".equals(variableType)
|| filterPrimitivesAndWrappers(variableType));
}

View File

@ -60,10 +60,10 @@ public class SingletonClassReturningNewInstanceRule extends AbstractJavaRule {
* return m_instance; } }
*/
List<ASTBlockStatement> ASTBlockStatements = node.findDescendantsOfType(ASTBlockStatement.class);
List<ASTBlockStatement> astBlockStatements = node.findDescendantsOfType(ASTBlockStatement.class);
returnVariableName = getReturnVariableName(node);
if (ASTBlockStatements.size() != 0) {
for (ASTBlockStatement blockStatement : ASTBlockStatements) {
if (astBlockStatements.size() != 0) {
for (ASTBlockStatement blockStatement : astBlockStatements) {
if (blockStatement.hasDescendantOfType(ASTLocalVariableDeclaration.class)) {
List<ASTLocalVariableDeclaration> lVarList = blockStatement
.findDescendantsOfType(ASTLocalVariableDeclaration.class);

View File

@ -170,7 +170,7 @@ public class VariableNamingConventionsRule extends AbstractJavaRule {
String varName = variableDeclaratorId.getImage();
// Skip serialVersionUID
if (varName.equals("serialVersionUID")) {
if ("serialVersionUID".equals(varName)) {
return data;
}

View File

@ -113,7 +113,7 @@ public class ConsecutiveAppendsShouldReuseRule extends AbstractJavaRule {
.getFirstDescendantOfType(ASTPrimarySuffix.class);
if (primarySuffix != null) {
final String name = primarySuffix.getImage();
if (name != null && name.equals("append")) {
if ("append".equals(name)) {
final ASTPrimaryExpression pExp = stmtExp
.getFirstDescendantOfType(ASTPrimaryExpression.class);
if (pExp != null) {
@ -140,7 +140,7 @@ public class ConsecutiveAppendsShouldReuseRule extends AbstractJavaRule {
ASTPrimarySuffix primarySuffix = exp.getFirstDescendantOfType(ASTPrimarySuffix.class);
if (primarySuffix != null) {
final String name = primarySuffix.getImage();
if (name != null && name.equals("append")) {
if ("append".equals(name)) {
String variable = vdId.getImage();
if (isAStringBuilderBuffer(primarySuffix, variable)) {
return variable;

View File

@ -119,6 +119,6 @@ public class UnusedPrivateFieldRule extends AbstractLombokAwareRule {
}
private boolean isOK(String image) {
return image.equals("serialVersionUID") || image.equals("serialPersistentFields") || image.equals("IDENT");
return "serialVersionUID".equals(image) || "serialPersistentFields".equals(image) || "IDENT".equals(image);
}
}

View File

@ -155,22 +155,22 @@ public class SimpleTypedNameDeclaration implements TypedNameDeclaration {
if (primitiveTypes.contains(lcType) && primitiveTypes.contains(otherLcType)) {
if (lcType.equals(otherLcType)) {
return true;
} else if ((lcType.equals("char") || lcType.equals("character"))
&& (otherLcType.equals("char") || otherLcType.equals("character"))) {
} else if (("char".equals(lcType) || "character".equals(lcType))
&& ("char".equals(otherLcType) || "character".equals(otherLcType))) {
return true;
} else if ((lcType.equals("int") || lcType.equals("integer"))
&& (otherLcType.equals("int") || otherLcType.equals("integer")
|| otherLcType.equals("short") || otherLcType.equals("char")
|| otherLcType.equals("character") || otherLcType.equals("byte"))) {
} else if (("int".equals(lcType) || "integer".equals(lcType))
&& ("int".equals(otherLcType) || "integer".equals(otherLcType)
|| "short".equals(otherLcType) || "char".equals(otherLcType)
|| "character".equals(otherLcType) || "byte".equals(otherLcType))) {
return true;
} else if (lcType.equals("double") && (otherLcType.equals("float") || otherLcType.equals("int")
|| otherLcType.equals("integer") || otherLcType.equals("long"))) {
} else if ("double".equals(lcType) && ("float".equals(otherLcType) || "int".equals(otherLcType)
|| "integer".equals(otherLcType) || "long".equals(otherLcType))) {
return true;
} else if (lcType.equals("float") && (otherLcType.equals("int") || otherLcType.equals("integer")
|| otherLcType.equals("long"))) {
} else if ("float".equals(lcType) && ("int".equals(otherLcType) || "integer".equals(otherLcType)
|| "long".equals(otherLcType))) {
return true;
} else if (lcType.equals("long") && (otherLcType.equals("int") || otherLcType.equals("integer")
|| otherLcType.equals("char") || otherLcType.equals("character"))) {
} else if ("long".equals(lcType) && ("int".equals(otherLcType) || "integer".equals(otherLcType)
|| "char".equals(otherLcType) || "character".equals(otherLcType))) {
return true;
}
}

View File

@ -15,11 +15,11 @@ import net.sourceforge.pmd.testframework.TestDescriptor;
public class RegexpAcceptanceTest extends SimpleAggregatorTst {
private static final String xPath = "//ClassOrInterfaceDeclaration[matches(@Image, 'F?o')]";
private static final String XPATH = "//ClassOrInterfaceDeclaration[matches(@Image, 'F?o')]";
@Test
public void testSimple() {
Rule r = new XPathRule(xPath);
Rule r = new XPathRule(XPATH);
r.setLanguage(LanguageRegistry.getLanguage(JavaLanguageModule.NAME));
r.setMessage("");
TestDescriptor[] testDescriptors = extractTestsFromXml(r, "RegexpAcceptance");

View File

@ -47,7 +47,7 @@ public class JDKVersionTest extends ParserTst {
// assert keyword/identifier
@Test
public void testAssertAsKeywordVariantsSucceedWith1_4() {
public void testAssertAsKeywordVariantsSucceedWith14() {
parseJava14(loadSource("assert_test1.java"));
parseJava14(loadSource("assert_test2.java"));
parseJava14(loadSource("assert_test3.java"));
@ -55,22 +55,22 @@ public class JDKVersionTest extends ParserTst {
}
@Test(expected = ParseException.class)
public void testAssertAsVariableDeclIdentifierFailsWith1_4() {
public void testAssertAsVariableDeclIdentifierFailsWith14() {
parseJava14(loadSource("assert_test5.java"));
}
@Test(expected = ParseException.class)
public void testAssertAsMethodNameIdentifierFailsWith1_4() {
public void testAssertAsMethodNameIdentifierFailsWith14() {
parseJava14(loadSource("assert_test7.java"));
}
@Test
public void testAssertAsIdentifierSucceedsWith1_3() {
public void testAssertAsIdentifierSucceedsWith13() {
parseJava13(loadSource("assert_test5.java"));
}
@Test(expected = ParseException.class)
public void testAssertAsKeywordFailsWith1_3() {
public void testAssertAsKeywordFailsWith13() {
parseJava13(loadSource("assert_test6.java"));
}
// assert keyword/identifier
@ -154,7 +154,7 @@ public class JDKVersionTest extends ParserTst {
}
@Test
public void testAssertAsIdentifierSucceedsWith1_3_test2() {
public void testAssertAsIdentifierSucceedsWith13Test2() {
parseJava13(loadSource("assert_test5_a.java"));
}

View File

@ -51,147 +51,147 @@ public class AcceptanceTest extends ParserTst {
}
@Test
public void test_1() {
public void test1() {
assertTrue(check(TEST1_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST1)));
}
@Test
public void test_2() {
public void test2() {
assertTrue(check(TEST2_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST2)));
}
@Test
public void test_3() {
public void test3() {
assertTrue(check(TEST3_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST3)));
}
@Test
public void test_4() {
public void test4() {
assertTrue(check(TEST4_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST4)));
}
@Test
public void test_6() {
public void test6() {
assertTrue(check(TEST5_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST6)));
}
@Test
public void test_7() {
public void test7() {
assertTrue(check(TEST5_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST7)));
}
@Test
public void test_8() {
public void test8() {
assertTrue(check(TEST8_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST8)));
}
@Test
public void test_9() {
public void test9() {
assertTrue(check(TEST5_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST9)));
}
@Test
public void test_10() {
public void test10() {
assertTrue(check(TEST8_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST10)));
}
@Test
public void test_11() {
public void test11() {
assertTrue(check(TEST8_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST11)));
}
@Test
public void test_12() {
public void test12() {
assertTrue(check(TEST12_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST12)));
}
@Test
public void test_13() {
public void test13() {
assertTrue(check(TEST13_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST13)));
}
@Test
public void test_14() {
public void test14() {
assertTrue(check(TEST14_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST14)));
}
@Test
public void test_15() {
public void test15() {
assertTrue(check(TEST15_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST15)));
}
@Test
public void test_16() {
public void test16() {
assertTrue(check(TEST16_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST16)));
}
@Test
public void test_17() {
public void test17() {
assertTrue(check(TEST17_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST17)));
}
@Test
public void test_18() {
public void test18() {
assertTrue(check(TEST18_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST18)));
}
@Test
public void test_19() {
public void test19() {
assertTrue(check(TEST19_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST19)));
}
@Test
public void test_20() {
public void test20() {
assertTrue(check(TEST20_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST20)));
}
@Test
public void test_21() {
public void test21() {
assertTrue(check(TEST21_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST21)));
}
@Test
public void test_22() {
public void test22() {
assertTrue(check(TEST22_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST22)));
}
@Test
public void test_23() {
public void test23() {
assertTrue(check(TEST23_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST23)));
}
@Test
public void test_24() {
public void test24() {
assertTrue(check(TEST24_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST24)));
}
@Test
public void test_25() {
public void test25() {
assertTrue(check(TEST25_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST25)));
}
@Test
public void test_26() {
public void test26() {
assertTrue(check(TEST26_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST26)));
}
@Test
public void test_27() {
public void test27() {
assertTrue(check(TEST27_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST27)));
}
@Test
public void test_28() {
public void test28() {
assertTrue(check(TEST28_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST28)));
}
@Test
public void test_29() {
public void test29() {
assertTrue(check(TEST29_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST29)));
}
@Test
public void test_30() {
public void test30() {
assertTrue(check(TEST30_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST30)));
}

View File

@ -93,7 +93,7 @@ public class XPathRuleTest extends RuleTst {
*/
@Test
public void testImageOfPrimarySuffix() throws Exception {
String SUFFIX = "import java.io.File;\n" + "\n" + "public class TestSuffix {\n"
final String SUFFIX = "import java.io.File;\n" + "\n" + "public class TestSuffix {\n"
+ " public static void main(String args[]) {\n" + " new File(\"subdirectory\").list();\n"
+ " }\n" + "}";
LanguageVersion language = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getDefaultVersion();
@ -138,7 +138,7 @@ public class XPathRuleTest extends RuleTst {
*/
@Test
public void testFollowingSibling() throws Exception {
String SOURCE = "public class dummy {\n" + " public String toString() {\n"
final String SOURCE = "public class dummy {\n" + " public String toString() {\n"
+ " String test = \"bad example\";\n" + " test = \"a\";\n" + " return test;\n" + " }\n" + "}";
LanguageVersion language = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getDefaultVersion();
ParserOptions parserOptions = language.getLanguageVersionHandler().getDefaultParserOptions();

View File

@ -7,6 +7,6 @@ package net.sourceforge.pmd.lang.java.rule.unusedcode.unusedprivatemethod;
/**
* Sample class
*/
public class DashboardGraphInnateFilter_o extends DashboardInnateFilter_o {
public class DashboardGraphInnateFilter extends DashboardInnateFilter {
// yes, this is empty, it just need to be a subclass.
}

View File

@ -7,7 +7,7 @@ package net.sourceforge.pmd.lang.java.rule.unusedcode.unusedprivatemethod;
/**
* Sample class
*/
public class DashboardInnateFilter_o {
public class DashboardInnateFilter {
// yes, this class is empty. It is the base class for
// DashboardGraphInnateFilter_o
}

View File

@ -7,5 +7,5 @@ package net.sourceforge.pmd.typeresolution.testdata;
public class ExtraTopLevelClass {
}
class TheExtraTopLevelClass {
class TheExtraTopLevelClass { // SUPPRESS CHECKSTYLE explicityl testing two classes in one file
}

View File

@ -562,7 +562,7 @@ public class Foo extends MultiActionController {
private static final Logger logger = Logger.getLogger(Foo.class);
public DashboardGraphInnateFilter_o getGraphInnateFilter(HttpServletRequest request) {
public DashboardGraphInnateFilter getGraphInnateFilter(HttpServletRequest request) {
setInnateFilterFields();
return null;
}
@ -582,13 +582,13 @@ import net.sourceforge.pmd.lang.java.rule.unusedcode.unusedprivatemethod.*;
public class Foo extends MultiActionController {
private static final Logger logger = Logger.getLogger(Foo.class);
public DashboardGraphInnateFilter_o getGraphInnateFilter(HttpServletRequest request) {
DashboardGraphInnateFilter_o filter = new DashboardGraphInnateFilter_o();
public DashboardGraphInnateFilter getGraphInnateFilter(HttpServletRequest request) {
DashboardGraphInnateFilter filter = new DashboardGraphInnateFilter();
setInnateFilterFields(filter, request);
return filter;
}
private void setInnateFilterFields(DashboardInnateFilter_o filter, HttpServletRequest request) { //incorrectly flagged
private void setInnateFilterFields(DashboardInnateFilter filter, HttpServletRequest request) { //incorrectly flagged
logger.info("here");
}
}