You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2016/04/13 20:56:31 UTC
[39/51] [partial] git commit: [flex-falcon]
[refs/heads/feature/maven-migration-test] - - Check-In of the migrated
project to make error analysis easier
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IfEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IfEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IfEmitter.java
new file mode 100644
index 0000000..5370a95
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IfEmitter.java
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IConditionalNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IIfNode;
+import org.apache.flex.compiler.tree.as.ITerminalNode;
+
+public class IfEmitter extends JSSubEmitter implements
+ ISubEmitter<IIfNode>
+{
+ public IfEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IIfNode node)
+ {
+ IConditionalNode conditional = (IConditionalNode) node.getChild(0);
+ emitConditional(conditional, false);
+
+ IConditionalNode[] nodes = node.getElseIfNodes();
+ if (nodes.length > 0)
+ {
+ for (int i = 0; i < nodes.length; i++)
+ {
+ IConditionalNode enode = nodes[i];
+ IContainerNode snode = (IContainerNode) enode
+ .getStatementContentsNode();
+
+ final boolean isImplicit = EmitterUtils.isImplicit(snode);
+ if (isImplicit)
+ writeNewline();
+ else
+ write(ASEmitterTokens.SPACE);
+
+ emitConditional(enode, true);
+ }
+ }
+
+ ITerminalNode elseNode = node.getElseNode();
+ if (elseNode != null)
+ {
+ emitElse(elseNode);
+ }
+
+ }
+
+ protected void emitConditional(IConditionalNode node, boolean isElseIf)
+ {
+ startMapping(node);
+ if (isElseIf)
+ {
+ writeToken(ASEmitterTokens.ELSE);
+ }
+ writeToken(ASEmitterTokens.IF);
+ write(ASEmitterTokens.PAREN_OPEN);
+ endMapping(node);
+
+ IASNode conditionalExpression = node.getChild(0);
+ getWalker().walk(conditionalExpression);
+
+ startMapping(node, conditionalExpression);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ IContainerNode xnode = (IContainerNode) node.getStatementContentsNode();
+ if (!EmitterUtils.isImplicit(xnode))
+ write(ASEmitterTokens.SPACE);
+ endMapping(node);
+
+ getWalker().walk(node.getChild(1)); // BlockNode
+ }
+
+ protected void emitElse(ITerminalNode node)
+ {
+ IContainerNode cnode = (IContainerNode) node.getChild(0);
+
+ // if an implicit if, add a newline with no space
+ final boolean isImplicit = EmitterUtils.isImplicit(cnode);
+ if (isImplicit)
+ writeNewline();
+ else
+ write(ASEmitterTokens.SPACE);
+
+ startMapping(node);
+ write(ASEmitterTokens.ELSE);
+ if (!isImplicit)
+ write(ASEmitterTokens.SPACE);
+ endMapping(node);
+
+ getWalker().walk(node); // TerminalNode
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/InterfaceEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/InterfaceEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/InterfaceEmitter.java
new file mode 100644
index 0000000..626896f
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/InterfaceEmitter.java
@@ -0,0 +1,131 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.definitions.ITypeDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSDocEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IAccessorNode;
+import org.apache.flex.compiler.tree.as.IDefinitionNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
+
+public class InterfaceEmitter extends JSSubEmitter implements
+ ISubEmitter<IInterfaceNode>
+{
+
+ public InterfaceEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IInterfaceNode node)
+ {
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ ICompilerProject project = getWalker().getProject();
+
+ fjs.getDocEmitter().emitInterfaceDoc(node, project);
+
+ String qname = node.getQualifiedName();
+ if (qname != null && !qname.equals(""))
+ {
+ write(getEmitter().formatQualifiedName(qname));
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.FUNCTION);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+
+ final IDefinitionNode[] members = node.getAllMemberDefinitionNodes();
+ for (IDefinitionNode mnode : members)
+ {
+ boolean isAccessor = mnode.getNodeID() == ASTNodeID.GetterID
+ || mnode.getNodeID() == ASTNodeID.SetterID;
+
+ if (!isAccessor
+ || !getModel().getInterfacePropertyMap().contains(qname))
+ {
+ writeNewline();
+
+ if (isAccessor)
+ {
+ IAccessorNode accessor = (IAccessorNode)mnode;
+ String propType = accessor.getVariableType();
+ IExpressionNode typeNode = accessor.getVariableTypeNode();
+ ITypeDefinition typeDef = typeNode.resolveType(project);
+ String packageName = typeDef.getPackageName();
+ packageName = project.getActualPackageName(packageName);
+ write(JSDocEmitterTokens.JSDOC_OPEN);
+ write(ASEmitterTokens.SPACE);
+ fjs.getDocEmitter().emitType(propType, packageName);
+ write(ASEmitterTokens.SPACE);
+ write(JSDocEmitterTokens.JSDOC_CLOSE);
+ }
+ write(getEmitter().formatQualifiedName(qname));
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.PROTOTYPE);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(mnode.getQualifiedName());
+
+ if (isAccessor
+ && !getModel().getInterfacePropertyMap()
+ .contains(qname))
+ {
+ getModel().getInterfacePropertyMap().add(qname);
+ }
+ else
+ {
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.FUNCTION);
+
+ fjs.emitParameters(((IFunctionNode) mnode)
+ .getParametersContainerNode());
+
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ }
+ fjs.getPackageFooterEmitter().emitClassInfo(node);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IterationFlowEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IterationFlowEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IterationFlowEmitter.java
new file mode 100644
index 0000000..25c2d10
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IterationFlowEmitter.java
@@ -0,0 +1,54 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.tree.as.IIdentifierNode;
+import org.apache.flex.compiler.tree.as.IIterationFlowNode;
+
+public class IterationFlowEmitter extends JSSubEmitter implements
+ ISubEmitter<IIterationFlowNode>
+{
+ public IterationFlowEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IIterationFlowNode node)
+ {
+ startMapping(node);
+ write(node.getKind().toString().toLowerCase());
+ IIdentifierNode lnode = node.getLabelNode();
+ if (lnode != null)
+ {
+ write(ASEmitterTokens.SPACE);
+ endMapping(node);
+ getWalker().walk(lnode);
+ }
+ else
+ {
+ endMapping(node);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LanguageIdentifierEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LanguageIdentifierEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LanguageIdentifierEmitter.java
new file mode 100644
index 0000000..8f01b71
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LanguageIdentifierEmitter.java
@@ -0,0 +1,44 @@
+package org.apache.flex.compiler.internal.codegen.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.common.ISourceLocation;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.tree.as.ILanguageIdentifierNode;
+
+public class LanguageIdentifierEmitter extends JSSubEmitter implements
+ ISubEmitter<ILanguageIdentifierNode>
+{
+ public LanguageIdentifierEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(ILanguageIdentifierNode node)
+ {
+ startMapping((ISourceLocation) node);
+ if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.ANY_TYPE)
+ {
+ write(ASEmitterTokens.ANY_TYPE);
+ }
+ else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.REST)
+ {
+ write(ASEmitterTokens.ELLIPSIS);
+ }
+ else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.SUPER)
+ {
+ write(ASEmitterTokens.SUPER);
+ }
+ else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS)
+ {
+ write(ASEmitterTokens.THIS);
+ }
+ else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.VOID)
+ {
+ write(ASEmitterTokens.VOID);
+ }
+ endMapping((ISourceLocation) node);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralContainerEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralContainerEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralContainerEmitter.java
new file mode 100644
index 0000000..d1d24fd
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralContainerEmitter.java
@@ -0,0 +1,96 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.ILiteralContainerNode;
+
+public class LiteralContainerEmitter extends JSSubEmitter implements
+ ISubEmitter<ILiteralContainerNode>
+{
+ public LiteralContainerEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(ILiteralContainerNode node)
+ {
+ final IContainerNode cnode = node.getContentsNode();
+ final IContainerNode.ContainerType type = cnode.getContainerType();
+ String preFix = null;
+ String postFix = null;
+
+ if (type == IContainerNode.ContainerType.BRACES)
+ {
+ preFix = ASEmitterTokens.BLOCK_OPEN.getToken();
+ postFix = ASEmitterTokens.BLOCK_CLOSE.getToken();
+ }
+ else if (type == IContainerNode.ContainerType.BRACKETS)
+ {
+ preFix = ASEmitterTokens.SQUARE_OPEN.getToken();
+ postFix = ASEmitterTokens.SQUARE_CLOSE.getToken();
+ }
+ else if (type == IContainerNode.ContainerType.IMPLICIT)
+ {
+ // nothing to write, move along
+ }
+ else if (type == IContainerNode.ContainerType.PARENTHESIS)
+ {
+ preFix = ASEmitterTokens.PAREN_OPEN.getToken();
+ postFix = ASEmitterTokens.PAREN_CLOSE.getToken();
+ }
+
+ if (preFix != null)
+ {
+ startMapping(node);
+ write(preFix);
+ endMapping(node);
+ }
+
+ final int len = cnode.getChildCount();
+ for (int i = 0; i < len; i++)
+ {
+ IASNode child = cnode.getChild(i);
+ getWalker().walk(child);
+ if (i < len - 1)
+ {
+ //we're mapping the comma to the literal container, but we fill
+ //the space between the current child and the next because we
+ //don't know exactly where the comma appears in ActionScript
+ startMapping(node, child);
+ writeToken(ASEmitterTokens.COMMA);
+ endMapping(node);
+ }
+ }
+
+ if (postFix != null)
+ {
+ startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1);
+ write(postFix);
+ endMapping(node);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
new file mode 100644
index 0000000..70d2c48
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
@@ -0,0 +1,134 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.tree.as.IdentifierNode;
+import org.apache.flex.compiler.internal.tree.as.LiteralNode;
+import org.apache.flex.compiler.internal.tree.as.RegExpLiteralNode;
+import org.apache.flex.compiler.internal.tree.as.XMLLiteralNode;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.ILiteralNode;
+import org.apache.flex.compiler.tree.as.ILiteralNode.LiteralType;
+
+public class LiteralEmitter extends JSSubEmitter implements
+ ISubEmitter<ILiteralNode>
+{
+
+ public LiteralEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(ILiteralNode node)
+ {
+ boolean isWritten = false;
+
+ String s = node.getValue(true);
+ if (!(node instanceof RegExpLiteralNode))
+ {
+ if (node.getLiteralType() == LiteralType.XML)
+ {
+ write("new XML");
+ writeToken(ASEmitterTokens.PAREN_OPEN);
+ XMLLiteralNode xmlNode = (XMLLiteralNode)node;
+ if (xmlNode.getContentsNode().getChildCount() == 1)
+ {
+ if (s.contains("'"))
+ write("\"" + s + "\"");
+ else
+ write("'" + s + "'");
+ isWritten = true;
+ }
+ else
+ {
+ // probably contains {initializers}
+ int n = xmlNode.getContentsNode().getChildCount();
+ for (int i = 0; i < n; i++)
+ {
+ if (i > 0)
+ write(" + ");
+ IASNode child = xmlNode.getContentsNode().getChild(i);
+ if (child instanceof LiteralNode)
+ {
+ s = ((LiteralNode)child).getValue(true);
+ if (s.contains("'"))
+ write("\"" + s + "\"");
+ else
+ write("'" + s + "'");
+ isWritten = true;
+ }
+ else if (child instanceof IdentifierNode)
+ {
+ s = getEmitter().stringifyNode(child);
+ write(s);
+ }
+ }
+ }
+ writeToken(ASEmitterTokens.PAREN_CLOSE);
+ }
+ s = s.replaceAll("\n", "__NEWLINE_PLACEHOLDER__");
+ s = s.replaceAll("\r", "__CR_PLACEHOLDER__");
+ s = s.replaceAll("\t", "__TAB_PLACEHOLDER__");
+ s = s.replaceAll("\f", "__FORMFEED_PLACEHOLDER__");
+ s = s.replaceAll("\b", "__BACKSPACE_PLACEHOLDER__");
+ s = s.replaceAll("\\\\\"", "__QUOTE_PLACEHOLDER__");
+ s = s.replaceAll("\\\\", "__ESCAPE_PLACEHOLDER__");
+ //s = "\'" + s.replaceAll("\'", "\\\\\'") + "\'";
+ s = s.replaceAll("__ESCAPE_PLACEHOLDER__", "\\\\\\\\");
+ s = s.replaceAll("__QUOTE_PLACEHOLDER__", "\\\\\"");
+ s = s.replaceAll("__BACKSPACE_PLACEHOLDER__", "\\\\b");
+ s = s.replaceAll("__FORMFEED_PLACEHOLDER__", "\\\\f");
+ s = s.replaceAll("__TAB_PLACEHOLDER__", "\\\\t");
+ s = s.replaceAll("__CR_PLACEHOLDER__", "\\\\r");
+ s = s.replaceAll("__NEWLINE_PLACEHOLDER__", "\\\\n");
+ if (node.getLiteralType() == LiteralType.STRING)
+ {
+ char c = s.charAt(0);
+ if (c == '"')
+ {
+ s = s.substring(1, s.length() - 1);
+ s = s.replace("\"", "\\\"");
+ s = "\"" + s + "\"";
+ }
+ else if (c == '\'')
+ {
+ s = s.substring(1, s.length() - 1);
+ s = s.replace("'", "\\'");
+ s = "'" + s + "'";
+ }
+ s = s.replace("\u2028", "\\u2028");
+ s = s.replace("\u2029", "\\u2029");
+ }
+
+ }
+
+ if (!isWritten)
+ {
+ startMapping(node);
+ write(s);
+ endMapping(node);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
new file mode 100644
index 0000000..7088431
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
@@ -0,0 +1,323 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.constants.IASLanguageConstants;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
+import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.tree.as.FunctionCallNode;
+import org.apache.flex.compiler.internal.tree.as.GetterNode;
+import org.apache.flex.compiler.internal.tree.as.IdentifierNode;
+import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
+import org.apache.flex.compiler.internal.tree.as.NamespaceAccessExpressionNode;
+import org.apache.flex.compiler.projects.ICompilerProject;
+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.IIdentifierNode;
+import org.apache.flex.compiler.tree.as.ILanguageIdentifierNode;
+import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.IOperatorNode.OperatorType;
+import org.apache.flex.compiler.utils.ASNodeUtils;
+
+public class MemberAccessEmitter extends JSSubEmitter implements
+ ISubEmitter<IMemberAccessExpressionNode>
+{
+
+ public MemberAccessEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IMemberAccessExpressionNode node)
+ {
+ if (ASNodeUtils.hasParenOpen(node))
+ write(ASEmitterTokens.PAREN_OPEN);
+
+ IASNode leftNode = node.getLeftOperandNode();
+ IASNode rightNode = node.getRightOperandNode();
+
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter)getEmitter();
+ IDefinition def = node.resolve(getProject());
+ if (def == null)
+ {
+ IASNode parentNode = node.getParent();
+ // could be XML
+ boolean isXML = false;
+ boolean isProxy = false;
+ if (leftNode instanceof MemberAccessExpressionNode)
+ isXML = fjs.isXMLList((MemberAccessExpressionNode)leftNode);
+ else if (leftNode instanceof IExpressionNode)
+ isXML = fjs.isXML((IExpressionNode)leftNode);
+ if (leftNode instanceof MemberAccessExpressionNode)
+ isProxy = fjs.isProxy((MemberAccessExpressionNode)leftNode);
+ else if (leftNode instanceof IExpressionNode)
+ isProxy = fjs.isProxy((IExpressionNode)leftNode);
+ if (isXML)
+ {
+ boolean descendant = (node.getOperator() == OperatorType.DESCENDANT_ACCESS);
+ boolean child = (node.getOperator() == OperatorType.MEMBER_ACCESS) &&
+ (!(parentNode instanceof FunctionCallNode)) &&
+ rightNode.getNodeID() != ASTNodeID.Op_AtID;
+ if (descendant || child)
+ {
+ writeLeftSide(node, leftNode, rightNode);
+ if (descendant)
+ write(".descendants('");
+ if (child)
+ write(".child('");
+ String s = fjs.stringifyNode(rightNode);
+ int dot = s.indexOf('.');
+ if (dot != -1)
+ {
+ String name = s.substring(0, dot);
+ String afterDot = s.substring(dot);
+ write(name);
+ write("')");
+ write(afterDot);
+ }
+ else
+ {
+ write(s);
+ write("')");
+ }
+ return;
+ }
+ }
+ else if (isProxy)
+ {
+ boolean child = (node.getOperator() == OperatorType.MEMBER_ACCESS) &&
+ (!(parentNode instanceof FunctionCallNode)) &&
+ rightNode.getNodeID() != ASTNodeID.Op_AtID;
+ if (child)
+ {
+ writeLeftSide(node, leftNode, rightNode);
+ if (child)
+ write(".getProperty('");
+ String s = fjs.stringifyNode(rightNode);
+ int dot = s.indexOf('.');
+ if (dot != -1)
+ {
+ String name = s.substring(0, dot);
+ String afterDot = s.substring(dot);
+ write(name);
+ write("')");
+ write(afterDot);
+ }
+ else
+ {
+ write(s);
+ write("')");
+ }
+ return;
+ }
+ }
+ else if (rightNode instanceof NamespaceAccessExpressionNode)
+ {
+ // if you define a local variable with the same URI as a
+ // namespace that defines a namespaced property
+ // it doesn't resolve above so we handle it here
+ NamespaceAccessExpressionNode naen = (NamespaceAccessExpressionNode)rightNode;
+ IDefinition d = naen.getLeftOperandNode().resolve(getProject());
+ IdentifierNode r = (IdentifierNode)(naen.getRightOperandNode());
+ // output bracket access with QName
+ writeLeftSide(node, leftNode, rightNode);
+ write(ASEmitterTokens.SQUARE_OPEN);
+ write(ASEmitterTokens.NEW);
+ write(ASEmitterTokens.SPACE);
+ write(IASLanguageConstants.QName);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(d.getBaseName());
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(r.getName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SQUARE_CLOSE);
+ return;
+ }
+ }
+ else if (fjs.isDateProperty(node))
+ {
+ writeLeftSide(node, leftNode, rightNode);
+ write(".get");
+ String rightName = ((IIdentifierNode)rightNode).getName();
+ String firstChar = rightName.substring(0, 1);
+ firstChar = firstChar.toUpperCase();
+ rightName = rightName.substring(1);
+ write(firstChar);
+ write(rightName);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return;
+ }
+ else if (def.getParent() != null &&
+ def.getParent().getQualifiedName().equals("Array"))
+ {
+ if (def.getBaseName().equals("removeAt"))
+ {
+ writeLeftSide(node, leftNode, rightNode);
+ write(".splice");
+ return;
+ }
+ else if (def.getBaseName().equals("insertAt"))
+ {
+ writeLeftSide(node, leftNode, rightNode);
+ write(".splice");
+ return;
+ }
+ }
+ else if (rightNode instanceof NamespaceAccessExpressionNode)
+ {
+ NamespaceAccessExpressionNode naen = (NamespaceAccessExpressionNode)rightNode;
+ IDefinition d = naen.getLeftOperandNode().resolve(getProject());
+ IdentifierNode r = (IdentifierNode)(naen.getRightOperandNode());
+ // output bracket access with QName
+ writeLeftSide(node, leftNode, rightNode);
+ write(ASEmitterTokens.SQUARE_OPEN);
+ write(ASEmitterTokens.NEW);
+ write(ASEmitterTokens.SPACE);
+ write(IASLanguageConstants.QName);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(fjs.formatQualifiedName(d.getBaseName()));
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(r.getName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SQUARE_CLOSE);
+ return;
+ }
+ boolean isStatic = false;
+ if (def != null && def.isStatic())
+ isStatic = true;
+ boolean needClosure = false;
+ if (def instanceof FunctionDefinition && (!(def instanceof AccessorDefinition))
+ && !def.getBaseName().equals("constructor")) // don't wrap references to obj.constructor
+ {
+ IASNode parentNode = node.getParent();
+ if (parentNode != null)
+ {
+ ASTNodeID parentNodeId = parentNode.getNodeID();
+ // we need a closure if this MAE is the top-level in a chain
+ // of MAE and not in a function call.
+ needClosure = !isStatic && parentNodeId != ASTNodeID.FunctionCallID &&
+ parentNodeId != ASTNodeID.MemberAccessExpressionID &&
+ parentNodeId != ASTNodeID.ArrayIndexExpressionID;
+
+ }
+ }
+
+ boolean continueWalk = true;
+ if (!isStatic)
+ {
+ if (needClosure)
+ getEmitter().emitClosureStart();
+
+ continueWalk = writeLeftSide(node, leftNode, rightNode);
+ if (continueWalk)
+ {
+ startMapping(node, node.getLeftOperandNode());
+ write(node.getOperator().getOperatorText());
+ endMapping(node);
+ }
+ }
+
+ if (continueWalk)
+ {
+ getWalker().walk(node.getRightOperandNode());
+ }
+
+ if (needClosure)
+ {
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ writeLeftSide(node, leftNode, rightNode);
+ getEmitter().emitClosureEnd(node);
+ }
+
+ if (ASNodeUtils.hasParenClose(node))
+ write(ASEmitterTokens.PAREN_CLOSE);
+ }
+
+ private boolean writeLeftSide(IMemberAccessExpressionNode node, IASNode leftNode, IASNode rightNode)
+ {
+ if (!(leftNode instanceof ILanguageIdentifierNode && ((ILanguageIdentifierNode) leftNode)
+ .getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS))
+ {
+ IDefinition rightDef = null;
+ if (rightNode instanceof IIdentifierNode)
+ rightDef = ((IIdentifierNode) rightNode)
+ .resolve(getProject());
+
+ if (leftNode.getNodeID() != ASTNodeID.SuperID)
+ {
+ getWalker().walk(node.getLeftOperandNode());
+ }
+ else if (leftNode.getNodeID() == ASTNodeID.SuperID
+ && (rightNode.getNodeID() == ASTNodeID.GetterID || (rightDef != null && rightDef instanceof AccessorDefinition)))
+ {
+ ICompilerProject project = this.getProject();
+ if (project instanceof FlexJSProject)
+ ((FlexJSProject)project).needLanguage = true;
+ // setter is handled in binaryOperator
+ write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSFlexJSEmitterTokens.SUPERGETTER);
+ write(ASEmitterTokens.PAREN_OPEN);
+ IClassNode cnode = (IClassNode) node
+ .getAncestorOfType(IClassNode.class);
+ write(getEmitter().formatQualifiedName(
+ cnode.getQualifiedName()));
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.THIS);
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ if (rightDef != null)
+ write(rightDef.getBaseName());
+ else
+ write(((GetterNode) rightNode).getName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return false;
+ }
+ }
+ else
+ {
+ startMapping(leftNode);
+ write(ASEmitterTokens.THIS);
+ endMapping(leftNode);
+ }
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberKeywordEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberKeywordEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberKeywordEmitter.java
new file mode 100644
index 0000000..3f71c78
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberKeywordEmitter.java
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IDefinitionNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IKeywordNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+
+public class MemberKeywordEmitter extends JSSubEmitter implements
+ ISubEmitter<IDefinitionNode>
+{
+ public MemberKeywordEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IDefinitionNode node)
+ {
+ IKeywordNode keywordNode = null;
+ for(int i = 0; i < node.getChildCount(); i++)
+ {
+ IASNode childNode = node.getChild(i);
+ if (childNode instanceof IKeywordNode)
+ {
+ keywordNode = (IKeywordNode) childNode;
+ break;
+ }
+ }
+ if (keywordNode != null)
+ {
+ startMapping(keywordNode);
+ }
+ if (node instanceof IFunctionNode)
+ {
+ writeToken(ASEmitterTokens.FUNCTION);
+ }
+ else if (node instanceof IVariableNode)
+ {
+ writeToken(ASEmitterTokens.VAR);
+ }
+ if (keywordNode != null)
+ {
+ endMapping(keywordNode);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MethodEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MethodEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MethodEmitter.java
new file mode 100644
index 0000000..2657907
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MethodEmitter.java
@@ -0,0 +1,145 @@
+/*
+ *
+ * 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.js.jx;
+
+import java.util.ArrayList;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.common.ASModifier;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
+import org.apache.flex.compiler.definitions.ITypeDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSessionModel;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+
+public class MethodEmitter extends JSSubEmitter implements
+ ISubEmitter<IFunctionNode>
+{
+ public MethodEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IFunctionNode node)
+ {
+ getModel().getMethods().add(node);
+
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
+
+ ICompilerProject project = getWalker().getProject();
+
+ fjs.getDocEmitter().emitMethodDoc(node, project);
+
+ boolean isConstructor = node.isConstructor();
+
+ String qname = null;
+ IFunctionDefinition.FunctionClassification classification = fn.getFunctionClassification();
+ if(classification == IFunctionDefinition.FunctionClassification.FILE_MEMBER ||
+ classification == IFunctionDefinition.FunctionClassification.PACKAGE_MEMBER)
+ {
+ write(fjs.formatQualifiedName(fn.getQualifiedName()));
+ }
+ else
+ {
+ startMapping(node.getNameExpressionNode());
+ ITypeDefinition typeDef = EmitterUtils.getTypeDefinition(node);
+ if (typeDef != null)
+ {
+ qname = typeDef.getQualifiedName();
+ }
+ if (qname != null && !qname.equals(""))
+ {
+ write(fjs.formatQualifiedName(qname));
+ if (!isConstructor)
+ {
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ if (!fn.hasModifier(ASModifier.STATIC))
+ {
+ write(JSEmitterTokens.PROTOTYPE);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ }
+ }
+ }
+ if (!isConstructor)
+ {
+ fjs.emitMemberName(node);
+ }
+ endMapping(node.getNameExpressionNode());
+ }
+
+ startMapping(node);
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.FUNCTION);
+ endMapping(node);
+
+ fjs.emitParameters(node.getParametersContainerNode());
+
+ boolean hasSuperClass = EmitterUtils.hasSuperClass(project, node);
+
+ if (isConstructor && node.getScopedNode().getChildCount() == 0)
+ {
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ if (hasSuperClass)
+ fjs.emitSuperCall(node, JSSessionModel.CONSTRUCTOR_EMPTY);
+ writeNewline();
+ IClassNode cnode = (IClassNode) node
+ .getAncestorOfType(IClassNode.class);
+ fjs.emitComplexInitializers(cnode);
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+
+ if (!isConstructor || node.getScopedNode().getChildCount() > 0)
+ {
+ getEmitter().pushSourceMapName(node);
+ fjs.emitMethodScope(node.getScopedNode());
+ getEmitter().popSourceMapName();
+ }
+
+ if (isConstructor && hasSuperClass)
+ {
+ writeNewline(ASEmitterTokens.SEMICOLON);
+ write(JSGoogEmitterTokens.GOOG_INHERITS);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(fjs.formatQualifiedName(qname));
+ writeToken(ASEmitterTokens.COMMA);
+ String sname = EmitterUtils.getSuperClassDefinition(node, project)
+ .getQualifiedName();
+ write(fjs.formatQualifiedName(sname));
+ write(ASEmitterTokens.PAREN_CLOSE);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/NumericLiteralEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/NumericLiteralEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/NumericLiteralEmitter.java
new file mode 100644
index 0000000..604d1d6
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/NumericLiteralEmitter.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.common.ISourceLocation;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.tree.as.INumericLiteralNode;
+
+public class NumericLiteralEmitter extends JSSubEmitter implements
+ ISubEmitter<INumericLiteralNode>
+{
+ public NumericLiteralEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(INumericLiteralNode node)
+ {
+ startMapping((ISourceLocation) node);
+ write(node.getNumericValue().toString());
+ endMapping((ISourceLocation) node);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ObjectDefinePropertyEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ObjectDefinePropertyEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ObjectDefinePropertyEmitter.java
new file mode 100644
index 0000000..d867332
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ObjectDefinePropertyEmitter.java
@@ -0,0 +1,166 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.common.ASModifier;
+import org.apache.flex.compiler.common.IMetaInfo;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
+import org.apache.flex.compiler.definitions.ITypeDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.internal.tree.as.SetterNode;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IAccessorNode;
+
+public class ObjectDefinePropertyEmitter extends JSSubEmitter implements
+ ISubEmitter<IAccessorNode>
+{
+
+ public ObjectDefinePropertyEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IAccessorNode node)
+ {
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ //TODO: ajh is this method needed anymore?
+
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(fjs.getProblems());
+
+ IFunctionDefinition definition = node.getDefinition();
+ ITypeDefinition type = (ITypeDefinition) definition.getParent();
+
+ // ToDo (erikdebruin): add VF2JS conditional -> only use check during full SDK compilation
+ if (type == null)
+ return;
+
+ boolean isBindableSetter = false;
+ if (node instanceof SetterNode)
+ {
+ IMetaInfo[] metaInfos = null;
+ metaInfos = node.getMetaInfos();
+ for (IMetaInfo metaInfo : metaInfos)
+ {
+ String name = metaInfo.getTagName();
+ if (name.equals("Bindable")
+ && metaInfo.getAllAttributes().length == 0)
+ {
+ isBindableSetter = true;
+ break;
+ }
+ }
+ }
+ if (isBindableSetter)
+ {
+ fjs.getDocEmitter().emitMethodDoc(fn, getWalker().getProject());
+ write(fjs.formatQualifiedName(type.getQualifiedName()));
+ if (!node.hasModifier(ASModifier.STATIC))
+ {
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.PROTOTYPE);
+ }
+
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("__bindingWrappedSetter__");
+ writeToken(node.getName());
+ writeToken(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.FUNCTION);
+ fjs.emitParameters(node.getParametersContainerNode());
+ //writeNewline();
+ fjs.emitMethodScope(node.getScopedNode());
+ }
+
+ super_emitObjectDefineProperty(node);
+ }
+
+ protected void super_emitObjectDefineProperty(IAccessorNode node)
+ {
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ /*
+ Object.defineProperty(
+ A.prototype,
+ 'foo',
+ {get: function() {return -1;},
+ configurable: true}
+ );
+ */
+
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(fjs.getProblems());
+
+ // head
+ write(JSGoogEmitterTokens.OBJECT);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.DEFINE_PROPERTY);
+ fjs.writeNewline(ASEmitterTokens.PAREN_OPEN, true);
+
+ // Type
+ IFunctionDefinition definition = node.getDefinition();
+ ITypeDefinition type = (ITypeDefinition) definition.getParent();
+ write(type.getQualifiedName());
+ if (!node.hasModifier(ASModifier.STATIC))
+ {
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.PROTOTYPE);
+ }
+ writeToken(ASEmitterTokens.COMMA);
+ writeNewline();
+
+ // name
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(definition.getBaseName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COMMA);
+ writeNewline();
+
+ // info object
+ // declaration
+ write(ASEmitterTokens.BLOCK_OPEN);
+ write(node.getNodeID() == ASTNodeID.GetterID ? ASEmitterTokens.GET
+ : ASEmitterTokens.SET);
+ write(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.FUNCTION);
+ fjs.emitParameters(node.getParametersContainerNode());
+
+ fjs.emitDefinePropertyFunction(node);
+
+ writeToken(ASEmitterTokens.COMMA);
+ write(JSEmitterTokens.CONFIGURABLE);
+ write(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.TRUE);
+ fjs.writeNewline(ASEmitterTokens.BLOCK_CLOSE, false);
+
+ // tail, no colon; parent container will add it
+ write(ASEmitterTokens.PAREN_CLOSE);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ObjectLiteralValuePairEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ObjectLiteralValuePairEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ObjectLiteralValuePairEmitter.java
new file mode 100644
index 0000000..d93d701
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ObjectLiteralValuePairEmitter.java
@@ -0,0 +1,53 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.common.ISourceLocation;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IObjectLiteralValuePairNode;
+
+public class ObjectLiteralValuePairEmitter extends JSSubEmitter implements
+ ISubEmitter<IObjectLiteralValuePairNode>
+{
+ public ObjectLiteralValuePairEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IObjectLiteralValuePairNode node)
+ {
+ ISourceLocation sourceLocationNode = (ISourceLocation) node;
+
+ IExpressionNode nameNode = node.getNameNode();
+ getWalker().walk(nameNode);
+
+ startMapping(sourceLocationNode, nameNode);
+ write(ASEmitterTokens.COLON);
+ endMapping(sourceLocationNode);
+
+ IExpressionNode valueNode = node.getValueNode();
+ getWalker().walk(valueNode);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/PackageFooterEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/PackageFooterEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/PackageFooterEmitter.java
new file mode 100644
index 0000000..e5aaf34
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/PackageFooterEmitter.java
@@ -0,0 +1,640 @@
+/*
+ *
+ * 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.js.jx;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.common.ASModifier;
+import org.apache.flex.compiler.common.ModifiersSet;
+import org.apache.flex.compiler.constants.IASKeywordConstants;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.IPackageDefinition;
+import org.apache.flex.compiler.definitions.ITypeDefinition;
+import org.apache.flex.compiler.definitions.metadata.IMetaTagAttribute;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSDocEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.tree.as.SetterNode;
+import org.apache.flex.compiler.scopes.IASScope;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IDefinitionNode;
+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.ITypeNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.apache.flex.compiler.tree.metadata.IMetaTagNode;
+import org.apache.flex.compiler.tree.metadata.IMetaTagsNode;
+
+public class PackageFooterEmitter extends JSSubEmitter implements
+ ISubEmitter<IPackageDefinition>
+{
+
+ public PackageFooterEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IPackageDefinition definition)
+ {
+ getEmitter().popSourceMapName();
+ IASScope containedScope = definition.getContainedScope();
+ ITypeDefinition type = EmitterUtils.findType(containedScope
+ .getAllLocalDefinitions());
+ if (type == null)
+ return;
+
+ getEmitter().emitSourceMapDirective(type.getNode());
+ }
+
+ public void emitClassInfo(ITypeNode tnode)
+ {
+ JSFlexJSDocEmitter doc = (JSFlexJSDocEmitter) getEmitter()
+ .getDocEmitter();
+
+ /*
+ * 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(JSFlexJSEmitterTokens.FLEXJS_CLASS_INFO);
+ writeToken(ASEmitterTokens.EQUAL);
+ writeToken(ASEmitterTokens.BLOCK_OPEN);
+
+ // names: [{ name: '', qName: '' }]
+ write(JSFlexJSEmitterTokens.NAMES);
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SQUARE_OPEN);
+ writeToken(ASEmitterTokens.BLOCK_OPEN);
+ write(JSFlexJSEmitterTokens.NAME);
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(tnode.getName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COMMA);
+ write(JSFlexJSEmitterTokens.QNAME);
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(getEmitter().formatQualifiedName(tnode.getQualifiedName()));
+ write(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();
+
+ if (enodes.length > 0)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+
+ // interfaces: [a.IC, a.ID]
+ write(JSFlexJSEmitterTokens.INTERFACES);
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SQUARE_OPEN);
+ 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);
+
+ if (!(tnode instanceof IInterfaceNode))
+ {
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ doc.begin();
+ writeNewline(" * Prevent renaming of class. Needed for reflection.");
+ doc.end();
+ write(JSFlexJSEmitterTokens.GOOG_EXPORT_SYMBOL);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(getEmitter().formatQualifiedName(tnode.getQualifiedName()));
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ write(getEmitter().formatQualifiedName(tnode.getQualifiedName()));
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+
+ collectReflectionData(tnode);
+ IMetaTagNode[] metadata = null;
+ IMetaTagsNode metadataTags = tnode.getMetaTags();
+ if (metadataTags != null)
+ metadata = metadataTags.getAllTags();
+ emitReflectionData(getEmitter().formatQualifiedName(tnode.getQualifiedName()),
+ varData,
+ accessorData,
+ methodData,
+ metadata);
+ }
+
+ public class VariableData
+ {
+ public String name;
+ public String type;
+ public IMetaTagNode[] metaData;
+ }
+
+ private ArrayList<VariableData> varData;
+
+ public class MethodData
+ {
+ public String name;
+ public String type;
+ public String declaredBy;
+ public IMetaTagNode[] metaData;
+ }
+
+ private ArrayList<MethodData> accessorData;
+ private ArrayList<MethodData> methodData;
+
+ public void collectReflectionData(ITypeNode tnode)
+ {
+ varData = new ArrayList<VariableData>();
+ accessorData = new ArrayList<MethodData>();
+ methodData = new ArrayList<MethodData>();
+ /*
+ * Reflection
+ *
+ * @return {Object.<string, Function>}
+ */
+ IDefinitionNode[] dnodes;
+ boolean isInterface = tnode instanceof IInterfaceNode;
+ if (!isInterface)
+ dnodes = ((IClassNode) tnode).getAllMemberNodes();
+ else
+ dnodes = ((IInterfaceNode) tnode).getAllMemberDefinitionNodes();
+
+ for (IDefinitionNode dnode : dnodes)
+ {
+ ModifiersSet modifierSet = dnode.getDefinition().getModifiers();
+ boolean isStatic = (modifierSet != null && modifierSet
+ .hasModifier(ASModifier.STATIC));
+ if (!isStatic && (dnode.getNodeID() == ASTNodeID.VariableID ||
+ dnode.getNodeID() == ASTNodeID.BindableVariableID))
+ {
+ IVariableNode varNode = (IVariableNode)dnode;
+ String ns = varNode.getNamespace();
+ if (ns == IASKeywordConstants.PUBLIC || isInterface)
+ {
+ VariableData data = new VariableData();
+ varData.add(data);
+ data.name = varNode.getName();
+ data.type = getEmitter().formatQualifiedName(varNode.getVariableType());
+ IMetaTagsNode metaData = varNode.getMetaTags();
+ if (metaData != null)
+ {
+ IMetaTagNode[] tags = metaData.getAllTags();
+ if (tags.length > 0)
+ data.metaData = tags;
+ }
+ }
+ }
+ }
+
+ HashMap<String, MethodData> accessorMap = new HashMap<String, MethodData>();
+ for (IDefinitionNode dnode : dnodes)
+ {
+ ModifiersSet modifierSet = dnode.getDefinition().getModifiers();
+ boolean isStatic = (modifierSet != null && modifierSet
+ .hasModifier(ASModifier.STATIC));
+ if (!isStatic && (dnode.getNodeID() == ASTNodeID.GetterID ||
+ dnode.getNodeID() == ASTNodeID.SetterID))
+ {
+ IFunctionNode fnNode = (IFunctionNode)dnode;
+ String ns = fnNode.getNamespace();
+ if (ns == IASKeywordConstants.PUBLIC || isInterface)
+ {
+ MethodData data = new MethodData();
+ data.name = fnNode.getName();
+ if (accessorMap.containsKey(data.name)) continue;
+ accessorData.add(data);
+ if (dnode.getNodeID() == ASTNodeID.GetterID)
+ data.type = fnNode.getReturnType();
+ else
+ data.type = ((SetterNode)fnNode).getVariableType();
+ accessorMap.put(data.name, data);
+ data.type = getEmitter().formatQualifiedName(data.type);
+ IClassNode declarer = (IClassNode)fnNode.getAncestorOfType(IClassNode.class);
+ String declarant = getEmitter().formatQualifiedName(tnode.getQualifiedName());
+ if (declarer != null)
+ declarant = getEmitter().formatQualifiedName(declarer.getQualifiedName());
+ data.declaredBy = declarant;
+ IMetaTagsNode metaData = fnNode.getMetaTags();
+ if (metaData != null)
+ {
+ IMetaTagNode[] tags = metaData.getAllTags();
+ if (tags.length > 0)
+ data.metaData = tags;
+ }
+ }
+ }
+ }
+ for (IDefinitionNode dnode : dnodes)
+ {
+ ModifiersSet modifierSet = dnode.getDefinition().getModifiers();
+ boolean isStatic = (modifierSet != null && modifierSet
+ .hasModifier(ASModifier.STATIC));
+ if (dnode.getNodeID() == ASTNodeID.FunctionID && !isStatic)
+ {
+ IFunctionNode fnNode = (IFunctionNode)dnode;
+ String ns = fnNode.getNamespace();
+ if (ns == IASKeywordConstants.PUBLIC || isInterface)
+ {
+ MethodData data = new MethodData();
+ methodData.add(data);
+ data.name = fnNode.getName();
+ data.type = getEmitter().formatQualifiedName(fnNode.getReturnType());
+ ITypeNode declarer;
+ if (isInterface)
+ declarer = (IInterfaceNode)fnNode.getAncestorOfType(IInterfaceNode.class);
+ else
+ declarer = (IClassNode)fnNode.getAncestorOfType(IClassNode.class);
+ String declarant = getEmitter().formatQualifiedName(tnode.getQualifiedName());
+ if (declarer != null)
+ declarant = getEmitter().formatQualifiedName(declarer.getQualifiedName());
+ data.declaredBy = declarant;
+ IMetaTagsNode metaData = fnNode.getMetaTags();
+ if (metaData != null)
+ {
+ IMetaTagNode[] tags = metaData.getAllTags();
+ if (tags.length > 0)
+ data.metaData = tags;
+ }
+ }
+ }
+ }
+ }
+
+ public void emitReflectionData(String typeName,
+ List<VariableData> varData,
+ List<MethodData> accessorData,
+ List<MethodData> methodData,
+ IMetaTagNode[] metaData
+ )
+ {
+ JSFlexJSDocEmitter doc = (JSFlexJSDocEmitter) getEmitter()
+ .getDocEmitter();
+ /*
+ * Reflection
+ *
+ * @return {Object.<string, Function>}
+ */
+
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ doc.begin();
+ writeNewline(" * Reflection");
+ writeNewline(" *");
+ writeNewline(" * @return {Object.<string, Function>}");
+ doc.end();
+
+ // a.B.prototype.FLEXJS_REFLECTION_INFO = function() {
+ write(typeName);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.PROTOTYPE);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ writeToken(JSFlexJSEmitterTokens.FLEXJS_REFLECTION_INFO);
+ writeToken(ASEmitterTokens.EQUAL);
+ writeToken(ASEmitterTokens.FUNCTION);
+ write(ASEmitterTokens.PAREN_OPEN);
+ writeToken(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+
+ indentPush();
+ writeNewline();
+ // return {
+ writeToken(ASEmitterTokens.RETURN);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ indentPush();
+ writeNewline();
+ // variables: function() {
+ write("variables");
+ writeToken(ASEmitterTokens.COLON);
+ writeToken(ASEmitterTokens.FUNCTION);
+ write(ASEmitterTokens.PAREN_OPEN);
+ writeToken(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ indentPush();
+ writeNewline();
+ // return {
+ writeToken(ASEmitterTokens.RETURN);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ indentPush();
+
+ int count = 0;
+ for (VariableData var : varData)
+ {
+ if (count > 0)
+ write(ASEmitterTokens.COMMA);
+ writeNewline();
+ count++;
+ // varname: { type: typename
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(var.name);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COLON);
+ writeToken(ASEmitterTokens.BLOCK_OPEN);
+ write("type");
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(var.type);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ IMetaTagNode[] tags = var.metaData;
+ if (tags != null)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+ writeMetaData(tags);
+ }
+ // close object
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+ indentPop();
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ indentPop();
+ writeNewline();
+ // close variable function
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.COMMA);
+ writeNewline();
+
+
+ // accessors: function() {
+ write("accessors");
+ writeToken(ASEmitterTokens.COLON);
+ writeToken(ASEmitterTokens.FUNCTION);
+ write(ASEmitterTokens.PAREN_OPEN);
+ writeToken(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ indentPush();
+ writeNewline();
+ // return {
+ writeToken(ASEmitterTokens.RETURN);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ indentPush();
+
+ count = 0;
+ for (MethodData accessor : accessorData)
+ {
+ if (count > 0)
+ write(ASEmitterTokens.COMMA);
+ writeNewline();
+ count++;
+ // accessorname: { type: typename
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(accessor.name);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COLON);
+ writeToken(ASEmitterTokens.BLOCK_OPEN);
+ write("type");
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(accessor.type);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COMMA);
+ write("declaredBy");
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(accessor.declaredBy);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ IMetaTagNode[] tags = accessor.metaData;
+ if (tags != null)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+ writeMetaData(tags);
+ }
+ // close object
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+ indentPop();
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ indentPop();
+ writeNewline();
+ // close accessor function
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.COMMA);
+ writeNewline();
+
+
+ // methods: function() {
+ write("methods");
+ writeToken(ASEmitterTokens.COLON);
+ writeToken(ASEmitterTokens.FUNCTION);
+ write(ASEmitterTokens.PAREN_OPEN);
+ writeToken(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ indentPush();
+ writeNewline();
+ // return {
+ writeToken(ASEmitterTokens.RETURN);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ indentPush();
+
+ count = 0;
+ for (MethodData method : methodData)
+ {
+ if (count > 0)
+ write(ASEmitterTokens.COMMA);
+ writeNewline();
+ count++;
+ // methodname: { type: typename
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(method.name);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COLON);
+ writeToken(ASEmitterTokens.BLOCK_OPEN);
+ write("type");
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(method.type);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COMMA);
+ write("declaredBy");
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(method.declaredBy);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ IMetaTagNode[] tags = method.metaData;
+ if (tags != null)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+ writeMetaData(tags);
+ }
+ // close object
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+ // close return
+ indentPop();
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ indentPop();
+ writeNewline();
+ // close method function
+ write(ASEmitterTokens.BLOCK_CLOSE);
+
+ if (metaData != null && metaData.length > 0)
+ {
+ write(ASEmitterTokens.COMMA);
+ writeNewline();
+ writeMetaData(metaData);
+ }
+
+ indentPop();
+ writeNewline();
+ // close return object
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+
+ // close function
+ indentPop();
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ writeNewline(ASEmitterTokens.SEMICOLON);
+ }
+
+ private void writeMetaData(IMetaTagNode[] tags)
+ {
+ JSGoogConfiguration config = ((FlexJSProject)getWalker().getProject()).config;
+ Set<String> allowedNames = config.getCompilerKeepAs3Metadata();
+
+ // metadata: function() {
+ write("metadata");
+ writeToken(ASEmitterTokens.COLON);
+ writeToken(ASEmitterTokens.FUNCTION);
+ write(ASEmitterTokens.PAREN_OPEN);
+ writeToken(ASEmitterTokens.PAREN_CLOSE);
+ writeToken(ASEmitterTokens.BLOCK_OPEN);
+ // return [ array of metadata tags ]
+ writeToken(ASEmitterTokens.RETURN);
+ writeToken(ASEmitterTokens.SQUARE_OPEN);
+
+ int count = 0;
+ for (int i = 0; i < tags.length; i++)
+ {
+ IMetaTagNode tag = tags[i];
+ if (count > 0)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+ }
+ if (!allowedNames.contains(tag.getTagName()))
+ continue;
+ count++;
+ // { name: <tag name>
+ writeToken(ASEmitterTokens.BLOCK_OPEN);
+ write("name");
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(tag.getTagName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ IMetaTagAttribute[] args = tag.getAllAttributes();
+ if (args.length > 0)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+
+ // args: [
+ write("args");
+ writeToken(ASEmitterTokens.COLON);
+ writeToken(ASEmitterTokens.SQUARE_OPEN);
+
+ for (int j = 0; j < args.length; j++)
+ {
+ if (j > 0)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+ }
+ // { key: key, value: value }
+ IMetaTagAttribute arg = args[j];
+ writeToken(ASEmitterTokens.BLOCK_OPEN);
+ write("key");
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ String key = arg.getKey();
+ write(key == null ? "" : key);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COMMA);
+ write("value");
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(arg.getValue());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+ // close array of args
+ write(ASEmitterTokens.SQUARE_CLOSE);
+ }
+ // close metadata object
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+ // close array of metadatas
+ write(ASEmitterTokens.SQUARE_CLOSE);
+ writeToken(ASEmitterTokens.SEMICOLON);
+ // close function
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+}