Fix formatting and static code analysis findings.
This commit is contained in:
parent
1a9e721fb6
commit
69a24126f7
@ -5,18 +5,21 @@
|
||||
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTParameter;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
|
||||
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Scans classes which implement the `Queueable` interface. If the `public void
|
||||
* execute(QueueableContext context)` method does not call the `System.attachFinalizer(Finalizer f)`
|
||||
* method, then a violation will be added to the `execute` method.
|
||||
* execute(QueueableContext context)` method does not call the
|
||||
* `System.attachFinalizer(Finalizer f)` method, then a violation will be added
|
||||
* to the `execute` method.
|
||||
*
|
||||
* @author mitchspano
|
||||
*/
|
||||
@ -33,8 +36,9 @@ public class QueueableWithoutFinalizerRule extends AbstractApexRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* If the class implements the `Queueable` interface and the `execute(QueueableContext context)`
|
||||
* does not call the `System.attachFinalizer(Finalizer f)` method, then add a violation.
|
||||
* If the class implements the `Queueable` interface and the
|
||||
* `execute(QueueableContext context)` does not call the
|
||||
* `System.attachFinalizer(Finalizer f)` method, then add a violation.
|
||||
*/
|
||||
@Override
|
||||
public Object visit(ASTUserClass theClass, Object data) {
|
||||
@ -53,7 +57,7 @@ public class QueueableWithoutFinalizerRule extends AbstractApexRule {
|
||||
/** Determines if the class implements the Queueable interface. */
|
||||
private boolean implementsTheQueueableInterface(ASTUserClass theClass) {
|
||||
for (String interfaceName : theClass.getInterfaceNames()) {
|
||||
if (interfaceName.equalsIgnoreCase(QUEUEABLE)) {
|
||||
if (QUEUEABLE.equalsIgnoreCase(interfaceName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -61,23 +65,25 @@ public class QueueableWithoutFinalizerRule extends AbstractApexRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the method is the `execute(QueueableContext context)` method. Parameter count is
|
||||
* checked to account for method overloading.
|
||||
* Determines if the method is the `execute(QueueableContext context)`
|
||||
* method. Parameter count is checked to account for method overloading.
|
||||
*/
|
||||
private boolean isTheExecuteMethodOfTheQueueableInterface(ASTMethod theMethod) {
|
||||
if (!theMethod.getCanonicalName().equalsIgnoreCase(EXECUTE)) {
|
||||
if (!EXECUTE.equalsIgnoreCase(theMethod.getCanonicalName())) {
|
||||
return false;
|
||||
}
|
||||
List<ASTParameter> parameters = theMethod.descendants(ASTParameter.class).toList();
|
||||
return parameters.size() == 1
|
||||
&& parameters.get(0).getType().equalsIgnoreCase(QUEUEABLE_CONTEXT);
|
||||
return parameters.size() == 1 && QUEUEABLE_CONTEXT.equalsIgnoreCase(parameters.get(0).getType());
|
||||
}
|
||||
|
||||
/** Determines if the method calls the `System.attachFinalizer(Finalizer f)` method. */
|
||||
/**
|
||||
* Determines if the method calls the `System.attachFinalizer(Finalizer f)`
|
||||
* method.
|
||||
*/
|
||||
private boolean callsTheSystemAttachFinalizerMethod(ASTMethod theMethod) {
|
||||
for (ASTMethodCallExpression methodCallExpression :
|
||||
theMethod.descendants(ASTMethodCallExpression.class).toList()) {
|
||||
if (methodCallExpression.getFullMethodName().equalsIgnoreCase(SYSTEM_ATTACH_FINALIZER)) {
|
||||
for (ASTMethodCallExpression methodCallExpression : theMethod.descendants(ASTMethodCallExpression.class)
|
||||
.toList()) {
|
||||
if (SYSTEM_ATTACH_FINALIZER.equalsIgnoreCase(methodCallExpression.getFullMethodName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user