Example #1
0
 public void visit(NormalAnnotationExpr n, Object arg) {
   n.getName().accept(this, arg);
   for (Iterator<MemberValuePair> i = n.getPairs().iterator(); i.hasNext(); ) {
     MemberValuePair m = i.next();
     m.accept(this, arg);
     if (i.hasNext()) {}
   }
 }
 public void visit(NormalAnnotationExpr n, A arg) {
   n.getName().accept(this, arg);
   if (n.getPairs() != null) {
     for (MemberValuePair m : n.getPairs()) {
       m.accept(this, arg);
     }
   }
 }
Example #3
0
  @Test
  public void testUpdateAnnotation() throws Exception {
    CompilerAssert<File, File> helper = compiler("metamodel.tag");
    helper.assertCompile();

    //
    JavaFile file = helper.assertSource("metamodel", "tag", "package-info.java");
    PackageDeclaration a = file.assertPackage();
    NormalAnnotationExpr applicationDecl = (NormalAnnotationExpr) a.getAnnotations().get(0);
    NormalAnnotationExpr tagDecl =
        (NormalAnnotationExpr) applicationDecl.getPairs().get(0).getValue();
    boolean changed = false;
    for (MemberValuePair pair : tagDecl.getPairs()) {
      if (pair.getName().equals("path")) {
        pair.setValue(new StringLiteralExpr("bar.gtmpl"));
        changed = true;
      }
    }
    assertTrue(changed);
    file.assertSave();

    //
    File ser = helper.getSourceOutput().getPath("juzu", "metamodel.ser");
    MetaModelState unserialize = Tools.unserialize(MetaModelState.class, ser);
    ModuleMetaModel mm = (ModuleMetaModel) unserialize.metaModel;
    mm.getQueue().clear();
    Tools.serialize(unserialize, ser);

    //
    helper.addClassPath(helper.getClassOutput()).assertCompile();
    unserialize = Tools.unserialize(MetaModelState.class, ser);
    mm = (ModuleMetaModel) unserialize.metaModel;
    List<MetaModelEvent> events = mm.getQueue().clear();
    assertEquals(3, events.size());
    assertEquals(MetaModelEvent.BEFORE_REMOVE, events.get(0).getType());
    assertInstanceOf(TemplateMetaModel.class, events.get(0).getObject());
    assertEquals(
        Path.parse("/metamodel/tag/tags/foo.gtmpl"),
        ((TemplateMetaModel) events.get(0).getObject()).getPath());
    assertEquals(MetaModelEvent.AFTER_ADD, events.get(1).getType());
    assertInstanceOf(TemplateMetaModel.class, events.get(1).getObject());
    assertEquals(
        Path.parse("/metamodel/tag/tags/bar.gtmpl"),
        ((TemplateMetaModel) events.get(1).getObject()).getPath());
    assertEquals(MetaModelEvent.UPDATED, events.get(2).getType());
    assertInstanceOf(ApplicationMetaModel.class, events.get(2).getObject());
  }
Example #4
0
 public void visit(MemberValuePair n, Object arg) {
   n.getValue().accept(this, arg);
 }