Skip to content

Commit

Permalink
fix #553
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed Jun 30, 2024
1 parent fc78f7e commit bdc5a7a
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

@ExecutableCheck(reportedProblems = {ProblemType.USE_OPERATOR_ASSIGNMENT})

public class UseOperatorAssignment extends IntegratedCheck {
private static final List<Class<?>> NON_COMMUTATIVE_TYPES = List.of(
java.lang.String.class
);
private static final Set<BinaryOperatorKind> NON_ASSIGNABLE_OPERATORS = Set.of(
BinaryOperatorKind.AND,
BinaryOperatorKind.EQ,
BinaryOperatorKind.GE,
BinaryOperatorKind.GT,
BinaryOperatorKind.INSTANCEOF,
BinaryOperatorKind.LE,
BinaryOperatorKind.LT,
BinaryOperatorKind.NE,
BinaryOperatorKind.OR
);

private boolean isCommutativeType(CtTypedElement<?> ctTypedElement) {
return ctTypedElement.getType() == null
Expand All @@ -42,13 +54,13 @@ private boolean isCommutative(BinaryOperatorKind binaryOperatorKind) {
}

private boolean isAssignable(BinaryOperatorKind binaryOperatorKind) {
return this.isCommutative(binaryOperatorKind) || List.of(
return !NON_ASSIGNABLE_OPERATORS.contains(binaryOperatorKind) && (this.isCommutative(binaryOperatorKind) || List.of(
BinaryOperatorKind.MOD,
BinaryOperatorKind.MINUS,
BinaryOperatorKind.DIV,
BinaryOperatorKind.SL,
BinaryOperatorKind.SR
).contains(binaryOperatorKind);
).contains(binaryOperatorKind));
}

@Override
Expand Down

0 comments on commit bdc5a7a

Please sign in to comment.