net.jangaroo.exml.tools.ExtAsApi Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ext-as-api-generator Show documentation
Show all versions of ext-as-api-generator Show documentation
parses an EXML and generates an AS config class
package net.jangaroo.exml.tools;
import net.jangaroo.jooc.CompilerError;
import net.jangaroo.jooc.JangarooParser;
import net.jangaroo.jooc.StdOutCompileLog;
import net.jangaroo.jooc.api.CompileLog;
import net.jangaroo.jooc.ast.CompilationUnit;
import net.jangaroo.jooc.backend.ApiModelGenerator;
import net.jangaroo.jooc.config.ParserOptions;
import net.jangaroo.jooc.config.SemicolonInsertionMode;
import net.jangaroo.jooc.input.InputSource;
import net.jangaroo.jooc.input.PathInputSource;
import net.jangaroo.jooc.model.CompilationUnitModel;
import net.jangaroo.jooc.model.CompilationUnitModelRegistry;
import net.jangaroo.jooc.util.MessageFormat;
import net.jangaroo.utils.CompilerUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* A tool to getParser a given Ext AS API and build a model of it.
*/
public class ExtAsApi {
private Properties extJsNameMappingProperties = new Properties();
private final ApiModelGenerator apiModelGenerator;
private JangarooParser jangarooParser;
private CompilationUnitModelRegistry compilationUnitModelRegistry;
public ExtAsApi(Properties extJsNameMappingProperties, String jangarooRuntimeVersion, String jangarooLibsVersion) throws IOException {
this.extJsNameMappingProperties = extJsNameMappingProperties;
jangarooParser = getParser(jangarooRuntimeVersion, jangarooLibsVersion);
compilationUnitModelRegistry = new CompilationUnitModelRegistry();
apiModelGenerator = new ApiModelGenerator(false);
}
private static JangarooParser getParser(String jangarooRuntimeVersion, String jangarooLibsVersion) {
return getParser(Arrays.asList(
getMavenArtifact("net.jangaroo", "jangaroo-runtime", jangarooRuntimeVersion, null),
getMavenArtifact("net.jangaroo", "jangaroo-browser", jangarooLibsVersion, null)
),
getMavenArtifact("net.jangaroo", "ext-as", jangarooLibsVersion, "sources"),
new StdOutCompileLog());
}
public List getCompilationUnitModels(String newName) {
List result = new ArrayList();
for (String qName : getReferenceQNames(newName)) {
CompilationUnitModel compilationUnitModel = compilationUnitModelRegistry.resolveCompilationUnit(qName);
if (compilationUnitModel == null) {
CompilationUnit compilationUnit = jangarooParser.getCompilationUnit(qName);
if (compilationUnit != null && compilationUnit.isInSourcePath()) {
compilationUnit.analyze(null);
try {
compilationUnitModel = apiModelGenerator.generateModel(compilationUnit);
compilationUnitModelRegistry.register(compilationUnitModel);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (compilationUnitModel != null) {
result.add(compilationUnitModel);
}
}
return result;
}
private boolean isQualifiedName(String qName) {
return compilationUnitModelRegistry.resolveCompilationUnit(qName) != null ||
jangarooParser.getCompilationUnit(qName) != null;
}
public String getMappedQName(String originalQName) {
return originalQName == null ? null : extJsNameMappingProperties.getProperty(originalQName, originalQName);
}
public List getReferenceQNames(String newQName) {
if (newQName == null) {
return null;
}
List result = new ArrayList();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy