flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [16/19] git commit: [flex-falcon] [refs/heads/develop] - fix jsroot optional parameter handling
Date Wed, 25 May 2016 18:25:23 GMT
fix jsroot optional parameter handling


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/a0758899
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/a0758899
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/a0758899

Branch: refs/heads/develop
Commit: a07588995f4b8d70a7c49ff49d780b6c561bf8e2
Parents: e4b5e9a
Author: Alex Harui <aharui@apache.org>
Authored: Wed May 25 11:24:01 2016 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Wed May 25 11:24:01 2016 -0700

----------------------------------------------------------------------
 .../externals/reference/BaseReference.java      | 31 +++++++++++++++++---
 .../externals/reference/FieldReference.java     |  2 +-
 .../codegen/externals/utils/FunctionUtils.java  |  8 ++++-
 3 files changed, 35 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a0758899/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
index b74167e..cabc9bb 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
@@ -198,7 +198,7 @@ public abstract class BaseReference
         emitReturns(sb);
     }
 
-    protected String mapBackToJS(String t)
+    protected String mapBackToJS(String t, boolean optional)
     {
     	// remove all whitespace
     	t = t.replace(" ", "");
@@ -234,6 +234,22 @@ public abstract class BaseReference
     		t = t.replace("|Boolean)", "|boolean)");
     	if (t.contains("|object)")) 
     		t = t.replace("|object)", "|Object)");
+    	if (optional)
+    	{
+    		// try to strip out undefined and null and replace with =
+    		if (t.contains("null|"))
+    			t = t.replace("null|", "");
+    		if (t.contains("|null"))
+    			t = t.replace("|null", "");
+    		if (t.contains("undefined|"))
+    			t = t.replace("undefined|", "");
+    		if (t.contains("|undefined"))
+    			t = t.replace("|undefined", "");
+    		// strip off wrapping parens if not needed
+    		if (!t.contains("|") && t.startsWith("(") && t.endsWith(")"))
+    			t = t.substring(1, t.length() - 1);
+    		t = t + "=";
+    	}
     	return t;
     }
     
@@ -248,15 +264,22 @@ public abstract class BaseReference
             sb.append(indent);
             sb.append(" * @param ");
 
+            boolean optional = parameterType != null && parameterType.isOptionalArg();
             if (outputJS && parameterType != null)
             {
                 sb.append("{");
-                sb.append(mapBackToJS(getModel().evaluate(parameterType).toAnnotationString()));
+                sb.append(mapBackToJS(getModel().evaluate(parameterType).toAnnotationString(),
optional));
                 sb.append("}");
                 sb.append(" ");            	
             }
             
-            sb.append(paramName);
+            if (outputJS && optional)
+            {
+            	sb.append("opt_");            	
+            	sb.append(paramName);            	
+            }
+            else
+            	sb.append(paramName);
             sb.append(" ");
 
             if (!outputJS && parameterType != null)
@@ -283,7 +306,7 @@ public abstract class BaseReference
                 sb.append(" * @returns ");
                 sb.append("{");
                 if (outputJS)
-                    sb.append(mapBackToJS(getModel().evaluate(returnType).toAnnotationString()));
+                    sb.append(mapBackToJS(getModel().evaluate(returnType).toAnnotationString(),
false));
                 else
                 	sb.append(getModel().evaluate(returnType).toAnnotationString());
                 sb.append("} ");

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a0758899/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
index e01a72a..674fa19 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
@@ -249,7 +249,7 @@ public class FieldReference extends MemberReference
                 sb.append(indent);
                 sb.append(" * @type ");
                 sb.append("{");
-                sb.append(mapBackToJS(getModel().evaluate(type).toAnnotationString()));
+                sb.append(mapBackToJS(getModel().evaluate(type).toAnnotationString(), false));
                 sb.append("} ");
                 sb.append("\n");
         	}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a0758899/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
index 5a9b658..15d83f4 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
@@ -184,7 +184,13 @@ public class FunctionUtils
                 paramType = "Object";
             }
 
-            sb.append(paramName);
+            if (outputJS && parameterType.isOptionalArg())
+            {
+            	sb.append("opt_");
+            	sb.append(paramName);            	
+            }
+            else
+            	sb.append(paramName);
             if (!outputJS)
             {
                 sb.append(":");


Mime
View raw message