public GeneratorBase createGenerator(GenDiagram diagram) {
   final GenEditorGenerator editorGen = diagram.getEditorGen();
   // using caching EmitterSource saves few seconds on test execution (115-118 compared to 112)
   // but it seems reasonable to avoid unpredictability of reuse (due to use of soft references)
   // and might be good idea to have separate test to test emitter reuse explicitly
   return new Generator(
       editorGen,
       new CodegenEmitters(
           !editorGen.isDynamicTemplates(),
           editorGen.getTemplateDirectory(),
           editorGen.getModelAccess() != null));
 }
 // CreateShortcut, LoadResource, InitDiagramFileAction
 public void testPredefinedActions() throws Exception {
   DiaGenSource s1 = createLibraryGen(false);
   final GenEditorGenerator editorGen = s1.getGenDiagram().getEditorGen();
   GenContextMenu menu = GMFGenFactory.eINSTANCE.createGenContextMenu();
   menu.getContext().add(s1.getGenDiagram());
   final CreateShortcutAction createShortcutAction =
       GMFGenFactory.eINSTANCE.createCreateShortcutAction();
   final LoadResourceAction loadResourceAction =
       GMFGenFactory.eINSTANCE.createLoadResourceAction();
   menu.getItems().add(createShortcutAction);
   menu.getItems().add(loadResourceAction);
   editorGen.getContextMenus().clear(); // make sure there's no other (default) menus
   editorGen.getContextMenus().add(menu);
   editorGen.getDiagram().getContainsShortcutsTo().add("ecore");
   assertTrue("sanity", editorGen.getDiagram().generateCreateShortcutAction());
   //
   generateAndCompile(s1);
   //
   IProject generatedProject =
       ResourcesPlugin.getWorkspace().getRoot().getProject(editorGen.getPlugin().getID());
   IFile generatedManifest = generatedProject.getFile("plugin.xml");
   assertTrue(generatedManifest.exists());
   DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
   Document parsedManifest = db.parse(new InputSource(generatedManifest.getContents()));
   XPath xf = XPathFactory.newInstance().newXPath();
   XPathExpression xe =
       xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution/command");
   NodeList result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
   assertEquals(2, result.getLength());
   xe = xf.compile("/plugin/extension[@point = 'org.eclipse.ui.commands']/command");
   result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
   assertTrue(result.getLength() > 2);
   HashSet<String> allCommands = new HashSet<String>();
   for (int i = result.getLength() - 1; i >= 0; i--) {
     allCommands.add(result.item(i).getAttributes().getNamedItem("defaultHandler").getNodeValue());
   }
   assertTrue(allCommands.contains(createShortcutAction.getQualifiedClassName()));
   assertTrue(allCommands.contains(loadResourceAction.getQualifiedClassName()));
   IFile file1 =
       generatedProject.getFile(
           "/src/" + createShortcutAction.getQualifiedClassName().replace('.', '/') + ".java");
   IFile file2 =
       generatedProject.getFile(
           "/src/" + loadResourceAction.getQualifiedClassName().replace('.', '/') + ".java");
   assertTrue(file1.exists());
   assertTrue(file2.exists());
   //
   //		DiaGenSource s2 = createLibraryGen(true);
   //		fail("TODO");
 }
 /** @generated NOT */
 public String getName() {
   String result = getNameGen();
   if (GenCommonBaseImpl.isEmpty(result)) {
     GenEditorGenerator generator = getEditorGen();
     if (generator != null) {
       String prefix = "Diagram Editor";
       GenModel genModel = generator.getDomainGenModel();
       if (genModel != null) {
         prefix = genModel.getModelName();
       }
       result = prefix + " Plugin";
     }
   }
   return result;
 }
  public void testGenModelTransform() {
    assertNotNull(
        "GenEditorGenerator is expected as result of mapping transformation",
        myTransformationResult);
    assertNotNull("GenDiagram is expected to be set...", myTransformationResult.getDiagram());
    assertNotNull(
        "... as well as GenPlugin is expected to be set", myTransformationResult.getPlugin());
    assertNotNull(
        "Diagram filename extension not set", myTransformationResult.getDiagramFileExtension());
    // FIXME add more

    GenNode[] genNodes = myTransformer.getTrace().find(getNodeMapping());
    assertEquals("Result model contains no GenNode for nodeMapping", 1, genNodes.length);
    // FIXME add more

    GenLink genLink = myTransformer.getTrace().find(getLinkMapping());
    assertNotNull("Result model contains no GenLink for linkMapping", genLink);
    // FIXME add more
  }
 // check CustomParser#isGenerateBoilerplate == true emits java class
 public void testCustomParsers() throws Exception {
   DiaGenSource s = createLibraryGen(false);
   final GenEditorGenerator gd = s.getGenDiagram().getEditorGen();
   CustomParser cp1 = GMFGenFactory.eINSTANCE.createCustomParser();
   cp1.setQualifiedName(gd.getLabelParsers().getImplPackageName() + "CustomParserOne");
   CustomParser cp2 = GMFGenFactory.eINSTANCE.createCustomParser();
   cp2.setQualifiedName(gd.getLabelParsers().getImplPackageName() + "CustomParserTwo");
   cp2.setGenerateBoilerplate(true);
   gd.getLabelParsers().getImplementations().add(cp1);
   gd.getLabelParsers().getImplementations().add(cp2);
   //
   generateAndCompile(s);
   //
   IProject generatedProject =
       ResourcesPlugin.getWorkspace().getRoot().getProject(gd.getPlugin().getID());
   IFile file_cp1 =
       generatedProject.getFile("/src/" + cp1.getQualifiedName().replace('.', '/') + ".java");
   IFile file_cp2 =
       generatedProject.getFile("/src/" + cp2.getQualifiedName().replace('.', '/') + ".java");
   assertFalse(file_cp1.exists());
   assertTrue(file_cp2.exists());
 }
  public void testCompileDynamicDomainModel() throws Exception {
    DiaGenSource s = createLibraryGen(false);
    final GenEditorGenerator editorGen = s.getGenDiagram().getEditorGen();
    assertNull("prereq", editorGen.getModelAccess());
    DynamicModelAccess dma = GMFGenFactory.eINSTANCE.createDynamicModelAccess();
    editorGen.setModelAccess(dma);
    generateAndCompile(
        s,
        new GenDiagramMutator("dynmodel") {

          @Override
          public void doMutation(GenDiagram d) {
            final DynamicModelAccess modelAccess = d.getEditorGen().getModelAccess();
            modelAccess.setClassName("NonDefaultDynamicAccessorName");
          }

          @Override
          public void undoMutation(GenDiagram d) {
            final DynamicModelAccess modelAccess = d.getEditorGen().getModelAccess();
            modelAccess.setClassName(null);
          }
        });
  }
 public void testCreatedPalette() {
   final Palette palette = myTransformationResult.getDiagram().getPalette();
   for (TopNodeReference topNode : getMapping().getNodes()) {
     final NodeMapping nodeMapping = topNode.getChild();
     GenTopLevelNode genNode = myTransformer.getTrace().findTopNode(nodeMapping);
     assertNotNull(genNode);
     assertEquals(nodeMapping.getTool() != null ? 1 : 0, countUses(genNode, palette));
   }
   for (LinkMapping linkMapping : getMapping().getLinks()) {
     GenLink genLink = myTransformer.getTrace().find(linkMapping);
     assertNotNull(genLink);
     assertEquals(linkMapping.getTool() != null ? 1 : 0, countUses(genLink, palette));
   }
   // TODO add grooping test
 }
示例#8
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public GenEditorGenerator getGMFGenEditorGenerator() {
   if (gmfGenEditorGenerator != null && gmfGenEditorGenerator.eIsProxy()) {
     InternalEObject oldGMFGenEditorGenerator = (InternalEObject) gmfGenEditorGenerator;
     gmfGenEditorGenerator = (GenEditorGenerator) eResolveProxy(oldGMFGenEditorGenerator);
     if (gmfGenEditorGenerator != oldGMFGenEditorGenerator) {
       if (eNotificationRequired()) {
         eNotify(
             new ENotificationImpl(
                 this,
                 Notification.RESOLVE,
                 DawnGmfGenmodelPackage.DAWN_GMF_GENERATOR__GMF_GEN_EDITOR_GENERATOR,
                 oldGMFGenEditorGenerator,
                 gmfGenEditorGenerator));
       }
     }
   }
   return gmfGenEditorGenerator;
 }
  public void testCustomActions() throws Exception {
    DiaGenSource s = createLibraryGen(false);
    final GenEditorGenerator editorGen = s.getGenDiagram().getEditorGen();
    GenContextMenu menu = GMFGenFactory.eINSTANCE.createGenContextMenu();
    GenCustomAction a1 = GMFGenFactory.eINSTANCE.createGenCustomAction();
    GenCustomAction a2 = GMFGenFactory.eINSTANCE.createGenCustomAction();
    GenCustomAction a3 = GMFGenFactory.eINSTANCE.createGenCustomAction();
    a1.setGenerateBoilerplate(false);
    a2.setGenerateBoilerplate(true);
    a3.setGenerateBoilerplate(true);
    a1.setQualifiedClassName("org.sample.actions.Action1");
    a2.setQualifiedClassName("org.sample.actions.Action2");
    a3.setQualifiedClassName("org.sample.actions.Action3");
    a1.setName("testaction-1");
    a2.setName("testaction-2");
    a3.setName("testaction-3");
    GenMenuManager subMenu = GMFGenFactory.eINSTANCE.createGenMenuManager();
    subMenu.setID("org.sample.submenu");
    GenGroupMarker gm = GMFGenFactory.eINSTANCE.createGenGroupMarker();
    gm.setGroupName("group.name");
    GenCommandAction cmdAction = GMFGenFactory.eINSTANCE.createGenCommandAction();
    cmdAction.setCommandIdentifier("org.sample.command");
    subMenu.getItems().add(a3);
    subMenu.getItems().add(gm);
    subMenu.getItems().add(cmdAction);
    menu.getItems().add(a1);
    menu.getItems().add(GMFGenFactory.eINSTANCE.createGenSeparator());
    menu.getItems().add(a2);
    menu.getItems().add(subMenu);
    editorGen.getContextMenus().clear(); // make sure there's no other (default) menus
    editorGen.getContextMenus().add(menu);
    //
    generateAndCompile(s);
    //
    IProject generatedProject =
        ResourcesPlugin.getWorkspace().getRoot().getProject(editorGen.getPlugin().getID());
    IFile generatedManifest = generatedProject.getFile("plugin.xml");
    assertTrue(generatedManifest.exists());
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document parsedManifest = db.parse(new InputSource(generatedManifest.getContents()));
    XPath xf = XPathFactory.newInstance().newXPath();
    XPathExpression xe =
        xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution");
    NodeList result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(
        2, result.getLength()); // one contribution to global context menu and another for submenu
    String l1 = result.item(0).getAttributes().getNamedItem("locationURI").getNodeValue();
    String l2 = result.item(1).getAttributes().getNamedItem("locationURI").getNodeValue();
    assertEquals(l1, "popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu");
    assertEquals(l2, "popup:" + subMenu.getID());
    //
    xe = xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution/menu");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(1, result.getLength());
    String menuIdAttr = result.item(0).getAttributes().getNamedItem("id").getNodeValue();
    assertEquals(subMenu.getID(), menuIdAttr);
    //
    xe = xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution/command");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(4, result.getLength());
    // FIXME assert command contribution goes into correct locationURI
    //
    xe =
        xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution/separator");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(2, result.getLength());
    //
    xe =
        xf.compile(
            "/plugin/extension[@point = 'org.eclipse.ui.commands']/command[starts-with(@name,'testaction-')]");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(3, result.getLength());
    //
    xe = xf.compile("/plugin/extension[@point = 'org.eclipse.ui.handlers']/handler");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(3, result.getLength());
    String h1 = result.item(0).getAttributes().getNamedItem("class").getNodeValue();
    String h2 = result.item(1).getAttributes().getNamedItem("class").getNodeValue();
    String h3 = result.item(2).getAttributes().getNamedItem("class").getNodeValue();
    assertEquals(a1.getQualifiedClassName(), h1);
    assertEquals(a2.getQualifiedClassName(), h2);
    assertEquals(a3.getQualifiedClassName(), h3);

    // check real files for handlers
    IFile file_a1 =
        generatedProject.getFile("/src/" + a1.getQualifiedClassName().replace('.', '/') + ".java");
    IFile file_a2 =
        generatedProject.getFile("/src/" + a2.getQualifiedClassName().replace('.', '/') + ".java");
    IFile file_a3 =
        generatedProject.getFile("/src/" + a3.getQualifiedClassName().replace('.', '/') + ".java");
    assertFalse(file_a1.exists());
    assertTrue(file_a2.exists());
    assertTrue(file_a3.exists());
  }