Skip to content

Commit

Permalink
Set types on method invocation names to the same type the compiler ge…
Browse files Browse the repository at this point in the history
…nerates. (#365)
  • Loading branch information
traceyyoshima authored Dec 7, 2023
1 parent f399d72 commit 513b6fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (methodMatcher.matches(method) && type != null && !newReturnType.equals(type.getReturnType().toString())) {
type = type.withReturnType(JavaType.buildType(newReturnType));
m = m.withMethodType(type);
if (m.getName().getType() != null) {
m = m.withName(m.getName().withType(type));
}
methodUpdated = true;
}
return m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
Optional<JavaType.Method> formatted = method.getMethodType().getDeclaringType().getMethods().stream()
.filter(m -> m.getName().equals("formatted")).findAny();
mi = mi.withMethodType(formatted.orElse(null));
if (mi.getName().getType() != null) {
mi = mi.withName(mi.getName().withType(mi.getMethodType()));
}
Expression select = wrapperNotNeeded ? arguments.get(0) :
new J.Parentheses<>(Tree.randomId(), Space.EMPTY, Markers.EMPTY, JRightPadded.build(arguments.get(0)));
mi = mi.withSelect(select);
Expand Down

0 comments on commit 513b6fa

Please sign in to comment.