diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java index cc49bb13bd0..b59711497b3 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java @@ -670,6 +670,9 @@ public ITypeBinding resolveExpressionType(Expression expr) { } } var jcTree = this.converter.domToJavac.get(expr); + if (jcTree instanceof JCMethodInvocation javacMethodInvocation) { + return this.bindings.getTypeBinding(javacMethodInvocation.meth.type.asMethodType().getReturnType()); + } if (jcTree instanceof JCFieldAccess jcFieldAccess) { if (jcFieldAccess.type instanceof PackageType) { return null; diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacProblemConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacProblemConverter.java index b067dc40515..fef24ca6ab1 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacProblemConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacProblemConverter.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.util.Locale; import java.util.Map; +import java.util.stream.Stream; import javax.tools.Diagnostic; import javax.tools.JavaFileObject; @@ -78,12 +79,13 @@ public JavacProblem createJavacProblem(Diagnostic diag return null; } org.eclipse.jface.text.Position diagnosticPosition = getDiagnosticPosition(diagnostic, context); + String[] arguments = getDiagnosticStringArguments(diagnostic); return new JavacProblem( diagnostic.getSource().getName().toCharArray(), diagnostic.getMessage(Locale.getDefault()), diagnostic.getCode(), problemId, - new String[0], + arguments, severity, diagnosticPosition.getOffset(), diagnosticPosition.getOffset() + diagnosticPosition.getLength() - 1, @@ -489,6 +491,27 @@ private Object[] getDiagnosticArguments(Diagnostic diagnostic) { return jcDiagnostic.getArgs(); } + private String[] getDiagnosticStringArguments(Diagnostic diagnostic) { + if (!(diagnostic instanceof JCDiagnostic jcDiagnostic)) { + return new String[0]; + } + + if (!jcDiagnostic.getSubdiagnostics().isEmpty()) { + jcDiagnostic = jcDiagnostic.getSubdiagnostics().get(0); + } + + if (jcDiagnostic.getArgs().length != 0 + && jcDiagnostic.getArgs()[0] instanceof JCDiagnostic argDiagnostic) { + return Stream.of(argDiagnostic.getArgs()) // + .map(Object::toString) // + .toArray(String[]::new); + } + + return Stream.of(jcDiagnostic.getArgs()) // + .map(Object::toString) // + .toArray(String[]::new); + } + // compiler.err.prob.found.req -> TypeMismatch, ReturnTypeMismatch, IllegalCast, VoidMethodReturnsValue... private int convertTypeMismatch(Diagnostic diagnostic) { Diagnostic diagnosticArg = getDiagnosticArgumentByType(diagnostic, Diagnostic.class);