Brains2b.ORG |
|
TypeWriter 1.02
|
stable
|
component
|
Component which makes the writing of java sources easier |
Full description
|
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.
|
Files |
name | date | zip | zip (source) | tar.gz | tar.gz (source) |
TypeWriter 1.02 | 30-07-2007 | TypeWriter-1.02.zip | TypeWriter-src-1.02.zip | TypeWriter-0.20.tar.gz | TypeWriter-src-1.02.tar.gz |
TypeWriter 0.20 | 27-08-2004 | TypeWriter-0.20.zip | | TypeWriter-0.20.tar.gz | |
Note: If you want to make a quick start download the .zip or .tar.gz file.
It includes the compiled jar and possible dependencies. The sources contains the sources for this specific project and the compiled libraries listed as dependencies.
|
Dependencies
|
language:
| java 1.4+ |
Using TypeWriter
|
How to use
|
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
|
Reference implementation/examples
|
|
releases
|
TypeWriter 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
- Some internal changes from the Waldorf code review
|
TypeWriter 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
|
TypeWriter 0.10
|
- First creation as independent product
|
|
|