Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo first quickfixes #17

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.40.13-BOOT2</version>
<version>0.40.16</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Set;
import String;

import util::Reflective;
import util::IDEServices;

// ---- Utilities -------------------------------------------------------------

Expand Down Expand Up @@ -327,20 +328,25 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
if(decl is abstract){
if("javaClass" in tagsMap){
if("java" notin modifiers){
c.report(warning(decl.signature, "Missing modifier `java`"));
c.report(warning(decl.signature, "Missing modifier `java`", fixes=[addJavaModifier(decl)]));
}
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){
c.report(warning(decl.signature, "Redundant tag `javaClass`"));
c.report(warning(decl.signature, "Redundant tag `javaClass`", fixes=[removeJavaClass(decl)]));
}
if("java" in modifiers){
c.report(warning(decl.signature, "Redundant modifier `java`"));
c.report(warning(decl.signature, "Redundant modifier `java`", fixes=[removeJavaModifier(decl)]));
}
}

Expand Down Expand Up @@ -731,4 +737,29 @@ void collect (current: (Declaration) `<Tags tags> <Visibility visibility> alias
endUseTypeParameters(c);


}
}

/* Here are some quickfixes used above */

CodeAction addJavaModifier(FunctionDeclaration decl) = action(
title="add `java` modifier",
edits=[changed([insertBefore(decl.signature.modifiers@\loc, "java")])]
);

CodeAction removeJavaModifier(FunctionDeclaration decl) = action(
title="remove `java` modifier",
edits=[changed([delete(l@\loc) | /l:(FunctionModifier) `java` := decl])]
);

CodeAction removeJavaClass(FunctionDeclaration decl) = action(
title="remove <l>",
edits=[changed([delete(l@\loc) | /l:(Tag) `@javaClass<TagString _>` := decl])]
);

list[CodeAction] javaClassProposals(FunctionDeclaration decl) = [
action(
title="add missing <a>",
edits=[changed([insertBefore(decl.tags@\loc, "<a>", separator="\n")])]
)
| str a <- sort({"<t>" | /t:(Tag) `@javaClass<TagString _>` := parseModule(decl@\loc.top)})
];
Loading