patternjavaCritical
Seeking useful Eclipse Java code templates
Viewed 0 times
templatesseekingjavausefuleclipsecode
Problem
You can create various Java code templates in Eclipse via
Window > Preferences > Java > Editor > Templates
e.g.
You can activate this by typing
What useful Java code templates do you currently use? Include the name and description of it and why it's awesome.
I am looking for an original/novel use of a template rather than a built-in existing feature.
Window > Preferences > Java > Editor > Templates
e.g.
sysout is expanded to:System.out.println(${word_selection}${});${cursor}You can activate this by typing
sysout followed by CTRL+SPACEWhat useful Java code templates do you currently use? Include the name and description of it and why it's awesome.
I am looking for an original/novel use of a template rather than a built-in existing feature.
- Create Log4J logger
- Get swt color from display
- Syncexec - Eclipse Framework
- Singleton Pattern/Enum Singleton Generation
- Readfile
- Const
- Traceout
- Format String
- Comment Code Review
- String format
- Try Finally Lock
- Message Format i18n and log
- Equalsbuilder
- Hashcodebuilder
- Spring Object Injection
- Create FileOutputStream
Solution
The following code templates will both create a logger and create the right imports, if needed.
SLF4J
Log4J 2
Log4J
Source.
JUL
SLF4J
${:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}
private static final Logger LOG = LoggerFactory.getLogger(${enclosing_type}.class);Log4J 2
${:import(org.apache.logging.log4j.LogManager,org.apache.logging.log4j.Logger)}
private static final Logger LOG = LogManager.getLogger(${enclosing_type}.class);Log4J
${:import(org.apache.log4j.Logger)}
private static final Logger LOG = Logger.getLogger(${enclosing_type}.class);Source.
JUL
${:import(java.util.logging.Logger)}
private static final Logger LOG = Logger.getLogger(${enclosing_type}.class.getName());Code Snippets
${:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}
private static final Logger LOG = LoggerFactory.getLogger(${enclosing_type}.class);${:import(org.apache.logging.log4j.LogManager,org.apache.logging.log4j.Logger)}
private static final Logger LOG = LogManager.getLogger(${enclosing_type}.class);${:import(org.apache.log4j.Logger)}
private static final Logger LOG = Logger.getLogger(${enclosing_type}.class);${:import(java.util.logging.Logger)}
private static final Logger LOG = Logger.getLogger(${enclosing_type}.class.getName());Context
Stack Overflow Q#1028858, score: 428
Revisions (0)
No revisions yet.