Specifically for editing Java code, I was wanting to know if I could change the colour of the text of any line of code beginning with the string LOG.
which indicates a logging statement.
In this example I would like to be able to make LOG
statement appear all in grey for example. It would help when reading code that is heavily logged.
public class Foo
{
private static final Logger LOG = LoggerFactory.getLogger(Foo.class);
public void doSomething() {
LOG.info("About to do something");
// code
}
}
It's probably more difficult than just identifying a single line, as logging could be split over multiple lines, and/or even contained within a if(LOG.isDebugEnabled) {...}
block.
Visualy I would like these LOG statements/blocks to appear like the default colouring of // comments /* */
To change the color of current selected lines (TEXT), follow these steps Eclipse-- In Eclipse: go to Windows -> preference-> General -> Editors -> Text Editors ->Appearance color options ->Selection foreground Color
Now that we have installed the color theme plugin, it is time to use this plugin and change the skin of Eclipse. Go to Menu->Windows->Preference: In the left sidebar, go to General->Appearance->Color Theme. When you select that, it will show you different available themes in the right pane. You can choose the one you like and press OK.
To change the color of current selected line background, follow these steps Eclipse-- In Eclipse: go to Windows -> preference-> General -> Editors -> Text Editors ->Appearance color options ->Selection Background Color.
The one you are after are probably in General -> Editors -> Text Editors ===> Then Appearance Color options -> Current line highlight & Selection background Share Improve this answer Follow answered Dec 28 '11 at 6:21
You can achieve the same by writing a eclipse custom plugin.
Eclipse works to color the syntex as per rule basis.
ITokenScanner scanner = new RuleBasedScanner();
IToken string = createToken(colorString);
IRule[] rules = new IRule[3];
// Add rule for double quotes
rules[0] = new SingleLineRule("\"", "\"", string, '\\');
// Add a rule for single quotes
rules[1] = new SingleLineRule("'", "'", string, '\\');
// Add generic whitespace rule.
rules[2] = new WhitespaceRule(whitespaceDetector);
scanner.setRules(rules);
scanner.setDefaultReturnToken(createToken(colorTag));
The createToken method instantiates a Token object for a particular color:
private IToken createToken(Color color) {
return new Token(new TextAttribute(color));
}
To proceed further to achieve the same you can refer to the Eclipse FAQ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With