diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/LinguisticNamingRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/LinguisticNamingRule.java index 061e7e4196..86edffe880 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/LinguisticNamingRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/LinguisticNamingRule.java @@ -7,6 +7,9 @@ package net.sourceforge.pmd.lang.java.rule.codestyle; import static net.sourceforge.pmd.properties.PropertyFactory.booleanProperty; import static net.sourceforge.pmd.properties.PropertyFactory.stringListProperty; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Locale; @@ -18,11 +21,11 @@ import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTResultType; import net.sourceforge.pmd.lang.java.ast.ASTType; import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator; -import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; +import net.sourceforge.pmd.lang.java.rule.AbstractIgnoredAnnotationRule; import net.sourceforge.pmd.lang.java.typeresolution.TypeHelper; import net.sourceforge.pmd.properties.PropertyDescriptor; -public class LinguisticNamingRule extends AbstractJavaRule { +public class LinguisticNamingRule extends AbstractIgnoredAnnotationRule { private static final PropertyDescriptor CHECK_BOOLEAN_METHODS = booleanProperty("checkBooleanMethod").defaultValue(true).desc("Check method names and types for inconsistent naming.").build(); private static final PropertyDescriptor CHECK_GETTERS = @@ -70,6 +73,11 @@ public class LinguisticNamingRule extends AbstractJavaRule { addRuleChainVisit(ASTLocalVariableDeclaration.class); } + @Override + protected Collection defaultSuppressionAnnotations() { + return Collections.checkedList(Arrays.asList("java.lang.Override"), String.class); + } + @Override public Object visit(ASTMethodDeclaration node, Object data) { String nameOfMethod = node.getMethodName(); @@ -132,10 +140,12 @@ public class LinguisticNamingRule extends AbstractJavaRule { } private void checkSetters(ASTMethodDeclaration node, Object data, String nameOfMethod) { - ASTResultType resultType = node.getResultType(); - if (hasPrefix(nameOfMethod, "set") && !resultType.isVoid()) { - addViolationWithMessage(data, node, "Linguistics Antipattern - The setter ''{0}'' should not return any type except void linguistically", - new Object[] { nameOfMethod }); + if (!hasIgnoredAnnotation(node)) { + ASTResultType resultType = node.getResultType(); + if (hasPrefix(nameOfMethod, "set") && !resultType.isVoid()) { + addViolationWithMessage(data, node, "Linguistics Antipattern - The setter ''{0}'' should not return any type except void linguistically", + new Object[] { nameOfMethod }); + } } } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/LinguisticNaming.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/LinguisticNaming.xml index 006b005d35..905b91fa42 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/LinguisticNaming.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/LinguisticNaming.xml @@ -549,6 +549,29 @@ public class AtomicBooleanFN { AtomicBoolean willX = new AtomicBoolean(true); AtomicBoolean shouldX = new AtomicBoolean(true); } +} + ]]> + + + #1543 [java] LinguisticNaming should ignore overriden methods + 1 +