Search in sources :

Example 1 with ExmlModel

use of net.jangaroo.exml.model.ExmlModel 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 ExmlModel

use of net.jangaroo.exml.model.ExmlModel 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 ExmlModel

use of net.jangaroo.exml.model.ExmlModel 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 ExmlModel

use of net.jangaroo.exml.model.ExmlModel in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testParseUntyped.

@Test
public void testParseUntyped() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestUntyped.exml"));
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("items", new JsonArray(new JsonObject("xtype", "panel", "untyped", "text"), new JsonObject("xtype", "panel", "untyped", true), new JsonObject("xtype", "panel", "untyped", false), new JsonObject("xtype", "panel", "untyped", 1.0), new JsonObject("xtype", "panel", "untyped", -1.5), new JsonObject("xtype", "panel", "untyped", 3.0), new JsonObject("xtype", "panel", "untyped", "3L"), new JsonObject("xtype", "panel", "untyped", "42x")));
    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 ExmlModel

use of net.jangaroo.exml.model.ExmlModel in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testParseAllElements.

@Test
public void testParseAllElements() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/AllElements.exml"));
    Assert.assertEquals(new HashSet<String>(Arrays.asList("exmlparser.config.allElements", "ext.config.component", "ext.MessageBox", "ext.Panel")), model.getImports());
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    final List<Declaration> varDeclarations = model.getVars();
    Assert.assertEquals(3, varDeclarations.size());
    final Declaration myVar = varDeclarations.get(0);
    Assert.assertEquals("myVar", myVar.getName());
    Assert.assertEquals("String", myVar.getType());
    Assert.assertEquals("config.myProperty + '_suffix'", myVar.getValue());
    final Declaration myVar2 = varDeclarations.get(1);
    Assert.assertEquals("myVar2", myVar2.getName());
    Assert.assertEquals("Object", myVar2.getType());
    Assert.assertEquals("{\n" + "      prop: config.myProperty\n" + "    }", myVar2.getValue().replaceAll(System.getProperty("line.separator"), "\n"));
    final Declaration myVar3 = varDeclarations.get(2);
    Assert.assertEquals("myVar3", myVar3.getName());
    Assert.assertEquals("ext.config.component", myVar3.getType());
    Assert.assertEquals("ext.config.component({\n" + "      xtype: \"button\",\n" + "      text: \"Foo\"\n" + "    })", myVar3.getValue().replaceAll(System.getProperty("line.separator"), "\n"));
    final List<Declaration> constantDeclarations = model.getConfigClass().getConstants();
    Assert.assertEquals(3, constantDeclarations.size());
    final Declaration myConst1 = constantDeclarations.get(0);
    Assert.assertEquals("SOME_CONSTANT", myConst1.getName());
    Assert.assertEquals("1234", myConst1.getValue());
    Assert.assertEquals("uint", myConst1.getType());
    Assert.assertEquals("This is my <b>constant</b>", myConst1.getDescription().trim());
    final Declaration myConst2 = constantDeclarations.get(1);
    Assert.assertEquals("ANOTHER_CONSTANT", myConst2.getName());
    Assert.assertEquals("\"\\n      Lorem ipsum & Co.\\n      Another line.\\n    \"", myConst2.getValue());
    Assert.assertEquals("String", myConst2.getType());
    Assert.assertEquals("This is another <b>constant</b>", myConst2.getDescription().trim());
    final Declaration myConst3 = constantDeclarations.get(2);
    Assert.assertEquals("CODE_CONSTANT", myConst3.getName());
    Assert.assertEquals("1 + 1", myConst3.getValue());
    Assert.assertEquals("int", myConst3.getType());
    JsonObject expectedJsonObject = new JsonObject("layout", JsonObject.code("config.myLayout"), "title", "I am a panel", "someList", new JsonArray(new JsonObject("xtype", "button", "text", "click me!")), "defaults", new JsonObject("layout", "border"), "layoutConfig", new JsonObject("bla", "blub", "anchor", new JsonObject("style", "test"), "border", new JsonObject("type", "solid")), "items", new JsonArray(new JsonObject("xtype", "button", "text", "Save", "handler", JsonObject.code("function():void {\n" + "          window.alert('gotcha!');\n" + "        }"))), "menu", new JsonArray(new JsonObject("xtype", "menuitem", "text", "juhu1"), new JsonObject("xtype", "menuitem", "text", "juhu2"), new JsonObject("xtype", "menuitem", "text", "juhu3")), "tools", new JsonArray(new JsonObject("handler", JsonObject.code("function(x){return ''+x;}"), "id", "gear")), "plugins", new JsonArray(new JsonObject("ptype", "aplugin"), new JsonObject("ptype", "aplugin")), "layout2", new JsonObject("type", "a"));
    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) Declaration(net.jangaroo.exml.model.Declaration) Test(org.junit.Test)

Aggregations

ExmlModel (net.jangaroo.exml.model.ExmlModel)18 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 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 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 ConfigClass (net.jangaroo.exml.model.ConfigClass)1