Skip to content

Commit

Permalink
Merge pull request #1 from dykov/feature/migrate-to-pmd7
Browse files Browse the repository at this point in the history
Fix deprecated warnings in Java rules
  • Loading branch information
dykov authored Jan 23, 2024
2 parents c719e56 + af52995 commit 90c458d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.lang.java.rule.AbstractPoorMethodCall;
import net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence;
import net.sourceforge.pmd.lang.java.xpath.TypeIsExactlyFunction;
import net.sourceforge.pmd.lang.java.xpath.TypeIsFunction;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
Expand Down Expand Up @@ -91,11 +90,9 @@ public Object visit(final ASTVariableDeclaratorId node, final Object data) {
for (final NameOccurrence usage : node.getUsages()) {
final JavaNameOccurrence occurrence = (JavaNameOccurrence) usage;
if (this.isNotedMethod(occurrence.getNameForWhichThisIsAQualifier())) {
this.addViolation(
data, occurrence.getLocation(), new String[]{
this.asCtx(data).addViolation(occurrence.getLocation(),
this.getProperty(CLASS),
occurrence.getNameForWhichThisIsAQualifier().getImage(),
}
occurrence.getNameForWhichThisIsAQualifier().getImage()
);
}
}
Expand All @@ -113,9 +110,9 @@ private boolean hasNotedClass(final ASTVariableDeclaratorId node) {
final String typename = this.getProperty(CLASS);
final ASTType typenode = node.getTypeNode();
if (this.getProperty(CHECK_SUBTYPES)) {
noted = TypeIsFunction.typeIs(typenode, typename);
noted = TypeTestUtil.isA(typename, typenode);
} else {
noted = TypeIsExactlyFunction.typeIsExactly(typenode, typename);
noted = TypeTestUtil.isExactlyA(typename, typenode);
}
return noted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public MissingMandatoryAnnotation() {
public Object visit(final ASTMethodDeclaration mthd, final Object data) {
final Optional<ASTAnnotation> restannot = this.getRestAnnotation(mthd);
if (restannot.isPresent() && this.hasNoMandatoryAnnotation(mthd)) {
this.addViolation(data, restannot.get());
asCtx(data).addViolation(restannot.get());
}
return super.visit(mthd, data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Object visit(final ASTVariableDeclaratorId vardecl, final Object data) {
getArguments(occurrence)
.stream()
.filter(this::hasSensitiveData)
.forEach(arg -> this.addViolation(data, arg));
.forEach(arg -> asCtx(data).addViolation(arg));
}
}
return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
import net.sourceforge.pmd.lang.java.xpath.TypeIsFunction;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
Expand Down Expand Up @@ -82,7 +83,7 @@ public Object visit(final ASTMethodDeclaration mthd, final Object data) {
.filter(this::isMdc)
.forEach(this::updateMap);
for (final ASTPrimaryExpression expression : this.keymap.values()) {
this.addViolation(data, expression);
asCtx(data).addViolation(expression);
}
return data;
}
Expand All @@ -95,7 +96,7 @@ public Object visit(final ASTMethodDeclaration mthd, final Object data) {
private boolean isMdc(final ASTPrimaryPrefix prefix) {
return this.getProperty(MDC_CLASSES)
.stream()
.anyMatch(mdc -> TypeIsFunction.typeIs(prefix, mdc));
.anyMatch(mdc -> TypeTestUtil.isA(mdc, prefix));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Object visit(final ASTLiteral node, final Object data) {
String image = node.getTextBlockContent();
image = image.substring(1, image.length() - 1);
if (image.length() > 0 && this.pattern.matcher(image).find()) {
this.addViolation(data, node);
asCtx(data).addViolation(node);
}
}
return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public WrongRestMethodSignature() {
@Override
public Object visit(final ASTMethodDeclaration mthd, final Object data) {
if (this.isRestMethod(mthd) && hasWrongSignature(mthd)) {
this.addViolation(data, mthd);
asCtx(data).addViolation(mthd);
}
return super.visit(mthd, data);
}
Expand Down

0 comments on commit 90c458d

Please sign in to comment.