Search code examples
javaeclipsetemplatescode-templates

Loop over fields in eclipse code template


Can you do loops in code templates, e.g I want to print all the fields in a class. Is there a template for that?


Solution

  • Since I didn't find what I was looking for, I put it in my plugin. It supports variations. If you have class called Company with fields companyName, companyType, etc. it will generate print statements as shown below if you select logger.debug variation :

    if (logger.isDebugEnabled()) {
        logger.debug("Company Name " + company.getCompanyName());
        logger.debug("Company Type " + company.getCompanyType());
    }
    

    template-variation