Revision: 4001
          http://vexi.svn.sourceforge.net/vexi/?rev=4001&view=rev
Author:   clrg
Date:     2011-01-25 03:01:11 +0000 (Tue, 25 Jan 2011)

Log Message:
-----------
Don't nest [] for optional arguments when building arguments string
- before: func(arg[, opt1[, opt2]]);
- after: func(arg[, opt1, opt2]);

Modified Paths:
--------------
    trunk/org.vexi-build.jsdoc/src/main/java/org/vexi/build/jsdoc/Property.java

Modified: 
trunk/org.vexi-build.jsdoc/src/main/java/org/vexi/build/jsdoc/Property.java
===================================================================
--- trunk/org.vexi-build.jsdoc/src/main/java/org/vexi/build/jsdoc/Property.java 
2011-01-25 01:20:33 UTC (rev 4000)
+++ trunk/org.vexi-build.jsdoc/src/main/java/org/vexi/build/jsdoc/Property.java 
2011-01-25 03:01:11 UTC (rev 4001)
@@ -7,7 +7,7 @@
 
 import freemarker.template.*;
 
-abstract public class Property implements TemplateHashModel{
+abstract public class Property implements TemplateHashModel {
 
        final public String name;
        public String desc;
@@ -18,7 +18,7 @@
        }
 
        public void setDesc(Attribute a) {
-               if(a!=null) {
+               if (a!=null) {
                        desc = a.text;
                }
        }
@@ -26,13 +26,15 @@
        
        public boolean isEmpty() { return false; }
        public TemplateModel get(String s) {
-                    if("name".equals(s)) return new SimpleScalar(name);
-               else if("desc".equals(s)) return new SimpleScalar(desc);
-               else if("link".equals(s)) return link==null?null:new 
SimpleScalar(link);
+               if ("name".equals(s)) return new SimpleScalar(name);
+               if ("desc".equals(s)) return new SimpleScalar(desc);
+               if ("link".equals(s)) return link==null?null:new 
SimpleScalar(link);
                return null;
        }
 
-       static public class Ordinary extends Property{
+
+
+       static public class Ordinary extends Property {
                public String type;
                public String initial_value;
                public List<String> group;
@@ -41,74 +43,85 @@
                        super(name);
                }
                public void setType(Attribute a) throws DocException {
-                       if(a!=null) type = a.findArg(0);
+                       if (a!=null) type = a.findArg(0);
                }
                public void setInitialValue(Attribute a) throws DocException {
-                       if(a!=null) {
+                       if (a!=null) {
                                initial_value = a.findArg(0);
                                boolean code = a.getArg("code", true);
-                               if(code) initial_value = 
"<code>"+initial_value+"</code>";
+                               if (code) initial_value = 
"<code>"+initial_value+"</code>";
                                else initial_value = "<i>"+initial_value+"</i>";
                        }
                }
                public void setGroup(Attribute a) {
-                       if(a!=null) group = a.allArgs();
+                       if (a!=null) group = a.allArgs();
                }
                
                public TemplateModel get(String s) {
-                       if("name".equals(s)) {
-                                if(group==null) return new SimpleScalar(name);
+                       if ("name".equals(s)) {
+                                if (group==null)
+                                    return new SimpleScalar(name);
                                 String r = name+"<br />";
-                                for(String a: group){
+                                for (String a: group) {
                                        r += a+"<br />";
                                 }
                                 return new SimpleScalar(r);
                        }
-               else if("type".equals(s)) return new SimpleScalar(type);
-                       else if("initial_value".equals(s)) return new 
SimpleScalar(initial_value);
+               if ("type".equals(s)) return new SimpleScalar(type);
+                       if ("initial_value".equals(s)) return new 
SimpleScalar(initial_value);
                        return super.get(s);
                }
                
        }
-       
-       static private String buildArgs(Iterator<Attribute> I, boolean comma) 
throws DocException{
 
-               if(!I.hasNext()) return "";
+    static private String buildArgs(Iterator<Attribute> I, boolean comma) 
throws DocException { return buildArgs(I, comma, false); }
+       static private String buildArgs(Iterator<Attribute> I, boolean comma, 
boolean optional) throws DocException {
+               if (!I.hasNext()) return "";
+               
                Attribute a = I.next();
                String r = (comma?", ":"")+a.findArg("name",0);
-               r+=buildArgs(I, true);
-               if(a.getArg("optional",false))
-                       r = "["+r+"]";
+        boolean opt = a.getArg("optional", false);
+        
+        // func(arg[, optarg], arg2) does not make sense
+        if (optional && !opt)
+            throw new DocException("Arguments must be ordered as mandatory 
followed by optional");
+        
+        String nextArg = buildArgs(I, true, opt);
+        if (!optional && opt)
+            r = "["+r;
+               if (nextArg=="" && (optional || opt))
+                   r += "]";
+               else r += nextArg;
                return r;
        }
-       
-       static public class Function extends Property{
+
+
+
+       static public class Function extends Property {
                public String args;
                public String return_type;
                public Function(String name) {
                        super(name);
                }
                
-
-               
                public void setParams(List<Attribute> params) throws 
DocException {
                        Iterator<Attribute> I = params.iterator();
                        args = buildArgs(I,false);
                }
                
                public void setReturnType(Attribute a) throws DocException {
-                       if(a!=null) return_type = a.findArg(0);
+                       if (a!=null) return_type = a.findArg(0);
                }
                public TemplateModel get(String s) {
-                       if("args".equals(s)) return new SimpleScalar(args);
-                       else if("return_type".equals(s)) return new 
SimpleScalar(return_type);
+                       if ("args".equals(s)) return new SimpleScalar(args);
+                       if ("return_type".equals(s)) return new 
SimpleScalar(return_type);
                        return super.get(s);
                }
        }
        
        
 
-       static public class Constructor extends Property{
+       static public class Constructor extends Property {
                public String args;
                public Constructor(String name) {
                        super(name);
@@ -120,14 +133,9 @@
                }
                
                public TemplateModel get(String s) {
-                       if("args".equals(s)) return new SimpleScalar(args);
+                       if ("args".equals(s)) return new SimpleScalar(args);
                        return super.get(s);
                }
        }
 
-
-
-
-
-
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to