Most of DITA output per class file. Next up: consolidate into package files
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/9345ae4f Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/9345ae4f Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/9345ae4f Branch: refs/heads/develop Commit: 9345ae4f954dfb6daf74eb8116bfbb1b605b3f05 Parents: 1c96ccd Author: Alex Harui <aha...@apache.org> Authored: Tue Oct 18 12:26:30 2016 -0700 Committer: Alex Harui <aha...@apache.org> Committed: Sun Oct 23 23:42:59 2016 -0700 ---------------------------------------------------------------------- .../compiler/asdoc/flexjs/ASDocComment.java | 32 +- .../apache/flex/compiler/clients/ASDOCJSC.java | 5 + .../apache/flex/compiler/clients/MXMLJSC.java | 1 + .../js/flexjs/JSFlexJSASDocDITAEmitter.java | 1169 ++++++++++++++++++ .../codegen/js/flexjs/JSFlexJSASDocEmitter.java | 42 +- .../mxml/flexjs/MXMLFlexJSASDocEmitter.java | 3 +- .../mxml/flexjs/MXMLFlexJSASDocDITABackend.java | 136 ++ 7 files changed, 1381 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9345ae4f/compiler-jx/src/main/java/org/apache/flex/compiler/asdoc/flexjs/ASDocComment.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/asdoc/flexjs/ASDocComment.java b/compiler-jx/src/main/java/org/apache/flex/compiler/asdoc/flexjs/ASDocComment.java index b8e97d3..0f0a4dc 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/asdoc/flexjs/ASDocComment.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/asdoc/flexjs/ASDocComment.java @@ -78,6 +78,11 @@ public class ASDocComment implements IASDocComment @Override public void compile() { + compile(true); + } + + public void compile(boolean trimlines) + { String s = token.getText(); String[] lines = s.split("\n"); StringBuilder sb = new StringBuilder(); @@ -89,17 +94,26 @@ public class ASDocComment implements IASDocComment lines[0] = lines[0].substring(0, c); } // clip off asdoc slash-star-star - sb.append(lines[0].substring(3).trim()); + String line = lines[0].substring(3); + if (trimlines) + sb.append(line.trim()); + else + sb.append(line + "\n"); for (int i = 1; i < n - 1; i++) { - String line = lines[i]; + line = lines[i]; int star = line.indexOf("*"); int at = line.indexOf("@"); if (at == -1) { sb.append(" "); if (star > -1) - sb.append(line.substring(star + 1).trim()); + { + if (trimlines) + sb.append(line.substring(star + 1).trim()); + else + sb.append(line.substring(star + 1) + "\n"); + } } else { @@ -124,7 +138,10 @@ public class ASDocComment implements IASDocComment } } } - description = sb.toString().trim().replace("\"", "\\\""); + if (trimlines) + description = sb.toString().trim().replace("\"", "\\\""); + else + description = sb.toString(); } @Override @@ -138,7 +155,12 @@ public class ASDocComment implements IASDocComment @Override public IASDocTag getTag(String name) { - return tagMap.get(name).get(0); + if (tagMap == null) + return null; + List<IASDocTag> tags = tagMap.get(name); + if (tags == null) + return null; + return tags.get(0); } @Override http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9345ae4f/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java index 0ba33f0..8aa0552 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java @@ -42,6 +42,7 @@ import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend; import org.apache.flex.compiler.internal.driver.js.goog.ASDocConfiguration; import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend; import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSASDocBackend; +import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSASDocDITABackend; import org.apache.flex.compiler.internal.driver.mxml.jsc.MXMLJSCJSSWCBackend; import org.apache.flex.compiler.internal.driver.mxml.vf2js.MXMLVF2JSSWCBackend; import org.apache.flex.compiler.internal.projects.CompilerProject; @@ -135,6 +136,10 @@ public class ASDOCJSC extends MXMLJSC backend = new MXMLFlexJSASDocBackend(); break; + case FLEXJS_DITA: + backend = new MXMLFlexJSASDocDITABackend(); + break; + case GOOG: backend = new GoogBackend(); break; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9345ae4f/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java index 0430905..875439a 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java @@ -107,6 +107,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider, GOOG("goog"), VF2JS("vf2js"), FLEXJS_DUAL("flexjs_dual"), + FLEXJS_DITA("flexjs_dita"), JSC("jsc"), NODE("node"); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9345ae4f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSASDocDITAEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSASDocDITAEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSASDocDITAEmitter.java new file mode 100644 index 0000000..04ac05a --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSASDocDITAEmitter.java @@ -0,0 +1,1169 @@ +/* + * + * 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.flexjs; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.FilterWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.flex.compiler.asdoc.IASDocTag; +import org.apache.flex.compiler.asdoc.flexjs.ASDocComment; +import org.apache.flex.compiler.codegen.js.flexjs.IJSFlexJSASDocEmitter; +import org.apache.flex.compiler.codegen.js.flexjs.IJSFlexJSEmitter; +import org.apache.flex.compiler.constants.IASLanguageConstants; +import org.apache.flex.compiler.definitions.IAccessorDefinition; +import org.apache.flex.compiler.definitions.IClassDefinition; +import org.apache.flex.compiler.definitions.IDefinition; +import org.apache.flex.compiler.definitions.IFunctionDefinition; +import org.apache.flex.compiler.definitions.IInterfaceDefinition; +import org.apache.flex.compiler.definitions.IPackageDefinition; +import org.apache.flex.compiler.definitions.IParameterDefinition; +import org.apache.flex.compiler.definitions.metadata.IDeprecationInfo; +import org.apache.flex.compiler.definitions.metadata.IMetaTag; +import org.apache.flex.compiler.definitions.references.INamespaceReference; +import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitter; +import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLFlexJSASDocEmitter; +import org.apache.flex.compiler.internal.definitions.AccessorDefinition; +import org.apache.flex.compiler.internal.definitions.ClassDefinition; +import org.apache.flex.compiler.internal.definitions.EventDefinition; +import org.apache.flex.compiler.internal.definitions.FunctionDefinition; +import org.apache.flex.compiler.internal.definitions.InterfaceDefinition; +import org.apache.flex.compiler.internal.definitions.VariableDefinition; +import org.apache.flex.compiler.internal.projects.FlexJSASDocProject; +import org.apache.flex.compiler.internal.tree.as.metadata.EventTagNode; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IAccessorNode; +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.IFileNode; +import org.apache.flex.compiler.tree.as.IFunctionNode; +import org.apache.flex.compiler.tree.as.IGetterNode; +import org.apache.flex.compiler.tree.as.IInterfaceNode; +import org.apache.flex.compiler.tree.as.INamespaceNode; +import org.apache.flex.compiler.tree.as.IPackageNode; +import org.apache.flex.compiler.tree.as.ISetterNode; +import org.apache.flex.compiler.tree.as.IVariableNode; +import org.apache.flex.compiler.tree.metadata.IMetaTagNode; +import org.apache.flex.compiler.utils.NativeUtils; + +/** + * Concrete implementation of the 'FlexJS' JavaScript production. + * + * @author Michael Schmalle + * @author Erik de Bruin + */ +public class JSFlexJSASDocDITAEmitter extends JSGoogEmitter implements IJSFlexJSEmitter, IJSFlexJSASDocEmitter +{ + + private boolean wroteSomething = false; + + @Override + public String postProcess(String output) + { + return output; + } + + public JSFlexJSASDocDITAEmitter(FilterWriter out) + { + super(out); + } + + @Override + protected void writeIndent() + { + write(JSFlexJSEmitterTokens.INDENT); + } + + @Override + protected String getIndent(int numIndent) + { + final StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numIndent; i++) + sb.append(JSFlexJSEmitterTokens.INDENT.getToken()); + return sb.toString(); + } + + @Override + public void emitNamespace(INamespaceNode node) + { + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + if (asDoc != null && asDoc.commentNoEnd().contains("@private")) + return; + writeNewline("{ \"type\": \"namespace\","); + write(" \"qname\": \""); + write(formatQualifiedName(node.getQualifiedName())); + writeNewline("\","); + indentPush(); + if (asDoc != null) + writeASDoc(asDoc); + indentPop(); + writeNewline("}"); + } + + + @Override + public String formatQualifiedName(String name) + { + return formatQualifiedName(name, false); + } + + public MXMLFlexJSASDocEmitter mxmlEmitter = null; + + public String formatQualifiedName(String name, boolean isDoc) + { + if (mxmlEmitter != null) + name = mxmlEmitter.formatQualifiedName(name); + /* + if (name.contains("goog.") || name.startsWith("Vector.")) + return name; + name = name.replaceAll("\\.", "_"); + */ + if (getModel().isInternalClass(name)) + return getModel().getInternalClasses().get(name); + if (NativeUtils.isJSNative(name)) return name; + if (name.startsWith("window.")) + name = name.substring(7); + else if (!isDoc) + { + } + int c = name.lastIndexOf("."); + if (c != -1) + name = name.substring(0, c) + ":" + name.substring(c + 1); + return name; + } + + public String convertASTypeToJS(String name) + { + String result = name; + + if (name.equals("")) + result = IASLanguageConstants.Object; + else if (name.equals(IASLanguageConstants.Class)) + result = IASLanguageConstants.Object; + else if (name.equals(IASLanguageConstants._int) + || name.equals(IASLanguageConstants.uint)) + result = IASLanguageConstants.Number; + + boolean isBuiltinFunction = name.matches("Vector\\.<.*>"); + if (isBuiltinFunction) + { + result = IASLanguageConstants.Array; + } + return result; + } + + //-------------------------------------------------------------------------- + // Package Level + //-------------------------------------------------------------------------- + + @Override + public void emitPackageHeader(IPackageDefinition definition) + { + IPackageNode packageNode = definition.getNode(); + IFileNode fileNode = (IFileNode) packageNode.getAncestorOfType(IFileNode.class); + int nodeCount = fileNode.getChildCount(); + for (int i = 0; i < nodeCount; i++) + { + IASNode pnode = fileNode.getChild(i); + + if (pnode instanceof IPackageNode) + { + } + else if (pnode instanceof IClassNode) + { + getWalker().walk(pnode); + } + else if (pnode instanceof IInterfaceNode) + { + getWalker().walk(pnode); + } + else if (pnode instanceof IFunctionNode) + { + getWalker().walk(pnode); + } + else if (pnode instanceof INamespaceNode) + { + getWalker().walk(pnode); + } + else if (pnode instanceof IVariableNode) + { + getWalker().walk(pnode); + } + } + } + + @Override + public void emitPackageHeaderContents(IPackageDefinition definition) + { + } + + @Override + public void emitPackageFooter(IPackageDefinition definition) + { + } + + //-------------------------------------------------------------------------- + // Class + //-------------------------------------------------------------------------- + + @Override + public void emitClass(IClassNode node) + { + IClassDefinition def = node.getDefinition(); + write("<apiClassifier id=\""); + write(formatQualifiedName(node.getQualifiedName())); + write("\"><apiName>"); + write(node.getName()); + write("</apiName>"); + + String linkText = ""; + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + String shortdesc = null; + if (asDoc != null) + { + asDoc.compile(false); + shortdesc = makeShortDescription(asDoc); + write(shortdesc); + linkText = writeASDoc(asDoc); + } + else + write("<shortdesc/>"); + + write("<apiClassifierDetail>"); + write("<apiClassifierDef>"); + if (def.isPublic()) + write("<apiAccess value=\"public\"/>"); + write("<apiStatic/>"); + IExpressionNode interfaceNodes[] = node.getImplementedInterfaceNodes(); + for (IExpressionNode base : interfaceNodes) + { + write("<apiBaseInterface>"); + write(formatQualifiedName(base.resolve(getWalker().getProject()).getQualifiedName())); + write("</apiBaseInterface>"); + } + write("<apiBaseClassifier>"); + IExpressionNode baseNode = node.getBaseClassExpressionNode(); + if (baseNode == null) + write("Object"); + else + write(formatQualifiedName(baseNode.resolve(getWalker().getProject()).getQualifiedName())); + write("</apiBaseClassifier>"); + write("</apiClassifierDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</apiClassifierDetail>"); + write(linkText); + + final IDefinitionNode[] members = node.getAllMemberNodes(); + for (IDefinitionNode mnode : members) + { + getWalker().walk(mnode); + } + IMetaTagNode[] metas = node.getMetaTagNodesByName("Event"); + for (IMetaTagNode mnode : metas) + { + writeEventTagNode(mnode, def); + } + + write("</apiClassifier>"); + addToIndex(node.getDefinition(), asDoc); + FlexJSASDocProject project = (FlexJSASDocProject)getWalker().getProject(); + FlexJSASDocProject.ASDocRecord record = project.new ASDocRecord(); + record.definition = node.getDefinition(); + if (asDoc != null) + record.description = makeShortDescription(asDoc); + else + record.description = ""; + ((FlexJSASDocProject)getWalker().getProject()).classes.put(formatQualifiedName(node.getQualifiedName()), record); + } + + @Override + public void emitInterface(IInterfaceNode node) + { + IInterfaceDefinition def = node.getDefinition(); + write("<apiClassifier id=\""); + write(formatQualifiedName(node.getQualifiedName())); + write("\"><apiName>"); + write(node.getName()); + write("</apiName>"); + + String linkText = ""; + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + String shortdesc = null; + if (asDoc != null) + { + asDoc.compile(false); + shortdesc = makeShortDescription(asDoc); + write(shortdesc); + linkText = writeASDoc(asDoc); + } + else + write("<shortdesc/>"); + + write("<apiClassifierDetail>"); + write("<apiClassifierDef>"); + write("<apiInterface/>"); + if (def.isPublic()) + write("<apiAccess value=\"public\"/>"); + write("<apiStatic/>"); + IExpressionNode baseNodes[] = node.getExtendedInterfaceNodes(); + for (IExpressionNode base : baseNodes) + { + write("<apiBaseInterface>"); + write(formatQualifiedName(base.resolve(getWalker().getProject()).getQualifiedName())); + write("</apiBaseInterface>"); + } + write("<apiBaseClassifier/>"); + write("</apiClassifierDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</apiClassifierDetail>"); + + final IDefinitionNode[] members = node.getAllMemberDefinitionNodes(); + for (IDefinitionNode mnode : members) + { + getWalker().walk(mnode); + } + write(linkText); + write("</apiClassifier>"); + addToIndex(node.getDefinition(), asDoc); + FlexJSASDocProject project = (FlexJSASDocProject)getWalker().getProject(); + FlexJSASDocProject.ASDocRecord record = project.new ASDocRecord(); + record.definition = node.getDefinition(); + if (asDoc != null) + record.description = makeShortDescription(asDoc); + else + record.description = ""; + ((FlexJSASDocProject)getWalker().getProject()).classes.put(formatQualifiedName(node.getQualifiedName()), record); + } + + private ArrayList<String> accessors = new ArrayList<String>(); + + @Override + public void emitGetAccessor(IGetterNode node) + { + IDefinition def = node.getDefinition(); + boolean isInterface = def.getParent() instanceof InterfaceDefinition; + if (node.getDefinition().isPrivate()) return; + + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + if (asDoc != null && asDoc.commentNoEnd().contains("@private")) + return; + + String name = node.getName(); + if (accessors.contains(name)) return; + accessors.add(name); + write("<apiValue id=\""); + if (isInterface) + { + write(formatQualifiedName(def.getParent().getQualifiedName())); + write(":"); + } + write(formatQualifiedName(def.getParent().getQualifiedName())); + write(":"); + write(formatQualifiedName(node.getQualifiedName())); + write(":get\"><apiName>"); + write(node.getName()); + write("</apiName>"); + String shortdesc = null; + String linkText = ""; + if (asDoc != null) + { + asDoc.compile(false); + shortdesc = makeShortDescription(asDoc); + write(shortdesc); + linkText = writeASDoc(asDoc); + } + else + write("<shortdesc/>"); + + write("<apiValueDetail>"); + write("<apiValueDef>"); + write("<apiProperty/>"); + if (def.isPublic() || isInterface) + write("<apiAccess value=\"public\"/>"); + else if (def.isProtected()) + write("<apiAccess value=\"protected\"/>"); + if (def.isStatic()) + write("<apiStatic/>"); + write("<apiDynamic/>"); + write("<apiValueAccess value=\"read\"/>"); + write("<apiType value=\""); + write(formatQualifiedName(def.resolveType(getWalker().getProject()).getQualifiedName())); + write("\"/>"); + write("</apiValueDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</apiValueDetail>"); + write(linkText); + write("</apiValue>"); + addToIndex(node.getDefinition(), asDoc); + } + + @Override + public void emitSetAccessor(ISetterNode node) + { + IDefinition def = node.getDefinition(); + boolean isInterface = def.getParent() instanceof InterfaceDefinition; + if (node.getDefinition().isPrivate()) return; + + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + if (asDoc != null && asDoc.commentNoEnd().contains("@private")) + return; + + String name = node.getName(); + if (accessors.contains(name)) return; + accessors.add(name); + write("<apiValue id=\""); + if (isInterface) + { + write(formatQualifiedName(def.getParent().getQualifiedName())); + write(":"); + } + write(formatQualifiedName(def.getParent().getQualifiedName())); + write(":"); + write(formatQualifiedName(node.getQualifiedName())); + write(":set\"><apiName>"); + write(node.getName()); + write("</apiName>"); + String shortdesc = null; + String linkText = ""; + if (asDoc != null) + { + asDoc.compile(false); + shortdesc = makeShortDescription(asDoc); + write(shortdesc); + linkText = writeASDoc(asDoc); + } + else + write("<shortdesc/>"); + + write("<apiValueDetail>"); + write("<apiValueDef>"); + writeAPIProperties(def); + if (def.isPublic() || def.getParent() instanceof InterfaceDefinition) + write("<apiAccess value=\"public\"/>"); + else if (def.isProtected()) + write("<apiAccess value=\"protected\"/>"); + if (def.isStatic()) + write("<apiStatic/>"); + write("<apiDynamic/>"); + write("<apiValueAccess value=\"write\"/>"); + write("<apiValueClassifier>"); + write(formatQualifiedName(def.resolveType(getWalker().getProject()).getQualifiedName())); + write("</apiValueClassifier>"); + write("</apiValueDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</apiValueDetail>"); + write(linkText); + write("</apiValue>"); + + addToIndex(node.getDefinition(), asDoc); + } + + @Override + public void emitField(IVariableNode node) + { + IDefinition def = node.getDefinition(); + if (node.getDefinition().isPrivate()) return; + + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + if (asDoc != null && asDoc.commentNoEnd().contains("@private")) + return; + write("<apiValue id=\""); + write(formatQualifiedName(def.getParent().getQualifiedName())); + write(":"); + write(formatQualifiedName(node.getQualifiedName())); + write("\"><apiName>"); + write(node.getName()); + write("</apiName>"); + String shortdesc = null; + String linkText = ""; + if (asDoc != null) + { + asDoc.compile(false); + shortdesc = makeShortDescription(asDoc); + write(shortdesc); + linkText = writeASDoc(asDoc); + } + else + write("<shortdesc/>"); + + write("<apiValueDetail>"); + write("<apiValueDef>"); + writeAPIProperties(def); + if (def.isPublic() || def.getParent() instanceof InterfaceDefinition) + write("<apiAccess value=\"public\"/>"); + else if (def.isProtected()) + write("<apiAccess value=\"protected\"/>"); + if (def.isStatic()) + write("<apiStatic/>"); + write("<apiDynamic/>"); + write("<apiValueClassifier>"); + write(formatQualifiedName(def.resolveType(getWalker().getProject()).getQualifiedName())); + write("</apiValueClassifier>"); + write("</apiValueDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</apiValueDetail>"); + write(linkText); + write("</apiValue>"); + addToIndex(node.getDefinition(), asDoc); + } + + @Override + public void emitVarDeclaration(IVariableNode node) + { + IDefinition def = node.getDefinition(); + if (node.getDefinition().isPrivate()) return; + + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + if (asDoc != null && asDoc.commentNoEnd().contains("@private")) + return; + write("<apiValue id=\""); + write(formatQualifiedName(node.getQualifiedName())); + write("\"><apiName>"); + write(node.getName()); + write("</apiName>"); + String shortdesc = null; + if (asDoc != null) + { + asDoc.compile(false); + shortdesc = makeShortDescription(asDoc); + write(shortdesc); + writeASDoc(asDoc); + } + else + write("<shortdesc/>"); + + write("<apiValueDetail>"); + write("<apiValueDef>"); + writeAPIProperties(def); + if (def.isPublic() || def.getParent() instanceof InterfaceDefinition) + write("<apiAccess value=\"public\"/>"); + else if (def.isProtected()) + write("<apiAccess value=\"protected\"/>"); + if (def.isStatic()) + write("<apiStatic/>"); + write("<apiDynamic/>"); + write("<apiType value=\""); + write(formatQualifiedName(def.resolveType(getWalker().getProject()).getQualifiedName())); + write("\"/>"); + write("</apiValueDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</apiValueDetail>"); + write("</apiValue>"); + addToIndex(node.getDefinition(), asDoc); + } + + @Override + public void emitAccessors(IAccessorNode node) + { + if (node.getDefinition().isPrivate()) return; + + String name = node.getName(); + if (accessors.contains(name)) return; + accessors.add(name); + writeNewline("{ \"type\": \"accessor\","); + IAccessorDefinition def = (IAccessorDefinition)node.getDefinition(); + IAccessorDefinition otherDef = (IAccessorDefinition)def.resolveCorrespondingAccessor(getWalker().getProject()); + IAccessorNode otherNode = null; + if (otherDef != null) + { + otherNode = (IAccessorNode)otherDef.getNode(); + writeNewline(" \"access\": \"read-write\","); + } + else + writeNewline(" \"access\": \"read-only\","); + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + if (asDoc == null || asDoc.commentNoEnd().contains("@private")) + { + if (otherNode != null) + asDoc = (ASDocComment) otherNode.getASDocComment(); + } + write("<apiValue id=\""); + write(formatQualifiedName(node.getQualifiedName())); + write(":set\"><apiName>"); + write(node.getName()); + write("</apiName>"); + String shortdesc = null; + if (asDoc != null) + { + asDoc.compile(false); + shortdesc = makeShortDescription(asDoc); + write(shortdesc); + writeASDoc(asDoc); + } + else + write("<shortdesc/>"); + + write("<apiValueDetail>"); + write("<apiValueDef>"); + writeAPIProperties(def); + if (def.isPublic() || def.getParent() instanceof InterfaceDefinition) + write("<apiAccess value=\"public\"/>"); + else if (def.isProtected()) + write("<apiAccess value=\"protected\"/>"); + if (def.isStatic()) + write("<apiStatic/>"); + write("<apiDynamic/>"); + if (otherDef != null) + { + otherNode = (IAccessorNode)otherDef.getNode(); + write("<apiValueAccess value=\"read-write\"/>"); + } + else + writeNewline(" \"access\": \"read\","); + write("<apiType value=\""); + write(formatQualifiedName(def.resolveType(getWalker().getProject()).getQualifiedName())); + write("\"/>"); + write("</apiValueDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</apiValueDetail>"); + write("</apiValue>"); + addToIndex(node.getDefinition(), asDoc); + } + + @Override + public void emitMethod(IFunctionNode node) + { + IFunctionDefinition def = node.getDefinition(); + if (def.isPrivate()) return; + + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + if (asDoc != null && asDoc.commentNoEnd().contains("@private")) + return; + + if (node.isConstructor()) + { + write("<apiConstructor id=\""); + write(formatQualifiedName(node.getQualifiedName())); + write(":"); + write(node.getName()); + write("\"><apiName>"); + write(node.getName()); + write("</apiName>"); + String shortdesc = null; + if (asDoc != null) + { + asDoc.compile(false); + shortdesc = makeShortDescription(asDoc); + write(shortdesc); + writeASDoc(asDoc); + } + else + write("<shortdesc/>"); + + write("<apiConstructorDetail>"); + write("<apiConstructorDef>"); + write("<apiAccess value=\"public\"/>"); + write("</apiConstructorDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</apiConstructorDetail>"); + write("</apiConstructor>"); + } + else + { + write("<apiOperation id=\""); + write(formatQualifiedName(def.getParent().getQualifiedName())); + write(":"); + write(formatQualifiedName(node.getQualifiedName())); + write("\"><apiName>"); + write(node.getName()); + write("</apiName>"); + String shortdesc = null; + if (asDoc != null) + { + asDoc.compile(false); + shortdesc = makeShortDescription(asDoc); + write(shortdesc); + writeASDoc(asDoc); + } + else + write("<shortdesc/>"); + + write("<apiOperationDetail>"); + write("<apiOperationDef>"); + if (def.isPublic() || def.getParent() instanceof InterfaceDefinition) + write("<apiAccess value=\"public\"/>"); + else if (def.isProtected()) + write("<apiAccess value=\"protected\"/>"); + if (def.isStatic()) + write("<apiStatic/>"); + write("<apiReturn><apiType value=\""); + write(def.getReturnTypeAsDisplayString()); + write("\"/></apiReturn>"); + IParameterDefinition params[] = def.getParameters(); + write("<apiParam>"); + for (IParameterDefinition param : params) + { + write("<apiItemName>"); + write(param.getBaseName()); + write("</apiItemName><apiType value=\""); + write(param.getTypeAsDisplayString()); + write("\">"); + if (param.hasDefaultValue()) + { + write("<apiData>"); + write(param.getNode().getDefaultValue()); + write("</apiData>"); + } + write("</apiParam>"); + } + write("</apiOperationDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</apiOperationDetail>"); + write("</apiOperation>"); + } + addToIndex(node.getDefinition(), asDoc); + } + + public String writeASDoc(ASDocComment asDoc) + { + StringBuilder linkText = new StringBuilder(); + FlexJSASDocProject project = (FlexJSASDocProject)getWalker().getProject(); + List<String> tagList = project.tags; + Map<String, List<IASDocTag>> tags = asDoc.getTags(); + if (tags != null) + { + write("<prolog><asMetadata><apiVersion>"); + List<IASDocTag> values = tags.get("langversion"); + if (values != null) + { + for (IASDocTag value : values) + { + write("<apiLanguage version=\""); + write(value.getDescription()); + write("\"/>"); + } + } + values = tags.get("playerversion"); + if (values != null) + { + for (IASDocTag value : values) + { + write("<apiPlatform description=\"\" name=\""); + String desc = value.getDescription(); + String parts[] = desc.split(" "); + write(parts[0]); + write("\" version=\""); + write(parts[1]); + write("\"/>"); + } + } + values = tags.get("productversion"); + if (values != null) + { + for (IASDocTag value : values) + { + write("<apiTool description=\"\" name=\""); + String desc = value.getDescription(); + String parts[] = desc.split(" "); + write(parts[0]); + write("\" version=\""); + write(parts[1]); + write("\"/>"); + } + } + values = tags.get("see"); + if (values != null) + { + linkText.append("<related-links>"); + for (IASDocTag value : values) + { + linkText.append("<link href=\""); + String desc = value.getDescription(); + String parts[] = desc.split("#"); + String fileName = parts[0]; + int c = fileName.lastIndexOf("."); + if (c == -1) + { + c = fileName.length(); + } + linkText.append(fileName.substring(0, c)); + if (parts.length == 1) + { + linkText.append(".xml"); + } + else + { + linkText.append(".xml#"); + linkText.append(fileName.substring(c + 1)); + linkText.append("/"); + linkText.append(parts[1]); + } + linkText.append("\"/>"); + linkText.append("<linktext>"); + linkText.append(parts[0]); + if (parts.length > 1) + { + linkText.append("."); + linkText.append(parts[1]); + } + linkText.append("</linktext>"); + linkText.append("</link>"); + } + linkText.append("</related-links>"); + } + write("</apiVersion></asMetadata>"); + boolean needHeader = true; + boolean needFooter = false; + Set<String> tagNames = tags.keySet(); + for (String tagName : tagNames) + { + if (!tagList.contains(tagName)) + tagList.add(tagName); + if (!(tagName.equals("see") || + tagName.equals("copy") || + tagName.equals("productversion") || + tagName.equals("langversion") || + tagName.equals("playerversion"))) + { + if (needHeader) + { + write("<asCustoms>"); + needFooter = true; + } + values = tags.get(tagName); + if (values != null) + { + write("<" + tagName + ">"); + for (IASDocTag value : values) + { + write(value.getDescription()); + } + write("</" + tagName + ">"); + } + else + write("<" + tagName + "/>"); + } + } + if (needFooter) + write("</asCustoms>"); + write("</prolog>"); + } + else + write("<prolog/>"); + return linkText.toString(); + } + + @Override + public void write(String value) + { + super.write(value); + wroteSomething = true; + } + + public void writeEventTagNode(IMetaTagNode node, IClassDefinition classDef) + { + EventTagNode evt = (EventTagNode)node; + ASDocComment asDoc = (ASDocComment) evt.getASDocComment(); + if (asDoc != null && asDoc.commentNoEnd().contains("@private")) + return; + write("<adobeApiEvent id=\""); + write(formatQualifiedName(classDef.getQualifiedName())); + write("_"); + write(evt.getValue("type")); + write("_"); + write(evt.getValue("name")); + writeNewline("\">"); + write("<apiName>"); + write(evt.getValue("name")); + write("</apiName>"); + if (asDoc != null) + { + asDoc.compile(false); + write(makeShortDescription(asDoc)); + writeASDoc(asDoc); + } + write("<adobeApiEventDetail>"); + write("<adobeApiEventDef>"); + write("<adobeApiEventClassifier>"); + write(evt.getValue("type")); + write("</adobeApiEventClassifier>"); + write("<apiGeneratedEvent>"); + write("</adobeApiEventDef>"); + if (asDoc != null) + { + writeAPIDesc(asDoc); + } + write("</adobeApiEventDetail>"); + write("</adobeApiEvent>"); + + addToIndex(evt.getDefinition(), asDoc); + } + + private void addToIndex(IDefinition def, ASDocComment asDoc) + { + FlexJSASDocProject project = (FlexJSASDocProject)getWalker().getProject(); + List<FlexJSASDocProject.ASDocRecord> list = project.index.get(def.getBaseName()); + if (list == null) + { + list = new ArrayList<FlexJSASDocProject.ASDocRecord>(); + project.index.put(def.getBaseName(), list); + } + FlexJSASDocProject.ASDocRecord record = project.new ASDocRecord(); + record.definition = def; + if (asDoc != null) + record.description = makeShortDescription(asDoc); + else + record.description = ""; + list.add(record); + } + + private String makeShortDescription(ASDocComment asDoc) + { + String description = asDoc.getDescription(); + if (description == null || description.length() == 0) + return "<shortdesc/>"; + + StringBuilder sb = new StringBuilder(); + sb.append("<shortdesc"); + IASDocTag copyTag = asDoc.getTag("copy"); + if (copyTag != null) + { + sb.append(" conref=\""); + sb.append(copyTag.getDescription()); + sb.append("\">\n"); + } + else + { + sb.append(">"); + int c = description.indexOf("."); + if (c != -1) + sb.append(description.substring(0, c + 1)); + else + sb.append(description); + } + sb.append("</shortdesc>"); + return sb.toString(); + } + + private void writeAPIDesc(ASDocComment asDoc) + { + write("<apiDesc"); + IASDocTag copyTag = asDoc.getTag("copy"); + if (copyTag != null) + { + write(" conref=\""); + write(copyTag.getDescription()); + write("\">\n"); + } + else + { + write(">"); + write(asDoc.getDescription()); + } + write("</apiDesc>"); + + } + + public void writeAPIProperties(IDefinition def) + { + IMetaTag propTag = def.getMetaTagByName("Bindable"); + if (propTag == null) + { + write("<apiProperty/>"); + return; + } + write("<apiProperty isBindable=\"true\""); + String value = propTag.getValue(); + if (value != null) + { + write(" name=\""); + write(value); + write("\""); + } + write("/>"); + } + + public void outputIndex(File outputFolder, FlexJSASDocProject project) throws IOException + { + final File indexFile = new File(outputFolder, "index.json"); + FileWriter out = new FileWriter(indexFile); + out.write("{ \"index\": ["); + System.out.println("Compiling file: " + indexFile); + Set<String> keys = project.index.keySet(); + List<String> keyList = new ArrayList<String>(keys); + Collections.sort(keyList); + boolean firstLine = true; + for (String key : keyList) + { + List<FlexJSASDocProject.ASDocRecord> list = project.index.get(key); + for (FlexJSASDocProject.ASDocRecord record : list) + { + if (!firstLine) + out.write(",\n"); + firstLine = false; + out.write("{ \"name\": \""); + out.write(key); + out.write("\",\n"); + out.write(" \"type\": "); + if (record.definition instanceof ClassDefinition) + out.write("\"Class\",\n"); + else if (record.definition instanceof InterfaceDefinition) + out.write("\"Interface\",\n"); + else if (record.definition instanceof EventDefinition) + out.write("\"Event\",\n"); + else if (record.definition instanceof AccessorDefinition) + { + out.write("\"Property\",\n"); + out.write(" \"class\": \""); + out.write(formatQualifiedName(record.definition.getParent().getQualifiedName())); + out.write("\",\n"); + } + else if (record.definition instanceof VariableDefinition) + { + out.write("\"Property\",\n"); + out.write(" \"class\": \""); + out.write(formatQualifiedName(record.definition.getParent().getQualifiedName())); + out.write("\",\n"); + } + else if (record.definition instanceof FunctionDefinition) + { + out.write("\"Method\",\n"); + out.write(" \"class\": \""); + out.write(formatQualifiedName(record.definition.getParent().getQualifiedName())); + out.write("\",\n"); + } + out.write(" \"description\": \""); + out.write(record.description); + out.write("\"}"); + } + } + out.write("]}"); + try { + out.flush(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void outputClasses(File outputFolder, FlexJSASDocProject project) throws IOException + { + final File indexFile = new File(outputFolder, "classes.json"); + FileWriter out = new FileWriter(indexFile); + out.write("{ \"classes\": ["); + System.out.println("Compiling file: " + indexFile); + Set<String> keys = project.classes.keySet(); + List<String> keyList = new ArrayList<String>(keys); + Collections.sort(keyList); + boolean firstLine = true; + for (String key : keyList) + { + if (!firstLine) + out.write(",\n"); + firstLine = false; + FlexJSASDocProject.ASDocRecord record = project.classes.get(key); + out.write("{ \"name\": \""); + out.write(key); + out.write("\",\n"); + out.write(" \"description\": \""); + out.write(record.description); + out.write("\"}"); + } + out.write("]}"); + try { + out.flush(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void outputTags(File outputFolder, FlexJSASDocProject project) throws IOException + { + final File indexFile = new File(outputFolder, "tags.json"); + FileWriter out = new FileWriter(indexFile); + out.write("{ \"tags\": ["); + System.out.println("Compiling file: " + indexFile); + Collections.sort(project.tags); + boolean firstLine = true; + for (String tag : project.tags) + { + if (!firstLine) + out.write(",\n"); + firstLine = false; + out.write("\""); + out.write(tag); + out.write("\""); + } + out.write("]}"); + try { + out.flush(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9345ae4f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSASDocEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSASDocEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSASDocEmitter.java index 63e5e03..47b6854 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSASDocEmitter.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSASDocEmitter.java @@ -40,6 +40,7 @@ import org.apache.flex.compiler.constants.IASLanguageConstants; import org.apache.flex.compiler.definitions.IAccessorDefinition; import org.apache.flex.compiler.definitions.IDefinition; import org.apache.flex.compiler.definitions.IPackageDefinition; +import org.apache.flex.compiler.definitions.IParameterDefinition; import org.apache.flex.compiler.definitions.metadata.IDeprecationInfo; import org.apache.flex.compiler.definitions.references.INamespaceReference; import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitter; @@ -233,6 +234,9 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit write(formatQualifiedName(node.getQualifiedName())); writeNewline("\","); indentPush(); + write(" \"baseClassname\": \""); + write(formatQualifiedName(node.getBaseClassName())); + writeNewline("\","); if (asDoc != null) writeASDoc(asDoc); final IDefinitionNode[] members = node.getAllMemberNodes(); @@ -303,6 +307,22 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit write(" \"qname\": \""); write(formatQualifiedName(node.getQualifiedName())); writeNewline("\","); + String bases[] = node.getExtendedInterfaces(); + if (bases.length > 0) + { + writeNewline(","); + writeNewline("extends: ["); + boolean firstBase = true; + for (String base : bases) + { + if (!firstBase) + writeNewline(", "); + firstBase = false; + write("\"" + base + "\""); + write(base); + } + writeNewline("]"); + } indentPush(); if (asDoc != null) writeASDoc(asDoc); @@ -509,6 +529,23 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit indentPush(); if (asDoc != null) writeASDoc(asDoc); + write(" \"return\": \""); + write(formatQualifiedName(node.getReturnType())); + writeNewline("\","); + write(" \"params\": ["); + boolean firstParam = true; + IParameterDefinition params[] = node.getDefinition().getParameters(); + for (IParameterDefinition param : params) + { + if (!firstParam) + writeNewline(","); + write("{ name: \""); + write(param.getBaseName()); + write("\", type: \""); + write(formatQualifiedName(param.getTypeAsDisplayString())); + writeNewline("\"}"); + } + write("]"); indentPop(); write("}"); addToIndex(node.getDefinition(), asDoc); @@ -634,7 +671,10 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit if (asDoc != null && asDoc.commentNoEnd().contains("@private")) return; write("{ \"qname\": \""); - write(formatQualifiedName(evt.getName())); + write(formatQualifiedName(evt.getValue("name"))); + writeNewline("\","); + write(" \"type\": \""); + write(evt.getValue("type")); writeNewline("\","); indentPush(); if (asDoc != null) http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9345ae4f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSASDocEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSASDocEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSASDocEmitter.java index 1a91e6e..9ca02e5 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSASDocEmitter.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSASDocEmitter.java @@ -30,6 +30,7 @@ import java.util.Set; import org.apache.flex.abc.semantics.Name; import org.apache.flex.abc.semantics.Namespace; import org.apache.flex.compiler.codegen.as.IASEmitter; +import org.apache.flex.compiler.codegen.js.IJSEmitter; import org.apache.flex.compiler.codegen.mxml.flexjs.IMXMLFlexJSEmitter; import org.apache.flex.compiler.definitions.IClassDefinition; import org.apache.flex.compiler.definitions.IDefinition; @@ -131,7 +132,7 @@ public class MXMLFlexJSASDocEmitter extends MXMLEmitter implements documentDefinition = cdef; // TODO (mschmalle) will remove this cast as more things get abstracted - JSFlexJSASDocEmitter fjs = (JSFlexJSASDocEmitter) ((IMXMLBlockWalker) getMXMLWalker()) + IJSEmitter fjs = (IJSEmitter) ((IMXMLBlockWalker) getMXMLWalker()) .getASEmitter(); fjs.getModel().setCurrentClass(cdef); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9345ae4f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/flexjs/MXMLFlexJSASDocDITABackend.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/flexjs/MXMLFlexJSASDocDITABackend.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/flexjs/MXMLFlexJSASDocDITABackend.java new file mode 100644 index 0000000..84ae221 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/mxml/flexjs/MXMLFlexJSASDocDITABackend.java @@ -0,0 +1,136 @@ +/* + * + * 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.driver.mxml.flexjs; + +import java.io.FilterWriter; +import java.util.List; + +import org.apache.flex.compiler.codegen.IDocEmitter; +import org.apache.flex.compiler.codegen.as.IASEmitter; +import org.apache.flex.compiler.codegen.js.IJSEmitter; +import org.apache.flex.compiler.codegen.js.IJSWriter; +import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter; +import org.apache.flex.compiler.config.Configurator; +import org.apache.flex.compiler.driver.IBackend; +import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSASDocDITAEmitter; +import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSASDocEmitter; +import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogDocEmitter; +import org.apache.flex.compiler.internal.codegen.mxml.MXMLBlockWalker; +import org.apache.flex.compiler.internal.codegen.mxml.MXMLWriter; +import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLFlexJSASDocEmitter; +import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLFlexJSBlockWalker; +import org.apache.flex.compiler.internal.driver.js.goog.ASDocConfiguration; +import org.apache.flex.compiler.internal.driver.mxml.ASDocASSourceFileHandler; +import org.apache.flex.compiler.internal.projects.ISourceFileHandler; +import org.apache.flex.compiler.internal.targets.FlexJSSWCTarget; +import org.apache.flex.compiler.internal.targets.JSTarget; +import org.apache.flex.compiler.internal.visitor.as.ASNodeSwitch; +import org.apache.flex.compiler.internal.visitor.mxml.MXMLNodeSwitch; +import org.apache.flex.compiler.problems.ICompilerProblem; +import org.apache.flex.compiler.projects.IASProject; +import org.apache.flex.compiler.targets.ITargetProgressMonitor; +import org.apache.flex.compiler.targets.ITargetSettings; +import org.apache.flex.compiler.tree.mxml.IMXMLFileNode; +import org.apache.flex.compiler.units.ICompilationUnit; +import org.apache.flex.compiler.visitor.IBlockVisitor; +import org.apache.flex.compiler.visitor.IBlockWalker; +import org.apache.flex.compiler.visitor.mxml.IMXMLBlockWalker; + +/** + * A concrete implementation of the {@link IBackend} API where the + * {@link MXMLBlockWalker} is used to traverse the {@link IMXMLFileNode} AST. + * + * @author Erik de Bruin + */ +public class MXMLFlexJSASDocDITABackend extends MXMLFlexJSSWCBackend +{ + + @Override + public Configurator createConfigurator() + { + return new Configurator(ASDocConfiguration.class); + } + + @Override + public IMXMLEmitter createMXMLEmitter(FilterWriter out) + { + return new MXMLFlexJSASDocEmitter(out); + } + + @Override + public IMXMLBlockWalker createMXMLWalker(IASProject project, + List<ICompilerProblem> errors, IMXMLEmitter mxmlEmitter, + IASEmitter asEmitter, IBlockWalker asBlockWalker) + { + MXMLBlockWalker walker = new MXMLFlexJSBlockWalker(errors, project, + mxmlEmitter, asEmitter, asBlockWalker); + + ASNodeSwitch asStrategy = new ASNodeSwitch( + (IBlockVisitor) asBlockWalker); + walker.setASStrategy(asStrategy); + + MXMLNodeSwitch mxmlStrategy = new MXMLNodeSwitch(walker); + walker.setMXMLStrategy(mxmlStrategy); + + return walker; + } + + @Override + public IDocEmitter createDocEmitter(IASEmitter emitter) + { + return new JSGoogDocEmitter((IJSEmitter) emitter); + } + + @Override + public IJSEmitter createEmitter(FilterWriter out) + { + IJSEmitter emitter = new JSFlexJSASDocDITAEmitter(out); + emitter.setDocEmitter(createDocEmitter(emitter)); + return emitter; + } + + @Override + public IJSWriter createMXMLWriter(IASProject project, + List<ICompilerProblem> problems, ICompilationUnit compilationUnit, + boolean enableDebug) + { + return new MXMLWriter(project, problems, compilationUnit, enableDebug); + } + + @Override + public JSTarget createTarget(IASProject project, ITargetSettings settings, + ITargetProgressMonitor monitor) + { + return new FlexJSSWCTarget(project, settings, monitor); + } + + @Override + public ISourceFileHandler getSourceFileHandlerInstance() + { + return ASDocASSourceFileHandler.INSTANCE; + } + + @Override + public String getOutputExtension() + { + return "xml"; + } + +}