flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject svn commit: r1436642 - in /flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler: internal/as/codegen/ASEmitter.java internal/js/codegen/goog/JSGoogDocEmitter.java internal/js/codegen/goog/JSGoogEmitter.java js/codegen/goog/IJSGoogDocEmitter.java
Date Mon, 21 Jan 2013 21:52:16 GMT
Author: erikdebruin
Date: Mon Jan 21 21:52:16 2013
New Revision: 1436642

URL: http://svn.apache.org/viewvc?rev=1436642&view=rev
Log:
- made minor adjustments to the 'goog' output in various places, to ensure that the VanillaSDK
POC project is emitted as valid 'goog' JS

Modified:
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java?rev=1436642&r1=1436641&r2=1436642&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
Mon Jan 21 21:52:16 2013
@@ -1084,7 +1084,7 @@ public class ASEmitter implements IASEmi
         return null;
     }
 
-    private void walkArguments(IExpressionNode[] nodes)
+    protected void walkArguments(IExpressionNode[] nodes)
     {
         int len = nodes.length;
         for (int i = 0; i < len; i++)

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java?rev=1436642&r1=1436641&r2=1436642&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
Mon Jan 21 21:52:16 2013
@@ -20,16 +20,13 @@
 package org.apache.flex.compiler.internal.js.codegen.goog;
 
 import org.apache.flex.compiler.common.ASModifier;
-import org.apache.flex.compiler.common.DependencyType;
 import org.apache.flex.compiler.constants.IASKeywordConstants;
 import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
-import org.apache.flex.compiler.definitions.references.IReference;
 import org.apache.flex.compiler.internal.as.codegen.ASEmitter;
 import org.apache.flex.compiler.internal.js.codegen.JSDocEmitter;
 import org.apache.flex.compiler.internal.js.codegen.JSSharedData;
-import org.apache.flex.compiler.internal.scopes.ASScope;
 import org.apache.flex.compiler.internal.semantics.SemanticUtils;
 import org.apache.flex.compiler.js.codegen.IJSEmitter;
 import org.apache.flex.compiler.js.codegen.goog.IJSGoogDocEmitter;
@@ -37,13 +34,12 @@ import org.apache.flex.compiler.projects
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IInterfaceNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
-import org.apache.flex.compiler.tree.as.IScopedNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
-import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
 
 public class JSGoogDocEmitter extends JSDocEmitter implements IJSGoogDocEmitter
 {
@@ -56,50 +52,51 @@ public class JSGoogDocEmitter extends JS
     {
         super(emitter);
     }
-
+    
     @Override
     public void emitInterfaceDoc(IInterfaceNode node)
     {
         begin();
-
-        emitJSDocLine(JSGoogEmitter.INTERFACE);
-
+        
+        emitJSDocLine(JSGoogEmitter.INTERFACE); 
+        
         String[] inodes = node.getExtendedInterfaces();
         for (String inode : inodes)
         {
             emitJSDocLine(IASKeywordConstants.EXTENDS, inode);
         }
-
+        
         end();
     }
-
+    
     @Override
     public void emitFieldDoc(IVariableNode node)
     {
-        begin();
-
-        String ns = node.getNamespace();
-        if (ns == IASKeywordConstants.PRIVATE)
-        {
-            emitPrivate(node);
-        }
-        else if (ns == IASKeywordConstants.PROTECTED)
-        {
-            emitProtected(node);
-        }
-
-        if (node.isConst())
-            emitConst(node);
-
-        emitType(node);
-
-        end();
+    	begin();
+    	
+    	String ns = node.getNamespace();
+    	if (ns == IASKeywordConstants.PRIVATE)
+    	{
+    		emitPrivate(node);
+    	}
+    	else if (ns == IASKeywordConstants.PROTECTED)
+    	{	
+    		emitProtected(node);
+    	}
+    	
+    	if (node.isConst())
+    		emitConst(node);
+    	
+    	emitType(node, "");
+    	
+    	end();
     }
-
+    
     @Override
     public void emitMethodDoc(IFunctionNode node, ICompilerProject project)
     {
-        IClassDefinition classDefinition = resolveClassDefinition(node);
+        IClassNode cnode = (IClassNode) node.getAncestorOfType(IClassNode.class);
+        IClassDefinition classDefinition = cnode.getDefinition();
 
         if (node instanceof IFunctionNode)
         {
@@ -107,37 +104,28 @@ public class JSGoogDocEmitter extends JS
 
             if (node.isConstructor())
             {
+            	// TODO (erikdebruin) handle JSDOC for constructors with arguments
+            	
                 begin();
                 hasDoc = true;
-
+                
                 emitJSDocLine(JSGoogEmitter.CONSTRUCTOR);
-
-                IClassDefinition parent = (IClassDefinition) node
-                        .getDefinition().getParent();
+                
+                IClassDefinition parent = (IClassDefinition) node.getDefinition().getParent();
                 IClassDefinition superClass = parent.resolveBaseClass(project);
-                String qname = superClass.getQualifiedName();
-
-                if (superClass != null
-                        && !qname.equals(IASLanguageConstants.Object))
+            	String qname = superClass.getQualifiedName();
+            	
+                if (superClass != null && !qname.equals(IASLanguageConstants.Object))
                     emitExtends(superClass);
-
-                IReference[] references = classDefinition
-                        .getImplementedInterfaceReferences();
-                for (IReference iReference : references)
+                
+                IExpressionNode[] inodes = cnode.getImplementedInterfaceNodes();
+                if (inodes.length > 0)
                 {
-                    emitImplements((ITypeDefinition) iReference.resolve(
-                            project, (ASScope) classDefinition.getContainingScope(),
-                            DependencyType.INHERITANCE, true));
+                    for (IExpressionNode inode : inodes)
+                    {
+                    	emitImplements(inode.resolveType(project));
+                    }
                 }
-
-                //                IExpressionNode[] inodes = cnode.getImplementedInterfaceNodes();
-                //                if (inodes.length > 0)
-                //                {
-                //                    for (IExpressionNode inode : inodes)
-                //                    {
-                //                        emitImplements(inode.resolveType(project));
-                //                    }
-                //                }
             }
             else
             {
@@ -165,9 +153,7 @@ public class JSGoogDocEmitter extends JS
 
                 // @return
                 String returnType = node.getReturnType();
-                if (returnType != ""
-                        && returnType != ASTNodeID.LiteralVoidID
-                                .getParaphrase())
+                if (returnType != "" && returnType != ASTNodeID.LiteralVoidID.getParaphrase())
                 {
                     if (!hasDoc)
                     {
@@ -191,29 +177,33 @@ public class JSGoogDocEmitter extends JS
                     emitOverride(node);
                 }
             }
-
+            
             if (hasDoc)
                 end();
         }
     }
 
     @Override
-    public void emitVarDoc(IVariableNode node)
+    public void emitVarDoc(IVariableNode node, ITypeDefinition typedef)
     {
+    	String packageName = "";
+        if (typedef != null)
+        	packageName = typedef.getPackageName();
+
         if (!node.isConst())
-        {
-            emitTypeShort(node);
+        {	
+        	emitTypeShort(node, packageName);
         }
         else
         {
-            writeNewline();
-            begin();
-            emitConst(node);
-            emitType(node);
-            end();
+        	writeNewline();
+        	begin();
+        	emitConst(node);
+        	emitType(node, packageName);
+        	end();
         }
     }
-
+    
     @Override
     public void emitConst(IVariableNode node)
     {
@@ -244,15 +234,13 @@ public class JSGoogDocEmitter extends JS
     @Override
     public void emitExtends(IClassDefinition superDefinition)
     {
-        emitJSDocLine(IASKeywordConstants.EXTENDS,
-                superDefinition.getQualifiedName());
+        emitJSDocLine(IASKeywordConstants.EXTENDS, superDefinition.getQualifiedName());
     }
 
     @Override
     public void emitImplements(ITypeDefinition definition)
     {
-        emitJSDocLine(IASKeywordConstants.IMPLEMENTS,
-                definition.getQualifiedName());
+        emitJSDocLine(IASKeywordConstants.IMPLEMENTS, definition.getQualifiedName());
     }
 
     @Override
@@ -278,15 +266,14 @@ public class JSGoogDocEmitter extends JS
     @Override
     public void emitParam(IParameterNode node)
     {
-        String postfix = (node.getDefaultValue() == null) ? ""
-                : ASEmitter.EQUALS;
-
-        String paramType = "";
-        if (node.isRest())
-            paramType = IASLanguageConstants.REST;
-        else
-            paramType = convertASTypeToJS(node.getVariableType());
-
+    	String postfix = (node.getDefaultValue() == null) ? "" : ASEmitter.EQUALS;
+    	
+    	String paramType = "";
+    	if (node.isRest())
+    		paramType = IASLanguageConstants.REST;
+    	else
+    		paramType = convertASTypeToJS(node.getVariableType());
+    	
         emitJSDocLine(PARAM, paramType + postfix, node.getName());
     }
 
@@ -319,21 +306,26 @@ public class JSGoogDocEmitter extends JS
     }
 
     @Override
-    public void emitType(IASNode node)
+    public void emitType(IASNode node, String packageName)
     {
         String type = ((IVariableNode) node).getVariableType();
         emitJSDocLine(TYPE, convertASTypeToJS(type));
     }
 
-    public void emitTypeShort(IASNode node)
+    public void emitTypeShort(IASNode node, String packageName)
     {
-        String type = ((IVariableNode) node).getVariableType();
+        String type = ((IVariableNode) node).getVariableType(); 
         write(JSDOC_OPEN);
         writeSpace();
         write(AT);
         write(TYPE);
-        writeSpace();
+    	writeSpace();
         writeBlockOpen();
+        if (packageName != "")
+        {
+        	write(packageName);
+        	write(ASEmitter.PERIOD);
+        }
         write(convertASTypeToJS(type));
         writeBlockClose();
         writeSpace();
@@ -364,14 +356,14 @@ public class JSGoogDocEmitter extends JS
 
     private void emitJSDocLine(String name)
     {
-        emitJSDocLine(name, "");
+    	emitJSDocLine(name, "");
     }
-
+    
     private void emitJSDocLine(String name, String type)
     {
-        emitJSDocLine(name, type, "");
+    	emitJSDocLine(name, type, "");
     }
-
+    
     private void emitJSDocLine(String name, String type, String param)
     {
         writeSpace();
@@ -380,20 +372,20 @@ public class JSGoogDocEmitter extends JS
         write(AT);
         write(name);
         if (type != "")
-        {
-            writeSpace();
-            writeBlockOpen();
-            write(type);
-            writeBlockClose();
-        }
+    	{
+	    	writeSpace();
+	        writeBlockOpen();
+	        write(type);
+	        writeBlockClose();
+    	}
         if (param != "")
-        {
-            writeSpace();
-            write(param);
-        }
+    	{
+	    	writeSpace();
+	        write(param);
+    	}
         writeNewline();
     }
-
+    
     private boolean containsThisReference(IASNode node)
     {
         final int len = node.getChildCount();
@@ -416,32 +408,21 @@ public class JSGoogDocEmitter extends JS
 
     private String convertASTypeToJS(String name)
     {
-        String result = name;
-
-        if (name.equals(""))
-            result = IASLanguageConstants.ANY_TYPE;
-        else if (name.equals(IASLanguageConstants.Boolean)
-                || name.equals(IASLanguageConstants.String)
-                || name.equals(IASLanguageConstants.Number))
-            result = result.toLowerCase();
-        else if (name.equals(IASLanguageConstants._int)
-                || name.equals(IASLanguageConstants.uint))
-            result = IASLanguageConstants.Number.toLowerCase();
-
-        result = result.replace(IASLanguageConstants.String,
-                IASLanguageConstants.String.toLowerCase());
-
+    	String result = name;
+    	
+    	if (name.equals(""))
+    		result = IASLanguageConstants.ANY_TYPE;
+    	else if (name.equals(IASLanguageConstants.Boolean) || 
+    			 name.equals(IASLanguageConstants.String) || 
+    			 name.equals(IASLanguageConstants.Number))
+    		result = result.toLowerCase();
+    	else if (name.equals(IASLanguageConstants._int) || 
+    			 name.equals(IASLanguageConstants.uint))
+    		result = IASLanguageConstants.Number.toLowerCase();
+       
+    	result = result.replace(IASLanguageConstants.String, IASLanguageConstants.String.toLowerCase());
+    	
         return result;
     }
 
-    private IClassDefinition resolveClassDefinition(IFunctionNode node)
-    {
-        IScopedNode scope = node.getContainingScope();
-        if (scope instanceof IMXMLDocumentNode)
-            return ((IMXMLDocumentNode) scope).getClassDefinition();
-
-        IClassNode cnode = (IClassNode) node
-                .getAncestorOfType(IClassNode.class);
-        return cnode.getDefinition();
-    }
 }

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java?rev=1436642&r1=1436641&r2=1436642&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
Mon Jan 21 21:52:16 2013
@@ -74,10 +74,10 @@ import org.apache.flex.compiler.tree.as.
  */
 public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
 {
-    private static final String CONSTRUCTOR_EMPTY = "emptyConstructor";
-    private static final String CONSTRUCTOR_FULL = "fullConstructor";
-    private static final String SUPER_FUNCTION_CALL = "replaceSuperFunction";
-
+	private static final String CONSTRUCTOR_EMPTY = "emptyConstructor";
+	private static final String CONSTRUCTOR_FULL = "fullConstructor";
+	private static final String SUPER_FUNCTION_CALL = "replaceSuperFunction";
+	
     public static final String GOOG_BASE = "goog.base";
     public static final String GOOG_INHERITS = "goog.inherits";
     public static final String GOOG_PROVIDE = "goog.provide";
@@ -88,9 +88,8 @@ public class JSGoogEmitter extends JSEmi
     //                    a property with a type declaration to go with them. We
     //                    only want one declaration per property, so we need to
     //                    know if we visited the complementary instance already...
-    //                    Q for (mschmalle): do we need to reset this at some point? 
     private List<String> propertyNames = new ArrayList<String>();
-
+    
     IJSGoogDocEmitter getDoc()
     {
         return (IJSGoogDocEmitter) getDocEmitter();
@@ -145,7 +144,7 @@ public class JSGoogEmitter extends JSEmi
         {
             if (imp.indexOf(AS3) != -1)
                 continue;
-
+            
             /* goog.require('x');\n */
             write(GOOG_REQUIRE);
             write(PARENTHESES_OPEN);
@@ -156,11 +155,11 @@ public class JSGoogEmitter extends JSEmi
             write(SEMICOLON);
             writeNewline();
         }
-
+        
         // (erikdebruin) only write 'closing' line break when there are 
         //               actually imports...
-        if (list.size() > 1
-                || (list.size() == 1 && list.get(0).indexOf(AS3) == -1))
+        if (list.size() > 1 
+        		|| (list.size() == 1 && list.get(0).indexOf(AS3) == -1))
         {
             writeNewline();
         }
@@ -223,23 +222,23 @@ public class JSGoogEmitter extends JSEmi
                     write(SEMICOLON);
                 }
             }
-            else if (dnode.getNodeID() == ASTNodeID.GetterID
-                    || dnode.getNodeID() == ASTNodeID.SetterID)
+            else if (dnode.getNodeID() == ASTNodeID.GetterID 
+            		|| dnode.getNodeID() == ASTNodeID.SetterID)
             {
                 writeNewline();
                 writeNewline();
-                emitAccessors((IAccessorNode) dnode);
+            	emitAccessors((IAccessorNode) dnode);
                 write(SEMICOLON);
             }
         }
     }
-
+    
     @Override
     public void emitInterface(IInterfaceNode node)
     {
-        getDoc().emitInterfaceDoc(node);
+    	getDoc().emitInterfaceDoc(node);
 
-        write(node.getNamespace());
+    	write(node.getNamespace());
         write(SPACE);
 
         writeToken(IASKeywordConstants.INTERFACE);
@@ -252,40 +251,40 @@ public class JSGoogEmitter extends JSEmi
         write(CURLYBRACE_CLOSE);
 
         final IDefinitionNode[] members = node.getAllMemberDefinitionNodes();
-        for (IDefinitionNode mnode : members)
-        {
-            boolean isAccessor = mnode.getNodeID() == ASTNodeID.GetterID
-                    || mnode.getNodeID() == ASTNodeID.SetterID;
-
-            String qname = node.getQualifiedName();
-
-            if (!isAccessor || !propertyNames.contains(qname))
-            {
-                writeNewline();
-
-                emitMemberName(node);
-                write(PERIOD);
-                write(PROTOTYPE);
-                write(PERIOD);
-                write(mnode.getQualifiedName());
-
-                if (isAccessor && !propertyNames.contains(qname))
-                {
-                    propertyNames.add(qname);
-                }
-                else
-                {
-                    write(SPACE);
-                    write(EQUALS);
-                    write(SPACE);
-                    write(FUNCTION);
-
-                    emitParamters(((IFunctionNode) mnode).getParameterNodes());
-                }
-
-                write(SEMICOLON);
-            }
-        }
+    	for (IDefinitionNode mnode : members)
+    	{
+    		boolean isAccessor = mnode.getNodeID() == ASTNodeID.GetterID 
+    				|| mnode.getNodeID() == ASTNodeID.SetterID;
+        	
+			String qname = node.getQualifiedName();
+
+			if (!isAccessor || !propertyNames.contains(qname))
+	    	{
+	    		writeNewline();
+	
+	    		emitMemberName(node);
+				write(PERIOD);
+				write(PROTOTYPE);
+				write(PERIOD);
+				write(mnode.getQualifiedName());
+				
+				if (isAccessor && !propertyNames.contains(qname))
+				{
+					propertyNames.add(qname);
+		    	}
+		    	else
+				{
+		    		write(SPACE);
+		    		write(EQUALS);
+		    		write(SPACE);
+		    		write(FUNCTION);
+	
+		    		emitParamters(((IFunctionNode) mnode).getParameterNodes());
+				}
+    		
+				write(SEMICOLON);
+	    	}
+    	}
     }
 
     @Override
@@ -296,19 +295,19 @@ public class JSGoogEmitter extends JSEmi
         getDoc().emitFieldDoc(node);
 
         /* x.prototype.y = z */
-
+        
         String root = "";
         if (!node.isConst())
         {
-            root = PROTOTYPE;
-            root += PERIOD;
+        	root = PROTOTYPE;
+        	root += PERIOD;
         }
         write(definition.getQualifiedName() + PERIOD + root + node.getName());
-
+        
         IExpressionNode vnode = node.getAssignedValueNode();
         if (vnode != null)
         {
-            write(SPACE);
+        	write(SPACE);
             write(EQUALS);
             write(SPACE);
             getWalker().walk(vnode);
@@ -340,18 +339,20 @@ public class JSGoogEmitter extends JSEmi
         }
 
         IExpressionNode avnode = node.getAssignedValueNode();
-
         if (avnode != null)
         {
+            // (erikdebruin) 'goog' needs the fully qualified type
+            ITypeDefinition typedef = avnode.resolveType(getWalker().getProject());
+            
             String opcode = avnode.getNodeID().getParaphrase();
-            if (opcode != "AnonymousFunction")
-                getDoc().emitVarDoc(node);
+	        if (opcode != "AnonymousFunction")
+	        	getDoc().emitVarDoc(node, typedef);
         }
         else
         {
-            getDoc().emitVarDoc(node);
+        	getDoc().emitVarDoc(node, null);
         }
-
+        
         emitDeclarationName(node);
         emitAssignedValue(avnode);
 
@@ -371,39 +372,39 @@ public class JSGoogEmitter extends JSEmi
             }
         }
     }
-
+    
     @Override
     public void emitGetAccessor(IGetterNode node)
     {
         emitObjectDefineProperty(node);
     }
-
+    
     @Override
     public void emitSetAccessor(ISetterNode node)
     {
         emitObjectDefineProperty(node);
     }
-
+    
     private void emitAccessors(IAccessorNode node)
     {
-        String qname = node.getQualifiedName();
-        if (!propertyNames.contains(qname))
-        {
-            emitField(node);
+    	String qname = node.getQualifiedName();
+    	if (!propertyNames.contains(qname))
+    	{
+    		emitField(node);
             write(SEMICOLON);
             writeNewline();
             writeNewline();
-
-            propertyNames.add(qname);
-        }
-
-        if (node.getNodeID() == ASTNodeID.GetterID)
+            
+    		propertyNames.add(qname);
+    	}
+    	
+    	if (node.getNodeID() == ASTNodeID.GetterID)
         {
-            emitGetAccessor((IGetterNode) node);
+        	emitGetAccessor((IGetterNode) node);
         }
         else if (node.getNodeID() == ASTNodeID.SetterID)
         {
-            emitSetAccessor((ISetterNode) node);
+        	emitSetAccessor((ISetterNode) node);
         }
     }
 
@@ -414,50 +415,50 @@ public class JSGoogEmitter extends JSEmi
         fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
 
         ICompilerProject project = getWalker().getProject();
-
+        
         getDoc().emitMethodDoc(node, project);
-
+        
         boolean isConstructor = node.isConstructor();
-
+        
         String qname = getTypeDefinition(node).getQualifiedName();
         if (qname != null && !qname.equals(""))
         {
             write(qname);
             if (!isConstructor)
             {
-                write(PERIOD);
-                if (!fn.hasModifier(ASModifier.STATIC))
-                {
-                    write(PROTOTYPE);
-                    write(PERIOD);
-                }
+            	write(PERIOD);
+            	if (!fn.hasModifier(ASModifier.STATIC))
+	            {
+	                write(PROTOTYPE);
+	            	write(PERIOD);
+	            }
             }
         }
 
         if (!isConstructor)
-            emitMemberName(node);
-
+    		emitMemberName(node);
+        
         write(SPACE);
         write(EQUALS);
         write(SPACE);
         write(FUNCTION);
-
+        
         emitParamters(node.getParameterNodes());
 
         boolean hasSuperClass = hasSuperClass(node);
 
         if (isConstructor && node.getScopedNode().getChildCount() == 0)
         {
-            write(SPACE);
-            write(CURLYBRACE_OPEN);
+        	write(SPACE);
+        	write(CURLYBRACE_OPEN);
             if (hasSuperClass)
-                emitSuperCall(node, CONSTRUCTOR_EMPTY);
+        		emitSuperCall(node, CONSTRUCTOR_EMPTY);
             writeNewline();
-            write(CURLYBRACE_CLOSE);
+        	write(CURLYBRACE_CLOSE);
         }
 
         if (!isConstructor || node.getScopedNode().getChildCount() > 0)
-            emitMethodScope(node.getScopedNode());
+        	emitMethodScope(node.getScopedNode());
 
         if (isConstructor && hasSuperClass)
         {
@@ -469,7 +470,7 @@ public class JSGoogEmitter extends JSEmi
             write(COMMA);
             write(SPACE);
             String sname = getSuperClassDefinition(node, project)
-                    .getQualifiedName();
+            		.getQualifiedName();
             write(sname);
             write(PARENTHESES_CLOSE);
         }
@@ -478,23 +479,46 @@ public class JSGoogEmitter extends JSEmi
     @Override
     public void emitFunctionCall(IFunctionCallNode node)
     {
-        ASTNodeID id = node.getChild(0).getNodeID();
+    	IASNode cnode = node.getChild(0);
+    	
+    	if (cnode.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+    		cnode = cnode.getChild(0);
+    	
+    	ASTNodeID id = cnode.getNodeID();
+    	if (id != ASTNodeID.SuperID)
+    	{
+            if (node.isNewExpression())
+            {
+                write(IASKeywordConstants.NEW);
+                write(SPACE);
+                
+                // (erikdebruin) 'goog' needs the fully qualified type
+                ITypeDefinition def = node.resolveType(getWalker().getProject());
+                if (def != null && def.getPackageName() != "")
+                {
+                	write(def.getPackageName());
+                	write(PERIOD);
+                }
+        	}
 
-        if (id == ASTNodeID.MemberAccessExpressionID)
-            id = node.getChild(0).getChild(0).getNodeID();
+            getWalker().walk(node.getNameNode());
 
-        if (id != ASTNodeID.SuperID)
-            super.emitFunctionCall(node);
-        else
-            emitSuperCall(node, SUPER_FUNCTION_CALL);
+            write(PARENTHESES_OPEN);
+            walkArguments(node.getArgumentNodes());
+            write(PARENTHESES_CLOSE);
+    	}
+    	else
+    	{
+    		emitSuperCall(node, SUPER_FUNCTION_CALL);
+    	}
     }
 
     @Override
     public void emitFunctionBlockHeader(IFunctionNode node)
     {
-        if (node.isConstructor() && hasSuperClass(node))
-            emitSuperCall(node, CONSTRUCTOR_FULL);
-
+    	if (node.isConstructor() && hasSuperClass(node))
+    		emitSuperCall(node, CONSTRUCTOR_FULL);
+        
         emitRestParameterCodeBlock(node);
 
         emitDefaultParameterCodeBlock(node);
@@ -502,63 +526,70 @@ public class JSGoogEmitter extends JSEmi
 
     private void emitSuperCall(IASNode node, String type)
     {
-        IFunctionNode fnode = (node instanceof IFunctionNode) ? (IFunctionNode) node
-                : null;
-        IFunctionCallNode fcnode = (node instanceof IFunctionCallNode) ? (FunctionCallNode)
node
-                : null;
-
-        if (type == CONSTRUCTOR_EMPTY)
-        {
-            indentPush();
-            writeNewline();
-            indentPop();
-        }
-        else if (type == SUPER_FUNCTION_CALL)
-        {
-            if (fnode == null)
-                fnode = (IFunctionNode) fcnode
-                        .getAncestorOfType(IFunctionNode.class);
-        }
-
-        write(GOOG_BASE);
-        write(PARENTHESES_OPEN);
-        write(IASKeywordConstants.THIS);
-
-        if (fnode != null && !fnode.isConstructor())
-        {
-            write(COMMA);
-            write(SPACE);
-            write(SINGLE_QUOTE);
-            write(fnode.getName());
-            write(SINGLE_QUOTE);
-        }
-
-        if (fcnode != null)
-        {
-            IExpressionNode[] enodes = fcnode.getArgumentNodes();
-            int len = enodes.length;
-            for (int i = 0; i < len; i++)
-            {
-                write(COMMA);
-                write(SPACE);
-
-                getWalker().walk(enodes[i]);
-            }
-        }
-
-        write(PARENTHESES_CLOSE);
-
-        if (type == CONSTRUCTOR_FULL)
-        {
-            write(SEMICOLON);
-            writeNewline();
-        }
-        else if (type == CONSTRUCTOR_EMPTY)
-        {
-            write(SEMICOLON);
-        }
+    	IFunctionNode fnode = 
+    			(node instanceof IFunctionNode) ? (IFunctionNode) node : null;
+    	IFunctionCallNode fcnode = 
+    			(node instanceof IFunctionCallNode) ? (FunctionCallNode) node : null;
+
+    	if (type == CONSTRUCTOR_EMPTY)
+    	{
+        	indentPush();
+    		writeNewline();
+    		indentPop();
+    	}
+    	else if (type == CONSTRUCTOR_FULL)
+    	{
+    		// TODO (erikdebruin) don't emit 'default' super call when there is
+    		//                    a user implemented super call in the function
+    		//                    body
+    	}
+    	else if (type == SUPER_FUNCTION_CALL)
+    	{
+    		if (fnode == null)
+    			fnode = (IFunctionNode) fcnode.getAncestorOfType(IFunctionNode.class);
+    	}
+
+    	write(GOOG_BASE);
+    	write(PARENTHESES_OPEN);
+    	write(IASKeywordConstants.THIS);
+
+    	if (fnode != null && !fnode.isConstructor())
+    	{
+    		write(COMMA);
+    		write(SPACE);
+    		write(SINGLE_QUOTE);
+    		write(fnode.getName());
+    		write(SINGLE_QUOTE);
+    	}
+
+    	// TODO (erikdebruin) handle 'goog.base' call in constructor when it has
+    	//                    no super call, but does have arguments
+    	if (fcnode != null)
+    	{
+    		IExpressionNode[] enodes = fcnode.getArgumentNodes();
+    		int len = enodes.length;
+    		for (int i = 0; i < len; i++)
+    		{
+    			write(COMMA);
+    			write(SPACE);
+
+    			getWalker().walk(enodes[i]);
+    		}
+    	}
+
+    	write(PARENTHESES_CLOSE);
+
+    	if (type == CONSTRUCTOR_FULL)
+    	{
+        	write(SEMICOLON);
+        	writeNewline();
+    	}
+    	else if (type == CONSTRUCTOR_EMPTY)
+    	{
+        	write(SEMICOLON);
+    	}
     }
-
+    
     private void emitDefaultParameterCodeBlock(IFunctionNode node)
     {
         IParameterNode[] pnodes = node.getParameterNodes();
@@ -582,12 +613,12 @@ public class JSGoogEmitter extends JSEmi
 
             for (int i = 0, n = parameters.size(); i < n; i++)
             {
-                IParameterNode pnode = parameters.get(i);
-
+            	IParameterNode pnode = parameters.get(i);
+            	
                 if (pnode != null)
                 {
                     code.setLength(0);
-
+                    
                     /* x = typeof y !== 'undefined' ? y : z;\n */
                     code.append(pnode.getName());
                     code.append(SPACE);
@@ -595,7 +626,7 @@ public class JSGoogEmitter extends JSEmi
                     code.append(SPACE);
                     code.append(IASKeywordConstants.TYPEOF);
                     code.append(SPACE);
-                    code.append(pnode.getName());
+                    code.append(pnode.getName()); 
                     code.append(SPACE);
                     code.append(ASTNodeID.Op_StrictNotEqualID.getParaphrase());
                     code.append(SPACE);
@@ -605,18 +636,18 @@ public class JSGoogEmitter extends JSEmi
                     code.append(SPACE);
                     code.append(ASTNodeID.TernaryExpressionID.getParaphrase());
                     code.append(SPACE);
-                    code.append(pnode.getName());
-                    code.append(SPACE);
-                    code.append(COLON);
-                    code.append(SPACE);
+                    code.append(pnode.getName()); 
+                    code.append(SPACE); 
+                    code.append(COLON); 
+                    code.append(SPACE); 
                     code.append(pnode.getDefaultValue());
-                    code.append(SEMICOLON);
+                    code.append(SEMICOLON); 
 
                     write(code.toString());
-
+                    
                     if (i == n - 1 && !hasBody(node))
                         indentPop();
-
+                    
                     writeNewline();
                 }
             }
@@ -639,21 +670,21 @@ public class JSGoogEmitter extends JSEmi
             code.append(SPACE);
             code.append(IASLanguageConstants.Array);
             code.append(PERIOD);
-            code.append(PROTOTYPE);
-            code.append(PERIOD);
-            code.append(SLICE);
-            code.append(PERIOD);
-            code.append(CALL);
-            code.append(PARENTHESES_OPEN);
-            code.append(IASLanguageConstants.arguments);
-            code.append(COMMA);
-            code.append(SPACE);
-            code.append(String.valueOf(pnodes.length - 1));
-            code.append(PARENTHESES_CLOSE);
-            code.append(SEMICOLON);
+        	code.append(PROTOTYPE);
+        	code.append(PERIOD);
+        	code.append(SLICE);
+        	code.append(PERIOD);
+        	code.append(CALL);
+        	code.append(PARENTHESES_OPEN);
+        	code.append(IASLanguageConstants.arguments);
+        	code.append(COMMA);
+        	code.append(SPACE);
+        	code.append(String.valueOf(pnodes.length - 1));
+        	code.append(PARENTHESES_CLOSE);
+        	code.append(SEMICOLON);
 
             write(code.toString());
-
+            
             writeNewline();
         }
     }
@@ -665,6 +696,25 @@ public class JSGoogEmitter extends JSEmi
     }
 
     @Override
+    protected void emitAssignedValue(IExpressionNode node)
+    {
+        if (node != null)
+        {
+        	write(SPACE);
+            write(EQUALS);
+            write(SPACE);
+            if (node.getNodeID() == ASTNodeID.ClassReferenceID)
+            {
+                IDefinition definition = node.resolve(getWalker().getProject());
+            	write(definition.getQualifiedName());
+            }
+            else
+            {
+            	getWalker().walk(node);
+            }
+        }
+    }
+    @Override
     public void emitTypedExpression(ITypedExpressionNode node)
     {
         getWalker().walk(node.getCollectionNode());
@@ -686,7 +736,7 @@ public class JSGoogEmitter extends JSEmi
 
         write(PARENTHESES_CLOSE);
         if (!isImplicit(xnode))
-            write(SPACE);
+        	write(SPACE);
 
         getWalker().walk(node.getStatementContentsNode());
     }
@@ -741,31 +791,27 @@ public class JSGoogEmitter extends JSEmi
     private static IClassDefinition getClassDefinition(IDefinitionNode node)
     {
         IClassNode tnode = (IClassNode) node
-                .getAncestorOfType(IClassNode.class);
+        		.getAncestorOfType(IClassNode.class);
         return tnode.getDefinition();
     }
 
     private static IClassDefinition getSuperClassDefinition(
-            IDefinitionNode node, ICompilerProject project)
+    		IDefinitionNode node, ICompilerProject project)
     {
         IClassDefinition parent = (IClassDefinition) node.getDefinition()
-                .getParent();
+        		.getParent();
         IClassDefinition superClass = parent.resolveBaseClass(project);
         return superClass;
     }
 
     private boolean hasSuperClass(IDefinitionNode node)
     {
-        ICompilerProject project = getWalker().getProject();
-        IClassDefinition superClassDefinition = getSuperClassDefinition(node,
-                project);
-        // XXX (mschmalle) this is nulling for MXML super class, figure out why
-        if (superClassDefinition == null)
-            return false;
-        
-        String qname = superClassDefinition.getQualifiedName();
-        return superClassDefinition != null
-                && !qname.equals(IASLanguageConstants.Object);
+    	ICompilerProject project = getWalker().getProject();
+    	IClassDefinition superClassDefinition = getSuperClassDefinition(node, 
+    			project);
+    	String qname = superClassDefinition.getQualifiedName();
+    	return superClassDefinition != null 
+    			&& !qname.equals(IASLanguageConstants.Object);
     }
 
     private static boolean hasBody(IFunctionNode node)
@@ -784,10 +830,10 @@ public class JSGoogEmitter extends JSEmi
             configurable: true}
          );
         */
-
+    
         FunctionNode fn = (FunctionNode) node;
         fn.parseFunctionBody(problems);
-
+        
         // head
         write(IASLanguageConstants.Object);
         write(PERIOD);
@@ -802,8 +848,8 @@ public class JSGoogEmitter extends JSEmi
         write(type.getQualifiedName());
         if (!node.hasModifier(ASModifier.STATIC))
         {
-            write(PERIOD);
-            write(PROTOTYPE);
+	        write(PERIOD);
+	        write(PROTOTYPE);
         }
         write(COMMA);
         write(SPACE);
@@ -820,14 +866,14 @@ public class JSGoogEmitter extends JSEmi
         // info object
         // declaration
         write(CURLYBRACE_OPEN);
-        write(node.getNodeID() == ASTNodeID.GetterID ? IASKeywordConstants.GET
-                : IASKeywordConstants.SET);
+        write(node.getNodeID() == ASTNodeID.GetterID ? IASKeywordConstants.GET 
+        		: IASKeywordConstants.SET);
         write(COLON);
         write(FUNCTION);
         emitParamters(node.getParameterNodes());
 
         emitMethodScope(node.getScopedNode());
-
+        
         write(COMMA);
         write(SPACE);
         write(CONFIGURABLE);
@@ -856,12 +902,12 @@ public class JSGoogEmitter extends JSEmi
     @Override
     public void emitBinaryOperator(IBinaryOperatorNode node)
     {
-        ASTNodeID id = node.getNodeID();
-
-        if (id == ASTNodeID.Op_AsID || id == ASTNodeID.Op_IsID)
+    	ASTNodeID id = node.getNodeID();
+    	
+    	if (id == ASTNodeID.Op_AsID || id == ASTNodeID.Op_IsID)
         {
-            // TODO (erikdebruin) replace: this is a placeholder for the 
-            //                    eventual implementation
+        	// TODO (erikdebruin) replace: this is a placeholder for the 
+    		//                    eventual implementation
             write((id == ASTNodeID.Op_AsID) ? "as" : "is");
             write(PARENTHESES_OPEN);
             getWalker().walk(node.getLeftOperandNode());
@@ -872,33 +918,33 @@ public class JSGoogEmitter extends JSEmi
         }
         else
         {
-            getWalker().walk(node.getLeftOperandNode());
+        	getWalker().walk(node.getLeftOperandNode());
 
             if (id != ASTNodeID.Op_CommaID)
                 write(SPACE);
-
+            
             // (erikdebruin) rewrite 'a &&= b' to 'a = a && b'
-            if (id == ASTNodeID.Op_LogicalAndAssignID
-                    || id == ASTNodeID.Op_LogicalOrAssignID)
+            if (id == ASTNodeID.Op_LogicalAndAssignID 
+            		|| id == ASTNodeID.Op_LogicalOrAssignID)
             {
-                IIdentifierNode lnode = (IIdentifierNode) node
-                        .getLeftOperandNode();
-
+            	IIdentifierNode lnode = (IIdentifierNode) node
+            			.getLeftOperandNode();
+            	
                 write(EQUALS);
                 write(SPACE);
                 write(lnode.getName());
                 write(SPACE);
-                write((id == ASTNodeID.Op_LogicalAndAssignID) ? ASTNodeID.Op_LogicalAndID
-                        .getParaphrase() : ASTNodeID.Op_LogicalOrID
-                        .getParaphrase());
+                write((id == ASTNodeID.Op_LogicalAndAssignID) 
+                		? ASTNodeID.Op_LogicalAndID.getParaphrase() 
+                				: ASTNodeID.Op_LogicalOrID.getParaphrase());
             }
             else
             {
-                write(node.getOperator().getOperatorText());
+            	write(node.getOperator().getOperatorText());
             }
-
+            
             write(SPACE);
-
+            
             getWalker().walk(node.getRightOperandNode());
         }
     }

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java?rev=1436642&r1=1436641&r2=1436642&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java
Mon Jan 21 21:52:16 2013
@@ -55,7 +55,7 @@ public interface IJSGoogDocEmitter exten
 
     void emitMethodDoc(IFunctionNode node, ICompilerProject project);
 
-    void emitVarDoc(IVariableNode node);
+    void emitVarDoc(IVariableNode node, ITypeDefinition typedef);
     
     /*
      * https://developers.google.com/closure/compiler/docs/js-for-compiler#types
@@ -139,7 +139,7 @@ public interface IJSGoogDocEmitter exten
 
     void emitThis(ITypeDefinition node);
 
-    void emitType(IASNode node);
+    void emitType(IASNode node, String packageName);
 
     void emitTypedef(IASNode node);
 }



Mime
View raw message