TypeWriter 1.02
Component which makes the writing of java sources easier
This component is a convinient way for writing java class files from another java application. It takes care of basic things like formatting, imports, ordering and has methods to easily methods, innerclasses and such in the javafile.
It also supplies an easy way to write the class file to file and packages
This version is pretty basic and does not enforce a lot of rules, it can check for reserved words, but does not do that automatically yet and imports are only partially handled automatically.
More rules about valid Java files will be added in future versions. To keep this component handy to write classes simultaniously the limit for this project will be that it will not expect classes used in the file to be compiled or available in the classpath in writing other classes which might depend on it. All other additions to thightening the rules will be welcome.
usage
A small example on how to use Typewriter: This creates a class with accessors for id and name and a Constructor and wites it to the temp directory, creating the required folders for the package if they do not exist.
ClassTemplate ct=new ClassTemplate("org.brains2b.test","MyClass",null,null);
//add a comment
ct.createComment().addText("This is a TypeWriter test Class");
//add members
ct.createMember("int","id",new Literal("0"));
ct.createMember("String","name");
//add a constructor
MethodTemplate cons=ct.createConstructor(
new String[][]{{"int","String"},{"id","name"}});
cons.addText("setId(id);");
cons.addText("this.name=name;");
//add methods
MethodTemplate m=ct.createMethod("setName",new String[]{"String"});
m.addText("name=arg0;");
MethodTemplate m_id=ct.createMethod("getId","int",null);
m_id.addText("return id;");
// the short form
ct.createMethod("getName","String",null).addText("return name;");
MethodTemplate m_sid=ct.createMethod(
Modifier.PROTECTED,"setId",null,new String[][]{{"int"},{"id"}});
m_sid.addText("this.id=id;");
try {
ct.writeClass(System.getProperty("java.io.tmpdir"));
} catch (IOException iex) {
Logger.printException(iex);
}
For more information you can look at the javadoc and the Unit tests included in the source
language
java jdk 8+
dependencies
references
- Sql2Class 1.05+
- Babel 1.06+
files
| Name | Version | Date | binary | tar | source |
|---|---|---|---|---|---|
| TypeWriter | 1.02 | May 3, 2024 | TypeWriter-1.02.zip | TypeWriter-1.02.tar.gz | TypeWriter-src-1.02.zip |
changelog
1.02
- All class names have to be supplied as Strings, while passing the class names as Classes suggests the classes should be in the classpath while writing it. Which is not the case
- Added support for finally, static and synchronized blocks
- Fixed small problem with writing Literals
0.20
- Added javadoc and unit tests for all classes
- Fixed Literal which was used the other way around, all non-literal Strings required Literal
- Some minor bugfixing in formatting
0.10
- First creation as independent product