http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java new file mode 100644 index 0000000..9576e24 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java @@ -0,0 +1,187 @@ +/* + * + * 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.visitor.mxml; + +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode; +import org.apache.flex.compiler.tree.mxml.IMXMLBindingNode; +import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode; +import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDataBindingNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDeclarationsNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDeferredInstanceNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode; +import org.apache.flex.compiler.tree.mxml.IMXMLEmbedNode; +import org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode; +import org.apache.flex.compiler.tree.mxml.IMXMLFactoryNode; +import org.apache.flex.compiler.tree.mxml.IMXMLFileNode; +import org.apache.flex.compiler.tree.mxml.IMXMLImplementsNode; +import org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode; +import org.apache.flex.compiler.tree.mxml.IMXMLIntNode; +import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode; +import org.apache.flex.compiler.tree.mxml.IMXMLMetadataNode; +import org.apache.flex.compiler.tree.mxml.IMXMLNumberNode; +import org.apache.flex.compiler.tree.mxml.IMXMLObjectNode; +import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode; +import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode; +import org.apache.flex.compiler.tree.mxml.IMXMLStringNode; +import org.apache.flex.compiler.tree.mxml.IMXMLStyleNode; +import org.apache.flex.compiler.tree.mxml.IMXMLStyleSpecifierNode; +import org.apache.flex.compiler.tree.mxml.IMXMLUintNode; +import org.apache.flex.compiler.tree.mxml.IMXMLVectorNode; +import org.apache.flex.compiler.visitor.IASNodeStrategy; +import org.apache.flex.compiler.visitor.IBlockVisitor; +import org.apache.flex.compiler.visitor.mxml.IMXMLBlockVisitor; + +/** + * @author Michael Schmalle + * @author Erik de Bruin + */ +public class MXMLNodeSwitch implements IASNodeStrategy +{ + private final IMXMLBlockVisitor visitor; + + public MXMLNodeSwitch(IBlockVisitor visitor) + { + this.visitor = (IMXMLBlockVisitor) visitor; + } + + @Override + public void handle(IASNode node) + { + switch (node.getNodeID()) + { + case MXMLArrayID: + visitor.visitArray((IMXMLArrayNode) node); + break; + case MXMLBooleanID: + visitor.visitBoolean((IMXMLBooleanNode) node); + break; + case MXMLDeclarationsID: + visitor.visitDeclarations((IMXMLDeclarationsNode) node); + break; + case MXMLDeferredInstanceID: + visitor.visitDeferredInstance((IMXMLDeferredInstanceNode) node); + break; + case MXMLDocumentID: + visitor.visitDocument((IMXMLDocumentNode) node); + break; + case MXMLEventSpecifierID: + visitor.visitEventSpecifier((IMXMLEventSpecifierNode) node); + break; + case MXMLFileID: + visitor.visitFile((IMXMLFileNode) node); + break; + case MXMLIntID: + visitor.visitInt((IMXMLIntNode) node); + break; + case MXMLInstanceID: + visitor.visitInstance((IMXMLInstanceNode) node); + break; + case MXMLLiteralID: + visitor.visitLiteral((IMXMLLiteralNode) node); + break; + case MXMLNumberID: + visitor.visitNumber((IMXMLNumberNode) node); + break; + case MXMLPropertySpecifierID: + visitor.visitPropertySpecifier((IMXMLPropertySpecifierNode) node); + break; + case MXMLScriptID: + visitor.visitScript((IMXMLScriptNode) node); + break; + case MXMLStringID: + visitor.visitString((IMXMLStringNode) node); + break; + case MXMLStyleSpecifierID: + visitor.visitStyleSpecifier((IMXMLStyleSpecifierNode) node); + break; + case MXMLUintID: + visitor.visitUint((IMXMLUintNode) node); + break; + case MXMLStyleID: + visitor.visitStyleBlock((IMXMLStyleNode)node); + break; + case MXMLStateID: + visitor.visitInstance((IMXMLInstanceNode) node); + break; + case MXMLFactoryID: + visitor.visitFactory((IMXMLFactoryNode) node); + break; + case MXMLComponentID: + visitor.visitComponent((IMXMLComponentNode) node); + break; + case MXMLMetadataID: + visitor.visitMetadata((IMXMLMetadataNode) node); + break; + case MXMLEmbedID: + visitor.visitEmbed((IMXMLEmbedNode) node); + break; + case MXMLImplementsID: + visitor.visitImplements((IMXMLImplementsNode) node); + break; + case MXMLVectorID: + visitor.visitVector((IMXMLVectorNode) node); + break; + case MXMLDataBindingID: + visitor.visitDatabinding((IMXMLDataBindingNode) node); + break; + case MXMLBindingID: + visitor.visitBinding((IMXMLBindingNode) node); + break; + case MXMLObjectID: + visitor.visitObject((IMXMLObjectNode) node); + break; + case MXMLApplicationID: + case MXMLBindingAttributeID: + case MXMLClassID: + case MXMLClassDefinitionID: + case MXMLClearID: + case MXMLConcatenatedDataBindingID: + case MXMLDateID: + case MXMLDefinitionID: + case MXMLDesignLayerID: + case MXMLEffectSpecifierID: + case MXMLFunctionID: + case MXMLHTTPServiceID: + case MXMLHTTPServiceRequestID: + case MXMLLibraryID: + case MXMLModelID: + case MXMLModelPropertyID: + case MXMLModelRootID: + case MXMLPrivateID: + case MXMLRegExpID: + case MXMLRemoteObjectID: + case MXMLRemoteObjectMethodID: + case MXMLReparentID: + //case MXMLRepeaterID: + case MXMLResourceID: + case MXMLWebServiceID: + case MXMLWebServiceOperationID: + case MXMLXMLID: + case MXMLXMLListID: + default: + throw new IllegalArgumentException( + "No handler specified for nodes of type '" + + node.getNodeID().getParaphrase() + "'"); + } + } + +}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/problems/UnsupportedLanguageFeatureProblem.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/problems/UnsupportedLanguageFeatureProblem.java b/compiler-jx/src/main/java/org/apache/flex/compiler/problems/UnsupportedLanguageFeatureProblem.java new file mode 100644 index 0000000..fbd55cd --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/problems/UnsupportedLanguageFeatureProblem.java @@ -0,0 +1,37 @@ +/* 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.problems; + +import org.apache.flex.compiler.common.ISourceLocation; +import org.apache.flex.compiler.problems.annotations.ProblemClassification; + +@ProblemClassification(CompilerProblemClassification.SYNTAX_ERROR) +public class UnsupportedLanguageFeatureProblem extends CodegenProblem +{ + + public static final String DESCRIPTION = + "'${tokenText}' cannot be cross-compiled."; + + public UnsupportedLanguageFeatureProblem(ISourceLocation site, String text) + { + super(site); + tokenText = text; + } + + public final String tokenText; +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/targets/IJSTarget.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/targets/IJSTarget.java b/compiler-jx/src/main/java/org/apache/flex/compiler/targets/IJSTarget.java new file mode 100644 index 0000000..1fb4508 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/targets/IJSTarget.java @@ -0,0 +1,52 @@ +/* + * + * 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.targets; + +import java.util.Collection; + +import org.apache.flex.compiler.clients.JSConfiguration; +import org.apache.flex.compiler.driver.IBackend; +import org.apache.flex.compiler.driver.js.IJSApplication; +import org.apache.flex.compiler.problems.ICompilerProblem; +import org.apache.flex.compiler.projects.IASProject; + +/** + * The {@link IJSTarget} interface allows the compiler an abstraction to + * <em>how</em> the actual JavaScript is built. + * <p> + * The interface ties into the {@link IBackend} and is created at the start of + * compile before the {@link JSConfiguration} class is configured. + * + * @author Michael Schmalle + * + * @see IBackend#createJSTarget(IASProject, ITargetSettings, + * ITargetProgressMonitor) + */ +public interface IJSTarget extends ITarget +{ + /** + * Build the target JavaScript application and collect problems. Every time + * the method is called, a new {@link IJSApplication} model is created. + * + * @param problems compilation problems output + * @return IJSApplication if build is a success. + */ + IJSApplication build(Collection<ICompilerProblem> problems); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/utils/ASNodeUtils.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/ASNodeUtils.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/ASNodeUtils.java new file mode 100644 index 0000000..b7c524e --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/ASNodeUtils.java @@ -0,0 +1,93 @@ +/* + * + * 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.utils; + +import java.util.ArrayList; + +import org.apache.flex.compiler.tree.ASTNodeID; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IBlockNode; +import org.apache.flex.compiler.tree.as.IConditionalNode; +import org.apache.flex.compiler.tree.as.IExpressionNode; +import org.apache.flex.compiler.tree.as.IOperatorNode; +import org.apache.flex.compiler.tree.as.ISwitchNode; +import org.apache.flex.compiler.tree.as.ITerminalNode; + +/** + * @author Michael Schmalle + */ +public class ASNodeUtils +{ + //-------------------------------------------------------------------------- + // Temp: These need JIRA tickets + //-------------------------------------------------------------------------- + + // there seems to be a bug in the ISwitchNode.getCaseNodes(), need to file a bug + public static final IConditionalNode[] getCaseNodes(ISwitchNode node) + { + IBlockNode block = (IBlockNode) node.getChild(1); + int childCount = block.getChildCount(); + ArrayList<IConditionalNode> retVal = new ArrayList<IConditionalNode>( + childCount); + + for (int i = 0; i < childCount; i++) + { + IASNode child = block.getChild(i); + if (child instanceof IConditionalNode) + retVal.add((IConditionalNode) child); + } + + return retVal.toArray(new IConditionalNode[0]); + } + + // there seems to be a bug in the ISwitchNode.getDefaultNode(), need to file a bug + public static final ITerminalNode getDefaultNode(ISwitchNode node) + { + IBlockNode block = (IBlockNode) node.getChild(1); + int childCount = block.getChildCount(); + for (int i = childCount - 1; i >= 0; i--) + { + IASNode child = block.getChild(i); + if (child instanceof ITerminalNode) + return (ITerminalNode) child; + } + + return null; + } + + public static boolean hasParenOpen(IOperatorNode node) + { + return node.hasParenthesis(); + //return node.getParent() instanceof IBinaryOperatorNode + // && !ASNodeUtils.isString(node.getRightOperandNode()); + } + + public static boolean hasParenClose(IOperatorNode node) + { + return node.hasParenthesis(); + //return node.getParent() instanceof IBinaryOperatorNode + // && !ASNodeUtils.isString(node.getRightOperandNode()); + } + + public static boolean isString(IExpressionNode node) + { + return node.getNodeID() == ASTNodeID.LiteralStringID; + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/utils/DefinitionUtils.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/DefinitionUtils.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/DefinitionUtils.java new file mode 100644 index 0000000..f13c427 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/DefinitionUtils.java @@ -0,0 +1,37 @@ +/* + * + * 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.utils; + +import org.apache.flex.compiler.definitions.IClassDefinition; +import org.apache.flex.compiler.definitions.IDefinition; +import org.apache.flex.compiler.definitions.IInterfaceDefinition; + +/** + * @author Michael Schmalle + */ +public class DefinitionUtils +{ + public static final boolean isMemberDefinition(IDefinition definition) + { + return definition != null + && (definition.getParent() instanceof IClassDefinition || definition + .getParent() instanceof IInterfaceDefinition); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerUtil.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerUtil.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerUtil.java new file mode 100644 index 0000000..cab0752 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerUtil.java @@ -0,0 +1,98 @@ +/* + * + * 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.utils; + +import java.security.Permission; + +import com.google.javascript.jscomp.CommandLineRunner; + +public class JSClosureCompilerUtil +{ + + public static void run(String[] options) + { + forbidSystemExitCall(); + try + { + JSClosureCommandLineRunner.main(options); + } + catch (ExitTrappedException e) + { + // (erikdebruin) the CLR issued an System.Exit(), but we have + // denied the request ;-) + } + finally + { + enableSystemExitCall(); + } + } + + private static class JSClosureCommandLineRunner extends CommandLineRunner + { + JSClosureCommandLineRunner(String[] args) + { + super(args); + } + + public static void main(String[] args) + { + JSClosureCommandLineRunner runner = new JSClosureCommandLineRunner( + args); + + if (runner.shouldRunCompiler()) + { + runner.run(); + } + else + { + System.exit(-1); + } + } + } + + private static class ExitTrappedException extends SecurityException + { + private static final long serialVersionUID = 666; + } + + private static void forbidSystemExitCall() + { + final SecurityManager securityManager = new SecurityManager() { + @Override + public void checkPermission(Permission permission) + { + } + + @Override + public void checkExit(int status) + { + throw new ExitTrappedException(); + } + }; + + System.setSecurityManager(securityManager); + } + + private static void enableSystemExitCall() + { + System.setSecurityManager(null); + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java new file mode 100644 index 0000000..4008b01 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java @@ -0,0 +1,305 @@ +/* + * + * 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.utils; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; + +import com.google.javascript.jscomp.CheckLevel; +import com.google.javascript.jscomp.CommandLineRunner; +import com.google.javascript.jscomp.CompilationLevel; +import com.google.javascript.jscomp.Compiler; +import com.google.javascript.jscomp.CompilerOptions; +import com.google.javascript.jscomp.CompilerOptions.LanguageMode; +import com.google.javascript.jscomp.DependencyOptions; +import com.google.javascript.jscomp.DiagnosticGroups; +import com.google.javascript.jscomp.FlexJSDiagnosticGroups; +import com.google.javascript.jscomp.SourceFile; +import com.google.javascript.jscomp.SourceMap; +import com.google.javascript.jscomp.WarningLevel; + +public class JSClosureCompilerWrapper +{ + + public JSClosureCompilerWrapper(List<String> args) + { + Compiler.setLoggingLevel(Level.INFO); + + compiler_ = new Compiler(); + + ArrayList<String> splitArgs = new ArrayList<String>(); + for (String s : args) + { + if (s.contains(" ")) + { + String[] parts = s.split(" "); + for (String part : parts) + splitArgs.add(part); + } + else + splitArgs.add(s); + } + String[] stringArgs = new String[splitArgs.size()]; + splitArgs.toArray(stringArgs); + options_ = new CompilerOptionsParser(stringArgs).getOptions(); + + jsSourceFiles_ = new ArrayList<SourceFile>(); + jsExternsFiles_ = new ArrayList<SourceFile>(); + + initOptions(args); + initExterns(); + + } + + private Compiler compiler_; + private CompilerOptions options_; + private List<SourceFile> jsExternsFiles_; + private List<SourceFile> jsSourceFiles_; + + public String targetFilePath; + + public void addJSExternsFile(String fileName) + { + addJSExternsFile(SourceFile.fromFile(fileName)); + } + + public void addJSExternsFile(SourceFile file) + { + jsExternsFiles_.add(file); + } + + public void addJSSourceFile(String fileName) + { + jsSourceFiles_.add(SourceFile.fromFile(fileName)); + } + + public void compile() + { + compiler_.compile(jsExternsFiles_, jsSourceFiles_, options_); + + try + { + FileWriter targetFile = new FileWriter(targetFilePath); + targetFile.write(compiler_.toSource()); + targetFile.close(); + + FileWriter sourceMapFile = new FileWriter(options_.sourceMapOutputPath); + compiler_.getSourceMap().appendTo(sourceMapFile, ""); + sourceMapFile.close(); + } + catch (IOException error) + { + System.out.println(error); + } + + /* + for (JSError message : compiler_.getWarnings()) + { + System.err.println("Warning message: " + message.toString()); + } + + for (JSError message : compiler_.getErrors()) + { + System.err.println("Error message: " + message.toString()); + } + */ + } + + @SuppressWarnings( "deprecation" ) + private void initExterns() + { + try + { + List<SourceFile> defaultExterns = CommandLineRunner.getDefaultExterns(); + for (SourceFile defaultExtern : defaultExterns) + { + this.addJSExternsFile(defaultExtern); + } + } + catch (IOException error) + { + System.out.println(error); + } + } + + private void initOptions(List<String> args) + { + final String JS_FLAG = "--js "; + + boolean hasCompilationLevel = false; + boolean hasWarningLevel = false; + for (String s : args) + { + if (s.startsWith(JS_FLAG)) + addJSSourceFile(s.substring(JS_FLAG.length())); + + if (s.startsWith("--compilation_level ") || + s.startsWith("-O ")) + hasCompilationLevel = true; + + if (s.startsWith("--warning_level ") || + s.startsWith("-W ")) + hasWarningLevel = true; + } + if (!hasCompilationLevel) + CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel( + options_); + + if (!hasWarningLevel) + WarningLevel.VERBOSE.setOptionsForWarningLevel(options_); + + String[] asdocTags = new String[] {"productversion", + "playerversion", "langversion", "copy", + "asparam", "asreturn", "asprivate", + "flexjsignoreimport", "flexjsignorecoercion"}; + options_.setExtraAnnotationNames(Arrays.asList(asdocTags)); + } + + public void setOptions(String sourceMapPath, boolean useStrictPublishing, String projectName) + { + if (useStrictPublishing) + { + // (erikdebruin) set compiler flags to 'strictest' to allow maximum + // code optimization + + options_.setDefineToBooleanLiteral("goog.DEBUG", true); + + // ToDo (erikdebruin): re-evaluate this option on future GC release + options_.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT); + + options_.setPreferSingleQuotes(true); + + options_.setFoldConstants(true); + options_.setDeadAssignmentElimination(true); + options_.setInlineConstantVars(true); + options_.setInlineFunctions(true); + options_.setInlineLocalFunctions(true); + options_.setCrossModuleCodeMotion(true); + options_.setCoalesceVariableNames(true); + options_.setCrossModuleMethodMotion(true); + options_.setInlineGetters(true); + options_.setInlineVariables(true); + options_.setSmartNameRemoval(true); + options_.setRemoveDeadCode(true); + options_.setCheckMissingReturn(CheckLevel.WARNING); + options_.setExtractPrototypeMemberDeclarations(true); + options_.setRemoveUnusedPrototypeProperties(true); + options_.setRemoveUnusedPrototypePropertiesInExterns(false); + options_.setRemoveUnusedClassProperties(true); + options_.setRemoveUnusedVars(true); + options_.setRemoveUnusedLocalVars(true); + options_.setCollapseVariableDeclarations(true); + options_.setCollapseAnonymousFunctions(true); + options_.setAliasAllStrings(true); + options_.setConvertToDottedProperties(true); + options_.setRewriteFunctionExpressions(true); + options_.setOptimizeParameters(true); + options_.setOptimizeReturns(true); + options_.setOptimizeCalls(true); + options_.setOptimizeArgumentsArray(true); + options_.setGenerateExports(true); + options_.setExportLocalPropertyDefinitions(true); + + DependencyOptions dopts = new DependencyOptions(); + ArrayList<String> entryPoints = new ArrayList<String>(); + entryPoints.add(projectName); + dopts.setDependencyPruning(true) + .setDependencySorting(true) + .setMoocherDropping(true) + .setEntryPoints(entryPoints); + options_.setDependencyOptions(dopts); + + // warnings already activated in previous incarnation + options_.setWarningLevel(DiagnosticGroups.ACCESS_CONTROLS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CONST, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CONSTANT_PROPERTY, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.STRICT_MODULE_DEP_CHECK, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.VISIBILITY, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.DEPRECATED, CheckLevel.OFF); // OFF + + // the 'full' set of warnings + options_.setWarningLevel(DiagnosticGroups.AMBIGUOUS_FUNCTION_DECL, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_EVENTFUL_OBJECT_DISPOSAL, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_REGEXP, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_USELESS_CODE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.DEBUGGER_STATEMENT_PRESENT, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.DUPLICATE_MESSAGE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.DUPLICATE_VARS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.ES3, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.ES5_STRICT, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.EXTERNS_VALIDATION, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.GLOBAL_THIS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.FILEOVERVIEW_JSDOC, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.INTERNET_EXPLORER_CHECKS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.INVALID_CASTS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.OFF); // OFF + options_.setWarningLevel(DiagnosticGroups.MISPLACED_TYPE_ANNOTATION, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_PROPERTIES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_REQUIRE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_RETURN, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.NEW_CHECK_TYPES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.NON_STANDARD_JSDOC, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.REPORT_UNKNOWN_TYPES, CheckLevel.OFF); // OFF + options_.setWarningLevel(DiagnosticGroups.SUSPICIOUS_CODE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.TWEAKS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.TYPE_INVALIDATION, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.UNDEFINED_NAMES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.UNDEFINED_VARIABLES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.UNKNOWN_DEFINES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.UNNECESSARY_CASTS, CheckLevel.OFF); // OFF + options_.setWarningLevel(DiagnosticGroups.USE_OF_GOOG_BASE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.VIOLATED_MODULE_DEP, CheckLevel.WARNING); + + // TODO (erikdebruin) Need to figure out how we can replace @expose + options_.setWarningLevel(DiagnosticGroups.DEPRECATED_ANNOTATIONS, CheckLevel.OFF); + + // create custom DiagnosticGroups to shut off some individual warnings when we + // still want warnings for others in the group. + options_.setWarningLevel(FlexJSDiagnosticGroups.FLEXJS_NOT_A_CONSTRUCTOR, CheckLevel.OFF); + options_.setWarningLevel(FlexJSDiagnosticGroups.FLEXJS_SUPER_CALL_TO_DIFFERENT_NAME, CheckLevel.OFF); + options_.setWarningLevel(FlexJSDiagnosticGroups.FLEXJS_UNKNOWN_JSDOC_TYPE_NAME, CheckLevel.OFF); +// options_.setWarningLevel(FlexJSDiagnosticGroups.FLEXJS_REFERENCE_BEFORE_DECLARE, CheckLevel.OFF); + } + + options_.sourceMapFormat = SourceMap.Format.V3; + options_.sourceMapOutputPath = sourceMapPath + ".map"; + } + + private static class CompilerOptionsParser extends CommandLineRunner + { + public CompilerOptionsParser(String[] args) + { + super(args); + } + + public CompilerOptions getOptions() + { + return createOptions(); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/utils/NativeUtils.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/NativeUtils.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/NativeUtils.java new file mode 100644 index 0000000..9ea630b --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/NativeUtils.java @@ -0,0 +1,161 @@ +/* + * + * 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.utils; + +/** + * @author Michael Schmalle + */ +public class NativeUtils +{ + public enum NativeASType + { + Any("*"), // not JS but use full in the context of native + + Argument("Argument"), + Array("Array"), + Boolean("Boolean"), + Class("Class"), + Date("Date"), + Error("Error"), + EvalError("EvalError"), + Function("Function"), + Infinity("Infinity"), + Math("Math"), + JSON("JSON"), + NaN("NaN"), + Namespace("Namespace"), + Number("Number"), + Object("Object"), + QName("QName"), + RangeError("RangeError"), + ReferenceError("ReferenceError"), + RegExp("RegExp"), + String("String"), + SyntaxError("SyntaxError"), + TypeError("TypeError"), + URIError("URIError"), + Vector("Vector"), + XML("XML"), + XMLList("XMLList"), + _assert("assert"), + decodeURI("decodeURI"), + decodeURIComponent("decodeURIComponent"), + encodeURI("encodeURI"), + encodeURIComponent("encodeURIComponent"), + escape("escape"), + _int("int"), + isFinite("isFinite"), + isNaN("isNaN"), + isXMLName("isXMLName"), + parseFloat("parseFloat"), + parseInt("parseInt"), + trace("trace"), + uint("uint"), + undefined("undefined"), + unescape("unescape"); + + private final String value; + + NativeASType(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } + } + + public enum NativeJSType + { + // (erikdebruin) Ref.: https://cwiki.apache.org/confluence/display/FLEX/Full+Table + + Array("Array"), + Boolean("Boolean"), + decodeURI("decodeURI"), + decodeURIComponent("decodeURIComponent"), + encodeURI("encodeURI"), + encodeURIComponent("encodeURIComponent"), + escape("escape"), + isFinite("isFinite"), + isNaN("isNaN"), + Number("Number"), + Object("Object"), + parseFloat("parseFloat"), + parseInt("parseInt"), + String("String"), + unescape("unescape"), + + // (erikdebruin) These aren't strictly 'native' to JS, but the + // Publisher provides global functions, so, for all + // intends and purposes they behave like they are. + _int("int"), + trace("trace"), + uint("uint"), + + // (erikdebruin) These are left out, but should, at some point, be + // treated as if they actually are 'native'. + /* + isXMLName("isXMLName"), + Vector("Vector"), + XML("XML"), + XMLList("XMLList"), + */ + + _byte("byte"), + + ; + private final String value; + + NativeJSType(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } + } + + public static boolean isNative(String type) + { + for (NativeASType test : NativeASType.values()) + { + if (test.getValue().equals(type)) + return true; + } + if (type.startsWith("Vector.<")) + return true; + return false; + } + + public static boolean isJSNative(String type) + { + for (NativeJSType test : NativeJSType.values()) + { + if (test.getValue().equals(type)) + return true; + } + return false; + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSClosureCompilerWrapper.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSClosureCompilerWrapper.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSClosureCompilerWrapper.java new file mode 100644 index 0000000..f1240e4 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSClosureCompilerWrapper.java @@ -0,0 +1,224 @@ +/* + * + * 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.utils; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; + +import com.google.javascript.jscomp.CheckLevel; +import com.google.javascript.jscomp.CommandLineRunner; +import com.google.javascript.jscomp.CompilationLevel; +import com.google.javascript.jscomp.Compiler; +import com.google.javascript.jscomp.CompilerOptions; +import com.google.javascript.jscomp.DiagnosticGroups; +import com.google.javascript.jscomp.SourceFile; +import com.google.javascript.jscomp.SourceMap; +import com.google.javascript.jscomp.WarningLevel; +import com.google.javascript.rhino.Node; +import com.google.javascript.rhino.Token; + +public class VF2JSClosureCompilerWrapper +{ + + public VF2JSClosureCompilerWrapper() + { + Compiler.setLoggingLevel(Level.ALL); + + compiler_ = new Compiler(); + + options_ = new CompilerOptions(); + initOptions(); + + jsExternsFiles_ = new ArrayList<SourceFile>(); + initExterns(); + + jsSourceFiles_ = new ArrayList<SourceFile>(); + } + + private Compiler compiler_; + private CompilerOptions options_; + private List<SourceFile> jsExternsFiles_; + private List<SourceFile> jsSourceFiles_; + + public String targetFilePath; + + public void addJSExternsFile(String fileName) + { + addJSExternsFile(SourceFile.fromFile(fileName)); + } + + public void addJSExternsFile(SourceFile file) + { + jsExternsFiles_.add(file); + } + + public void addJSSourceFile(String fileName) + { + jsSourceFiles_.add(SourceFile.fromFile(fileName)); + } + + public void compile() + { + compiler_.compile(jsExternsFiles_, jsSourceFiles_, options_); + + try + { + FileWriter targetFile = new FileWriter(targetFilePath); + targetFile.write(compiler_.toSource()); + targetFile.close(); + + FileWriter sourceMapFile = new FileWriter(options_.sourceMapOutputPath); + compiler_.getSourceMap().appendTo(sourceMapFile, ""); + sourceMapFile.close(); + } + catch (IOException error) + { + System.out.println(error); + } + } + + @SuppressWarnings( "deprecation" ) + private void initExterns() + { + try + { + List<SourceFile> defaultExterns = CommandLineRunner.getDefaultExterns(); + for (SourceFile defaultExtern : defaultExterns) + { + this.addJSExternsFile(defaultExtern); + } + } + catch (IOException error) + { + System.out.println(error); + } + } + + private void initOptions() + { + CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel( + options_); + + WarningLevel.VERBOSE.setOptionsForWarningLevel(options_); + + String[] asdocTags = new String[] {"productversion", + "playerversion", "langversion", "copy"}; + options_.setExtraAnnotationNames(Arrays.asList(asdocTags)); + } + + public void setOptions(String sourceMapPath, boolean useStrictPublishing) + { + if (useStrictPublishing) + { + // (erikdebruin) set compiler flags to 'strictest' to allow maximum + // code optimization + + options_.getDefineReplacements().put( + "goog.DEBUG", new Node(Token.TRUE)); + + // ToDo (erikdebruin): re-evaluate this option on future GC release + //options_.setLanguageIn(LanguageMode.ECMASCRIPT6_STRICT); + + options_.setPreferSingleQuotes(true); + + options_.setFoldConstants(true); + options_.setDeadAssignmentElimination(true); + options_.setInlineConstantVars(true); + options_.setInlineFunctions(true); + options_.setInlineLocalFunctions(true); + options_.setCrossModuleCodeMotion(true); + options_.setCoalesceVariableNames(true); + options_.setCrossModuleMethodMotion(true); + options_.setInlineGetters(true); + options_.setInlineVariables(true); + options_.setSmartNameRemoval(true); + options_.setRemoveDeadCode(true); + options_.setCheckMissingReturn(CheckLevel.WARNING); + options_.setExtractPrototypeMemberDeclarations(true); + options_.setRemoveUnusedPrototypeProperties(true); + options_.setRemoveUnusedPrototypePropertiesInExterns(true); + options_.setRemoveUnusedClassProperties(true); + options_.setRemoveUnusedVars(true); + options_.setRemoveUnusedLocalVars(true); + options_.setCollapseVariableDeclarations(true); + options_.setCollapseAnonymousFunctions(true); + options_.setAliasAllStrings(true); + options_.setConvertToDottedProperties(true); + options_.setRewriteFunctionExpressions(true); + options_.setOptimizeParameters(true); + options_.setOptimizeReturns(true); + options_.setOptimizeCalls(true); + options_.setOptimizeArgumentsArray(true); + + // warnings already activated in previous incarnation + options_.setWarningLevel(DiagnosticGroups.ACCESS_CONTROLS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CONST, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CONSTANT_PROPERTY, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.STRICT_MODULE_DEP_CHECK, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.VISIBILITY, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.DEPRECATED, CheckLevel.OFF); // OFF + + // the 'full' set of warnings + options_.setWarningLevel(DiagnosticGroups.AMBIGUOUS_FUNCTION_DECL, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_EVENTFUL_OBJECT_DISPOSAL, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_REGEXP, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_USELESS_CODE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.DEBUGGER_STATEMENT_PRESENT, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.DUPLICATE_MESSAGE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.DUPLICATE_VARS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.ES3, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.ES5_STRICT, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.EXTERNS_VALIDATION, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.GLOBAL_THIS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.FILEOVERVIEW_JSDOC, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.INTERNET_EXPLORER_CHECKS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.INVALID_CASTS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.OFF); // OFF + options_.setWarningLevel(DiagnosticGroups.MISPLACED_TYPE_ANNOTATION, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_PROPERTIES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_REQUIRE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.MISSING_RETURN, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.NEW_CHECK_TYPES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.NON_STANDARD_JSDOC, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.REPORT_UNKNOWN_TYPES, CheckLevel.OFF); // OFF + options_.setWarningLevel(DiagnosticGroups.SUSPICIOUS_CODE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.TWEAKS, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.TYPE_INVALIDATION, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.UNDEFINED_NAMES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.UNDEFINED_VARIABLES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.UNKNOWN_DEFINES, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.UNNECESSARY_CASTS, CheckLevel.OFF); // OFF + options_.setWarningLevel(DiagnosticGroups.USE_OF_GOOG_BASE, CheckLevel.WARNING); + options_.setWarningLevel(DiagnosticGroups.VIOLATED_MODULE_DEP, CheckLevel.WARNING); + } + + options_.sourceMapFormat = SourceMap.Format.V3; + options_.sourceMapOutputPath = sourceMapPath + ".map"; + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSProjectUtils.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSProjectUtils.java b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSProjectUtils.java new file mode 100644 index 0000000..0542097 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/VF2JSProjectUtils.java @@ -0,0 +1,132 @@ +/* + * + * 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.utils; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; + +import com.google.common.io.Files; + + +public class VF2JSProjectUtils +{ + + private static File tempDir; + + public static final String createTempProject(String projectFilePath, + boolean isFlashBuilderProject) + { + tempDir = Files.createTempDir(); + + String fileName = projectFilePath.substring(projectFilePath.lastIndexOf(File.separator) + 1, projectFilePath.length()); + + String path = projectFilePath.substring(0, projectFilePath.lastIndexOf(File.separator)); + + createTempProjectDir(new File(path).listFiles(), ""); + + return tempDir.getAbsolutePath() + File.separator + fileName; + } + + private static void createTempProjectDir(File[] files, String parentPath) + { + for (File file : files) + { + if (file.isDirectory()) + { + String path = parentPath + File.separator + file.getName(); + + new File(tempDir + File.separator + path).mkdirs(); + + createTempProjectDir(file.listFiles(), path); + } + else + { + String fileName = file.getName(); + + if (fileName.contains(".") && fileName.charAt(0) != '.') + { + String extension = fileName.substring(fileName.lastIndexOf("."), fileName.length()); + + if (extension.equals(".mxml") || extension.equals(".as")) + { + File intermediateFile = file; + String tempFileName = fileName.substring(0, fileName.indexOf(".")); + File targetDir = new File(tempDir + File.separator + parentPath); + + createTempFileWithVF2JSNamespace(intermediateFile, + tempFileName, false, targetDir, extension); + } + } + } + } + } + + private static File createTempFileWithVF2JSNamespace(File intermediateFile, + String tempFileName, boolean createTempFile, File targetDir, + String extension) + { + File tempFile = null; + + try + { + String content = FileUtils.readFileToString(intermediateFile, "UTF-8"); + + // mx (MXML) + content = content.replace( + "xmlns:mx=\"library://ns.adobe.com/flex/mx\"", + "xmlns:vf2js_mx=\"http://flex.apache.org/vf2js_mx/ns\""); + content = content.replace("<mx:", "<vf2js_mx:"); + content = content.replace("</mx:", "</vf2js_mx:"); + + // mx (AS) + content = content.replace("mx.", "vf2js_mx."); + + // s (MXML) + content = content.replace( + "xmlns:s=\"library://ns.adobe.com/flex/spark\"", + "xmlns:vf2js_s=\"http://flex.apache.org/vf2js_s/ns\""); + content = content.replace("<s:", "<vf2js_s:"); + content = content.replace("</s:", "</vf2js_s:"); + + // s (AS) + content = content.replace("spark.", "vf2js_s."); + + if (createTempFile) + { + tempFile = File.createTempFile(tempFileName, extension, + targetDir); + tempFile.deleteOnExit(); + } + else + { + tempFile = new File(targetDir.getAbsolutePath(), + tempFileName + extension); + } + FileUtils.writeStringToFile(tempFile, content, "UTF-8"); + } + catch (IOException e) + { + throw new RuntimeException("Generating file failed", e); + } + + return tempFile; + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IASNodeStrategy.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IASNodeStrategy.java b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IASNodeStrategy.java new file mode 100644 index 0000000..589e00e --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IASNodeStrategy.java @@ -0,0 +1,38 @@ +/* + * + * 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.visitor; + +import org.apache.flex.compiler.tree.as.IASNode; + +/** + * A simple strategy to allow composition of {@link IASNode} handling when + * walking the AST node tree. + * + * @author Michael Schmalle + */ +public interface IASNodeStrategy +{ + /** + * The strategy will handle the specific {@link IASNode}. + * + * @param node The {@link IASNode} to handle. + */ + void handle(IASNode node); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IBlockVisitor.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IBlockVisitor.java b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IBlockVisitor.java new file mode 100644 index 0000000..5681b21 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IBlockVisitor.java @@ -0,0 +1,28 @@ +/* + * + * 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.visitor; + +/** + * @author Erik de Bruin + */ +public interface IBlockVisitor +{ + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IBlockWalker.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IBlockWalker.java b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IBlockWalker.java new file mode 100644 index 0000000..3bba54c --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/IBlockWalker.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.visitor; + +import org.apache.flex.compiler.projects.ICompilerProject; +import org.apache.flex.compiler.tree.as.IASNode; + +/** + * @author Michael Schmalle + * @author Erik de Bruin + */ +public interface IBlockWalker +{ + + /** + * Returns the current {@link ICompilerProject} for the traverse state. + */ + ICompilerProject getProject(); + + /** + * Traverses an {@link IASNode} based on the semantics of the known node. + * <p> + * Typically uses the {@link IASNodeStrategy#handle(IASNode)} to delegate + * how the node will be traversed. + * + * @param node The {@link IASNode} to traverse using the current strategy + */ + void walk(IASNode node); + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/as/IASBlockVisitor.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/as/IASBlockVisitor.java b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/as/IASBlockVisitor.java new file mode 100644 index 0000000..db3cda0 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/as/IASBlockVisitor.java @@ -0,0 +1,229 @@ +/* + * + * 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.visitor.as; + +import org.apache.flex.compiler.internal.codegen.as.ASBlockWalker; +import org.apache.flex.compiler.internal.tree.as.LabeledStatementNode; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IBinaryOperatorNode; +import org.apache.flex.compiler.tree.as.IBlockNode; +import org.apache.flex.compiler.tree.as.ICatchNode; +import org.apache.flex.compiler.tree.as.IClassNode; +import org.apache.flex.compiler.tree.as.IContainerNode; +import org.apache.flex.compiler.tree.as.IDefaultXMLNamespaceNode; +import org.apache.flex.compiler.tree.as.IDynamicAccessNode; +import org.apache.flex.compiler.tree.as.IEmbedNode; +import org.apache.flex.compiler.tree.as.IExpressionNode; +import org.apache.flex.compiler.tree.as.IFileNode; +import org.apache.flex.compiler.tree.as.IForLoopNode; +import org.apache.flex.compiler.tree.as.IFunctionCallNode; +import org.apache.flex.compiler.tree.as.IFunctionNode; +import org.apache.flex.compiler.tree.as.IFunctionObjectNode; +import org.apache.flex.compiler.tree.as.IGetterNode; +import org.apache.flex.compiler.tree.as.IIdentifierNode; +import org.apache.flex.compiler.tree.as.IIfNode; +import org.apache.flex.compiler.tree.as.IImportNode; +import org.apache.flex.compiler.tree.as.IInterfaceNode; +import org.apache.flex.compiler.tree.as.IIterationFlowNode; +import org.apache.flex.compiler.tree.as.IKeywordNode; +import org.apache.flex.compiler.tree.as.ILanguageIdentifierNode; +import org.apache.flex.compiler.tree.as.ILiteralNode; +import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode; +import org.apache.flex.compiler.tree.as.INamespaceAccessExpressionNode; +import org.apache.flex.compiler.tree.as.INamespaceNode; +import org.apache.flex.compiler.tree.as.INumericLiteralNode; +import org.apache.flex.compiler.tree.as.IObjectLiteralValuePairNode; +import org.apache.flex.compiler.tree.as.IPackageNode; +import org.apache.flex.compiler.tree.as.IParameterNode; +import org.apache.flex.compiler.tree.as.IReturnNode; +import org.apache.flex.compiler.tree.as.ISetterNode; +import org.apache.flex.compiler.tree.as.ISwitchNode; +import org.apache.flex.compiler.tree.as.ITerminalNode; +import org.apache.flex.compiler.tree.as.ITernaryOperatorNode; +import org.apache.flex.compiler.tree.as.IThrowNode; +import org.apache.flex.compiler.tree.as.ITryNode; +import org.apache.flex.compiler.tree.as.ITypedExpressionNode; +import org.apache.flex.compiler.tree.as.IUnaryOperatorNode; +import org.apache.flex.compiler.tree.as.IUseNamespaceNode; +import org.apache.flex.compiler.tree.as.IVariableExpressionNode; +import org.apache.flex.compiler.tree.as.IVariableNode; +import org.apache.flex.compiler.tree.as.IWhileLoopNode; +import org.apache.flex.compiler.tree.as.IWithNode; +import org.apache.flex.compiler.tree.metadata.IMetaTagNode; +import org.apache.flex.compiler.tree.metadata.IMetaTagsNode; +import org.apache.flex.compiler.units.ICompilationUnit; +import org.apache.flex.compiler.visitor.IASNodeStrategy; +import org.apache.flex.compiler.visitor.IBlockVisitor; + +/** + * The {@link IASBlockVisitor} interface allows an {@link IASNodeStrategy} to + * delegate within it's {@link IASNodeStrategy#handle(IASNode)} method to this + * API's visitor method. + * <p> + * <strong>Note</strong> This API is not complete. + * + * @author Michael Schmalle + * + * @see ASBlockWalker + */ +public interface IASBlockVisitor extends IBlockVisitor +{ + //-------------------------------------------------------------------------- + // Top level nodes + //-------------------------------------------------------------------------- + + void visitCompilationUnit(ICompilationUnit unit); + + void visitFile(IFileNode node); + + void visitPackage(IPackageNode node); + + void visitClass(IClassNode node); + + void visitInterface(IInterfaceNode node); + + //-------------------------------------------------------------------------- + // Member nodes + //-------------------------------------------------------------------------- + + // block var or field + void visitVariable(IVariableNode node); + + void visitFunction(IFunctionNode node); + + void visitGetter(IGetterNode node); + + void visitSetter(ISetterNode node); + + void visitNamespace(INamespaceNode node); + + //-------------------------------------------------------------------------- + // Statement nodes + //-------------------------------------------------------------------------- + + void visitIf(IIfNode node); + + void visitForLoop(IForLoopNode node); + + void visitWhileLoop(IWhileLoopNode node); + + void visitTry(ITryNode node); + + void visitCatch(ICatchNode node); + + void visitSwitch(ISwitchNode node); + + void visitLabeledStatement(LabeledStatementNode node); + + void visitWith(IWithNode node); + + void visitThrow(IThrowNode node); + + //-------------------------------------------------------------------------- + // Statement helper nodes + //-------------------------------------------------------------------------- + + void visitIterationFlow(IIterationFlowNode node); + + // is a IVariableNode + void visitParameter(IParameterNode node); + + void visitObjectLiteralValuePair(IObjectLiteralValuePairNode node); + + //-------------------------------------------------------------------------- + // Expression Statement nodes + //-------------------------------------------------------------------------- + + void visitMemberAccessExpression(IMemberAccessExpressionNode node); + + void visitNamespaceAccessExpression(INamespaceAccessExpressionNode node); + + void visitVariableExpression(IVariableExpressionNode node); + + void visitLanguageIdentifierNode(ILanguageIdentifierNode node); + + void visitReturn(IReturnNode node); + + void visitDefaultXMLNamespace(IDefaultXMLNamespaceNode node); + + void visitTypedExpression(ITypedExpressionNode node); + + // this is a IBinaryOperatorNode goes before + void visitDynamicAccess(IDynamicAccessNode node); + + void visitTernaryOperator(ITernaryOperatorNode node); + + //-------------------------------------------------------------------------- + // Container nodes + //-------------------------------------------------------------------------- + + void visitBlock(IBlockNode node); + + //-------------------------------------------------------------------------- + // Expression nodes + //-------------------------------------------------------------------------- + + void visitFunctionObject(IFunctionObjectNode node); + + void visitFunctionCall(IFunctionCallNode node); + + void visitAsOperator(IBinaryOperatorNode node); + + void visitIsOperator(IBinaryOperatorNode node); + + void visitBinaryOperator(IBinaryOperatorNode node); + + void visitUnaryOperator(IUnaryOperatorNode node); + + void visitExpression(IExpressionNode node); + + //-------------------------------------------------------------------------- + // Terminal like Expression nodes + //-------------------------------------------------------------------------- + + void visitIdentifier(IIdentifierNode node); + + void visitKeyword(IKeywordNode node); + + void visitLiteral(ILiteralNode node); + + void visitNumericLiteral(INumericLiteralNode node); + + void visitTerminal(ITerminalNode node); + + //-------------------------------------------------------------------------- + // Various nodes + //-------------------------------------------------------------------------- + + void visitImport(IImportNode node); + + void visitMetaTags(IMetaTagsNode node); + + void visitMetaTag(IMetaTagNode node); + + void visitUseNamespace(IUseNamespaceNode node); + + void visitEmbed(IEmbedNode node); + + void visitContainer(IContainerNode node); + + void visitE4XFilter(IMemberAccessExpressionNode node); + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/as/IASBlockWalker.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/as/IASBlockWalker.java b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/as/IASBlockWalker.java new file mode 100644 index 0000000..f97b9ad --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/as/IASBlockWalker.java @@ -0,0 +1,43 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.flex.compiler.visitor.as; + +import java.util.List; + +import org.apache.flex.compiler.codegen.as.IASEmitter; +import org.apache.flex.compiler.problems.ICompilerProblem; +import org.apache.flex.compiler.visitor.IBlockWalker; + +/** + * @author Michael Schmalle + */ +public interface IASBlockWalker extends IASBlockVisitor, IBlockWalker +{ + + /** + * The current code emitter. + */ + IASEmitter getEmitter(); + + /** + * The current project errors. + */ + List<ICompilerProblem> getErrors(); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java new file mode 100644 index 0000000..d6c45a8 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java @@ -0,0 +1,138 @@ +/* + * + * 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.visitor.mxml; + +import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode; +import org.apache.flex.compiler.tree.mxml.IMXMLBindingNode; +import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode; +import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode; +import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDataBindingNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDeclarationsNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDeferredInstanceNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode; +import org.apache.flex.compiler.tree.mxml.IMXMLEmbedNode; +import org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode; +import org.apache.flex.compiler.tree.mxml.IMXMLFactoryNode; +import org.apache.flex.compiler.tree.mxml.IMXMLFileNode; +import org.apache.flex.compiler.tree.mxml.IMXMLImplementsNode; +import org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode; +import org.apache.flex.compiler.tree.mxml.IMXMLIntNode; +import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode; +import org.apache.flex.compiler.tree.mxml.IMXMLMetadataNode; +import org.apache.flex.compiler.tree.mxml.IMXMLNumberNode; +import org.apache.flex.compiler.tree.mxml.IMXMLObjectNode; +import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode; +import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode; +import org.apache.flex.compiler.tree.mxml.IMXMLStringNode; +import org.apache.flex.compiler.tree.mxml.IMXMLStyleNode; +import org.apache.flex.compiler.tree.mxml.IMXMLStyleSpecifierNode; +import org.apache.flex.compiler.tree.mxml.IMXMLUintNode; +import org.apache.flex.compiler.tree.mxml.IMXMLVectorNode; +import org.apache.flex.compiler.units.ICompilationUnit; +import org.apache.flex.compiler.visitor.IBlockVisitor; + +/** + * @author Michael Schmalle + * @author Erik de Bruin + */ +public interface IMXMLBlockVisitor extends IBlockVisitor +{ + + //-------------------------------------------------------------------------- + + void visitCompilationUnit(ICompilationUnit unit); + + void visitFile(IMXMLFileNode node); + + void visitDocument(IMXMLDocumentNode node); + + void visitClassDefinition(IMXMLClassDefinitionNode node); + + void visitDeclarations(IMXMLDeclarationsNode node); + + //-------------------------------------------------------------------------- + + void visitDeferredInstance(IMXMLDeferredInstanceNode node); + + //-------------------------------------------------------------------------- + + void visitEventSpecifier(IMXMLEventSpecifierNode node); + + void visitInstance(IMXMLInstanceNode node); + + void visitPropertySpecifier(IMXMLPropertySpecifierNode node); + + void visitScript(IMXMLScriptNode node); + + void visitStyleBlock(IMXMLStyleNode node); + + void visitStyleSpecifier(IMXMLStyleSpecifierNode node); + + //-------------------------------------------------------------------------- + + void visitArray(IMXMLArrayNode node); + + void visitBoolean(IMXMLBooleanNode node); + + void visitInt(IMXMLIntNode node); + + void visitNumber(IMXMLNumberNode node); + + void visitString(IMXMLStringNode node); + + void visitUint(IMXMLUintNode node); + + //-------------------------------------------------------------------------- + + void visitLiteral(IMXMLLiteralNode node); + + void visitFactory(IMXMLFactoryNode node); + + void visitComponent(IMXMLComponentNode node); + + //-------------------------------------------------------------------------- + + void visitMetadata(IMXMLMetadataNode node); + + //-------------------------------------------------------------------------- + + void visitEmbed(IMXMLEmbedNode node); + + //-------------------------------------------------------------------------- + + void visitImplements(IMXMLImplementsNode node); + + //-------------------------------------------------------------------------- + + void visitVector(IMXMLVectorNode node); + + //-------------------------------------------------------------------------- + + void visitDatabinding(IMXMLDataBindingNode node); + + //-------------------------------------------------------------------------- + + void visitBinding(IMXMLBindingNode node); + + //-------------------------------------------------------------------------- + + void visitObject(IMXMLObjectNode node); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/mxml/IMXMLBlockWalker.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/mxml/IMXMLBlockWalker.java b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/mxml/IMXMLBlockWalker.java new file mode 100644 index 0000000..1aab260 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/visitor/mxml/IMXMLBlockWalker.java @@ -0,0 +1,43 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.flex.compiler.visitor.mxml; + +import org.apache.flex.compiler.codegen.as.IASEmitter; +import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter; +import org.apache.flex.compiler.visitor.IBlockWalker; + +/** + * @author Michael Schmalle + * @author Erik de Bruin + */ +public interface IMXMLBlockWalker extends IMXMLBlockVisitor, IBlockWalker +{ + + /** + * The current code emitter. + */ + IASEmitter getASEmitter(); + + /** + * The current code emitter. + */ + IMXMLEmitter getMXMLEmitter(); + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/resources/META-INF/services/org.apache.flex.tools.FlexToolGroup ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/resources/META-INF/services/org.apache.flex.tools.FlexToolGroup b/compiler-jx/src/main/resources/META-INF/services/org.apache.flex.tools.FlexToolGroup new file mode 100644 index 0000000..b2ad16f --- /dev/null +++ b/compiler-jx/src/main/resources/META-INF/services/org.apache.flex.tools.FlexToolGroup @@ -0,0 +1,2 @@ +org.apache.flex.compiler.clients.FlexJSToolGroup +org.apache.flex.compiler.clients.VF2JSToolGroup http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestAccessorMembers.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestAccessorMembers.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestAccessorMembers.java new file mode 100644 index 0000000..922af9c --- /dev/null +++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestAccessorMembers.java @@ -0,0 +1,101 @@ +/* + * + * 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.as; + +import org.apache.flex.compiler.internal.test.ASTestBase; +import org.apache.flex.compiler.tree.as.IAccessorNode; +import org.junit.Test; + +/** + * This class tests the production of valid ActionScript3 code for Class + * Accessor members. + * + * @author Michael Schmalle + */ +public class TestAccessorMembers extends ASTestBase +{ + //-------------------------------------------------------------------------- + // Accessor + //-------------------------------------------------------------------------- + + @Test + public void testGetAccessor() + { + IAccessorNode node = getAccessor("function get foo():int{return -1;}"); + asBlockWalker.visitFunction(node); + assertOut("function get foo():int {\n\treturn -1;\n}"); + } + + @Test + public void testGetAccessor_withNamespace() + { + IAccessorNode node = getAccessor("public function get foo():int{return -1;}"); + asBlockWalker.visitFunction(node); + assertOut("public function get foo():int {\n\treturn -1;\n}"); + } + + @Test + public void testGetAccessor_withNamespaceOverride() + { + IAccessorNode node = getAccessor("public override function get foo():int{return -1;}"); + asBlockWalker.visitFunction(node); + assertOut("public override function get foo():int {\n\treturn -1;\n}"); + } + + @Test + public void testGetAccessor_withStatic() + { + IAccessorNode node = getAccessor("public static function get foo():int{return -1;}"); + asBlockWalker.visitFunction(node); + assertOut("public static function get foo():int {\n\treturn -1;\n}"); + } + + @Test + public void testSetAccessor() + { + IAccessorNode node = getAccessor("function set foo(value:int):void{}"); + asBlockWalker.visitFunction(node); + assertOut("function set foo(value:int):void {\n}"); + } + + @Test + public void testSetAccessor_withNamespace() + { + IAccessorNode node = getAccessor("public function set foo(value:int):void{}"); + asBlockWalker.visitFunction(node); + assertOut("public function set foo(value:int):void {\n}"); + } + + @Test + public void testSetAccessor_withNamespaceOverride() + { + IAccessorNode node = getAccessor("public override function set foo(value:int):void{}"); + asBlockWalker.visitFunction(node); + assertOut("public override function set foo(value:int):void {\n}"); + } + + @Test + public void testSetAccessor_withStatic() + { + IAccessorNode node = getAccessor("public static function set foo(value:int):void{}"); + asBlockWalker.visitFunction(node); + assertOut("public static function set foo(value:int):void {\n}"); + } +}