Skip to content

Commit

Permalink
refactor: Operator wrapping on end of line
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek and TeamModerne committed Sep 21, 2024
1 parent 11a43f2 commit 0466552
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public J visitMethodInvocation(J.MethodInvocation mi, ExecutionContext ctx) {
}

// Replace StringUtils.isEmpty(var.trim()) with var.trim().isEmpty()
if (trimMatcher.matches(arg)
&& (((J.MethodInvocation) arg).getSelect() instanceof J.Identifier || ((J.MethodInvocation) arg).getSelect() instanceof J.FieldAccess)) {
if (trimMatcher.matches(arg) &&
(((J.MethodInvocation) arg).getSelect() instanceof J.Identifier || ((J.MethodInvocation) arg).getSelect() instanceof J.FieldAccess)) {
JavaTemplate replacementTemplate = isEmptyCall ? isEmptyTrimmed : isNotEmptyTrimmed;
// Maybe remove imports
maybeRemoveImport("org.apache.commons.lang3.StringUtils");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ static boolean isRepeatableArgument(Expression arg) {
return true;
}
// Allow simple getters that return a String
return arg instanceof J.MethodInvocation
&& ((J.MethodInvocation) arg).getSelect() instanceof J.Identifier
&& ((J.MethodInvocation) arg).getSimpleName().startsWith("get")
&& (((J.MethodInvocation) arg).getArguments().isEmpty() || ((J.MethodInvocation) arg).getArguments().get(0) instanceof J.Empty)
&& TypeUtils.isAssignableTo("java.lang.String", ((J.MethodInvocation) arg).getMethodType());
return arg instanceof J.MethodInvocation &&
((J.MethodInvocation) arg).getSelect() instanceof J.Identifier &&
((J.MethodInvocation) arg).getSimpleName().startsWith("get") &&
(((J.MethodInvocation) arg).getArguments().isEmpty() || ((J.MethodInvocation) arg).getArguments().get(0) instanceof J.Empty) &&
TypeUtils.isAssignableTo("java.lang.String", ((J.MethodInvocation) arg).getMethodType());
}

@Override
Expand Down

0 comments on commit 0466552

Please sign in to comment.