Editing and formatting


  • Implemented formatter on new lexer.
  • 290 unit formatter/indent tests.
  • Supported formatting styles.
  • Supported formatting of active and not active code.

Not solved problems:

  • Formatter does not take into account macro expansion. If expansion contains key word or not balanced braces or parenthesis the formatting can be wrong.
  • Sometimes algorithm of formating #if-#else-#endif blocks is wrong. Need more clever algorithm. At least algorithm should detect dead branches and does not take it into account.
  • No reliable algorithm to differ unary/binary operators and binary/separators (+,-,*,&,<,>). Need code model support.

Plans for future improvement

  • Persist user defined styles. User view.
  • Detect and preserve style of repeated statement. Users like to wrap equality sign and end line comments.
  • Use code model abstract syntax tree for more accurate formatting.


Formatting active and not active code

#ifdef A
for (int i = 0; i < 2; i++) {

Dead code (technical comments for editor)

#if 0

Binary or part of type?

a * b;

Repeated statements

int A    = 10;      // This is an A
int A20  = 200;     // This is an A20
int A100 = A + A20; // This is an A100

Unbalanced brace in macro

#define FOR(n) for (int i = 0; i < n; i++) {


Status Whiteboard keyword: formatting

(click on the keyword above to get issues list)

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo