royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [royale-compiler] branch develop updated: fix the way we generate externs. This should eliminate warnings from Closure Compiler
Date Wed, 23 May 2018 22:58:38 GMT
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new 850c46a  fix the way we generate externs.  This should eliminate warnings from Closure
Compiler
850c46a is described below

commit 850c46aaf8aa008bf10701116477143a60996f23
Author: Alex Harui <aharui@apache.org>
AuthorDate: Wed May 23 15:58:28 2018 -0700

    fix the way we generate externs.  This should eliminate warnings from Closure Compiler
---
 .../codegen/js/jx/PackageFooterEmitter.java        | 225 +++++++++++----------
 .../codegen/js/jx/PackageHeaderEmitter.java        |  78 ++++---
 2 files changed, 166 insertions(+), 137 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/PackageFooterEmitter.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/PackageFooterEmitter.java
index 980f1b3..0048b91 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/PackageFooterEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/PackageFooterEmitter.java
@@ -76,121 +76,124 @@ public class PackageFooterEmitter extends JSSubEmitter implements
 
 		boolean isInterface = tnode instanceof IInterfaceNode;
 
-	    /*
-	     * Metadata
-	     * 
-	     * @type {Object.<string, Array.<Object>>}
-	     */
-	    writeNewline();
-	    writeNewline();
-	    writeNewline();
-	    doc.begin();
-	    writeNewline(" * Metadata");
-	    writeNewline(" *");
-	    writeNewline(" * @type {Object.<string, Array.<Object>>}");
-	    doc.end();
-
-	    // a.B.prototype.AFJS_CLASS_INFO = {  };
-	    write(getEmitter().formatQualifiedName(tnode.getQualifiedName()));
-	    write(ASEmitterTokens.MEMBER_ACCESS);
-	    write(JSEmitterTokens.PROTOTYPE);
-	    write(ASEmitterTokens.MEMBER_ACCESS);
-	    writeToken(JSRoyaleEmitterTokens.ROYALE_CLASS_INFO);
-	    writeToken(ASEmitterTokens.EQUAL);
-	    writeToken(ASEmitterTokens.BLOCK_OPEN);
-	
-	    // names: [{ name: '', qName: '', kind:'interface|class' }]
-	    write(JSRoyaleEmitterTokens.NAMES);
-	    writeToken(ASEmitterTokens.COLON);
-	    write(ASEmitterTokens.SQUARE_OPEN);
-	    writeToken(ASEmitterTokens.BLOCK_OPEN);
-	    write(JSRoyaleEmitterTokens.NAME);
-	    writeToken(ASEmitterTokens.COLON);
-	    write(ASEmitterTokens.SINGLE_QUOTE);
-	    write(tnode.getName());
-	    write(ASEmitterTokens.SINGLE_QUOTE);
-	    writeToken(ASEmitterTokens.COMMA);
-	    write(JSRoyaleEmitterTokens.QNAME);
-	    writeToken(ASEmitterTokens.COLON);
-	    write(ASEmitterTokens.SINGLE_QUOTE);
-	    write(getEmitter().formatQualifiedName(tnode.getQualifiedName()));
-	    write(ASEmitterTokens.SINGLE_QUOTE);
-		writeToken(ASEmitterTokens.COMMA);
-		write(JSRoyaleEmitterTokens.ROYALE_CLASS_INFO_KIND);
-		writeToken(ASEmitterTokens.COLON);
-		write(ASEmitterTokens.SINGLE_QUOTE);
-		if (isInterface) write(JSRoyaleEmitterTokens.ROYALE_CLASS_INFO_INTERFACE_KIND);
-		else write(JSRoyaleEmitterTokens.ROYALE_CLASS_INFO_CLASS_KIND);
-		writeToken(ASEmitterTokens.SINGLE_QUOTE);
-	    write(ASEmitterTokens.BLOCK_CLOSE);
-	    write(ASEmitterTokens.SQUARE_CLOSE);
-
-	    IExpressionNode[] enodes;
-	    if (tnode instanceof IClassNode)
-	        enodes = ((IClassNode) tnode).getImplementedInterfaceNodes();
-	    else {
-			enodes = ((IInterfaceNode) tnode).getExtendedInterfaceNodes();
-		}
-
-
-		boolean needsIEventDispatcher = tnode instanceof IClassNode
-				&& ((IClassDefinition) tnode.getDefinition()).needsEventDispatcher(getProject())
-				&& getModel().getImplicitBindableImplementation() == ImplicitBindableImplementation.IMPLEMENTS;
-
-		//we can remove the mapping from the model for ImplicitBindableImplementation now
-		if (tnode.getDefinition() instanceof IClassDefinition)
-				getModel().unregisterImplicitBindableImplementation(
-						(IClassDefinition) tnode.getDefinition());
-
-	    if (enodes.length > 0 || needsIEventDispatcher)
+	    if (!getEmitter().getModel().isExterns)
 	    {
-	        writeToken(ASEmitterTokens.COMMA);
+		    /*
+		     * Metadata
+		     * 
+		     * @type {Object.<string, Array.<Object>>}
+		     */
+		    writeNewline();
+		    writeNewline();
+		    writeNewline();
+		    doc.begin();
+		    writeNewline(" * Metadata");
+		    writeNewline(" *");
+		    writeNewline(" * @type {Object.<string, Array.<Object>>}");
+		    doc.end();
 	
-	        // interfaces: [a.IC, a.ID]
-	        write(JSRoyaleEmitterTokens.INTERFACES);
-	        writeToken(ASEmitterTokens.COLON);
-	        write(ASEmitterTokens.SQUARE_OPEN);
-			if (needsIEventDispatcher) {
-				//add IEventDispatcher interface to implemented interfaces list
-				write(getEmitter().formatQualifiedName(BindableEmitter.DISPATCHER_INTERFACE_QNAME));
-				if (enodes.length > 0)
-					writeToken(ASEmitterTokens.COMMA);
+		    // a.B.prototype.AFJS_CLASS_INFO = {  };
+		    write(getEmitter().formatQualifiedName(tnode.getQualifiedName()));
+		    write(ASEmitterTokens.MEMBER_ACCESS);
+		    write(JSEmitterTokens.PROTOTYPE);
+		    write(ASEmitterTokens.MEMBER_ACCESS);
+		    writeToken(JSRoyaleEmitterTokens.ROYALE_CLASS_INFO);
+		    writeToken(ASEmitterTokens.EQUAL);
+		    writeToken(ASEmitterTokens.BLOCK_OPEN);
+		
+		    // names: [{ name: '', qName: '', kind:'interface|class' }]
+		    write(JSRoyaleEmitterTokens.NAMES);
+		    writeToken(ASEmitterTokens.COLON);
+		    write(ASEmitterTokens.SQUARE_OPEN);
+		    writeToken(ASEmitterTokens.BLOCK_OPEN);
+		    write(JSRoyaleEmitterTokens.NAME);
+		    writeToken(ASEmitterTokens.COLON);
+		    write(ASEmitterTokens.SINGLE_QUOTE);
+		    write(tnode.getName());
+		    write(ASEmitterTokens.SINGLE_QUOTE);
+		    writeToken(ASEmitterTokens.COMMA);
+		    write(JSRoyaleEmitterTokens.QNAME);
+		    writeToken(ASEmitterTokens.COLON);
+		    write(ASEmitterTokens.SINGLE_QUOTE);
+		    write(getEmitter().formatQualifiedName(tnode.getQualifiedName()));
+		    write(ASEmitterTokens.SINGLE_QUOTE);
+			writeToken(ASEmitterTokens.COMMA);
+			write(JSRoyaleEmitterTokens.ROYALE_CLASS_INFO_KIND);
+			writeToken(ASEmitterTokens.COLON);
+			write(ASEmitterTokens.SINGLE_QUOTE);
+			if (isInterface) write(JSRoyaleEmitterTokens.ROYALE_CLASS_INFO_INTERFACE_KIND);
+			else write(JSRoyaleEmitterTokens.ROYALE_CLASS_INFO_CLASS_KIND);
+			writeToken(ASEmitterTokens.SINGLE_QUOTE);
+		    write(ASEmitterTokens.BLOCK_CLOSE);
+		    write(ASEmitterTokens.SQUARE_CLOSE);
+	
+		    IExpressionNode[] enodes;
+		    if (tnode instanceof IClassNode)
+		        enodes = ((IClassNode) tnode).getImplementedInterfaceNodes();
+		    else {
+				enodes = ((IInterfaceNode) tnode).getExtendedInterfaceNodes();
 			}
-	        int i = 0;
-	        for (IExpressionNode enode : enodes)
-	        {
-	        	IDefinition edef = enode.resolve(getProject());
-	        	if (edef == null)
-	        		continue;
-	            write(getEmitter().formatQualifiedName(
-	                    edef.getQualifiedName()));
-	            if (i < enodes.length - 1)
-	                writeToken(ASEmitterTokens.COMMA);
-	            i++;
-	        }
-	        write(ASEmitterTokens.SQUARE_CLOSE);
+	
+	
+			boolean needsIEventDispatcher = tnode instanceof IClassNode
+					&& ((IClassDefinition) tnode.getDefinition()).needsEventDispatcher(getProject())
+					&& getModel().getImplicitBindableImplementation() == ImplicitBindableImplementation.IMPLEMENTS;
+	
+			//we can remove the mapping from the model for ImplicitBindableImplementation now
+			if (tnode.getDefinition() instanceof IClassDefinition)
+					getModel().unregisterImplicitBindableImplementation(
+							(IClassDefinition) tnode.getDefinition());
+	
+		    if (enodes.length > 0 || needsIEventDispatcher)
+		    {
+		        writeToken(ASEmitterTokens.COMMA);
+		
+		        // interfaces: [a.IC, a.ID]
+		        write(JSRoyaleEmitterTokens.INTERFACES);
+		        writeToken(ASEmitterTokens.COLON);
+		        write(ASEmitterTokens.SQUARE_OPEN);
+				if (needsIEventDispatcher) {
+					//add IEventDispatcher interface to implemented interfaces list
+					write(getEmitter().formatQualifiedName(BindableEmitter.DISPATCHER_INTERFACE_QNAME));
+					if (enodes.length > 0)
+						writeToken(ASEmitterTokens.COMMA);
+				}
+		        int i = 0;
+		        for (IExpressionNode enode : enodes)
+		        {
+		        	IDefinition edef = enode.resolve(getProject());
+		        	if (edef == null)
+		        		continue;
+		            write(getEmitter().formatQualifiedName(
+		                    edef.getQualifiedName()));
+		            if (i < enodes.length - 1)
+		                writeToken(ASEmitterTokens.COMMA);
+		            i++;
+		        }
+		        write(ASEmitterTokens.SQUARE_CLOSE);
+		    }
+		    write(ASEmitterTokens.SPACE);
+		    write(ASEmitterTokens.BLOCK_CLOSE);
+		    write(ASEmitterTokens.SEMICOLON);
+
+		    collectReflectionData(tnode);
+		    IMetaTagNode[] metadata = null;
+		    IMetaTagsNode metadataTags = tnode.getMetaTags();
+		    if (metadataTags != null)
+		    	metadata = metadataTags.getAllTags();
+	
+			String typeName = getEmitter().formatQualifiedName(tnode.getQualifiedName());
+	
+		    emitReflectionData(
+		    		typeName,
+					reflectionKind,
+		    		varData,
+		    		accessorData,
+		    		methodData,
+		    		metadata);
+		    
+		    emitExportProperties(typeName, exportProperties, exportSymbols);
 	    }
-	    write(ASEmitterTokens.SPACE);
-	    write(ASEmitterTokens.BLOCK_CLOSE);
-	    write(ASEmitterTokens.SEMICOLON);
-
-	    collectReflectionData(tnode);
-	    IMetaTagNode[] metadata = null;
-	    IMetaTagsNode metadataTags = tnode.getMetaTags();
-	    if (metadataTags != null)
-	    	metadata = metadataTags.getAllTags();
-
-		String typeName = getEmitter().formatQualifiedName(tnode.getQualifiedName());
-
-	    emitReflectionData(
-	    		typeName,
-				reflectionKind,
-	    		varData,
-	    		accessorData,
-	    		methodData,
-	    		metadata);
-	    
-	    emitExportProperties(typeName, exportProperties, exportSymbols);
     }
 
     public enum ReflectionKind{
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java
index 172519e..acc7317 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java
@@ -143,34 +143,60 @@ public class PackageHeaderEmitter extends JSSubEmitter implements
         writeNewline(" */");
         writeNewline();
 
-        /* goog.provide('x');\n\n */
-        write(JSGoogEmitterTokens.GOOG_PROVIDE);
-        write(ASEmitterTokens.PAREN_OPEN);
-        write(ASEmitterTokens.SINGLE_QUOTE);
-        write(((JSRoyaleEmitter)getEmitter()).formatQualifiedName(qname, true));
-        write(ASEmitterTokens.SINGLE_QUOTE);
-        write(ASEmitterTokens.PAREN_CLOSE);
-        writeNewline(ASEmitterTokens.SEMICOLON);
-        
-        HashMap<String, String> internalClasses = getEmitter().getModel().getInternalClasses();
-        if (internalClasses.size() > 0)
+        if (!isExterns)
         {
-        	ArrayList<String> classesInOrder = new ArrayList<String>();
-        	for (String internalClass : internalClasses.keySet())
-        	{
-        		classesInOrder.add(internalClass);
-        	}
-        	Collections.sort(classesInOrder);
-        	for (String internalClass : classesInOrder)
+	        /* goog.provide('x');\n\n */
+	        write(JSGoogEmitterTokens.GOOG_PROVIDE);
+	        write(ASEmitterTokens.PAREN_OPEN);
+	        write(ASEmitterTokens.SINGLE_QUOTE);
+	        write(((JSRoyaleEmitter)getEmitter()).formatQualifiedName(qname, true));
+	        write(ASEmitterTokens.SINGLE_QUOTE);
+	        write(ASEmitterTokens.PAREN_CLOSE);
+	        writeNewline(ASEmitterTokens.SEMICOLON);
+	        
+	        HashMap<String, String> internalClasses = getEmitter().getModel().getInternalClasses();
+	        if (internalClasses.size() > 0)
+	        {
+	        	ArrayList<String> classesInOrder = new ArrayList<String>();
+	        	for (String internalClass : internalClasses.keySet())
+	        	{
+	        		classesInOrder.add(internalClass);
+	        	}
+	        	Collections.sort(classesInOrder);
+	        	for (String internalClass : classesInOrder)
+	        	{
+	        	       /* goog.provide('x');\n\n */
+	                write(JSGoogEmitterTokens.GOOG_PROVIDE);
+	                write(ASEmitterTokens.PAREN_OPEN);
+	                write(ASEmitterTokens.SINGLE_QUOTE);
+	                write(((JSRoyaleEmitter)getEmitter()).formatQualifiedName(internalClass,
true));
+	                write(ASEmitterTokens.SINGLE_QUOTE);
+	                write(ASEmitterTokens.PAREN_CLOSE);
+	                writeNewline(ASEmitterTokens.SEMICOLON);
+	        	}
+	        }
+        }
+        else
+        {
+        	String pkgName = definition.getQualifiedName();
+        	if (pkgName.length() > 0)
         	{
-        	       /* goog.provide('x');\n\n */
-                write(JSGoogEmitterTokens.GOOG_PROVIDE);
-                write(ASEmitterTokens.PAREN_OPEN);
-                write(ASEmitterTokens.SINGLE_QUOTE);
-                write(((JSRoyaleEmitter)getEmitter()).formatQualifiedName(internalClass,
true));
-                write(ASEmitterTokens.SINGLE_QUOTE);
-                write(ASEmitterTokens.PAREN_CLOSE);
-                writeNewline(ASEmitterTokens.SEMICOLON);
+        		String[] parts = pkgName.split("\\.");
+        		String current = "";
+        		boolean firstOne = true;
+        		for (String part : parts)
+        		{
+        			current += part;
+        			if (firstOne)
+        			{
+        				write("var ");
+        				firstOne = false;
+        			}
+        			write(current);
+        			write(" = {}");
+	                writeNewline(ASEmitterTokens.SEMICOLON);
+	                current += ".";
+        		}
         	}
         }
         writeNewline();

-- 
To stop receiving notification emails like this one, please contact
aharui@apache.org.

Mime
View raw message