flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joshtynj...@apache.org
Subject [6/6] git commit: [flex-falcon] [refs/heads/develop] - compiler-jx: externc updated to use Closure compiler v20161201
Date Fri, 16 Dec 2016 23:26:24 GMT
compiler-jx: externc updated to use Closure compiler v20161201


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

Branch: refs/heads/develop
Commit: 8714ab1a77e129a89938f1489d162bd74aa02850
Parents: 5a121f9
Author: Josh Tynjala <joshtynjala@gmail.com>
Authored: Thu Dec 15 17:11:24 2016 -0800
Committer: Josh Tynjala <joshtynjala@gmail.com>
Committed: Fri Dec 16 15:25:39 2016 -0800

----------------------------------------------------------------------
 .../externals/pass/ReferenceCompiler.java       | 12 +--
 .../externals/reference/MethodReference.java    |  2 +-
 .../codegen/externals/TestExternChrome.java     |  2 +-
 .../codegen/externals/TestExternES3.java        |  2 +-
 .../codegen/externals/TestTypeExternals.java    | 79 +++++++-------------
 5 files changed, 34 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8714ab1a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java
index 2017848..4de8a88 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java
@@ -36,8 +36,6 @@ import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
 
 public class ReferenceCompiler
 {
-    private static final List<SourceFile> EMPTY_EXTERNS = ImmutableList.of(SourceFile.fromCode("externs",
""));
-
     private ReferenceModel model;
 
     private Compiler jscompiler;
@@ -100,21 +98,23 @@ public class ReferenceCompiler
     
     public Result compile() throws IOException
     {
-        List<SourceFile> sources = new ArrayList<SourceFile>();
+        List<SourceFile> externs = new ArrayList<SourceFile>();
         for (ExternalFile externalFile : model.getConfiguration().getExternals())
         {
             String name = externalFile.getName();
             String source = FileUtils.readFileToString(externalFile.getFile());
-            sources.add(SourceFile.fromCode("[" + name + "]", source));
+            externs.add(SourceFile.fromCode("[" + name + "]", source));
         }
         for (ExternalFile externalFile : model.getConfiguration().getExternalExterns())
         {
             String name = externalFile.getName();
             String source = FileUtils.readFileToString(externalFile.getFile());
-            sources.add(SourceFile.fromCode("[" + name + "]", source));
+            externs.add(SourceFile.fromCode("[" + name + "]", source));
         }
 
-        Result result = jscompiler.compile(EMPTY_EXTERNS, sources, options);
+        //should be passed in as externs rather than source files because they
+        //may contain annotations that are only allowed in externs -JT
+        Result result = jscompiler.compile(externs, new ArrayList<SourceFile>(), options);
         if (!result.success)
         {
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8714ab1a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
index 777967c..e978bf7 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
@@ -327,7 +327,7 @@ public class MethodReference extends MemberReference
         for (int i = 0; i < len; i++)
         {
             String parameterName = comment.getParameterNameAt(i);
-            JSTypeExpression parameterType = comment.getParameterType(i);
+            JSTypeExpression parameterType = comment.getParameterType(parameterName);
             sb.append(FunctionUtils.toParameter(getContext(), comment, parameterName, parameterType,
outputJS));
             if (i < len - 1)
                 sb.append(", ");

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8714ab1a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternChrome.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternChrome.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternChrome.java
index 107c725..6056569 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternChrome.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternChrome.java
@@ -67,7 +67,7 @@ public class TestExternChrome extends ExternalsTestBase
                 "ChromeLoadTimes",
                 "ChromeCsiInfo" };
 
-        assertEquals(285, model.getClasses().size());
+        assertEquals(301, model.getClasses().size());
         for (String className : classes)
         {
             assertTrue(model.hasClass(className));

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8714ab1a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
index 6052a19..3112707 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
@@ -60,7 +60,7 @@ public class TestExternES3 extends ExternalsTestBase
                 "Math" };
 
         // IObject and IArrayLike are two extras
-        assertEquals(19, model.getClasses().size());
+        assertEquals(23, model.getClasses().size());
         for (String className : classes)
         {
             assertTrue(model.hasClass(className));

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8714ab1a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeExternals.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeExternals.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeExternals.java
index 514f7a9..ac01088 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeExternals.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeExternals.java
@@ -28,6 +28,8 @@ import java.io.IOException;
 import org.apache.flex.compiler.clients.ExternCConfiguration;
 import org.apache.flex.compiler.internal.codegen.externals.reference.ClassReference;
 import org.apache.flex.compiler.internal.codegen.externals.reference.MethodReference;
+import org.apache.flex.compiler.internal.codegen.externals.utils.JSTypeUtils;
+
 import org.junit.Test;
 
 import com.google.javascript.rhino.JSDocInfo;
@@ -58,12 +60,12 @@ public class TestTypeExternals extends ExternalsTestBase
 
         ClassReference reference = model.getClassReference("Foo");
 
-        JSType jsType1 = getJSType("test1", "arg1");
-        JSType jsType2 = getJSType("test2", "arg1");
-        JSType jsType3 = getJSType("test3", "arg1");
-        JSType jsType4 = getJSType("test4", "arg1");
-        JSType jsType5 = getJSType("test5", "arg1");
-        JSType jsType6 = getJSType("test6", "arg1");
+        JSType jsType1 = getJSType("test1", true, "arg1");
+        JSType jsType2 = getJSType("test2", true, "arg1");
+        JSType jsType3 = getJSType("test3", true, "arg1");
+        JSType jsType4 = getJSType("test4", true, "arg1");
+        JSType jsType5 = getJSType("test5", true, "arg1");
+        JSType jsType6 = getJSType("test6", true, "arg1");
 
         assertTrue(jsType1.isString());
         assertTrue(jsType2.isUnionType());
@@ -72,64 +74,33 @@ public class TestTypeExternals extends ExternalsTestBase
         assertTrue(jsType5.isInstanceType());
         assertTrue(jsType6.isFunctionType());
 
-        assertEquals("String", toParamTypeString(jsType1));
-        assertEquals("foo.bar.Baz", toParamTypeString(jsType2));
+        assertEquals("String",
+                JSTypeUtils.toParamTypeString(reference.getStaticMethod("test1"), "arg1"));
+        assertEquals("foo.bar.Baz",
+                JSTypeUtils.toParamTypeString(reference.getStaticMethod("test2"), "arg1"));
         assertEquals("Object /* {myNum: number, myObject: ?} */",
-                toParamTypeString(jsType3));
-        assertEquals("Number", toParamTypeString(jsType4));
-        assertEquals("Object", toParamTypeString(jsType5));
+                JSTypeUtils.toParamTypeString(reference.getStaticMethod("test3"), "arg1"));
+        assertEquals("Number",
+                JSTypeUtils.toParamTypeString(reference.getStaticMethod("test4"), "arg1"));
+        assertEquals("Object",
+                JSTypeUtils.toParamTypeString(reference.getStaticMethod("test5"), "arg1"));
         assertEquals("Function /* function (string, boolean): ? */",
-                toParamTypeString(jsType6));
+                JSTypeUtils.toParamTypeString(reference.getStaticMethod("test6"), "arg1"));
     }
 
-    public String toParamTypeString(JSType jsType)
+    private JSType getJSType(String methodName, boolean isStatic, String paramName)
     {
-        String result = "";
-        if (jsType instanceof NamedType)
-        {
-            NamedType nt = (NamedType) jsType;
-            return nt.toAnnotationString();
-        }
-        else if (jsType.isString())
-        {
-            return "String";
-        }
-        else if (jsType.isBooleanObjectType())
-        {
-            return "Boolean";
-        }
-        else if (jsType.isNumber())
-        {
-            return "Number";
-        }
-        else if (jsType.isUnionType())
+    	MethodReference method = null;
+    	if(isStatic)
         {
-            JSType collapseUnion = jsType.restrictByNotNullOrUndefined();
-            return toParamTypeString(collapseUnion);
+            method = model.getClassReference("Foo").getStaticMethod(methodName);
         }
-        else if (jsType.isRecordType())
+        else
         {
-            return "Object /* " + jsType.toAnnotationString() + " */";
+            method = model.getClassReference("Foo").getInstanceMethod(methodName);
         }
-        else if (jsType.isInstanceType())
-        {
-            return jsType.toAnnotationString();
-        }
-        else if (jsType.isFunctionType())
-        {
-            return "Function /* " + jsType.toAnnotationString() + " */";
-        }
-
-        return result;
-    }
-
-    private JSType getJSType(String methodName, String paramName)
-    {
-    	MethodReference method = model.getClassReference("Foo").getInstanceMethod(methodName);
-    	if (method == null)
-    		method = model.getClassReference("Foo").getStaticMethod(methodName);
         JSDocInfo comment = method.getComment();
-        JSTypeExpression parameterType = comment.getParameterType("arg1");
+        JSTypeExpression parameterType = comment.getParameterType(paramName);
         JSType jsType = model.evaluate(parameterType);
         return jsType;
     }


Mime
View raw message