Repository: flex-falcon Updated Branches: refs/heads/develop 72814611d -> f3e9ac72d
FLEX-34544 first pass at adding asdoc to js debug cross-compiles Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/f3e9ac72 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/f3e9ac72 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/f3e9ac72 Branch: refs/heads/develop Commit: f3e9ac72de22621a291f35ffe741e8bb4ba59535 Parents: 7281461 Author: Alex Harui <aha...@apache.org> Authored: Fri Sep 26 20:50:13 2014 -0700 Committer: Alex Harui <aha...@apache.org> Committed: Fri Sep 26 20:52:19 2014 -0700 ---------------------------------------------------------------------- .../compiler/asdoc/flexjs/ASDocComment.java | 55 +++++++++ .../apache/flex/compiler/clients/MXMLJSC.java | 2 + .../codegen/js/flexjs/JSFlexJSDocEmitter.java | 40 +++++-- .../parsing/as/FlexJSASDocDelegate.java | 119 +++++++++++++++++++ 4 files changed, 209 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f3e9ac72/compiler.jx/src/org/apache/flex/compiler/asdoc/flexjs/ASDocComment.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/asdoc/flexjs/ASDocComment.java b/compiler.jx/src/org/apache/flex/compiler/asdoc/flexjs/ASDocComment.java new file mode 100644 index 0000000..379a4c2 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/asdoc/flexjs/ASDocComment.java @@ -0,0 +1,55 @@ +/* + * + * 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.asdoc.flexjs; + +import org.apache.flex.compiler.asdoc.IASDocComment; +import org.apache.flex.compiler.internal.codegen.js.JSDocEmitterTokens; + +import antlr.Token; + +public class ASDocComment implements IASDocComment +{ + + public ASDocComment(Token t) + { + token = t; + } + + Token token; + + public String commentNoEnd() + { + String s = token.getText(); + String[] lines = s.split("\n"); + StringBuilder sb = new StringBuilder(); + sb.append(lines[0]); + sb.append("\n"); + int n = lines.length; + for (int i = 1; i < n - 1; i++) + { + String line = lines[i]; + int star = line.indexOf("*"); + sb.append(" "); + sb.append(line.substring(star)); + sb.append("\n"); + } + return sb.toString(); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f3e9ac72/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java index 0e1c0a7..bb581ac 100644 --- a/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java +++ b/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java @@ -58,6 +58,7 @@ import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend; import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend; import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSBackend; import org.apache.flex.compiler.internal.driver.mxml.vf2js.MXMLVF2JSBackend; +import org.apache.flex.compiler.internal.parsing.as.FlexJSASDocDelegate; import org.apache.flex.compiler.internal.projects.CompilerProject; import org.apache.flex.compiler.internal.projects.FlexJSProject; import org.apache.flex.compiler.internal.projects.ISourceFileHandler; @@ -211,6 +212,7 @@ public class MXMLJSC { JSSharedData.backend = backend; workspace = new Workspace(); + workspace.setASDocDelegate(new FlexJSASDocDelegate()); project = new FlexJSProject(workspace); problems = new ProblemQuery(); JSSharedData.OUTPUT_EXTENSION = backend.getOutputExtension(); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f3e9ac72/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java index 8571846..bc17444 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java @@ -19,6 +19,7 @@ package org.apache.flex.compiler.internal.codegen.js.flexjs; +import org.apache.flex.compiler.asdoc.flexjs.ASDocComment; import org.apache.flex.compiler.codegen.js.IJSEmitter; import org.apache.flex.compiler.common.ASModifier; import org.apache.flex.compiler.common.DependencyType; @@ -52,13 +53,18 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter { IClassDefinition classDefinition = resolveClassDefinition(node); + ASDocComment asDoc = (ASDocComment) node.getASDocComment(); + if (node instanceof IFunctionNode) { boolean hasDoc = false; if (node.isConstructor()) { - begin(); + if (asDoc != null) + write(asDoc.commentNoEnd()); + else + begin(); hasDoc = true; emitJSDocLine(JSEmitterTokens.CONSTRUCTOR); @@ -88,7 +94,10 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter String ns = node.getNamespace(); if (ns != null) { - begin(); + if (asDoc != null) + write(asDoc.commentNoEnd()); + else + begin(); emitMethodAccess(node); hasDoc = true; } @@ -100,7 +109,10 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter { if (!hasDoc) { - begin(); + if (asDoc != null) + write(asDoc.commentNoEnd()); + else + begin(); emitMethodAccess(node); hasDoc = true; } @@ -124,7 +136,10 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter { if (!hasDoc) { - begin(); + if (asDoc != null) + write(asDoc.commentNoEnd()); + else + begin(); emitMethodAccess(node); hasDoc = true; } @@ -147,7 +162,10 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter { if (!hasDoc) { - begin(); + if (asDoc != null) + write(asDoc.commentNoEnd()); + else + begin(); emitMethodAccess(node); hasDoc = true; } @@ -165,11 +183,16 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter { boolean hasDoc = false; + ASDocComment asDoc = (ASDocComment) ((IFunctionNode) node).getASDocComment(); + String returnType = ((IFunctionNode) node).getReturnType(); if (returnType != "" && returnType != ASEmitterTokens.VOID.getToken()) // has return { - begin(); + if (asDoc != null) + write(asDoc.commentNoEnd()); + else + begin(); hasDoc = true; ITypeDefinition tdef = ((IFunctionDefinition)node.getDefinition()) @@ -183,7 +206,10 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter { if (!hasDoc) { - begin(); + if (asDoc != null) + write(asDoc.commentNoEnd()); + else + begin(); hasDoc = true; } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f3e9ac72/compiler.jx/src/org/apache/flex/compiler/internal/parsing/as/FlexJSASDocDelegate.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/parsing/as/FlexJSASDocDelegate.java b/compiler.jx/src/org/apache/flex/compiler/internal/parsing/as/FlexJSASDocDelegate.java new file mode 100644 index 0000000..c2fd2aa --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/parsing/as/FlexJSASDocDelegate.java @@ -0,0 +1,119 @@ +package org.apache.flex.compiler.internal.parsing.as; + + + + +import antlr.Token; + +import org.apache.flex.compiler.asdoc.IASDocComment; +import org.apache.flex.compiler.asdoc.IASDocDelegate; +import org.apache.flex.compiler.asdoc.IASParserASDocDelegate; +import org.apache.flex.compiler.asdoc.IMetadataParserASDocDelegate; +import org.apache.flex.compiler.asdoc.IPackageDITAParser; +import org.apache.flex.compiler.asdoc.flexjs.ASDocComment; +import org.apache.flex.compiler.common.ISourceLocation; +import org.apache.flex.compiler.definitions.IDocumentableDefinition; +import org.apache.flex.compiler.tree.as.IDocumentableDefinitionNode; + +/** + * Default implementation of {@link IASDocDelegate} that does not have any code + * model or eclipse dependencies. + */ +public final class FlexJSASDocDelegate implements IASDocDelegate +{ + private static final FlexJSASDocDelegate INSTANCE = new FlexJSASDocDelegate(); + + /** + * Gets the single instance of this delegate. + * + * @return The single instance of this delegate. + */ + public static IASDocDelegate get() + { + return INSTANCE; + } + + public FlexJSASDocDelegate() + { + } + + @Override + public IASParserASDocDelegate getASParserASDocDelegate() + { + return ASDelegate.INSTANCE; + } + + @Override + public IASDocComment createASDocComment(ISourceLocation location, IDocumentableDefinition definition) + { + return null; + } + + @Override + public IPackageDITAParser getPackageDitaParser() + { + return IPackageDITAParser.NIL_PARSER; + } + + private static final class ASDelegate implements IASParserASDocDelegate + { + static final ASDelegate INSTANCE = new ASDelegate(); + + @Override + public void beforeVariable() + { + } + + @Override + public void afterVariable() + { + } + + Token currentToken; + + @Override + public void setCurrentASDocToken(Token asDocToken) + { + currentToken = asDocToken; + } + + @Override + public IASDocComment afterDefinition(IDocumentableDefinitionNode definitionNode) + { + return new ASDocComment(currentToken); + } + + @Override + public IMetadataParserASDocDelegate getMetadataParserASDocDelegate() + { + return MetadataDelegate.INSTANCE; + } + + } + + private static final class MetadataDelegate implements IMetadataParserASDocDelegate + { + static final MetadataDelegate INSTANCE = new MetadataDelegate(); + + @Override + public void setCurrentASDocToken(Token asDocToken) + { + } + + @Override + public IASDocComment afterDefinition(IDocumentableDefinitionNode definitionNode) + { + return null; + } + + @Override + public void clearMetadataComment(String metaDataTagName) + { + } + + @Override + public void afterMetadata(int metaDataEndOffset) + { + } + } +}