- A Concurrent Affair - https://www.concurrentaffair.org -

Still Working on Subtyped Annotation API

Just when I thought I had a complete working API for my annotations with subtyping, and after I had written a special version of my invariant checker that uses annotations with subtyping, I ran into some trouble with more complicated annotations that contain other annotations. For example:

@Not(@And({@Or({@ThreadWithName("foo"),
@ThreadWithName("bar")}),
@And({@EventThread,@SynchronizedThis})}))
public void testNotAndOrTwoAndTwo() {
System.out.println("testNotAndOrTwoAndTwo!");
}

Internally, the JVM instantiates these annotation classes using proxies, just like I do. These proxies are created at runtime and therefore, of course, do not have any associated class files. My API was still trying to find them and failing. I think I’ve got most of those issues fixed now, but the holidays have taken over, and I was also busy with DrJava for a few days.

I still need to write a few more tests. I’m already very happy with the way these invariant annotations look like. The annotation expressed above would probably have been several hundred lines of code before, just because there was no general way to perform Boolean AND and OR operations on any kind of invariant annotation. They pretty much had to be custom-written.

Now that I have been working a bit with proxies, I remembered the idea about the @DelegatesTo annotation [1] that I had a while back. I think proxies would make the implementation of that really simple. I still have to generate the interface, and the type checker of the Java compiler is still a problem, as explained in the original posting, but proxies would probably make all bytecode rewriting unnecessary. I could do it all using proxies and reflection. Again, I think it’s worth investigating.

[2] [3]Share [4]