podam icon indicating copy to clipboard operation
podam copied to clipboard

Add support for setter methods not starting with set

Open krzysiekbr opened this issue 10 years ago • 6 comments

Most of classes I'm using in my project have setters starting with "with" keyword and returning "this". For now, if I understand it correctly, it's not possible for me to use Podam because it searches methods starting by "set" keyword and returning void (as per PodamUtils.java)

Is it possible to make Podam search for both of these method prefixes ("set" and "with") or make this prefix configurable?

krzysiekbr avatar Oct 24 '16 12:10 krzysiekbr

Yes, this is possible. You can implement your own version of ClassInfoStrategy or extend AbstractClassInfoStrategy overriding ClassInfoStrategy.getClassInfo(Class pojoClass) and feed this strategy to a Podam factory.

daivanov avatar Oct 24 '16 14:10 daivanov

7.0.1 snapshot available from here.

daivanov avatar Oct 25 '16 20:10 daivanov

Thanks for quick reaction. I wrote my own strategy implementation and it works like a charm.

krzysiekbr avatar Oct 26 '16 09:10 krzysiekbr

Thank you for pointing this out. I've changed AbstractClassInfoStrategy implementation so it's a bit easier to override:

    ClassInfoStrategy classInfoStrategy = new AbstractClassInfoStrategy() {
        @Override
        protected Pattern getGetterPattern() {
            return Pattern.compile("^whatIs");
        }

        @Override
        protected Pattern getSetterPattern() {
            return Pattern.compile("^with");
        }
    };
    PodamFactory factory = new PodamFactoryImpl();
    factory.setClassStrategy(classInfoStrategy);

daivanov avatar Oct 26 '16 10:10 daivanov

That makes everything much easier for me, thanks. When these changes can be released?

krzysiekbr avatar Oct 27 '16 12:10 krzysiekbr

Now Podam 7.0.1 is released, it will appear at some point at Maven repository.

daivanov avatar Oct 27 '16 18:10 daivanov