Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private ReloadableJava11Parser(
// https://docs.oracle.com/en/java/javacard/3.1/guide/setting-java-compiler-options.html
Options.instance(context).put("-g", "-g");
Options.instance(context).put("-proc", "none");
Options.instance(context).put("-parameters", "true");

// Ensure type attribution continues despite errors in individual files or nodes.
// If an error occurs in a single file or node, type attribution should still proceed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public J visitClass(ClassTree node, Space fmt) {

List<Tree> membersMultiVariablesSeparated = new ArrayList<>(node.getMembers().size());
for (Tree m : node.getMembers()) {
// skip lomobok generated trees
// skip lombok generated trees
if (isLombokGenerated(m)) {
continue;
}
Expand Down Expand Up @@ -1938,7 +1938,6 @@ private static boolean isLombokGenerated(Tree t) {
Tree tree = (t instanceof JCAnnotation) ? ((JCAnnotation) t).getAnnotationType() : t;

Symbol sym = extractSymbol(tree);

if (sym == null) {
// not a symbol we can check
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private ReloadableJava17Parser(
// https://docs.oracle.com/en/java/javacard/3.1/guide/setting-java-compiler-options.html
Options.instance(context).put("-g", "-g");
Options.instance(context).put("-proc", "none");
Options.instance(context).put("-parameters", "true");

// Ensure type attribution continues despite errors in individual files or nodes.
// If an error occurs in a single file or node, type attribution should still proceed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private ReloadableJava21Parser(
// https://docs.oracle.com/en/java/javacard/3.1/guide/setting-java-compiler-options.html
Options.instance(context).put("-g", "-g");
Options.instance(context).put("-proc", "none");
Options.instance(context).put("-parameters", "true");

// Ensure type attribution continues despite errors in individual files or nodes.
// If an error occurs in a single file or node, type attribution should still proceed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ReloadableJava8Parser implements JavaParser {
// https://docs.oracle.com/en/java/javacard/3.1/guide/setting-java-compiler-options.html
Options.instance(context).put("-g", "-g");
Options.instance(context).put("-proc", "none");
Options.instance(context).put("-parameters", "true");

// Ensure type attribution continues despite errors in individual files or nodes.
// If an error occurs in a single file or node, type attribution should still proceed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ public J visitCompilationUnit(CompilationUnitTree node, Space fmt) {
packageDecl = new J.Package(randomId(), packagePrefix, Markers.EMPTY,
convert(cu.getPackageName()), packageAnnotations);
}

return new J.CompilationUnit(
randomId(),
fmt,
Expand Down Expand Up @@ -912,10 +911,11 @@ public J visitMethodInvocation(MethodInvocationTree node, Space fmt) {
singletonList(padRight(new J.Empty(randomId(), sourceBefore(")"), Markers.EMPTY), EMPTY)) :
convertAll(node.getArguments(), commaDelim, t -> sourceBefore(")")), Markers.EMPTY);

Symbol genericSymbol = (jcSelect instanceof JCFieldAccess) ? ((JCFieldAccess) jcSelect).sym : ((JCIdent) jcSelect).sym;
Symbol methodSymbol = (jcSelect instanceof JCFieldAccess) ? ((JCFieldAccess) jcSelect).sym :
((JCIdent) jcSelect).sym;

return new J.MethodInvocation(randomId(), fmt, Markers.EMPTY, select, typeParams, name, args,
typeMapping.methodInvocationType(jcSelect.type, genericSymbol));
typeMapping.methodInvocationType(jcSelect.type, methodSymbol));
}

@Override
Expand Down Expand Up @@ -1701,9 +1701,6 @@ private boolean isEnum(Tree t) {
}

private <J2 extends @Nullable J> @Nullable JRightPadded<J2> convert(@Nullable Tree t, Function<Tree, Space> suffix) {
if (t == null) {
return null;
}
return convert(t, suffix, j -> Markers.EMPTY);
}

Expand Down Expand Up @@ -1942,9 +1939,9 @@ private static boolean isLombokGenerated(Tree t) {
}

return isLombokAnnotationType(sym.getQualifiedName().toString()) ||
sym.getDeclarationAttributes().stream()
.map(c -> c.type.toString())
.anyMatch(ReloadableJava8ParserVisitor::isLombokAnnotationType);
sym.getDeclarationAttributes().stream()
.map(a -> a.type.toString())
.anyMatch(ReloadableJava8ParserVisitor::isLombokAnnotationType);
}

private static boolean isLombokAnnotationType(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

import org.junit.jupiter.api.Test;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Issue;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.MinimumJava11;
import org.openrewrite.test.RewriteTest;

import java.util.Optional;
Expand Down Expand Up @@ -132,4 +135,28 @@ void m() {
)
);
}

@Issue("https://github.com/openrewrite/rewrite/issues/5400") // Fails on Java 8, but passes on Java 11 and later
@MinimumJava11
@Test
void methodParameterNamesPresent() {
rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().classpath("assertj-core")),
java(
"""
import static org.assertj.core.api.Assertions.assertThat;
class Regular {
void method(String exp, String act) {
assertThat(act).isEqualTo(exp);
}
}
""",
spec -> spec.beforeRecipe(cu -> {
J.MethodDeclaration md = (J.MethodDeclaration) cu.getClasses().get(0).getBody().getStatements().get(0);
J.MethodInvocation mi = (J.MethodInvocation) md.getBody().getStatements().get(0);
assertThat(mi.getMethodType().getParameterNames()).containsExactly("expected");
})
)
);
}
}
Loading