Search in sources :

Example 1 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlToMxml method exmlToMxml.

private File exmlToMxml(ExmlSourceFile exmlSourceFile) throws IOException, SAXException {
    ExmlModel exmlModel = new ExmlToModelParser(configClassRegistry).parse(exmlSourceFile.getSourceFile());
    File sourceFile = exmlSourceFile.getSourceFile();
    File outputFile = CompilerUtils.fileFromQName(exmlSourceFile.getTargetClassName(), configClassRegistry.getConfig().getSourcePath().get(0), ".mxml");
    FileUtils.forceMkdir(outputFile.getParentFile());
    PrintStream writer = new PrintStream(new FileOutputStream(outputFile), true, net.jangaroo.exml.api.Exmlc.OUTPUT_CHARSET);
    ExmlToConfigClassParser.parseFileWithHandler(sourceFile, new ExmlToMxmlHandler(exmlSourceFile, exmlModel, writer));
    return outputFile;
}
Also used : PrintStream(java.io.PrintStream) ExmlModel(net.jangaroo.exml.model.ExmlModel) FileOutputStream(java.io.FileOutputStream) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) ExmlSourceFile(net.jangaroo.exml.model.ExmlSourceFile) File(java.io.File)

Example 2 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlComponentClassGeneratorTest method testGenerateClassWithLowerCaseFileName.

@Test
public void testGenerateClassWithLowerCaseFileName() throws Exception {
    setUp("exmlparser.config");
    File sourceFile = getFile("/exmlparser/testLowerCase.exml");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(sourceFile);
    Assert.assertEquals("TestLowerCase", model.getClassName());
    Assert.assertEquals("testLowerCase", model.getConfigClass().getName());
    Assert.assertEquals("exmlparser", model.getPackageName());
}
Also used : ExmlModel(net.jangaroo.exml.model.ExmlModel) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) ExmlSourceFile(net.jangaroo.exml.model.ExmlSourceFile) File(java.io.File) Test(org.junit.Test)

Example 3 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlComponentClassGeneratorTest method testGenerateClass.

@Test
public void testGenerateClass() throws Exception {
    setUp("exmlparser.config");
    String expected = FileUtils.readFileToString(new File(getClass().getResource("/expected/AllElements.as").toURI()));
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/AllElements.exml"));
    StringWriter output = new StringWriter();
    new ExmlComponentClassGenerator(getExmlc().getConfig()).generateClass(model, output);
    Assert.assertEquals(expected, output.toString());
}
Also used : StringWriter(java.io.StringWriter) ExmlModel(net.jangaroo.exml.model.ExmlModel) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) ExmlComponentClassGenerator(net.jangaroo.exml.generator.ExmlComponentClassGenerator) ExmlSourceFile(net.jangaroo.exml.model.ExmlSourceFile) File(java.io.File) Test(org.junit.Test)

Example 4 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testParseArrayAttribute.

@Test
public void testParseArrayAttribute() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestArrayAttribute.exml"));
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("items", JsonObject.code("config.myItems"), "tools", new JsonArray("tools"));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getJsonObject().toString(2));
}
Also used : JsonArray(net.jangaroo.exml.json.JsonArray) ExmlModel(net.jangaroo.exml.model.ExmlModel) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Example 5 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testConfigDefaultValues.

@Test
public void testConfigDefaultValues() throws Exception {
    setUp("testNamespace.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/testPackage/TestComponentWithCfgDefaults.exml"));
    List<ConfigAttribute> cfgs = model.getConfigClass().getDirectCfgs();
    Assert.assertEquals(9, cfgs.size());
    JsonObject expectedJsonObject = new JsonObject("propertyWithLiteralDefault", "foobar", "propertyWithExpressionDefault", JsonObject.code("'foo' + 'bar'"), "propertyWithDefaultElement", new JsonObject("xtype", "button", "text", "click me!"), "propertyWithDefaultElementUsingConfig", new JsonObject("xtype", "button", "text", JsonObject.code("config.title + '!'")), "arrayPropertyWithDefaultElement", new JsonArray(new JsonObject("xtype", "button", "text", "button1"), new JsonObject("xtype", "button", "text", "button2")), "propertyWithInterfaceAndDefault", JsonObject.code(" new TestImpl() "), "propertyFromOtherPackage", JsonObject.code(" new SomeOtherClass('lala') "));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getCfgDefaults().toString(2));
}
Also used : JsonArray(net.jangaroo.exml.json.JsonArray) ExmlModel(net.jangaroo.exml.model.ExmlModel) ConfigAttribute(net.jangaroo.exml.model.ConfigAttribute) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Aggregations

ExmlModel (net.jangaroo.exml.model.ExmlModel)17 ExmlToModelParser (net.jangaroo.exml.parser.ExmlToModelParser)17 Test (org.junit.Test)16 JsonObject (net.jangaroo.exml.json.JsonObject)11 JsonArray (net.jangaroo.exml.json.JsonArray)10 File (java.io.File)4 ExmlSourceFile (net.jangaroo.exml.model.ExmlSourceFile)4 Declaration (net.jangaroo.exml.model.Declaration)2 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 ExmlComponentClassGenerator (net.jangaroo.exml.generator.ExmlComponentClassGenerator)1 ConfigAttribute (net.jangaroo.exml.model.ConfigAttribute)1