How to Define a Custom Annotation Processor

Friday 16 May 2014

What's Problem?

Now we have a new Automated Testing Framework, and we are adding cases to it. What we need is the number of cases we have added to it. These cases have case ID and some descriptions, we can use case ID to identify these cases in our code, by custom annotation, but how to get them?

 @CaseIDs(values = {
    public void testClient(String caseID, String clientID) throws Exception{"Entering "+ caseID + " as the first line...");
        if(actualResponse.getStatusCode() == RestConstants.HTTP_OK_200){
        } else{
        }"Leaving "+ caseID + " as the last line...");

How to deal with it?

We can use ADT to implement this feature. APT stands for Annotation Processing Tool. Sun shipped an API for APT in JDK 1.5. In JDK 6, the API was modified considerably and standardized through JSR-269, and the Sun implementation was built into the javac compiler rather than requiring a standalone tool.

So we can write our own annotation processor to process these annotations. Here are some reference:

Introduction to Annotation Processing in Eclipse

And bellowing is my code:


comments powered by Disqus