Author: tchemit
Date: 2009-02-10 21:41:49 +0000 (Tue, 10 Feb 2009)
New Revision: 1217
Modified:
jaxx/trunk/jaxx-compiler-api/changelog.txt
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JavaFile.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultObjectHandler.java
Log:
can now generate abstract and generic classes
Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-02-09 02:29:01 UTC (rev 1216)
+++ jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-02-10 21:41:49 UTC (rev 1217)
@@ -1,4 +1,5 @@
1.1 chemit 200901??
+ * 20090202 [chemit] - can now generate abstract and generic classes
* 20090202 [chemit] - introduce a property validatorFQN in CompilerOptions to specify the validator implementation
* 20090124 [chemit] - introduce a flag useUIManagerForIcon to retreave icons from UIManager
* 20090123 [chemit] - cache the lineSeparator property in JAXXCompiler
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java 2009-02-09 02:29:01 UTC (rev 1216)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java 2009-02-10 21:41:49 UTC (rev 1217)
@@ -171,6 +171,15 @@
/** extra interfaces which can by passed to root object via the 'implements' attribute */
private String[] extraInterfaces;
+ /** a flag to generate a abstract class */
+ private boolean abstractClass;
+
+ /** the possible generic type of the class */
+ private String genericType;
+
+ /** thepossible generic type of the super class */
+ private String superGenericType;
+
/** Extra code to be added to the instance initializer. */
protected StringBuffer initializer = new StringBuffer();
@@ -1255,6 +1264,30 @@
return extraInterfaces;
}
+ public boolean isAbstractClass() {
+ return abstractClass;
+ }
+
+ public void setAbstractClass(boolean abstractClass) {
+ this.abstractClass = abstractClass;
+ }
+
+ public String getGenericType() {
+ return genericType;
+ }
+
+ public void setGenericType(String genericType) {
+ this.genericType = genericType;
+ }
+
+ public String getSuperGenericType() {
+ return superGenericType;
+ }
+
+ public void setSuperGenericType(String superGenericType) {
+ this.superGenericType = superGenericType;
+ }
+
public void addSimpleField(JavaField javaField) {
getJavaFile().addSimpleField(javaField);
}
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java 2009-02-09 02:29:01 UTC (rev 1216)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java 2009-02-10 21:41:49 UTC (rev 1217)
@@ -141,10 +141,10 @@
javaFile.setSuperClass(JAXXCompiler.getCanonicalName(superclass));
javaFile.setSuperclassIsJAXXObject(superclassIsJAXXObject);
- // can have extra interfaces from compiler
- if (compiler.getExtraInterfaces() != null) {
- javaFile.addInterfaces(java.util.Arrays.asList(compiler.getExtraInterfaces()));
- }
+ javaFile.addInterfaces(compiler.getExtraInterfaces());
+ javaFile.setAbstractClass(compiler.isAbstractClass());
+ javaFile.setGenericType(compiler.getGenericType());
+ javaFile.setSuperGenericType(compiler.getSuperGenericType());
for (CompiledObject object : compiler.getObjects().values()) {
if (!object.isOverride() && !(object instanceof ScriptInitializer)) {
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JavaFile.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JavaFile.java 2009-02-09 02:29:01 UTC (rev 1216)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JavaFile.java 2009-02-10 21:41:49 UTC (rev 1217)
@@ -35,6 +35,9 @@
private List<String> interfaces;
private StringBuffer rawBodyCode = new StringBuffer();
private boolean superclassIsJAXXObject;
+ private boolean abstractClass;
+ private String genericType;
+ private String superGenericType;
public JavaFile() {
@@ -110,6 +113,9 @@
this.interfaces = interfaces;
}
+ public void setGenericType(String genericType) {
+ this.genericType = genericType;
+ }
public void addMethod(JavaMethod method) {
methods.add(method);
@@ -245,10 +251,19 @@
public String getClassDefinition(String lineSeparator) {
StringBuffer result = new StringBuffer();
result.append(getModifiersText(modifiers));
+ if (abstractClass) {
+ result.append("abstract ");
+ }
result.append("class ");
result.append(className.substring(className.lastIndexOf(".") + 1));
+ if (genericType != null) {
+ result.append('<').append(genericType).append('>');
+ }
result.append(" extends ");
result.append(superClass);
+ if (superGenericType != null) {
+ result.append('<').append(superGenericType).append('>');
+ }
if (interfaces != null && !interfaces.isEmpty()) {
result.append(" implements ").append(interfaces.get(0));
for (int i = 1; i < interfaces.size(); i++) {
@@ -309,7 +324,10 @@
}
}
- public void addInterfaces(List<String> canonicalNames) {
+ public void addInterfaces(String[] canonicalNames) {
+ if (canonicalNames == null) {
+ return;
+ }
for (String canonicalName : canonicalNames) {
if (interfaces == null || !interfaces.contains(canonicalName)) {
getInterfaces().add(canonicalName);
@@ -324,4 +342,13 @@
public void setSuperclassIsJAXXObject(boolean superclassIsJAXXObject) {
this.superclassIsJAXXObject = superclassIsJAXXObject;
}
+
+ public void setAbstractClass(boolean abstractClass) {
+ this.abstractClass = abstractClass;
+ }
+
+
+ public void setSuperGenericType(String superGenericType) {
+ this.superGenericType = superGenericType;
+ }
}
\ No newline at end of file
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultObjectHandler.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultObjectHandler.java 2009-02-09 02:29:01 UTC (rev 1216)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultObjectHandler.java 2009-02-10 21:41:49 UTC (rev 1217)
@@ -194,7 +194,7 @@
* @return the property's type
* @throws CompilerException if the type cannot be determined
*/
- public ClassDescriptor getPropertyType(CompiledObject object, String propertyName, JAXXCompiler compiler) {
+ public ClassDescriptor getPropertyType(CompiledObject object, String propertyName, JAXXCompiler compiler) {
try {
init();
} catch (IntrospectionException e) {
@@ -287,7 +287,7 @@
* @param compiler the current <code>JAXXCompiler</code>
* @return Java code snippet which causes the listener to be added to the object
*/
- public String getAddMemberListenerCode(String objectCode, String dataBinding, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler) {
+ public String getAddMemberListenerCode(String objectCode, String dataBinding, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler) {
if ("getClass".equals(memberName)) {
return null;
}
@@ -342,7 +342,7 @@
}
- public String getRemoveMemberListenerCode(String objectCode, String dataBinding, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler) {
+ public String getRemoveMemberListenerCode(String objectCode, String dataBinding, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler) {
if ("getClass".equals(memberName)) {
return null;
}
@@ -512,13 +512,13 @@
}
- public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
scanAttributesForDependencies(tag, compiler);
compileChildrenFirstPass(tag, compiler);
}
- public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
try {
init();
} catch (IntrospectionException e) {
@@ -541,7 +541,7 @@
}
- public void registerCompiledObject(Element tag, JAXXCompiler compiler) {
+ public void registerCompiledObject(Element tag, JAXXCompiler compiler) {
String id = tag.getAttribute("id");
if (id == null || id.length() == 0) {
id = compiler.getAutoId(getBeanClass());
@@ -563,7 +563,7 @@
* @param compiler compiler to use
* @return the <code>CompiledObject</code> to use
*/
- protected CompiledObject createCompiledObject(String id, JAXXCompiler compiler) {
+ protected CompiledObject createCompiledObject(String id, JAXXCompiler compiler) {
return new CompiledObject(id, getBeanClass(), compiler);
}
@@ -576,7 +576,7 @@
* @param tag the tag being compiled
* @param compiler the current <code>JAXXCompiler</code>
*/
- protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) {
+ protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) {
}
@@ -610,7 +610,7 @@
* @param tag tag to scan
* @param compiler compiler to use
*/
- protected void scanAttributesForDependencies(Element tag, JAXXCompiler compiler) {
+ protected void scanAttributesForDependencies(Element tag, JAXXCompiler compiler) {
List<Attr> attributes = new ArrayList<Attr>();
NamedNodeMap children = tag.getAttributes();
for (int i = 0; i < children.getLength(); i++) {
@@ -621,7 +621,7 @@
for (Attr attribute : attributes) {
String name = attribute.getName();
String value = attribute.getValue();
- if (name.equals("javaBean")) {
+ if (name.equals("javaBean")) {
continue;
}
if (name.equals("constraints") || isEventHandlerName(name)) {
@@ -647,7 +647,7 @@
* @param tag the tag from which to pull attributes
* @param compiler the current <code>JAXXCompiler</code>
*/
- public void setAttributes(CompiledObject object, Element tag, JAXXCompiler compiler) {
+ public void setAttributes(CompiledObject object, Element tag, JAXXCompiler compiler) {
List<Attr> attributes = new ArrayList<Attr>();
NamedNodeMap children = tag.getAttributes();
for (int i = 0; i < children.getLength(); i++) {
@@ -681,6 +681,36 @@
continue;
}
+ if (name.equals("abstract")) {
+ if (object != compiler.getRootObject()) {
+ // can ony be apply to root object
+ compiler.reportError("'abstract' attribute can only be found on root tag but was found on tag " + tag);
+ return;
+ }
+ compiler.setAbstractClass(true);
+ continue;
+ }
+
+ if (name.equals("genericType")) {
+ if (object != compiler.getRootObject()) {
+ // can ony be apply to root object
+ compiler.reportError("'genericType' attribute can only be found on root tag but was found on tag " + tag);
+ return;
+ }
+ compiler.setGenericType(value);
+ continue;
+ }
+
+ if (name.equals("superGenericType")) {
+ if (object != compiler.getRootObject()) {
+ // can ony be apply to root object
+ compiler.reportError("'superGenericType' attribute can only be found on root tag but was found on tag " + tag);
+ return;
+ }
+ compiler.setSuperGenericType(value);
+ continue;
+ }
+
if (isEventHandlerName(name)) {
// event handler
if (!value.endsWith(";")) {
@@ -728,7 +758,7 @@
}
- public String getApplyPropertyOrDataBindingCode(CompiledObject object, String propertyName, String stringValue, JAXXCompiler compiler) {
+ public String getApplyPropertyOrDataBindingCode(CompiledObject object, String propertyName, String stringValue, JAXXCompiler compiler) {
ClassDescriptor type = getPropertyType(object, propertyName, compiler);
String binding = compiler.processDataBindings(stringValue, type);
if (binding != null) {
@@ -759,7 +789,7 @@
* @param inline <code>true</code> if the value was directly specified as an inline class tag attribute, <code>false</code> otherwise (a default value, specified in CSS, etc.)
* @param compiler the current <code>JAXXCompiler</code>
*/
- public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) {
+ public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) {
try {
if (ClassDescriptorLoader.getClassDescriptor(JAXXObject.class).isAssignableFrom(object.getObjectClass())) {
// check for data binding & remove if found
@@ -866,7 +896,7 @@
object.appendInitializationCode(child.getInitializationCode(compiler));
}
} else if (stylesheet != null) {
- StylesheetHelper.applyTo(object, compiler,stylesheet, overrides);
+ StylesheetHelper.applyTo(object, compiler, stylesheet, overrides);
}
}
catch (ClassNotFoundException e) {
@@ -950,7 +980,7 @@
* @return the snippet
* @throws CompilerException if a compilation error occurs
*/
- public String getSetPropertyCode(String javaCode, String name, String valueCode, JAXXCompiler compiler) {
+ public String getSetPropertyCode(String javaCode, String name, String valueCode, JAXXCompiler compiler) {
JAXXPropertyDescriptor property = properties.get(name);
if (property != null) {
if (property.getWriteMethodDescriptor() != null) {
@@ -977,7 +1007,7 @@
* @param compiler the current <code>JAXXCompiler</code>
* @throws CompilerException if a compilation error occurs
*/
- public void setProperty(CompiledObject object, String name, Object value, JAXXCompiler compiler) {
+ public void setProperty(CompiledObject object, String name, Object value, JAXXCompiler compiler) {
object.appendInitializationCode(getSetPropertyCode(object.getJavaCodeForProperty(name), name, TypeManager.getJavaCode(value), compiler));
}
@@ -1062,7 +1092,7 @@
* @throws CompilerException if a compilation error occurs
* @throws IOException if an I/O error occurs
*/
- protected void compileChildrenFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ protected void compileChildrenFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
NodeList children = tag.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
@@ -1084,7 +1114,7 @@
* @throws CompilerException if a compilation error occurs
* @throws IOException if an I/O error occurs
*/
- protected void compileChildrenSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ protected void compileChildrenSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
NodeList children = tag.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
@@ -1111,7 +1141,7 @@
* @throws CompilerException if a compilation error occurs
* @throws IOException if an I/O error occurs
*/
- protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
compiler.compileFirstPass(tag);
}
@@ -1125,7 +1155,7 @@
* @throws CompilerException if a compilation error occurs
* @throws IOException if an I/O error occurs
*/
- protected void compileChildTagSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ protected void compileChildTagSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
compiler.compileSecondPass(tag);
}