Jaxx-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
July 2009
- 3 participants
- 68 discussions
[Buix-commits] r1544 - trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
30 Jul '09
Author: kmorin
Date: 2009-07-30 17:00:19 +0200 (Thu, 30 Jul 2009)
New Revision: 1544
Modified:
trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/Controller.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
Log:
update the example files with the new feature
Modified: trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/Controller.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/Controller.java 2009-07-30 14:59:58 UTC (rev 1543)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/Controller.java 2009-07-30 15:00:19 UTC (rev 1544)
@@ -1,3 +1,21 @@
+/**
+ * *##% guix-test-swing
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
package org.nuiton.guix.demo;
public class Controller {
@@ -2,6 +20,28 @@
+ private java.lang.String text = "controller";
+ private int num = 0;
+
public Controller() {
System.out.println("Dude, it's bloody raining");
}
+ public void test() {
+
+ }
+
+ public java.lang.String getText() {
+ return text;
+ }
+
+ public void setText(java.lang.String text) {
+ this.text = text;
+ }
+
+ public int getNum() {
+ return num;
+ }
+
+ public void setNum(int num) {
+ this.num = num;
+ }
}
Modified: trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.guix 2009-07-30 14:59:58 UTC (rev 1543)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.guix 2009-07-30 15:00:19 UTC (rev 1544)
@@ -41,7 +41,9 @@
}
]]></script>
- <java.util.ArrayList id="controller" />
+ <java.util.ArrayList id="list" />
+ <org.nuiton.guix.demo.Controller id="c1" text="c1" />
+ <org.nuiton.guix.demo.Controller id="c2" num="10" />
<MenuBar border="new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED)">
<Menu constructor='"menu 1"'>
<MenuItem id="item1" text="item1" />
@@ -89,9 +91,14 @@
</Row>
<Row>
<Cell columns="3">
- <GuixDemo3 id="bt34" text="bt34" />
+ <Label text="{c1.getText()} : {c1.getNum()}" />
</Cell>
- </Row>
+ </Row>
+ <Row>
+ <Cell columns="3">
+ <Label text="{c2.getText()} : {c2.getNum()}" />
+ </Cell>
+ </Row>
<Row>
<Cell columns="2">
<Label id="label3" text="color" foreground="java.awt.Color.YELLOW" />
1
0
[Buix-commits] r1543 - trunk/maven-guix-plugin/src/main/java/org/nuiton/guix
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
30 Jul '09
Author: kmorin
Date: 2009-07-30 16:59:58 +0200 (Thu, 30 Jul 2009)
New Revision: 1543
Modified:
trunk/maven-guix-plugin/src/main/java/org/nuiton/guix/GuixMojo.java
Log:
add the source directory
Modified: trunk/maven-guix-plugin/src/main/java/org/nuiton/guix/GuixMojo.java
===================================================================
--- trunk/maven-guix-plugin/src/main/java/org/nuiton/guix/GuixMojo.java 2009-07-30 14:59:37 UTC (rev 1542)
+++ trunk/maven-guix-plugin/src/main/java/org/nuiton/guix/GuixMojo.java 2009-07-30 14:59:58 UTC (rev 1543)
@@ -107,6 +107,7 @@
GuixLauncher gcl = new GuixLauncher(guixFiles.toArray(
new File[guixFiles.size()]), targetDirectory, rootPackage,
+ new File(project.getBasedir(), "src/main/java"),
guixFilesDir, mainClass, generatorClass, launcherName);
boolean result = gcl.compile();
if (result) {
1
0
[Buix-commits] r1542 - in trunk/guix-test-gwt/src/main/java/org/nuiton/guix: client demo
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
30 Jul '09
Author: kmorin
Date: 2009-07-30 16:59:37 +0200 (Thu, 30 Jul 2009)
New Revision: 1542
Added:
trunk/guix-test-gwt/src/main/java/org/nuiton/guix/client/Controller.java
Modified:
trunk/guix-test-gwt/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
Log:
update the example files with the new feature
Added: trunk/guix-test-gwt/src/main/java/org/nuiton/guix/client/Controller.java
===================================================================
--- trunk/guix-test-gwt/src/main/java/org/nuiton/guix/client/Controller.java (rev 0)
+++ trunk/guix-test-gwt/src/main/java/org/nuiton/guix/client/Controller.java 2009-07-30 14:59:37 UTC (rev 1542)
@@ -0,0 +1,48 @@
+/**
+ * *##% guix-test-swing
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.guix.client;
+
+public class Controller {
+
+ private java.lang.String text = "controller";
+ private int num = 0;
+
+ public Controller() {
+ System.out.println("Dude, it's bloody raining");
+ }
+
+ public void test() {
+ }
+
+ public java.lang.String getText() {
+ return text;
+ }
+
+ public void setText(java.lang.String text) {
+ this.text = text;
+ }
+
+ public int getNum() {
+ return num;
+ }
+
+ public void setNum(int num) {
+ this.num = num;
+ }
+}
Modified: trunk/guix-test-gwt/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
===================================================================
--- trunk/guix-test-gwt/src/main/java/org/nuiton/guix/demo/GuixDemo.guix 2009-07-30 14:59:12 UTC (rev 1541)
+++ trunk/guix-test-gwt/src/main/java/org/nuiton/guix/demo/GuixDemo.guix 2009-07-30 14:59:37 UTC (rev 1542)
@@ -46,6 +46,9 @@
}
]]></script>
+
+ <org.nuiton.guix.client.Controller id="c1" text="c1" />
+ <org.nuiton.guix.client.Controller id="c2" num="10" />
<MenuBar>
<Menu text="menu 1">
<MenuItem id="item1" text="item11" action='cmd' />
@@ -59,6 +62,7 @@
</Menu>
</Menu>
</MenuBar>
+ <java.util.ArrayList id="list" />
<TabPanel size='800px","400px'>
<Table id="table1" name="Table">
<Row>
@@ -67,7 +71,7 @@
<TextField id="textfield" text='test' enabled="{gd2.getButton().down && gd22.button.isSelected()}" onFocus='{System.out.println("dude !")}'/>
</Cell>
<Cell>
- <Label id="label" text="{textfield.getText()}" styleClass="bold" />
+ <Label id="label" visible="{textfield.enabled}" text="{textfield.getText()}" styleClass="bold" />
</Cell>
<Cell rows='3'>
<Label id="label2" text="color" style="color: yellow" />
@@ -75,7 +79,7 @@
</Row>
<Row insets="0,0,0,0">
<Cell columns="3">
- <GuixDemo3 id="bt3" text="bt3" onClick='{System.out.println("beau gosse")}'/>
+ <GuixDemo3 id="bt3" text="bt3" onClick='{System.out.println("beau gosse");list.add("test" + list.size())}'/>
</Cell>
</Row>
<Row insets="0,0,0,0">
@@ -88,12 +92,17 @@
</Row>
<Row>
<Cell columns="3">
- <GuixDemo3 id="bt34" text="bt34" />
+ <Label text="{c1.getText()} : {c1.getNum()}" />
</Cell>
- </Row>
+ </Row>
+ <Row>
+ <Cell columns="3">
+ <Label text="{c2.getText()} : {c2.getNum()}" />
+ </Cell>
+ </Row>
<Row>
<Cell columns="2">
- <Label id="label3" text="color" style="color: yellow" />
+ <Label id="label3" text="list size : {list.size()}" style="color: yellow" />
</Cell>
</Row>
</Table>
1
0
[Buix-commits] r1541 - in trunk/guix-compiler-swing/src: main/java/org/nuiton/guix/generator test/java/org/nuiton/guix/generator
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
30 Jul '09
Author: kmorin
Date: 2009-07-30 16:59:12 +0200 (Thu, 30 Jul 2009)
New Revision: 1541
Modified:
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingAbstractClassGenerator.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java
trunk/guix-compiler-swing/src/test/java/org/nuiton/guix/generator/SwingGeneratorTest.java
Log:
Add the acceptation for tags that represents classes defined in the src directory
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingAbstractClassGenerator.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingAbstractClassGenerator.java 2009-07-30 14:59:00 UTC (rev 1540)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingAbstractClassGenerator.java 2009-07-30 14:59:12 UTC (rev 1541)
@@ -20,6 +20,10 @@
//~--- non-JDK imports --------------------------------------------------------
import java.beans.IntrospectionException;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.io.Reader;
import org.nuiton.guix.tags.swing.MenuBarHandler;
;
import org.nuiton.guix.model.GuixModelObject;
@@ -62,6 +66,8 @@
/** Bindings to generate */
Map<String,Map<String, String>> bindings2Generate = new HashMap<String,Map<String, String>>();
+ SwingGenerator swingGenerator;
+
/**
* Constructor
*
@@ -80,6 +86,10 @@
script = sh.decomposeScript(gmo.getClassDescriptor().getScript());
}
+ public void setSwingGenerator(SwingGenerator swingGenerator) {
+ this.swingGenerator = swingGenerator;
+ }
+
@Override
public JavaFile generate() {
super.addImports(gmo);
@@ -331,92 +341,101 @@
}
//if the class hasn't been found
if (clazz == null) {
- File f = new File(gmo.getClassDescriptor().toString().replace('.', File.separatorChar));
- if(f.exists()) {
-
+ File f = new File(swingGenerator.getSrcDir(), gmo.getClassDescriptor().toString().replace('.', File.separatorChar) + ".java");
+ try {
+ Reader isr = new InputStreamReader(new FileInputStream(f));
+ JavaFile jFile = JavaFileParser.parseJavaFile(gmo.getClassDescriptor().toString(), isr);
+ jf.addField(new JavaField(Modifier.PRIVATE, gmo.getClassDescriptor().toString(), gmo.getId(), gmo.getJavadoc()), true);
+ StringBuffer creationMethod = new StringBuffer();
+ String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
+ creationMethod.append(gmo.getId()).append(" = new ").append(gmo.getClassDescriptor().toString()).append("(").append(gmo.getConstructor() != null ? gmo.getConstructor() : "").append(");\n");
+ componentsCreation.append("create").append(capitalizedId).append("();\n");
+ processAttributes(jFile, gmo, creationMethod);
}
- else {
+ catch (FileNotFoundException eee) {
+ log.error(eee);
throw new ClassNotFoundException();
}
}
-
- //if gmo has a TagHandler, add a field to the JavaFile with this TagHandler (used for the databinding generation)
- if(gmo.getClassDescriptor().getPackageName() == null
- && th != null && th.getClassToGenerate() != null) {
- jf.addField(new JavaField(Modifier.PRIVATE,
- clazz.getName(),
- gmo.getId(), gmo.getJavadoc(), th),
- true);
- }
- //if gmo is the root ModelObject, it equals "this"
- else if(gmo.getId() == null) {
- jf.addField(new JavaField(Modifier.PRIVATE,
- (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().toString() + "Abstract" : gmo.getClassDescriptor().toString(),
- gmo.getClassDescriptor().getName().toLowerCase(), "this", gmo.getJavadoc(), th),
- true);
- }
else {
- jf.addField(new JavaField(Modifier.PRIVATE,
- (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().toString() + "Abstract" : gmo.getClassDescriptor().toString(),
- gmo.getId(), gmo.getJavadoc(), th),
- true);
- }
+ //if gmo has a TagHandler, add a field to the JavaFile with this TagHandler (used for the databinding generation)
+ if(gmo.getClassDescriptor().getPackageName() == null
+ && th != null && th.getClassToGenerate() != null) {
+ jf.addField(new JavaField(Modifier.PRIVATE,
+ clazz.getName(),
+ gmo.getId(), gmo.getJavadoc(), th),
+ true);
+ }
+ //if gmo is the root ModelObject, it equals "this"
+ else if(gmo.getId() == null) {
+ jf.addField(new JavaField(Modifier.PRIVATE,
+ (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().toString() + "Abstract" : gmo.getClassDescriptor().toString(),
+ gmo.getClassDescriptor().getName().toLowerCase(), "this", gmo.getJavadoc(), th),
+ true);
+ }
+ else {
+ jf.addField(new JavaField(Modifier.PRIVATE,
+ (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().toString() + "Abstract" : gmo.getClassDescriptor().toString(),
+ gmo.getId(), gmo.getJavadoc(), th),
+ true);
+ }
- //if gmo does not represents the first tag
- if (gmo.getParent() != null) {
- //id with the first letter capitalized
- String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
- StringBuffer creationMethod = new StringBuffer();
- creationMethod.append(gmo.getId()).append(" = new ").append(classes.contains(gmo.getClassDescriptor().toString()) ? gmo.getClassDescriptor().toString() + "Impl" : clazz.getName()).append("(").append(gmo.getConstructor() != null ? gmo.getConstructor() : "").append(");\n");
- componentsCreation.append("create").append(capitalizedId).append("();\n");
+ //if gmo does not represents the first tag
+ if (gmo.getParent() != null) {
+ //id with the first letter capitalized
+ String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
+ StringBuffer creationMethod = new StringBuffer();
+ creationMethod.append(gmo.getId()).append(" = new ").append(classes.contains(gmo.getClassDescriptor().toString()) ? gmo.getClassDescriptor().toString() + "Impl" : clazz.getName()).append("(").append(gmo.getConstructor() != null ? gmo.getConstructor() : "").append(");\n");
+ componentsCreation.append("create").append(capitalizedId).append("();\n");
- //FIXME
- if (gmo.getStyleSheets() != null) {
- styleSheets.addAll(gmo.getStyleSheets());
- }
-
- constraint = processAttributes(clazz, gmo, creationMethod, null, seh, null, th);
+ //FIXME
+ if (gmo.getStyleSheets() != null) {
+ styleSheets.addAll(gmo.getStyleSheets());
+ }
- //if gmo is the child of a cell
- if (!((gmo.getParent().getClassDescriptor().getPackageName() == null || gmo.getParent().getClassDescriptor().getPackageName().equals("org.nuiton.guix.tags.swing")) && gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("Cell"))) {
- //if gmo represents a JMenuBar
- if (gmo.getClassDescriptor().toString().equals("javax.swing.JMenuBar")) {
- //the method to add a JMenuBar is not add but setJMenuBar
- componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".setJMenuBar(").append(gmo.getId()).append(");\n");
- }
- else {
- //add the component to its parent
- if(java.awt.Component.class.isAssignableFrom(clazz)) {
- componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId());
- //with a constraint if it is not null
- if (constraint != null) {
- componentsTree.append(",").append(constraint);
+ constraint = processAttributes(clazz, gmo, creationMethod, null, seh, null, th);
+
+ //if gmo is the child of a cell
+ if (!((gmo.getParent().getClassDescriptor().getPackageName() == null || gmo.getParent().getClassDescriptor().getPackageName().equals("org.nuiton.guix.tags.swing")) && gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("Cell"))) {
+ //if gmo represents a JMenuBar
+ if (gmo.getClassDescriptor().toString().equals("javax.swing.JMenuBar")) {
+ //the method to add a JMenuBar is not add but setJMenuBar
+ componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".setJMenuBar(").append(gmo.getId()).append(");\n");
+ }
+ else {
+ //add the component to its parent
+ if(java.awt.Component.class.isAssignableFrom(clazz)) {
+ componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId());
+ //with a constraint if it is not null
+ if (constraint != null) {
+ componentsTree.append(",").append(constraint);
+ }
+ componentsTree.append(");\n");
}
- componentsTree.append(");\n");
}
}
- }
- }
- //if gmo represents the first tag
- else {
- boolean layoutDefined = false;
- //set superclass and interface
- if(th != null) {
- jf.setSuperClass(th.getClassToGenerate().getName());
}
+ //if gmo represents the first tag
else {
- jf.setSuperClass(gmo.getClassDescriptor().getSuperClass().getPackageName() + "." + gmo.getClassDescriptor().getSuperClass().getName());
- }
- jf.addInterface(gmo.getClassDescriptor().getName());
+ boolean layoutDefined = false;
+ //set superclass and interface
+ if(th != null) {
+ jf.setSuperClass(th.getClassToGenerate().getName());
+ }
+ else {
+ jf.setSuperClass(gmo.getClassDescriptor().getSuperClass().getPackageName() + "." + gmo.getClassDescriptor().getSuperClass().getName());
+ }
+ jf.addInterface(gmo.getClassDescriptor().getName());
- //FIXME
- if (gmo.getStyleSheets() != null) {
- styleSheets.addAll(gmo.getStyleSheets());
+ //FIXME
+ if (gmo.getStyleSheets() != null) {
+ styleSheets.addAll(gmo.getStyleSheets());
+ }
+
+ constraint = processAttributes(clazz, gmo, null, componentsTree, seh, layoutDefined, th);
}
-
- constraint = processAttributes(clazz, gmo, null, componentsTree, seh, layoutDefined, th);
}
//browse the children of gmo
for (GuixModelObject child : gmo.getChildren()) {
@@ -483,7 +502,7 @@
m++;
}
//if yes
- if(m < methods.length) {
+ if(m < methods.length) {
//if the attribute binds the value of another component attribute
if (binding != null) {
if(!bindings2Generate.containsKey(gmo.getId())) {
@@ -491,14 +510,17 @@
}
bindings2Generate.get(gmo.getId()).put(attr.getName(), binding);
}
- else { //checks if the parameter of the setter is a String
+ else {
+ //checks if the parameter of the setter is a String
addQuote = methods[m].getParameterTypes()[0].equals(String.class);
//generates the code to set the attribute to object
- if(creationMethod != null)
+ if(creationMethod != null) {
creationMethod.append(gmo.getId()).append(".set").append(capitalizedAttribute).append("(").append(addQuote ? "\"" : "").append(attr.getValue()).append(addQuote ? "\"" : "").append(");\n");
+ }
//generates the code to set the attribute of the class
- if(componentsTree != null)
+ if(componentsTree != null) {
componentsTree.append("this.set").append(capitalizedAttribute).append("(").append(addQuote ? "\"" : "").append(attr.getValue()).append(addQuote ? "\"" : "").append(");\n");
+ }
//if the attribute name is layout
if (layoutDefined != null && attr.getName().equals("layout")) {
layoutDefined = true;
@@ -536,6 +558,57 @@
}
/**
+ *
+ * @param jFile
+ * @param gmo
+ * @param creationMethod
+ */
+ private void processAttributes(JavaFile jFile, GuixModelObject gmo, StringBuffer creationMethod) {
+ //processCSSAttributes(gmo, seh, clazz);
+ //browses the attributes
+ for (AttributeDescriptor attr : gmo.getAttributeDescriptors()) {
+ boolean addQuote = false;
+ //the attribute name with the first letter capitalized
+ String capitalizedAttribute = (attr.getName().length() > 0) ? Character.toUpperCase(attr.getName().charAt(0)) + attr.getName().substring(1) : attr.getName();
+
+ JavaMethod method = null;
+ for(JavaMethod m : jFile.getMethods()) {
+ if(m.getName().equals("set" + capitalizedAttribute)) {
+ method = m;
+ break;
+ }
+ }
+
+ if(method != null) {
+ String binding = BindingUtils.processDataBindings(attr.getValue());
+ if(binding != null) {
+ if(!bindings2Generate.containsKey(gmo.getId())) {
+ bindings2Generate.put(gmo.getId(), new HashMap<String, String>());
+ }
+ bindings2Generate.get(gmo.getId()).put(attr.getName(), binding);
+ }
+ else {
+ //checks if the parameter of the setter is a String
+ addQuote = method.getArguments()[0].getType().equals(String.class.getName());
+ //generates the code to set the attribute to object
+ creationMethod.append(gmo.getId()).append(".set").append(capitalizedAttribute).append("(").append(addQuote ? "\"" : "").append(attr.getValue()).append(addQuote ? "\"" : "").append(");\n");
+ }
+ }
+ else if(log.isErrorEnabled()) {
+ log.error(attr.getName() + " cannot be set.");
+ }
+ }
+ //if gmo does not represents the first tag
+ if(gmo.getId() != null && creationMethod != null) {
+ //id with the first letter capitalized
+ String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
+
+ //add to the file the creation method for this object
+ jf.addMethod(new JavaMethod(Modifier.PRIVATE, "void", "create" + capitalizedId, null, null, creationMethod.toString(), gmo.getId() + " creation"));
+ }
+ }
+
+ /**
* Transform the css attributes into AttributeDescriptors
*
* @param gmo the GuixModelObject which has got the css attributes
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java 2009-07-30 14:59:00 UTC (rev 1540)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java 2009-07-30 14:59:12 UTC (rev 1541)
@@ -52,9 +52,13 @@
public JavaFile generate() {
try {
String gmoClassName = gmo.getClassDescriptor().getName();
- File out = new File(destDir, gmoClassName + ".java");
- File outAbstract = new File(destDir, gmoClassName + "Abstract.java");
- File outImpl = new File(destDir, gmoClassName + "Impl.java");
+ File outDir = new File(destDir, gmo.getClassDescriptor().getPackageName().replace('.', File.separatorChar));
+ if(!outDir.exists()) {
+ outDir.mkdirs();
+ }
+ File out = new File(outDir, gmoClassName + ".java");
+ File outAbstract = new File(outDir, gmoClassName + "Abstract.java");
+ File outImpl = new File(outDir, gmoClassName + "Impl.java");
if (lastModification > out.lastModified()) {
try {
@@ -73,6 +77,7 @@
}
SwingInterfaceGenerator sing = new SwingInterfaceGenerator(gmo, classes);
SwingAbstractClassGenerator sacg = new SwingAbstractClassGenerator(gmo, classes);
+ sacg.setSwingGenerator(this);
SwingImplementationGenerator simg = new SwingImplementationGenerator(gmo, classes);
sing.generate();
@@ -84,7 +89,7 @@
if (mainClass) {
SwingMainClassGenerator smcg = new SwingMainClassGenerator(gmo);
- File outMain = new File(destDir, launcherName + ".java");
+ File outMain = new File(outDir, launcherName + ".java");
smcg.generate(outMain);
}
@@ -298,134 +303,145 @@
removeMethod = "removePropertyChangeListener";
}
}
- else {
- listener = PropertyChangeListener.class;
- addMethod = "addPropertyChangeListener";
- removeMethod = "removePropertyChangeListener";
+ try {
+ nextClazz = Class.forName(returnType);
+ if(listener == null && nextClazz.isAssignableFrom(java.awt.Container.class)) {
+ listener = PropertyChangeListener.class;
+ addMethod = "addPropertyChangeListener";
+ removeMethod = "removePropertyChangeListener";
+ }
}
-
- //starts to generate the code
- dbCreation.append("if(");
- dbDeletion.append("if(");
- if(alreadyChecked != null && !alreadyChecked.isEmpty()) {
- //add not null parent condition
- for(int j = 0 ; j < alreadyChecked.size() ; j++) {
- dbCreation.append(alreadyChecked.get(0));
- dbDeletion.append(alreadyChecked.get(0));
- for(int k = 1 ; k <= j ; k++) {
- dbCreation.append(".").append(alreadyChecked.get(k));
- dbDeletion.append(".").append(alreadyChecked.get(k));
+ catch (ClassNotFoundException eee) {
+ for(JavaFile javaFile : generatedFiles.values()) {
+ if(returnType.equals(javaFile.getPackageName() + "." + javaFile.getClassName())) {
+ nextFile = javaFile;
+ break;
}
- dbCreation.append(" != null && ");
- dbDeletion.append(" != null && ");
}
+ try {
+ Class c = Class.forName(nextFile.getSuperClass());
+ if(listener == null && c.isAssignableFrom(java.awt.Container.class)) {
+ listener = PropertyChangeListener.class;
+ addMethod = "addPropertyChangeListener";
+ removeMethod = "removePropertyChangeListener";
+ }
+ }
+ catch(ClassNotFoundException eeee) {
+ }
+ catch(NullPointerException eeee) {
+ }
+ }
+ if(listener != null) {
+ //starts to generate the code
+ dbCreation.append("if(");
+ dbDeletion.append("if(");
+ if(alreadyChecked != null && !alreadyChecked.isEmpty()) {
+ //add not null parent condition
+ for(int j = 0 ; j < alreadyChecked.size() ; j++) {
+ dbCreation.append(alreadyChecked.get(0));
+ dbDeletion.append(alreadyChecked.get(0));
+ for(int k = 1 ; k <= j ; k++) {
+ dbCreation.append(".").append(alreadyChecked.get(k));
+ dbDeletion.append(".").append(alreadyChecked.get(k));
+ }
+ dbCreation.append(" != null && ");
+ dbDeletion.append(" != null && ");
+ }
- if(binding.length > alreadyChecked.size() + 1) {
+ if(binding.length > alreadyChecked.size() + 1) {
+ for(int j = 0 ; j < alreadyChecked.size() ; j++) {
+ dbCreation.append(alreadyChecked.get(j)).append(".");
+ dbDeletion.append(alreadyChecked.get(j)).append(".");
+ }
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
+ }
+ else {
+ dbCreation.delete(dbCreation.length() - 4, dbCreation.length());
+ dbDeletion.delete(dbDeletion.length() - 4, dbDeletion.length());
+ }
+ }
+ else {
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
+ }
+ dbCreation.append(") {\n");
+ dbDeletion.append(") {\n");
+
+ if(alreadyChecked != null) {
for(int j = 0 ; j < alreadyChecked.size() ; j++) {
dbCreation.append(alreadyChecked.get(j)).append(".");
dbDeletion.append(alreadyChecked.get(j)).append(".");
}
- dbCreation.append(getter).append(" != null");
- dbDeletion.append(getter).append(" != null");
}
+ if(model != null) {
+ dbCreation.append("get").append(Character.toUpperCase(model.charAt(0)))
+ .append(model.substring(1)).append("()");
+ dbDeletion.append("get").append(Character.toUpperCase(model.charAt(0)))
+ .append(model.substring(1)).append("()");
+ }
else {
- dbCreation.delete(dbCreation.length() - 4, dbCreation.length());
- dbDeletion.delete(dbDeletion.length() - 4, dbDeletion.length());
+ dbCreation.append(getter);
+ dbDeletion.append(getter);
}
- }
- else {
- dbCreation.append(getter).append(" != null");
- dbDeletion.append(getter).append(" != null");
- }
- dbCreation.append(") {\n");
- dbDeletion.append(") {\n");
+ // dbCreation.append(".").append(addMethod).append("((")
+ // .append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(")
+ // .append(listener.getName()).append(".class,this,\"onChangeFrom")
+ // .append(methodToInvoke).append("\"));\n}\n");
+ // dbDeletion.append(".").append(removeMethod).append("((")
+ // .append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(")
+ // .append(listener.getName()).append(".class,this,\"onChangeFrom")
+ // .append(methodToInvoke).append("\"));\n}\n");
- if(alreadyChecked != null) {
- for(int j = 0 ; j < alreadyChecked.size() ; j++) {
- dbCreation.append(alreadyChecked.get(j)).append(".");
- dbDeletion.append(alreadyChecked.get(j)).append(".");
+ dbCreation.append(".").append(addMethod).append("(new ").append(listener.getName()).append("() {\n");
+ dbDeletion.append(".").append(removeMethod).append("(new ").append(listener.getName()).append("() {\n");
+ for(Method m : listener.getMethods()) {
+ StringBuffer sb = new StringBuffer();
+ for(Annotation a : m.getDeclaredAnnotations()) {
+ dbCreation.append(a.toString()).append("\n");
+ }
+ //add the method that handles the event
+ sb.append("public ")
+ .append(m.getReturnType().getCanonicalName())
+ .append(" ")
+ .append(m.getName())
+ .append("(");
+ for(int n = 0 ; n < m.getParameterTypes().length ; n++) {
+ sb.append(m.getParameterTypes()[n].getCanonicalName())
+ .append(" arg")
+ .append(n)
+ .append(", ");
+ }
+ sb.delete(sb.length() - 2, sb.length())
+ .append(")")
+ .append(" {\n")
+ .append("onChangeFrom").append(methodToInvoke)
+ .append("();\n}\n");
+ dbCreation.append(sb);
+ dbDeletion.append(sb);
}
- }
- if(model != null) {
- dbCreation.append("get").append(Character.toUpperCase(model.charAt(0)))
- .append(model.substring(1)).append("()");
- dbDeletion.append("get").append(Character.toUpperCase(model.charAt(0)))
- .append(model.substring(1)).append("()");
- }
- else {
- dbCreation.append(getter);
- dbDeletion.append(getter);
- }
-// dbCreation.append(".").append(addMethod).append("((")
-// .append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(")
-// .append(listener.getName()).append(".class,this,\"onChangeFrom")
-// .append(methodToInvoke).append("\"));\n}\n");
-// dbDeletion.append(".").append(removeMethod).append("((")
-// .append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(")
-// .append(listener.getName()).append(".class,this,\"onChangeFrom")
-// .append(methodToInvoke).append("\"));\n}\n");
-
- dbCreation.append(".").append(addMethod).append("(new ").append(listener.getName()).append("() {\n");
- dbDeletion.append(".").append(removeMethod).append("(new ").append(listener.getName()).append("() {\n");
- for(Method m : listener.getMethods()) {
- StringBuffer sb = new StringBuffer();
- for(Annotation a : m.getDeclaredAnnotations()) {
- dbCreation.append(a.toString()).append("\n");
+ dbCreation.append("});\n}\n");
+ dbDeletion.append("});\n}\n");
+
+ if(alreadyChecked == null){
+ alreadyChecked = new ArrayList<String>();
}
- //add the method that handles the event
- sb.append("public ")
- .append(m.getReturnType().getCanonicalName())
- .append(" ")
- .append(m.getName())
- .append("(");
- for(int n = 0 ; n < m.getParameterTypes().length ; n++) {
- sb.append(m.getParameterTypes()[n].getCanonicalName())
- .append(" arg")
- .append(n)
- .append(", ");
- }
- sb.delete(sb.length() - 2, sb.length())
- .append(")")
- .append(" {\n")
- .append("onChangeFrom").append(methodToInvoke)
- .append("();\n}\n");
- dbCreation.append(sb);
- dbDeletion.append(sb);
- }
- dbCreation.append("});\n}\n");
- dbDeletion.append("});\n}\n");
-
- try {
- nextClazz = Class.forName(returnType);
- }
- catch (ClassNotFoundException eee) {
- for(JavaFile javaFile : generatedFiles.values()) {
- if(returnType.equals(javaFile.getPackageName() + "." + javaFile.getClassName())) {
- nextFile = javaFile;
- break;
+ alreadyChecked.add(getter);
+ try {
+ //if it is not the last element of the binding
+ if(i + 1 < binding.length) {
+ result.addAll(generateBindings(dbCreation, dbDeletion, th, nextFile, nextClazz, binding, i+1, alreadyChecked, methodToInvoke, generatedFiles));
}
+ if(listener != null && !result.contains(listener)) {
+ result.add(listener);
+ }
}
- }
- if(alreadyChecked == null){
- alreadyChecked = new ArrayList<String>();
- }
- alreadyChecked.add(getter);
- try {
- //if it is not the last element of the binding
- if(i + 1 < binding.length) {
- result.addAll(generateBindings(dbCreation, dbDeletion, th, nextFile, nextClazz, binding, i+1, alreadyChecked, methodToInvoke, generatedFiles));
- }
- if(listener == null) {
- log.error("Unable to find the right listener");
+ catch(NullPointerException eee) {
+ log.error(i);
+ eee.printStackTrace();
return null;
}
- if(!result.contains(listener)) {
- result.add(listener);
- }
}
- catch(NullPointerException eee) {
- return null;
- }
}
else if(log.isErrorEnabled()) {
log.error("unable to bind " + binding[i]);
Modified: trunk/guix-compiler-swing/src/test/java/org/nuiton/guix/generator/SwingGeneratorTest.java
===================================================================
--- trunk/guix-compiler-swing/src/test/java/org/nuiton/guix/generator/SwingGeneratorTest.java 2009-07-30 14:59:00 UTC (rev 1540)
+++ trunk/guix-compiler-swing/src/test/java/org/nuiton/guix/generator/SwingGeneratorTest.java 2009-07-30 14:59:12 UTC (rev 1541)
@@ -59,9 +59,7 @@
//tests without TagHandlers
List<Class> l = sg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, JToggleButton.class, new String[]{"isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
Assert.assertNotNull(l);
- Assert.assertEquals(l.size(), 1);
- Assert.assertNotNull(l.get(0));
- Assert.assertEquals(l.get(0), PropertyChangeListener.class);
+ Assert.assertEquals(l.size(), 0);
//tests a successful generation with a method as a binding
l = sg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, JToggleButton.class, new String[]{"isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
Assert.assertNotNull(l);
@@ -76,16 +74,14 @@
Assert.assertEquals(l.get(0), ChangeListener.class);
//tests with a javafile parameter not null
- //tests if the result is null without the taghandler associated to the field
+ //tests if the result is empty without the taghandler associated to the field
JavaFile jf = new JavaFile();
jf.addField(new JavaField(Modifier.PRIVATE, "javax.swing.JToggleButton", "button", null));
jf.addMethod(new JavaMethod(Modifier.PUBLIC, "javax.swing.JToggleButton", "getButton", null, null, "", null));
l = sg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
Assert.assertNotNull(l);
- Assert.assertEquals(l.size(), 1);
- Assert.assertNotNull(l.get(0));
- Assert.assertEquals(l.get(0), PropertyChangeListener.class);
-
+ Assert.assertEquals(l.size(), 0);
+
//tests a successful generation with a method as a binding
jf = new JavaFile();
jf.addField(new JavaField(Modifier.PRIVATE, "javax.swing.JToggleButton", "button", null, new ToggleButtonHandler()));
@@ -107,22 +103,36 @@
Assert.assertEquals(l.get(1), PropertyChangeListener.class);
//tests with a javafile parameter not null with an attribute whose type is another generated file
- //tests if the result is null without the taghandler associated to the field
+ //tests if the result is empty without the taghandler associated to the field
jf = new JavaFile();
jf.addField(new JavaField(Modifier.PRIVATE, "test.Test", "test", null));
jf.addMethod(new JavaMethod(Modifier.PUBLIC, "test.Test", "getTest", null, null, "", null));
JavaFile jf2 = new JavaFile(Modifier.PUBLIC, 0, "test", "Test", null, null);
jf2.addField(new JavaField(Modifier.PRIVATE, "javax.swing.JToggleButton", "button", null));
jf2.addMethod(new JavaMethod(Modifier.PUBLIC, "javax.swing.JToggleButton", "getButton", null, null, "", null));
- Assert.assertNull(sg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
+ l = sg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
//test without jf2 in the map of generators with JavaFile
jf2 = new JavaFile(Modifier.PUBLIC, 0, "test", "Test", null, null);
jf2.addField(new JavaField(Modifier.PRIVATE, "javax.swing.JToggleButton", "button", null, new ToggleButtonHandler()));
jf2.addMethod(new JavaMethod(Modifier.PUBLIC, "javax.swing.JToggleButton", "getButton", null, null, "", null));
- Assert.assertNull(sg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
+ l = sg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
+
Map<GuixGenerator,JavaFile> map = new HashMap<GuixGenerator, JavaFile>();
map.put(sg, jf2);
+ //tests an unsuccessful binding generation with a method as a binding because the superclass of j2 is not assignable from java.awt.Container
+ l = sg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()", "isSelected()"}, 0, null, "", map);
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
//tests a successful generation with a method as a binding
+ jf2 = new JavaFile(Modifier.PUBLIC, 0, "test", "Test", "java.awt.Container", null);
+ jf2.addField(new JavaField(Modifier.PRIVATE, "javax.swing.JToggleButton", "button", null, new ToggleButtonHandler()));
+ jf2.addMethod(new JavaMethod(Modifier.PUBLIC, "javax.swing.JToggleButton", "getButton", null, null, "", null));
+ map = new HashMap<GuixGenerator, JavaFile>();
+ map.put(sg, jf2);
l = sg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()", "isSelected()"}, 0, null, "", map);
Assert.assertNotNull(l);
Assert.assertEquals(l.size(), 2);
1
0
[Buix-commits] r1540 - in trunk/guix-compiler-gwt/src: main/java/org/nuiton/guix/generator test/java/org/nuiton/guix/generator
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
30 Jul '09
Author: kmorin
Date: 2009-07-30 16:59:00 +0200 (Thu, 30 Jul 2009)
New Revision: 1540
Modified:
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtAbstractClassGenerator.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java
trunk/guix-compiler-gwt/src/test/java/org/nuiton/guix/generator/GwtGeneratorTest.java
Log:
Add the acceptation for tags that represents classes defined in the src directory
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtAbstractClassGenerator.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtAbstractClassGenerator.java 2009-07-30 14:58:40 UTC (rev 1539)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtAbstractClassGenerator.java 2009-07-30 14:59:00 UTC (rev 1540)
@@ -22,6 +22,13 @@
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.TabPanel;
import java.beans.IntrospectionException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
import org.nuiton.guix.model.GuixModelObject;
import java.lang.reflect.Modifier;
@@ -59,6 +66,8 @@
/** Bindings to generate */
Map<String,Map<String, String>> bindings2Generate = new HashMap<String,Map<String, String>>();
+ GwtGenerator gwtGenerator;
+
/**
* Constructor
*
@@ -77,6 +86,10 @@
script = sh.decomposeScript(gmo.getClassDescriptor().getScript());
}
+ public void setGwtGenerator(GwtGenerator gwtGenerator) {
+ this.gwtGenerator = gwtGenerator;
+ }
+
@Override
public JavaFile generate() {
super.addImports(gmo);
@@ -348,70 +361,106 @@
}
}
}
+ //if the class hasn't been found
if (clazz == null) {
- throw new ClassNotFoundException();
- }
+ File f = new File(gwtGenerator.getSrcDir(), gmo.getClassDescriptor().toString().replace('.', File.separatorChar) + ".java");
+ try {
+ FileInputStream fis = new FileInputStream(f);
+ Reader isr = new InputStreamReader(fis);
+ JavaFile jFile = JavaFileParser.parseJavaFile(gmo.getClassDescriptor().toString(), isr);
+ fis.close();
+// fis = new FileInputStream(f);
+// File dirDest = new File(gwtGenerator.getDestDir(), gmo.getClassDescriptor().getPackageName().replace('.', File.separatorChar));
+// if(!dirDest.exists()) {
+// dirDest.mkdirs();
+// }
+// File fDest = new File(dirDest, gmo.getClassDescriptor().getName() + ".java");
+// //fDest.createNewFile();
+// FileOutputStream fos = new FileOutputStream(fDest);
+// // segment size : 0.5Mo
+// byte buffer[] = new byte[512*1024];
+// int read;
+// while((read = fis.read(buffer)) != -1) {
+// fos.write(buffer, 0, read);
+// }
+// fis.close();
+// fos.close();
- //if gmo has a TagHandler, add a field to the JavaFile with this TagHandler (used for the databinding generation)
- if (gmo.getClassDescriptor().getPackageName() == null
- && TagManager.getGuixClassHandler(gmo.getClassDescriptor().getName()) != null) {
- jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
- clazz.getName(), gmo.getId(),
- " new " + clazz.getSimpleName() + "(" +
- ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), th),
- false);
+ jf.addField(new JavaField(Modifier.PRIVATE, gmo.getClassDescriptor().toString(), gmo.getId(), gmo.getJavadoc()), true);
+ StringBuffer creationMethod = new StringBuffer();
+ String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
+ creationMethod.append(gmo.getId()).append(" = new ").append(gmo.getClassDescriptor().toString()).append("(").append(gmo.getConstructor() != null ? gmo.getConstructor() : "").append(");\n");
+ componentsCreation.append("create").append(capitalizedId).append("();\n");
+ processAttributes(jFile, gmo, creationMethod);
+ }
+ catch(IOException eee) {
+ log.error(eee);
+ throw new ClassNotFoundException();
+ }
}
- //if gmo is the root ModelObject, it equals "this"
- else if(gmo.getParent() == null) {
- jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
- (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().getPackageName() + ".client." + gmo.getClassDescriptor().getName() + "Abstract" : gmo.getClassDescriptor().getPackageName() + "." + gmo.getClassDescriptor().getName(),
- gmo.getClassDescriptor().getName().toLowerCase(), "this", gmo.getJavadoc(), th),
- false);
- }
else {
- jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
- (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().getPackageName() + ".client." + gmo.getClassDescriptor().getName() + "Abstract" : gmo.getClassDescriptor().getPackageName() + "." + gmo.getClassDescriptor().getName(),
- gmo.getId(), "new " + ((classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().getName() + "Impl" : gmo.getClassDescriptor().getName()) + "(" +
- ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), th),
- false);
- }
- //if gmo is not the root ModelObject
- if (gmo.getParent() != null) {
- String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
- StringBuffer creationMethod = new StringBuffer();
- componentsCreation.append("create").append(capitalizedId).append("();\n");
- //if gmo is the child of a cell
- if (gmo.getParent().getClassDescriptor().getPackageName() != null || !gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("Cell")) {
- //if gmo herits from widget
- if(com.google.gwt.user.client.ui.Widget.class.isAssignableFrom(clazz)) {
- componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId());
- if(tabName != null) {
- componentsTree.append(",").append(tabName);
+ //if gmo has a TagHandler, add a field to the JavaFile with this TagHandler (used for the databinding generation)
+ if (gmo.getClassDescriptor().getPackageName() == null
+ && TagManager.getGuixClassHandler(gmo.getClassDescriptor().getName()) != null) {
+ jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
+ clazz.getName(), gmo.getId(),
+ " new " + clazz.getSimpleName() + "(" +
+ ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), th),
+ false);
+ }
+ //if gmo is the root ModelObject, it equals "this"
+ else if(gmo.getParent() == null) {
+ jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
+ (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().getPackageName() + ".client." + gmo.getClassDescriptor().getName() + "Abstract" : gmo.getClassDescriptor().getPackageName() + "." + gmo.getClassDescriptor().getName(),
+ gmo.getClassDescriptor().getName().toLowerCase(), "this", gmo.getJavadoc(), th),
+ false);
+ }
+ else {
+ jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
+ (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().getPackageName() + ".client." + gmo.getClassDescriptor().getName() + "Abstract" : gmo.getClassDescriptor().getPackageName() + "." + gmo.getClassDescriptor().getName(),
+ gmo.getId(), "new " + ((classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().getName() + "Impl" : gmo.getClassDescriptor().getName()) + "(" +
+ ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), th),
+ false);
+ }
+ //if gmo is not the root ModelObject
+ if (gmo.getParent() != null) {
+ String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
+ StringBuffer creationMethod = new StringBuffer();
+
+ componentsCreation.append("create").append(capitalizedId).append("();\n");
+ //if gmo is the child of a cell
+ if (gmo.getParent().getClassDescriptor().getPackageName() != null || !gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("Cell")) {
+ //if gmo herits from widget
+ if(com.google.gwt.user.client.ui.Widget.class.isAssignableFrom(clazz)) {
+ componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId());
+ if(tabName != null) {
+ componentsTree.append(",").append(tabName);
+ }
+ componentsTree.append(");\n");
}
- componentsTree.append(");\n");
}
- }
- processAttributes(clazz, gmo, creationMethod, null, geh, th);
+ processAttributes(clazz, gmo, creationMethod, null, geh, th);
- }
- else {
- processAttributes(clazz, gmo, null, componentsTree, geh, th);
- //set superclass and interface
- if(th != null) {
- jf.setSuperClass(th.getClassToGenerate().getName());
}
else {
- jf.setSuperClass(gmo.getClassDescriptor().getSuperClass().getPackageName() + "." + gmo.getClassDescriptor().getSuperClass().getName());
+ processAttributes(clazz, gmo, null, componentsTree, geh, th);
+ //set superclass and interface
+ if(th != null) {
+ jf.setSuperClass(th.getClassToGenerate().getName());
+ }
+ else {
+ jf.setSuperClass(gmo.getClassDescriptor().getSuperClass().getPackageName() + "." + gmo.getClassDescriptor().getSuperClass().getName());
+ }
+ jf.addInterface(gmo.getClassDescriptor().getName());
}
- jf.addInterface(gmo.getClassDescriptor().getName());
+ for (GuixModelObject child : gmo.getChildren()) {
+ Map<Method, String> methodBodies = browseModelObjects(child);
+ componentsCreation.append(methodBodies.get(Method.COMPONENTS_CREATION));
+ componentsTree.append(methodBodies.get(Method.COMPONENTS_TREE));
+ bindings.append(methodBodies.get(Method.DATABINDING_INIT));
+ }
}
- for (GuixModelObject child : gmo.getChildren()) {
- Map<Method, String> methodBodies = browseModelObjects(child);
- componentsCreation.append(methodBodies.get(Method.COMPONENTS_CREATION));
- componentsTree.append(methodBodies.get(Method.COMPONENTS_TREE));
- bindings.append(methodBodies.get(Method.DATABINDING_INIT));
- }
}
Map<Method, String> result = new HashMap<Method, String>();
result.put(Method.COMPONENTS_CREATION, componentsCreation.toString());
@@ -499,12 +548,62 @@
//generates the code for the events
creationMethod.append(geh.generate(gmo.getId()));
//add to the file the creation method for this object
- jf.addMethod(
- new JavaMethod(Modifier.PRIVATE, "void", "create" + capitalizedId, null, null, creationMethod.toString(), gmo.getId() + " creation"));
+ jf.addMethod(new JavaMethod(Modifier.PRIVATE, "void", "create" + capitalizedId, null, null, creationMethod.toString(), gmo.getId() + " creation"));
}
}
/**
+ *
+ * @param jFile
+ * @param gmo
+ * @param creationMethod
+ */
+ private void processAttributes(JavaFile jFile, GuixModelObject gmo, StringBuffer creationMethod) {
+ //processCSSAttributes(gmo, seh, clazz);
+ //browses the attributes
+ for (AttributeDescriptor attr : gmo.getAttributeDescriptors()) {
+ boolean addQuote = false;
+ //the attribute name with the first letter capitalized
+ String capitalizedAttribute = (attr.getName().length() > 0) ? Character.toUpperCase(attr.getName().charAt(0)) + attr.getName().substring(1) : attr.getName();
+
+ JavaMethod method = null;
+ for(JavaMethod m : jFile.getMethods()) {
+ if(m.getName().equals("set" + capitalizedAttribute)) {
+ method = m;
+ break;
+ }
+ }
+
+ if(method != null) {
+ String binding = BindingUtils.processDataBindings(attr.getValue());
+ if(binding != null) {
+ if(!bindings2Generate.containsKey(gmo.getId())) {
+ bindings2Generate.put(gmo.getId(), new HashMap<String, String>());
+ }
+ bindings2Generate.get(gmo.getId()).put(attr.getName(), binding);
+ }
+ else {
+ //checks if the parameter of the setter is a String
+ addQuote = method.getArguments()[0].getType().equals(String.class.getName());
+ //generates the code to set the attribute to object
+ creationMethod.append(gmo.getId()).append(".set").append(capitalizedAttribute).append("(").append(addQuote ? "\"" : "").append(attr.getValue()).append(addQuote ? "\"" : "").append(");\n");
+ }
+ }
+ else if(log.isErrorEnabled()) {
+ log.error(attr.getName() + " cannot be set.");
+ }
+ }
+ //if gmo does not represents the first tag
+ if(gmo.getId() != null && creationMethod != null) {
+ //id with the first letter capitalized
+ String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
+
+ //add to the file the creation method for this object
+ jf.addMethod(new JavaMethod(Modifier.PRIVATE, "void", "create" + capitalizedId, null, null, creationMethod.toString(), gmo.getId() + " creation"));
+ }
+ }
+
+ /**
* Browse the MenuBar children and generate the code
* @param gmo the GuixModelObject representing the MenuBar
* @return A map containing the creation, initialization and bindings methods
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java 2009-07-30 14:58:40 UTC (rev 1539)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java 2009-07-30 14:59:00 UTC (rev 1540)
@@ -47,17 +47,23 @@
/** Maps the different generators with the file to save the generated JavaFile */
Map<GwtJavaFileGenerator, File> generators = new HashMap<GwtJavaFileGenerator, File>();
+ List<String> modules = new ArrayList<String>();
+
@Override
public JavaFile generate() {
try {
String gmoClassName = gmo.getClassDescriptor().getName();
- File outDir = new File(destDir, "client");
+ File outDir = new File(destDir, gmo.getClassDescriptor().getPackageName().replace('.', File.separatorChar));
if (!outDir.exists()) {
- outDir.mkdir();
+ outDir.mkdirs();
}
- File out = new File(outDir, gmoClassName + ".java");
- File outAbstract = new File(outDir, gmoClassName + "Abstract.java");
- File outImpl = new File(outDir, gmoClassName + "Impl.java");
+ File outDirClient = new File(outDir, "client");
+ if (!outDirClient.exists()) {
+ outDirClient.mkdirs();
+ }
+ File out = new File(outDirClient, gmoClassName + ".java");
+ File outAbstract = new File(outDirClient, gmoClassName + "Abstract.java");
+ File outImpl = new File(outDirClient, gmoClassName + "Impl.java");
if (lastModification > out.lastModified()) {
try {
@@ -76,16 +82,17 @@
}
GwtInterfaceGenerator ging = new GwtInterfaceGenerator(gmo, classes);
GwtAbstractClassGenerator gacg = new GwtAbstractClassGenerator(gmo, classes);
+ gacg.setGwtGenerator(this);
GwtImplementationGenerator gimg = new GwtImplementationGenerator(gmo, classes);
if (mainClass) {
gimg.addMainMethod();
GwtConfigGenerator gcg = new GwtConfigGenerator(gmo, getCSSFiles());
GwtHtmlGenerator ghg = new GwtHtmlGenerator(gmo, launcherName);
- File outConfigMain = new File(destDir, launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".gwt.xml");
- File publicDir = new File(destDir, "public");
+ File outConfigMain = new File(outDir, launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".gwt.xml");
+ File publicDir = new File(outDir, "public");
if (!publicDir.exists()) {
- publicDir.mkdir();
+ publicDir.mkdirs();
}
File outHtmlMain = new File(publicDir, launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".html");
gcg.generate(outConfigMain);
@@ -166,7 +173,7 @@
String[] binding, int i, List<String> alreadyChecked, String methodToInvoke, Map<GuixGenerator, JavaFile> generatedFiles) {
if(dbCreation == null || dbDeletion == null || binding == null || (jf == null && clazz ==null)
|| methodToInvoke == null || generatedFiles == null || i < 0) {
- return null;
+ return new ArrayList();
}
//does the attribute or method to bind exists ?
@@ -311,86 +318,86 @@
}
else {
log.error("Impossible binding for the " + (realMethodName != null ? "method '" : "attribute '") + realAttributename + "' of the class '" + prevTh.getClassToGenerate().getName() + "'");
- return null;
}
+ if(listener != null) {
+ //starts to generate the code
+ dbCreation.append("if(");
+ dbDeletion.append("if(");
+ if (alreadyChecked != null && !alreadyChecked.isEmpty()) {
+ //add not null parent condition
+ for (int j = 0; j < alreadyChecked.size(); j++) {
+ dbCreation.append(alreadyChecked.get(0));
+ dbDeletion.append(alreadyChecked.get(0));
+ for (int k = 1; k <= j; k++) {
+ dbCreation.append(".").append(alreadyChecked.get(k));
+ dbDeletion.append(".").append(alreadyChecked.get(k));
+ }
+ dbCreation.append(" != null && ");
+ dbDeletion.append(" != null && ");
+ }
- //starts to generate the code
- dbCreation.append("if(");
- dbDeletion.append("if(");
- if (alreadyChecked != null && !alreadyChecked.isEmpty()) {
- //add not null parent condition
- for (int j = 0; j < alreadyChecked.size(); j++) {
- dbCreation.append(alreadyChecked.get(0));
- dbDeletion.append(alreadyChecked.get(0));
- for (int k = 1; k <= j; k++) {
- dbCreation.append(".").append(alreadyChecked.get(k));
- dbDeletion.append(".").append(alreadyChecked.get(k));
+ if (binding.length > alreadyChecked.size() + 1) {
+ for (int j = 0; j < alreadyChecked.size(); j++) {
+ dbCreation.append(alreadyChecked.get(j)).append(".");
+ dbDeletion.append(alreadyChecked.get(j)).append(".");
+ }
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
}
- dbCreation.append(" != null && ");
- dbDeletion.append(" != null && ");
+ else {
+ dbCreation.delete(dbCreation.length() - 4, dbCreation.length());
+ dbDeletion.delete(dbDeletion.length() - 4, dbDeletion.length());
+ }
}
+ else {
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
+ }
+ dbCreation.append(") {\n");
+ dbDeletion.append(") {\n");
- if (binding.length > alreadyChecked.size() + 1) {
+ if (alreadyChecked != null) {
for (int j = 0; j < alreadyChecked.size(); j++) {
dbCreation.append(alreadyChecked.get(j)).append(".");
dbDeletion.append(alreadyChecked.get(j)).append(".");
}
- dbCreation.append(getter).append(" != null");
- dbDeletion.append(getter).append(" != null");
}
- else {
- dbCreation.delete(dbCreation.length() - 4, dbCreation.length());
- dbDeletion.delete(dbDeletion.length() - 4, dbDeletion.length());
+ if (model != null) {
+ dbCreation.append("get").append(Character.toUpperCase(model.charAt(0))).append(model.substring(1)).append("()").append(".");
+ dbDeletion.append("get").append(Character.toUpperCase(model.charAt(0))).append(model.substring(1)).append("()").append(".");
}
- }
- else {
- dbCreation.append(getter).append(" != null");
- dbDeletion.append(getter).append(" != null");
- }
- dbCreation.append(") {\n");
- dbDeletion.append(") {\n");
-
- if (alreadyChecked != null) {
- for (int j = 0; j < alreadyChecked.size(); j++) {
- dbCreation.append(alreadyChecked.get(j)).append(".");
- dbDeletion.append(alreadyChecked.get(j)).append(".");
+ // dbCreation.append(addMethod).append("((").append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(").append(listener.getName()).append(".class,this,\"onChangeFrom").append(methodToInvoke).append("\"));\n}\n");
+ // dbDeletion.append(removeMethod).append("((").append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(").append(listener.getName()).append(".class,this,\"onChangeFrom").append(methodToInvoke).append("\"));\n}\n");
+ dbCreation.append(addMethod).append("(new ").append(listener.getName()).append("() {\n");
+ dbDeletion.append(removeMethod).append("(new ").append(listener.getName()).append("() {\n");
+ for(Method m : listener.getMethods()) {
+ StringBuffer sb = new StringBuffer();
+ for(Annotation a : m.getDeclaredAnnotations()) {
+ dbCreation.append(a.toString()).append("\n");
+ }
+ //add the method that handles the event
+ sb.append("public ")
+ .append(m.getReturnType().getCanonicalName())
+ .append(" ")
+ .append(m.getName())
+ .append("(");
+ for(int n = 0 ; n < m.getParameterTypes().length ; n++) {
+ sb.append(m.getParameterTypes()[n].getCanonicalName())
+ .append(" arg")
+ .append(n)
+ .append(", ");
+ }
+ sb.delete(sb.length() - 2, sb.length())
+ .append(")")
+ .append(" {\n")
+ .append("onChangeFrom").append(methodToInvoke)
+ .append("();\n}\n");
+ dbCreation.append(sb);
+ dbDeletion.append(sb);
}
+ dbCreation.append("});\n}\n");
+ dbDeletion.append("});\n}\n");
}
- if (model != null) {
- dbCreation.append("get").append(Character.toUpperCase(model.charAt(0))).append(model.substring(1)).append("()").append(".");
- dbDeletion.append("get").append(Character.toUpperCase(model.charAt(0))).append(model.substring(1)).append("()").append(".");
- }
-// dbCreation.append(addMethod).append("((").append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(").append(listener.getName()).append(".class,this,\"onChangeFrom").append(methodToInvoke).append("\"));\n}\n");
-// dbDeletion.append(removeMethod).append("((").append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(").append(listener.getName()).append(".class,this,\"onChangeFrom").append(methodToInvoke).append("\"));\n}\n");
- dbCreation.append(addMethod).append("(new ").append(listener.getName()).append("() {\n");
- dbDeletion.append(removeMethod).append("(new ").append(listener.getName()).append("() {\n");
- for(Method m : listener.getMethods()) {
- StringBuffer sb = new StringBuffer();
- for(Annotation a : m.getDeclaredAnnotations()) {
- dbCreation.append(a.toString()).append("\n");
- }
- //add the method that handles the event
- sb.append("public ")
- .append(m.getReturnType().getCanonicalName())
- .append(" ")
- .append(m.getName())
- .append("(");
- for(int n = 0 ; n < m.getParameterTypes().length ; n++) {
- sb.append(m.getParameterTypes()[n].getCanonicalName())
- .append(" arg")
- .append(n)
- .append(", ");
- }
- sb.delete(sb.length() - 2, sb.length())
- .append(")")
- .append(" {\n")
- .append("onChangeFrom").append(methodToInvoke)
- .append("();\n}\n");
- dbCreation.append(sb);
- dbDeletion.append(sb);
- }
- dbCreation.append("});\n}\n");
- dbDeletion.append("});\n}\n");
}
try {
Modified: trunk/guix-compiler-gwt/src/test/java/org/nuiton/guix/generator/GwtGeneratorTest.java
===================================================================
--- trunk/guix-compiler-gwt/src/test/java/org/nuiton/guix/generator/GwtGeneratorTest.java 2009-07-30 14:58:40 UTC (rev 1539)
+++ trunk/guix-compiler-gwt/src/test/java/org/nuiton/guix/generator/GwtGeneratorTest.java 2009-07-30 14:59:00 UTC (rev 1540)
@@ -23,6 +23,7 @@
import com.google.gwt.user.client.ui.ToggleButton;
import java.lang.reflect.Modifier;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.nuiton.guix.generator.GwtGenerator;
@@ -51,57 +52,81 @@
GwtGuixInitializer.initialize();
GwtGenerator gg = new GwtGenerator();
//tests the not null condition for the parameters that needs to be not null
- Assert.assertNull(gg.generateBindings(null, new StringBuffer(), null, null, Class.class, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), null, null, null, Class.class, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, null, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], -1, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], -1, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], 0, null, null, new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], 0, null, "", null));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, null, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
+ List<Class> l = gg.generateBindings(null, new StringBuffer(), null, null, Class.class, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
+ l = gg.generateBindings(new StringBuffer(), null, null, null, Class.class, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, null, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], -1, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], -1, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], 0, null, null, new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], 0, null, "", null);
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, null, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
//tests with a class parameter not null
//tests if a null listener as result returns null
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNull(l);
//tests a successful generation with a method as a binding
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).size(),1);
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0),ClickListener.class);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(),1);
+ Assert.assertNotNull(l.get(0));
+ Assert.assertEquals(l.get(0),ClickListener.class);
//tests a successful generation with an attribute as a binding
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).size(),1);
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0),ClickListener.class);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(),1);
+ Assert.assertNotNull(l.get(0));
+ Assert.assertEquals(l.get(0),ClickListener.class);
//tests a successful generation with a method with the generic name as a binding
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).size(),1);
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0),ClickListener.class);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(),1);
+ Assert.assertNotNull(l.get(0));
+ Assert.assertEquals(l.get(0),ClickListener.class);
//tests a successful generation with an attribute with the generic name as a binding
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"selected"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"selected"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).size(),1);
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"selected"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"selected"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0),ClickListener.class);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"selected"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(),1);
+ Assert.assertNotNull(l.get(0));
+ Assert.assertEquals(l.get(0),ClickListener.class);
//tests with a javafile parameter not null
//tests if the result is null without the taghandler associated to the field
JavaFile jf = new JavaFile();
jf.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null));
jf.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNull(l);
//tests a successful generation with a method as a binding
jf = new JavaFile();
jf.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null, new ToggleButtonHandler()));
jf.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null));
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).size(),1);
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0),ClickListener.class);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(),1);
+ Assert.assertNotNull(l.get(0));
+ Assert.assertEquals(l.get(0),ClickListener.class);
//tests a successful generation with an attribute as a binding
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"button","down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"button","down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).size(),1);
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"button","down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"button","down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()).get(0),ClickListener.class);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"button","down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(),1);
+ Assert.assertNotNull(l.get(0));
+ Assert.assertEquals(l.get(0),ClickListener.class);
//tests with a javafile parameter not null with an attribute whose type is another generated file
//tests if the result is null without the taghandler associated to the field
@@ -111,24 +136,30 @@
JavaFile jf2 = new JavaFile(Modifier.PUBLIC, JavaFile.CLASS, "test", "Test", null, null);
jf2.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null));
jf2.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
//test without jf2 in the map of generators with JavaFile
jf2 = new JavaFile(Modifier.PUBLIC, JavaFile.CLASS, "test", "Test", null, null);
jf2.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null, new ToggleButtonHandler()));
jf2.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null));
- Assert.assertNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()));
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>());
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(), 0);
Map<GuixGenerator,JavaFile> map = new HashMap<GuixGenerator, JavaFile>();
map.put(gg, jf2);
//tests a successful generation with a method as a binding
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()", "isDown()"}, 0, null, "", map));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()", "isDown()"}, 0, null, "", map).size(),1);
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()", "isDown()"}, 0, null, "", map).get(0));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()", "isDown()"}, 0, null, "", map).get(0),ClickListener.class);
+ l =gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()", "isDown()"}, 0, null, "", map);
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(),1);
+ Assert.assertNotNull(l.get(0));
+ Assert.assertEquals(l.get(0),ClickListener.class);
//tests a successful generation with an attribute as a binding
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"test","button","down"}, 0, null, "", map));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"test","button","down"}, 0, null, "", map).size(),1);
- Assert.assertNotNull(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"test","button","down"}, 0, null, "", map).get(0));
- Assert.assertEquals(gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"test","button","down"}, 0, null, "", map).get(0),ClickListener.class);
+ l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"test","button","down"}, 0, null, "", map);
+ Assert.assertNotNull(l);
+ Assert.assertEquals(l.size(),1);
+ Assert.assertNotNull(l.get(0));
+ Assert.assertEquals(l.get(0),ClickListener.class);
}
}
1
0
[Buix-commits] r1539 - in trunk/guix-compiler/src: main/java/org/nuiton/guix main/java/org/nuiton/guix/generator test/java/org/nuiton/guix test/java/org/nuiton/guix/compiler
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
by kmorin@users.labs.libre-entreprise.org 30 Jul '09
30 Jul '09
Author: kmorin
Date: 2009-07-30 16:58:40 +0200 (Thu, 30 Jul 2009)
New Revision: 1539
Added:
trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileParser.java
Modified:
trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java
trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java
trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java
Log:
Add the acceptation for tags that represents classes defined in the src directory
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-30 14:57:24 UTC (rev 1538)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-30 14:58:40 UTC (rev 1539)
@@ -22,7 +22,6 @@
import java.io.File;
import java.io.PrintWriter;
import java.io.StringReader;
-import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
@@ -71,6 +70,8 @@
private List<File> compiledFiles = new ArrayList<File>();
/** Maps the generator with the generated JavaFile */
private Map<GuixGenerator, JavaFile> generatedFiles = new HashMap<GuixGenerator, JavaFile>();
+ /** Source directory of the project */
+ private File srcDirectory;
/** Directory where to save the generated files */
private File targetDirectory;
/** Root package */
@@ -93,10 +94,11 @@
* @param generatorClass class of the generator
* @param launcherName name of the class that will launch the application
*/
- public GuixLauncher(File[] files, File targetDirectory, String rootPackage,
+ public GuixLauncher(File[] files, File targetDirectory, String rootPackage, File srcDir,
File baseDir, String mainClass, Class<? extends GuixGenerator> generatorClass, String launcherName) {
// Set up a simple configuration that logs on the console.
this.files = files;
+ this.srcDirectory = srcDir;
this.targetDirectory = targetDirectory;
this.rootPackage = rootPackage != null ? rootPackage : "";
if (files != null) {
@@ -127,7 +129,6 @@
* <code>false</code> otherwise
*/
public synchronized boolean compile() {
- File destDir = targetDirectory;
if (files != null) {
if (log.isInfoEnabled()) {
log.info("Start compiling");
@@ -154,24 +155,19 @@
if (targetDirectory != null) {
int dotPos = className.lastIndexOf(".");
if (dotPos != -1) {
- destDir = new File(targetDirectory, className.substring(0, dotPos).replace('.', File.separatorChar));
classPackage = className.substring(0, dotPos);
}
else {
- destDir = new File(targetDirectory, className);
- classPackage = className;
+ classPackage = "";
}
- if (!destDir.exists() && !destDir.mkdirs()) {
- if (log.isWarnEnabled()) {
- log.warn("couldn't create directory " + destDir);
- }
- continue;
- }
}
else {
- destDir = file.getParentFile();
- classPackage = destDir.getAbsolutePath().replace(File.separatorChar, '.');
+ targetDirectory = file.getParentFile();
+ classPackage = targetDirectory.getAbsolutePath().replace(File.separatorChar, '.');
}
+ if(!targetDirectory.exists()) {
+ targetDirectory.mkdirs();
+ }
//compile the file
GuixCompiler compiler = new GuixCompiler(file, this, classPackage);
GuixModelObject rootModelObject = compiler.compile();
@@ -224,7 +220,8 @@
try {
//init generator
GuixGenerator gen = (GuixGenerator) generatorClass.newInstance();
- gen.setDestDir(destDir);
+ gen.setSrcDir(srcDirectory);
+ gen.setDestDir(targetDirectory);
gen.setGmo(mo);
gen.setLastModification(rootModelObjects.get(mo));
gen.setMainClass((mo.getClassDescriptor().getPackageName() + "." + mo.getClassDescriptor().getName()).equals(mainClass));
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java 2009-07-30 14:57:24 UTC (rev 1538)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java 2009-07-30 14:58:40 UTC (rev 1539)
@@ -33,6 +33,10 @@
public JavaFile generate();
+ public File getSrcDir();
+
+ public void setSrcDir(File srcDir);
+
public File getDestDir();
public void setDestDir(File destDir);
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java 2009-07-30 14:57:24 UTC (rev 1538)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java 2009-07-30 14:58:40 UTC (rev 1539)
@@ -36,6 +36,8 @@
/** GuixModelObject which represents the class to generate */
protected GuixModelObject gmo = null;
+ /** Source directory */
+ protected File srcDir = null;
/** Destination directory of the generated file */
protected File destDir = null;
/** True if the class to generate is teh main class of the application */
@@ -60,6 +62,14 @@
*/
public abstract JavaFile generate();
+ public File getSrcDir() {
+ return srcDir;
+ }
+
+ public void setSrcDir(File srcDir) {
+ this.srcDir = srcDir;
+ }
+
public File getDestDir() {
return destDir;
}
Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileParser.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileParser.java (rev 0)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileParser.java 2009-07-30 14:58:40 UTC (rev 1539)
@@ -0,0 +1,214 @@
+package org.nuiton.guix.generator;
+
+import org.nuiton.guix.CompilerException;
+import org.nuiton.guix.compiler.GuixCompiler;
+import org.nuiton.guix.GuixLauncher;
+import org.nuiton.guix.parser.JavaParser;
+import org.nuiton.guix.parser.JavaParserTreeConstants;
+import org.nuiton.guix.parser.ParseException;
+import org.nuiton.guix.parser.SimpleNode;
+import org.nuiton.guix.tags.TagManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Reader;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+// TODO: need to unify this implementation with the parsing in ScriptManager
+public class JavaFileParser {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private final Log log = LogFactory.getLog(JavaFileParser.class);
+
+ private String className;
+ private String packageName = null;
+ private String superclassName = "java.lang.Object";
+ private List<JavaMethod> methods = new ArrayList<JavaMethod>();
+ private List<JavaField> fields = new ArrayList<JavaField>();
+
+
+ public static JavaFile parseJavaFile(String displayName, Reader src) throws ClassNotFoundException {
+ // has some limitations -- it reports all members as public, leaves getDeclaredMethod and getDeclaredField
+ // undefined, and doesn't report interfaces. It's safe to leave those the way they are for now, because
+ // Guix doesn't look at any of those for non-Guix classes.
+ JavaFileParser parser = new JavaFileParser();
+ if (log.isDebugEnabled()) {
+ log.debug("starting parsing : " + displayName);
+ }
+ try {
+ parser.doParse(displayName, src);
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ throw new RuntimeException(e);
+ }
+ JavaFile jf = new JavaFile(Modifier.PUBLIC, JavaFile.CLASS, parser.packageName,
+ parser.className, parser.superclassName, new ArrayList<String>(), null);
+ for(JavaMethod jm : parser.methods) {
+ if(Modifier.isPublic(jm.getModifiers())) {
+ jf.addMethod(jm);
+ }
+ }
+ for(JavaField jfi : parser.fields) {
+ if(Modifier.isPublic(jfi.getModifiers())) {
+ jf.addField(jfi);
+ }
+ }
+
+ Class superclass = Class.forName(parser.superclassName);
+ for(Method m : superclass.getMethods()) {
+ JavaArgument[] jas = new JavaArgument[m.getParameterTypes().length];
+ for(int i = 0 ; i < m.getParameterTypes().length ; i++) {
+ jas[i] = new JavaArgument(m.getParameterTypes()[i].getName(), "arg" + i);
+ }
+ String[] exceptions = new String[m.getExceptionTypes().length];
+ for(int i = 0 ; i < m.getExceptionTypes().length ; i++) {
+ exceptions[i] = m.getExceptionTypes()[i].getName();
+ }
+ jf.addMethod(new JavaMethod(m.getModifiers(), m.getReturnType().getName(), m.getName(), jas, exceptions, "", null));
+ }
+ for(Field f : superclass.getFields()) {
+ jf.addField(new JavaField(f.getModifiers(), f.getType().getName(), f.getName(), null));
+ }
+
+ for (Class i : superclass.getInterfaces()) {
+ jf.getInterfaces().add(i.getName());
+ }
+
+ return jf;
+ }
+
+ private void doParse(String displayName, Reader src) {
+ try {
+ JavaParser p = new JavaParser(src);
+ p.CompilationUnit();
+ SimpleNode node = p.popNode();
+ if (node != null) {
+ scanCompilationUnit(node);
+ return;
+ }
+ throw new CompilerException("Internal error: null node parsing Java file from " + src);
+ }
+ catch (ParseException e) {
+ throw new CompilerException("Error parsing Java source code " + displayName + ": " + e.getMessage());
+ }
+ }
+
+
+ private void scanCompilationUnit(SimpleNode node) {
+ for (int i = 0; i < node.jjtGetNumChildren(); i++) {
+ SimpleNode child = node.getChild(i);
+ int nodeType = child.getId();
+ if (nodeType == JavaParserTreeConstants.JJTPACKAGEDECLARATION) {
+ packageName = child.getChild(1).getText().trim();
+ } else
+ if (nodeType == JavaParserTreeConstants.JJTIMPORTDECLARATION) {
+ String text = child.getText().trim();
+ if (text.startsWith("import")) {
+ text = text.substring("import".length()).trim();
+ }
+ if (text.endsWith(";")) {
+ text = text.substring(0, text.length() - 1);
+ }
+ } else if (nodeType == JavaParserTreeConstants.JJTTYPEDECLARATION) {
+ scanCompilationUnit(child);
+ } else
+ if (nodeType == JavaParserTreeConstants.JJTCLASSORINTERFACEDECLARATION) {
+ scanClass(child);
+ }
+ }
+ }
+
+
+ // scans the main ClassOrInterfaceDeclaration
+ private void scanClass(SimpleNode node) {
+ boolean isInterface = node.firstToken.image.equals("interface");
+ className = node.firstToken.next.image;
+ if (packageName != null)
+ className = packageName + "." + className;
+ for (int i = 0; i < node.jjtGetNumChildren(); i++) {
+ SimpleNode child = node.getChild(i);
+ int nodeType = child.getId();
+ if (nodeType == JavaParserTreeConstants.JJTEXTENDSLIST) {
+ if (!isInterface) {
+ assert child.jjtGetNumChildren() == 1 : "expected ExtendsList to have exactly one child for a non-interface class";
+ String rawName = child.getChild(0).getText().trim();
+ superclassName = TagManager.resolveClassName(rawName);
+ if (superclassName == null) {
+ throw new CompilerException("Could not find class: " + rawName);
+ }
+ }
+ } else
+ if (nodeType == JavaParserTreeConstants.JJTCLASSORINTERFACEBODY) {
+ scanClassNode(child);
+ }
+ }
+ }
+
+
+ // scans class body nodes
+ private void scanClassNode(SimpleNode node) {
+ int nodeType = node.getId();
+ if (nodeType == JavaParserTreeConstants.JJTMETHODDECLARATION) {
+ String returnType = null;
+ String name = null;
+ List<JavaArgument> parameterTypes = new ArrayList<JavaArgument>();
+ //List<String> parameterNames = new ArrayList<String>();
+ for (int i = 0; i < node.jjtGetNumChildren(); i++) {
+ SimpleNode child = node.getChild(i);
+ int type = child.getId();
+ if (type == JavaParserTreeConstants.JJTRESULTTYPE)
+ returnType = TagManager.resolveClassName(child.getText().trim());
+ else if (type == JavaParserTreeConstants.JJTMETHODDECLARATOR) {
+ name = child.firstToken.image.trim();
+ SimpleNode formalParameters = child.getChild(0);
+ assert formalParameters.getId() == JavaParserTreeConstants.JJTFORMALPARAMETERS;
+ for (int j = 0; j < formalParameters.jjtGetNumChildren(); j++)
+ {
+ SimpleNode parameter = formalParameters.getChild(j);
+ String rawParameterType = parameter.getChild(1).getText().trim().replaceAll("\\.\\.\\.", "[]");
+ String parameterType = TagManager.resolveClassName(rawParameterType);
+ if (parameterType == null) {
+ throw new CompilerException("could not find class '" + rawParameterType + "'");
+ }
+ parameterTypes.add(new JavaArgument(parameterType, "arg" + j));
+ //parameterNames.add(parameter.getChild(2).getText().trim());
+ }
+ }
+ }
+ methods.add(new JavaMethod(Modifier.PUBLIC, returnType, name, parameterTypes.toArray(new JavaArgument[parameterTypes.size()]), null, "", null)); // TODO: determine the actual modifiers
+ } else
+ if (nodeType == JavaParserTreeConstants.JJTCLASSORINTERFACEDECLARATION) {
+ // TODO: handle inner classes
+ } else
+ if (nodeType == JavaParserTreeConstants.JJTCONSTRUCTORDECLARATION) {
+ // TODO: handle constructors
+ } else if (nodeType == JavaParserTreeConstants.JJTFIELDDECLARATION) {
+ String text = node.getText();
+ String declaration = text;
+ int equals = text.indexOf("=");
+ if (equals != -1) {
+ declaration = declaration.substring(0, equals);
+ }
+ declaration = declaration.trim();
+ String[] declarationTokens = declaration.split("\\s");
+ //boolean isFinal = Arrays.asList(declarationTokens).contains("final");
+ //boolean isStatic = Arrays.asList(declarationTokens).contains("static");
+ String name = declarationTokens[declarationTokens.length - 1];
+ if (name.endsWith(";")) {
+ name = name.substring(0, name.length() - 1).trim();
+ }
+ String className = declarationTokens[declarationTokens.length - 2];
+ String type = TagManager.resolveClassName(className);
+ fields.add(new JavaField(Modifier.PUBLIC, type, name, null)); // TODO: determine the actual modifiers
+ } else {
+ for (int i = 0; i < node.jjtGetNumChildren(); i++) {
+ SimpleNode child = node.getChild(i);
+ scanClassNode(child);
+ }
+ }
+ }
+}
Modified: trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java
===================================================================
--- trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java 2009-07-30 14:57:24 UTC (rev 1538)
+++ trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java 2009-07-30 14:58:40 UTC (rev 1539)
@@ -41,7 +41,7 @@
public void compileTest() {
GuixInitializer.initialize();
- GuixLauncher gl = new GuixLauncher(null,null,null,null,null,null,null);
+ GuixLauncher gl = new GuixLauncher(null,null,null,null,null,null,null,null);
assertTrue(gl.files == null || gl.classNames.length == gl.files.length);
assertTrue(gl.compile());
assertTrue(gl.files == null || gl.rootModelObjects.size() == gl.files.length);
@@ -50,7 +50,7 @@
File f2 = new File(f.getAbsolutePath());
File dir = new File("target/test");
File dir2 = new File(dir.getAbsolutePath());
- gl = new GuixLauncher(new File[]{f2},dir2,"org.nuiton.guix",f2.getParentFile(), null,null,null);
+ gl = new GuixLauncher(new File[]{f2},dir2,"org.nuiton.guix",null,f2.getParentFile(),null,null,null);
assertTrue(gl.files == null || gl.classNames.length == gl.files.length);
assertTrue(gl.compile());
}
@@ -60,7 +60,7 @@
*/
@Test
public void registerClassDescriptorTest() {
- GuixLauncher gl = new GuixLauncher(null,null,null,null,null,null,null);
+ GuixLauncher gl = new GuixLauncher(null,null,null,null,null,null,null,null);
assertNull(gl.registerClassDescriptor(null));
assertNull(gl.registerClassDescriptor(new ClassDescriptor(null, null)));
Modified: trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java
===================================================================
--- trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java 2009-07-30 14:57:24 UTC (rev 1538)
+++ trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java 2009-07-30 14:58:40 UTC (rev 1539)
@@ -36,7 +36,7 @@
File f = new File("src/test/test.guix");
File f2 = new File(f.getAbsolutePath());
GuixLauncher gl = new GuixLauncher(new File[]{f2}, null,
- "org.nuiton.guix",f2.getParentFile(),null,null,null);
+ "org.nuiton.guix",null,f2.getParentFile(),null,null,null);
GuixCompiler gc = new GuixCompiler(null, null,null);
assertNull(gc.compile());
1
0
Author: kmorin
Date: 2009-07-30 16:57:24 +0200 (Thu, 30 Jul 2009)
New Revision: 1538
Modified:
trunk/pom.xml
Log:
removed the runtime modules
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-07-28 14:51:19 UTC (rev 1537)
+++ trunk/pom.xml 2009-07-30 14:57:24 UTC (rev 1538)
@@ -19,11 +19,11 @@
<module>guix-compiler</module>
<module>guix-compiler-swing</module>
<module>guix-compiler-gwt</module>
- <module>guix-runtime-swing</module>
- <module>guix-runtime-gwt</module>
<module>maven-guix-plugin</module>
<module>guix-test-swing</module>
- <module>guix-test-gwt</module>
+ <module>guix-test-gwt</module>
+
+
</modules>
1
0
[Buix-commits] r1537 - trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler
by kmorin@users.labs.libre-entreprise.org 28 Jul '09
by kmorin@users.labs.libre-entreprise.org 28 Jul '09
28 Jul '09
Author: kmorin
Date: 2009-07-28 16:51:19 +0200 (Tue, 28 Jul 2009)
New Revision: 1537
Modified:
trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java
Log:
Replaced the $ symbol by the _ symbol for the autogenerated fields
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-07-28 10:38:42 UTC (rev 1536)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-07-28 14:51:19 UTC (rev 1537)
@@ -301,7 +301,7 @@
String id = ((xpp.getAttributeValue("", "id") != null)
? xpp.getAttributeValue("", "id")
- : "$" + tagName + index++);
+ : "_" + tagName + index++);
// create the GuixModelObject representing the tag
GuixModelObject mo = new GuixModelObject(id, xpp.getAttributeValue("", "constructor"),
1
0
[Buix-commits] r1536 - trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator
by kmorin@users.labs.libre-entreprise.org 28 Jul '09
by kmorin@users.labs.libre-entreprise.org 28 Jul '09
28 Jul '09
Author: kmorin
Date: 2009-07-28 12:38:42 +0200 (Tue, 28 Jul 2009)
New Revision: 1536
Modified:
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java
Log:
Correction after the last failed build
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java 2009-07-28 10:38:31 UTC (rev 1535)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java 2009-07-28 10:38:42 UTC (rev 1536)
@@ -96,23 +96,32 @@
return jf;
}
- catch (IllegalArgumentException ex) {
- log.error(ex);
+ catch (IllegalArgumentException eee) {
+ if(log.isErrorEnabled()) {
+ log.error(eee);
+ }
}
- catch (IllegalStateException ex) {
- log.error(ex);
+ catch (IllegalStateException eee) {
+ if(log.isErrorEnabled()) {
+ log.error(eee);
+ }
}
- catch (IOException ex) {
- log.error(ex);
+ catch (IOException eee) {
+ if(log.isErrorEnabled()) {
+ log.error(eee);
+ }
}
}
else if (log.isWarnEnabled()) {
log.warn(gmo.getClassDescriptor().getName() + " has already been generated and is up to date.");
}
}
- finally {
- return null;
+ catch(Exception eee) {
+ if(log.isErrorEnabled()) {
+ log.error(eee);
+ }
}
+ return null;
}
@Override
@@ -407,6 +416,7 @@
result.addAll(generateBindings(dbCreation, dbDeletion, th, nextFile, nextClazz, binding, i+1, alreadyChecked, methodToInvoke, generatedFiles));
}
if(listener == null) {
+ log.error("Unable to find the right listener");
return null;
}
if(!result.contains(listener)) {
1
0
[Buix-commits] r1535 - trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator
by kmorin@users.labs.libre-entreprise.org 28 Jul '09
by kmorin@users.labs.libre-entreprise.org 28 Jul '09
28 Jul '09
Author: kmorin
Date: 2009-07-28 12:38:31 +0200 (Tue, 28 Jul 2009)
New Revision: 1535
Modified:
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java
Log:
Correction after the last failed build
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java 2009-07-28 10:02:13 UTC (rev 1534)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java 2009-07-28 10:38:31 UTC (rev 1535)
@@ -125,23 +125,33 @@
return jf;
}
- catch (IllegalArgumentException ex) {
- log.error(ex);
+ catch (IllegalArgumentException eee) {
+ if(log.isErrorEnabled()) {
+ log.error(eee);
+ }
}
- catch (IllegalStateException ex) {
- log.error(ex);
+ catch (IllegalStateException eee) {
+ if(log.isErrorEnabled()) {
+ log.error(eee);
+ }
}
- catch (IOException ex) {
- log.error(ex);
+ catch (IOException eee) {
+ if(log.isErrorEnabled()) {
+ log.error(eee);
+ }
}
}
else if (log.isWarnEnabled()) {
log.warn(gmo.getClassDescriptor().getName() + " has already been generated and is up to date.");
}
}
- finally {
- return null;
+ catch(Exception eee) {
+ if(log.isErrorEnabled()) {
+ log.error(eee);
+ }
}
+
+ return null;
}
@Override
1
0