Author: tchemit Date: 2008-01-12 21:37:23 +0000 (Sat, 12 Jan 2008) New Revision: 164 Modified: trunk/jaxx/src/java/jaxx/compiler/JAXXCompiler.java trunk/jaxx/src/java/jaxx/compiler/ScriptManager.java trunk/jaxx/src/java/jaxx/tags/DefaultObjectHandler.java Log: correction des ; manquant dans les scripts g?\195?\169n?\195?\169r?\195?\169s mise en conformit?\195?\169 du code Modified: trunk/jaxx/src/java/jaxx/compiler/JAXXCompiler.java =================================================================== --- trunk/jaxx/src/java/jaxx/compiler/JAXXCompiler.java 2008-01-12 21:32:32 UTC (rev 163) +++ trunk/jaxx/src/java/jaxx/compiler/JAXXCompiler.java 2008-01-12 21:37:23 UTC (rev 164) @@ -1001,8 +1001,9 @@ public void run() { DefaultObjectHandler handler = (DefaultObjectHandler) TagManager.getTagHandler(null, finalClassName, JAXXCompiler.this); - if (handler == null) + if (handler == null) { throw new CompilerException("Internal error: missing TagHandler for '" + finalClassName + "'"); + } handler.registerCompiledObject(tag, JAXXCompiler.this); } }); @@ -1169,8 +1170,9 @@ public void closeComponent(CompiledObject component) { - if (openComponents.pop() != component) + if (openComponents.pop() != component) { throw new IllegalArgumentException("can only close the topmost open object"); + } } @@ -1181,14 +1183,17 @@ public void registerCompiledObject(CompiledObject object) { assert symbolTables.values().contains(symbolTable) : "attempting to register CompiledObject before pass 1 is complete"; - if (root == null) + if (root == null) { root = object; + } String id = object.getId(); - if (ids.containsKey(object)) + if (ids.containsKey(object)) { reportError("object '" + object + "' is already registered with id '" + ids.get(object) + "', cannot re-register as '" + id + "'"); - if (objects.containsKey(id) && !(objects.get(id) instanceof Element)) + } + if (objects.containsKey(id) && !(objects.get(id) instanceof Element)) { reportError("id '" + id + "' is already registered to component " + objects.get(id)); + } objects.put(id, object); ids.put(object, id); } @@ -1279,15 +1284,17 @@ int lastPos = 0; while (pos != -1 && pos < stringValue.length()) { if (pos > lastPos) { - if (expression.length() > 0) + if (expression.length() > 0) { expression.append(" + "); + } expression.append('"'); expression.append(JAXXCompiler.escapeJavaString(stringValue.substring(lastPos, pos))); expression.append('"'); } - if (expression.length() > 0) + if (expression.length() > 0) { expression.append(" + "); + } expression.append('('); int pos2 = getNextRightBrace(stringValue, pos + 1); if (pos2 == -1) { @@ -1306,8 +1313,9 @@ } } if (lastPos < stringValue.length()) { - if (expression.length() > 0) + if (expression.length() > 0) { expression.append(" + "); + } expression.append('"'); expression.append(JAXXCompiler.escapeJavaString(stringValue.substring(lastPos))); expression.append('"'); @@ -1384,8 +1392,9 @@ public void addScriptMethod(MethodDescriptor method) { - if (method.getName().equals("main") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].getName().equals("[Ljava.lang.String;")) + if (method.getName().equals("main") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].getName().equals("[Ljava.lang.String;")) { mainDeclared = true; + } symbolTable.getScriptMethods().add(method); } @@ -1396,14 +1405,20 @@ public void registerScript(String script, File sourceFile) throws CompilerException { - if (sourceFile != null) + if (sourceFile != null) { sourceFiles.push(sourceFile); + } + script = script.trim(); + if (!"".equals(script) && !script.endsWith("}") && !script.endsWith(";")) { + script +=";"; + } scriptManager.registerScript(script); if (sourceFile != null) { File pop = sourceFiles.pop(); - if (pop != sourceFile) + if (pop != sourceFile) { throw new RuntimeException("leaving registerScript(), but " + sourceFile + " was not the top entry on the stack (found " + pop + " instead)"); + } } } @@ -1414,17 +1429,20 @@ public void registerStylesheet(Stylesheet stylesheet) { - if (this.stylesheet == null) + if (this.stylesheet == null) { this.stylesheet = stylesheet; - else + } + else { this.stylesheet.add(stylesheet.getRules()); + } } public Stylesheet getStylesheet() { Stylesheet merged = new Stylesheet(); - if (stylesheet != null) + if (stylesheet != null) { merged.add(stylesheet.getRules()); + } merged.add(inlineStyles.toArray(new Rule[inlineStyles.size()])); return merged; } @@ -1442,8 +1460,9 @@ public void reportWarning(String warning) { Element currentTag = null; - if (!tagsBeingCompiled.isEmpty()) + if (!tagsBeingCompiled.isEmpty()) { currentTag = tagsBeingCompiled.peek(); + } reportWarning(currentTag, warning, 0); } @@ -1452,8 +1471,9 @@ String lineNumber = null; if (tag != null) { String lineAttr = tag.getAttributeNS(JAXX_INTERNAL_NAMESPACE, "line"); - if (lineAttr.length() > 0) + if (lineAttr.length() > 0) { lineNumber = lineAttr; + } } File src = sourceFiles.peek(); try { @@ -1464,8 +1484,9 @@ } System.err.print(src); - if (lineNumber != null) + if (lineNumber != null) { System.err.print(":" + ((sourceFiles.size() == 1) ? Integer.parseInt(lineNumber) + lineOffset : lineOffset + 1)); + } System.err.println(": Warning: " + warning); warningCount++; } @@ -1473,8 +1494,9 @@ public void reportError(String error) { Element currentTag = null; - if (!tagsBeingCompiled.isEmpty()) + if (!tagsBeingCompiled.isEmpty()) { currentTag = tagsBeingCompiled.peek(); + } reportError(currentTag, error); } @@ -1486,16 +1508,20 @@ public void reportError(String extraMessage, CompilerException ex) { String message = ex.getMessage(); - if (ex.getClass() == UnsupportedAttributeException.class || ex.getClass() == UnsupportedTagException.class) + if (ex.getClass() == UnsupportedAttributeException.class || ex.getClass() == UnsupportedTagException.class) { message = ex.getClass().getName().substring(ex.getClass().getName().lastIndexOf(".") + 1) + ": " + message; + } int lineOffset; - if (ex instanceof ParseException) + if (ex instanceof ParseException) { lineOffset = Math.max(0, ((ParseException) ex).getLine() - 1); - else + } + else { lineOffset = 0; + } Element currentTag = null; - if (!tagsBeingCompiled.isEmpty()) + if (!tagsBeingCompiled.isEmpty()) { currentTag = tagsBeingCompiled.peek(); + } reportError(currentTag, extraMessage != null ? extraMessage + message : message, lineOffset); } @@ -1509,8 +1535,9 @@ int lineNumber = 0; if (tag != null) { String lineAttr = tag.getAttributeNS(JAXX_INTERNAL_NAMESPACE, "line"); - if (lineAttr.length() > 0) + if (lineAttr.length() > 0) { lineNumber = Integer.parseInt(lineAttr); + } } lineNumber = Math.max(lineNumber, 1) + lineOffset; reportError(lineNumber, error); @@ -1520,16 +1547,18 @@ public void reportError(int lineNumber, String error) { File src = sourceFiles.isEmpty() ? null : sourceFiles.peek(); try { - if (src != null) + if (src != null) { src = src.getCanonicalFile(); + } } catch (IOException e) { // ignore ? } System.err.print(src != null ? src.getPath() : "<unknown source>"); - if (lineNumber > 0) + if (lineNumber > 0) { System.err.print(":" + lineNumber); + } System.err.println(": " + error); errorCount++; failed = true; @@ -1558,8 +1587,9 @@ i++; } else if (c < 32 || c > 127) { String value = Integer.toString((int) c, 16); - while (value.length() < 4) + while (value.length() < 4) { value = "0" + value; + } out.replace(i, i + 1, "\\u" + value); i += 5; } @@ -1587,8 +1617,9 @@ public ClassLoader getClassLoader() { if (classLoader == null) { String classPath = options.getClassPath(); - if (classPath == null) + if (classPath == null) { classPath = "."; + } String[] paths = classPath.split(File.pathSeparator); URL[] urls = new URL[paths.length]; for (int i = 0; i < paths.length; i++) { @@ -1623,8 +1654,9 @@ */ public static SymbolTable getSymbolTable(String className) { JAXXCompiler compiler = getJAXXCompiler(className); - if (compiler == null) + if (compiler == null) { return null; + } return compiler.getSymbolTable(); } @@ -1633,11 +1665,13 @@ } public static File URLtoFile(String urlString) { - if (!urlString.startsWith("file:")) + if (!urlString.startsWith("file:")) { throw new IllegalArgumentException("url must start with 'file:'"); + } urlString = urlString.substring("file:".length()); - if (urlString.startsWith("/") && System.getProperty("os.name").startsWith("Windows")) + if (urlString.startsWith("/") && System.getProperty("os.name").startsWith("Windows")) { urlString = urlString.substring(1); + } try { return new File(URLDecoder.decode(urlString.replace('/', File.separatorChar), "utf-8")); } @@ -1654,8 +1688,9 @@ try { File jaxxFile = URLtoFile(jaxxURL); File classFile = URLtoFile(classURL); - if (classFile.lastModified() > jaxxFile.lastModified()) + if (classFile.lastModified() > jaxxFile.lastModified()) { return; // class file is newer, no need to recompile + } } catch (Exception e) { // do nothing @@ -1673,8 +1708,9 @@ assert jaxxFile.getName().equalsIgnoreCase(className.substring(className.lastIndexOf(".") + 1) + ".jaxx") : "expecting file name to match " + className + ", but found " + jaxxFile.getName(); if (jaxxFile.getName().equals(className.substring(className.lastIndexOf(".") + 1) + ".jaxx")) { // check case match - if (currentPass == PASS_2) + if (currentPass == PASS_2) { throw new AssertionError("Internal error: adding dependency class " + className + " during second compilation pass"); + } jaxxFileClassNames.add(className); jaxxFiles.add(jaxxFile); } @@ -1917,18 +1953,23 @@ success = false; } options.setTargetDirectory(targetDirectory); - } else + } else { success = false; + } } else if (arg[i].equals("-cp") || arg[i].equals("-classpath")) { - if (++i < arg.length) + if (++i < arg.length) { options.setClassPath(arg[i]); - else + } + else { success = false; + } } else if (arg[i].equals("-javac_opts")) { - if (++i < arg.length) + if (++i < arg.length) { options.setJavacOpts(arg[i]); - else + } + else { success = false; + } } else if (arg[i].equals("-k") || arg[i].equals("-keep")) options.setKeepJavaFiles(true); else if (arg[i].equals("-j") || arg[i].equals("-java")) { @@ -1951,8 +1992,9 @@ success &= (errorCount == 0 && files.size() > 0); - if (success) + if (success) { success = compile(new File("."), files.toArray(new String[files.size()]), options); + } else { showUsage(); System.exit(1); Modified: trunk/jaxx/src/java/jaxx/compiler/ScriptManager.java =================================================================== --- trunk/jaxx/src/java/jaxx/compiler/ScriptManager.java 2008-01-12 21:32:32 UTC (rev 163) +++ trunk/jaxx/src/java/jaxx/compiler/ScriptManager.java 2008-01-12 21:37:23 UTC (rev 164) @@ -88,26 +88,32 @@ private void preprocessScriptNode(SimpleNode node, boolean staticContext) throws CompilerException { // identify static methods and initializers -- we can't fire events statically if (node.getId() == JavaParserTreeConstants.JJTMETHODDECLARATION) { - if (node.getParent().getChild(0).getText().indexOf("static") != -1) + if (node.getParent().getChild(0).getText().indexOf("static") != -1) { staticContext = true; + } } else if (node.getId() == JavaParserTreeConstants.JJTINITIALIZER) - if (node.getText().trim().startsWith("static")) + if (node.getText().trim().startsWith("static")) { staticContext = true; + } int count = node.jjtGetNumChildren(); - for (int i = 0; i < count; i++) + for (int i = 0; i < count; i++) { preprocessScriptNode(node.getChild(i), staticContext); + } int id = node.getId(); - if (id == JavaParserTreeConstants.JJTNAME || id == JavaParserTreeConstants.JJTCLASSORINTERFACETYPE) + if (id == JavaParserTreeConstants.JJTNAME || id == JavaParserTreeConstants.JJTCLASSORINTERFACETYPE) { scanCompoundSymbol(node.getText()); + } if (!staticContext) { String lhs = null; - if (id == JavaParserTreeConstants.JJTASSIGNMENTEXPRESSION || (id == JavaParserTreeConstants.JJTPOSTFIXEXPRESSION && node.jjtGetNumChildren() == 2)) + if (id == JavaParserTreeConstants.JJTASSIGNMENTEXPRESSION || (id == JavaParserTreeConstants.JJTPOSTFIXEXPRESSION && node.jjtGetNumChildren() == 2)) { lhs = ((SimpleNode) node.jjtGetChild(0)).getText().trim(); + } else - if (id == JavaParserTreeConstants.JJTPREINCREMENTEXPRESSION || id == JavaParserTreeConstants.JJTPREDECREMENTEXPRESSION) + if (id == JavaParserTreeConstants.JJTPREINCREMENTEXPRESSION || id == JavaParserTreeConstants.JJTPREDECREMENTEXPRESSION) { lhs = ((SimpleNode) node.jjtGetChild(0)).getText().trim(); + } if (lhs != null) { FieldDescriptor[] fields = compiler.getScriptFields(); for (FieldDescriptor field : fields) { @@ -135,31 +141,36 @@ if (line.jjtGetNumChildren() == 1) { SimpleNode node = line.getChild(0); if (node.getId() == JavaParserTreeConstants.JJTBLOCKSTATEMENT) { - if (node.jjtGetNumChildren() == 1) + if (node.jjtGetNumChildren() == 1) { return node.getChild(0).getId(); + } } else if (node.getId() == JavaParserTreeConstants.JJTCLASSORINTERFACEBODYDECLARATION) { int id = node.getChild(0).getId(); - if (id == JavaParserTreeConstants.JJTMODIFIERS) + if (id == JavaParserTreeConstants.JJTMODIFIERS) { return node.getChild(1).getId(); - else if (id == JavaParserTreeConstants.JJTINITIALIZER) + } + if (id == JavaParserTreeConstants.JJTINITIALIZER) { return id; + } } return node.getId(); - } else - return JavaParserTreeConstants.JJTLINE; // generic value implying that it's okay to put into the initializer block + } + return JavaParserTreeConstants.JJTLINE; // generic value implying that it's okay to put into the initializer block } private SimpleNode findExplicitConstructorInvocation(SimpleNode parent) { - if (parent.getId() == JavaParserTreeConstants.JJTEXPLICITCONSTRUCTORINVOCATION) + if (parent.getId() == JavaParserTreeConstants.JJTEXPLICITCONSTRUCTORINVOCATION) { return parent; + } int count = parent.jjtGetNumChildren(); for (int i = 0; i < count; i++) { SimpleNode result = findExplicitConstructorInvocation(parent.getChild(i)); - if (result != null) + if (result != null) { return result; + } } return null; } @@ -168,16 +179,19 @@ private void processConstructor(String modifiers, SimpleNode node) { assert node.getId() == JavaParserTreeConstants.JJTCONSTRUCTORDECLARATION : "expected node to be ConstructorDeclaration, found " + JavaParserTreeConstants.jjtNodeName[node.getId()] + " instead"; assert node.getChild(0).getId() == JavaParserTreeConstants.JJTFORMALPARAMETERS : "expected node 0 to be FormalParameters, found " + JavaParserTreeConstants.jjtNodeName[node.getChild(1).getId()] + " instead"; - if (node.getChild(0).jjtGetNumChildren() == 0) + if (node.getChild(0).jjtGetNumChildren() == 0) { compiler.reportError("The default no-argument constructor may not be redefined"); + } else { SimpleNode explicitConstructorInvocation = findExplicitConstructorInvocation(node); if (explicitConstructorInvocation == null || explicitConstructorInvocation.getText().trim().startsWith("super(")) { String code = "$initialize();" + JAXXCompiler.getLineSeparator(); - if (explicitConstructorInvocation == null) + if (explicitConstructorInvocation == null) { node.getChild(1).firstToken.image = code + node.getChild(1).firstToken.image; - else + } + else { explicitConstructorInvocation.lastToken.image += code; + } } } @@ -190,10 +204,12 @@ int nodeType = getLineType(node); if (nodeType == JavaParserTreeConstants.JJTIMPORTDECLARATION) { // have to handle imports early so the preprocessing takes them into account String text = node.getChild(0).getText().trim(); - if (text.startsWith("import")) + if (text.startsWith("import")) { text = text.substring("import".length()).trim(); - if (text.endsWith(";")) + } + if (text.endsWith(";")) { text = text.substring(0, text.length() - 1); + } compiler.addImport(text); } @@ -241,7 +257,11 @@ } else if (nodeType == JavaParserTreeConstants.JJTCLASSORINTERFACEDECLARATION || nodeType == JavaParserTreeConstants.JJTINITIALIZER) { - compiler.bodyCode.append(node.getText()); + String str = node.getText().trim(); + if (str.endsWith(";")) { + str+=";"; + } + compiler.bodyCode.append(str); //compiler.bodyCode.append(";\n"); } else if (nodeType == JavaParserTreeConstants.JJTCONSTRUCTORDECLARATION) { @@ -251,11 +271,15 @@ // the "local" variable declarations in this expression aren't actually local -- they are flagged local // just because there isn't an enclosing class scope visible to the parser. "Real" local variable // declarations won't show up here, because they will be buried inside of methods. - String text = node.getText(); + String text = node.getText().trim(); + if (!text.endsWith(";")) { + text+=";"; + } String declaration = text; int equals = text.indexOf("="); - if (equals != -1) + if (equals != -1) { declaration = declaration.substring(0, equals); + } declaration = declaration.trim(); String[] declarationTokens = declaration.split("\\s"); boolean isFinal = Arrays.asList(declarationTokens).contains("final"); @@ -288,6 +312,9 @@ } else { String text = node.getText().trim(); if (text.length() > 0) { + if (!text.endsWith(";")) { + text += ";"; + } compiler.initializer.append(text); //compiler.initializer.append(";\n"); } Modified: trunk/jaxx/src/java/jaxx/tags/DefaultObjectHandler.java =================================================================== --- trunk/jaxx/src/java/jaxx/tags/DefaultObjectHandler.java 2008-01-12 21:32:32 UTC (rev 163) +++ trunk/jaxx/src/java/jaxx/tags/DefaultObjectHandler.java 2008-01-12 21:37:23 UTC (rev 164) @@ -645,15 +645,15 @@ String name = attribute.getName(); String value = attribute.getValue(); if (name.equals("constraints") || isEventHandlerName(name)) { - compiler.preprocessScript(value + ";"); // adds dependencies as a side effect + compiler.preprocessScript(value); // adds dependencies as a side effect } else if (name.equals("constructorParams")) { String[] params = value.split("\\s*,\\s*"); for (String param : params) { - compiler.preprocessScript(param + ";"); + compiler.preprocessScript(param); } } else if (value.startsWith("{") && value.endsWith("}")) { - compiler.preprocessScript(value.substring(1, value.length() - 1) + ";"); + compiler.preprocessScript(value.substring(1, value.length() - 1)); } } } @@ -672,20 +672,26 @@ public void setAttributes(CompiledObject object, Element tag, JAXXCompiler compiler) { List<Attr> attributes = new ArrayList<Attr>(); NamedNodeMap children = tag.getAttributes(); - for (int i = 0; i < children.getLength(); i++) + for (int i = 0; i < children.getLength(); i++) { attributes.add((Attr) children.item(i)); + } Collections.sort(attributes, getAttributeComparator()); for (Attr attribute : attributes) { String name = attribute.getName(); - String value = attribute.getValue(); + String value = attribute.getValue().trim(); if (name.equals("id") || name.equals("constraints") || name.equals("constructorParams") || name.equals("styleClass") || name.startsWith("xmlns") || JAXXCompiler.JAXX_INTERNAL_NAMESPACE.equals(attribute.getNamespaceURI())) { // ignore, already handled - } else if (isEventHandlerName(name)) + } else if (isEventHandlerName(name)) { + if (!value.endsWith(";")) { + value+=";"; + } addEventHandler(object, Introspector.decapitalize(name.substring(2)), value, compiler); - else + } + else { setAttribute(object, name, value, true, compiler); + } } } @@ -769,8 +775,9 @@ ClassDescriptor type = getPropertyType(object, propertyName, compiler); String binding = compiler.processDataBindings(stringValue, type); if (binding != null) { - if (inline) + if (inline) { compiler.addInlineStyle(object, propertyName, true); + } ClassDescriptor propertyType = getPropertyType(object, propertyName, compiler); if (propertyType != null && propertyType != ClassDescriptorLoader.getClassDescriptor(Boolean.class) && @@ -779,16 +786,18 @@ propertyType != ClassDescriptorLoader.getClassDescriptor(Integer.class) && propertyType != ClassDescriptorLoader.getClassDescriptor(Float.class) && propertyType != ClassDescriptorLoader.getClassDescriptor(Double.class) && - propertyType != ClassDescriptorLoader.getClassDescriptor(Character.class)) - binding = "((" + propertyType.getName() + ") " + binding + ")"; + propertyType != ClassDescriptorLoader.getClassDescriptor(Character.class)) { + //binding = "((" + propertyType.getName() + ") " + binding + ")"; + } if (propertyName.equals("layout")) { // handle containerDelegate (e.g. contentPane on JFrame) // have to set layout early, before children are added object.appendInitializationCode(getSetPropertyCode(object.getJavaCode(), propertyName, binding, compiler)); } object.registerDataBinding(binding, propertyName, getSetPropertyCode(object.getJavaCode(), propertyName, binding, compiler), compiler); } else { // no bindings, convert from string - if (inline) + if (inline) { compiler.addInlineStyle(object, propertyName, false); + } try { Class typeClass = type != null ? ClassDescriptorLoader.getClass(type.getName(), type.getClassLoader()) : null; Object value = convertFromString(propertyName, stringValue, typeClass);
participants (1)
-
tchemit@users.labs.libre-entreprise.org