3

I'm looking for a way to mask specific code lines in the IDE. I prefer doing it in eclipse, but intellij would be fine also.

The purpose is, that when I have a method like this:

public String serialize() {
    log.info("Starting to serialize");
    StringBuilder sb = new StringBuilder();
    sb.append("name: " + this.name);
    sb.append("age: " + this.age);
    sb.append("sex: " + this.sex);

    log.info("Finished serializing. The result is: " + sb.toString());
    return sb.toString();
}

I will make it look like this:

public String serialize() {
    StringBuilder sb = new StringBuilder();
    sb.append("name: " + this.name);
    sb.append("age: " + this.age);
    sb.append("sex: " + this.sex);

    return sb.toString();
}

This is of course only an example. I work with code that contains a lot of log lines and a lot of metrics for better monitoring of the app. This clutters the code massively and I wish to only see code logic when I code.

Does either of the mentioned IDE (or another one) enable this feature?

Avi
  • 21,182
  • 26
  • 82
  • 121
  • 1
    Good idea! You can add a issue to the bugtracker. =) – Sergey Morozov Nov 14 '13 at 06:10
  • 1
    Logging and metrics sound like cross-cutting concerns. Could you use AOP to actually get those lines out of the code? – jaco0646 Nov 14 '13 at 06:12
  • @jaco0646 - I thought about it and we did a little POC. The problem is that it slows down to code in some nano-second. But because that's a big-data system with millions of hit per hour, it accumulates and it's problematic for us. Also, most of the times we need to use variables in the code to the log or use metrics according to sepcific paramters, which makes it very complicated for simple AOP to handle. – Avi Nov 14 '13 at 07:44
  • Shift-delete can easily mask a line of code. – vikingsteve Nov 14 '13 at 08:02
  • @vikingsteve - I don't want to delete it. I just don't want to see it. Also I want to do it for the whole project and not for a specific line. – Avi Nov 14 '13 at 09:18
  • Use Control-Z to see it again. – vikingsteve Nov 14 '13 at 12:14
  • Usually, code folding implies replacing the code by a single line. So in case of your example you don’t win anything. If you want to fold a single line to nothing you need to implement an entirely new algorithm instead of just adding a new folding rule. – Holger Nov 14 '13 at 13:21
  • http://stackoverflow.com/questions/12037188/create-collapsible-code-block-eclipse – Holger Nov 14 '13 at 13:27
  • @Holger - Thanks, but that indeed doesn't help because the reason you mentioned. I want to completely ignore these lines when I read my code. I'm think of an on/off button that hides these lines completely. I guess there would be better have some sort of a marker that those lines are there (as they still are part of the code). But I want to be able to read the code wittout them. – Avi Nov 14 '13 at 14:12

1 Answers1

0

That is which aspect oriented programming is for. This is a simple thing, only same programmer/marketing people gave it this flam name.

You should hook the serialize() function/method with your logging chunk. Quiet simple.

I suggest you start some googling for "AspectJ".

peterh
  • 11,875
  • 18
  • 85
  • 108
  • Hi MaXX and thanks for your answer. That was my initial approach. Please see my commend to Jaco0646 (The third comment on the question) to see why I'm looking for something else which is IDE oriented. – Avi Nov 14 '13 at 14:45