From cc59bccbad21989b72191e9bdf422559a1e8c23c Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 4 Nov 2024 12:10:08 +0100 Subject: [PATCH] fixes --- .../rascalcore/check/CollectDeclaration.rsc | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc index 0cb58ba2..9746fa4b 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc @@ -326,8 +326,13 @@ void collect(current: (FunctionDeclaration) ``, Collec if("test" in modifiers){ c.report(warning(decl.signature, "Modifier `test` cannot be used for Java functions")); } - } else { - c.report(warning(decl, "Empty function body")); + } + else if ("java" in modifiers && "javaClass" notin tagsMap) { + c.report(warning(decl.signature, "Missing @javaClass tag with Java function"), fixes=javaClassProposals(decl)); + } + else { + c.report(warning(decl, "Empty function body, without a `java` modifier or @javaClass tag."), + fixes=[addJavaModifier(decl), *javaClassProposals(decl)]); } } else { if("javaClass" in tagsMap){ @@ -733,15 +738,20 @@ void collect (current: (Declaration) ` alias CodeAction addJavaModifier(FunctionDeclaration decl) = action( title="add `java` modifier", - edits=[changed(decl.top, [replace(decl.signature.modifiers@\loc, "java ")])] + edits=[changed(decl@\loc.top, [replace(decl.signature.modifiers@\loc, "java ")])] ); CodeAction removeJavaModifier(FunctionDeclaration decl) = action( title="remove `java` modifier", - edits=[changed(decl.top, [replace(l@\loc, "") | /l:(FunctionModifier) `java` := decl])] + edits=[changed(decl@\loc.top, [replace(l@\loc, "") | /l:(FunctionModifier) `java` := decl])] ); CodeAction removeJavaClass(FunctionDeclaration decl) = action( title="remove @javaClass tag", - edits=[changed(decl.top, [replace(l@\loc, "") | /l:(Tag) `@javaClass` := decl])] -); \ No newline at end of file + edits=[changed(decl@\loc.top, [replace(l@\loc, "") | /l:(Tag) `@javaClass` := decl])] +); + +list[CodeAction] javaClassProposals(FunctionDeclaration decl) = [ + action(title="add missing ", edits=[replace(decl.tags@\loc.top(decl.tags@\loc.offset, 0), "\n")]) + | /t:(Tag) `@javaClass` := parseModule(decl@\loc.top) +]; \ No newline at end of file