You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ft...@apache.org on 2015/06/27 19:21:48 UTC

[2/2] git commit: [flex-falcon] [refs/heads/develop] - Fix: EXTERNC - IMPORT NOT EMITTED

Fix: EXTERNC - IMPORT NOT EMITTED

Imports relative to some function return type
are now emitted only if either the static member or the
return type class are not excluded.

This includes that:

 Given a function A():ns.ReturnType
  And A is not excluded
  And ns.ReturnType is not excluded
Then the import of ns.ReturnType will occur.

 Given a function A():ns.ReturnType
  And A is not excluded
  And ns.ReturnType is excluded
Then the import of ns.ReturnType will NOT occur.

 Given a function A():ns.ReturnType
  And A is excluded
  And ns.ReturnType is not excluded
Then the import of ns.ReturnType will NOT occur.

 Given a function A():ns.ReturnType
  And B():ns.ReturnType
  And B is excluded
  And ns.ReturnType is not excluded
 Then the import of ns.ReturnType still occur.


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

Branch: refs/heads/develop
Commit: 9775608bab4674b8ff54ed86ed01c9135443939c
Parents: 83664d7
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Sat Jun 27 18:07:19 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Sat Jun 27 18:20:25 2015 +0100

----------------------------------------------------------------------
 .../codegen/externals/ExternalsTestUtils.java   |  3 +
 .../codegen/externals/TestExternJasmine.java    | 83 ++++++++++++++++++++
 .../externals/reference/ClassReference.java     | 50 +++++++++---
 3 files changed, 123 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9775608b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestUtils.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestUtils.java
index 8cdca1b..b6989bc 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestUtils.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestUtils.java
@@ -37,6 +37,9 @@ public class ExternalsTestUtils
     public static File EXTERNAL_JS_DIR = FilenameNormalization.normalize(new File(
             "../externs/js/externs"));
 
+    public static File EXTERNAL_JASMINE_DIR = FilenameNormalization.normalize(new File(
+            "../externs/jasmine/externs"));
+
     public static File AS_ROOT_DIR = new File(TEMP_DIR, "externals/as");
 
     public static void addTestExcludesFull(ExternCConfiguration config)

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9775608b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternJasmine.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternJasmine.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternJasmine.java
new file mode 100644
index 0000000..fdfd3ce
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternJasmine.java
@@ -0,0 +1,83 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.externals;
+
+import com.google.javascript.jscomp.Result;
+import org.apache.flex.compiler.clients.ExternCConfiguration;
+import org.apache.flex.compiler.internal.codegen.externals.reference.ClassReference;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.*;
+
+public class TestExternJasmine extends ExternalsTestBase
+{
+    @Test
+    public void test_classes() throws IOException
+    {
+        client.cleanOutput();
+        Result result = compile();
+        assertTrue(result.success);
+
+        String[] classes = {
+                "jasmine",
+                "jasmine.Clock"};
+
+        assertEquals(9, model.getClasses().size());
+        for (String className : classes)
+        {
+            assertTrue(model.hasClass(className));
+        }
+
+        client.emit();
+    }
+
+    @Test
+    public void test_members() throws IOException
+    {
+        client.cleanOutput();
+        Result result = compile();
+        assertTrue(result.success);
+
+        // jasmine
+        ClassReference jasmine = model.getClassReference("jasmine");
+        assertNotNull(jasmine);
+
+        assertTrue(jasmine.hasStaticMethod("clock"));
+        assertEquals("jasmine.Clock", jasmine.getMethod("clock").toReturnTypeAnnotationString());
+
+        assertTrue(jasmine.hasImport("jasmine.Clock"));
+
+        //Clock
+        ClassReference Clock = model.getClassReference("jasmine.Clock");
+        assertNotNull(Clock);
+    }
+
+    @Override
+    protected void configure(ExternCConfiguration install) throws IOException
+    {
+        config.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
+
+        String coreRoot = ExternalsTestUtils.EXTERNAL_JASMINE_DIR.getAbsolutePath();
+        config.addExternal(coreRoot + "/jasmine-2.0.js");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9775608b/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 d74684a..dfaf0a6 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
@@ -19,29 +19,24 @@
 
 package org.apache.flex.compiler.internal.codegen.externals.reference;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.flex.compiler.internal.codegen.externals.utils.DebugLogUtils;
-import org.apache.flex.compiler.internal.codegen.externals.utils.JSTypeUtils;
-
 import com.google.javascript.rhino.JSDocInfo;
 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 org.apache.flex.compiler.internal.codegen.externals.utils.DebugLogUtils;
+import org.apache.flex.compiler.internal.codegen.externals.utils.JSTypeUtils;
+
+import java.io.File;
+import java.util.*;
+import java.util.Map.Entry;
 
 public class ClassReference extends BaseReference
 {
     private boolean isFinal;
     private int enumConstantCounter = 0;
 
-    private List<String> imports = new ArrayList<String>();
+    private Set<String> imports = new HashSet<String>();
     private MethodReference constructor;
     private Map<String, FieldReference> fields = new HashMap<String, FieldReference>();
     private Map<String, MethodReference> methods = new HashMap<String, MethodReference>();
@@ -121,7 +116,6 @@ public class ClassReference extends BaseReference
      * @param node (FUNCTION [NAME, PARAM_LIST, BLOCK]), or (ASSIGN [FUNCTION
      *        [NAME, PARAM_LIST, BLOCK]])
      * @param qualfiedName
-     * @param comment
      */
     public ClassReference(ReferenceModel model, Node node, String qualfiedName)
     {
@@ -509,10 +503,35 @@ public class ClassReference extends BaseReference
 
         MethodReference method = new MethodReference(getModel(), this, node,
                 functionName, comment, isStatic);
+
+        final String returnType = getReturnType(method);
+        if (returnType != null)
+        {
+            addImport(returnType);
+        }
+
         methods.put(functionName, method);
         return method;
     }
 
+    private String getReturnType(final MethodReference method) {
+        String returnType = null;
+
+        final JSDocInfo comment = method.getComment();
+        if (method.isExcluded() == null && comment != null && comment.hasReturnType())
+        {
+            try {
+                final Node firstChild = comment.getReturnType().getRoot().getFirstChild();
+                returnType = firstChild.getString();
+                final ClassReference reference = new ClassReference(null, method.getNode(), returnType);
+                returnType = returnType.contains(".") ? getModel().isExcludedClass(reference) == null ? returnType : null : null;
+            } catch (Exception e) {
+                returnType = null;
+            }
+        }
+        return returnType;
+    }
+
     public boolean isMethodOverrideFromInterface(MethodReference reference)
     {
         if (!hasImplementations())
@@ -614,6 +633,11 @@ public class ClassReference extends BaseReference
         imports.add(qualifiedName);
     }
 
+    public boolean hasImport(String qualifiedName)
+    {
+        return imports.contains(qualifiedName);
+    }
+
     private boolean hasImplementations()
     {
         return getComment().getImplementedInterfaceCount() > 0;