This commit is contained in:
@@ -356,9 +356,9 @@ public class Standards {
|
||||
static void variable(ASTVariableId id) {
|
||||
if (id.isEnumConstant() && !id.getName().matches("[A-Z][A-Z0-9]*(_[A-Z0-9]+)*"))
|
||||
block(id, "Enum constants require UPPER_SNAKE_CASE");
|
||||
if (id.isRecordComponent() || id.isEnumConstant() || id.isPatternBinding() || id.isUnnamed())
|
||||
if (id.isRecordComponent() || id.isEnumConstant() || id.isUnnamed())
|
||||
return;
|
||||
if (id.isTypeInferred() && !id.isLambdaParameter()) {
|
||||
if (id.isTypeInferred() && !id.isLambdaParameter() && !id.isPatternBinding()) {
|
||||
final ASTExpression initializer = id.getInitializer();
|
||||
if (!(initializer instanceof ASTConstructorCall)
|
||||
&& !(initializer instanceof ASTCastExpression)
|
||||
@@ -447,12 +447,8 @@ public class Standards {
|
||||
}
|
||||
|
||||
static boolean trivial(ASTExecutableDeclaration method) {
|
||||
if (method.getBody() == null) return false;
|
||||
final String body = method
|
||||
.getTextDocument()
|
||||
.sliceOriginalText(method.getBody().getTextRegion())
|
||||
.toString()
|
||||
.replaceAll("\\s+", "");
|
||||
if (method.getBody() == null || method.getBody().getNumChildren() != 1) return false;
|
||||
final JavaNode statement = method.getBody().getChild(0);
|
||||
final String name = method.getName();
|
||||
String property = name;
|
||||
if (name.startsWith("get") || name.startsWith("set")) property = name.substring(3);
|
||||
@@ -463,12 +459,26 @@ public class Standards {
|
||||
if (method.getEnclosingType().getSymbol().getDeclaredFields().stream()
|
||||
.noneMatch(f -> f.getSimpleName().equals(fieldName))) return false;
|
||||
if (method.getArity() == 0)
|
||||
return body.equals("{return" + property + ";}")
|
||||
|| body.equals("{returnthis." + property + ";}");
|
||||
return statement instanceof ASTReturnStatement returned
|
||||
&& accessorField(returned.getExpr(), method, property);
|
||||
if (method.getArity() != 1 || !name.startsWith("set")) return false;
|
||||
final String parameter = method.getFormalParameters().get(0).getVarId().getName();
|
||||
return body.equals("{this." + property + "=" + parameter + ";}")
|
||||
|| !property.equals(parameter) && body.equals("{" + property + "=" + parameter + ";}");
|
||||
return statement instanceof ASTExpressionStatement expression
|
||||
&& expression.getExpr() instanceof ASTAssignmentExpression assignment
|
||||
&& !assignment.isCompound()
|
||||
&& accessorField(assignment.getLeftOperand(), method, property)
|
||||
&& assignment.getRightOperand() instanceof ASTVariableAccess value
|
||||
&& method.getFormalParameters().get(0).getVarId().getSymbol()
|
||||
.equals(value.getReferencedSym());
|
||||
}
|
||||
|
||||
static boolean accessorField(
|
||||
ASTExpression expression, ASTExecutableDeclaration method, String property) {
|
||||
if (!(expression instanceof ASTAssignableExpr.ASTNamedReferenceExpr reference)) return false;
|
||||
if (expression instanceof ASTFieldAccess field
|
||||
&& !(field.getQualifier() instanceof ASTThisExpression)) return false;
|
||||
return method.getEnclosingType().getSymbol().getDeclaredFields().stream()
|
||||
.anyMatch(field -> field.getSimpleName().equals(property)
|
||||
&& field.equals(reference.getReferencedSym()));
|
||||
}
|
||||
|
||||
record Dependency(JTypeMirror type, Set<String> qualifiers) {}
|
||||
|
||||
Reference in New Issue
Block a user