简体   繁体   中英

using java annotations in rythm template engine

In the quest of getting JUnit tests to be part of how we use Ryhtm we came up with the code snippet below. All went well until we added

@Test

which obviously is a java annotation and uses the @ marker as a syntax element that is also being used by Rythm. How can the desired effect be achieved to get the @annotation? To simply escape the @@ does not work it gives a

Syntax error on token "@", delete this token

error. So How can a Java @ annotation be used ?

I have also filed this as a bug report at https://github.com/greenlaw110/Rythm/issues/285

@// This is a rythm template
@import static org.junit.Assert.*
@import org.junit.Test.*
@def static {
  class TestMe {
    String name;
    @Test
    public void testMe() {
      name="test";
      assertEquals("test",name);
    }
  }
}
@{
  TestMe testme=new TestMe();
  testme.name="testme";
}
The TestMe has the name @(testme.name)

如果您使用完全合格的注释,则它应该起作用:

 @org.junit.Test

模板代码中的@import org.junit.Test.*应该是@import org.junit.Test ,请注意.*需要@import org.junit.Test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM