Repository: flex-falcon Updated Branches: refs/heads/develop ec0a79236 -> 0610fdb6a
- Refactored as and is to emitter. - Fixed the call placements/name of the AccessorEmitter. Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/0610fdb6 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/0610fdb6 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/0610fdb6 Branch: refs/heads/develop Commit: 0610fdb6ab24424b1b87c63f6031e7d49ecd73f3 Parents: ec0a792 Author: Michael Schmalle <[email protected]> Authored: Sun May 31 12:32:26 2015 -0400 Committer: Michael Schmalle <[email protected]> Committed: Sun May 31 12:32:26 2015 -0400 ---------------------------------------------------------------------- .../codegen/js/flexjs/JSFlexJSEmitter.java | 101 ++----- .../internal/codegen/js/jx/AccessorEmitter.java | 303 +++++++++++++++++++ .../internal/codegen/js/jx/AsIsEmitter.java | 118 ++++++++ .../internal/codegen/js/jx/ClassEmitter.java | 23 +- .../internal/codegen/js/jx/GetSetEmitter.java | 290 ------------------ .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java | 12 +- 6 files changed, 456 insertions(+), 391 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0610fdb6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java index f86ca5a..2460d3f 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java @@ -21,12 +21,10 @@ package org.apache.flex.compiler.internal.codegen.js.flexjs; import java.io.FilterWriter; -import org.apache.flex.compiler.asdoc.flexjs.ASDocComment; import org.apache.flex.compiler.codegen.IDocEmitter; import org.apache.flex.compiler.codegen.js.flexjs.IJSFlexJSEmitter; import org.apache.flex.compiler.common.ASModifier; import org.apache.flex.compiler.common.IMetaInfo; -import org.apache.flex.compiler.definitions.IDefinition; import org.apache.flex.compiler.definitions.IFunctionDefinition; import org.apache.flex.compiler.definitions.IPackageDefinition; import org.apache.flex.compiler.definitions.ITypeDefinition; @@ -34,7 +32,10 @@ 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.goog.JSGoogEmitter; import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens; +import org.apache.flex.compiler.internal.codegen.js.jx.AccessorEmitter; +import org.apache.flex.compiler.internal.codegen.js.jx.AsIsEmitter; import org.apache.flex.compiler.internal.codegen.js.jx.BinaryOperatorEmitter; +import org.apache.flex.compiler.internal.codegen.js.jx.BindableEmitter; import org.apache.flex.compiler.internal.codegen.js.jx.ClassEmitter; import org.apache.flex.compiler.internal.codegen.js.jx.FieldEmitter; import org.apache.flex.compiler.internal.codegen.js.jx.ForEachEmitter; @@ -81,20 +82,34 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter private PackageHeaderEmitter packageHeaderEmitter; private PackageFooterEmitter packageFooterEmitter; + private BindableEmitter bindableEmitter; + private ClassEmitter classEmitter; private FieldEmitter fieldEmitter; + private AccessorEmitter accessorEmitter; private FunctionCallEmitter functionCallEmitter; private SuperCallEmitter superCallEmitter; private ForEachEmitter forEachEmitter; private MemberAccessEmitter memberAccessEmitter; + private AsIsEmitter asIsEmitter; private BinaryOperatorEmitter binaryOperatorEmitter; private IdentifierEmitter identifierEmitter; + public BindableEmitter getBindableEmitter() + { + return bindableEmitter; + } + public ClassEmitter getClassEmiter() { return classEmitter; } + public AccessorEmitter getAccessorEmitter() + { + return accessorEmitter; + } + @Override public IDocEmitter getDocEmitter() { @@ -110,12 +125,16 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter packageHeaderEmitter = new PackageHeaderEmitter(this); packageFooterEmitter = new PackageFooterEmitter(this); + bindableEmitter = new BindableEmitter(this); + classEmitter = new ClassEmitter(this); fieldEmitter = new FieldEmitter(this); + accessorEmitter = new AccessorEmitter(this); functionCallEmitter = new FunctionCallEmitter(this); superCallEmitter = new SuperCallEmitter(this); forEachEmitter = new ForEachEmitter(this); memberAccessEmitter = new MemberAccessEmitter(this); + asIsEmitter = new AsIsEmitter(this); binaryOperatorEmitter = new BinaryOperatorEmitter(this); identifierEmitter = new IdentifierEmitter(this); } @@ -156,14 +175,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter @Override public void emitAccessors(IAccessorNode node) { - if (node.getNodeID() == ASTNodeID.GetterID) - { - emitGetAccessor((IGetterNode) node); - } - else if (node.getNodeID() == ASTNodeID.SetterID) - { - emitSetAccessor((ISetterNode) node); - } + accessorEmitter.emit(node); } @Override @@ -210,70 +222,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter public void emitIsAs(IExpressionNode left, IExpressionNode right, ASTNodeID id, boolean coercion) { - // project is null in unit tests - IDefinition dnode = project != null ? (right).resolve(project) : null; - if (id != ASTNodeID.Op_IsID && dnode != null) - { - // find the function node - IFunctionNode functionNode = (IFunctionNode) left - .getAncestorOfType(IFunctionNode.class); - if (functionNode != null) // can be null in synthesized binding code - { - ASDocComment asDoc = (ASDocComment) functionNode - .getASDocComment(); - if (asDoc != null) - { - String asDocString = asDoc.commentNoEnd(); - String ignoreToken = JSFlexJSEmitterTokens.IGNORE_COERCION - .getToken(); - boolean ignore = false; - int ignoreIndex = asDocString.indexOf(ignoreToken); - while (ignoreIndex != -1) - { - String ignorable = asDocString.substring(ignoreIndex - + ignoreToken.length()); - int endIndex = ignorable.indexOf("\n"); - ignorable = ignorable.substring(0, endIndex); - ignorable = ignorable.trim(); - String rightSide = dnode.getQualifiedName(); - if (ignorable.equals(rightSide)) - { - ignore = true; - break; - } - ignoreIndex = asDocString.indexOf(ignoreToken, - ignoreIndex + ignoreToken.length()); - } - if (ignore) - { - getWalker().walk(left); - return; - } - } - } - } - write(JSFlexJSEmitterTokens.LANGUAGE_QNAME); - write(ASEmitterTokens.MEMBER_ACCESS); - if (id == ASTNodeID.Op_IsID) - write(ASEmitterTokens.IS); - else - write(ASEmitterTokens.AS); - write(ASEmitterTokens.PAREN_OPEN); - getWalker().walk(left); - writeToken(ASEmitterTokens.COMMA); - - if (dnode != null) - write(formatQualifiedName(dnode.getQualifiedName())); - else - getWalker().walk(right); - - if (coercion) - { - writeToken(ASEmitterTokens.COMMA); - write(ASEmitterTokens.TRUE); - } - - write(ASEmitterTokens.PAREN_CLOSE); + asIsEmitter.emitIsAs(left, right, id, coercion); } @Override @@ -289,13 +238,13 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter @Override public void emitGetAccessor(IGetterNode node) { - classEmitter.getGetSetEmitter().emitGet(node); + accessorEmitter.emitGet(node); } @Override public void emitSetAccessor(ISetterNode node) { - classEmitter.getGetSetEmitter().emitSet(node); + accessorEmitter.emitSet(node); } @Override http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0610fdb6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AccessorEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AccessorEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AccessorEmitter.java new file mode 100644 index 0000000..0d0bd66 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AccessorEmitter.java @@ -0,0 +1,303 @@ +/* + * + * 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.HashMap; +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.IMetaInfo; +import org.apache.flex.compiler.common.ModifiersSet; +import org.apache.flex.compiler.definitions.IClassDefinition; +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.JSDocEmitterTokens; +import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens; +import org.apache.flex.compiler.internal.codegen.js.JSSessionModel.PropertyNodes; +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.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; +import org.apache.flex.compiler.tree.as.IGetterNode; +import org.apache.flex.compiler.tree.as.ISetterNode; + +public class AccessorEmitter extends JSSubEmitter implements + ISubEmitter<IAccessorNode> +{ + + public AccessorEmitter(IJSEmitter emitter) + { + super(emitter); + } + + @Override + public void emit(IAccessorNode node) + { + if (node.getNodeID() == ASTNodeID.GetterID) + { + emitGet((IGetterNode) node); + } + else if (node.getNodeID() == ASTNodeID.SetterID) + { + emitSet((ISetterNode) node); + } + } + + public void emit(IClassDefinition definition) + { + // TODO (mschmalle) will remove this cast as more things get abstracted + JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter(); + + if (!getModel().getPropertyMap().isEmpty()) + { + writeNewline(); + writeNewline(); + writeNewline(); + write(JSGoogEmitterTokens.OBJECT); + write(ASEmitterTokens.MEMBER_ACCESS); + write(JSEmitterTokens.DEFINE_PROPERTIES); + write(ASEmitterTokens.PAREN_OPEN); + String qname = definition.getQualifiedName(); + write(fjs.formatQualifiedName(qname)); + write(ASEmitterTokens.MEMBER_ACCESS); + write(JSEmitterTokens.PROTOTYPE); + write(ASEmitterTokens.COMMA); + write(ASEmitterTokens.SPACE); + write("/** @lends {" + fjs.formatQualifiedName(qname) + + ".prototype} */ "); + writeNewline(ASEmitterTokens.BLOCK_OPEN); + + Set<String> propertyNames = getModel().getPropertyMap().keySet(); + boolean firstTime = true; + for (String propName : propertyNames) + { + if (firstTime) + firstTime = false; + else + writeNewline(ASEmitterTokens.COMMA); + + PropertyNodes p = getModel().getPropertyMap().get(propName); + writeNewline("/** @expose */"); + write(propName); + write(ASEmitterTokens.COLON); + write(ASEmitterTokens.SPACE); + writeNewline(ASEmitterTokens.BLOCK_OPEN); + if (p.getter != null) + { + write(ASEmitterTokens.GET); + write(ASEmitterTokens.COLON); + write(ASEmitterTokens.SPACE); + write(JSDocEmitterTokens.JSDOC_OPEN); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.ATSIGN); + write(ASEmitterTokens.THIS); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.BLOCK_OPEN); + write(fjs.formatQualifiedName(qname)); + write(ASEmitterTokens.BLOCK_CLOSE); + write(ASEmitterTokens.SPACE); + write(JSDocEmitterTokens.JSDOC_CLOSE); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.FUNCTION); + fjs.emitParameters(p.getter.getParameterNodes()); + + fjs.emitDefinePropertyFunction(p.getter); + } + if (p.setter != null) + { + if (p.getter != null) + writeNewline(ASEmitterTokens.COMMA); + + write(ASEmitterTokens.SET); + write(ASEmitterTokens.COLON); + write(ASEmitterTokens.SPACE); + write(JSDocEmitterTokens.JSDOC_OPEN); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.ATSIGN); + write(ASEmitterTokens.THIS); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.BLOCK_OPEN); + write(fjs.formatQualifiedName(qname)); + write(ASEmitterTokens.BLOCK_CLOSE); + write(ASEmitterTokens.SPACE); + write(JSDocEmitterTokens.JSDOC_CLOSE); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.FUNCTION); + fjs.emitParameters(p.setter.getParameterNodes()); + + fjs.emitDefinePropertyFunction(p.setter); + } + write(ASEmitterTokens.BLOCK_CLOSE); + } + writeNewline(ASEmitterTokens.BLOCK_CLOSE); + write(ASEmitterTokens.PAREN_CLOSE); + write(ASEmitterTokens.SEMICOLON); + } + if (!getModel().getStaticPropertyMap().isEmpty()) + { + write(JSGoogEmitterTokens.OBJECT); + write(ASEmitterTokens.MEMBER_ACCESS); + write(JSEmitterTokens.DEFINE_PROPERTIES); + write(ASEmitterTokens.PAREN_OPEN); + String qname = definition.getQualifiedName(); + write(fjs.formatQualifiedName(qname)); + write(ASEmitterTokens.COMMA); + write(ASEmitterTokens.SPACE); + write("/** @lends {" + fjs.formatQualifiedName(qname) + "} */ "); + writeNewline(ASEmitterTokens.BLOCK_OPEN); + + Set<String> propertyNames = getModel().getStaticPropertyMap() + .keySet(); + boolean firstTime = true; + for (String propName : propertyNames) + { + if (firstTime) + firstTime = false; + else + writeNewline(ASEmitterTokens.COMMA); + + PropertyNodes p = getModel().getStaticPropertyMap().get( + propName); + writeNewline("/** @expose */"); + write(propName); + write(ASEmitterTokens.COLON); + write(ASEmitterTokens.SPACE); + writeNewline(ASEmitterTokens.BLOCK_OPEN); + if (p.getter != null) + { + write(ASEmitterTokens.GET); + write(ASEmitterTokens.COLON); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.FUNCTION); + fjs.emitParameters(p.getter.getParameterNodes()); + + fjs.emitDefinePropertyFunction(p.getter); + } + if (p.setter != null) + { + if (p.getter != null) + writeNewline(ASEmitterTokens.COMMA); + + write(ASEmitterTokens.SET); + write(ASEmitterTokens.COLON); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.FUNCTION); + fjs.emitParameters(p.setter.getParameterNodes()); + + fjs.emitDefinePropertyFunction(p.setter); + } + write(ASEmitterTokens.BLOCK_CLOSE); + } + writeNewline(ASEmitterTokens.BLOCK_CLOSE); + write(ASEmitterTokens.PAREN_CLOSE); + write(ASEmitterTokens.SEMICOLON); + } + } + + public void emitGet(IGetterNode node) + { + // TODO (mschmalle) will remove this cast as more things get abstracted + JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter(); + + ModifiersSet modifierSet = node.getDefinition().getModifiers(); + boolean isStatic = (modifierSet != null && modifierSet + .hasModifier(ASModifier.STATIC)); + HashMap<String, PropertyNodes> map = isStatic ? getModel() + .getStaticPropertyMap() : getModel().getPropertyMap(); + String name = node.getName(); + PropertyNodes p = map.get(name); + if (p == null) + { + p = new PropertyNodes(); + map.put(name, p); + } + p.getter = node; + FunctionNode fn = (FunctionNode) node; + fn.parseFunctionBody(fjs.getProblems()); + } + + public void emitSet(ISetterNode node) + { + // TODO (mschmalle) will remove this cast as more things get abstracted + JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter(); + JSFlexJSDocEmitter doc = (JSFlexJSDocEmitter) fjs.getDocEmitter(); + + ModifiersSet modifierSet = node.getDefinition().getModifiers(); + boolean isStatic = (modifierSet != null && modifierSet + .hasModifier(ASModifier.STATIC)); + HashMap<String, PropertyNodes> map = isStatic ? getModel() + .getStaticPropertyMap() : getModel().getPropertyMap(); + String name = node.getName(); + PropertyNodes p = map.get(name); + if (p == null) + { + p = new PropertyNodes(); + map.put(name, p); + } + p.setter = node; + FunctionNode fn = (FunctionNode) node; + fn.parseFunctionBody(fjs.getProblems()); + + boolean isBindableSetter = false; + if (node instanceof SetterNode) + { + IMetaInfo[] metaInfos = null; + metaInfos = node.getMetaInfos(); + for (IMetaInfo metaInfo : metaInfos) + { + name = metaInfo.getTagName(); + if (name.equals("Bindable") + && metaInfo.getAllAttributes().length == 0) + { + isBindableSetter = true; + break; + } + } + } + if (isBindableSetter) + { + IFunctionDefinition definition = node.getDefinition(); + ITypeDefinition type = (ITypeDefinition) definition.getParent(); + doc.emitMethodDoc(fn, 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.getParameterNodes()); + //writeNewline(); + fjs.emitMethodScope(node.getScopedNode()); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0610fdb6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AsIsEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AsIsEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AsIsEmitter.java new file mode 100644 index 0000000..5d243c7 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AsIsEmitter.java @@ -0,0 +1,118 @@ +/* + * + * 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.asdoc.flexjs.ASDocComment; +import org.apache.flex.compiler.codegen.js.IJSEmitter; +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.tree.ASTNodeID; +import org.apache.flex.compiler.tree.as.IExpressionNode; +import org.apache.flex.compiler.tree.as.IFunctionNode; + +public class AsIsEmitter extends JSSubEmitter +{ + + public AsIsEmitter(IJSEmitter emitter) + { + super(emitter); + } + + public void emitIsAs(IExpressionNode left, IExpressionNode right, + ASTNodeID id, boolean coercion) + { + // TODO (mschmalle) will remove this cast as more things get abstracted + JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter(); + + // project is null in unit tests + //IDefinition dnode = project != null ? (right).resolve(project) : null; + IDefinition dnode = getProject() != null ? (right) + .resolve(getProject()) : null; + if (id != ASTNodeID.Op_IsID && dnode != null) + { + // find the function node + IFunctionNode functionNode = (IFunctionNode) left + .getAncestorOfType(IFunctionNode.class); + if (functionNode != null) // can be null in synthesized binding code + { + ASDocComment asDoc = (ASDocComment) functionNode + .getASDocComment(); + if (asDoc != null) + { + String asDocString = asDoc.commentNoEnd(); + String ignoreToken = JSFlexJSEmitterTokens.IGNORE_COERCION + .getToken(); + boolean ignore = false; + int ignoreIndex = asDocString.indexOf(ignoreToken); + while (ignoreIndex != -1) + { + String ignorable = asDocString.substring(ignoreIndex + + ignoreToken.length()); + int endIndex = ignorable.indexOf("\n"); + ignorable = ignorable.substring(0, endIndex); + ignorable = ignorable.trim(); + String rightSide = dnode.getQualifiedName(); + if (ignorable.equals(rightSide)) + { + ignore = true; + break; + } + ignoreIndex = asDocString.indexOf(ignoreToken, + ignoreIndex + ignoreToken.length()); + } + if (ignore) + { + getWalker().walk(left); + return; + } + } + } + } + + write(JSFlexJSEmitterTokens.LANGUAGE_QNAME); + write(ASEmitterTokens.MEMBER_ACCESS); + + if (id == ASTNodeID.Op_IsID) + write(ASEmitterTokens.IS); + else + write(ASEmitterTokens.AS); + + write(ASEmitterTokens.PAREN_OPEN); + getWalker().walk(left); + writeToken(ASEmitterTokens.COMMA); + + if (dnode != null) + write(fjs.formatQualifiedName(dnode.getQualifiedName())); + else + getWalker().walk(right); + + if (coercion) + { + writeToken(ASEmitterTokens.COMMA); + write(ASEmitterTokens.TRUE); + } + + write(ASEmitterTokens.PAREN_CLOSE); + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0610fdb6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java index 33f6f26..516bd98 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java @@ -39,26 +39,10 @@ import org.apache.flex.compiler.tree.as.IVariableNode; public class ClassEmitter extends JSSubEmitter implements ISubEmitter<IClassNode> { - private BindableEmitter bindableEmitter; - private GetSetEmitter getSetEmitter; - - public BindableEmitter getBindableEmitter() - { - return bindableEmitter; - } - - public GetSetEmitter getGetSetEmitter() - { - return getSetEmitter; - } - + public ClassEmitter(IJSEmitter emitter) { super(emitter); - - bindableEmitter = new BindableEmitter(emitter); - // TODO (mschnalle) this is wrong - getSetEmitter = new GetSetEmitter(emitter); } @Override @@ -150,8 +134,7 @@ public class ClassEmitter extends JSSubEmitter implements } } - bindableEmitter.emit(definition); - - getSetEmitter.emit(definition); + fjs.getBindableEmitter().emit(definition); + fjs.getAccessorEmitter().emit(definition); } } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0610fdb6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/GetSetEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/GetSetEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/GetSetEmitter.java deleted file mode 100644 index 0f996ce..0000000 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/GetSetEmitter.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * - * 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.HashMap; -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.IMetaInfo; -import org.apache.flex.compiler.common.ModifiersSet; -import org.apache.flex.compiler.definitions.IClassDefinition; -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.JSDocEmitterTokens; -import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens; -import org.apache.flex.compiler.internal.codegen.js.JSSessionModel.PropertyNodes; -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.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.as.IGetterNode; -import org.apache.flex.compiler.tree.as.ISetterNode; - -public class GetSetEmitter extends JSSubEmitter implements - ISubEmitter<IClassDefinition> -{ - - public GetSetEmitter(IJSEmitter emitter) - { - super(emitter); - } - - @Override - public void emit(IClassDefinition definition) - { - // TODO (mschmalle) will remove this cast as more things get abstracted - JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter(); - - if (!getModel().getPropertyMap().isEmpty()) - { - writeNewline(); - writeNewline(); - writeNewline(); - write(JSGoogEmitterTokens.OBJECT); - write(ASEmitterTokens.MEMBER_ACCESS); - write(JSEmitterTokens.DEFINE_PROPERTIES); - write(ASEmitterTokens.PAREN_OPEN); - String qname = definition.getQualifiedName(); - write(fjs.formatQualifiedName(qname)); - write(ASEmitterTokens.MEMBER_ACCESS); - write(JSEmitterTokens.PROTOTYPE); - write(ASEmitterTokens.COMMA); - write(ASEmitterTokens.SPACE); - write("/** @lends {" + fjs.formatQualifiedName(qname) - + ".prototype} */ "); - writeNewline(ASEmitterTokens.BLOCK_OPEN); - - Set<String> propertyNames = getModel().getPropertyMap().keySet(); - boolean firstTime = true; - for (String propName : propertyNames) - { - if (firstTime) - firstTime = false; - else - writeNewline(ASEmitterTokens.COMMA); - - PropertyNodes p = getModel().getPropertyMap().get(propName); - writeNewline("/** @expose */"); - write(propName); - write(ASEmitterTokens.COLON); - write(ASEmitterTokens.SPACE); - writeNewline(ASEmitterTokens.BLOCK_OPEN); - if (p.getter != null) - { - write(ASEmitterTokens.GET); - write(ASEmitterTokens.COLON); - write(ASEmitterTokens.SPACE); - write(JSDocEmitterTokens.JSDOC_OPEN); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.ATSIGN); - write(ASEmitterTokens.THIS); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.BLOCK_OPEN); - write(fjs.formatQualifiedName(qname)); - write(ASEmitterTokens.BLOCK_CLOSE); - write(ASEmitterTokens.SPACE); - write(JSDocEmitterTokens.JSDOC_CLOSE); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.FUNCTION); - fjs.emitParameters(p.getter.getParameterNodes()); - - fjs.emitDefinePropertyFunction(p.getter); - } - if (p.setter != null) - { - if (p.getter != null) - writeNewline(ASEmitterTokens.COMMA); - - write(ASEmitterTokens.SET); - write(ASEmitterTokens.COLON); - write(ASEmitterTokens.SPACE); - write(JSDocEmitterTokens.JSDOC_OPEN); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.ATSIGN); - write(ASEmitterTokens.THIS); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.BLOCK_OPEN); - write(fjs.formatQualifiedName(qname)); - write(ASEmitterTokens.BLOCK_CLOSE); - write(ASEmitterTokens.SPACE); - write(JSDocEmitterTokens.JSDOC_CLOSE); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.FUNCTION); - fjs.emitParameters(p.setter.getParameterNodes()); - - fjs.emitDefinePropertyFunction(p.setter); - } - write(ASEmitterTokens.BLOCK_CLOSE); - } - writeNewline(ASEmitterTokens.BLOCK_CLOSE); - write(ASEmitterTokens.PAREN_CLOSE); - write(ASEmitterTokens.SEMICOLON); - } - if (!getModel().getStaticPropertyMap().isEmpty()) - { - write(JSGoogEmitterTokens.OBJECT); - write(ASEmitterTokens.MEMBER_ACCESS); - write(JSEmitterTokens.DEFINE_PROPERTIES); - write(ASEmitterTokens.PAREN_OPEN); - String qname = definition.getQualifiedName(); - write(fjs.formatQualifiedName(qname)); - write(ASEmitterTokens.COMMA); - write(ASEmitterTokens.SPACE); - write("/** @lends {" + fjs.formatQualifiedName(qname) + "} */ "); - writeNewline(ASEmitterTokens.BLOCK_OPEN); - - Set<String> propertyNames = getModel().getStaticPropertyMap() - .keySet(); - boolean firstTime = true; - for (String propName : propertyNames) - { - if (firstTime) - firstTime = false; - else - writeNewline(ASEmitterTokens.COMMA); - - PropertyNodes p = getModel().getStaticPropertyMap().get( - propName); - writeNewline("/** @expose */"); - write(propName); - write(ASEmitterTokens.COLON); - write(ASEmitterTokens.SPACE); - writeNewline(ASEmitterTokens.BLOCK_OPEN); - if (p.getter != null) - { - write(ASEmitterTokens.GET); - write(ASEmitterTokens.COLON); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.FUNCTION); - fjs.emitParameters(p.getter.getParameterNodes()); - - fjs.emitDefinePropertyFunction(p.getter); - } - if (p.setter != null) - { - if (p.getter != null) - writeNewline(ASEmitterTokens.COMMA); - - write(ASEmitterTokens.SET); - write(ASEmitterTokens.COLON); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.FUNCTION); - fjs.emitParameters(p.setter.getParameterNodes()); - - fjs.emitDefinePropertyFunction(p.setter); - } - write(ASEmitterTokens.BLOCK_CLOSE); - } - writeNewline(ASEmitterTokens.BLOCK_CLOSE); - write(ASEmitterTokens.PAREN_CLOSE); - write(ASEmitterTokens.SEMICOLON); - } - } - - - public void emitGet(IGetterNode node) - { - // TODO (mschmalle) will remove this cast as more things get abstracted - JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter(); - - ModifiersSet modifierSet = node.getDefinition().getModifiers(); - boolean isStatic = (modifierSet != null && modifierSet - .hasModifier(ASModifier.STATIC)); - HashMap<String, PropertyNodes> map = isStatic ? getModel() - .getStaticPropertyMap() : getModel().getPropertyMap(); - String name = node.getName(); - PropertyNodes p = map.get(name); - if (p == null) - { - p = new PropertyNodes(); - map.put(name, p); - } - p.getter = node; - FunctionNode fn = (FunctionNode) node; - fn.parseFunctionBody(fjs.getProblems()); - } - - public void emitSet(ISetterNode node) - { - // TODO (mschmalle) will remove this cast as more things get abstracted - JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter(); - JSFlexJSDocEmitter doc = (JSFlexJSDocEmitter) fjs.getDocEmitter(); - - ModifiersSet modifierSet = node.getDefinition().getModifiers(); - boolean isStatic = (modifierSet != null && modifierSet - .hasModifier(ASModifier.STATIC)); - HashMap<String, PropertyNodes> map = isStatic ? getModel() - .getStaticPropertyMap() : getModel().getPropertyMap(); - String name = node.getName(); - PropertyNodes p = map.get(name); - if (p == null) - { - p = new PropertyNodes(); - map.put(name, p); - } - p.setter = node; - FunctionNode fn = (FunctionNode) node; - fn.parseFunctionBody(fjs.getProblems()); - - boolean isBindableSetter = false; - if (node instanceof SetterNode) - { - IMetaInfo[] metaInfos = null; - metaInfos = node.getMetaInfos(); - for (IMetaInfo metaInfo : metaInfos) - { - name = metaInfo.getTagName(); - if (name.equals("Bindable") - && metaInfo.getAllAttributes().length == 0) - { - isBindableSetter = true; - break; - } - } - } - if (isBindableSetter) - { - IFunctionDefinition definition = node.getDefinition(); - ITypeDefinition type = (ITypeDefinition) definition.getParent(); - doc.emitMethodDoc(fn, 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.getParameterNodes()); - //writeNewline(); - fjs.emitMethodScope(node.getScopedNode()); - } - } -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0610fdb6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java index 4efa7a6..41fd718 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java @@ -182,9 +182,12 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements // visit MXML IClassDefinition cdef = node.getClassDefinition(); classDefinition = cdef; - IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker()) + + // TODO (mschmalle) will remove this cast as more things get abstracted + JSFlexJSEmitter fjs = (JSFlexJSEmitter) ((IMXMLBlockWalker) getMXMLWalker()) .getASEmitter(); - ((JSFlexJSEmitter) asEmitter).getModel().setCurrentClass(cdef); + + fjs.getModel().setCurrentClass(cdef); // visit tags final int len = node.getChildCount(); @@ -210,8 +213,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements emitScripts(); - ((JSFlexJSEmitter)asEmitter).getClassEmiter().getBindableEmitter().emit(cdef); - ((JSFlexJSEmitter)asEmitter).getClassEmiter().getGetSetEmitter().emit(cdef); + fjs.getBindableEmitter().emit(cdef); + fjs.getAccessorEmitter().emit(cdef); emitEvents(cname); @@ -220,7 +223,6 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements emitMXMLDescriptorFuncs(cname); emitBindingData(cname, cdef); - } public void emitSubDocument(IMXMLComponentNode node)
