[Laszlo-checkins] r12827 - openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler
hqm@openlaszlo.org
hqm at openlaszlo.org
Wed Feb 11 18:22:00 PST 2009
Author: hqm
Date: 2009-02-11 18:21:55 -0800 (Wed, 11 Feb 2009)
New Revision: 12827
Modified:
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassCompiler.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassModel.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ViewSchema.java
Log:
Change 20090211-hqm-9 by hqm at badtzmaru.home on 2009-02-11 14:40:22 EST
in /Users/hqm/openlaszlo/trunk4
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: add checking in compiler for required attributes
New Features:
Bugs Fixed: LPP-7743, LPP-7440
Technical Reviewer: ptw
QA Reviewer: promanik
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
+ support 'required' declaration on attributes
+ NodeModel checks list of supplied attributes of an instance against
the compiler's class model list of required attributes.
+ The code is optimized so that the list of required attributes that
is stored on the class model contains the union of required attributes
of all superclasses, so we don't have to follow that chain up every
time we want to enumerate the required attributes of a class.
Tests:
<canvas>
<class name="foo">
<attribute name="grid" value="null" required="true"/>
</class>
<class name="bar" extends="foo">
<attribute name="r2" value="null" required="true"/>
<attribute name="a3" value="null" required="false"/>
<attribute name="a4" value="null" required="false"/>
</class>
<foo/>
<foo grid="259"/>
<bar/>
<bar grid="259"/>
<bar grid="259" r2="12" a3="canvas"/>
</canvas>
Should issue warnings
req.lzx:12:9: Missing required attribute grid for tag foo
req.lzx:15:9: Missing required attribute r2 for tag bar
req.lzx:15:9: Missing required attribute grid for tag bar
req.lzx:16:20: Missing required attribute r2 for tag bar
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassCompiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassCompiler.java 2009-02-11 19:44:51 UTC (rev 12826)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassCompiler.java 2009-02-12 02:21:55 UTC (rev 12827)
@@ -260,7 +260,7 @@
AttributeSpec attrSpec =
new AttributeSpec(attrName, attrType, attrDefault,
- attrSetter, child);
+ attrSetter, "true".equals(attrRequired), child);
attrSpec.allocation = allocation;
attrSpec.isfinal = child.getAttributeValue("final");
if (attrName.equals("text") && attrTypeName != null) {
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassModel.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassModel.java 2009-02-11 19:44:51 UTC (rev 12826)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassModel.java 2009-02-12 02:21:55 UTC (rev 12827)
@@ -43,6 +43,8 @@
public Set mixinNames = new HashSet(2, 0.6f);
+ public List requiredAttributes = new ArrayList();
+
/* Class or superclass has an <attribute type="text"/> */
protected boolean supportsTextAttribute = false;
/** Map attribute name to type */
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 2009-02-11 19:44:51 UTC (rev 12826)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java 2009-02-12 02:21:55 UTC (rev 12827)
@@ -519,11 +519,31 @@
model.addProperty("clickable", "true", ALLOCATION_INSTANCE, elt);
}
}
+
+ // Check that all attributes required by the class or it's superclasses are present
+ checkRequiredAttributes(elt, model, schema);
+
// Record the model in the element for classes
((ElementWithLocationInfo) elt).model = model;
return model;
}
+ private static void checkRequiredAttributes(Element element, NodeModel model, ViewSchema schema) {
+ ClassModel classinfo = schema.getClassModel(element.getName());
+ Map attrs = model.attrs;
+
+ CompilationEnvironment env = schema.getCompilationEnvironment();
+ // Check that each required attribute is present in the list of supplied attributes
+ for (Iterator iter = classinfo.requiredAttributes.listIterator(); iter.hasNext(); ) {
+ String reqname = (String) iter.next();
+ if (!attrs.containsKey(reqname)) {
+ env.warn(
+ new CompilationError("Missing required attribute "+reqname+ " for tag "+element.getName() , element),
+ element);
+ }
+ }
+ }
+
static void checkTagDeclared(Element element, ViewSchema schema) {
ClassModel classinfo = schema.getClassModel(element.getName());
if (classinfo == null || classinfo.definition == null) {
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 2009-02-11 19:44:51 UTC (rev 12826)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ViewSchema.java 2009-02-12 02:21:55 UTC (rev 12827)
@@ -3,7 +3,7 @@
* ****************************************************************************/
/* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2008 Laszlo Systems, Inc. All Rights Reserved. *
+* Copyright 2001-2009 Laszlo Systems, Inc. All Rights Reserved. *
* Use is subject to license terms. *
* J_LZ_COPYRIGHT_END *********************************************************/
@@ -188,6 +188,10 @@
classModel.classAttributeSpecs.put(attrName, attrspec);
}
+ if (attrspec.required) {
+ classModel.requiredAttributes.add(attrName);
+ }
+
if (attrName.equals("text")) {
classModel.supportsTextAttribute = true;
}
@@ -408,6 +412,8 @@
// Add in the attribute declarations
addAttributeDefs(elt, tagName, attributeDefs, env);
+ // merge in superclass requiredAttributes list to make lookup more efficient
+ info.requiredAttributes.addAll(superclass.requiredAttributes);
}
/**
@@ -1049,6 +1055,7 @@
attributeAttributes.add("allocation");
attributeAttributes.add("name");
attributeAttributes.add("setter");
+ attributeAttributes.add("required");
}
More information about the Laszlo-checkins
mailing list