[Buix-commits] r1395 - in guix/trunk/guix-compiler/src: main/java/org/nuiton/guix main/java/org/nuiton/guix/compiler main/java/org/nuiton/guix/css main/java/org/nuiton/guix/generator main/java/org/nuiton/guix/model main/java/org/nuiton/guix/parser main/java/org/nuiton/guix/tags test/java/org/nuiton/guix test/java/org/nuiton/guix/compiler
Author: kmorin Date: 2009-05-07 15:19:37 +0000 (Thu, 07 May 2009) New Revision: 1395 Added: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/MainClassGenerator.java Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/CompilerException.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedAttributeException.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedTagException.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSSParserConstants.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSSParserTreeConstants.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/JJTCSSParserState.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/Node.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/ParseException.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/SimpleCharStream.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/SimpleNode.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/Token.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/TokenMgrError.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/AbstractClassGenerator.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/ImplementationGenerator.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/InterfaceGenerator.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Rule.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Selector.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/StyleSheet.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JJTJavaParserState.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JavaParserConstants.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JavaParserTreeConstants.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Node.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/ParseException.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Token.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/TokenMgrError.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java Log: Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/CompilerException.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/CompilerException.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/CompilerException.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -4,10 +4,8 @@ public class CompilerException extends RuntimeException { /** Creates a new <code>ParseException</code>. */ - public CompilerException() { - } + public CompilerException() {} - /** * Creates a new <code>ParseException</code> with the specified detail message. * @@ -17,7 +15,6 @@ super(msg); } - /** * Creates a new <code>ParseException</code> with the specified cause. * @@ -27,7 +24,6 @@ super(initCause); } - /** * Creates a new <code>ParseException</code> with the specified detail message and cause. * @@ -38,10 +34,12 @@ super(msg, initCause); } - public void printStackTrace() { super.printStackTrace(); System.err.println("CompilerException printed from:"); Thread.dumpStack(); } -} \ No newline at end of file +} + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,6 +1,7 @@ - package org.nuiton.guix; +//~--- non-JDK imports -------------------------------------------------------- + import org.nuiton.guix.tags.TagManager; /** @@ -9,7 +10,6 @@ * @author morin */ public class GuixInitializer { - public static void initialize() { TagManager.registerGuixClasse("Button"); TagManager.registerGuixClasse("Panel"); @@ -19,3 +19,6 @@ TagManager.registerGuixClasse("Application"); } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -17,6 +17,7 @@ import org.nuiton.guix.generator.AbstractClassGenerator; import org.nuiton.guix.generator.ImplementationGenerator; import org.nuiton.guix.generator.InterfaceGenerator; +import org.nuiton.guix.generator.MainClassGenerator; import org.nuiton.guix.model.ClassDescriptor; import org.nuiton.guix.model.GuixModelObject; import org.nuiton.guix.model.Rule; @@ -53,6 +54,7 @@ protected int compilerCount; private File targetDirectory; private String rootPackage; + private String mainClass; /** * Constructor @@ -60,7 +62,7 @@ * @param files the files to compile */ public GuixLauncher(File[] files, File targetDirectory, String rootPackage, - File baseDir) { + File baseDir, String mainClass) { // Set up a simple configuration that logs on the console. this.files = files; this.targetDirectory = targetDirectory; @@ -86,6 +88,12 @@ else { classNames = null; } + if (mainClass != null) { + this.mainClass = mainClass; + } + else { + mainClass = ""; + } } /** @@ -98,6 +106,9 @@ compilerCount = 0; File destDir = targetDirectory; if (files != null) { + if (log.isInfoEnabled()) { + log.info("Start compiling"); + } guixFiles.addAll(Arrays.asList(files)); guixFileClassNames.addAll(Arrays.asList(classNames)); boolean success = true; @@ -173,7 +184,7 @@ null); XmlSerializer serializer = factory.newSerializer(); - File config = new File(targetDirectory,"config.xml"); + File config = new File(destDir,"config.xml"); serializer.setOutput(new PrintWriter(config)); serializer.startDocument("UTF-8", null); @@ -185,13 +196,14 @@ serializer.startTag("", "beans"); for (GuixModelObject mo : rootModelObjects.keySet()) { + String moClassName = mo.getClassDescriptor().getName(); //File f = new File(destDir, mo.getClassDescriptor().getName() + "ModelTree.xml"); - File out = new File(destDir, mo.getClassDescriptor().getName() + ".java"); - File outAbstract = new File(destDir, mo.getClassDescriptor().getName() + "Abstract.java"); - File outImpl = new File(destDir, mo.getClassDescriptor().getName() + "Impl.java"); + File out = new File(destDir, moClassName + ".java"); + File outAbstract = new File(destDir, moClassName + "Abstract.java"); + File outImpl = new File(destDir, moClassName + "Impl.java"); if (log.isInfoEnabled()) { - log.info(mo.getClassDescriptor().getName() + " last modification : " + new Date(rootModelObjects.get(mo).getLastModification())); + log.info(moClassName + " last modification : " + new Date(rootModelObjects.get(mo).getLastModification())); } if (rootModelObjects.get(mo).getLastModification() > out.lastModified()) { @@ -231,32 +243,68 @@ img.generate(outImpl); serializer.startTag("", "bean"); - serializer.attribute("", "id", out.getName().replace(out.getName().charAt(0), - Character.toLowerCase(out.getName().charAt(0)))); - serializer.attribute("", "class", out.getName() + "Impl"); + serializer.attribute("", "id", moClassName.replace(moClassName.charAt(0), + Character.toLowerCase(moClassName.charAt(0)))); + serializer.attribute("", "class", + mo.getClassDescriptor().getPackageName() + "." + moClassName + "Impl"); serializer.attribute("", "singleton", "false"); + serializer.endTag("", "bean"); - /*<bean id = "articlesDao" class + if ((mo.getClassDescriptor().getPackageName() + "." + mo.getClassDescriptor().getName()).equals(mainClass)) { + MainClassGenerator mcg = new MainClassGenerator(mo, destDir); + FileWriter fw = null; + try { + fw = new FileWriter(new File(destDir, "Main.java")); + fw.write(mcg.getClassContent()); + fw.close(); + } + catch (IOException ex) { + if (log.isErrorEnabled()) { + log.error(ex); + } + } + finally { + try { + fw.close(); + } + catch (IOException ex) { + log.error(ex); + } + } - ="istia.st.articles.dao.ArticlesDaoPlainJdbc"> - <constructor-arg index="0"> - <value>org.firebirdsql.jdbc.FBDriver</value> - </constructor-arg> - <constructor-arg index="1"> - <value>jdbc:firebirdsql:localhost/3050:d:/databases/dbarticles.gdb</value> - </constructor-arg> - <constructor-arg index="2"> - <value>someone</value> - </constructor-arg> - <constructor-arg index="3"> - <value>somepassword</value> - </constructor-arg> - </bean>*/ + serializer.startTag("", "bean"); + serializer.attribute("", "id", "main"); + serializer.attribute("", "class", mo.getClassDescriptor().getPackageName() + ".Main"); + serializer.startTag("", "property"); + serializer.attribute("", "name", moClassName.replace(moClassName.charAt(0), + Character.toLowerCase(moClassName.charAt(0)))); + serializer.startTag("", "ref"); + serializer.attribute("", "bean", moClassName.replace(moClassName.charAt(0), + Character.toLowerCase(moClassName.charAt(0)))); + serializer.endTag("", "ref"); + serializer.endTag("", "property"); + serializer.endTag("", "bean"); + } + /*<bean id = "articlesDao" class + ="istia.st.articles.dao.ArticlesDaoPlainJdbc"> + <constructor-arg index="0"> + <value>org.firebirdsql.jdbc.FBDriver</value> + </constructor-arg> + <constructor-arg index="1"> + <value>jdbc:firebirdsql:localhost/3050:d:/databases/dbarticles.gdb</value> + </constructor-arg> + <constructor-arg index="2"> + <value>someone</value> + </constructor-arg> + <constructor-arg index="3"> + <value>somepassword</value> + </constructor-arg> + </bean>*/ + } - else - if (log.isWarnEnabled()) { + else if (log.isWarnEnabled()) { log.warn(mo.getClassDescriptor().getName() + " has already been generated and is up to date."); } } Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedAttributeException.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedAttributeException.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedAttributeException.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -6,10 +6,8 @@ public class UnsupportedAttributeException extends CompilerException { /** Creates a new <code>UnsupportedAttributeException</code>. */ - public UnsupportedAttributeException() { - } + public UnsupportedAttributeException() {} - /** * Creates a new <code>UnsupportedAttributeException</code> with the specified detail message. * @@ -19,7 +17,6 @@ super(msg); } - /** * Creates a new <code>UnsupportedAttributeException</code> with the specified cause. * @@ -29,7 +26,6 @@ super(initCause); } - /** * Creates a new <code>UnsupportedAttributeException</code> with the specified detail message and cause. * @@ -39,4 +35,7 @@ public UnsupportedAttributeException(String msg, Throwable initCause) { super(msg, initCause); } -} \ No newline at end of file +} + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedTagException.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedTagException.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedTagException.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -4,10 +4,8 @@ public class UnsupportedTagException extends CompilerException { /** Creates a new <code>UnsupportedTagException</code>. */ - public UnsupportedTagException() { - } + public UnsupportedTagException() {} - /** * Creates a new <code>UnsupportedTagException</code> with the specified detail message. * @@ -17,7 +15,6 @@ super(msg); } - /** * Creates a new <code>UnsupportedTagException</code> with the specified cause. * @@ -27,7 +24,6 @@ super(initCause); } - /** * Creates a new <code>UnsupportedTagException</code> with the specified detail message and cause. * @@ -37,4 +33,7 @@ public UnsupportedTagException(String msg, Throwable initCause) { super(msg, initCause); } -} \ No newline at end of file +} + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,13 +1,11 @@ package org.nuiton.guix.compiler; -import org.nuiton.guix.GuixLauncher; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +//~--- non-JDK imports -------------------------------------------------------- + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + +import org.nuiton.guix.GuixLauncher; import org.nuiton.guix.model.AttributeDescriptor; import org.nuiton.guix.model.ClassDescriptor; import org.nuiton.guix.model.GuixModelObject; @@ -15,10 +13,20 @@ import org.nuiton.guix.tags.ScriptHandler; import org.nuiton.guix.tags.StyleHandler; import org.nuiton.guix.tags.TagManager; + import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import java.util.ArrayList; +import java.util.List; + /** * Compiles Guix files into model tree * @@ -28,29 +36,39 @@ /** log */ protected static final Log log = LogFactory.getLog(GuixCompiler.class); + + /** + * Integer used to give an id to the objects which don't have one specified + * by the user + */ + private int index = 1; + private StyleHandler styleHandler = new StyleHandler(); + private ScriptHandler scriptHandler = new ScriptHandler(); + + /** Directory containing the guix files */ + private File baseDir; + /** Flag to detec if an error occurs while compiling guix file */ protected boolean failed; - /** Directory containing the guix files */ - private File baseDir; - /** Guix file to compile */ - private File src; - private String srcPackage; + + /** + * Long representing the date and time of the last modification of any file + * used during compilation + */ + private long lastModification; + /** GuixLauncher instance which launched this compiler */ private GuixLauncher launcher; - private StyleHandler styleHandler = new StyleHandler(); - private ScriptHandler scriptHandler = new ScriptHandler(); + /** Root of the model */ private GuixModelObject rootMO; - /** Long representing the date and time of the last modification of any file - * used during compilation */ - private long lastModification; - /** Integer used to give an id to the objects which don't have one specified - * by the user */ - private int index = 1; - /*------------------------------------------------------------------------*/ - /*-- Constructor methods -------------------------------------------------*/ - /*------------------------------------------------------------------------*/ + /** Guix file to compile */ + private File src; + private String srcPackage; + + /* -- Constructor methods ------------------------------------------------- */ + /** * Creates a new GuixCompiler. * @@ -58,14 +76,17 @@ * @param launcher the launcher of the compiler */ public GuixCompiler(File src, GuixLauncher launcher, String srcPackage) { - this.src = src; + this.src = src; this.launcher = launcher; - if(srcPackage != null) + + if (srcPackage != null) { this.srcPackage = srcPackage; - else + } else { this.srcPackage = ""; + } + if (src != null) { - baseDir = src.getParentFile(); + baseDir = src.getParentFile(); lastModification = src.lastModified(); } } @@ -76,87 +97,116 @@ * @return the root of the model */ public GuixModelObject compile() { - if (src != null && launcher != null) { + if ((src != null) && (launcher != null)) { try { - //Creation of the Xml parser - XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); + + // Creation of the Xml parser + XmlPullParserFactory factory = + XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); + factory.setNamespaceAware(true); + XmlPullParser xpp = factory.newPullParser(); + xpp.setInput(new FileReader(src)); - //Start parsing + + // Start parsing if (xpp.getEventType() == XmlPullParser.START_DOCUMENT) { - //javaDoc of the class to create + + // javaDoc of the class to create StringBuffer doc = new StringBuffer(); + do { xpp.nextToken(); + if (xpp.getEventType() == XmlPullParser.COMMENT) { doc.append(xpp.getText()); } } while (xpp.getEventType() != XmlPullParser.START_TAG); - //resolve the package of teh superclass + + // resolve the package of teh superclass String tagNameSpace = xpp.getNamespace(); String tagName; + if (xpp.getName().lastIndexOf('.') >= 0) { tagName = xpp.getName().substring(xpp.getName().lastIndexOf('.') + 1); } else { tagName = xpp.getName(); } + String tagPackageName = resolvePackageName(tagNameSpace, xpp.getName()); - //creation of the root GuixModelObject - rootMO = new GuixModelObject(xpp.getAttributeValue("", "id"), doc.toString(), xpp.getAttributeValue("", "styleClass")); - //the class name is the name of the file minus the extension + + // creation of the root GuixModelObject + rootMO = new GuixModelObject(xpp.getAttributeValue("", "id"), doc.toString(), + xpp.getAttributeValue("", "styleClass")); + + // the class name is the name of the file minus the extension String className = src.getName().substring(0, src.getName().lastIndexOf('.')); + rootMO.setClassDescriptor(new ClassDescriptor(className, srcPackage)); rootMO.getClassDescriptor().setSuperClass(new ClassDescriptor(tagName, tagPackageName)); rootMO.setAttributeDescriptors(getAttributes(xpp)); rootMO.setChildren(new ArrayList<GuixModelObject>()); - //add the stylesheet of the CSS file with the same name as the Guix file + // add the stylesheet of the CSS file with the same name as the Guix file File styleFile = new File(src.getParentFile(), className + ".css"); + if (styleFile.exists()) { StyleSheet ss = styleHandler.autoDetectStyleFile(styleFile); + rootMO.getStyleSheets().add(ss); lastModification = Math.max(lastModification, styleFile.lastModified()); } StringBuffer script = new StringBuffer(); - //add the script in the .script file with the same name as the Guix file + + // add the script in the .script file with the same name as the Guix file File scriptFile = new File(src.getParentFile(), className + ".script"); + if (scriptFile.exists()) { script.append(scriptHandler.loadScriptFile(scriptFile)); lastModification = Math.max(lastModification, scriptFile.lastModified()); } - //reach the next START_TAG + // reach the next START_TAG do { xpp.nextToken(); - } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT); - //if not eof + } while ((xpp.getEventType() != XmlPullParser.START_TAG) + && (xpp.getEventType() != XmlPullParser.END_DOCUMENT)); + + // if not eof if (xpp.getEventType() == XmlPullParser.START_TAG) { - //compile the rest of the file + + // compile the rest of the file script.append(compile(xpp, rootMO, doc.toString())); } - //all the script tags have been recorded + + // all the script tags have been recorded rootMO.getClassDescriptor().setScript(script.toString()); - //register the root ClassDescriptor + + // register the root ClassDescriptor failed = !launcher.registerClassDescriptor(rootMO.getClassDescriptor()); + return rootMO; } } catch (XmlPullParserException ex) { - if(log.isErrorEnabled()) + if (log.isErrorEnabled()) { log.error(ex); + } } catch (IOException ex) { - if(log.isErrorEnabled()) + if (log.isErrorEnabled()) { log.error(ex); + } } } + failed = true; + return null; } - /*------------------------------------------------------------------------*/ - /*-- Compile methods -----------------------------------------------------*/ - /*------------------------------------------------------------------------*/ + /* -- Compile methods ----------------------------------------------------- */ + /** * * @param xpp the parser referencing the tag @@ -164,106 +214,128 @@ * @param javaDoc the comments above the tag, to add to its javaDoc * @return the scripts already discovered while parsing the file */ - protected StringBuffer compile(final XmlPullParser xpp, GuixModelObject previousMO, - String javaDoc) { - - StringBuffer result = new StringBuffer(); - StringBuffer doc = new StringBuffer(); + protected StringBuffer compile(final XmlPullParser xpp, GuixModelObject previousMO, String javaDoc) { + StringBuffer result = new StringBuffer(); + StringBuffer doc = new StringBuffer(); GuixModelObject prev; try { - //if the tag is a style tag - if (xpp.getName() != null && xpp.getName().equals("style")) { + + // if the tag is a style tag + if ((xpp.getName() != null) && xpp.getName().equals("style")) { File styleFile = null; - //the name of the file to load + + // the name of the file to load String source = xpp.getAttributeValue("", "source"); - //if the source attribute is specified + + // if the source attribute is specified if (source != null) { styleFile = new File(baseDir, source.replace('/', File.separatorChar)); } - //creates a new stylesheet + + // creates a new stylesheet StyleSheet ss = styleHandler.compileStyle(xpp, styleFile); + if (ss != null) { rootMO.getStyleSheets().add(ss); } - if (styleFile != null && styleFile.exists()) { + + if ((styleFile != null) && styleFile.exists()) { lastModification = Math.max(lastModification, styleFile.lastModified()); } - //the parent is still the same + // the parent is still the same prev = previousMO; - } //if the tag is a script tag - else if (xpp.getName() != null && xpp.getName().equals("script")) { + } // if the tag is a script tag + else if ((xpp.getName() != null) && xpp.getName().equals("script")) { File scriptFile = null; - //the name of the file to load + + // the name of the file to load String source = xpp.getAttributeValue("", "source"); - //if the source attribute is specified + + // if the source attribute is specified if (source != null) { scriptFile = new File(baseDir, source.replace('/', File.separatorChar)); } - //add the script to the result + + // add the script to the result result.append(scriptHandler.compileScript(xpp, scriptFile)); - if (scriptFile != null && scriptFile.exists()) { + + if ((scriptFile != null) && scriptFile.exists()) { lastModification = Math.max(lastModification, scriptFile.lastModified()); } - //the parent is still the same + + // the parent is still the same prev = previousMO; - } //if the tag is a class tag - else { - String tagNameSpace = xpp.getNamespace(); + } // if the tag is a class tag + else { + String tagNameSpace = xpp.getNamespace(); String tagPackageName = resolvePackageName(tagNameSpace, xpp.getName()); String tagName; - //if the name of the tag is the fully-qualified class name + + // if the name of the tag is the fully-qualified class name if (xpp.getName().lastIndexOf('.') >= 0) { tagName = xpp.getName().substring(xpp.getName().lastIndexOf('.') + 1); } else { tagName = xpp.getName(); } - String id = (xpp.getAttributeValue("", "id") != null ? - xpp.getAttributeValue("", "id") - : "$" + tagName + index++); - //create the GuixModelObject representing the tag - GuixModelObject mo = new GuixModelObject(id, javaDoc, - xpp.getAttributeValue("", "styleClass")); + String id = ((xpp.getAttributeValue("", "id") != null) + ? xpp.getAttributeValue("", "id") + : "$" + tagName + index++); + + // create the GuixModelObject representing the tag + GuixModelObject mo = new GuixModelObject(id, javaDoc, xpp.getAttributeValue("", "styleClass")); + mo.setParent(previousMO); mo.setClassDescriptor(new ClassDescriptor(tagName, tagPackageName)); mo.setChildren(new ArrayList<GuixModelObject>()); - //add this GuixModelObject to the children of the parent + + // add this GuixModelObject to the children of the parent previousMO.getChildren().add(mo); - //register the ClassDescriptor + // register the ClassDescriptor failed = !launcher.registerClassDescriptor(mo.getClassDescriptor()); + if (!failed) { - //parse the children of the tag + + // parse the children of the tag prev = mo; - do { - xpp.nextToken(); - //if the tag has no children - if (xpp.getEventType() == XmlPullParser.END_TAG) { - prev = prev.getParent(); - } else if (xpp.getEventType() == XmlPullParser.COMMENT) { - //add the comment to the doc of the next tag - doc.append(xpp.getText()); - } - } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT); } else { return null; } } - //if not eof + do { + xpp.nextToken(); + + // if the tag has no children + if (xpp.getEventType() == XmlPullParser.END_TAG) { + prev = prev.getParent(); + } else if (xpp.getEventType() == XmlPullParser.COMMENT) { + + // add the comment to the doc of the next tag + doc.append(xpp.getText()); + } + } while ((xpp.getEventType() != XmlPullParser.START_TAG) + && (xpp.getEventType() != XmlPullParser.END_DOCUMENT)); + + // if not eof if (xpp.getEventType() == XmlPullParser.START_TAG) { - //compile the rest of the document + + // compile the rest of the document result.append(compile(xpp, prev, doc.toString())); } } catch (XmlPullParserException ex) { - if(log.isErrorEnabled()) - log.error(ex); + if (log.isErrorEnabled()) { + log.error(ex); + } } catch (IOException ex) { - if(log.isErrorEnabled()) - log.error(ex); + if (log.isErrorEnabled()) { + log.error(ex); + } } + return result; } @@ -277,11 +349,13 @@ */ private String resolvePackageName(String tagNameSpace, String tagName) { String packageName = null; - //if there is a namespace - if (tagNameSpace != null && tagNameSpace.endsWith("*")) { + + // if there is a namespace + if ((tagNameSpace != null) && tagNameSpace.endsWith("*")) { packageName = tagNameSpace.substring(0, tagNameSpace.length() - 2); } - //if the name of the tag is the fully qualified class name + + // if the name of the tag is the fully qualified class name if (tagName.lastIndexOf('.') >= 0) { if (packageName == null) { packageName = tagName.substring(0, tagName.lastIndexOf('.')); @@ -289,11 +363,16 @@ packageName += tagName.substring(0, tagName.lastIndexOf('.')); } } - //if nor the namespace nor the fully qualified class name is defined + + // if nor the namespace nor the fully qualified class name is defined if (packageName == null) { String fullClassName = TagManager.resolveClassName(tagName); - packageName = (fullClassName == null) ? null : fullClassName.substring(0, fullClassName.lastIndexOf('.')); + + packageName = (fullClassName == null) + ? null + : fullClassName.substring(0, fullClassName.lastIndexOf('.')); } + return packageName; } @@ -307,12 +386,13 @@ */ private List<AttributeDescriptor> getAttributes(XmlPullParser xpp) { List<AttributeDescriptor> result = new ArrayList<AttributeDescriptor>(); + for (int i = 0; i < xpp.getAttributeCount(); i++) { if (!xpp.getAttributeName(i).equals("id")) { - result.add(new AttributeDescriptor( - xpp.getAttributeName(i), xpp.getAttributeValue(i))); + result.add(new AttributeDescriptor(xpp.getAttributeName(i), xpp.getAttributeValue(i))); } } + return result; } @@ -329,3 +409,4 @@ return lastModification; } } + Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSSParserConstants.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSSParserConstants.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSSParserConstants.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,3 +1,4 @@ + /* Generated By:JJTree&JavaCC: Do not edit this line. CSSParserConstants.java */ package org.nuiton.guix.css; @@ -2,69 +3,38 @@ public interface CSSParserConstants { - - int EOF = 0; - int DECIMAL_LITERAL = 7; - int INTEGER_LITERAL = 8; - int IDENTIFIER = 9; - int LETTER = 10; - int DIGIT = 11; - int PSEUDOCLASS_IDENTIFIER = 12; - int PSEUDOCLASS_COLON = 13; - int COLON = 14; - int SEMICOLON = 15; - int LEFT_BRACE = 16; - int RIGHT_BRACE = 17; - int JAVA_CODE_START = 18; - int JAVA_CODE = 19; - int JAVA_CODE_END = 20; - int PROGRAMMATIC_PSEUDOCLASS = 21; - int STRING = 22; - int HEXCOLOR = 23; - int HEXDIGIT = 24; - int EMS = 25; - int EXS = 26; - int LENGTH = 27; - - int DEFAULT = 0; - int IN_RULE = 1; - int JAVA_CODE_RULE = 2; - int IN_PSEUDOCLASS = 3; - - String[] tokenImage = { - "<EOF>", - "\" \"", - "\"\\t\"", - "\"\\n\"", - "\"\\r\"", - "<token of kind 5>", - "<token of kind 6>", - "<DECIMAL_LITERAL>", - "<INTEGER_LITERAL>", - "<IDENTIFIER>", - "<LETTER>", - "<DIGIT>", - "<PSEUDOCLASS_IDENTIFIER>", - "\":\"", - "\":\"", - "\";\"", - "\"{\"", - "\"}\"", - "<JAVA_CODE_START>", - "<JAVA_CODE>", - "<JAVA_CODE_END>", - "<PROGRAMMATIC_PSEUDOCLASS>", - "<STRING>", - "<HEXCOLOR>", - "<HEXDIGIT>", - "<EMS>", - "<EXS>", - "<LENGTH>", - "\",\"", - "\"*\"", - "\"#\"", - "\".\"", - "\"[\"", - "\"]\"", - "\"=\"", + int COLON = 14; + int DECIMAL_LITERAL = 7; + int DEFAULT = 0; + int DIGIT = 11; + int EMS = 25; + int EOF = 0; + int EXS = 26; + int HEXCOLOR = 23; + int HEXDIGIT = 24; + int IDENTIFIER = 9; + int INTEGER_LITERAL = 8; + int IN_PSEUDOCLASS = 3; + int IN_RULE = 1; + int JAVA_CODE = 19; + int JAVA_CODE_END = 20; + int JAVA_CODE_RULE = 2; + int JAVA_CODE_START = 18; + int LEFT_BRACE = 16; + int LENGTH = 27; + int LETTER = 10; + int PROGRAMMATIC_PSEUDOCLASS = 21; + int PSEUDOCLASS_COLON = 13; + int PSEUDOCLASS_IDENTIFIER = 12; + int RIGHT_BRACE = 17; + int SEMICOLON = 15; + int STRING = 22; + String[] tokenImage = { + "<EOF>", "\" \"", "\"\\t\"", "\"\\n\"", "\"\\r\"", "<token of kind 5>", "<token of kind 6>", + "<DECIMAL_LITERAL>", "<INTEGER_LITERAL>", "<IDENTIFIER>", "<LETTER>", "<DIGIT>", "<PSEUDOCLASS_IDENTIFIER>", + "\":\"", "\":\"", "\";\"", "\"{\"", "\"}\"", "<JAVA_CODE_START>", "<JAVA_CODE>", "<JAVA_CODE_END>", + "<PROGRAMMATIC_PSEUDOCLASS>", "<STRING>", "<HEXCOLOR>", "<HEXDIGIT>", "<EMS>", "<EXS>", "<LENGTH>", "\",\"", + "\"*\"", "\"#\"", "\".\"", "\"[\"", "\"]\"", "\"=\"", }; - } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSSParserTreeConstants.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSSParserTreeConstants.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSSParserTreeConstants.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,40 +1,28 @@ -/* Generated By:JJTree: Do not edit this line. .\CSSParserTreeConstants.java */ +/* Generated By:JJTree: Do not edit this line. .\CSSParserTreeConstants.java */ package org.nuiton.guix.css; public interface CSSParserTreeConstants { - public int JJTSTYLESHEET = 0; - public int JJTRULE = 1; - public int JJTSELECTORS = 2; - public int JJTSELECTOR = 3; - public int JJTJAVACLASS = 4; - public int JJTID = 5; - public int JJTCLASS = 6; - public int JJTPSEUDOCLASS = 7; - public int JJTANIMATIONPROPERTIES = 8; - public int JJTANIMATIONPROPERTY = 9; - public int JJTDECLARATION = 10; - public int JJTPROPERTY = 11; - public int JJTEXPRESSION = 12; - public int JJTJAVACODE = 13; - public int JJTIDENTIFIER = 14; - - - public String[] jjtNodeName = { - "Stylesheet", - "Rule", - "Selectors", - "Selector", - "JavaClass", - "Id", - "Class", - "PseudoClass", - "AnimationProperties", - "AnimationProperty", - "Declaration", - "Property", - "Expression", - "JavaCode", - "Identifier", + public int JJTANIMATIONPROPERTIES = 8; + public int JJTANIMATIONPROPERTY = 9; + public int JJTCLASS = 6; + public int JJTDECLARATION = 10; + public int JJTEXPRESSION = 12; + public int JJTID = 5; + public int JJTIDENTIFIER = 14; + public int JJTJAVACLASS = 4; + public int JJTJAVACODE = 13; + public int JJTPROPERTY = 11; + public int JJTPSEUDOCLASS = 7; + public int JJTRULE = 1; + public int JJTSELECTOR = 3; + public int JJTSELECTORS = 2; + public int JJTSTYLESHEET = 0; + public String[] jjtNodeName = { + "Stylesheet", "Rule", "Selectors", "Selector", "JavaClass", "Id", "Class", "PseudoClass", "AnimationProperties", + "AnimationProperty", "Declaration", "Property", "Expression", "JavaCode", "Identifier", }; } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/JJTCSSParserState.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/JJTCSSParserState.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/JJTCSSParserState.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,31 +1,34 @@ + /* Generated By:JJTree: Do not edit this line. .\JJTCSSParserState.java */ - package org.nuiton.guix.css; class JJTCSSParserState { - private java.util.Stack<Node> nodes; private java.util.Stack<Integer> marks; + private int mk; // current mark + private boolean node_created; + private java.util.Stack<Node> nodes; + private int sp; // number of nodes on stack - private int sp; // number of nodes on stack - private int mk; // current mark - private boolean node_created; - JJTCSSParserState() { nodes = new java.util.Stack<Node>(); marks = new java.util.Stack<Integer>(); - sp = 0; - mk = 0; + sp = 0; + mk = 0; } - /* Determines whether the current node was actually closed and - pushed. This should only be called in the final user action of a - node scope. */ + /* + * Determines whether the current node was actually closed and + * pushed. This should only be called in the final user action of a + * node scope. + */ boolean nodeCreated() { return node_created; } - /* Call this to reinitialize the node stack. It is called -automatically by the parser's ReInit() method. */ + /* + * Call this to reinitialize the node stack. It is called + * automatically by the parser's ReInit() method. + */ void reset() { nodes.removeAllElements(); marks.removeAllElements(); @@ -33,8 +36,10 @@ mk = 0; } - /* Returns the root node of the AST. It only makes sense to call -this after a successful parse. */ + /* + * Returns the root node of the AST. It only makes sense to call + * this after a successful parse. + */ Node rootNode() { return nodes.elementAt(0); } @@ -45,12 +50,15 @@ ++sp; } - /* Returns the node on the top of the stack, and remove it from the - stack. */ + /* + * Returns the node on the top of the stack, and remove it from the + * stack. + */ Node popNode() { if (--sp < mk) { mk = marks.pop(); } + return nodes.pop(); } @@ -59,65 +67,78 @@ return nodes.peek(); } - /* Returns the number of children on the stack in the current node - scope. */ + /* + * Returns the number of children on the stack in the current node + * scope. + */ int nodeArity() { return sp - mk; } - void clearNodeScope(Node n) { while (sp > mk) { popNode(); } + mk = marks.pop(); } - void openNodeScope(Node n) { marks.push(mk); mk = sp; n.jjtOpen(); } - - /* A definite node is constructed from a specified number of -children. That number of nodes are popped from the stack and -made the children of the definite node. Then the definite node -is pushed on to the stack. */ + /* + * A definite node is constructed from a specified number of + * children. That number of nodes are popped from the stack and + * made the children of the definite node. Then the definite node + * is pushed on to the stack. + */ void closeNodeScope(Node n, int num) { mk = marks.pop(); + while (num-- > 0) { Node c = popNode(); + c.jjtSetParent(n); n.jjtAddChild(c, num); } + n.jjtClose(); pushNode(n); node_created = true; } - - /* A conditional node is constructed if its condition is true. All -the nodes that have been pushed since the node was opened are -made children of the the conditional node, which is then pushed -on to the stack. If the condition is false the node is not -constructed and they are left on the stack. */ + /* + * A conditional node is constructed if its condition is true. All + * the nodes that have been pushed since the node was opened are + * made children of the the conditional node, which is then pushed + * on to the stack. If the condition is false the node is not + * constructed and they are left on the stack. + */ void closeNodeScope(Node n, boolean condition) { if (condition) { int a = nodeArity(); + mk = marks.pop(); + while (a-- > 0) { Node c = popNode(); + c.jjtSetParent(n); n.jjtAddChild(c, a); } + n.jjtClose(); pushNode(n); node_created = true; } else { - mk = marks.pop(); + mk = marks.pop(); node_created = false; } } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/Node.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/Node.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/Node.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,11 +1,10 @@ + /* Generated By:JJTree: Do not edit this line. Node.java */ - package org.nuiton.guix.css; -/* All AST nodes must implement this interface. It provides basic - machinery for constructing the parent and child relationships - between nodes. */ - +/*All AST nodes must implement this interface. It provides basic +machinery for constructing the parent and child relationships +between nodes. */ public interface Node { /** @@ -49,3 +48,6 @@ /** @return the number of children the node has. */ public int jjtGetNumChildren(); } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/ParseException.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/ParseException.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/ParseException.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,3 +1,4 @@ + /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ package org.nuiton.guix.css; @@ -8,13 +9,14 @@ super(); } - public ParseException(String message) { super(message); } - public ParseException(String message, int line, int column) { super(message, line, column); } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/SimpleCharStream.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/SimpleCharStream.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/SimpleCharStream.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,3 +1,4 @@ + /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */ package org.nuiton.guix.css; @@ -5,29 +6,71 @@ * An implementation of interface CharStream, where the stream is assumed to * contain only ASCII characters (without unicode processing). */ - public class SimpleCharStream { - public static final boolean staticFlag = false; - int bufsize; - int available; - int tokenBegin; - public int bufpos = -1; - protected int bufline[]; - protected int bufcolumn[]; + public static final boolean staticFlag = false; + public int bufpos = -1; + protected int column = 0; + protected int inBuf = 0; + protected int line = 1; + protected int maxNextCharInd = 0; + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + protected int tabSize = 8; + int available; + protected int bufcolumn[]; + protected char[] buffer; + protected int bufline[]; + int bufsize; + protected java.io.Reader inputStream; + int tokenBegin; - protected int column = 0; - protected int line = 1; + public SimpleCharStream(java.io.InputStream dstream) { + this(dstream, 1, 1, 4096); + } - protected boolean prevCharIsCR = false; - protected boolean prevCharIsLF = false; + public SimpleCharStream(java.io.Reader dstream) { + this(dstream, 1, 1, 4096); + } - protected java.io.Reader inputStream; + public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { + this(dstream, encoding, 1, 1, 4096); + } - protected char[] buffer; - protected int maxNextCharInd = 0; - protected int inBuf = 0; - protected int tabSize = 8; + public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn) { + this(dstream, startline, startcolumn, 4096); + } + public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn) { + this(dstream, startline, startcolumn, 4096); + } + + public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn) + throws java.io.UnsupportedEncodingException { + this(dstream, encoding, startline, startcolumn, 4096); + } + + public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn, + int buffersize) + throws java.io.UnsupportedEncodingException { + this((encoding == null) + ? new java.io.InputStreamReader(dstream) + : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + protected void setTabSize(int i) { tabSize = i; } @@ -36,48 +79,38 @@ return tabSize; } - protected void ExpandBuff(boolean wrapAround) { - char[] newbuffer = new char[bufsize + 2048]; - int newbufline[] = new int[bufsize + 2048]; - int newbufcolumn[] = new int[bufsize + 2048]; + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; try { if (wrapAround) { System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - System.arraycopy(buffer, 0, newbuffer, - bufsize - tokenBegin, bufpos); + System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); buffer = newbuffer; - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); bufline = newbufline; - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); - bufcolumn = newbufcolumn; - + bufcolumn = newbufcolumn; maxNextCharInd = (bufpos += (bufsize - tokenBegin)); } else { System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); buffer = newbuffer; - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); bufline = newbufline; - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - bufcolumn = newbufcolumn; - + bufcolumn = newbufcolumn; maxNextCharInd = (bufpos -= tokenBegin); } - } - catch (Throwable t) { + } catch (Throwable t) { throw new Error(t.getMessage()); } - - bufsize += 2048; - available = bufsize; + bufsize += 2048; + available = bufsize; tokenBegin = 0; } @@ -85,41 +118,49 @@ if (maxNextCharInd == available) { if (available == bufsize) { if (tokenBegin > 2048) { - bufpos = maxNextCharInd = 0; + bufpos = maxNextCharInd = 0; available = tokenBegin; - } else if (tokenBegin < 0) + } else if (tokenBegin < 0) { bufpos = maxNextCharInd = 0; - else + } else { ExpandBuff(false); - } else if (available > tokenBegin) + } + } else if (available > tokenBegin) { available = bufsize; - else if ((tokenBegin - available) < 2048) + } else if ((tokenBegin - available) < 2048) { ExpandBuff(true); - else + } else { available = tokenBegin; + } } int i; + try { - if ((i = inputStream.read(buffer, maxNextCharInd, - available - maxNextCharInd)) == -1) { + if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) { inputStream.close(); + throw new java.io.IOException(); - } else + } else { maxNextCharInd += i; - } - catch (java.io.IOException e) { + } + } catch (java.io.IOException e) { --bufpos; backup(0); - if (tokenBegin == -1) + + if (tokenBegin == -1) { tokenBegin = bufpos; + } + throw e; } } public char BeginToken() throws java.io.IOException { tokenBegin = -1; + char c = readChar(); + tokenBegin = bufpos; return c; @@ -130,31 +171,39 @@ if (prevCharIsLF) { prevCharIsLF = false; - line += (column = 1); + line += (column = 1); } else if (prevCharIsCR) { prevCharIsCR = false; + if (c == '\n') { prevCharIsLF = true; - } else + } else { line += (column = 1); + } } switch (c) { - case '\r': - prevCharIsCR = true; - break; - case '\n': - prevCharIsLF = true; - break; - case '\t': - column--; - column += (tabSize - (column % tabSize)); - break; - default: - break; + case '\r' : + prevCharIsCR = true; + + break; + + case '\n' : + prevCharIsLF = true; + + break; + + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + + break; + + default : + break; } - bufline[bufpos] = line; + bufline[bufpos] = line; bufcolumn[bufpos] = column; } @@ -162,18 +211,21 @@ if (inBuf > 0) { --inBuf; - if (++bufpos == bufsize) + if (++bufpos == bufsize) { bufpos = 0; + } return buffer[bufpos]; } - if (++bufpos >= maxNextCharInd) + if (++bufpos >= maxNextCharInd) { FillBuff(); + } char c = buffer[bufpos]; UpdateLineColumn(c); + return (c); } @@ -182,7 +234,6 @@ * @see #getEndColumn * @deprecated */ - public int getColumn() { return bufcolumn[bufpos]; } @@ -192,7 +243,6 @@ * @see #getEndLine * @deprecated */ - public int getLine() { return bufline[bufpos]; } @@ -214,52 +264,31 @@ } public void backup(int amount) { + inBuf += amount; - inBuf += amount; - if ((bufpos -= amount) < 0) + if ((bufpos -= amount) < 0) { bufpos += bufsize; + } } - public SimpleCharStream(java.io.Reader dstream, int startline, - int startcolumn, int buffersize) { + public void ReInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { inputStream = dstream; - line = startline; - column = startcolumn - 1; + line = startline; + column = startcolumn - 1; - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; - } - - public SimpleCharStream(java.io.Reader dstream, int startline, - int startcolumn) { - this(dstream, startline, startcolumn, 4096); - } - - public SimpleCharStream(java.io.Reader dstream) { - this(dstream, 1, 1, 4096); - } - - public void ReInit(java.io.Reader dstream, int startline, - int startcolumn, int buffersize) { - inputStream = dstream; - line = startline; - column = startcolumn - 1; - - if (buffer == null || buffersize != buffer.length) { + if ((buffer == null) || (buffersize != buffer.length)) { available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; + buffer = new char[buffersize]; + bufline = new int[buffersize]; bufcolumn = new int[buffersize]; } + prevCharIsLF = prevCharIsCR = false; - tokenBegin = inBuf = maxNextCharInd = 0; - bufpos = -1; + tokenBegin = inBuf = maxNextCharInd = 0; + bufpos = -1; } - public void ReInit(java.io.Reader dstream, int startline, - int startcolumn) { + public void ReInit(java.io.Reader dstream, int startline, int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } @@ -267,41 +296,14 @@ ReInit(dstream, 1, 1, 4096); } - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { - this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) + throws java.io.UnsupportedEncodingException { + ReInit((encoding == null) + ? new java.io.InputStreamReader(dstream) + : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); } - public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) { - this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); - } - - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException { - this(dstream, encoding, startline, startcolumn, 4096); - } - - public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn) { - this(dstream, startline, startcolumn, 4096); - } - - public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { - this(dstream, encoding, 1, 1, 4096); - } - - public SimpleCharStream(java.io.InputStream dstream) { - this(dstream, 1, 1, 4096); - } - - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { - ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); - } - - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) { + public void ReInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); } @@ -313,32 +315,30 @@ ReInit(dstream, 1, 1, 4096); } - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException { + public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn) + throws java.io.UnsupportedEncodingException { ReInit(dstream, encoding, startline, startcolumn, 4096); } - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn) { + public void ReInit(java.io.InputStream dstream, int startline, int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } public String GetImage() { - if (bufpos >= tokenBegin) + if (bufpos >= tokenBegin) { return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); - else - return new String(buffer, tokenBegin, bufsize - tokenBegin) + - new String(buffer, 0, bufpos + 1); + } else { + return new String(buffer, tokenBegin, bufsize - tokenBegin) + new String(buffer, 0, bufpos + 1); + } } public char[] GetSuffix(int len) { char[] ret = new char[len]; - if ((bufpos + 1) >= len) + if ((bufpos + 1) >= len) { System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); - else { - System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, - len - bufpos - 1); + } else { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, len - bufpos - 1); System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); } @@ -346,8 +346,8 @@ } public void Done() { - buffer = null; - bufline = null; + buffer = null; + bufline = null; bufcolumn = null; } @@ -367,32 +367,36 @@ len = bufsize - tokenBegin + bufpos + 1 + inBuf; } - int i = 0, j = 0, k; - int nextColDiff, columnDiff = 0; + int i = 0, + j = 0, k; + int nextColDiff, + columnDiff = 0; - while (i < len && - bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) { - bufline[j] = newLine; - nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + while ((i < len) && (bufline[j = start % bufsize] == bufline[k = ++start % bufsize])) { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; bufcolumn[j] = newCol + columnDiff; - columnDiff = nextColDiff; + columnDiff = nextColDiff; i++; } if (i < len) { - bufline[j] = newLine++; + bufline[j] = newLine++; bufcolumn[j] = newCol + columnDiff; while (i++ < len) { - if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) { bufline[j] = newLine++; - else + } else { bufline[j] = newLine; + } } } - line = bufline[j]; + line = bufline[j]; column = bufcolumn[j]; } +} -} + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/SimpleNode.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/SimpleNode.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/SimpleNode.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,16 +1,15 @@ + /* Generated By:JJTree: Do not edit this line. SimpleNode.java */ - package org.nuiton.guix.css; public class SimpleNode implements Node { - protected Node parent; - protected Node[] children; - protected int id; + protected Node[] children; + public Token firstToken; + protected int id; + public Token lastToken; + protected Node parent; protected CSSParser parser; - public Token firstToken; - public Token lastToken; - public SimpleNode(int i) { id = i; } @@ -20,16 +19,13 @@ parser = p; } - public int getId() { return id; } - public void jjtOpen() { - } + public void jjtOpen() {} - public void jjtClose() { - } + public void jjtClose() {} public void jjtSetParent(Node n) { parent = n; @@ -48,9 +44,11 @@ children = new Node[i + 1]; } else if (i >= children.length) { Node c[] = new Node[i + 1]; + System.arraycopy(children, 0, c, 0, children.length); children = c; } + children[i] = n; } @@ -63,15 +61,18 @@ } public int jjtGetNumChildren() { - return (children == null) ? 0 : children.length; + return (children == null) + ? 0 + : children.length; } - /* You can override these two methods in subclasses of SimpleNode to -customize the way the node appears when the tree is dumped. If -your output uses more than one line you should override -toString(String), otherwise overriding toString() is probably all -you need to do. */ - + /* + * You can override these two methods in subclasses of SimpleNode to + * customize the way the node appears when the tree is dumped. If + * your output uses more than one line you should override + * toString(String), otherwise overriding toString() is probably all + * you need to do. + */ @Override public String toString() { return getClass().getName() + "[" + getText() + "]"; @@ -81,14 +82,17 @@ return prefix + toString(); } - /* Override this method if you want to customize how the node dumps - out its children. */ - + /* + * Override this method if you want to customize how the node dumps + * out its children. + */ public void dump(String prefix) { System.out.println(toString(prefix)); + if (children != null) { for (Node aChildren : children) { SimpleNode n = (SimpleNode) aChildren; + if (n != null) { n.dump(prefix + " "); } @@ -103,16 +107,19 @@ } } - /** @return the text of the tokens comprising this node. */ public String getText() { StringBuffer text = new StringBuffer(); - Token t = firstToken; + Token t = firstToken; + while (t != null) { appendSpecialTokens(text, t.specialToken); text.append(t.image); - if (t == lastToken) + + if (t == lastToken) { break; + } + t = t.next; } @@ -120,3 +127,5 @@ } } + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/Token.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/Token.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/Token.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,3 +1,4 @@ + /* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ package org.nuiton.guix.css; @@ -2,13 +3,5 @@ /** Describes the input token stream. */ - public class Token { /** - * An integer that describes the kind of this token. This numbering - * system is determined by JavaCCParser, and a table of these numbers is - * stored in the file ...Constants.java. - */ - public int kind; - - /** * beginLine and beginColumn describe the position of the first character @@ -23,6 +16,13 @@ public String image; /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** * A reference to the next regular (non-special) token from the input * stream. If this is the last token from the input stream, or if the * token manager has not read tokens beyond this one, this field is @@ -68,9 +68,11 @@ */ public static Token newToken(int ofKind) { switch (ofKind) { - default: - return new Token(); + default : + return new Token(); } } +} -} + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/TokenMgrError.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/TokenMgrError.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/TokenMgrError.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,3 +1,4 @@ + /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ package org.nuiton.guix.css; @@ -2,18 +3,20 @@ public class TokenMgrError extends Error { + + /** Tried to change to an invalid lexical state. */ + static final int INVALID_LEXICAL_STATE = 2; + /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ + * Ordinals for various reasons why an Error of this type can be thrown. + */ /** Lexical error occured. */ static final int LEXICAL_ERROR = 0; - /** An attempt wass made to create a second instance of a static token manager. */ - static final int STATIC_LEXER_ERROR = 1; - - /** Tried to change to an invalid lexical state. */ - static final int INVALID_LEXICAL_STATE = 2; - /** Detected (and bailed out of) an infinite loop in the token manager. */ static final int LOOP_DETECTED = 3; + /** An attempt wass made to create a second instance of a static token manager. */ + static final int STATIC_LEXER_ERROR = 1; + private static final long serialVersionUID = -4308847190164230336L; + /** @@ -23,8 +26,22 @@ * one of the above 4 values. */ int errorCode; - private static final long serialVersionUID = -4308847190164230336L; + /* + * Constructors of various flavors follow. + */ + public TokenMgrError() {} + + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, + char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } + /** * Replaces unprintable characters by their espaced (or unicode escaped) * equivalents in the given string @@ -34,44 +51,55 @@ */ protected static String addEscapes(String str) { StringBuffer retval = new StringBuffer(); - char ch; + char ch; + for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { - case 0: - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u").append(s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } + case 0 : + continue; + case '\b' : + retval.append("\\b"); + + continue; + case '\t' : + retval.append("\\t"); + + continue; + case '\n' : + retval.append("\\n"); + + continue; + case '\f' : + retval.append("\\f"); + + continue; + case '\r' : + retval.append("\\r"); + + continue; + case '\"' : + retval.append("\\\""); + + continue; + case '\'' : + retval.append("\\\'"); + + continue; + case '\\' : + retval.append("\\\\"); + + continue; + default : + if ((ch = str.charAt(i)) < 0x20 || (ch > 0x7e)) { + String s = "0000" + Integer.toString(ch, 16); + + retval.append("\\u").append(s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } } } + return retval.toString(); } @@ -86,12 +114,12 @@ * @return a detailed message for the Error when it is thrown by the * token manager to indicate a lexical error. */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return ("Lexical error at line " + - errorLine + ", column " + - errorColumn + ". Encountered: " + - (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + - "after : \"" + addEscapes(errorAfter) + "\""); + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, + String errorAfter, char curChar) { + return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " + (EOFSeen + ? "<EOF> " + : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + "after : \"" + + addEscapes(errorAfter) + "\""); } /** @@ -107,20 +135,7 @@ public String getMessage() { return super.getMessage(); } +} - /* - * Constructors of various flavors follow. - */ - public TokenMgrError() { - } - - public TokenMgrError(String message, int reason) { - super(message); - errorCode = reason; - } - - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - } -} +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/AbstractClassGenerator.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/AbstractClassGenerator.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/AbstractClassGenerator.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,21 +1,18 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - package org.nuiton.guix.generator; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +//~--- non-JDK imports -------------------------------------------------------- + import org.nuiton.guix.model.GuixModelObject; +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; + /** * * @author morin */ public class AbstractClassGenerator extends GuixGenerator { - public AbstractClassGenerator(GuixModelObject gmo) { super(gmo); } @@ -24,35 +21,39 @@ public void generate(File out) { super.generate(); + if (!gmo.getJavadoc().equals("")) { + sb.append("\n/**\n* "); + sb.append(gmo.getJavadoc()); + sb.append("\n*/"); + } + sb.append("\npublic abstract class "); sb.append(gmo.getClassDescriptor().getName()); - sb.append("Abstract {\n"); - + sb.append("Abstract implements "); + sb.append(gmo.getClassDescriptor().getName()); + sb.append(" {\n"); addAttributes(gmo); - + sb.append("\n\n\t//Getters and Setters"); addGettersAndSetters(gmo); - - sb.append("\n\n}"); - + sb.append("\n\npublic abstract void test();\n\n}"); saveFile(out); } @Override protected void addGettersAndSetters(GuixModelObject gmo) { for (GuixModelObject child : gmo.getChildren()) { - sb.append(child.getId().startsWith("$") ? "\n\n\tprotected " : "\n\n\tpublic "); + sb.append("\n\n\tpublic "); sb.append(child.getClassDescriptor().getName()); sb.append(" get"); - sb.append(child.getId().replace(child.getId().charAt(0), - Character.toUpperCase(child.getId().charAt(0)))); + sb.append(child.getId().replace(child.getId().charAt(0), Character.toUpperCase(child.getId().charAt(0)))); sb.append("() {\n\t\treturn this."); - sb.append((child.getId() != null && !child.getId().equals("")) ? child.getId() : "test"); + sb.append(((child.getId() != null) &&!child.getId().equals("")) + ? child.getId() + : "test"); sb.append(";\n\t}"); - - sb.append(child.getId().startsWith("$") ? "\n\n\tprotected " : "\n\n\tpublic "); + sb.append("\n\n\tpublic "); sb.append("void set"); - sb.append(child.getId().replace(child.getId().charAt(0), - Character.toUpperCase(child.getId().charAt(0)))); + sb.append(child.getId().replace(child.getId().charAt(0), Character.toUpperCase(child.getId().charAt(0)))); sb.append("("); sb.append(child.getClassDescriptor().getName()); sb.append(" "); @@ -62,14 +63,19 @@ sb.append(" = "); sb.append(child.getId()); sb.append(";\n\t}"); - addGettersAndSetters(child); } } private void addAttributes(GuixModelObject gmo) { for (GuixModelObject child : gmo.getChildren()) { - sb.append("\tprivate "); + if (!child.getJavadoc().equals("")) { + sb.append("\n\t/**\n\t * "); + sb.append(child.getJavadoc()); + sb.append("\n\t */"); + } + + sb.append("\n\tprivate "); sb.append(child.getClassDescriptor().getName()); sb.append(" "); sb.append(child.getId()); @@ -77,5 +83,5 @@ addAttributes(child); } } +} -} Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,15 +1,20 @@ package org.nuiton.guix.generator; +//~--- non-JDK imports -------------------------------------------------------- + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.nuiton.guix.model.GuixModelObject; + +//~--- JDK imports ------------------------------------------------------------ + import java.io.File; import java.io.FileWriter; import java.io.IOException; + import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.guix.model.GuixModelObject; /** * GuixGenerator @@ -18,10 +23,10 @@ public abstract class GuixGenerator { /** log */ - protected Log log = LogFactory.getLog(GuixGenerator.class); + protected Log log = LogFactory.getLog(GuixGenerator.class); + protected StringBuffer sb = new StringBuffer(); + protected List<String> classes = new ArrayList<String>(); protected GuixModelObject gmo; - protected StringBuffer sb = new StringBuffer(); - protected List<String> classes = new ArrayList<String>(); public GuixGenerator(GuixModelObject gmo) { this.gmo = gmo; @@ -33,7 +38,6 @@ sb.append("package "); sb.append(gmo.getClassDescriptor().getPackageName()); sb.append(";\n\n"); - addImports(gmo); } @@ -42,29 +46,36 @@ protected void addImports(GuixModelObject gmo) { for (GuixModelObject child : gmo.getChildren()) { String fqn = child.getClassDescriptor().getPackageName() + "." + child.getClassDescriptor().getName(); + if (!classes.contains(fqn)) { classes.add(fqn); sb.append("import " + fqn + ";\n"); } + addImports(child); } } protected void saveFile(File out) { FileWriter fw = null; + try { fw = new FileWriter(out); fw.write(sb.toString()); fw.close(); } catch (IOException ex) { - if(log.isErrorEnabled()) + if (log.isErrorEnabled()) { log.error(ex); + } } finally { try { fw.close(); } catch (IOException ex) { - Logger.getLogger(GuixGenerator.class.getName()).log(Level.SEVERE, null, ex); + log.error(ex); } } } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/ImplementationGenerator.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/ImplementationGenerator.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/ImplementationGenerator.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,20 +1,24 @@ + /* - * To change this template, choose Tools | Templates - * and open the template in the editor. +* To change this template, choose Tools | Templates +* and open the template in the editor. */ - package org.nuiton.guix.generator; +//~--- non-JDK imports -------------------------------------------------------- + +import org.nuiton.guix.model.GuixModelObject; + +//~--- JDK imports ------------------------------------------------------------ + import java.io.File; import java.io.IOException; -import org.nuiton.guix.model.GuixModelObject; /** * * @author morin */ public class ImplementationGenerator extends GuixGenerator { - public ImplementationGenerator(GuixModelObject gmo) { super(gmo); } @@ -23,19 +27,25 @@ public void generate(File out) { super.generate(); + if (!gmo.getJavadoc().equals("")) { + sb.append("\n/**\n * "); + sb.append(gmo.getJavadoc()); + sb.append("\n */"); + } + sb.append("\npublic class "); sb.append(gmo.getClassDescriptor().getName()); sb.append("Impl extends "); sb.append(gmo.getClassDescriptor().getName()); sb.append("Abstract {\n"); - + sb.append("public void test() {System.out.println(\"ca marche\");}"); sb.append("\n\n}"); - saveFile(out); } @Override - protected void addGettersAndSetters(GuixModelObject gmo) { - } + protected void addGettersAndSetters(GuixModelObject gmo) {} +} -} + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/InterfaceGenerator.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/InterfaceGenerator.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/InterfaceGenerator.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,13 +1,19 @@ package org.nuiton.guix.generator; +//~--- non-JDK imports -------------------------------------------------------- + +import org.nuiton.guix.model.GuixModelObject; + +//~--- JDK imports ------------------------------------------------------------ + import java.io.File; import java.io.FileWriter; import java.io.IOException; + import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import org.nuiton.guix.model.GuixModelObject; /** * Generator of interfaces @@ -15,7 +21,6 @@ * @author morin */ public class InterfaceGenerator extends GuixGenerator { - public InterfaceGenerator(GuixModelObject gmo) { super(gmo); } @@ -23,40 +28,35 @@ @Override public void generate(File out) { super.generate(); - sb.append("\npublic interface "); sb.append(gmo.getClassDescriptor().getName()); sb.append(" {\n"); - + sb.append("\n\t//Getters and Setters"); addGettersAndSetters(gmo); - - sb.append("\n\n}"); - + sb.append("\n\npublic void test();\n\n}"); saveFile(out); } @Override protected void addGettersAndSetters(GuixModelObject gmo) { for (GuixModelObject child : gmo.getChildren()) { - sb.append(child.getId().startsWith("$") ? "\n\n\tprotected " : "\n\n\tpublic "); + sb.append("\n\n\tpublic "); sb.append(child.getClassDescriptor().getName()); sb.append(" get"); - sb.append(child.getId().replace(child.getId().charAt(0), - Character.toUpperCase(child.getId().charAt(0)))); + sb.append(child.getId().replace(child.getId().charAt(0), Character.toUpperCase(child.getId().charAt(0)))); sb.append("();"); - - sb.append(child.getId().startsWith("$") ? "\n\n\tprotected " : "\n\n\tpublic "); + sb.append("\n\n\tpublic "); sb.append("void set"); - sb.append(child.getId().replace(child.getId().charAt(0), - Character.toUpperCase(child.getId().charAt(0)))); + sb.append(child.getId().replace(child.getId().charAt(0), Character.toUpperCase(child.getId().charAt(0)))); sb.append("("); sb.append(child.getClassDescriptor().getName()); sb.append(" "); sb.append(child.getId()); sb.append(");"); - addGettersAndSetters(child); } } +} -} + +//~ Formatted by Jindent --- http://www.jindent.com Added: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/MainClassGenerator.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/MainClassGenerator.java (rev 0) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/MainClassGenerator.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -0,0 +1,60 @@ +package org.nuiton.guix.generator; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.nuiton.guix.model.GuixModelObject; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Generator of interfaces + * + * @author morin + */ +public class MainClassGenerator { + private StringBuffer clazz = new StringBuffer(); + + public MainClassGenerator(GuixModelObject gmo, File destDir) { + String gmoClassName = gmo.getClassDescriptor().getName(); + String gmoAttributeName = gmoClassName.replace(gmoClassName.charAt(0), + Character.toLowerCase(gmoClassName.charAt(0))); + + clazz.append("package "); + clazz.append(gmo.getClassDescriptor().getPackageName()); + clazz.append(";\n\nimport java.io.File;\n" + + "import org.springframework.beans.factory.ListableBeanFactory;\n" + + "import org.springframework.beans.factory.xml.XmlBeanFactory;\n" + + "import org.springframework.core.io.FileSystemResource;\n" + + "\npublic class Main {" + + "\n\n\tpublic static void main(String[] args) {\n" + "\t\t//usine à beans\n" + + "\t\tListableBeanFactory bf = new XmlBeanFactory(" + + "new FileSystemResource(new File(\""); + clazz.append(destDir.getAbsolutePath()); + clazz.append("/config.xml\")));\n\t\t"); + clazz.append(gmoClassName); + clazz.append(" "); + clazz.append(gmoAttributeName); + clazz.append(" = ("); + clazz.append(gmoClassName); + clazz.append(") bf.getBean(\""); + clazz.append(gmoAttributeName); + clazz.append("\");\n\t\t"); + clazz.append(gmoAttributeName); + clazz.append(".test();" + + "\n\t}\n\n}"); + } + + public String getClassContent() { + return clazz.toString(); + } +} + Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -9,6 +9,7 @@ /** Name of the attribute */ private String name; + /** Value of the attribute */ private String value; @@ -19,7 +20,7 @@ * @param value value of the attribute */ public AttributeDescriptor(String name, String value) { - this.name = name; + this.name = name; this.value = value; } @@ -42,5 +43,7 @@ public String toString() { return name + " : " + value; } - } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -9,13 +9,20 @@ /** Name of the class */ private String name; - /** Package of the class (must ends with '.*')*/ + + /** Package of the class (must ends with '.*') */ private String packageName; - /** Script declared in the guix file. - * Available only for the root GuixModelObject class.*/ + + /** + * Script declared in the guix file. + * Available only for the root GuixModelObject class. + */ private String script; - /** Superclass of the class - * Available only for the root GuixModelObject class.*/ + + /** + * Superclass of the class + * Available only for the root GuixModelObject class. + */ private ClassDescriptor superClass; /** @@ -24,8 +31,8 @@ * @param name name of the class * @param packageName name of the package */ - public ClassDescriptor(String name, String packageName){ - this.name = name; + public ClassDescriptor(String name, String packageName) { + this.name = name; this.packageName = packageName; } @@ -62,6 +69,11 @@ } public String toString() { - return (packageName != null) ? packageName + "." + name : name; + return (packageName != null) + ? packageName + "." + name + : name; } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,5 +1,7 @@ package org.nuiton.guix.model; +//~--- JDK imports ------------------------------------------------------------ + import java.util.ArrayList; import java.util.List; @@ -10,22 +12,30 @@ */ public class GuixModelObject { - /** The id of the object */ - private String id; - /** The component containing the object */ - private GuixModelObject parent; /** The children that the object contains */ private List<GuixModelObject> children = new ArrayList<GuixModelObject>(); + + /** The descriptor of the attributes of the object */ + private List<AttributeDescriptor> attributeDescriptors = new ArrayList<AttributeDescriptor>(); + + /** + * The stylesheets associated to the object + * (in case the object is a root model object) + */ + private List<StyleSheet> styleSheets = new ArrayList<StyleSheet>(); + /** The descriptor the class of the object */ private ClassDescriptor classDescriptor; - /** The descriptor of the attributes of the object */ - private List<AttributeDescriptor> attributeDescriptors - = new ArrayList<AttributeDescriptor>(); - /** The stylesheets associated to the object - * (in case the object is a root model object) */ - private List<StyleSheet> styleSheets = new ArrayList<StyleSheet>(); + + /** The id of the object */ + private String id; + /** The javaDoc of the object */ private String javadoc; + + /** The component containing the object */ + private GuixModelObject parent; + /** The style class of the object */ private String styleClass; @@ -37,8 +47,8 @@ * @param styleClass the styleclass of the object */ public GuixModelObject(String id, String javadoc, String styleClass) { - this.id = id; - this.javadoc = javadoc; + this.id = id; + this.javadoc = javadoc; this.styleClass = styleClass; } @@ -105,5 +115,7 @@ public void setStyleClass(String styleClass) { this.styleClass = styleClass; } - } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Rule.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Rule.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Rule.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,9 +1,11 @@ package org.nuiton.guix.model; +//~--- JDK imports ------------------------------------------------------------ + import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; -import java.util.List; /** * Representation of a rule of a CSS file @@ -12,9 +14,12 @@ */ public class Rule { - /** Properties of the rule : - * Maps the name of the property to its value.*/ - private Map<String,String> properties = new HashMap<String,String>(); + /** + * Properties of the rule : + * Maps the name of the property to its value. + */ + private Map<String, String> properties = new HashMap<String, String>(); + /** Selectors which the rule is applied to */ private List<Selector> selectors = new ArrayList<Selector>(); @@ -33,5 +38,7 @@ public void setSelectors(List<Selector> selectors) { this.selectors = selectors; } +} -} + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Selector.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Selector.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Selector.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,5 +1,7 @@ package org.nuiton.guix.model; +//~--- JDK imports ------------------------------------------------------------ + import java.util.ArrayList; import java.util.List; @@ -9,28 +11,40 @@ * @author morin */ public class Selector implements java.io.Serializable, Comparable<Selector> { - public static final int NEVER_APPLIES = 0; + public static final int ALWAYS_APPLIES = 4; + public static final int ALWAYS_APPLIES_INHERIT_ONLY = 3; + public static final int NEVER_APPLIES = 0; + public static final int PSEUDOCLASS_APPLIES = 2; public static final int PSEUDOCLASS_APPLIES_INHERIT_ONLY = 1; - public static final int PSEUDOCLASS_APPLIES = 2; - public static final int ALWAYS_APPLIES_INHERIT_ONLY = 3; - public static final int ALWAYS_APPLIES = 4; - /** Class which rules are applied to - * e.g. Label */ - private String javaClassName; - /** Styleclass which rules are applied to - * e.g. .bold */ - private String styleClass; - /** Pseudoclass which rules are applied to - * e.g. :hover */ - private String pseudoClass; - /** Id of the object which rules are applied to - * e.g. #label5 */ - private String id; /** List of the rules applied to the selector */ private List<Rule> rules = new ArrayList<Rule>(); /** + * Id of the object which rules are applied to + * e.g. #label5 + */ + private String id; + + /** + * Class which rules are applied to + * e.g. Label + */ + private String javaClassName; + + /** + * Pseudoclass which rules are applied to + * e.g. :hover + */ + private String pseudoClass; + + /** + * Styleclass which rules are applied to + * e.g. .bold + */ + private String styleClass; + + /** * Constructor * * @param javaClassName class which rules are applied to @@ -40,9 +54,9 @@ */ public Selector(String javaClassName, String styleClass, String pseudoClass, String id) { this.javaClassName = javaClassName; - this.styleClass = styleClass; - this.pseudoClass = pseudoClass; - this.id = id; + this.styleClass = styleClass; + this.pseudoClass = pseudoClass; + this.id = id; } public String getId() { @@ -87,31 +101,38 @@ @Override public int compareTo(Selector selector) { - - if (pseudoClass != null && selector.pseudoClass == null) { + if ((pseudoClass != null) && (selector.pseudoClass == null)) { return 1; } - if (pseudoClass == null && selector.pseudoClass != null) { + + if ((pseudoClass == null) && (selector.pseudoClass != null)) { return -1; } - if (id != null && selector.id == null) { + + if ((id != null) && (selector.id == null)) { return 1; } - if (id == null && selector.id != null) { + + if ((id == null) && (selector.id != null)) { return -1; } - if (styleClass != null && selector.styleClass == null) { + + if ((styleClass != null) && (selector.styleClass == null)) { return 1; } - if (styleClass == null && selector.styleClass != null) { + + if ((styleClass == null) && (selector.styleClass != null)) { return -1; } - if (javaClassName != null && selector.javaClassName == null) { + + if ((javaClassName != null) && (selector.javaClassName == null)) { return 1; } - if (javaClassName == null && selector.javaClassName != null) { + + if ((javaClassName == null) && (selector.javaClassName != null)) { return -1; } + return 0; } @@ -120,3 +141,6 @@ return "Selector[" + javaClassName + ", " + styleClass + ", " + pseudoClass + ", " + id + "]"; } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/StyleSheet.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/StyleSheet.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/StyleSheet.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,6 +1,7 @@ - package org.nuiton.guix.model; +//~--- JDK imports ------------------------------------------------------------ + import java.util.ArrayList; import java.util.List; @@ -32,5 +33,7 @@ public void setSelectors(List<Selector> selectors) { this.selectors = selectors; } +} -} + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JJTJavaParserState.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JJTJavaParserState.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JJTJavaParserState.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,31 +1,34 @@ + /* Generated By:JJTree: Do not edit this line. .\JJTJavaParserState.java */ - package org.nuiton.guix.parser; class JJTJavaParserState { - private java.util.Stack<Node> nodes; private java.util.Stack<Integer> marks; + private int mk; // current mark + private boolean node_created; + private java.util.Stack<Node> nodes; + private int sp; // number of nodes on stack - private int sp; // number of nodes on stack - private int mk; // current mark - private boolean node_created; - JJTJavaParserState() { nodes = new java.util.Stack<Node>(); marks = new java.util.Stack<Integer>(); - sp = 0; - mk = 0; + sp = 0; + mk = 0; } - /* Determines whether the current node was actually closed and - pushed. This should only be called in the final user action of a - node scope. */ + /* + * Determines whether the current node was actually closed and + * pushed. This should only be called in the final user action of a + * node scope. + */ boolean nodeCreated() { return node_created; } - /* Call this to reinitialize the node stack. It is called -automatically by the parser's ReInit() method. */ + /* + * Call this to reinitialize the node stack. It is called + * automatically by the parser's ReInit() method. + */ void reset() { nodes.removeAllElements(); marks.removeAllElements(); @@ -33,8 +36,10 @@ mk = 0; } - /* Returns the root node of the AST. It only makes sense to call -this after a successful parse. */ + /* + * Returns the root node of the AST. It only makes sense to call + * this after a successful parse. + */ Node rootNode() { return nodes.elementAt(0); } @@ -45,12 +50,15 @@ ++sp; } - /* Returns the node on the top of the stack, and remove it from the - stack. */ + /* + * Returns the node on the top of the stack, and remove it from the + * stack. + */ Node popNode() { if (--sp < mk) { mk = marks.pop(); } + return nodes.pop(); } @@ -59,65 +67,78 @@ return nodes.peek(); } - /* Returns the number of children on the stack in the current node - scope. */ + /* + * Returns the number of children on the stack in the current node + * scope. + */ int nodeArity() { return sp - mk; } - void clearNodeScope(Node n) { while (sp > mk) { popNode(); } + mk = marks.pop(); } - void openNodeScope(Node n) { marks.push(mk); mk = sp; n.jjtOpen(); } - - /* A definite node is constructed from a specified number of -children. That number of nodes are popped from the stack and -made the children of the definite node. Then the definite node -is pushed on to the stack. */ + /* + * A definite node is constructed from a specified number of + * children. That number of nodes are popped from the stack and + * made the children of the definite node. Then the definite node + * is pushed on to the stack. + */ void closeNodeScope(Node n, int num) { mk = marks.pop(); + while (num-- > 0) { Node c = popNode(); + c.jjtSetParent(n); n.jjtAddChild(c, num); } + n.jjtClose(); pushNode(n); node_created = true; } - - /* A conditional node is constructed if its condition is true. All -the nodes that have been pushed since the node was opened are -made children of the the conditional node, which is then pushed -on to the stack. If the condition is false the node is not -constructed and they are left on the stack. */ + /* + * A conditional node is constructed if its condition is true. All + * the nodes that have been pushed since the node was opened are + * made children of the the conditional node, which is then pushed + * on to the stack. If the condition is false the node is not + * constructed and they are left on the stack. + */ void closeNodeScope(Node n, boolean condition) { if (condition) { int a = nodeArity(); + mk = marks.pop(); + while (a-- > 0) { Node c = popNode(); + c.jjtSetParent(n); n.jjtAddChild(c, a); } + n.jjtClose(); pushNode(n); node_created = true; } else { - mk = marks.pop(); + mk = marks.pop(); node_created = false; } } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JavaParserConstants.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JavaParserConstants.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JavaParserConstants.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,3 +1,4 @@ + /* Generated By:JJTree&JavaCC: Do not edit this line. JavaParserConstants.java */ package org.nuiton.guix.parser; @@ -2,257 +3,147 @@ public interface JavaParserConstants { - - int EOF = 0; - int WHITE_SPACE = 3; - int SINGLE_LINE_COMMENT = 4; - int FORMAL_COMMENT = 5; - int MULTI_LINE_COMMENT = 6; - int ABSTRACT = 8; - int ASSERT = 9; - int BOOLEAN = 10; - int BREAK = 11; - int BYTE = 12; - int CASE = 13; - int CATCH = 14; - int CHAR = 15; - int CLASS = 16; - int CONST = 17; - int CONTINUE = 18; - int _DEFAULT = 19; - int DO = 20; - int DOUBLE = 21; - int ELSE = 22; - int ENUM = 23; - int EXTENDS = 24; - int FALSE = 25; - int FINAL = 26; - int FINALLY = 27; - int FLOAT = 28; - int FOR = 29; - int GOTO = 30; - int IF = 31; - int IMPLEMENTS = 32; - int IMPORT = 33; - int INSTANCEOF = 34; - int INT = 35; - int INTERFACE = 36; - int LONG = 37; - int NATIVE = 38; - int NEW = 39; - int NULL = 40; - int PACKAGE = 41; - int PRIVATE = 42; - int PROTECTED = 43; - int PUBLIC = 44; - int RETURN = 45; - int SHORT = 46; - int STATIC = 47; - int STRICTFP = 48; - int SUPER = 49; - int SWITCH = 50; - int SYNCHRONIZED = 51; - int THIS = 52; - int THROW = 53; - int THROWS = 54; - int TRANSIENT = 55; - int TRUE = 56; - int TRY = 57; - int VOID = 58; - int VOLATILE = 59; - int WHILE = 60; - int INTEGER_LITERAL = 61; - int DECIMAL_LITERAL = 62; - int HEX_LITERAL = 63; - int OCTAL_LITERAL = 64; - int FLOATING_POINT_LITERAL = 65; - int DECIMAL_FLOATING_POINT_LITERAL = 66; - int DECIMAL_EXPONENT = 67; - int HEXADECIMAL_FLOATING_POINT_LITERAL = 68; - int HEXADECIMAL_EXPONENT = 69; - int CHARACTER_LITERAL = 70; - int STRING_LITERAL = 71; - int IDENTIFIER = 72; - int LETTER = 73; - int PART_LETTER = 74; - int LPAREN = 75; - int RPAREN = 76; - int LBRACE = 77; - int RBRACE = 78; - int LBRACKET = 79; - int RBRACKET = 80; - int SEMICOLON = 81; - int COMMA = 82; - int DOT = 83; - int AT = 84; - int ASSIGN = 85; - int LT = 86; - int BANG = 87; - int TILDE = 88; - int HOOK = 89; - int COLON = 90; - int EQ = 91; - int LE = 92; - int GE = 93; - int NE = 94; - int SC_OR = 95; - int SC_AND = 96; - int INCR = 97; - int DECR = 98; - int PLUS = 99; - int MINUS = 100; - int STAR = 101; - int SLASH = 102; - int BIT_AND = 103; - int BIT_OR = 104; - int XOR = 105; - int REM = 106; - int LSHIFT = 107; - int PLUSASSIGN = 108; - int MINUSASSIGN = 109; - int STARASSIGN = 110; - int SLASHASSIGN = 111; - int ANDASSIGN = 112; - int ORASSIGN = 113; - int XORASSIGN = 114; - int REMASSIGN = 115; - int LSHIFTASSIGN = 116; - int RSIGNEDSHIFTASSIGN = 117; - int RUNSIGNEDSHIFTASSIGN = 118; - int ELLIPSIS = 119; - int RUNSIGNEDSHIFT = 120; - int RSIGNEDSHIFT = 121; - int GT = 122; - int STUFF_TO_IGNORE = 124; - - int DEFAULT = 0; - int IN_FORMAL_COMMENT = 1; - int IN_MULTI_LINE_COMMENT = 2; - - String[] tokenImage = { - "<EOF>", - "<token of kind 1>", - "\"/*\"", - "<WHITE_SPACE>", - "<SINGLE_LINE_COMMENT>", - "\"*/\"", - "\"*/\"", - "<token of kind 7>", - "\"abstract\"", - "\"assert\"", - "\"boolean\"", - "\"break\"", - "\"byte\"", - "\"case\"", - "\"catch\"", - "\"char\"", - "\"class\"", - "\"const\"", - "\"continue\"", - "\"default\"", - "\"do\"", - "\"double\"", - "\"else\"", - "\"enum\"", - "\"extends\"", - "\"false\"", - "\"final\"", - "\"finally\"", - "\"float\"", - "\"for\"", - "\"goto\"", - "\"if\"", - "\"implements\"", - "\"import\"", - "\"instanceof\"", - "\"int\"", - "\"interface\"", - "\"long\"", - "\"native\"", - "\"new\"", - "\"null\"", - "\"package\"", - "\"private\"", - "\"protected\"", - "\"public\"", - "\"return\"", - "\"short\"", - "\"static\"", - "\"strictfp\"", - "\"super\"", - "\"switch\"", - "\"synchronized\"", - "\"this\"", - "\"throw\"", - "\"throws\"", - "\"transient\"", - "\"true\"", - "\"try\"", - "\"void\"", - "\"volatile\"", - "\"while\"", - "<INTEGER_LITERAL>", - "<DECIMAL_LITERAL>", - "<HEX_LITERAL>", - "<OCTAL_LITERAL>", - "<FLOATING_POINT_LITERAL>", - "<DECIMAL_FLOATING_POINT_LITERAL>", - "<DECIMAL_EXPONENT>", - "<HEXADECIMAL_FLOATING_POINT_LITERAL>", - "<HEXADECIMAL_EXPONENT>", - "<CHARACTER_LITERAL>", - "<STRING_LITERAL>", - "<IDENTIFIER>", - "<LETTER>", - "<PART_LETTER>", - "\"(\"", - "\")\"", - "\"{\"", - "\"}\"", - "\"[\"", - "\"]\"", - "\";\"", - "\",\"", - "\".\"", - "\"@\"", - "\"=\"", - "\"<\"", - "\"!\"", - "\"~\"", - "\"?\"", - "\":\"", - "\"==\"", - "\"<=\"", - "\">=\"", - "\"!=\"", - "\"||\"", - "\"&&\"", - "\"++\"", - "\"--\"", - "\"+\"", - "\"-\"", - "\"*\"", - "\"/\"", - "\"&\"", - "\"|\"", - "\"^\"", - "\"%\"", - "\"<<\"", - "\"+=\"", - "\"-=\"", - "\"*=\"", - "\"/=\"", - "\"&=\"", - "\"|=\"", - "\"^=\"", - "\"%=\"", - "\"<<=\"", - "\">>=\"", - "\">>>=\"", - "\"...\"", - "\">>>\"", - "\">>\"", - "\">\"", - "\"\\u001a\"", - "<STUFF_TO_IGNORE>", + int ABSTRACT = 8; + int ANDASSIGN = 112; + int ASSERT = 9; + int ASSIGN = 85; + int AT = 84; + int BANG = 87; + int BIT_AND = 103; + int BIT_OR = 104; + int BOOLEAN = 10; + int BREAK = 11; + int BYTE = 12; + int CASE = 13; + int CATCH = 14; + int CHAR = 15; + int CHARACTER_LITERAL = 70; + int CLASS = 16; + int COLON = 90; + int COMMA = 82; + int CONST = 17; + int CONTINUE = 18; + int DECIMAL_EXPONENT = 67; + int DECIMAL_FLOATING_POINT_LITERAL = 66; + int DECIMAL_LITERAL = 62; + int DECR = 98; + int DEFAULT = 0; + int DO = 20; + int DOT = 83; + int DOUBLE = 21; + int ELLIPSIS = 119; + int ELSE = 22; + int ENUM = 23; + int EOF = 0; + int EQ = 91; + int EXTENDS = 24; + int FALSE = 25; + int FINAL = 26; + int FINALLY = 27; + int FLOAT = 28; + int FLOATING_POINT_LITERAL = 65; + int FOR = 29; + int FORMAL_COMMENT = 5; + int GE = 93; + int GOTO = 30; + int GT = 122; + int HEXADECIMAL_EXPONENT = 69; + int HEXADECIMAL_FLOATING_POINT_LITERAL = 68; + int HEX_LITERAL = 63; + int HOOK = 89; + int IDENTIFIER = 72; + int IF = 31; + int IMPLEMENTS = 32; + int IMPORT = 33; + int INCR = 97; + int INSTANCEOF = 34; + int INT = 35; + int INTEGER_LITERAL = 61; + int INTERFACE = 36; + int IN_FORMAL_COMMENT = 1; + int IN_MULTI_LINE_COMMENT = 2; + int LBRACE = 77; + int LBRACKET = 79; + int LE = 92; + int LETTER = 73; + int LONG = 37; + int LPAREN = 75; + int LSHIFT = 107; + int LSHIFTASSIGN = 116; + int LT = 86; + int MINUS = 100; + int MINUSASSIGN = 109; + int MULTI_LINE_COMMENT = 6; + int NATIVE = 38; + int NE = 94; + int NEW = 39; + int NULL = 40; + int OCTAL_LITERAL = 64; + int ORASSIGN = 113; + int PACKAGE = 41; + int PART_LETTER = 74; + int PLUS = 99; + int PLUSASSIGN = 108; + int PRIVATE = 42; + int PROTECTED = 43; + int PUBLIC = 44; + int RBRACE = 78; + int RBRACKET = 80; + int REM = 106; + int REMASSIGN = 115; + int RETURN = 45; + int RPAREN = 76; + int RSIGNEDSHIFT = 121; + int RSIGNEDSHIFTASSIGN = 117; + int RUNSIGNEDSHIFT = 120; + int RUNSIGNEDSHIFTASSIGN = 118; + int SC_AND = 96; + int SC_OR = 95; + int SEMICOLON = 81; + int SHORT = 46; + int SINGLE_LINE_COMMENT = 4; + int SLASH = 102; + int SLASHASSIGN = 111; + int STAR = 101; + int STARASSIGN = 110; + int STATIC = 47; + int STRICTFP = 48; + int STRING_LITERAL = 71; + int STUFF_TO_IGNORE = 124; + int SUPER = 49; + int SWITCH = 50; + int SYNCHRONIZED = 51; + int THIS = 52; + int THROW = 53; + int THROWS = 54; + int TILDE = 88; + int TRANSIENT = 55; + int TRUE = 56; + int TRY = 57; + int VOID = 58; + int VOLATILE = 59; + int WHILE = 60; + int WHITE_SPACE = 3; + int XOR = 105; + int XORASSIGN = 114; + int _DEFAULT = 19; + String[] tokenImage = { + "<EOF>", "<token of kind 1>", "\"/*\"", "<WHITE_SPACE>", "<SINGLE_LINE_COMMENT>", "\"*/\"", "\"*/\"", + "<token of kind 7>", "\"abstract\"", "\"assert\"", "\"boolean\"", "\"break\"", "\"byte\"", "\"case\"", + "\"catch\"", "\"char\"", "\"class\"", "\"const\"", "\"continue\"", "\"default\"", "\"do\"", "\"double\"", + "\"else\"", "\"enum\"", "\"extends\"", "\"false\"", "\"final\"", "\"finally\"", "\"float\"", "\"for\"", + "\"goto\"", "\"if\"", "\"implements\"", "\"import\"", "\"instanceof\"", "\"int\"", "\"interface\"", "\"long\"", + "\"native\"", "\"new\"", "\"null\"", "\"package\"", "\"private\"", "\"protected\"", "\"public\"", "\"return\"", + "\"short\"", "\"static\"", "\"strictfp\"", "\"super\"", "\"switch\"", "\"synchronized\"", "\"this\"", + "\"throw\"", "\"throws\"", "\"transient\"", "\"true\"", "\"try\"", "\"void\"", "\"volatile\"", "\"while\"", + "<INTEGER_LITERAL>", "<DECIMAL_LITERAL>", "<HEX_LITERAL>", "<OCTAL_LITERAL>", "<FLOATING_POINT_LITERAL>", + "<DECIMAL_FLOATING_POINT_LITERAL>", "<DECIMAL_EXPONENT>", "<HEXADECIMAL_FLOATING_POINT_LITERAL>", + "<HEXADECIMAL_EXPONENT>", "<CHARACTER_LITERAL>", "<STRING_LITERAL>", "<IDENTIFIER>", "<LETTER>", + "<PART_LETTER>", "\"(\"", "\")\"", "\"{\"", "\"}\"", "\"[\"", "\"]\"", "\";\"", "\",\"", "\".\"", "\"@\"", + "\"=\"", "\"<\"", "\"!\"", "\"~\"", "\"?\"", "\":\"", "\"==\"", "\"<=\"", "\">=\"", "\"!=\"", "\"||\"", + "\"&&\"", "\"++\"", "\"--\"", "\"+\"", "\"-\"", "\"*\"", "\"/\"", "\"&\"", "\"|\"", "\"^\"", "\"%\"", "\"<<\"", + "\"+=\"", "\"-=\"", "\"*=\"", "\"/=\"", "\"&=\"", "\"|=\"", "\"^=\"", "\"%=\"", "\"<<=\"", "\">>=\"", + "\">>>=\"", "\"...\"", "\">>>\"", "\">>\"", "\">\"", "\"\\u001a\"", "<STUFF_TO_IGNORE>", }; - } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JavaParserTreeConstants.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JavaParserTreeConstants.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/JavaParserTreeConstants.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,230 +1,142 @@ -/* Generated By:JJTree: Do not edit this line. ./JavaParserTreeConstants.java */ +/* Generated By:JJTree: Do not edit this line. ./JavaParserTreeConstants.java */ package org.nuiton.guix.parser; public interface JavaParserTreeConstants { - public int JJTLINE = 0; - public int JJTCOMPILATIONUNIT = 1; - public int JJTPACKAGEDECLARATION = 2; - public int JJTIMPORTDECLARATION = 3; - public int JJTMODIFIERS = 4; - public int JJTTYPEDECLARATION = 5; - public int JJTCLASSORINTERFACEDECLARATION = 6; - public int JJTEXTENDSLIST = 7; - public int JJTIMPLEMENTSLIST = 8; - public int JJTENUMDECLARATION = 9; - public int JJTENUMBODY = 10; - public int JJTENUMCONSTANT = 11; - public int JJTTYPEPARAMETERS = 12; - public int JJTTYPEPARAMETER = 13; - public int JJTTYPEBOUND = 14; - public int JJTCLASSORINTERFACEBODY = 15; - public int JJTCLASSORINTERFACEBODYDECLARATION = 16; - public int JJTFIELDDECLARATION = 17; - public int JJTVARIABLEDECLARATOR = 18; - public int JJTVARIABLEDECLARATORID = 19; - public int JJTVARIABLEINITIALIZER = 20; - public int JJTARRAYINITIALIZER = 21; - public int JJTMETHODDECLARATION = 22; - public int JJTMETHODDECLARATOR = 23; - public int JJTFORMALPARAMETERS = 24; - public int JJTFORMALPARAMETER = 25; - public int JJTCONSTRUCTORDECLARATION = 26; - public int JJTEXPLICITCONSTRUCTORINVOCATION = 27; - public int JJTINITIALIZER = 28; - public int JJTTYPE = 29; - public int JJTREFERENCETYPE = 30; - public int JJTCLASSORINTERFACETYPE = 31; - public int JJTTYPEARGUMENTS = 32; - public int JJTTYPEARGUMENT = 33; - public int JJTWILDCARDBOUNDS = 34; - public int JJTPRIMITIVETYPE = 35; - public int JJTRESULTTYPE = 36; - public int JJTNAME = 37; - public int JJTNAMELIST = 38; - public int JJTEXPRESSION = 39; - public int JJTASSIGNMENTOPERATOR = 40; - public int JJTASSIGNMENTEXPRESSION = 41; - public int JJTCONDITIONALEXPRESSION = 42; - public int JJTCONDITIONALOREXPRESSION = 43; - public int JJTCONDITIONALANDEXPRESSION = 44; - public int JJTINCLUSIVEOREXPRESSION = 45; - public int JJTEXCLUSIVEOREXPRESSION = 46; - public int JJTANDEXPRESSION = 47; - public int JJTEQUALITYEXPRESSION = 48; - public int JJTINSTANCEOFEXPRESSION = 49; - public int JJTRELATIONALEXPRESSION = 50; - public int JJTSHIFTEXPRESSION = 51; - public int JJTADDITIVEEXPRESSION = 52; - public int JJTMULTIPLICATIVEEXPRESSION = 53; - public int JJTUNARYEXPRESSION = 54; - public int JJTPREINCREMENTEXPRESSION = 55; - public int JJTPREDECREMENTEXPRESSION = 56; - public int JJTUNARYEXPRESSIONNOTPLUSMINUS = 57; - public int JJTCASTLOOKAHEAD = 58; - public int JJTPOSTFIXEXPRESSION = 59; - public int JJTPOSTFIXOPERATOR = 60; - public int JJTCASTEXPRESSION = 61; - public int JJTPRIMARYEXPRESSION = 62; - public int JJTMEMBERSELECTOR = 63; - public int JJTPRIMARYPREFIX = 64; - public int JJTPRIMARYSUFFIX = 65; - public int JJTLITERAL = 66; - public int JJTBOOLEANLITERAL = 67; - public int JJTNULLLITERAL = 68; - public int JJTARGUMENTS = 69; - public int JJTARGUMENTLIST = 70; - public int JJTALLOCATIONEXPRESSION = 71; - public int JJTARRAYDIMSANDINITS = 72; - public int JJTSTATEMENT = 73; - public int JJTASSERTSTATEMENT = 74; - public int JJTLABELEDSTATEMENT = 75; - public int JJTBLOCK = 76; - public int JJTBLOCKSTATEMENT = 77; - public int JJTLOCALVARIABLEDECLARATION = 78; - public int JJTEMPTYSTATEMENT = 79; - public int JJTSTATEMENTEXPRESSION = 80; - public int JJTSWITCHSTATEMENT = 81; - public int JJTSWITCHLABEL = 82; - public int JJTIFSTATEMENT = 83; - public int JJTWHILESTATEMENT = 84; - public int JJTDOSTATEMENT = 85; - public int JJTFORSTATEMENT = 86; - public int JJTFORINIT = 87; - public int JJTSTATEMENTEXPRESSIONLIST = 88; - public int JJTFORUPDATE = 89; - public int JJTBREAKSTATEMENT = 90; - public int JJTCONTINUESTATEMENT = 91; - public int JJTRETURNSTATEMENT = 92; - public int JJTTHROWSTATEMENT = 93; - public int JJTSYNCHRONIZEDSTATEMENT = 94; - public int JJTTRYSTATEMENT = 95; - public int JJTRUNSIGNEDSHIFT = 96; - public int JJTRSIGNEDSHIFT = 97; - public int JJTANNOTATION = 98; - public int JJTNORMALANNOTATION = 99; - public int JJTMARKERANNOTATION = 100; - public int JJTSINGLEMEMBERANNOTATION = 101; - public int JJTMEMBERVALUEPAIRS = 102; - public int JJTMEMBERVALUEPAIR = 103; - public int JJTMEMBERVALUE = 104; - public int JJTMEMBERVALUEARRAYINITIALIZER = 105; - public int JJTANNOTATIONTYPEDECLARATION = 106; - public int JJTANNOTATIONTYPEBODY = 107; - public int JJTANNOTATIONTYPEMEMBERDECLARATION = 108; - public int JJTDEFAULTVALUE = 109; - - - public String[] jjtNodeName = { - "Line", - "CompilationUnit", - "PackageDeclaration", - "ImportDeclaration", - "Modifiers", - "TypeDeclaration", - "ClassOrInterfaceDeclaration", - "ExtendsList", - "ImplementsList", - "EnumDeclaration", - "EnumBody", - "EnumConstant", - "TypeParameters", - "TypeParameter", - "TypeBound", - "ClassOrInterfaceBody", - "ClassOrInterfaceBodyDeclaration", - "FieldDeclaration", - "VariableDeclarator", - "VariableDeclaratorId", - "VariableInitializer", - "ArrayInitializer", - "MethodDeclaration", - "MethodDeclarator", - "FormalParameters", - "FormalParameter", - "ConstructorDeclaration", - "ExplicitConstructorInvocation", - "Initializer", - "Type", - "ReferenceType", - "ClassOrInterfaceType", - "TypeArguments", - "TypeArgument", - "WildcardBounds", - "PrimitiveType", - "ResultType", - "Name", - "NameList", - "Expression", - "AssignmentOperator", - "AssignmentExpression", - "ConditionalExpression", - "ConditionalOrExpression", - "ConditionalAndExpression", - "InclusiveOrExpression", - "ExclusiveOrExpression", - "AndExpression", - "EqualityExpression", - "InstanceOfExpression", - "RelationalExpression", - "ShiftExpression", - "AdditiveExpression", - "MultiplicativeExpression", - "UnaryExpression", - "PreIncrementExpression", - "PreDecrementExpression", - "UnaryExpressionNotPlusMinus", - "CastLookahead", - "PostfixExpression", - "PostfixOperator", - "CastExpression", - "PrimaryExpression", - "MemberSelector", - "PrimaryPrefix", - "PrimarySuffix", - "Literal", - "BooleanLiteral", - "NullLiteral", - "Arguments", - "ArgumentList", - "AllocationExpression", - "ArrayDimsAndInits", - "Statement", - "AssertStatement", - "LabeledStatement", - "Block", - "BlockStatement", - "LocalVariableDeclaration", - "EmptyStatement", - "StatementExpression", - "SwitchStatement", - "SwitchLabel", - "IfStatement", - "WhileStatement", - "DoStatement", - "ForStatement", - "ForInit", - "StatementExpressionList", - "ForUpdate", - "BreakStatement", - "ContinueStatement", - "ReturnStatement", - "ThrowStatement", - "SynchronizedStatement", - "TryStatement", - "RUNSIGNEDSHIFT", - "RSIGNEDSHIFT", - "Annotation", - "NormalAnnotation", - "MarkerAnnotation", - "SingleMemberAnnotation", - "MemberValuePairs", - "MemberValuePair", - "MemberValue", - "MemberValueArrayInitializer", - "AnnotationTypeDeclaration", - "AnnotationTypeBody", - "AnnotationTypeMemberDeclaration", - "DefaultValue", + public int JJTADDITIVEEXPRESSION = 52; + public int JJTALLOCATIONEXPRESSION = 71; + public int JJTANDEXPRESSION = 47; + public int JJTANNOTATION = 98; + public int JJTANNOTATIONTYPEBODY = 107; + public int JJTANNOTATIONTYPEDECLARATION = 106; + public int JJTANNOTATIONTYPEMEMBERDECLARATION = 108; + public int JJTARGUMENTLIST = 70; + public int JJTARGUMENTS = 69; + public int JJTARRAYDIMSANDINITS = 72; + public int JJTARRAYINITIALIZER = 21; + public int JJTASSERTSTATEMENT = 74; + public int JJTASSIGNMENTEXPRESSION = 41; + public int JJTASSIGNMENTOPERATOR = 40; + public int JJTBLOCK = 76; + public int JJTBLOCKSTATEMENT = 77; + public int JJTBOOLEANLITERAL = 67; + public int JJTBREAKSTATEMENT = 90; + public int JJTCASTEXPRESSION = 61; + public int JJTCASTLOOKAHEAD = 58; + public int JJTCLASSORINTERFACEBODY = 15; + public int JJTCLASSORINTERFACEBODYDECLARATION = 16; + public int JJTCLASSORINTERFACEDECLARATION = 6; + public int JJTCLASSORINTERFACETYPE = 31; + public int JJTCOMPILATIONUNIT = 1; + public int JJTCONDITIONALANDEXPRESSION = 44; + public int JJTCONDITIONALEXPRESSION = 42; + public int JJTCONDITIONALOREXPRESSION = 43; + public int JJTCONSTRUCTORDECLARATION = 26; + public int JJTCONTINUESTATEMENT = 91; + public int JJTDEFAULTVALUE = 109; + public int JJTDOSTATEMENT = 85; + public int JJTEMPTYSTATEMENT = 79; + public int JJTENUMBODY = 10; + public int JJTENUMCONSTANT = 11; + public int JJTENUMDECLARATION = 9; + public int JJTEQUALITYEXPRESSION = 48; + public int JJTEXCLUSIVEOREXPRESSION = 46; + public int JJTEXPLICITCONSTRUCTORINVOCATION = 27; + public int JJTEXPRESSION = 39; + public int JJTEXTENDSLIST = 7; + public int JJTFIELDDECLARATION = 17; + public int JJTFORINIT = 87; + public int JJTFORMALPARAMETER = 25; + public int JJTFORMALPARAMETERS = 24; + public int JJTFORSTATEMENT = 86; + public int JJTFORUPDATE = 89; + public int JJTIFSTATEMENT = 83; + public int JJTIMPLEMENTSLIST = 8; + public int JJTIMPORTDECLARATION = 3; + public int JJTINCLUSIVEOREXPRESSION = 45; + public int JJTINITIALIZER = 28; + public int JJTINSTANCEOFEXPRESSION = 49; + public int JJTLABELEDSTATEMENT = 75; + public int JJTLINE = 0; + public int JJTLITERAL = 66; + public int JJTLOCALVARIABLEDECLARATION = 78; + public int JJTMARKERANNOTATION = 100; + public int JJTMEMBERSELECTOR = 63; + public int JJTMEMBERVALUE = 104; + public int JJTMEMBERVALUEARRAYINITIALIZER = 105; + public int JJTMEMBERVALUEPAIR = 103; + public int JJTMEMBERVALUEPAIRS = 102; + public int JJTMETHODDECLARATION = 22; + public int JJTMETHODDECLARATOR = 23; + public int JJTMODIFIERS = 4; + public int JJTMULTIPLICATIVEEXPRESSION = 53; + public int JJTNAME = 37; + public int JJTNAMELIST = 38; + public int JJTNORMALANNOTATION = 99; + public int JJTNULLLITERAL = 68; + public int JJTPACKAGEDECLARATION = 2; + public int JJTPOSTFIXEXPRESSION = 59; + public int JJTPOSTFIXOPERATOR = 60; + public int JJTPREDECREMENTEXPRESSION = 56; + public int JJTPREINCREMENTEXPRESSION = 55; + public int JJTPRIMARYEXPRESSION = 62; + public int JJTPRIMARYPREFIX = 64; + public int JJTPRIMARYSUFFIX = 65; + public int JJTPRIMITIVETYPE = 35; + public int JJTREFERENCETYPE = 30; + public int JJTRELATIONALEXPRESSION = 50; + public int JJTRESULTTYPE = 36; + public int JJTRETURNSTATEMENT = 92; + public int JJTRSIGNEDSHIFT = 97; + public int JJTRUNSIGNEDSHIFT = 96; + public int JJTSHIFTEXPRESSION = 51; + public int JJTSINGLEMEMBERANNOTATION = 101; + public int JJTSTATEMENT = 73; + public int JJTSTATEMENTEXPRESSION = 80; + public int JJTSTATEMENTEXPRESSIONLIST = 88; + public int JJTSWITCHLABEL = 82; + public int JJTSWITCHSTATEMENT = 81; + public int JJTSYNCHRONIZEDSTATEMENT = 94; + public int JJTTHROWSTATEMENT = 93; + public int JJTTRYSTATEMENT = 95; + public int JJTTYPE = 29; + public int JJTTYPEARGUMENT = 33; + public int JJTTYPEARGUMENTS = 32; + public int JJTTYPEBOUND = 14; + public int JJTTYPEDECLARATION = 5; + public int JJTTYPEPARAMETER = 13; + public int JJTTYPEPARAMETERS = 12; + public int JJTUNARYEXPRESSION = 54; + public int JJTUNARYEXPRESSIONNOTPLUSMINUS = 57; + public int JJTVARIABLEDECLARATOR = 18; + public int JJTVARIABLEDECLARATORID = 19; + public int JJTVARIABLEINITIALIZER = 20; + public int JJTWHILESTATEMENT = 84; + public int JJTWILDCARDBOUNDS = 34; + public String[] jjtNodeName = { + "Line", "CompilationUnit", "PackageDeclaration", "ImportDeclaration", "Modifiers", "TypeDeclaration", + "ClassOrInterfaceDeclaration", "ExtendsList", "ImplementsList", "EnumDeclaration", "EnumBody", "EnumConstant", + "TypeParameters", "TypeParameter", "TypeBound", "ClassOrInterfaceBody", "ClassOrInterfaceBodyDeclaration", + "FieldDeclaration", "VariableDeclarator", "VariableDeclaratorId", "VariableInitializer", "ArrayInitializer", + "MethodDeclaration", "MethodDeclarator", "FormalParameters", "FormalParameter", "ConstructorDeclaration", + "ExplicitConstructorInvocation", "Initializer", "Type", "ReferenceType", "ClassOrInterfaceType", + "TypeArguments", "TypeArgument", "WildcardBounds", "PrimitiveType", "ResultType", "Name", "NameList", + "Expression", "AssignmentOperator", "AssignmentExpression", "ConditionalExpression", "ConditionalOrExpression", + "ConditionalAndExpression", "InclusiveOrExpression", "ExclusiveOrExpression", "AndExpression", + "EqualityExpression", "InstanceOfExpression", "RelationalExpression", "ShiftExpression", "AdditiveExpression", + "MultiplicativeExpression", "UnaryExpression", "PreIncrementExpression", "PreDecrementExpression", + "UnaryExpressionNotPlusMinus", "CastLookahead", "PostfixExpression", "PostfixOperator", "CastExpression", + "PrimaryExpression", "MemberSelector", "PrimaryPrefix", "PrimarySuffix", "Literal", "BooleanLiteral", + "NullLiteral", "Arguments", "ArgumentList", "AllocationExpression", "ArrayDimsAndInits", "Statement", + "AssertStatement", "LabeledStatement", "Block", "BlockStatement", "LocalVariableDeclaration", "EmptyStatement", + "StatementExpression", "SwitchStatement", "SwitchLabel", "IfStatement", "WhileStatement", "DoStatement", + "ForStatement", "ForInit", "StatementExpressionList", "ForUpdate", "BreakStatement", "ContinueStatement", + "ReturnStatement", "ThrowStatement", "SynchronizedStatement", "TryStatement", "RUNSIGNEDSHIFT", "RSIGNEDSHIFT", + "Annotation", "NormalAnnotation", "MarkerAnnotation", "SingleMemberAnnotation", "MemberValuePairs", + "MemberValuePair", "MemberValue", "MemberValueArrayInitializer", "AnnotationTypeDeclaration", + "AnnotationTypeBody", "AnnotationTypeMemberDeclaration", "DefaultValue", }; } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Node.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Node.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Node.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,11 +1,10 @@ + /* Generated By:JJTree: Do not edit this line. Node.java */ - package org.nuiton.guix.parser; -/* All AST nodes must implement this interface. It provides basic - machinery for constructing the parent and child relationships - between nodes. */ - +/*All AST nodes must implement this interface. It provides basic +machinery for constructing the parent and child relationships +between nodes. */ public interface Node { /** @@ -49,3 +48,6 @@ /** @return the number of children the node has. */ public int jjtGetNumChildren(); } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/ParseException.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/ParseException.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/ParseException.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,3 +1,4 @@ + /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ package org.nuiton.guix.parser; @@ -11,38 +12,42 @@ * mechanisms so long as you retain the public fields. */ public class ParseException extends org.nuiton.guix.CompilerException { - int line; - int column; private static final long serialVersionUID = 6179854408401024700L; + /** The end of line string for this machine. */ + protected String eol = System.getProperty("line.separator", "\n"); + int column; + /** - * This constructor is used by the method "generateParseException" - * in the generated parser. Calling this constructor generates - * a new object of this type with the fields "currentToken", - * "expectedTokenSequences", and "tokenImage" set. The boolean - * flag "specialConstructor" is also set to true to indicate that - * this constructor was used to create this object. - * This constructor calls its super class with the empty string - * to force the "toString" method of parent class "Throwable" to - * print the error message in the form: - * ParseException: <result of getMessage> - * - * @param currentTokenVal ? - * @param expectedTokenSequencesVal ? - * @param tokenImageVal ? + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. */ - public ParseException(Token currentTokenVal, - int[][] expectedTokenSequencesVal, - String[] tokenImageVal - ) { - super(""); - specialConstructor = true; - currentToken = currentTokenVal; - expectedTokenSequences = expectedTokenSequencesVal; - tokenImage = tokenImageVal; - } + public Token currentToken; /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + int line; + + /** + * This variable determines which constructor was used to create + * this object and thereby affects the semantics of the + * "getMessage" method (see below). + */ + protected boolean specialConstructor; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** * The following constructors are for use by you for whatever * purpose you can think of. Constructing the exception in this * manner makes the exception behave in the normal way - i.e., as @@ -51,7 +56,6 @@ * relevant information. The JavaCC generated code does not use * these constructors. */ - public ParseException() { super(); specialConstructor = false; @@ -65,40 +69,35 @@ public ParseException(String message, int line, int column) { super(message); specialConstructor = false; - this.line = line; - this.column = column; + this.line = line; + this.column = column; } - /** - * This variable determines which constructor was used to create - * this object and thereby affects the semantics of the - * "getMessage" method (see below). + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. The boolean + * flag "specialConstructor" is also set to true to indicate that + * this constructor was used to create this object. + * This constructor calls its super class with the empty string + * to force the "toString" method of parent class "Throwable" to + * print the error message in the form: + * ParseException: <result of getMessage> + * + * @param currentTokenVal ? + * @param expectedTokenSequencesVal ? + * @param tokenImageVal ? */ - protected boolean specialConstructor; + public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal) { + super(""); + specialConstructor = true; + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } /** - * This is the last token that has been consumed successfully. If - * this object has been created due to a parse error, the token - * followng this token will (therefore) be the first error token. - */ - public Token currentToken; - - /** - * Each entry in this array is an array of integers. Each array - * of integers represents a sequence of tokens (by their ordinal - * values) that is expected at this point of the parse. - */ - public int[][] expectedTokenSequences; - - /** - * This is a reference to the "tokenImage" array of the generated - * parser within which the parse error occurred. This array is - * defined in the generated ...Constants interface. - */ - public String[] tokenImage; - - /** * This method has the standard behavior when this object has been * created using the standard constructors. Otherwise, it uses * "currentToken" and "expectedTokenSequences" to generate a parse @@ -112,43 +111,58 @@ if (!specialConstructor) { return super.getMessage(); } + StringBuffer expected = new StringBuffer(); - int maxSize = 0; + int maxSize = 0; + for (int[] expectedTokenSequence : expectedTokenSequences) { if (maxSize < expectedTokenSequence.length) { maxSize = expectedTokenSequence.length; } + for (int anExpectedTokenSequence : expectedTokenSequence) { expected.append(tokenImage[anExpectedTokenSequence]).append(" "); } + if (expectedTokenSequence[expectedTokenSequence.length - 1] != 0) { expected.append("..."); } + expected.append(eol).append(" "); } + String retval = "Encountered \""; - Token tok = currentToken.next; + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { - if (i != 0) retval += " "; + if (i != 0) { + retval += " "; + } + if (tok.kind == 0) { retval += tokenImage[0]; + break; } + retval += add_escapes(tok.image); - tok = tok.next; + tok = tok.next; } + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += "." + eol; + if (expectedTokenSequences.length == 1) { retval += "Was expecting:" + eol + " "; } else { retval += "Was expecting one of:" + eol + " "; } + retval += expected.toString(); + return retval; } - public int getLine() { return line; } @@ -157,9 +171,6 @@ return column; } - /** The end of line string for this machine. */ - protected String eol = System.getProperty("line.separator", "\n"); - /** * Used to convert raw characters to their escaped version * when these raw version cannot be used as part of an ASCII @@ -170,45 +181,58 @@ */ protected String add_escapes(String str) { StringBuffer retval = new StringBuffer(); - char ch; + char ch; + for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { - case 0: - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u").append(s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } + case 0 : + continue; + case '\b' : + retval.append("\\b"); + + continue; + case '\t' : + retval.append("\\t"); + + continue; + case '\n' : + retval.append("\\n"); + + continue; + case '\f' : + retval.append("\\f"); + + continue; + case '\r' : + retval.append("\\r"); + + continue; + case '\"' : + retval.append("\\\""); + + continue; + case '\'' : + retval.append("\\\'"); + + continue; + case '\\' : + retval.append("\\\\"); + + continue; + default : + if ((ch = str.charAt(i)) < 0x20 || (ch > 0x7e)) { + String s = "0000" + Integer.toString(ch, 16); + + retval.append("\\u").append(s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } } } + return retval.toString(); - } + } +} -} + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,19 +1,20 @@ + /* Generated By:JJTree: Do not edit this line. SimpleNode.java */ - package org.nuiton.guix.parser; +//~--- non-JDK imports -------------------------------------------------------- + import org.nuiton.guix.model.ClassDescriptor; public class SimpleNode implements Node { - protected Node parent; - protected Node[] children; - protected int id; - protected JavaParser parser; - public Token firstToken; - public Token lastToken; + protected Node[] children; + public Token firstToken; + protected int id; private ClassDescriptor javaType; + public Token lastToken; + protected Node parent; + protected JavaParser parser; - public SimpleNode(int i) { id = i; } @@ -23,16 +24,13 @@ parser = p; } - public int getId() { return id; } - public void jjtOpen() { - } + public void jjtOpen() {} - public void jjtClose() { - } + public void jjtClose() {} public void jjtSetParent(Node n) { parent = n; @@ -46,12 +44,10 @@ return (SimpleNode) parent; } - public ClassDescriptor getJavaType() { return javaType; } - public void setJavaType(ClassDescriptor javaType) { this.javaType = javaType; } @@ -61,9 +57,11 @@ children = new Node[i + 1]; } else if (i >= children.length) { Node c[] = new Node[i + 1]; + System.arraycopy(children, 0, c, 0, children.length); children = c; } + children[i] = n; } @@ -76,15 +74,18 @@ } public int jjtGetNumChildren() { - return (children == null) ? 0 : children.length; + return (children == null) + ? 0 + : children.length; } - /* You can override these two methods in subclasses of SimpleNode to -customize the way the node appears when the tree is dumped. If -your output uses more than one line you should override -toString(String), otherwise overriding toString() is probably all -you need to do. */ - + /* + * You can override these two methods in subclasses of SimpleNode to + * customize the way the node appears when the tree is dumped. If + * your output uses more than one line you should override + * toString(String), otherwise overriding toString() is probably all + * you need to do. + */ @Override public String toString() { return getClass().getName() + "[" + getText() + "]"; @@ -94,14 +95,17 @@ return prefix + toString(); } - /* Override this method if you want to customize how the node dumps - out its children. */ - + /* + * Override this method if you want to customize how the node dumps + * out its children. + */ public void dump(String prefix) { System.out.println(toString(prefix)); + if (children != null) { for (Node aChildren : children) { SimpleNode n = (SimpleNode) aChildren; + if (n != null) { n.dump(prefix + " "); } @@ -116,16 +120,19 @@ } } - /** @return the text of the tokens comprising this node. */ public String getText() { StringBuffer text = new StringBuffer(); - Token t = firstToken; + Token t = firstToken; + while (t != null) { appendSpecialTokens(text, t.specialToken); text.append(t.image); - if (t == lastToken) + + if (t == lastToken) { break; + } + t = t.next; } @@ -133,3 +140,5 @@ } } + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Token.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Token.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Token.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,3 +1,4 @@ + /* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ package org.nuiton.guix.parser; @@ -2,10 +3,3 @@ /** Describes the input token stream. */ - public class Token { - /** - * An integer that describes the kind of this token. This numbering - * system is determined by JavaCCParser, and a table of these numbers is - * stored in the file ...Constants.java. - */ - public int kind; @@ -22,6 +16,13 @@ public String image; /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** * A reference to the next regular (non-special) token from the input * stream. If this is the last token from the input stream, or if the * token manager has not read tokens beyond this one, this field is @@ -64,12 +65,13 @@ */ public static final Token newToken(int ofKind) { switch (ofKind) { - default: - return new Token(); - case JavaParserConstants.RUNSIGNEDSHIFT: - case JavaParserConstants.RSIGNEDSHIFT: - case JavaParserConstants.GT: - return new GTToken(); + default : + return new Token(); + + case JavaParserConstants.RUNSIGNEDSHIFT : + case JavaParserConstants.RSIGNEDSHIFT : + case JavaParserConstants.GT : + return new GTToken(); } } @@ -77,3 +79,6 @@ int realKind = JavaParserConstants.GT; } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/TokenMgrError.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/TokenMgrError.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/TokenMgrError.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,3 +1,4 @@ + /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ package org.nuiton.guix.parser; @@ -2,18 +3,20 @@ public class TokenMgrError extends Error { + + /** Tried to change to an invalid lexical state. */ + static final int INVALID_LEXICAL_STATE = 2; + /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ + * Ordinals for various reasons why an Error of this type can be thrown. + */ /** Lexical error occured. */ static final int LEXICAL_ERROR = 0; - /** An attempt wass made to create a second instance of a static token manager. */ - static final int STATIC_LEXER_ERROR = 1; - - /** Tried to change to an invalid lexical state. */ - static final int INVALID_LEXICAL_STATE = 2; - /** Detected (and bailed out of) an infinite loop in the token manager. */ static final int LOOP_DETECTED = 3; + /** An attempt wass made to create a second instance of a static token manager. */ + static final int STATIC_LEXER_ERROR = 1; + private static final long serialVersionUID = -9131500865453532454L; + /** @@ -23,8 +26,22 @@ * one of the above 4 values. */ int errorCode; - private static final long serialVersionUID = -9131500865453532454L; + /* + * Constructors of various flavors follow. + */ + public TokenMgrError() {} + + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, + char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } + /** * Replaces unprintable characters by their espaced (or unicode escaped) * equivalents in the given string @@ -34,44 +51,55 @@ */ protected static String addEscapes(String str) { StringBuffer retval = new StringBuffer(); - char ch; + char ch; + for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { - case 0: - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u").append(s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } + case 0 : + continue; + case '\b' : + retval.append("\\b"); + + continue; + case '\t' : + retval.append("\\t"); + + continue; + case '\n' : + retval.append("\\n"); + + continue; + case '\f' : + retval.append("\\f"); + + continue; + case '\r' : + retval.append("\\r"); + + continue; + case '\"' : + retval.append("\\\""); + + continue; + case '\'' : + retval.append("\\\'"); + + continue; + case '\\' : + retval.append("\\\\"); + + continue; + default : + if ((ch = str.charAt(i)) < 0x20 || (ch > 0x7e)) { + String s = "0000" + Integer.toString(ch, 16); + + retval.append("\\u").append(s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } } } + return retval.toString(); } @@ -86,12 +114,12 @@ * @return a detailed message for the Error when it is thrown by the * token manager to indicate a lexical error. */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return ("Lexical error at line " + - errorLine + ", column " + - errorColumn + ". Encountered: " + - (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + - "after : \"" + addEscapes(errorAfter) + "\""); + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, + String errorAfter, char curChar) { + return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " + (EOFSeen + ? "<EOF> " + : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + "after : \"" + + addEscapes(errorAfter) + "\""); } /** @@ -107,20 +135,7 @@ public String getMessage() { return super.getMessage(); } +} - /* - * Constructors of various flavors follow. - */ - public TokenMgrError() { - } - - public TokenMgrError(String message, int reason) { - super(message); - errorCode = reason; - } - - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - } -} +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,11 +1,16 @@ package org.nuiton.guix.tags; +//~--- non-JDK imports -------------------------------------------------------- + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +//~--- JDK imports ------------------------------------------------------------ + import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.StringWriter; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; /** * Handles the <code><script></code> tag. @@ -23,12 +28,14 @@ */ public String loadScriptFile(File scriptFile) throws IOException { StringWriter scriptBuffer = new StringWriter(); - FileReader in = new FileReader(scriptFile); - char[] readBuffer = new char[2048]; - int c; + FileReader in = new FileReader(scriptFile); + char[] readBuffer = new char[2048]; + int c; + while ((c = in.read(readBuffer)) > 0) { scriptBuffer.write(readBuffer, 0, c); } + return scriptBuffer.toString(); } @@ -42,24 +49,26 @@ * @throws IOException * @throws XmlPullParserException */ - public String compileScript(XmlPullParser xpp, File scriptFile) - throws IOException, XmlPullParserException { - + public String compileScript(XmlPullParser xpp, File scriptFile) throws IOException, XmlPullParserException { StringBuffer script = new StringBuffer(); - if(scriptFile != null && scriptFile.exists()) + + if ((scriptFile != null) && scriptFile.exists()) { script.append(loadScriptFile(scriptFile)); + } xpp.nextToken(); + if (xpp.getEventType() == XmlPullParser.CDSECT) { script.append(xpp.getText()); } + while ((xpp.getEventType() != XmlPullParser.END_TAG) || (!xpp.getName().equals("script"))) { xpp.nextToken(); } - do { - xpp.nextToken(); - } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT); - + return script.toString(); } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,18 +1,10 @@ - package org.nuiton.guix.tags; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +//~--- non-JDK imports -------------------------------------------------------- + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.nuiton.guix.css.CSSParser; import org.nuiton.guix.css.CSSParserConstants; import org.nuiton.guix.css.CSSParserTreeConstants; @@ -21,9 +13,24 @@ import org.nuiton.guix.model.Rule; import org.nuiton.guix.model.Selector; import org.nuiton.guix.model.StyleSheet; + import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * Handles the <code><style></code> tag. * @@ -32,8 +39,9 @@ public class StyleHandler { /** log */ - protected static final Log log = LogFactory.getLog(TagManager.class); - /** List of the selectors */ + protected static final Log log = LogFactory.getLog(TagManager.class); + + /** List of the selectors */ private List<Selector> selectors = new ArrayList<Selector>(); /** @@ -46,12 +54,14 @@ */ private String loadStyleFile(File styleFile) throws FileNotFoundException, IOException { StringWriter styleBuffer = new StringWriter(); - FileReader in = new FileReader(styleFile); - char[] readBuffer = new char[2048]; - int c; + FileReader in = new FileReader(styleFile); + char[] readBuffer = new char[2048]; + int c; + while ((c = in.read(readBuffer)) > 0) { styleBuffer.write(readBuffer, 0, c); } + return styleBuffer.toString(); } @@ -85,81 +95,94 @@ * while parsing the guix file */ public StyleSheet compileStyle(XmlPullParser xpp, File styleFile) throws IOException, XmlPullParserException { - StyleSheet result = null; + StyleSheet result = null; + StringBuffer style = new StringBuffer(); - StringBuffer style = new StringBuffer(); - if(styleFile != null && styleFile.exists()) + if ((styleFile != null) && styleFile.exists()) { style.append(loadStyleFile(styleFile)); + } xpp.nextToken(); + do { switch (xpp.getEventType()) { - case XmlPullParser.START_TAG: - if(log.isWarnEnabled()) - log.warn("<style> tag may not contain child elements: " + xpp.getName()); - break; - case XmlPullParser.TEXT: - break;// fall through - case XmlPullParser.CDSECT: - style.append(xpp.getText()); - xpp.nextToken(); - break; + case XmlPullParser.START_TAG : + if (log.isWarnEnabled()) { + log.warn("<style> tag may not contain child elements: " + xpp.getName()); + } + + break; + + case XmlPullParser.TEXT : + break; // fall through + + case XmlPullParser.CDSECT : + style.append(xpp.getText()); + xpp.nextToken(); + + break; } } while ((xpp.getEventType() != XmlPullParser.END_TAG) && (!xpp.getName().equals("style"))); - - //analyze the content of the CSS + + // analyze the content of the CSS result = processStylesheet(style.toString()); - //reaches next START_TAG - do { - xpp.nextToken(); - } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT); - return result; - } /** * Analyses a selector node - * + * * @param selector the selector node to analyse * @return a Selector with the class, styleclass, pseudoclass and/or id * which rules will be applied to */ protected Selector processSelector(SimpleNode selector) { - //chack if it is a selector + + // chack if it is a selector if (selector.getId() != CSSParserTreeConstants.JJTSELECTOR) { throw new IllegalArgumentException("argument node is not a Selector"); } + String javaClassName = null; - String styleClass = null; - String pseudoClass = null; - String id = null; + String styleClass = null; + String pseudoClass = null; + String id = null; for (int i = 0; i < selector.jjtGetNumChildren(); i++) { SimpleNode child = selector.getChild(i); + switch (child.getId()) { - //class - case CSSParserTreeConstants.JJTJAVACLASS: - if (!child.getText().trim().equals("*")) { - javaClassName = child.getText(); - } - break; - //styleclass - case CSSParserTreeConstants.JJTCLASS: - styleClass = child.getText().substring(1); - break; - //pseudoclass - case CSSParserTreeConstants.JJTPSEUDOCLASS: - pseudoClass = child.getText().substring(1); - break; - //id - case CSSParserTreeConstants.JJTID: - id = child.getText().substring(1); - break; - //error if other - default: - throw new IllegalStateException("unexpected child of Selector node, type=" + child.getId()); + + // class + case CSSParserTreeConstants.JJTJAVACLASS : + if (!child.getText().trim().equals("*")) { + javaClassName = child.getText(); + } + + break; + + // styleclass + case CSSParserTreeConstants.JJTCLASS : + styleClass = child.getText().substring(1); + + break; + + // pseudoclass + case CSSParserTreeConstants.JJTPSEUDOCLASS : + pseudoClass = child.getText().substring(1); + + break; + + // id + case CSSParserTreeConstants.JJTID : + id = child.getText().substring(1); + + break; + + // error if other + default : + throw new IllegalStateException("unexpected child of Selector node, type=" + child.getId()); } } @@ -173,60 +196,76 @@ * @return a Rule containing the properties and the selectors of the rule */ protected Rule processRule(SimpleNode ruleNode) { - //checks if it is a rule + + // checks if it is a rule if (ruleNode.getId() != CSSParserTreeConstants.JJTRULE) { throw new IllegalArgumentException("argument node is not a Rule"); } SimpleNode selectorsNode = ruleNode.getChild(0); + assert selectorsNode.getId() == CSSParserTreeConstants.JJTSELECTORS : "expected node to be of type Selectors"; List<Selector> ruleSelectors = new ArrayList<Selector>(); - //analyses each selector + + // analyses each selector for (int i = 0; i < selectorsNode.jjtGetNumChildren(); i++) { SimpleNode selectorNode = selectorsNode.getChild(i); - Selector selector = processSelector(selectorNode); + Selector selector = processSelector(selectorNode); + ruleSelectors.add(selector); - //records the selector if it has not been recorded yet + + // records the selector if it has not been recorded yet if (!selectorRecorded(selector)) { selectors.add(selector); } } Map<String, String> properties = new HashMap<String, String>(); - //records the properties + + // records the properties for (int i = 1; i < ruleNode.jjtGetNumChildren(); i++) { SimpleNode declarationNode = ruleNode.getChild(i); + if (declarationNode.getId() == CSSParserTreeConstants.JJTDECLARATION) { - String key = declarationNode.getChild(0).getText(); + String key = declarationNode.getChild(0).getText(); SimpleNode valueNode = declarationNode.getChild(1); - String value = valueNode.getText(); + String value = valueNode.getText(); + if (valueNode.firstToken.kind == CSSParserConstants.STRING) { value = value.substring(1, value.length() - 1); } + properties.put(key, value); } } - //creates the new rule + + // creates the new rule Rule rule = new Rule(); + rule.setSelectors(ruleSelectors); + for (Selector selector : ruleSelectors) { selector.getRules().add(rule); } + rule.setProperties(properties); + return rule; } /** * Analyses the CSS - * + * * @param stylesheetText the content of the CSS file or the style tag * @return the StyleSheet containing the rules of the CSS file or the style tag */ protected StyleSheet processStylesheet(String stylesheetText) { - //parses the CSS - CSSParser p = new CSSParser(new StringReader(stylesheetText)); + + // parses the CSS + CSSParser p = new CSSParser(new StringReader(stylesheetText)); SimpleNode node; + try { node = p.Stylesheet(); } catch (ParseException ex) { @@ -234,16 +273,20 @@ } List<Rule> rules = new ArrayList<Rule>(); - //analyses each rule + + // analyses each rule for (int i = 0; i < node.jjtGetNumChildren(); i++) { SimpleNode ruleNode = node.getChild(i); - Rule rule = processRule(ruleNode); + Rule rule = processRule(ruleNode); + rules.add(rule); } - + StyleSheet styleSheet = new StyleSheet(); + styleSheet.setRules(rules); styleSheet.setSelectors(selectors); + return styleSheet; } @@ -255,18 +298,37 @@ */ private boolean selectorRecorded(Selector newSelector) { for (Selector selector : selectors) { - boolean areJavaClassNamesNull = newSelector.getJavaClassName() == null && selector.getJavaClassName() == null; - boolean areJavaClassNamesNotNull = newSelector.getJavaClassName() != null && selector.getJavaClassName() != null; - boolean areStyleClassesNull = newSelector.getStyleClass() == null && selector.getStyleClass() == null; - boolean areStyleClassesNotNull = newSelector.getStyleClass() != null && selector.getStyleClass() != null; - boolean arePseudoClassesNull = newSelector.getPseudoClass() == null && selector.getPseudoClass() == null; - boolean arePseudoClassesNotNull = newSelector.getPseudoClass() != null && selector.getPseudoClass() != null; - boolean areIdsNull = newSelector.getId() == null && selector.getId() == null; - boolean areIdsNotNull = newSelector.getId() != null && selector.getId() != null; - if ((areJavaClassNamesNull || (areJavaClassNamesNotNull && newSelector.getJavaClassName().equals(selector.getJavaClassName()))) && (areStyleClassesNull || (areStyleClassesNotNull && newSelector.getStyleClass().equals(selector.getStyleClass()))) && (arePseudoClassesNull || (arePseudoClassesNotNull && newSelector.getPseudoClass().equals(selector.getPseudoClass()))) && (areIdsNull || (areIdsNotNull && newSelector.getId().equals(selector.getId())))) { + boolean areJavaClassNamesNull = (newSelector.getJavaClassName() == null) + && (selector.getJavaClassName() == null); + boolean areJavaClassNamesNotNull = (newSelector.getJavaClassName() != null) + && (selector.getJavaClassName() != null); + boolean areStyleClassesNull = (newSelector.getStyleClass() == null) + && (selector.getStyleClass() == null); + boolean areStyleClassesNotNull = (newSelector.getStyleClass() != null) + && (selector.getStyleClass() != null); + boolean arePseudoClassesNull = (newSelector.getPseudoClass() == null) + && (selector.getPseudoClass() == null); + boolean arePseudoClassesNotNull = (newSelector.getPseudoClass() != null) + && (selector.getPseudoClass() != null); + boolean areIdsNull = (newSelector.getId() == null) && (selector.getId() == null); + boolean areIdsNotNull = (newSelector.getId() != null) && (selector.getId() != null); + + if ((areJavaClassNamesNull || (areJavaClassNamesNotNull && newSelector.getJavaClassName() + .equals(selector + .getJavaClassName()))) && (areStyleClassesNull || (areStyleClassesNotNull && newSelector + .getStyleClass() + .equals(selector + .getStyleClass()))) && (arePseudoClassesNull || (arePseudoClassesNotNull && newSelector + .getPseudoClass() + .equals(selector.getPseudoClass()))) && (areIdsNull || (areIdsNotNull && newSelector + .getId().equals(selector.getId())))) { return true; } } + return false; } } + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java =================================================================== --- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -1,258 +1,286 @@ package org.nuiton.guix.tags; +//~--- non-JDK imports -------------------------------------------------------- + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +//~--- JDK imports ------------------------------------------------------------ + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Manages tags of the .guix files. */ public class TagManager { - /** log */ - protected static final Log log = LogFactory.getLog(TagManager.class); - /** - * Namespace for Guix's non-class tags, such as <Button;>. The namespace normally does not - * need to be specified but can be used to resolve ambiguities. - */ - public static final String GUIX_NAMESPACE = "org.nuiton.guix.*"; - /** Maps simple tag names to their default namespaces (package names). */ - private static Map<String, String> defaultNamespaces = new HashMap<String, String>(); + /** + * Namespace for Guix's non-class tags, such as <Button;>. The namespace normally does not + * need to be specified but can be used to resolve ambiguities. + */ + public static final String GUIX_NAMESPACE = "org.nuiton.guix.*"; - /** Keeps track of whether or not named classes exist. */ - private static Map<String, Boolean> classExistenceCache = new HashMap<String, Boolean>(); + /** log */ + protected static final Log log = LogFactory.getLog(TagManager.class); /** List of the Guix classes such as <Button;> */ protected static List<String> guixClasses = new ArrayList<String>(); + /** Maps simple tag names to their default namespaces (package names). */ + private static Map<String, String> defaultNamespaces = new HashMap<String, String>(); - private TagManager() { /* not instantiable */ } + /** Keeps track of whether or not named classes exist. */ + private static Map<String, Boolean> classExistenceCache = new HashMap<String, Boolean>(); + private TagManager() { /* not instantiable */ + } - /*public static void reset(boolean verbose) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { - registeredBeans.clear(); - registeredTags.clear(); - defaultNamespaces.clear(); - CompiledObjectDecorator.reset(); - JAXXCompilerLaunchor.loadLibraries(verbose); - }*/ + /* + * public static void reset(boolean verbose) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { + * registeredBeans.clear(); + * registeredTags.clear(); + * defaultNamespaces.clear(); + * CompiledObjectDecorator.reset(); + * JAXXCompilerLaunchor.loadLibraries(verbose); + * } + */ + /** + * Maps a class tag to a specific <code>TagHandler</code>. When a tag representing the bean class is + * encountered (either the class' simple name, if it is unambiguous, or its fully-qualified name), the specified + * <code>TagHandler</code> will be invoked to compile it. + * + * @param beanClass the class to associate with a <code>TagHandler</code> + * @param handler the <code>TagHandler</code> class, which must descend from <code>DefaultObjectHandler</code> + * @throws IllegalArgumentException if the handler class does not descend from <code>DefaultObjectHandler</code> + */ - /** - * Maps a class tag to a specific <code>TagHandler</code>. When a tag representing the bean class is - * encountered (either the class' simple name, if it is unambiguous, or its fully-qualified name), the specified - * <code>TagHandler</code> will be invoked to compile it. - * - * @param beanClass the class to associate with a <code>TagHandler</code> - * @param handler the <code>TagHandler</code> class, which must descend from <code>DefaultObjectHandler</code> - * @throws IllegalArgumentException if the handler class does not descend from <code>DefaultObjectHandler</code> - */ - /*public static <T extends TagHandler> void registerBean(ClassDescriptor beanClass, Class<T> handler) { - if (!DefaultObjectHandler.class.isAssignableFrom(handler)) { - throw new IllegalArgumentException("handler class must be a subclass of DefaultObjectHandler"); - } - registeredBeans.put(beanClass, handler); - if (log.isDebugEnabled()) { - log.debug(beanClass + " : " + handler); - } - String name = beanClass.getName(); - int dotPos = name.lastIndexOf("."); - String namespace = name.substring(0, dotPos + 1) + "*"; - name = name.substring(dotPos + 1); - registerDefaultNamespace(name, namespace); - }*/ + /* + * public static <T extends TagHandler> void registerBean(ClassDescriptor beanClass, Class<T> handler) { + * if (!DefaultObjectHandler.class.isAssignableFrom(handler)) { + * throw new IllegalArgumentException("handler class must be a subclass of DefaultObjectHandler"); + * } + * registeredBeans.put(beanClass, handler); + * if (log.isDebugEnabled()) { + * log.debug(beanClass + " : " + handler); + * } + * String name = beanClass.getName(); + * int dotPos = name.lastIndexOf("."); + * String namespace = name.substring(0, dotPos + 1) + "*"; + * name = name.substring(dotPos + 1); + * registerDefaultNamespace(name, namespace); + * } + */ + /** + * Sets the default namespace for a tag. When the tag is encountered with no namespace specified, + * the specified namespace will be assumed. Mapping the same tag to two or more default namespaces + * removes the mapping and marks the entry as being ambiguous (by putting a <code>null</code> + * value into the map); this causes an error to be thrown if the tag is used without a namespace being + * specified. + * <p/> + * Java package names on tags are automatically converted into namespaces (e.g. <javax.swing.JButton/> + * and <JButton xmlns="javax.swing.*"/> are equivalent), so tags with package names are considered + * to have namespaces specified. + * + * @param tag tag name + * @param namespace namespace + */ + public static void registerDefaultNamespace(String tag, String namespace) { + if (defaultNamespaces.containsKey(tag) && (defaultNamespaces.get(tag) != null) + &&!defaultNamespaces.get(tag).equals(namespace)) { + defaultNamespaces.put(tag, null); // tag name is now ambiguous + } else { + defaultNamespaces.put(tag, namespace); + } + } - /** - * Sets the default namespace for a tag. When the tag is encountered with no namespace specified, - * the specified namespace will be assumed. Mapping the same tag to two or more default namespaces - * removes the mapping and marks the entry as being ambiguous (by putting a <code>null</code> - * value into the map); this causes an error to be thrown if the tag is used without a namespace being - * specified. - * <p/> - * Java package names on tags are automatically converted into namespaces (e.g. <javax.swing.JButton/> - * and <JButton xmlns="javax.swing.*"/> are equivalent), so tags with package names are considered - * to have namespaces specified. - * - * @param tag tag name - * @param namespace namespace - */ - public static void registerDefaultNamespace(String tag, String namespace) { - if (defaultNamespaces.containsKey(tag) - && defaultNamespaces.get(tag) != null - && !defaultNamespaces.get(tag).equals(namespace)) { - defaultNamespaces.put(tag, null); // tag name is now ambiguous - } else { - defaultNamespaces.put(tag, namespace); - } - } - /** - * + * * @param className */ public static void registerGuixClasse(String className) { guixClasses.add(className); } - /** - * Registers a <code>TagHandler</code> for a tag. When a tag with the given name and namespace - * is encountered, the <code>TagHandler's compileFirstPass</code> and <code>compileSecondPass</code> - * methods will be invoked to handle it. - * <p/> - * It is not an error to register an already-registered tag and namespace combination. The new mapping - * will replace the old mapping. - * - * @param namespace the tag's namespace - * @param tag the simple name of the tag - * @param handler the <code>TagHandler</code> which should process the tag - */ - /*public static <T extends TagHandler> void registerTag(String namespace, String tag, T handler) { - if (namespace == null) { - namespace = "*"; - } - //System.out.println("registerTag "+namespace+" : "+tag+" : "+handler); - if (log.isDebugEnabled()) { - log.debug(tag + " : " + handler); - } - registeredTags.put(new QName(namespace, tag), handler); - registerDefaultNamespace(tag, namespace); - }*/ + /** + * Registers a <code>TagHandler</code> for a tag. When a tag with the given name and namespace + * is encountered, the <code>TagHandler's compileFirstPass</code> and <code>compileSecondPass</code> + * methods will be invoked to handle it. + * <p/> + * It is not an error to register an already-registered tag and namespace combination. The new mapping + * will replace the old mapping. + * + * @param namespace the tag's namespace + * @param tag the simple name of the tag + * @param handler the <code>TagHandler</code> which should process the tag + */ + /* + * public static <T extends TagHandler> void registerTag(String namespace, String tag, T handler) { + * if (namespace == null) { + * namespace = "*"; + * } + * //System.out.println("registerTag "+namespace+" : "+tag+" : "+handler); + * if (log.isDebugEnabled()) { + * log.debug(tag + " : " + handler); + * } + * registeredTags.put(new QName(namespace, tag), handler); + * registerDefaultNamespace(tag, namespace); + * } + */ - /** - * Returns the <code>TagHandler</code> that should be used to process the specified tag. - * If the tag represents the class name of an uncompiled <code>.jaxx</code> file, the - * <code>.jaxx</code> is first compiled. - * - * @param namespace the tag's namespace (may be <code>null</code>) - * @param tag the tag's simple name - * @param compiler the current <code>JAXXCompiler</code> - * @return the <code>TagHandler</code> for the tag - * @throws jaxx.CompilerException ? - */ - /*public static TagHandler getTagHandler(String namespace, String tag, JAXXCompiler compiler) throws CompilerException { - return getTagHandler(namespace, tag, false, compiler); - }*/ + /** + * Returns the <code>TagHandler</code> that should be used to process the specified tag. + * If the tag represents the class name of an uncompiled <code>.jaxx</code> file, the + * <code>.jaxx</code> is first compiled. + * + * @param namespace the tag's namespace (may be <code>null</code>) + * @param tag the tag's simple name + * @param compiler the current <code>JAXXCompiler</code> + * @return the <code>TagHandler</code> for the tag + * @throws jaxx.CompilerException ? + */ + /* + * public static TagHandler getTagHandler(String namespace, String tag, JAXXCompiler compiler) throws CompilerException { + * return getTagHandler(namespace, tag, false, compiler); + * } + */ - /*private static String getNamespace(ClassDescriptor beanClass) { - String packageName = beanClass.getPackageName(); - return packageName != null ? packageName + ".*" : "*"; + /* + * private static String getNamespace(ClassDescriptor beanClass) { + * String packageName = beanClass.getPackageName(); + * return packageName != null ? packageName + ".*" : "*"; + * + * } + */ - }*/ + /* + * private static String getSimpleName(ClassDescriptor beanClass) { + * String packageName = beanClass.getPackageName(); + * if (packageName != null) { + * assert beanClass.getName().startsWith(packageName); + * return beanClass.getName().substring(packageName.length() + 1); + * } + * return beanClass.getName(); + * } + */ + /** + * @param beanClass the tag class + * @return the <code>TagHandler</code> that should be used to process the specified class. + * Only <code>TagHandlers</code> previously registered with <code>registerBean</code> + * are considered. + * @throws jaxx.CompilerException ? + */ - /*private static String getSimpleName(ClassDescriptor beanClass) { - String packageName = beanClass.getPackageName(); - if (packageName != null) { - assert beanClass.getName().startsWith(packageName); - return beanClass.getName().substring(packageName.length() + 1); - } - return beanClass.getName(); - }*/ + /* + * public static DefaultObjectHandler getTagHandler(ClassDescriptor beanClass) throws CompilerException { + * try { + * if (beanClass == null) { + * throw new NullPointerException(); + * } + * String namespace = getNamespace(beanClass); + * String tag = getSimpleName(beanClass); + * DefaultObjectHandler handler = (DefaultObjectHandler) registeredTags.get(new QName(namespace, tag)); + * if (handler == null) { + * Class<? extends TagHandler> handlerClass = registeredBeans.get(beanClass); + * if (handlerClass == null) { + * throw new CompilerException("unable to find handler for " + beanClass); + * } + * Constructor<? extends TagHandler> constructor = handlerClass.getConstructor(ClassDescriptor.class); + * handler = (DefaultObjectHandler) constructor.newInstance(beanClass); + * registerTag(namespace, tag, handler); + * } + * return handler; + * } + * catch (InstantiationException e) { + * throw new RuntimeException(e); + * } + * catch (NoSuchMethodException e) { + * throw new RuntimeException(e); + * } + * catch (IllegalAccessException e) { + * throw new RuntimeException(e); + * } + * catch (InvocationTargetException e) { + * throw new RuntimeException(e); + * } + * } + */ - - /** - * @param beanClass the tag class - * @return the <code>TagHandler</code> that should be used to process the specified class. - * Only <code>TagHandlers</code> previously registered with <code>registerBean</code> - * are considered. - * @throws jaxx.CompilerException ? - */ - /*public static DefaultObjectHandler getTagHandler(ClassDescriptor beanClass) throws CompilerException { - try { - if (beanClass == null) { - throw new NullPointerException(); - } - String namespace = getNamespace(beanClass); - String tag = getSimpleName(beanClass); - DefaultObjectHandler handler = (DefaultObjectHandler) registeredTags.get(new QName(namespace, tag)); - if (handler == null) { - Class<? extends TagHandler> handlerClass = registeredBeans.get(beanClass); - if (handlerClass == null) { - throw new CompilerException("unable to find handler for " + beanClass); - } - Constructor<? extends TagHandler> constructor = handlerClass.getConstructor(ClassDescriptor.class); - handler = (DefaultObjectHandler) constructor.newInstance(beanClass); - registerTag(namespace, tag, handler); - } - return handler; - } - catch (InstantiationException e) { - throw new RuntimeException(e); - } - catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - }*/ - /** * Tests if a class exists * * @param className name of the class we want to know if it exists * @return true if the class exists */ - private static boolean classExists(String className) { - if (classExistenceCache.containsKey(className)) { - return classExistenceCache.get(className); - } + private static boolean classExists(String className) { + if (classExistenceCache.containsKey(className)) { + return classExistenceCache.get(className); + } - boolean found = false; + boolean found = false; - try { - Class.forName(className); - found = true; - }catch (ClassNotFoundException e) { + try { + Class.forName(className); + found = true; + } catch (ClassNotFoundException e) { + // ignore ? + } catch (NoClassDefFoundError e) { // we get this instead of ClassNotFoundException on case-insensitive file systems when + + // looking up a class with the wrong case } - catch (NoClassDefFoundError e) { // we get this instead of ClassNotFoundException on case-insensitive file systems when - // looking up a class with the wrong case - } - - classExistenceCache.put(className, found); - return found; - } + classExistenceCache.put(className, found); - /** - * Resolves a simple class name (like <code>Object</code> or <code>String</code>) to its fully-qualified name. Inner - * classes should be represented as they would appear in Java source code (e.g. JPopupMenu.Separator). Fully-qualified names, - * such as <code>java.lang.Object</code> are legal and will be returned unmodified (and in fact it is generally impossible to - * even know whether a given reference is fully qualified until it has been resolved). Returns <code>null</code> if no matching - * class could be found. - * - * @param name name to resolve - * @param compiler compile to use - * @return the resolved fqn class name - */ - public static String resolveClassName(String name) { - if (name.endsWith("[]")) - return resolveClassName(name.substring(0, name.length() - 2)) + "[]"; - if (name.indexOf("<") != -1) - name = name.substring(0, name.indexOf("<")); // strip off generic types - name = name.intern(); - if (name.equals("boolean") || name.equals("byte") || name.equals("short") || name.equals("int") || - name.equals("long") || name.equals("float") || name.equals("double") || name.equals("char")) - return name; - - if (guixClasses.contains(name)) { + return found; + } + + /** + * Resolves a simple class name (like <code>Object</code> or <code>String</code>) to its fully-qualified name. Inner + * classes should be represented as they would appear in Java source code (e.g. JPopupMenu.Separator). Fully-qualified names, + * such as <code>java.lang.Object</code> are legal and will be returned unmodified (and in fact it is generally impossible to + * even know whether a given reference is fully qualified until it has been resolved). Returns <code>null</code> if no matching + * class could be found. + * + * @param name name to resolve + * @param compiler compile to use + * @return the resolved fqn class name + */ + public static String resolveClassName(String name) { + if (name.endsWith("[]")) { + return resolveClassName(name.substring(0, name.length() - 2)) + "[]"; + } + + if (name.indexOf("<") != -1) { + name = name.substring(0, name.indexOf("<")); // strip off generic types + } + + name = name.intern(); + + if (name.equals("boolean") || name.equals("byte") || name.equals("short") || name.equals("int") + || name.equals("long") || name.equals("float") || name.equals("double") || name.equals("char")) { + return name; + } + + if (guixClasses.contains(name)) { return GUIX_NAMESPACE.substring(0, GUIX_NAMESPACE.lastIndexOf('*')) + name; - } - //if the name of the tag is the fully qualified class name - if(name.lastIndexOf('.') >= 0) { + } + + // if the name of the tag is the fully qualified class name + if (name.lastIndexOf('.') >= 0) { return name; } - return null; - } -} \ No newline at end of file + return null; + } +} + + +//~ Formatted by Jindent --- http://www.jindent.com Modified: guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java =================================================================== --- guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -22,7 +22,7 @@ public void compileTest() { GuixInitializer.initialize(); - GuixLauncher gl = new GuixLauncher(null,null,null,null); + GuixLauncher gl = new GuixLauncher(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); @@ -31,7 +31,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()); + gl = new GuixLauncher(new File[]{f2},dir2,"org.nuiton.guix",f2.getParentFile(), null); assertTrue(gl.files == null || gl.classNames.length == gl.files.length); assertTrue(gl.compile()); } @@ -41,7 +41,7 @@ */ @Test public void registerClassDescriptorTest() { - GuixLauncher gl = new GuixLauncher(null,null,null,null); + GuixLauncher gl = new GuixLauncher(null,null,null,null,null); assertFalse(gl.registerClassDescriptor(null)); assertFalse(gl.registerClassDescriptor(new ClassDescriptor(null, null))); Modified: guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java =================================================================== --- guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java 2009-05-06 16:33:39 UTC (rev 1394) +++ guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java 2009-05-07 15:19:37 UTC (rev 1395) @@ -17,7 +17,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()); + "org.nuiton.guix",f2.getParentFile(),null); GuixCompiler gc = new GuixCompiler(null, null,null); assertNull(gc.compile());
participants (1)
-
kmorin@users.labs.libre-entreprise.org