Issue
I'm in the process of creating exercises in how to write a plug-in to a system integration tool. We will have the correct answers implemented for demonstration after exercises, but the students will receive source where some methods are empty and just have a comment with a TODO in them describing what they should do.
To avoid duplication, it would be nice if the students' versions could be generated from the compilable and correct answer source-files. It struck me that the Java Annotation Processing Tool (that APT, not the debian APT) could possibly be used to generate the exercises, to have APT spit out methods as empty if the input method carries an annotation to do so.
Is this possible to do using APT? If so, how would one do it?
Are there better/easier ways to avoid having duplication, to generate the exercises and correct answers from a single source, that I am overlooking?
Solution
I'm not sure APT can do this as you'd need access to the source code to spit out the results.
You're probably better off with a simple program that recognises methods prefixed by the annotation and replaces the contents of the methods opening and closing braces with a place holder for the students.
An alternative and probably a simpler mechanism would be to use a custom comment to mark the replaceable areas and then just process this file to get the results. E.g.
public class SomeClass {
public SomeClass() {
// real code here
}
public void someMethod() {
//EXERCISE:START
System.out("put some real compilable code here, "+
"that students will have to implement themselves");
//EXERCISE:END
}
}
You can then just do a simple bit of code to remove the comments and the content between them.
Answered By - BenM Answer Checked By - Mildred Charles (WPSolving Admin)