Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JDT macro auto expand
JDT macro auto expand [message #230653] Tue, 06 June 2006 03:16
wushilin is currently offline wushilinFriend
Messages: 1
Registered: July 2009
Junior Member
I think logging line number, method name, class name is very useful.
However, infering these informations in log4j is very slow.

We can write some code like this:

1: import org.apache.log4j.Logger;
2: public class Test {
3: public String className = "Test";
4: public static Logger log = Logger.getLogger(Test.class);
5: public void foo() {
6: String methodName = "foo";
7: int lineNumber = 7;
8: log.info(methodName, lineNumber, "Hi there!") ;
9: }
10: public void info(String methodName, int lineNumber, Object msg) {
11: log.info(className + "." + methodName + "(" + lineNumber + "):"
12: + msg);
13: }
14:}

However, as we progress, the line number/class name/method name got
changed
and it become more difficult to maintain that information.

Since jdt already have macros like $NON-NLS$, ${enclosing_method},
${enclosing_type} we can simply add some macro that could be auto expanded
upon save/load.

eg,
instead of
int lineNumber = 7;

we could write
/* JDT_MACRO:int lineNumber = ${line_number}; */


in other words, the program could be:

1: import org.apache.log4j.Logger;
2: public class Test {
3: /* JDT_MACRO:public String className = "${enclosing_type}"; */
4: public String className = "Test"; //Changed to Test automatically
5: public static Logger log = Logger.getLogger(Test.class);
6: public void foo() {
7: /* JDT_MACRO:String methodName = "${enclosing_method}"; */
8: String methodName = "foo";//Changed to Test automatically
9: /* JDT_MACRO:int lineNumber = "${line_number}"; */
10: int lineNumber = 10; //changed to 10 automatically
11: log.info(methodName, lineNumber, "Hi there!") ;
12: }
13: public void info(String methodName, int lineNumber, Object msg) {
14: log.info(className + "." + methodName + "(" + lineNumber + "):"
15: + msg);
16: }
17:}

and when file is loaded/saved, jdt add the line:
int lineNumber = 7;
below the macro line, or, if it exists, replace it.


This could applied to class name, date, method name and all existing
macros also.

Regards
Previous Topic:Leather Java Coat
Next Topic:Problems view displayed as a Table-Tree ...
Goto Forum:
  


Current Time: Sat Jul 13 16:43:26 GMT 2024

Powered by FUDForum. Page generated in 0.02345 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top