flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [1/6] git commit: [flex-falcon] [refs/heads/develop] - now we can generate a cleaner set of externs if we want to. If, for example, an API was missing and added in missing.js, this output externs would contain those APIs. This feature was originally do
Date Wed, 09 Dec 2015 21:47:35 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop c8581c9f4 -> f30777191


now we can generate a cleaner set of externs if we want to.  If, for example, an API was missing
and added in missing.js, this output externs would contain those APIs.  This feature was originally
done in order to generate externs from the live CreateJS code.


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

Branch: refs/heads/develop
Commit: 1a4a51ecc2d75bdd1a87de2e114c02bf2529a5b9
Parents: c8581c9
Author: Alex Harui <aharui@apache.org>
Authored: Tue Dec 8 15:15:07 2015 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Dec 8 15:15:16 2015 -0800

----------------------------------------------------------------------
 .../compiler/clients/ExternCConfiguration.java  |  17 ++-
 .../externals/reference/BaseReference.java      |  13 ++-
 .../externals/reference/ClassReference.java     | 116 +++++++++++++++----
 .../externals/reference/FieldReference.java     |  55 +++++++--
 .../externals/reference/FunctionReference.java  |   2 +-
 .../externals/reference/MethodReference.java    |  34 +++++-
 .../codegen/externals/utils/FunctionUtils.java  |  29 +++--
 7 files changed, 220 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1a4a51ec/compiler.jx/src/org/apache/flex/compiler/clients/ExternCConfiguration.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/clients/ExternCConfiguration.java b/compiler.jx/src/org/apache/flex/compiler/clients/ExternCConfiguration.java
index e711e20..7eea457 100644
--- a/compiler.jx/src/org/apache/flex/compiler/clients/ExternCConfiguration.java
+++ b/compiler.jx/src/org/apache/flex/compiler/clients/ExternCConfiguration.java
@@ -42,8 +42,10 @@ import org.apache.flex.utils.FilenameNormalization;
 
 public class ExternCConfiguration extends Configuration
 {
-    private File asRoot;
+    private File jsRoot;
 
+    private File asRoot;
+    
     private File asClassRoot;
     private File asInterfaceRoot;
     private File asFunctionRoot;
@@ -286,6 +288,19 @@ public class ExternCConfiguration extends Configuration
         excludesClass.add(new ExcludedMember(className, null, ""));
     }
 
+    public File getJsRoot()
+    {
+        return jsRoot;
+    }
+
+    @Config
+    @Mapping("js-root")
+    public void setJSRoot(ConfigurationValue cfgval, String filename) throws CannotOpen
+    {
+        this.jsRoot = new File(filename);
+    }
+
+
     public static class ExcludedMember
     {
         private String className;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1a4a51ec/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
index cb3ef49..60191ff 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
@@ -43,6 +43,8 @@ public abstract class BaseReference
 
     private ReferenceModel model;
 
+    protected boolean outputJS;
+
     protected String indent = "    ";
 
     public File getCurrentFile()
@@ -109,6 +111,7 @@ public abstract class BaseReference
         this.node = node;
         this.qualifiedName = qualifiedName;
         this.comment = comment;
+        outputJS = model.getConfiguration().getJsRoot() != null;
     }
 
     public ExcludedMember isExcluded()
@@ -206,10 +209,18 @@ public abstract class BaseReference
             sb.append(indent);
             sb.append(" * @param ");
 
+            if (outputJS && parameterType != null)
+            {
+                sb.append("{");
+                sb.append(getModel().evaluate(parameterType).toAnnotationString());
+                sb.append("}");
+                sb.append(" ");            	
+            }
+            
             sb.append(paramName);
             sb.append(" ");
 
-            if (parameterType != null)
+            if (!outputJS && parameterType != null)
             {
                 sb.append("[");
                 sb.append(getModel().evaluate(parameterType).toAnnotationString());

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1a4a51ec/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
index cdc7785..e2c576d 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
@@ -38,6 +38,7 @@ import com.google.javascript.rhino.JSDocInfoBuilder;
 import com.google.javascript.rhino.JSTypeExpression;
 import com.google.javascript.rhino.Node;
 import com.google.javascript.rhino.jstype.JSType;
+import com.sun.tools.internal.ws.processor.model.Model;
 
 public class ClassReference extends BaseReference
 {
@@ -294,13 +295,39 @@ public class ClassReference extends BaseReference
 
         String packageName = getPackageName();
 
-        sb.append("package ");
-        if (!packageName.equals(""))
-            sb.append(packageName).append(" ");
-        sb.append("{\n");
-        sb.append("\n");
-
-        emitImports(sb);
+        if (outputJS)
+        {
+        	sb.append("/** @fileoverview Auto-generated Externs files\n * @externs\n */\n");
+        	if (!packageName.isEmpty())
+        	{
+        		String[] pieces = packageName.split("\\.");
+        		String chain = "";
+        		int n = pieces.length;
+        		for (int i = 0; i < n - 1; i++)
+        		{
+        			String piece = pieces[i];
+                	sb.append("\n");
+                	sb.append("\n");
+        			sb.append("/** @const */\n");
+        			if (chain.isEmpty())
+        				sb.append("var " + piece + " = {};\n");
+        			else
+        				sb.append(chain + "." + piece + " = {}\n");
+        			chain = chain + "." + piece;
+        		}
+        	}
+        }
+        else
+        {
+	        sb.append("package ");
+	        if (!packageName.equals(""))
+	            sb.append(packageName).append(" ");
+	        sb.append("{\n");
+	        sb.append("\n");
+	
+	        emitImports(sb);
+        }
+        
         emitComment(sb);
 
         boolean isInterface = isInterface();
@@ -314,9 +341,12 @@ public class ClassReference extends BaseReference
             emitClass(sb);
         }
 
-        sb.append("{\n");
-        sb.append("\n");
-
+        if (!outputJS)
+        {
+	        sb.append("{\n");
+	        sb.append("\n");
+        }
+        
         if (!isInterface)
         {
             emitConstructor(sb);
@@ -326,8 +356,11 @@ public class ClassReference extends BaseReference
         emitFields(sb);
         emitMethods(sb);
 
-        sb.append("}\n");
-        sb.append("}\n"); // package
+        if (!outputJS)
+        {
+            sb.append("}\n");
+            sb.append("}\n"); // package        	
+        }
     }
 
     public boolean hasSuperField(String fieldName)
@@ -661,8 +694,25 @@ public class ClassReference extends BaseReference
         }
     }
 
+    @Override
+    protected void emitCommentBody(StringBuilder sb)
+    {
+    	super.emitCommentBody(sb);
+        if (getComment().hasBaseType())
+        {
+            emitSuperClass(sb);
+        }
+        if (!isInterface())
+        {
+            emitImplements(sb);
+        }
+    }
+    
     private void emitClass(StringBuilder sb)
     {
+    	if (outputJS)
+    		return;
+    	
         sb.append("public ");
         if (isDynamic)
         {
@@ -675,6 +725,8 @@ public class ClassReference extends BaseReference
         }
 
         sb.append("class ");
+		sb.append(getPackageName());
+		sb.append(".");
         sb.append(getBaseName()).append(" ");
 
         if (getComment().hasBaseType())
@@ -718,9 +770,19 @@ public class ClassReference extends BaseReference
 
     private void emitSuperClass(StringBuilder sb)
     {
-        sb.append("extends ");
-        String value = JSTypeUtils.toClassTypeString(this);
-        sb.append(value);
+    	if (outputJS)
+    	{
+	        sb.append(" * @extends ");
+	        String value = JSTypeUtils.toClassTypeString(this);
+	        sb.append(value);
+	        sb.append("\n");
+    	}
+    	else
+    	{
+	        sb.append("extends ");
+	        String value = JSTypeUtils.toClassTypeString(this);
+	        sb.append(value);
+    	}
     }
 
     private void emitImplements(StringBuilder sb)
@@ -729,7 +791,10 @@ public class ClassReference extends BaseReference
         if (implementedInterfaces.size() == 0)
             return;
 
-        sb.append("implements ");
+        if (outputJS)
+        	sb.append(" * @implements ");
+        else
+        	sb.append("implements ");
 
         int len = implementedInterfaces.size();
         for (int i = 0; i < len; i++)
@@ -737,8 +802,13 @@ public class ClassReference extends BaseReference
             String value = getModel().evaluate(implementedInterfaces.get(i)).getDisplayName();
 
             sb.append(value);
-            if (i < len - 1)
-                sb.append(", ");
+            if (outputJS)
+            	sb.append("\n");
+            else
+            {
+	            if (i < len - 1)
+	                sb.append(", ");
+            }
         }
 
         sb.append(" ");
@@ -773,8 +843,14 @@ public class ClassReference extends BaseReference
 
     public File getFile(File asSourceRoot)
     {
-        String packagePath = toPackagePath();
-        return new File(asSourceRoot, packagePath + File.separator + getBaseName() + ".as");
+    	File jsRoot = getModel().getConfiguration().getJsRoot();
+    	if (jsRoot == null)
+    	{
+            String packagePath = toPackagePath();
+            return new File(asSourceRoot, packagePath + File.separator + getBaseName() +
".as");    		
+    	}
+    	
+    	return new File(jsRoot, getBaseName() + ".js");
     }
 
     private String toPackagePath()

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1a4a51ec/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
index b75c607..4ded9de 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
@@ -129,6 +129,18 @@ public class FieldReference extends MemberReference
         if (type.contains("|") || type.contains("?"))
             type = "*";
 
+        if (outputJS)
+        {
+        	sb.append(getClassReference().getPackageName());
+        	sb.append(".");
+        	sb.append(getClassReference().getBaseName());
+        	sb.append(".");
+        	if (!isStatic)
+        		sb.append("prototype.");
+        	sb.append(getBaseName());
+        	sb.append(";\n");
+        	return;
+        }
         // getter
         sb.append(indent);
         sb.append(isPublic);
@@ -162,6 +174,19 @@ public class FieldReference extends MemberReference
         if (type.contains("|") || type.contains("?"))
             type = "*";
 
+        if (outputJS)
+        {
+        	sb.append(getClassReference().getPackageName());
+        	sb.append(".");
+        	sb.append(getClassReference().getBaseName());
+        	sb.append(".");
+        	if (!isStatic)
+        		sb.append("prototype.");
+        	sb.append(getBaseName());
+        	sb.append(";\n");
+        	return;
+        }
+        
         sb.append(indent);
         sb.append("public ");
         sb.append(staticValue);
@@ -212,15 +237,27 @@ public class FieldReference extends MemberReference
         JSTypeExpression type = getComment().getType();
         if (type != null)
         {
-            sb.append(indent);
-            sb.append(" * @see JSType - ");
-            sb.append("[");
-            sb.append(getModel().evaluate(type).toAnnotationString());
-            sb.append("] ");
-            String description = getComment().getReturnDescription();
-            if (description != null)
-                sb.append(description);
-            sb.append("\n");
+        	if (outputJS)
+        	{
+                sb.append(indent);
+                sb.append(" * @type ");
+                sb.append("{");
+                sb.append(getModel().evaluate(type).toAnnotationString());
+                sb.append("} ");
+                sb.append("\n");
+        	}
+        	else
+        	{
+                sb.append(indent);
+                sb.append(" * @see JSType - ");
+                sb.append("[");
+                sb.append(getModel().evaluate(type).toAnnotationString());
+                sb.append("] ");
+                String description = getComment().getReturnDescription();
+                if (description != null)
+                    sb.append(description);
+                sb.append("\n");        		
+        	}
         }
     }
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1a4a51ec/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
index 1fbc944..38d9d30 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
@@ -158,7 +158,7 @@ public class FunctionReference extends BaseReference {
     }
 
     private String toParameterString() {
-        return FunctionUtils.toParameterString(getContext(), getComment(), paramNode);
+        return FunctionUtils.toParameterString(getContext(), getComment(), paramNode, outputJS);
     }
 
     public boolean isOverride() {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1a4a51ec/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
index aee165f..58b7034 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
@@ -204,6 +204,22 @@ public class MethodReference extends MemberReference
         	publicModifier = "AS3 ";
         }
 
+    	if (outputJS)
+    	{
+        	sb.append(getClassReference().getPackageName());
+        	sb.append(".");
+        	sb.append(getClassReference().getBaseName());
+        	sb.append(".");
+        	if (isStatic)
+        		sb.append("prototype.");
+        	sb.append(qName);    		
+        	sb.append(" = function "); 		
+            sb.append(toParameterString());
+            sb.append(braces);
+            sb.append("\n");
+            return;
+    	}
+    	
         sb.append(indent);
         sb.append(publicModifier);
         sb.append(isOverride);
@@ -219,8 +235,20 @@ public class MethodReference extends MemberReference
 
     private void emitConstructor(StringBuilder sb)
     {
-        emitComment(sb);
-
+    	if (!outputJS)
+    		emitComment(sb);
+
+    	if (outputJS)
+    	{
+        	sb.append(getClassReference().getPackageName());
+        	sb.append(".");
+        	sb.append(getBaseName());    		
+        	sb.append(" = function "); 		
+            sb.append(toParameterString());
+            sb.append(" {}\n");
+            return;
+    	}
+    	
         sb.append(indent);
         sb.append("public function ");
         sb.append(getBaseName());
@@ -276,7 +304,7 @@ public class MethodReference extends MemberReference
 
     private String toParameterString()
     {
-        return FunctionUtils.toParameterString(getContext(), getContext().getComment(), paramNode);
+        return FunctionUtils.toParameterString(getContext(), getContext().getComment(), paramNode,
outputJS);
     }
 
     public boolean isOverride()

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1a4a51ec/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
index 82ff5ec..4b2885b 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
@@ -77,7 +77,7 @@ public class FunctionUtils
         return sb.toString();
     }
 
-    public static String toParameterString(BaseReference reference, JSDocInfo comment, Node
paramNode)
+    public static String toParameterString(BaseReference reference, JSDocInfo comment, Node
paramNode, boolean outputJS)
     {
         final StringBuilder sb = new StringBuilder();
 
@@ -96,7 +96,9 @@ public class FunctionUtils
                 {
                     for (Node param : paramNode.children())
                     {
-                        sb.append(param.getString()).append(":Object");
+                        sb.append(param.getString());
+                        if (!outputJS)
+                        	sb.append(":Object");
                         if (index < len - 1)
                             sb.append(", ");
                         index++;
@@ -107,7 +109,7 @@ public class FunctionUtils
             {
                 for (String paramName : comment.getParameterNames())
                 {
-                    sb.append(toParameter(reference, comment, paramName, comment.getParameterType(paramName)));
+                    sb.append(toParameter(reference, comment, paramName, comment.getParameterType(paramName),
outputJS));
 
                     if (index < len - 1)
                         sb.append(", ");
@@ -153,7 +155,7 @@ public class FunctionUtils
     }
 
     private static String toParameter(BaseReference reference, JSDocInfo comment, String
paramName,
-            JSTypeExpression parameterType)
+            JSTypeExpression parameterType, boolean outputJS)
     {
         final StringBuilder sb = new StringBuilder();
 
@@ -166,7 +168,10 @@ public class FunctionUtils
         }
         else if (parameterType.isVarArgs())
         {
-            sb.append("...").append(paramName);
+        	if (outputJS)
+        		sb.append("var_").append(paramName);
+        	else
+        		sb.append("...").append(paramName);
         }
         else
         {
@@ -177,13 +182,15 @@ public class FunctionUtils
             }
 
             sb.append(paramName);
-            sb.append(":");
-            sb.append(paramType);
-
-            if (parameterType.isOptionalArg())
+            if (!outputJS)
             {
-                sb.append(" = ");
-                sb.append(toDefaultParameterValue(paramType));
+                sb.append(":");
+                sb.append(paramType);            	
+	            if (parameterType.isOptionalArg())
+	            {
+	                sb.append(" = ");
+	                sb.append(toDefaultParameterValue(paramType));
+	            }
             }
         }
 


Mime
View raw message