Skip to content

Commit

Permalink
Fix deprecated addViolation usage.
Browse files Browse the repository at this point in the history
"When reporting a violation, you might see a deprecation of the addViolation methods. These methods have been moved to RuleContext. E.g. instead of addViolation(data, node, ...) use asCtx(data).addViolation(node, ...)."
  • Loading branch information
pnatashap committed Mar 29, 2024
1 parent c0a3d55 commit 0fb302c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public final class ProhibitPlainJunitAssertionsRule
@Override
public Object visit(final ASTMethodDeclaration method, final Object data) {
if (this.isJUnitMethod(method, data)
&& this.containsPlainJunitAssert(method.getBlock())) {
this.addViolation(data, method);
&& this.containsPlainJunitAssert(method.getBody())) {
this.asCtx(data).addViolation(method);
}
return data;
}
Expand All @@ -68,7 +68,7 @@ public Object visit(final ASTImportDeclaration imp, final Object data) {
for (final String element : ProhibitPlainJunitAssertionsRule
.PROHIBITED) {
if (imp.getImportedName().contains(element)) {
this.addViolation(data, imp);
this.asCtx(data).addViolation(imp);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
*
* @since 0.4
*/
@SuppressWarnings("deprecation")
public final class UnnecessaryLocalRule extends AbstractJavaRule {
@Override
public Object visit(final ASTMethodDeclaration meth, final Object data) {
Expand Down Expand Up @@ -83,12 +82,10 @@ public Object visit(final ASTArgumentList rtn, final Object data) {
* @param data Context.
* @param name Variable name.
*/
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private void usages(final JavaNode node, final Object data,
final ASTVariableDeclarator name) {
final Map<NameDeclaration, List<NameOccurrence>> vars = name
.getScope().getDeclarations();
// @checkstyle LineLength (1 line)
for (final Map.Entry<NameDeclaration, List<NameOccurrence>> entry
: vars.entrySet()) {
final List<NameOccurrence> usages = entry.getValue();
Expand All @@ -97,8 +94,8 @@ private void usages(final JavaNode node, final Object data,
}
for (final NameOccurrence occ: usages) {
if (occ.getLocation().equals(name)) {
this.addViolation(
data, node, new Object[]{name.getImage()}
this.asCtx(data).addViolation(
node, name.getImage()
);
}
}
Expand Down

0 comments on commit 0fb302c

Please sign in to comment.