|
Home
PresentationJeneral is a pure-Java class templates framework, that uses annotations processors. The project is still in its early research phase. Feel free to contribute any comment / suggestion through the issues tab. It aims at bridging the gap between Java's poor type-erasure generics and more powerful abstraction syntaxes found in other languages, such as C#'s generics or C++'s templates. Jeneral may be used to create :
All this is done through an unified syntax with the same template class. A template class is a real pure-Java class, hence easily refactorable and with full support from IDEs such as Eclipse and Netbeans. It also features some goodies such as a @Property annotation (generates getters and / or setters and / or initialization in constructors) or @ImplementMissingMembers (to avoid having to write all those dummy methods some interfaces feature when you only need to implement a single one). Why this name ?Jeneral lets Java programmers write generic abstractions that generate files (makes code genera(liza)tion easier :-D) Simple Meaningful Exampleimport com.ochafik.lang.jeneral.*;
import com.ochafik.lang.jeneral.annotations.*;
import javax.swing.JLabel;
// Declare that ElementsBuild is a template.
// It has to be abstract and to implement ElementsBuilder_Template, which is autogenerated on the fly in Eclipse, NetBeans or with the apt tool in Sun's JDK
@Template
public abstract class ElementsBuilder<T> implements ElementsBuilder_Template<T> {
// Trigger generation of getters and setters for the 'arg' property, and append it to all ElementBuilder's factory methods
@Property(fromConstructor = true)
String arg;
// Declare that T must have a constructor T(String) that throws no checked exception, and that it should be accessible as a new_T method :
@ParamConstructor
abstract T new_T(String arg);
public T buildElement() {
return new_T(getArg());
}
public static void main(String[] args) {
// There is one newInstance method for each public constructor of the template class
// Each newInstance method has the following arguments :
// - classes of generic template parameter
// - constant template parameters, if any (here Test has no constant template parameter)
// - arguments of the constructor that corresponds to this newInstance method (here String arg, which was added implicitely to the unique Test() constructor by the @Property(fromConstructor = true) annotation)
ElementsBuilder<JLabel> labelBuilder = ElementsBuilder_Template.Factory.newInstance(JLabel.class, "Default Label Text");
System.out.println(labelBuilder.buildElement());
}
}CreditsJeneral would be nothing without the amazing Spoon library, which it needs to work. Make sure you read the License page for more information. |