You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2016/11/05 08:50:53 UTC
[11/23] git commit: [flex-falcon]
[refs/heads/feature-autobuild/example-maven-dirs] - - Greatly worked on
cleaning up the compiler code
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
index 491bdb1..d71543b 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
@@ -80,10 +80,9 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
public MXMLFlexJSPublisher(Configuration config, FlexJSProject project)
{
super(config);
-
- this.isMarmotinniRun = ((JSGoogConfiguration) configuration).getMarmotinni() != null;
+ this.isMarmotinniRun = googConfiguration.getMarmotinni() != null;
this.outputPathParameter = configuration.getOutput();
- this.useStrictPublishing = ((JSGoogConfiguration) configuration).getStrictPublish();
+ this.useStrictPublishing = googConfiguration.getStrictPublish();
this.project = project;
}
@@ -102,9 +101,10 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
// the output redirected to the directory it specifies.
// - If there is an -output switch, use that path as the
// output parent folder.
+ // FIXME: What is marmotinni?
if (isMarmotinniRun)
{
- outputParentFolder = new File(((JSGoogConfiguration) configuration).getMarmotinni());
+ outputParentFolder = new File(googConfiguration.getMarmotinni());
}
else if (outputPathParameter != null)
{
@@ -124,8 +124,9 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
// (erikdebruin) Marmotinni handles file management, so we
// bypass the setup.
- if (!isMarmotinniRun && !((JSGoogConfiguration)configuration).getSkipTranspile())
+ if (!isMarmotinniRun && !googConfiguration.getSkipTranspile()) {
setupOutputFolder();
+ }
return outputFolder;
}
@@ -133,30 +134,25 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
@Override
public boolean publish(ProblemQuery problems) throws IOException
{
- @SuppressWarnings("unused")
- boolean ok;
- // boolean subsetGoog = true;
-
- final String intermediateDirPath = outputFolder.getPath();
- final File intermediateDir = new File(intermediateDirPath);
- File srcDir = new File(configuration.getTargetFile());
- srcDir = srcDir.getAbsoluteFile();
- srcDir = srcDir.getParentFile();
+ final File intermediateDir = outputFolder;
+ File mainSourceFile = new File(configuration.getTargetFile());
+ File srcDir = mainSourceFile.getAbsoluteFile().getParentFile();
final String projectName = FilenameUtils.getBaseName(configuration.getTargetFile());
final String outputFileName = projectName + "." + JSSharedData.OUTPUT_EXTENSION;
File releaseDir = new File(outputParentFolder, FLEXJS_RELEASE_DIR_NAME);
- final String releaseDirPath = releaseDir.getPath();
+ //final String releaseDirPath = releaseDir.getPath();
+ // Ensure the release-dir is available and clean.
if (!isMarmotinniRun)
{
if (releaseDir.exists())
{
- org.apache.commons.io.FileUtils.deleteQuietly(releaseDir);
+ FileUtils.deleteQuietly(releaseDir);
}
- if (!configuration.debug())
+ if (configuration.release())
{
if (!releaseDir.mkdirs())
{
@@ -165,37 +161,22 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
}
}
- JSClosureCompilerWrapper compilerWrapper = new JSClosureCompilerWrapper(((JSGoogConfiguration) configuration).getJSCompilerOptions());
+ JSClosureCompilerWrapper compilerWrapper = new JSClosureCompilerWrapper(googConfiguration.getJSCompilerOptions());
- // If the closure-lib parameter is empty we'll try to find the resources
- // in the classpath, dump its content to the output directory and use
- // this
- // as closure-lib parameter.
- if (((JSGoogConfiguration) configuration).isClosureLibSet())
+ // If the closure lib dir is explicitly set, use that directory. If it
+ // is not set, check if its content is available in the classpath. If
+ // it is found in the classpath, dump it's content to the filesystem and
+ // pass the files in to the compiler directly.
+ if (googConfiguration.isClosureLibSet())
{
- closureLibDirPath = ((JSGoogConfiguration) configuration).getClosureLib();
+ closureLibDirPath = googConfiguration.getClosureLib();
}
else
{
// Check if the "goog/deps.js" is available in the classpath.
- URL resource = Thread.currentThread().getContextClassLoader().getResource("goog/deps.js");
- if (resource != null)
+ File closureLibraryJar = getJarThatContainsClasspathResources("goog/deps.js");
+ if (closureLibraryJar != null)
{
- // Strip the url of the parts we don't need.
- // Unless we are not using some insanely complex setup
- // the resource will always be on the same machine.
- String resourceJarPath = resource.getFile();
- resourceJarPath = URLDecoder.decode(resourceJarPath, "UTF-8");
- if (resourceJarPath.contains(":"))
- {
- resourceJarPath = resourceJarPath.substring(resourceJarPath.lastIndexOf(":") + 1);
- }
- if (resourceJarPath.contains("!"))
- {
- resourceJarPath = resourceJarPath.substring(0, resourceJarPath.indexOf("!"));
- }
- File resourceJar = new File(resourceJarPath);
-
// We don't want to add all files to the classpath, so we only output the
// resources contained in 'closure-whitelist.properites' to the output.
Properties whiteList = new Properties();
@@ -203,73 +184,38 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
"flexjs/closure-whitelist.properites"));
// Add the closure files from classpath.
- for(SourceFile sourceFile : addClasspathResources(resourceJar, whiteList)) {
+ for(SourceFile sourceFile : getClasspathResources(closureLibraryJar, whiteList)) {
compilerWrapper.addJSSourceFile(sourceFile);
// And dump a copy to the output directory (we will need them to execute the application)
- FileUtils.write(new File(new File(intermediateDirPath, "library/closure"),
+ FileUtils.write(new File(new File(intermediateDir, "library/closure"),
sourceFile.getName()), sourceFile.getCode());
}
+
+ // We won't be using the closure-lib dir in this case.
+ closureLibDirPath = new File(intermediateDir, "library").getCanonicalPath();
}
// Fallback to the default.
else
{
- closureLibDirPath = ((JSGoogConfiguration) configuration).getClosureLib();
+ closureLibDirPath = googConfiguration.getClosureLib();
}
}
-
- @SuppressWarnings("unused")
- String flexJsLibDirPath;
- // Check if the "FlexJS/src/createjs_externals.js" is available in the
- // classpath.
- URL resource = Thread.currentThread().getContextClassLoader().getResource("FlexJS/src/createjs_externals.js");
-
- // If it exists, dump FlexJS to the target directory.
- if (resource != null)
- {
- File flexJsLibDir = new File(intermediateDir.getParent(), "flexjs");
-
- // Only create and dump the content, if the directory does not
- // exists.
- if (!flexJsLibDir.exists())
- {
- if (!flexJsLibDir.mkdirs())
- {
- throw new IOException("Unable to create directory for flexjs-lib at "
- + flexJsLibDir.getAbsolutePath());
- }
-
- // Strip the url of the parts we don't need.
- // Unless we are not using some insanely complex setup
- // the resource will always be on the same machine.
- String resourceJarPath = resource.getFile();
- if (resourceJarPath.contains(":"))
- {
- resourceJarPath = resourceJarPath.substring(resourceJarPath.lastIndexOf(":") + 1);
- }
- if (resourceJarPath.contains("!"))
- {
- resourceJarPath = resourceJarPath.substring(0, resourceJarPath.indexOf("!"));
- }
- File resourceJar = new File(resourceJarPath);
- // Dump the closure lib from classpath.
- dumpJar(resourceJar, flexJsLibDir);
- }
- }
+ final File closureGoogSrcLibDir = new File(closureLibDirPath, "closure/goog/");
- final String projectIntermediateJSFilePath = intermediateDirPath + File.separator + outputFileName;
- final String projectReleaseJSFilePath = releaseDirPath + File.separator + outputFileName;
+ final File projectIntermediateJSFile = new File(intermediateDir, outputFileName);
+ final File projectReleaseJSFile = new File(releaseDir, outputFileName);
- if (!((JSGoogConfiguration)configuration).getSkipTranspile())
+ if (!googConfiguration.getSkipTranspile())
{
- appendExportSymbol(projectIntermediateJSFilePath, projectName);
- appendEncodedCSS(projectIntermediateJSFilePath, projectName);
+ appendEncodedCSS(projectIntermediateJSFile, projectName);
// if (!subsetGoog)
// {
// (erikdebruin) We need to leave the 'goog' files and dependencies well
// enough alone. We copy the entire library over so the
// 'goog' dependencies will resolve without our help.
+// TODO: Check if this is needed.
// FileUtils.copyDirectory(new File(closureGoogSrcLibDirPath), new File(closureGoogTgtLibDirPath));
// }
}
@@ -290,15 +236,15 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
InputStream is = fileEntry.createInputStream();
String code = IOUtils.toString(is, "UTF-8");
is.close();
- JarSourceFile sexternFile = new JarSourceFile(key, code,true);
+ JarSourceFile externFile = new JarSourceFile(key, code,true);
System.out.println("using extern: " + key);
- compilerWrapper.addJSExternsFile(sexternFile);
+ compilerWrapper.addJSExternsFile(externFile);
}
}
}
}
- GoogDepsWriter gdw = new GoogDepsWriter(intermediateDir, projectName, (JSGoogConfiguration) configuration, swcs);
+ GoogDepsWriter gdw = new GoogDepsWriter(intermediateDir, projectName, googConfiguration, swcs);
// Add all the js-files generated by the compiler to to config.
ArrayList<String> fileList = gdw.getListOfFiles(problems);
@@ -311,7 +257,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
project.needCSS = gdw.needCSS;
- // Copy static resources to the intermediate directory.
+ // Copy static resources to the intermediate (and release) directory.
IOFileFilter pngSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE,
FileFilterUtils.suffixFileFilter(".png"));
IOFileFilter gifSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE,
@@ -324,73 +270,66 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
jsonSuffixFilter);
IOFileFilter subdirs = FileFilterUtils.or(DirectoryFileFilter.DIRECTORY, assetFiles);
FileUtils.copyDirectory(srcDir, intermediateDir, subdirs);
- if (!configuration.debug()) {
+ if (configuration.release()) {
FileUtils.copyDirectory(srcDir, releaseDir, subdirs);
}
File template = ((JSGoogConfiguration)configuration).getHtmlTemplate();
if (!((JSGoogConfiguration)configuration).getSkipTranspile())
{
- if (template != null)
- writeTemplate(template, "intermediate", projectName, intermediateDirPath, depsFileData.toString(), gdw.additionalHTML);
- else
- writeHTML("intermediate", projectName, intermediateDirPath, depsFileData.toString(), gdw.additionalHTML);
+ if (template != null) {
+ writeTemplate(template, "intermediate", projectName, intermediateDir, depsFileData, gdw.additionalHTML);
+ } else {
+ writeHTML("intermediate", projectName, intermediateDir, depsFileData, gdw.additionalHTML);
+ }
}
- if (!configuration.debug())
+ if (configuration.release())
{
- if (template != null)
- writeTemplate(template, "release", projectName, releaseDirPath, depsFileData.toString(), gdw.additionalHTML);
- else
- writeHTML("release", projectName, releaseDirPath, null, gdw.additionalHTML);
+ if (template != null) {
+ writeTemplate(template, "release", projectName, releaseDir, depsFileData, gdw.additionalHTML);
+ } else {
+ writeHTML("release", projectName, releaseDir, null, gdw.additionalHTML);
+ }
}
if (project.needCSS || ((JSGoogConfiguration)configuration).getSkipTranspile())
{
- if (!((JSGoogConfiguration)configuration).getSkipTranspile())
- writeCSS(projectName, intermediateDirPath);
- if (!configuration.debug())
- FileUtils.copyFile(new File(intermediateDirPath + File.separator + projectName + ".css"),
- new File(releaseDirPath + File.separator + projectName + ".css"));
+ if (!((JSGoogConfiguration)configuration).getSkipTranspile()) {
+ writeCSS(projectName, intermediateDir);
+ }
+ if (configuration.release()) {
+ FileUtils.copyFile(new File(intermediateDir, projectName + ".css"),
+ new File(releaseDir, projectName + ".css"));
+ }
}
- if (!configuration.debug())
+ if (configuration.release())
{
-// sourceFiles.addAll(addDirectoryResources(new File(closureGoogSrcLibDirPath)));
+ List<SourceFile> sourceFiles = getDirectoryResources(closureGoogSrcLibDir);
// Add all SourceFiles to the compiler.
-/* for(SourceFile sourceFile : sourceFiles) {
+ for(SourceFile sourceFile : sourceFiles) {
compilerWrapper.addJSSourceFile(sourceFile);
}
-*/
- compilerWrapper.setOptions(projectReleaseJSFilePath, useStrictPublishing, projectName);
+ compilerWrapper.setOptions(projectReleaseJSFile.getCanonicalPath(), useStrictPublishing, projectName);
/*
* // (erikdebruin) Include the 'goog' deps to allow the compiler to
* resolve // dependencies. compilerWrapper.addJSSourceFile(
* closureGoogSrcLibDirPath + File.separator + "deps.js");
*/
- List<String> externs = ((JSGoogConfiguration) configuration).getExternalJSLib();
+ List<String> externs = googConfiguration.getExternalJSLib();
for (String extern : externs)
{
compilerWrapper.addJSExternsFile(extern);
}
- compilerWrapper.targetFilePath = projectReleaseJSFilePath;
+ compilerWrapper.targetFilePath = projectReleaseJSFile.getCanonicalPath();
compilerWrapper.compile();
- appendSourceMapLocation(projectReleaseJSFilePath, projectName);
+ appendSourceMapLocation(projectReleaseJSFile, projectName);
}
- /*
- * if (!isMarmotinniRun) { String allDeps = ""; if (!subsetGoog) {
- * allDeps += FileUtils.readFileToString(srcDeps); } allDeps +=
- * FileUtils.readFileToString(new File(depsTgtFilePath));
- *
- * FileUtils.writeStringToFile(srcDeps, allDeps);
- *
- * org.apache.commons.io.FileUtils.deleteQuietly(new
- * File(depsTgtFilePath)); }
- */
// if (ok)
System.out.println("The project '" + projectName + "' has been successfully compiled and optimized.");
@@ -398,26 +337,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
return true;
}
- /*
- * private void addDeps(ArrayList<DependencyRecord> subsetdeps,
- * HashMap<String, String> gotgoog, HashMap<String, DependencyRecord>
- * defmap, String deps) { if (deps.length() == 0) { return; }
- *
- * String[] deplist = deps.split(","); for (String dep : deplist) { dep =
- * dep.trim(); DependencyRecord deprec = defmap.get(dep); if
- * (!gotgoog.containsKey(deprec.path)) { gotgoog.put(deprec.path, null); //
- * put addDependencyLine in subset file subsetdeps.add(deprec);
- * addDeps(subsetdeps, gotgoog, defmap, deprec.deps); } } }
- */
-
- private void appendExportSymbol(String path, String projectName) throws IOException
- {
- //every file should already have exportsymbol
- //writeFile(path, "\n\n// Ensures the symbol will be visible after compiler renaming.\n" + "goog.exportSymbol('"
- // + projectName + "', " + projectName + ");\n", true);
- }
-
- private void appendEncodedCSS(String path, String projectName) throws IOException
+ private void appendEncodedCSS(File targetFile, String projectName) throws IOException
{
StringBuilder appendString = new StringBuilder();
appendString.append("\n\n");
@@ -432,17 +352,17 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
{
String reqs = s.substring(reqidx);
s = s.substring(0, reqidx - 1);
- String fileData = readCode(new File(path));
+ String fileData = readCode(targetFile);
reqidx = fileData.indexOf(JSGoogEmitterTokens.GOOG_REQUIRE.getToken());
String after = fileData.substring(reqidx);
String before = fileData.substring(0, reqidx - 1);
s = before + reqs + after + appendString.toString() + s;
- writeFile(path, s, false);
+ writeFile(targetFile, s, false);
}
else
{
appendString.append(s);
- writeFile(path, appendString.toString(), true);
+ writeFile(targetFile, appendString.toString(), true);
}
}
}
@@ -473,7 +393,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
return code;
}
- protected void writeTemplate(File template, String type, String projectName, String dirPath, String deps, List<String> additionalHTML)
+ protected void writeTemplate(File template, String type, String projectName, File targetDir, String deps, List<String> additionalHTML)
throws IOException
{
// Check if the template exists.
@@ -517,7 +437,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
String templateBody = getTemplateBody(projectName);
result = result.replaceAll("\\$\\{body\\}", templateBody);
- writeFile(dirPath + File.separator + ((JSGoogConfiguration) configuration).getHtmlOutputFileName(), result, false);
+ writeFile(new File(targetDir, googConfiguration.getHtmlOutputFileName()), result, false);
}
protected String getTemplateAdditionalHTML(List<String> additionalHTML)
@@ -564,7 +484,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
return bodyHTML.toString();
}
- protected void writeHTML(String type, String projectName, String dirPath, String deps, List<String> additionalHTML)
+ protected void writeHTML(String type, String projectName, File targetDir, String deps, List<String> additionalHTML)
throws IOException
{
StringBuilder htmlFile = new StringBuilder();
@@ -586,17 +506,17 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
htmlFile.append("</body>\n");
htmlFile.append("</html>");
- writeFile(dirPath + File.separator + ((JSGoogConfiguration) configuration).getHtmlOutputFileName(), htmlFile.toString(), false);
+ writeFile(new File(targetDir, googConfiguration.getHtmlOutputFileName()), htmlFile.toString(), false);
}
- private void writeCSS(String projectName, String dirPath) throws IOException
+ private void writeCSS(String projectName, File targetDir) throws IOException
{
JSCSSCompilationSession cssSession = (JSCSSCompilationSession) project.getCSSCompilationSession();
- writeFile(dirPath + File.separator + projectName + ".css", cssSession.emitCSS(), false);
+ writeFile(new File(targetDir, projectName + ".css"), cssSession.emitCSS(), false);
for (CSSFontFace fontFace : cssSession.fontFaces)
{
// check frameworks/fonts folder
- String configdir = ((JSGoogConfiguration) configuration).getLoadConfig();
+ String configdir = configuration.getLoadConfig();
File dir = new File(configdir);
dir = dir.getParentFile();
for (ICSSPropertyValue prop : fontFace.getSources())
@@ -614,8 +534,8 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
int c = fontPath.indexOf("?");
if (c != -1)
fontPath = fontPath.substring(0, c);
- File fontFile = new File(dir.getAbsolutePath() + File.separator + fontPath);
- File destFile = new File(dirPath + File.separator + fontPath);
+ File fontFile = new File(dir, fontPath);
+ File destFile = new File(targetDir, fontPath);
if (fontFile.exists())
{
if (!destFile.exists())
@@ -636,8 +556,8 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
int c = fontPath.indexOf("?");
if (c != -1)
fontPath = fontPath.substring(0, c);
- File fontFile = new File(dir.getAbsolutePath() + File.separator + fontPath);
- File destFile = new File(dirPath + File.separator + fontPath);
+ File fontFile = new File(dir, fontPath);
+ File destFile = new File(targetDir, fontPath);
if (fontFile.exists())
{
if (!destFile.exists())
@@ -648,4 +568,28 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
}
}
}
+
+ protected File getJarThatContainsClasspathResources(String resourcePath) {
+ URL resource = Thread.currentThread().getContextClassLoader().getResource(resourcePath);
+ if (resource != null) {
+ // Strip the url of the parts we don't need.
+ // Unless we are not using some insanely complex setup
+ // the resource will always be on the same machine.
+ String resourceJarPath = resource.getFile();
+ try {
+ resourceJarPath = URLDecoder.decode(resourceJarPath, "UTF-8");
+ if (resourceJarPath.contains(":")) {
+ resourceJarPath = resourceJarPath.substring(resourceJarPath.lastIndexOf(":") + 1);
+ }
+ if (resourceJarPath.contains("!")) {
+ resourceJarPath = resourceJarPath.substring(0, resourceJarPath.indexOf("!"));
+ }
+ return new File(resourceJarPath);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3724c2ff/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSDescriptorSpecifier.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSDescriptorSpecifier.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSDescriptorSpecifier.java
deleted file mode 100644
index 8fef083..0000000
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSDescriptorSpecifier.java
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- *
- * 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.mxml.vf2js;
-
-import java.util.ArrayList;
-
-import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
-import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLEventSpecifier;
-import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLNodeSpecifier;
-
-/**
- * @author Erik de Bruin
- */
-public class MXMLVF2JSDescriptorSpecifier extends MXMLNodeSpecifier
-{
-
- //--------------------------------------------------------------------------
- //
- // Constructor
- //
- //--------------------------------------------------------------------------
-
- public MXMLVF2JSDescriptorSpecifier()
- {
- super();
-
- eventSpecifiers = new ArrayList<MXMLEventSpecifier>();
- propertySpecifiers = new ArrayList<MXMLVF2JSDescriptorSpecifier>();
-
- valueNeedsQuotes = false;
- }
-
- //--------------------------------------------------------------------------
- //
- // Properties
- //
- //--------------------------------------------------------------------------
-
- //---------------------------------
- // children
- //---------------------------------
-
- public MXMLVF2JSDescriptorSpecifier childrenSpecifier;
-
- //---------------------------------
- // properties
- //---------------------------------
-
- public ArrayList<MXMLVF2JSDescriptorSpecifier> propertySpecifiers;
-
- //---------------------------------
- // events
- //---------------------------------
-
- public ArrayList<MXMLEventSpecifier> eventSpecifiers;
-
- //---------------------------------
- // hasArray
- //---------------------------------
-
- public boolean hasArray;
-
- //---------------------------------
- // id
- //---------------------------------
-
- public String id;
-
- //---------------------------------
- // isTopNode
- //---------------------------------
-
- public boolean isTopNode;
-
- //---------------------------------
- // isProperty
- //---------------------------------
-
- public boolean isProperty;
-
- //---------------------------------
- // parent
- //---------------------------------
-
- public MXMLVF2JSDescriptorSpecifier parent;
-
- //--------------------------------------------------------------------------
- //
- // Methods
- //
- //--------------------------------------------------------------------------
-
- //---------------------------------
- // outputEventSpecifier
- //---------------------------------
-
- @SuppressWarnings("unused")
- private void outputEventSpecifier(boolean writeNewline)
- {
- // number of events
- int count = 0;
- for (MXMLEventSpecifier me : eventSpecifiers)
- {
- if (me.name != null)
- count++;
- }
- write(count + "");
-
- for (MXMLEventSpecifier me : eventSpecifiers)
- {
- writeDelimiter(writeNewline);
- write(me.output(writeNewline));
- }
- }
-
- //---------------------------------
- // outputPropertySpecifier
- //---------------------------------
-
- private String outputPropertySpecifier(boolean writeNewline)
- {
- /*
- write((isProperty) ? ASEmitterTokens.SINGLE_QUOTE.getToken() : "");
- write(name);
- write((isProperty) ? ASEmitterTokens.SINGLE_QUOTE.getToken() : "");
- */
- //writeDelimiter(writeNewline);
-
- if (isProperty)
- {
- if (value != null)
- {
- write(ASEmitterTokens.THIS);
- write(ASEmitterTokens.MEMBER_ACCESS);
- write(parent.id);
- write(ASEmitterTokens.MEMBER_ACCESS);
- writeToken(name);
- writeToken(ASEmitterTokens.EQUAL);
- write(value);
- write(ASEmitterTokens.SEMICOLON);
- }
- else
- {
- //write((hasArray) ? ASEmitterTokens.NULL : ASEmitterTokens.FALSE);
- //writeDelimiter(writeNewline && !hasArray);
-
- //write(ASEmitterTokens.SQUARE_OPEN);
- output(false);
- //write(ASEmitterTokens.SQUARE_CLOSE);
- }
-
- if (parent != null)
- {
- //writeDelimiter(writeNewline);
- }
-
- writeNewline("");
- }
- else
- {
- write(ASEmitterTokens.THIS);
- write(ASEmitterTokens.MEMBER_ACCESS);
- writeToken(id);
- writeToken(ASEmitterTokens.EQUAL);
- writeToken(ASEmitterTokens.NEW);
- write(name);
- write(ASEmitterTokens.PAREN_OPEN);
- write(ASEmitterTokens.PAREN_CLOSE);
- write(ASEmitterTokens.SEMICOLON);
-
- for (MXMLVF2JSDescriptorSpecifier md : propertySpecifiers)
- {
- if (md.name != null && md.name.equals("mxmlContent"))
- {
- childrenSpecifier = md;
- propertySpecifiers.remove(md);
- break;
- }
- }
-
- /*
- if (id != null)
- {
- write(propertySpecifiers.size() + 1 + "");
- writeDelimiter(writeNewline);
- String idPropName = (id
- .startsWith(MXMLFlexJSEmitterTokens.ID_PREFIX.getToken())) ? "_id"
- : "id";
- writeSimpleDescriptor(idPropName, ASEmitterTokens.TRUE.getToken(),
- ASEmitterTokens.SINGLE_QUOTE.getToken()
- + id + ASEmitterTokens.SINGLE_QUOTE.getToken(),
- writeNewline);
-
- writeDelimiter(writeNewline);
- }
- else
- {
- write(propertySpecifiers.size() + "");
- writeDelimiter(writeNewline);
- }
- */
- writeNewline("");
-
- output(writeNewline);
-
- writeNewline("this." + id + ".render();");
- }
-
- return sb.toString();
- }
-
- //---------------------------------
- // outputStyleSpecifier
- //---------------------------------
-
- @SuppressWarnings("unused")
- private void outputStyleSpecifier(boolean writeNewline)
- {
- // TODO (erikdebruin) not yet implemented in FlexJS
-
- write("0");
- writeDelimiter(writeNewline);
- }
-
- //---------------------------------
- // output
- //---------------------------------
-
- @Override
- public String output(boolean writeNewline)
- {
- for (MXMLVF2JSDescriptorSpecifier md : propertySpecifiers)
- {
- write(md.outputPropertySpecifier(writeNewline));
- }
-
- /*
- if (isTopNode)
- {
- int count = 0;
- for (MXMLVF2JSDescriptorSpecifier md : propertySpecifiers)
- {
- if (md.name != null)
- count++;
- }
-
- write(count + "");
- writeNewline(ASEmitterTokens.COMMA);
- }
-
- MXMLVF2JSDescriptorSpecifier model = null; // model goes first
- MXMLVF2JSDescriptorSpecifier beads = null; // beads go last
-
- for (MXMLVF2JSDescriptorSpecifier md : propertySpecifiers)
- {
- if (md.name != null && md.name.equals("model"))
- {
- model = md;
-
- break;
- }
- }
-
- if (model != null)
- write(model.outputPropertySpecifier(true));
-
- for (MXMLVF2JSDescriptorSpecifier md : propertySpecifiers)
- {
- if (md.name != null)
- {
- if (!md.name.equals("model") && !md.name.equals("beads"))
- write(md.outputPropertySpecifier(writeNewline));
- else if (md.name.equals("beads"))
- beads = md;
- }
- }
-
- if (beads != null)
- write(beads.outputPropertySpecifier(writeNewline));
-
- if (!isProperty)
- {
- outputStyleSpecifier(writeNewline);
-
- // TODO (erikdebruin) not yet implemented in FlexJS
- //outputEffectSpecifier(writeNewline);
-
- outputEventSpecifier(writeNewline);
-
- if (!isTopNode)
- {
- writeDelimiter(writeNewline);
-
- if (childrenSpecifier == null)
- write(ASEmitterTokens.NULL);
- else
- outputChildren(childrenSpecifier, writeNewline);
- }
-
- boolean isLastChild = parent != null
- && parent.propertySpecifiers.indexOf(this) == parent.propertySpecifiers
- .size() - 1;
-
- if (!isLastChild && !isTopNode)
- writeDelimiter(writeNewline);
- }
- //*/
-
- return sb.toString();
- }
-
- @SuppressWarnings("unused")
- private void outputChildren(MXMLVF2JSDescriptorSpecifier children, boolean writeNewline)
- {
- write(ASEmitterTokens.SQUARE_OPEN.getToken());
- write(children.output(false));
- write(ASEmitterTokens.SQUARE_CLOSE.getToken());
- }
-
-}