Enforcing a coding template in the getters of a class in java

Posted by Yoav Schwartz on Stack Overflow See other posts from Stack Overflow or by Yoav Schwartz
Published on 2010-04-12T13:38:04Z Indexed on 2010/04/12 13:43 UTC
Read the original article Hit count: 410

Filed under:
|

Hello,

I want to make sure all getters of the classes in a certain package follow a given template.

For example, all getters must be of the form:

XXX getYYY(){
    classLock.lock(); 
    return YYY;
    finally{
        classLock.unlock(); 
    }
}

Basically, I want that my project will not compile/run unless all getters are of that form.

What is the best way to do that? I would prefer a solution that can be used as an Eclipse plugin.

Thanks, Yoav

© Stack Overflow or respective owner

Related posts about java

Related posts about code-analysis