incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1421615 [2/4] - in /incubator/flex/whiteboard/mschmalle/falconjx: ./ compiler.jx.tests/ compiler.jx.tests/src/ compiler.jx.tests/src/org/ compiler.jx.tests/src/org/apache/ compiler.jx.tests/src/org/apache/flex/ compiler.jx.tests/src/org/ap...
Date Thu, 13 Dec 2012 23:32:16 GMT
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java?rev=1421615&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java Thu Dec 13 23:32:01 2012
@@ -0,0 +1,701 @@
+/*
+ *
+ *  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.clients;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.flex.compiler.clients.problems.ProblemPrinter;
+import org.apache.flex.compiler.clients.problems.ProblemQuery;
+import org.apache.flex.compiler.clients.problems.WorkspaceProblemFormatter;
+import org.apache.flex.compiler.common.VersionInfo;
+import org.apache.flex.compiler.config.Configuration;
+import org.apache.flex.compiler.config.ConfigurationBuffer;
+import org.apache.flex.compiler.config.Configurator;
+import org.apache.flex.compiler.config.ICompilerSettingsConstants;
+import org.apache.flex.compiler.exceptions.ConfigurationException;
+import org.apache.flex.compiler.exceptions.ConfigurationException.IOError;
+import org.apache.flex.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
+import org.apache.flex.compiler.exceptions.ConfigurationException.OnlyOneSource;
+import org.apache.flex.compiler.internal.driver.JSBackend;
+import org.apache.flex.compiler.internal.js.codgen.JSSharedData;
+import org.apache.flex.compiler.internal.js.codgen.JSWriter;
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.projects.FlexProject;
+import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
+import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.internal.units.ResourceModuleCompilationUnit;
+import org.apache.flex.compiler.internal.units.SourceCompilationUnitFactory;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.problems.ConfigurationProblem;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.problems.InternalCompilerProblem;
+import org.apache.flex.compiler.problems.UnableToBuildSWFProblem;
+import org.apache.flex.compiler.problems.UnexpectedExceptionProblem;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.js.IJSApplication;
+import org.apache.flex.utils.FileUtils;
+import org.apache.flex.utils.FilenameNormalization;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+/**
+ * @author Michael Schmalle
+ */
+public class MXMLJSC
+{
+
+    /*
+     * Exit code enumerations.
+     */
+    static enum ExitCode
+    {
+        SUCCESS(0),
+        PRINT_HELP(1),
+        FAILED_WITH_PROBLEMS(2),
+        FAILED_WITH_EXCEPTIONS(3),
+        FAILED_WITH_CONFIG_PROBLEMS(4);
+
+        ExitCode(int code)
+        {
+            this.code = code;
+        }
+
+        final int code;
+    }
+
+    /**
+     * Java program entry point.
+     * 
+     * @param args command line arguments
+     */
+    public static void main(final String[] args)
+    {
+        long startTime = System.nanoTime();
+
+        final IBackend backend = new JSBackend();
+        final MXMLJSC mxmlc = new MXMLJSC(backend);
+        final Set<ICompilerProblem> problems = new HashSet<ICompilerProblem>();
+        final int exitCode = mxmlc.mainNoExit(args, problems, true);
+
+        long endTime = System.nanoTime();
+        JSSharedData.instance.stdout((endTime - startTime) / 1e9 + " seconds");
+
+        System.exit(exitCode);
+    }
+
+    private Workspace workspace;
+    private FlexProject project;
+    private ProblemQuery problems;
+    private ISourceFileHandler asFileHandler;
+    private Configuration config;
+    private Configurator projectConfigurator;
+    private ConfigurationBuffer configBuffer;
+    private ICompilationUnit mainCU;
+    private JSTarget target;
+    private ITargetSettings targetSettings;
+    private IJSApplication jsTarget;
+
+    protected MXMLJSC(IBackend backend)
+    {
+        JSSharedData.backend = backend;
+        workspace = new Workspace();
+        project = new FlexProject(workspace);
+        problems = new ProblemQuery();
+        JSSharedData.OUTPUT_EXTENSION = backend.getOutputExtension();
+        JSSharedData.workspace = workspace;
+        asFileHandler = backend.getSourceFileHandlerInstance();
+    }
+
+    public int mainNoExit(final String[] args, Set<ICompilerProblem> problems,
+            Boolean printProblems)
+    {
+        int exitCode = -1;
+        try
+        {
+            exitCode = _mainNoExit(fixArgs(args), problems);
+        }
+        catch (Exception e)
+        {
+            JSSharedData.instance.stderr(e.toString());
+        }
+        finally
+        {
+            if (problems != null && !problems.isEmpty())
+            {
+                if (printProblems)
+                {
+                    final WorkspaceProblemFormatter formatter = new WorkspaceProblemFormatter(
+                            workspace);
+                    final ProblemPrinter printer = new ProblemPrinter(formatter);
+                    printer.printProblems(problems);
+                }
+            }
+        }
+        return exitCode;
+    }
+
+    /**
+     * Entry point that doesn't call <code>System.exit()</code>. This is for
+     * unit testing.
+     * 
+     * @param args command line arguments
+     * @return exit code
+     */
+    private int _mainNoExit(final String[] args,
+            Set<ICompilerProblem> outProblems)
+    {
+        ExitCode exitCode = ExitCode.SUCCESS;
+        try
+        {
+            final boolean continueCompilation = configure(args);
+
+            if (outProblems != null && !config.isVerbose())
+                JSSharedData.STDOUT = JSSharedData.STDERR = null;
+
+            if (continueCompilation)
+            {
+                compile();
+                if (problems.hasFilteredProblems())
+                    exitCode = ExitCode.FAILED_WITH_PROBLEMS;
+            }
+            else if (problems.hasFilteredProblems())
+            {
+                exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
+            }
+            else
+            {
+                exitCode = ExitCode.PRINT_HELP;
+            }
+        }
+        catch (Exception e)
+        {
+            if (outProblems == null)
+                JSSharedData.instance.stderr(e.getMessage());
+            else
+            {
+                final ICompilerProblem unexpectedExceptionProblem = new UnexpectedExceptionProblem(
+                        e);
+                problems.add(unexpectedExceptionProblem);
+            }
+            exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
+        }
+        finally
+        {
+            waitAndClose();
+
+            if (outProblems != null && problems.hasFilteredProblems())
+            {
+                for (ICompilerProblem problem : problems.getFilteredProblems())
+                {
+                    outProblems.add(problem);
+                }
+            }
+        }
+        return exitCode.code;
+    }
+
+    /**
+     * Main body of this program. This method is called from the public static
+     * method's for this program.
+     * 
+     * @return true if compiler succeeds
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    protected boolean compile()
+    {
+        boolean compilationSuccess = false;
+
+        try
+        {
+            setupJS();
+            if (!setupTargetFile())
+                return false;
+
+            //if (config.isDumpAst())
+            //    dumpAST();
+
+            buildArtifact();
+
+            if (jsTarget != null)
+            {
+                Collection<ICompilerProblem> errors = new ArrayList<ICompilerProblem>();
+                Collection<ICompilerProblem> warnings = new ArrayList<ICompilerProblem>();
+
+                // Don't create a swf if there are errors unless a 
+                // developer requested otherwise.
+                if (!config.getCreateTargetWithErrors())
+                {
+                    problems.getErrorsAndWarnings(errors, warnings);
+                    if (errors.size() > 0)
+                        return false;
+                }
+
+                final File outputFile = new File(getOutputFilePath());
+
+                final File outputFolder = new File(outputFile.getParent());
+                List<ICompilationUnit> reachableCompilationUnits = project
+                        .getReachableCompilationUnitsInSWFOrder(ImmutableSet
+                                .of(mainCU));
+                for (final ICompilationUnit cu : reachableCompilationUnits)
+                {
+                    if (cu.getCompilationUnitType() == ICompilationUnit.UnitType.AS_UNIT
+                            && cu != mainCU)
+                    {
+                        final File outputClassFile = new File(
+                                outputFolder.getAbsolutePath() + File.separator
+                                        + cu.getShortNames().get(0) + ".js");
+                        System.out.println(outputClassFile.getAbsolutePath());
+
+                        for (ICompilationUnit unit : reachableCompilationUnits)
+                        {
+                            JSWriter jswriter = JSSharedData.backend
+                                    .createWriter(project,
+                                            (List<ICompilerProblem>) errors,
+                                            unit, false);
+
+                            if (unit.getCompilationUnitType() != ICompilationUnit.UnitType.AS_UNIT)
+                                continue;
+
+                            // XXX hack what is CountingOutputStream?
+                            BufferedOutputStream out = new BufferedOutputStream(
+                                    new FileOutputStream(outputClassFile));
+                            jswriter.writeTo(out);
+                            out.flush();
+                            out.close();
+                            jswriter.close();
+                        }
+                    }
+                }
+                compilationSuccess = true;
+
+                //dumpDependencyGraphIfNeeded();
+            }
+        }
+        catch (Exception e)
+        {
+            final ICompilerProblem problem = new InternalCompilerProblem(e);
+            problems.add(problem);
+        }
+
+        return compilationSuccess;
+    }
+
+    /**
+     * Build target artifact.
+     * 
+     * @throws InterruptedException threading error
+     * @throws IOException IO error
+     * @throws ConfigurationException
+     */
+    protected void buildArtifact() throws InterruptedException, IOException,
+            ConfigurationException
+    {
+        jsTarget = buildJSTarget();
+    }
+
+    private IJSApplication buildJSTarget() throws InterruptedException,
+            FileNotFoundException, ConfigurationException
+    {
+        final List<ICompilerProblem> problemsBuildingSWF = new ArrayList<ICompilerProblem>();
+
+        final IJSApplication app = buildApplication(project,
+                config.getMainDefinition(), mainCU, problemsBuildingSWF);
+        problems.addAll(problemsBuildingSWF);
+        if (app == null)
+        {
+            ICompilerProblem problem = new UnableToBuildSWFProblem(
+                    getOutputFilePath());
+            problems.add(problem);
+        }
+
+        //reportRequiredRSLs(target);
+
+        return app;
+    }
+
+    /**
+     * Replaces FlexApplicationProject::buildSWF()
+     * 
+     * @param applicationProject
+     * @param rootClassName
+     * @param problems
+     * @return
+     * @throws InterruptedException
+     */
+
+    private IJSApplication buildApplication(CompilerProject applicationProject,
+            String rootClassName, ICompilationUnit mainCU,
+            Collection<ICompilerProblem> problems) throws InterruptedException,
+            ConfigurationException, FileNotFoundException
+    {
+        Collection<ICompilerProblem> fatalProblems = applicationProject
+                .getFatalProblems();
+        if (!fatalProblems.isEmpty())
+        {
+            problems.addAll(fatalProblems);
+            return null;
+        }
+
+        return target.build(mainCU, problems);
+    }
+
+    /**
+     * Get the output file path. If {@code -output} is specified, use its value;
+     * otherwise, use the same base name as the target file.
+     * 
+     * @return output file path
+     */
+    private String getOutputFilePath()
+    {
+        if (config.getOutput() == null)
+        {
+            final String extension = "." + JSSharedData.OUTPUT_EXTENSION;
+            return FilenameUtils.removeExtension(config.getTargetFile())
+                    .concat(extension);
+        }
+        else
+            return config.getOutput();
+    }
+
+    /**
+     * Mxmlc uses target file as the main compilation unit and derive the output
+     * SWF file name from this file.
+     * 
+     * @return true if successful, false otherwise.
+     * @throws OnlyOneSource
+     * @throws InterruptedException
+     */
+    protected boolean setupTargetFile() throws InterruptedException
+    {
+        final String mainFileName = config.getTargetFile();
+
+        final String normalizedMainFileName = FilenameNormalization
+                .normalize(mainFileName);
+
+        final SourceCompilationUnitFactory compilationUnitFactory = project
+                .getSourceCompilationUnitFactory();
+
+        File normalizedMainFile = new File(normalizedMainFileName);
+        if (compilationUnitFactory.canCreateCompilationUnit(normalizedMainFile))
+        {
+            // adds the source path to the sourceListManager
+            project.addIncludeSourceFile(normalizedMainFile);
+
+            // just using the basename is obviously wrong:
+            // final String mainQName = FilenameUtils.getBaseName(normalizedMainFile);
+
+            final List<String> sourcePath = config.getCompilerSourcePath();
+            String mainQName = null;
+            if (sourcePath != null && !sourcePath.isEmpty())
+            {
+                for (String path : sourcePath)
+                {
+                    final String otherPath = new File(path).getAbsolutePath();
+                    if (mainFileName.startsWith(otherPath))
+                    {
+                        mainQName = mainFileName
+                                .substring(otherPath.length() + 1);
+                        mainQName = mainQName.replaceAll("\\\\", "/");
+                        mainQName = mainQName.replaceAll("\\/", ".");
+                        if (mainQName.endsWith(".as"))
+                            mainQName = mainQName.substring(0,
+                                    mainQName.length() - 3);
+                        break;
+                    }
+                }
+            }
+
+            if (mainQName == null)
+                mainQName = FilenameUtils.getBaseName(mainFileName);
+
+            Collection<ICompilationUnit> mainFileCompilationUnits = workspace
+                    .getCompilationUnits(normalizedMainFileName, project);
+
+            //assert mainFileCompilationUnits.size() == 1;
+            mainCU = Iterables.getOnlyElement(mainFileCompilationUnits);
+
+            //assert ((DefinitionPriority)mainCU.getDefinitionPriority()).getBasePriority() == DefinitionPriority.BasePriority.SOURCE_LIST;
+
+            // Use main source file name as the root class name.
+            config.setMainDefinition(mainQName);
+        }
+
+        Preconditions.checkNotNull(mainCU,
+                "Main compilation unit can't be null");
+
+        // if (getTargetSettings() == null)
+        //     return false;
+
+        target = (JSTarget) JSSharedData.backend.createJSTarget(project,
+                getTargetSettings(), null);
+
+        return true;
+    }
+
+    private ITargetSettings getTargetSettings()
+    {
+        if (targetSettings == null)
+            targetSettings = projectConfigurator.getTargetSettings(null);
+
+        return targetSettings;
+    }
+
+    private void setupJS() throws IOException, InterruptedException
+    {
+        // JSSharedData.instance.reset();
+        project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+
+        // JSSharedData.instance.setVerbose(config.isVerbose());
+
+        //JSSharedData.DEBUG = config.debug();
+        //JSSharedData.OPTIMIZE = !config.debug() && config.optimize();
+
+        final Set<ICompilationUnit> compilationUnits = new HashSet<ICompilationUnit>();
+
+        // XXX // add builtins?
+
+        registerSWCs(project); // XXX is this needed?
+    }
+
+    public static void registerSWCs(CompilerProject project)
+            throws InterruptedException
+    {
+        final JSSharedData sharedData = JSSharedData.instance;
+
+        // collect all SWCCompilationUnit in swcUnits
+        final List<ICompilationUnit> swcUnits = new ArrayList<ICompilationUnit>();
+        for (ICompilationUnit cu : project.getCompilationUnits())
+        {
+            //            if (cu instanceof SWCCompilationUnit)
+            //                swcUnits.add(cu);
+            //
+            //            final List<IDefinition> defs = getDefinitions(cu, false);
+            //            for (IDefinition def : defs)
+            //            {
+            //                sharedData.registerDefinition(def);
+            //            }
+        }
+
+    }
+
+    /**
+     * Create a new Configurator. This method may be overridden to allow
+     * Configurator subclasses to be created that have custom configurations.
+     * 
+     * @return a new instance or subclass of {@link Configurator}.
+     */
+    protected Configurator createConfigurator()
+    {
+        return JSSharedData.backend.createConfigurator();
+    }
+
+    /**
+     * Load configurations from all the sources.
+     * 
+     * @param args command line arguments
+     * @return True if mxmlc should continue with compilation.
+     */
+    protected boolean configure(final String[] args)
+    {
+        project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+        projectConfigurator = createConfigurator();
+
+        try
+        {
+            //            // Print brief usage if no arguments provided.
+            //            if (args.length == 0)
+            //            {
+            //                final String usage = CommandLineConfigurator.brief(
+            //                        getProgramName(), DEFAULT_VAR,
+            //                        LocalizationManager.get(), L10N_CONFIG_PREFIX);
+            //                if (usage != null)
+            //                    println(usage);
+            //                return false;
+            //            }
+            //
+            projectConfigurator.setConfiguration(args,
+                    ICompilerSettingsConstants.FILE_SPECS_VAR);
+            projectConfigurator.applyToProject(project);
+            problems = new ProblemQuery(
+                    projectConfigurator.getCompilerProblemSettings());
+
+            // Get the configuration and configBuffer which are now initialized.
+            config = projectConfigurator.getConfiguration();
+            configBuffer = projectConfigurator.getConfigurationBuffer();
+            problems.addAll(projectConfigurator.getConfigurationProblems());
+
+            // Print version if "-version" is present.
+            if (configBuffer.getVar("version") != null) //$NON-NLS-1$
+            {
+                println(VersionInfo.buildMessage() + " ("
+                        + JSSharedData.COMPILER_VERSION + ")");
+                return false;
+            }
+            //
+            //            // Print help if "-help" is present.
+            //            final List<ConfigurationValue> helpVar = configBuffer
+            //                    .getVar("help"); //$NON-NLS-1$
+            //            if (helpVar != null)
+            //            {
+            //                processHelp(helpVar);
+            //                return false;
+            //            }
+            //
+            //            for (String fileName : projectConfigurator
+            //                    .getLoadedConfigurationFiles())
+            //            {
+            //                JSSharedData.instance.stdout("Loading configuration: "
+            //                        + fileName);
+            //            }
+            //
+            //            if (config.isVerbose())
+            //            {
+            //                for (final IFileSpecification themeFile : project
+            //                        .getThemeFiles())
+            //                {
+            //                    JSSharedData.instance.stdout(String.format(
+            //                            "Found theme file %s", themeFile.getPath()));
+            //                }
+            //            }
+            //
+            // If we have configuration errors then exit before trying to 
+            // validate the target.
+            if (problems.hasErrors())
+                return false;
+
+            validateTargetFile();
+            return true;
+        }
+        catch (ConfigurationException e)
+        {
+            final ICompilerProblem problem = new ConfigurationProblem(e);
+            problems.add(problem);
+            return false;
+        }
+        catch (Exception e)
+        {
+            final ICompilerProblem problem = new ConfigurationProblem(null, -1,
+                    -1, -1, -1, e.getMessage());
+            problems.add(problem);
+            return false;
+        }
+        finally
+        {
+            // If we couldn't create a configuration, then create a default one
+            // so we can exit without throwing an exception.
+            if (config == null)
+            {
+                config = new Configuration();
+                configBuffer = new ConfigurationBuffer(Configuration.class,
+                        Configuration.getAliases());
+            }
+        }
+    }
+
+    /**
+     * Validate target file.
+     * 
+     * @throws MustSpecifyTarget
+     * @throws IOError
+     */
+    protected void validateTargetFile() throws ConfigurationException
+    {
+        if (mainCU instanceof ResourceModuleCompilationUnit)
+            return; //when compiling a Resource Module, no target file is defined.
+
+        final String targetFile = config.getTargetFile();
+        if (targetFile == null)
+            throw new ConfigurationException.MustSpecifyTarget(null, null, -1);
+
+        final File file = new File(targetFile);
+        if (!file.exists())
+            throw new ConfigurationException.IOError(targetFile);
+    }
+
+    private void println(String string)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * Wait till the workspace to finish compilation and close.
+     */
+    protected void waitAndClose()
+    {
+        workspace.startIdleState();
+        try
+        {
+            workspace.close();
+        }
+        finally
+        {
+            workspace.endIdleState(Collections
+                    .<ICompilerProject, Set<ICompilationUnit>> emptyMap());
+        }
+    }
+
+    /**
+     * Force terminate the compilation process.
+     */
+    protected void close()
+    {
+        workspace.close();
+    }
+
+    // workaround for Falcon bug.
+    // Input files with relative paths confuse the algorithm that extracts the root class name.
+
+    protected static String[] fixArgs(final String[] args)
+    {
+        String[] newArgs = args;
+        if (args.length > 1)
+        {
+            String targetPath = args[args.length - 1];
+            if (targetPath.startsWith("."))
+            {
+                targetPath = FileUtils
+                        .getTheRealPathBecauseCanonicalizeDoesNotFixCase(new File(
+                                targetPath));
+                newArgs = new String[args.length];
+                for (int i = 0; i < args.length - 1; ++i)
+                    newArgs[i] = args[i];
+                newArgs[args.length - 1] = targetPath;
+            }
+        }
+        return newArgs;
+    }
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSApplication.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSApplication.java?rev=1421615&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSApplication.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSApplication.java Thu Dec 13 23:32:01 2012
@@ -0,0 +1,31 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.driver;
+
+import org.apache.flex.js.IJSApplication;
+
+public class JSApplication implements IJSApplication
+{
+
+    public JSApplication()
+    {
+    }
+
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSApplication.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSBackend.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSBackend.java?rev=1421615&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSBackend.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSBackend.java Thu Dec 13 23:32:01 2012
@@ -0,0 +1,108 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.driver;
+
+import java.io.StringWriter;
+import java.util.List;
+
+import org.apache.flex.compiler.clients.IBackend;
+import org.apache.flex.compiler.clients.JSConfiguration;
+import org.apache.flex.compiler.config.Configurator;
+import org.apache.flex.compiler.internal.driver.strategy.AfterNodeStrategy;
+import org.apache.flex.compiler.internal.driver.strategy.BeforeAfterStrategy;
+import org.apache.flex.compiler.internal.driver.strategy.BeforeNodeStrategy;
+import org.apache.flex.compiler.internal.js.codgen.ASBlockWalker;
+import org.apache.flex.compiler.internal.js.codgen.JSEmitter;
+import org.apache.flex.compiler.internal.js.codgen.JSFilterWriter;
+import org.apache.flex.compiler.internal.js.codgen.JSWriter;
+import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
+import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.internal.visitor.ASNodeSwitch;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.projects.IASProject;
+import org.apache.flex.compiler.targets.ITargetProgressMonitor;
+import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.units.ICompilationUnit;
+
+/**
+ * @author Michael Schmalle
+ */
+public class JSBackend implements IBackend
+{
+
+    @Override
+    public String getOutputExtension()
+    {
+        return "js";
+    }
+
+    @Override
+    public ISourceFileHandler getSourceFileHandlerInstance()
+    {
+        return JSSourceFileHandler.INSTANCE;
+    }
+
+    @Override
+    public Configurator createConfigurator()
+    {
+        return new Configurator(JSConfiguration.class);
+    }
+
+    @Override
+    public JSTarget createJSTarget(IASProject project,
+            ITargetSettings settings, ITargetProgressMonitor monitor)
+    {
+        return new JSTarget(project, settings, monitor);
+    }
+
+    @Override
+    public ASBlockWalker createWalker(IASProject project,
+            List<ICompilerProblem> errors, JSFilterWriter out)
+    {
+        JSEmitter emitter = new JSEmitter(out);
+        ASBlockWalker walker = new ASBlockWalker(errors, project, emitter);
+
+        BeforeAfterStrategy strategy = new BeforeAfterStrategy();
+        strategy.setHandler(new ASNodeSwitch(walker));
+        strategy.setBefore(new BeforeNodeStrategy(emitter));
+        strategy.setAfter(new AfterNodeStrategy(emitter));
+
+        walker.setStrategy(strategy);
+
+        return walker;
+    }
+
+    @Override
+    public JSFilterWriter createFilterWriter(IASProject project)
+    {
+        StringWriter out = new StringWriter();
+        JSFilterWriter writer = new JSFilterWriter(out);
+        return writer;
+    }
+
+    @Override
+    public JSWriter createWriter(IASProject project,
+            List<ICompilerProblem> problems, ICompilationUnit compilationUnit,
+            boolean enableDebug)
+    {
+        return new JSWriter(project, problems, compilationUnit, enableDebug);
+    }
+
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSBackend.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSCompilationUnit.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSCompilationUnit.java?rev=1421615&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSCompilationUnit.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSCompilationUnit.java Thu Dec 13 23:32:01 2012
@@ -0,0 +1,223 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.driver;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.flex.compiler.common.DependencyType;
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.projects.DefinitionPriority;
+import org.apache.flex.compiler.internal.units.ASCompilationUnit;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.targets.ITarget.TargetType;
+import org.apache.flex.compiler.units.requests.IABCBytesRequestResult;
+import org.apache.flex.compiler.units.requests.IOutgoingDependenciesRequestResult;
+
+/**
+ * JSCompilationUnit is the CompilationUnit for compiling ActionScript source
+ * files to JavasScript. JSCompilationUnit is derived from ASCompilationUnit and
+ * overrides the parts that generate the code. JSCompilationUnit also supports
+ * requests for two-pass compilation (see m_needsSecondPass).
+ * JSSourceFileHandler provides JSCompilationUnit for *.as files. JSDriver
+ * registers JSSourceFileHandler at FlexApplicationProject. This implementation
+ * is part of FalconJS. For more details on FalconJS see
+ * org.apache.flex.compiler.JSDriver
+ */
+
+public class JSCompilationUnit extends ASCompilationUnit
+{
+    private IABCBytesRequestResult m_abcBytes = null;
+    private Boolean m_needsSecondPass = false;
+    private Boolean m_inCodeGen = false;
+
+    /**
+     * Create a compilation unit from an ABC file.
+     * 
+     * @param project compiler project
+     * @param path ABC file path
+     * @throws IOException error
+     */
+    public JSCompilationUnit(CompilerProject project, String path)
+            throws IOException
+    {
+        this(project, path, DefinitionPriority.BasePriority.LIBRARY_PATH);
+    }
+
+    public JSCompilationUnit(CompilerProject project, String path,
+            DefinitionPriority.BasePriority basePriority)
+    {
+        super(project, path, basePriority);
+    }
+
+    public JSCompilationUnit(CompilerProject project, String path,
+            DefinitionPriority.BasePriority basePriority, String qname)
+    {
+        super(project, path, basePriority, 0, qname);
+    }
+
+    //    protected IABCBytesRequestResult _handleABCBytesRequest(Operation buildPhase) throws InterruptedException
+    //    {
+    //        // If JSEmitter.needsSecondPass() returns true, JSGenerator.generate() will return null during scanning, 
+    //        // which will result in JSCompilationUnit::handleSemanticProblemsRequest not caching any abcBytes for 
+    //        // handleABCBytesRequest. The net result is that JSGenerator.generate() will be called again in handleABCBytesRequest. 
+    //        // This mechanic will ensure selective two-pass compilation. 
+    //        if (m_abcBytes != null &&
+    //            !JSSharedData.instance.hasSymbols() && // Symbol support
+    //            !JSSharedData.instance.hasAnyClassInit()) // support for class inits 
+    //            return m_abcBytes;
+    //
+    //        JSGenerator jsGenerator = new JSGenerator();
+    //        jsGenerator.m_compilationUnit = this;
+    //        jsGenerator.setBuildPhase(buildPhase);
+    //
+    //        // Need to force the file scope request to happen first to get the ASFileScope
+    //        // for this compilation unit registered with the project.
+    //        // ** TODO this is a hack!
+    //        getFileScopeRequest().get();
+    //
+    //        // This is also a hack!  If there are embed directives, need to ensure
+    //        // semantic pass has finished, as that is what will generate the embed classes
+    //        // which are needed by codegen
+    //        if (buildPhase != Operation.GET_SEMANTIC_PROBLEMS)
+    //        {
+    //        	// AJH this was deadlocking as getOutgoingDependencies calls handleABCBytes
+    //        	if (buildPhase != Operation.GET_ABC_BYTES)
+    //        		getOutgoingDependenciesRequest().get();
+    //        }
+    //
+    //        final ISyntaxTreeRequestResult fsr = getSyntaxTreeRequest().get();
+    //        final IASNode rootNode = fsr.getAST();
+    //
+    //        startProfile(buildPhase);
+    //        IABCBytesRequestResult result = jsGenerator.generate(getFilenameNoPath(), rootNode, this.getProject());
+    //        stopProfile(buildPhase);
+    //
+    //        m_needsSecondPass = jsGenerator.needsSecondPass();
+    //
+    //        return result;
+    //    }
+
+    //   @Override
+    //    protected IABCBytesRequestResult handleABCBytesRequest() throws InterruptedException
+    //    {
+    //        final IABCBytesRequestResult result = _handleABCBytesRequest(Operation.GET_ABC_BYTES);
+    //
+    //        /*
+    //         * // explicitly reference all classes this class depends on if(
+    //         * result.getProblems() == null || result.getProblems().length == 0 ) {
+    //         * final String code = new String( result.getABCBytes() ); if(
+    //         * code.contains(JSSharedData.REQUIRED_TAG_MARKER) ) { final
+    //         * ICompilationUnit cu = this; final Set<ICompilationUnit> deps = new
+    //         * HashSet<ICompilationUnit>(); deps.addAll(
+    //         * getProject().getDependencies(cu) ); if( !deps.isEmpty() ) { String
+    //         * depNames = ""; Boolean separator = false; final List<IDefinition>
+    //         * defs = MXMLJSC.getClassDefinitions( cu ); for( IDefinition def: defs
+    //         * ) { if( def instanceof ClassDefinition ) { final String defName =
+    //         * JSGeneratingReducer.createFullNameFromDefinition(def); if( defName !=
+    //         * null && !defName.isEmpty() ) { if( separator ) depNames += ":"; else
+    //         * separator = true; depNames += defName; } } }
+    //         * code.replaceFirst(JSSharedData.REQUIRED_TAG_MARKER, depNames); return
+    //         * new ABCBytesRequestResult(code.getBytes(), result.getProblems()); } }
+    //         * }
+    //         */
+    //        return result;
+    //    }
+
+    @Override
+    protected IOutgoingDependenciesRequestResult
+            handleOutgoingDependenciesRequest() throws InterruptedException
+    {
+        //        // Every CU is dependent on the class glue, which is implemented in browser.adobe.
+        //        // Add dependency from this JSCompilationUnit to browser.adobe's JSCompilationUnit.
+        //        addDependency(JSSharedData.JS_FRAMEWORK_NAME, DependencyType.INHERITANCE);
+        //        addDependency(JSSharedData.FRAMEWORK_CLASS, DependencyType.INHERITANCE);
+
+        IOutgoingDependenciesRequestResult result = super
+                .handleOutgoingDependenciesRequest();
+
+        //        // SWFTarget::startBuildAndFindAllCompilationUnits() is called by SWFTarget::collectProblems(), which is called by SWFTarget::addToSWF() in JSDriver::main().
+        //        // This is our first pass. jsGenerator.generate() will return null if JSGeneratingReducer.getMember 
+        //        // If JSEmitter.needsSecondPass() returns true, JSGenerator.generate() will return null during scanning, 
+        //        // which will result in JSCompilationUnit::handleSemanticProblemsRequest not caching any abcBytes for 
+        //        // handleABCBytesRequest. The net result is that JSGenerator.generate() will be called again in handleABCBytesRequest. 
+        //        // This mechanic will ensure selective two-pass compilation. 
+        //        if (result.getProblems().length == 0)
+        //        {
+        //            m_needsSecondPass = false;
+        //            m_abcBytes = _handleABCBytesRequest(Operation.GET_SEMANTIC_PROBLEMS);
+        //            if (m_needsSecondPass)
+        //                m_abcBytes = null;
+        //        }
+
+        return result;
+    }
+
+    public Boolean addDependency(String className, DependencyType dt)
+    {
+        //        if (JSGeneratingReducer.isReservedDataType(className))
+        //            return false;
+        //
+        //        final ICompilationUnit fromCU = this;
+        //        final CompilerProject compilerProject = this.getProject();
+        //        final ASProjectScope projectScope = compilerProject.getScope();
+        //
+        //        final IDefinition classDef = projectScope.findDefinitionByName(className);
+        //        if (classDef == null)
+        //            return false;
+        //
+        //        final ICompilationUnit toCU = projectScope.getCompilationUnitForDefinition(classDef);
+        //        if (fromCU == toCU)
+        //            return false;
+        //
+        //        // sharedData.verboseMessage( "Adding dependency: " + className );
+        //        compilerProject.addDependency(fromCU, toCU, dt);
+
+        return true;
+    }
+
+    @Override
+    public void startBuildAsync(TargetType targetType)
+    {
+        // super.startBuildAsync(targetType);
+
+        getSyntaxTreeRequest();
+        getFileScopeRequest();
+        getOutgoingDependenciesRequest();
+
+        //        // scanning and code generating phases need to be separated
+        //        // in order to create two distinct passes for m_needSecondPass.
+        //        if (m_inCodeGen)
+        //        {
+        //            getABCBytesRequest();
+        //            getSWFTagsRequest();
+        //        }
+    }
+
+    @Override
+    public void waitForBuildFinish(final Collection<ICompilerProblem> problems,
+            TargetType targetType) throws InterruptedException
+    {
+        m_inCodeGen = true;
+        super.waitForBuildFinish(problems, targetType);
+        m_inCodeGen = false;
+    }
+
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSCompilationUnit.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSSourceFileHandler.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSSourceFileHandler.java?rev=1421615&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSSourceFileHandler.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSSourceFileHandler.java Thu Dec 13 23:32:01 2012
@@ -0,0 +1,81 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.driver;
+
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.projects.DefinitionPriority;
+import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
+import org.apache.flex.compiler.internal.units.ASCompilationUnit;
+import org.apache.flex.compiler.units.ICompilationUnit;
+
+/**
+ * Implementation of ISourceFileHandler that constructs
+ * {@link ASCompilationUnit}'s. JSSourceFileHandler is the SourceFileHandler
+ * that provides JSCompilationUnit for *.as files. JSDriver registers
+ * JSSourceFileHandler at FlexApplicationProject. This implementation is part of
+ * FalconJS. For more details on FalconJS see org.apache.flex.compiler.JSDriver
+ */
+public final class JSSourceFileHandler implements ISourceFileHandler
+{
+
+    public static final String EXTENSION = "as"; //$NON-NLS-1$
+    public static final JSSourceFileHandler INSTANCE = new JSSourceFileHandler();
+
+    private JSSourceFileHandler()
+    {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String[] getExtensions()
+    {
+        return new String[] { EXTENSION };
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ICompilationUnit createCompilationUnit(CompilerProject proj,
+            String path, DefinitionPriority.BasePriority basePriority,
+            int order, String qname, String locale)
+    {
+        return new JSCompilationUnit(proj, path, basePriority, qname);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean needCompilationUnit(CompilerProject project, String path,
+            String qname, String locale)
+    {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean canCreateInvisibleCompilationUnit()
+    {
+        return false;
+    }
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/JSSourceFileHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/ASNodeHandler.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/ASNodeHandler.java?rev=1421615&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/ASNodeHandler.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/ASNodeHandler.java Thu Dec 13 23:32:01 2012
@@ -0,0 +1,56 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.driver.strategy;
+
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.visitor.IASNodeStrategy;
+
+/**
+ * @author Michael Schmalle
+ */
+public class ASNodeHandler implements IASNodeStrategy
+{
+    IASNodeStrategy handler;
+
+    public IASNodeStrategy getHandler()
+    {
+        return handler;
+    }
+
+    public void setHandler(IASNodeStrategy filtered)
+    {
+        this.handler = filtered;
+    }
+
+    public ASNodeHandler()
+    {
+    }
+
+    public ASNodeHandler(IASNodeStrategy filtered)
+    {
+        this.handler = filtered;
+    }
+
+    @Override
+    public void handle(IASNode node)
+    {
+        handler.handle(node);
+    }
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/ASNodeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/AfterNodeStrategy.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/AfterNodeStrategy.java?rev=1421615&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/AfterNodeStrategy.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/AfterNodeStrategy.java Thu Dec 13 23:32:01 2012
@@ -0,0 +1,68 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.driver.strategy;
+
+import org.apache.flex.compiler.internal.js.codgen.JSEmitter;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IContainerNode.ContainerType;
+import org.apache.flex.compiler.visitor.IASNodeStrategy;
+
+/**
+ * @author Michael Schmalle
+ */
+public class AfterNodeStrategy implements IASNodeStrategy
+{
+    private final JSEmitter emitter;
+
+    public AfterNodeStrategy(JSEmitter emitter)
+    {
+        this.emitter = emitter;
+    }
+
+    @Override
+    public void handle(IASNode node)
+    {
+        if (node.getNodeID() == ASTNodeID.BlockID)
+        {
+            IContainerNode container = (IContainerNode) node;
+            ContainerType type = container.getContainerType();
+            if (type != ContainerType.IMPLICIT
+                    && type != ContainerType.SYNTHESIZED)
+            {
+                if (node.getChildCount() != 0)
+                {
+                    emitter.indentPop();
+                    emitter.write("\n");
+                }
+                emitter.write("}");
+            }
+            else if (type == ContainerType.IMPLICIT
+                    || type == ContainerType.SYNTHESIZED)
+            {
+                if (node.getChildCount() != 0)
+                {
+                    emitter.indentPop();
+                }
+            }
+        }
+    }
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/AfterNodeStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeAfterStrategy.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeAfterStrategy.java?rev=1421615&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeAfterStrategy.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeAfterStrategy.java Thu Dec 13 23:32:01 2012
@@ -0,0 +1,84 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.driver.strategy;
+
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.visitor.IASNodeStrategy;
+
+/**
+ * @author Michael Schmalle
+ */
+public class BeforeAfterStrategy extends ASNodeHandler
+{
+    private IASNodeStrategy before;
+    
+    private IASNodeStrategy after;
+
+    public BeforeAfterStrategy()
+    {
+    }
+
+    public BeforeAfterStrategy(IASNodeStrategy filtered,
+            IASNodeStrategy before, IASNodeStrategy after)
+    {
+        super(filtered);
+        this.before = before;
+        this.after = after;
+    }
+
+    public void handle(IASNode element)
+    {
+        before(element);
+        super.handle(element);
+        after(element);
+    }
+
+    protected void after(IASNode element)
+    {
+        if (after != null)
+            after.handle(element);
+    }
+
+    protected void before(IASNode element)
+    {
+        if (before != null)
+            before.handle(element);
+    }
+
+    public IASNodeStrategy getBefore()
+    {
+        return before;
+    }
+
+    public void setBefore(IASNodeStrategy before)
+    {
+        this.before = before;
+    }
+
+    public IASNodeStrategy getAfter()
+    {
+        return after;
+    }
+
+    public void setAfter(IASNodeStrategy after)
+    {
+        this.after = after;
+    }
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeAfterStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeNodeStrategy.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeNodeStrategy.java?rev=1421615&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeNodeStrategy.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeNodeStrategy.java Thu Dec 13 23:32:01 2012
@@ -0,0 +1,68 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.driver.strategy;
+
+import org.apache.flex.compiler.internal.js.codgen.JSEmitter;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IContainerNode.ContainerType;
+import org.apache.flex.compiler.visitor.IASNodeStrategy;
+
+public class BeforeNodeStrategy implements IASNodeStrategy
+{
+
+    private final JSEmitter emitter;
+
+    public BeforeNodeStrategy(JSEmitter emitter)
+    {
+        this.emitter = emitter;
+    }
+
+    @Override
+    public void handle(IASNode node)
+    {
+        if (node.getNodeID() == ASTNodeID.BlockID)
+        {
+            IASNode parent = node.getParent();
+            IContainerNode container = (IContainerNode) node;
+            ContainerType type = container.getContainerType();
+
+            if (parent.getNodeID() != ASTNodeID.LabledStatementID)
+            {
+                if (node.getChildCount() != 0)
+                    emitter.indentPush();
+            }
+            
+            // switch cases are SYNTHESIZED
+            if (type != ContainerType.IMPLICIT
+                    && type != ContainerType.SYNTHESIZED)
+            {
+                emitter.write("{");
+            }
+
+            if (parent.getNodeID() != ASTNodeID.LabledStatementID)
+            {
+                emitter.write("\n");
+            }
+        }
+    }
+
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/strategy/BeforeNodeStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message