incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gordonsm...@apache.org
Subject svn commit: r1425170 - in /incubator/flex/falcon/trunk: compiler.tests/feature-tests/mxml/tags/ compiler/src/org/apache/flex/compiler/internal/as/codegen/ compiler/src/org/apache/flex/compiler/internal/tree/mxml/
Date Fri, 21 Dec 2012 22:38:30 GMT
Author: gordonsmith
Date: Fri Dec 21 22:38:30 2012
New Revision: 1425170

URL: http://svn.apache.org/viewvc?rev=1425170&view=rev
Log:
Falcon feature tests: Added a feature test for the <Metadata> tag.

It appears that Falcon doesn't automatically keep such metadata; you have to use -keep-as3-metadata
if it isn't one of the types like Event and Style that are kept by default. This is probably
a bug.

Made it possible to pass additional compilation options like -keep-as3-metadata when compiling
feature tests.

Added:
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLMetadataTagTests.java
  (with props)
Modified:
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLHTTPServiceTagTests.java
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLIntTagTests.java
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLRemoteObjectTagTests.java
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLWebServiceTagTests.java
    incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java
    incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java

Modified: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java?rev=1425170&r1=1425169&r2=1425170&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java
(original)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java
Fri Dec 21 22:38:30 2012
@@ -63,7 +63,7 @@ public class MXMLFeatureTestsBase
     // The Ant script for compiler.tests copies a standalone player to the temp directory.
     private static final String FLASHPLAYER = FilenameNormalization.normalize("temp/FlashPlayer.exe");
 
-	protected void compileAndRun(String mxml, boolean withFramework, boolean withRPC, boolean
withSpark)
+	protected void compileAndRun(String mxml, boolean withFramework, boolean withRPC, boolean
withSpark, String[] otherOptions)
 	{
 		// Write the MXML into a temp file.
 		String tempDir = FilenameNormalization.normalize("temp");
@@ -101,16 +101,22 @@ public class MXMLFeatureTestsBase
 		}
 		String libraryPath = "-library-path=" + StringUtils.join(swcs.toArray(new String[0]), ",");
 		
+		List<String> args = new ArrayList<String>();
+		args.add("-external-library-path=" + PLAYERGLOBAL_SWC);
+		args.add(libraryPath);
+		args.add("-namespace=" + NAMESPACE_2009 + "," + MANIFEST_2009);
+		if (otherOptions != null)
+		{
+			for (String otherOption : otherOptions)
+			{
+				args.add(otherOption);
+			}
+		}
+		args.add(tempMXMLFile.getAbsolutePath());
+		
 		// Use MXMLC to compile the MXML file against playerglobal.swc and possibly other SWCs.
 		MXMLC mxmlc = new MXMLC();
-		String[] args = new String[]
-        {
-			"-external-library-path=" + PLAYERGLOBAL_SWC,
-			libraryPath,
-			"-namespace=" + NAMESPACE_2009 + "," + MANIFEST_2009,
-			tempMXMLFile.getAbsolutePath()
-		};
-		int exitCode = mxmlc.mainNoExit(args);
+		int exitCode = mxmlc.mainNoExit(args.toArray(new String[0]));
 		
 		// Check that there were no compilation problems.
 		List<ICompilerProblem> problems = mxmlc.getProblems().getProblems();
@@ -125,10 +131,10 @@ public class MXMLFeatureTestsBase
 		// Run the SWF in the standalone player amd wait until the SWF calls System.exit().
 		String swf = FilenameNormalization.normalize(tempMXMLFile.getAbsolutePath());
 		swf = swf.replace(".mxml", ".swf");
-		args = new String[] { FLASHPLAYER, swf };
+		String[] runArgs = new String[] { FLASHPLAYER, swf };
 		try
 		{
-			Process process = Runtime.getRuntime().exec(args);
+			Process process = Runtime.getRuntime().exec(runArgs);
 			process.waitFor();
 			exitCode = process.exitValue();
 		}
@@ -143,6 +149,6 @@ public class MXMLFeatureTestsBase
 	
 	protected void compileAndRun(String mxml)
 	{
-		compileAndRun(mxml, false, false, false);
+		compileAndRun(mxml, false, false, false, null);
 	}
 }

Modified: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLHTTPServiceTagTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLHTTPServiceTagTests.java?rev=1425170&r1=1425169&r2=1425170&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLHTTPServiceTagTests.java
(original)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLHTTPServiceTagTests.java
Fri Dec 21 22:38:30 2012
@@ -71,6 +71,6 @@ public class MXMLHTTPServiceTagTests ext
             "assertEqual('hs1.method', hs1.method, 'POST');"
         };
         String mxml = getMXML(declarations, asserts);
-        compileAndRun(mxml, true, true, false);
+        compileAndRun(mxml, true, true, false, null);
     }
 }

Modified: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLIntTagTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLIntTagTests.java?rev=1425170&r1=1425169&r2=1425170&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLIntTagTests.java
(original)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLIntTagTests.java
Fri Dec 21 22:38:30 2012
@@ -22,7 +22,7 @@ package mxml.tags;
 import org.junit.Test;
 
 /**
- * Feature tests for the MXML [@code <int>} tag.
+ * Feature tests for the MXML {@code <int>} tag.
  * 
  * @author Gordon Smith
  */

Added: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLMetadataTagTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLMetadataTagTests.java?rev=1425170&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLMetadataTagTests.java
(added)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLMetadataTagTests.java
Fri Dec 21 22:38:30 2012
@@ -0,0 +1,141 @@
+/*
+ *
+ *  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 mxml.tags;
+
+import org.apache.flex.utils.StringUtils;
+import org.junit.Test;
+
+/**
+ * Feature tests for the MXML {@code <Metadata>} tag.
+ * 
+ * @author Gordon Smith
+ */
+public class MXMLMetadataTagTests extends MXMLFeatureTestsBase
+{
+	/**
+	 * Combines various code snippets to make a complete one-file MXML Sprite-based application.
+	 */
+    protected String getMXML(String[] metadata, String[] moreMetadata, String[] asserts)
+    {
+        String[] template = new String[]
+        {
+            "<d:Sprite xmlns:fx='http://ns.adobe.com/mxml/2009' xmlns:d='flash.display.*'",
+            "          enterFrame='enterFrameHandler(event)'>",
+            "    %1",
+            "    <fx:Script>",
+            "    <![CDATA[",
+            "        private function assertEqual(message:String, actualValue:*, expectedValue:*):void",
+            "        {",
+            "            if (actualValue !== expectedValue)",
+            "            {",
+            "                trace(message, actualValue, expectedValue);",
+            "                System.exit(1);",
+            "            }",
+            "        }",
+            "        private function enterFrameHandler(event:Event):void",
+            "        {",
+            "            %3",
+            "            System.exit(0);",
+            "        }",
+            "    ]]>",
+            "    </fx:Script>",
+            "    %2",
+            "</d:Sprite>"
+        };
+        String mxml = StringUtils.join(template, "\n");
+        mxml = mxml.replace("%1", StringUtils.join(metadata, "\n    "));
+        mxml = mxml.replace("%2", StringUtils.join(moreMetadata, "\n    "));
+        mxml = mxml.replace("%3", StringUtils.join(asserts, "\n            "));
+        return mxml;
+    }
+    
+    protected String getMXML(String[] metadata, String[] asserts)
+    {
+    	return getMXML(metadata, new String[0], asserts);
+    }
+    
+	@Test
+	public void MXMLMetadataTag_oneTag()
+	{
+        String[] metadata = new String[]
+        {
+            "<fx:Metadata>",
+            "    [AAA(a1='1', a2='2')]",
+            "</fx:Metadata>"
+        };
+        String[] asserts = new String[]
+        {
+            // The <Metadata> tag should produce class-level metadata
+            // that we can inspect at runtime with describeType().
+            // Inside the root tag returned by describeType() should be
+            //     <metadata name="AAA">
+            //         <arg key="a1" value="1"/>
+            //         <arg key="a2" value="2"/>
+            //     </metadata>
+        	"var dt:XML = describeType(this);",
+        	"var aaa:XMLList = dt.metadata.(@name == 'AAA');",
+            "assertEqual('aaa.arg[0].@key.toString()', aaa.arg[0].@key.toString(), 'a1');",
+            "assertEqual('aaa.arg[0].@value.toString()', aaa.arg[0].@value.toString(), '1');",
+            "assertEqual('aaa.arg[1].@key.toString()', aaa.arg[1].@key.toString(), 'a2');",
+            "assertEqual('aaa.arg[1].@value.toString()', aaa.arg[1].@value.toString(), '2');",
+        };
+        String mxml = getMXML(metadata, asserts);
+        String[] otherOptions = new String[]
+        {
+        	"-keep-as3-metadata=AAA" // this should not be necessary; the old compiler seems
to have kept all MXML metadata
+        };
+        compileAndRun(mxml, false, false, false, otherOptions);
+	}
+    
+	@Test
+	public void MXMLMetadataTag_twoTags()
+	{
+        String[] metadata = new String[]
+        {
+            "<fx:Metadata>",
+            "    [AAA(a1='1')]",
+            "</fx:Metadata>"
+        };
+        String[] moreMetadata = new String[]
+        {
+            "<fx:Metadata>",
+            "    [BBB(b1='1')]",
+            "</fx:Metadata>"
+        };
+        String[] asserts = new String[]
+        {
+        	"var dt:XML = describeType(this);",
+        	"var aaa:XMLList = dt.metadata.(@name == 'AAA');",
+            "assertEqual('aaa.arg[0].@key.toString()', aaa.arg[0].@key.toString(), 'a1');",
+            "assertEqual('aaa.arg[0].@value.toString()', aaa.arg[0].@value.toString(), '1');",
+        	"var bbb:XMLList = dt.metadata.(@name == 'BBB');",
+            "assertEqual('bbb.arg[0].@key.toString()', bbb.arg[0].@key.toString(), 'b1');",
+            "assertEqual('bbb.arg[0].@value.toString()', bbb.arg[0].@value.toString(), '1');",
+        };
+        String mxml = getMXML(metadata, moreMetadata, asserts);
+        String[] otherOptions = new String[]
+        {
+        	"-keep-as3-metadata=AAA,BBB" // this should not be necessary; the old compiler seems
to have kept all MXML metadata
+        };
+        compileAndRun(mxml, false, false, false, otherOptions);
+	}
+	
+	// TODO Add tests with CDATA, comments, entities, etc.
+}

Propchange: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLMetadataTagTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLRemoteObjectTagTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLRemoteObjectTagTests.java?rev=1425170&r1=1425169&r2=1425170&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLRemoteObjectTagTests.java
(original)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLRemoteObjectTagTests.java
Fri Dec 21 22:38:30 2012
@@ -68,6 +68,6 @@ public class MXMLRemoteObjectTagTests ex
             "assertEqual('ro1.operations.m2.name', ro1.operations['m2'].name, 'm2');",
         };
         String mxml = getMXML(declarations, scriptDeclarations, asserts);
-        compileAndRun(mxml, true, true, false);
+        compileAndRun(mxml, true, true, false, null);
     }
 }

Modified: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLWebServiceTagTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLWebServiceTagTests.java?rev=1425170&r1=1425169&r2=1425170&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLWebServiceTagTests.java
(original)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLWebServiceTagTests.java
Fri Dec 21 22:38:30 2012
@@ -69,6 +69,6 @@ public class MXMLWebServiceTagTests exte
             "assertEqual('ws1.operations.op2.name', ws1.operations['op2'].name, 'op2');",
         };
         String mxml = getMXML(declarations, scriptDeclarations, asserts);
-        compileAndRun(mxml, true, true, false);
+        compileAndRun(mxml, true, true, false, null);
     }
 }

Modified: incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java?rev=1425170&r1=1425169&r2=1425170&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java
(original)
+++ incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java
Fri Dec 21 22:38:30 2012
@@ -122,6 +122,7 @@ import org.apache.flex.abc.visitors.IMet
 import org.apache.flex.abc.visitors.ITraitVisitor;
 import org.apache.flex.abc.visitors.ITraitsVisitor;
 import org.apache.flex.compiler.common.DependencyType;
+import org.apache.flex.compiler.common.IMetaInfo;
 import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.constants.IASLanguageConstants.BuiltinType;
 import org.apache.flex.compiler.css.ICSSDocument;
@@ -978,9 +979,9 @@ public class MXMLClassDirectiveProcessor
     {
         // add "goto_definition_help" metadata to user defined metadata.
         ITraitVisitor tv = classScope.getGlobalScope().traitsVisitor.visitClassTrait(
-                TRAIT_Class, className, 0, cinfo);
-        this.classScope.processMetadata(tv,
-                ClassDirectiveProcessor.getAllMetaTags(classDefinition));
+            TRAIT_Class, className, 0, cinfo);
+        IMetaInfo[] metaTags = ClassDirectiveProcessor.getAllMetaTags(classDefinition);
+        classScope.processMetadata(tv, metaTags);
         tv.visitEnd();
         
         // Make any vistEnd method calls
@@ -3569,7 +3570,10 @@ public class MXMLClassDirectiveProcessor
     
     private void processMXMLMetadata(IMXMLMetadataNode metadataNode, Context context)
     {
-        // TODO
+        // Nothing to do.
+        // The metadata inside a <Metadata> tag was set onto the class definition
+        // when the file scope for the MXML file was created by MXMLScopeBuilder.
+        // Then finishClassDefinition() of this class will process it into ABC.
     }
     
     /**

Modified: incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java?rev=1425170&r1=1425169&r2=1425170&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java
(original)
+++ incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java
Fri Dec 21 22:38:30 2012
@@ -25,7 +25,6 @@ import java.util.List;
 
 import org.apache.flex.compiler.common.SourceLocation;
 import org.apache.flex.compiler.constants.IASLanguageConstants;
-import org.apache.flex.compiler.constants.IASLanguageConstants.BuiltinType;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;



Mime
View raw message