This is an automated email from the git hooks/post-receive script. New commit to annotated tag v2.0.0-beta-2 in repository jaxx. See https://gitlab.nuiton.org/nuiton/jaxx.git commit f7b3961475b6bcffc7c8fd6b140643936db006f5 Author: Tony Chemit <chemit@codelutin.com> Date: Thu Nov 26 20:03:21 2009 +0000 use maven-changes-plugin 2.2 (with french translations :)) --- .../src/main/java/jaxx/compiler/JAXXCompiler.java | 71 ++++++++++++---------- .../src/main/java/jaxx/compiler/java/JavaFile.java | 58 ++++++++++-------- 2 files changed, 71 insertions(+), 58 deletions(-) diff --git a/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java b/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java index 106d038..22c3978 100644 --- a/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java +++ b/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java @@ -22,71 +22,47 @@ package jaxx.compiler; import jaxx.compiler.binding.DataBinding; import jaxx.compiler.css.StylesheetHelper; -import jaxx.compiler.script.ScriptManager; -import jaxx.compiler.java.JavaMethod; import jaxx.compiler.java.JavaField; import jaxx.compiler.java.JavaFile; +import jaxx.compiler.java.JavaFileGenerator; +import jaxx.compiler.java.JavaMethod; import jaxx.compiler.java.parser.ParseException; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorLoader; import jaxx.compiler.reflect.FieldDescriptor; import jaxx.compiler.reflect.MethodDescriptor; +import jaxx.compiler.script.ScriptManager; import jaxx.compiler.tags.DefaultObjectHandler; import jaxx.compiler.tags.TagHandler; import jaxx.compiler.tags.TagManager; +import jaxx.compiler.types.TypeManager; import jaxx.runtime.ComponentDescriptor; import jaxx.runtime.JAXXObjectDescriptor; import jaxx.runtime.css.Rule; import jaxx.runtime.css.Stylesheet; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; +import org.xml.sax.*; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.XMLFilterImpl; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.ErrorListener; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; +import javax.xml.transform.*; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.sax.SAXSource; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; +import java.io.*; import java.lang.reflect.Modifier; import java.net.URL; import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Stack; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -import jaxx.compiler.java.JavaFileGenerator; -import jaxx.compiler.types.TypeManager; -import org.apache.commons.lang.StringUtils; - /** * Compiles JAXX files into Java classes. * <p/> @@ -1625,4 +1601,33 @@ public class JAXXCompiler { public JAXXEngine getEngine() { return engine; } + + /** + * Convertit un nom de variable en nom de constante. + * + * @param variableName le nom de variable a convertir + * @return le nom de la constante à partir du nom de la variable + */ + public static String convertVariableNameToConstantName(String variableName) { + //TODO Faire des tests pour savoir si variableName est non null et valide + //TODO Ameliorer l'algo pour tenir compte des caractères non alpha + //TODO pour le moment cela convient, donc... + StringBuilder buffer = new StringBuilder(); + boolean lastCarIsUp = false; + for (int i = 0, j = variableName.length(); i < j; i++) { + char c = variableName.charAt(i); + boolean carIsUp = Character.isUpperCase(c); + if (i > 0 && !lastCarIsUp && carIsUp) { + // ajout d'un _ + buffer.append('_'); + } + if (carIsUp) { + buffer.append(c); + } else { + buffer.append(Character.toUpperCase(c)); + } + lastCarIsUp = carIsUp; + } + return buffer.toString(); + } } diff --git a/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java b/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java index 1de7de5..099658c 100644 --- a/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java +++ b/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java @@ -1,30 +1,32 @@ -/* - * *##% - * JAXX Compiler - * Copyright (C) 2008 - 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>. - * ##%* - */ +/* + * *##% + * JAXX Compiler + * Copyright (C) 2008 - 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 jaxx.compiler.java; +import jaxx.compiler.JAXXCompiler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * A Java source file being generated for output. Once the class is completely initialized, use the @@ -38,7 +40,8 @@ public class JavaFile extends JavaElement { static private final Log log = LogFactory.getLog(JavaFile.class); protected static final String GETTER_PATTERN = "return %1$s;"; protected static final String BOOLEAN_GETTER_PATTERN = "return %1$s !=null && %1$s;"; - protected static final String SETTER_PATTERN = "%1$s oldValue = this.%2$s;\nthis.%2$s = newValue;\nfirePropertyChange(\"%2$s\", oldValue, newValue);"; + protected static final String SETTER_PATTERN = "%1$s oldValue = this.%2$s;\nthis.%2$s = newValue;\nfirePropertyChange(%3$s, oldValue, newValue);"; + // protected static final String SETTER_PATTERN = "%1$s oldValue = this.%2$s;\nthis.%2$s = newValue;\nfirePropertyChange(\"%2$s\", oldValue, newValue);"; private List<String> imports = new ArrayList<String>(); private List<JavaField> fields = new ArrayList<JavaField>(); private List<JavaMethod> methods = new ArrayList<JavaMethod>(); @@ -123,12 +126,17 @@ public class JavaFile extends JavaElement { field.getType(), "get" + capitalizedName, null, null, content, field.isOverride())); if (javaBean) { - // add full javabean support + // add full javabean support accessor + mutator + constante with name of property to make it easier to use + // compute the property constante + String constantId = JAXXCompiler.convertVariableNameToConstantName("property" + capitalizedName); + addSimpleField(JavaFileGenerator.newField(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL, String.class.getSimpleName(), constantId, false, "\"" + id + "\"")); + if (Boolean.class.getName().equals(field.getType())) { content = String.format(BOOLEAN_GETTER_PATTERN, id); addMethod(new JavaMethod(Modifier.PUBLIC, field.getType(), "is" + capitalizedName, null, null, content, field.isOverride())); } - content = String.format(SETTER_PATTERN, field.getType(), id); + content = String.format(SETTER_PATTERN, field.getType(), id, constantId); +// content = String.format(SETTER_PATTERN, field.getType(), id); JavaArgument arg = new JavaArgument(field.getType(), "newValue"); addMethod(new JavaMethod(Modifier.PUBLIC, "void", "set" + capitalizedName, new JavaArgument[]{arg}, null, content, field.isOverride())); } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.