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?
+2
A:
Eclipse can generate toString()
, which includes a print out of all fields and their string values, if that's what you are after.
suihock
2010-04-11 09:02:54
+3
A:
Assuming you're talking about Java > Editor > Templates
a reference (maybe outdated) is here
This SO question useful-eclipse-java-code-templates containes some examples.
To iterate over class members using a toString() style generator you may find this useful: toString() Generator: Format Templates
stacker
2010-04-11 10:25:09
The link 'useful-eclipse-java-code-templates' just loops back to this question for me. I think the link was meant to go here: http://stackoverflow.com/questions/1028858/useful-eclipse-java-code-templates.
Bert F
2010-04-11 12:15:13
@Bert F - Thanks I fixed it
stacker
2010-04-11 15:06:56
@stacker - do you like my answer below?
fastcodejava
2010-10-08 19:20:49
+2
A:
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());
}
fastcodejava
2010-10-08 18:48:00