[Laszlo-checkins] r8997 - in openlaszlo/trunk: WEB-INF/lps/server/src/org/openlaszlo/compiler test/compiler_errors

hqm@openlaszlo.org hqm at openlaszlo.org
Mon May 5 10:23:11 PDT 2008


Author: hqm
Date: 2008-05-05 10:23:07 -0700 (Mon, 05 May 2008)
New Revision: 8997

Added:
   openlaszlo/trunk/test/compiler_errors/a.lzx
   openlaszlo/trunk/test/compiler_errors/bad-child-tag.lzx
Modified:
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ViewSchema.java
Log:
Change 20080505-hqm-w by hqm at badtzmaru.home on 2008-05-05 12:23:19 EDT
    in /Users/hqm/openlaszlo/trunk5
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary:  add compiler error for the case of child tags inside of method,attribute,event, or handler tags

New Features:

Bugs Fixed: LPP-5931

Technical Reviewer: ptw
QA Reviewer: pbr
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
    
+ NodeModel checks if there are any child elements underneath a method,handler,event, or attribute tag

note, I'm not sure if these should be compiler errors or warnings... 



Tests:

test case in bug report
lztest
new test case in compiler



Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java	2008-05-05 16:27:21 UTC (rev 8996)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java	2008-05-05 17:23:07 UTC (rev 8997)
@@ -342,7 +342,14 @@
             org.openlaszlo.i18n.LaszloMessages.getMessage(
                 Compiler.class.getName(),"051018-303", new Object[] {file.getAbsolutePath()})
 );
+            // Initialize the schema from the base LFC interface file
+            try {
+                env.getSchema().loadSchema(env);
+            } catch (org.jdom.JDOMException e) {
+                throw new ChainedException(e);
+            }
 
+
             Document doc = env.getParser().parse(file, env);
             Element root = doc.getRootElement();
             
@@ -367,13 +374,6 @@
             } 
 
             mLogger.debug("Making a writer...");
-
-            // Initialize the schema from the base LFC interface file
-            try {
-                env.getSchema().loadSchema(env);
-            } catch (org.jdom.JDOMException e) {
-                throw new ChainedException(e);
-            }
             ViewSchema schema = env.getSchema();
             Set externalLibraries = null;
             // If we are not linking, then we consider all external

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java	2008-05-05 16:27:21 UTC (rev 8996)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java	2008-05-05 17:23:07 UTC (rev 8997)
@@ -1163,17 +1163,26 @@
         }
     }
 
+   void warnIfHasChildren(Element element) {
+     if (element.getChildren().size() > 0) {
+       CompilationError cerr = new CompilationError(
+           "The "+element.getName()+" tag cannot have child tags in this context", element);
+       throw(cerr);        
+     }
+   }
+
     void addPropertyElement(Element element) {
-        String tagName = element.getName();
-        if (tagName.equals("method")) {
-            addMethodElement(element);
-        } else if (tagName.equals("handler")) {
-            addHandlerElement(element);
-        } else if (tagName.equals("event")) {
-          addEventElement(element);
-        } else if (tagName.equals("attribute")) {
-            addAttributeElement(element);
-        }
+      warnIfHasChildren(element);
+      String tagName = element.getName();
+      if (tagName.equals("method")) {
+        addMethodElement(element);
+      } else if (tagName.equals("handler")) {
+        addHandlerElement(element);
+      } else if (tagName.equals("event")) {
+        addEventElement(element);
+      } else if (tagName.equals("attribute")) {
+        addAttributeElement(element);
+      }
     }
 
     /** Defines an event handler.

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java	2008-05-05 16:27:21 UTC (rev 8996)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java	2008-05-05 17:23:07 UTC (rev 8997)
@@ -3,7 +3,7 @@
 * ****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -514,6 +514,12 @@
 
 
             if (child.getName().equals("include")) {
+                // Ensure there are no child elements
+                if (child.getChildren().size() > 0) {
+                    throw new CompilationError("'include' tag must not contain child elements", child);
+                }
+                // Ensure there are no illegal attributes
+                env.getSchema().checkValidAttributeNames(child);
                 String base = new File(getSourcePathname(element)).getParent();
                 String type = XMLUtils.getAttributeValue(child, "type", "xml");
                 String href = child.getAttributeValue("href");

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ViewSchema.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ViewSchema.java	2008-05-05 16:27:21 UTC (rev 8996)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ViewSchema.java	2008-05-05 17:23:07 UTC (rev 8997)
@@ -523,6 +523,19 @@
     }
 
 
+    /**
+     * Throw an error if there are any unknown attributes on a tag
+     */
+    public void checkValidAttributeNames(Element elt) {
+        for (Iterator iter = elt.getAttributes().iterator(); iter.hasNext(); ) {
+            Attribute attr = (Attribute) iter.next();
+            String name = attr.getName();
+            AttributeSpec attrspec = getAttributeSpec(elt.getName(), name);
+            if (attrspec == null) {
+                throw new CompilationError("Unknown attribute '"+name+"' on tag "+elt.getName(), elt);
+            }
+        }
+    }
 
     /**
      * Finds the AttributeSpec definition of an attribute, on a class

Added: openlaszlo/trunk/test/compiler_errors/a.lzx


Property changes on: openlaszlo/trunk/test/compiler_errors/a.lzx
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: openlaszlo/trunk/test/compiler_errors/bad-child-tag.lzx


Property changes on: openlaszlo/trunk/test/compiler_errors/bad-child-tag.lzx
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native



More information about the Laszlo-checkins mailing list