json output
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/cd0908b6 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/cd0908b6 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/cd0908b6 Branch: refs/heads/develop Commit: cd0908b65e52bf474f59771e57b18fa6eb81a30e Parents: 87fd5e0 Author: Alex Harui <aha...@apache.org> Authored: Thu Oct 13 22:15:28 2016 -0700 Committer: Alex Harui <aha...@apache.org> Committed: Sat Oct 15 23:27:57 2016 -0700 ---------------------------------------------------------------------- .../apache/flex/compiler/clients/ASDOCJSC.java | 7 + .../js/flexjs/IJSFlexJSASDocEmitter.java | 47 +++++ .../codegen/js/flexjs/JSFlexJSASDocEmitter.java | 209 ++++++++++++++++++- .../internal/projects/FlexJSASDocProject.java | 54 +++++ 4 files changed, 316 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/cd0908b6/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 db232fa..0ba33f0 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 @@ -30,6 +30,7 @@ import java.util.List; import java.util.Set; import org.apache.commons.io.FilenameUtils; import org.apache.flex.compiler.codegen.as.IASWriter; +import org.apache.flex.compiler.codegen.js.flexjs.IJSFlexJSASDocEmitter; import org.apache.flex.compiler.driver.IBackend; import org.apache.flex.compiler.driver.js.IJSApplication; import org.apache.flex.compiler.exceptions.ConfigurationException; @@ -44,6 +45,7 @@ import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSASDocBacke 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; +import org.apache.flex.compiler.internal.projects.FlexJSASDocProject; import org.apache.flex.compiler.internal.targets.FlexJSSWCTarget; import org.apache.flex.compiler.internal.targets.JSTarget; import org.apache.flex.compiler.problems.ICompilerProblem; @@ -160,6 +162,7 @@ public class ASDOCJSC extends MXMLJSC public ASDOCJSC(IBackend backend) { super(backend); + project = new FlexJSASDocProject(workspace); } /** @@ -247,6 +250,10 @@ public class ASDOCJSC extends MXMLJSC } } compilationSuccess = true; + IJSFlexJSASDocEmitter emitter = (IJSFlexJSASDocEmitter)JSSharedData.backend.createEmitter(null); + emitter.outputIndex(outputFolder, (FlexJSASDocProject)project); + emitter.outputClasses(outputFolder, (FlexJSASDocProject)project); + emitter.outputTags(outputFolder, (FlexJSASDocProject)project); } } catch (Exception e) http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/cd0908b6/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/flexjs/IJSFlexJSASDocEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/flexjs/IJSFlexJSASDocEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/flexjs/IJSFlexJSASDocEmitter.java new file mode 100644 index 0000000..3e7f79f --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/flexjs/IJSFlexJSASDocEmitter.java @@ -0,0 +1,47 @@ +/* + * + * 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.codegen.js.flexjs; + +import java.io.File; +import java.io.IOException; + +import org.apache.flex.compiler.internal.projects.FlexJSASDocProject; + +/** + * @author Erik de Bruin + */ +public interface IJSFlexJSASDocEmitter +{ + /** + * Outputs the index. + */ + void outputIndex(File outputFolder, FlexJSASDocProject project) throws IOException; + + /** + * Outputs the class list. + */ + void outputClasses(File outputFolder, FlexJSASDocProject project) throws IOException; + + /** + * Outputs the set of asdoc tags. + */ + void outputTags(File outputFolder, FlexJSASDocProject project) throws IOException; + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/cd0908b6/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 e1b658f..63e5e03 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 @@ -19,14 +19,22 @@ 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; @@ -36,6 +44,13 @@ 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; 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; @@ -58,7 +73,7 @@ import org.apache.flex.compiler.utils.NativeUtils; * @author Michael Schmalle * @author Erik de Bruin */ -public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmitter +public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmitter, IJSFlexJSASDocEmitter { private boolean wroteSomething = false; @@ -269,6 +284,15 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit indentPop(); writeNewline("}"); + 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.getDescription()); + else + record.description = ""; + ((FlexJSASDocProject)getWalker().getProject()).classes.put(formatQualifiedName(node.getQualifiedName()), record); } @Override @@ -303,6 +327,15 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit } indentPop(); writeNewline("}"); + 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.getDescription()); + else + record.description = ""; + ((FlexJSASDocProject)getWalker().getProject()).classes.put(formatQualifiedName(node.getQualifiedName()), record); } private ArrayList<String> accessors = new ArrayList<String>(); @@ -341,6 +374,7 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit writeASDoc(asDoc); indentPop(); write("}"); + addToIndex(node.getDefinition(), asDoc); } @Override @@ -377,6 +411,7 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit writeASDoc(asDoc); indentPop(); write("}"); + addToIndex(node.getDefinition(), asDoc); } @Override @@ -397,6 +432,7 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit writeASDoc(asDoc); indentPop(); write("}"); + addToIndex(node.getDefinition(), asDoc); } @Override @@ -417,6 +453,7 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit writeASDoc(asDoc); indentPop(); write("}"); + addToIndex(node.getDefinition(), asDoc); } @Override @@ -453,6 +490,7 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit writeASDoc(asDoc); indentPop(); write("}"); + addToIndex(node.getDefinition(), asDoc); } @Override @@ -473,10 +511,13 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit writeASDoc(asDoc); indentPop(); write("}"); + addToIndex(node.getDefinition(), asDoc); } public void writeASDoc(ASDocComment asDoc) { + FlexJSASDocProject project = (FlexJSASDocProject)getWalker().getProject(); + List<String> tagList = project.tags; asDoc.compile(); write(" \"description\": \""); write(asDoc.getDescription()); @@ -497,6 +538,8 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit firstTag = false; write("{ \"tagName\": \""); write(tagName); + if (!tagList.contains(tagName)) + tagList.add(tagName); writeNewline("\","); write(" \"values\": ["); indentPush(); @@ -598,7 +641,171 @@ public class JSFlexJSASDocEmitter extends JSGoogEmitter implements IJSFlexJSEmit writeASDoc(asDoc); indentPop(); write("}"); + 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.getDescription()); + else + record.description = ""; + list.add(record); } + private String makeShortDescription(String description) + { + int c = description.indexOf("."); + if (c != -1) + return description.substring(0, c + 1); + return description; + } + + 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/cd0908b6/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSASDocProject.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSASDocProject.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSASDocProject.java new file mode 100644 index 0000000..1b619c1 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSASDocProject.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.projects; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.flex.compiler.definitions.IDefinition; +import org.apache.flex.compiler.internal.workspaces.Workspace; + +/** + * @author aharui + * + */ +public class FlexJSASDocProject extends FlexJSProject +{ + + /** + * Constructor + * + * @param workspace The {@code Workspace} containing this project. + */ + public FlexJSASDocProject(Workspace workspace) + { + super(workspace); + } + + public class ASDocRecord + { + public IDefinition definition; + public String description; + } + + public Map<String, List<ASDocRecord>> index = new HashMap<String, List<ASDocRecord>>(); + public Map<String, ASDocRecord> classes = new HashMap<String, ASDocRecord>(); + public List<String> tags = new ArrayList<String>(); +}