This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I have created new code template with following content: $$query = " SELECT ${table1}.${field1} AS ${field1}, ${table2}.${field2} AS ${field2} FROM ${table1} INNER JOIN ${table2} ON ${table2}.${foreignKey2} = ${table1}.${primaryKey1} WHERE ${table1}.${primaryKey1} = ${primaryKeyValue} AND ${otherConditions} ORDER BY ${table1}.${primaryKey1} ASC LIMIT ${offset}, ${row_count} "; This template works ok when I am in plain script with no indention. But when I run my template under a method of a class, it gets indented wrong: $query = " SELECT table1.field1 AS field1, table2.field2 AS field2 FROM table1 INNER JOIN table2 ON table2.foreignKey2 = table1.primaryKey1 WHERE table1.primaryKey1 = primaryKeyValue AND otherConditions ORDER BY table1.primaryKey1 ASC LIMIT offset, row_count "; The probably is probably in automatic formatting that is applied.
Yes the formatter is applied after inserting the template. The problem is that it is not possible to format a string (inside). Very often the white spaces in the string are important and the formatter shouldn't change them. I know, in this case it would be reasonable, but there is now way how to distinguish, which string format and which not. For this case there can be a work around like: $$query = "SELECT \n" . " ${table1}.${field1} AS ${field1},\n" . " ${table2}.${field2} AS ${field2}\n" . " FROM ${table1}\n" . " INNER JOIN ${table2}\n" . " ON ${table2}.${foreignKey2} = ${table1}.${primaryKey1}\n" . " WHERE ${table1}.${primaryKey1} = ${primaryKeyValue}\n" . " AND ${otherConditions}\n" . " ORDER BY ${table1}.${primaryKey1} ASC\n" . " LIMIT ${offset}, ${row_count}"; Or something like this.
(In reply to comment #1) > Yes the formatter is applied after inserting the template. The problem is that > it is not possible to format a string (inside). Very often the white spaces in > the string are important and the formatter shouldn't change them. > > I know, in this case it would be reasonable, but there is now way how to > distinguish, which string format and which not. > > For this case there can be a work around like: > > $$query = > "SELECT \n" > . " ${table1}.${field1} AS ${field1},\n" > . " ${table2}.${field2} AS ${field2}\n" > . " FROM ${table1}\n" > . " INNER JOIN ${table2}\n" > . " ON ${table2}.${foreignKey2} = ${table1}.${primaryKey1}\n" > . " WHERE ${table1}.${primaryKey1} = ${primaryKeyValue}\n" > . " AND ${otherConditions}\n" > . " ORDER BY ${table1}.${primaryKey1} ASC\n" > . " LIMIT ${offset}, ${row_count}"; > > Or something like this. OK, so it is not fixable then. Too bad, this use to work with Eclipse. I don't see the reason to apply formatter here, it just makes things worse? One should format the tempalte before saving it, rather then formatting it every time it is being used. Thanks anyway.
The template has to be formatted every time, when is included into a document. It can be pasted in different column (all lines of the template has to be indented properly), there can be different formatting rules for different project etc. So the template is formatted according the setting that is applicable for the document. In your case is not formatted, because it's basically all one string. If you split the long string into small ones, as I suggest, it will work correctly.
(In reply to comment #3) > The template has to be formatted every time, when is included into a document. > It can be pasted in different column (all lines of the template has to be > indented properly), there can be different formatting rules for different > project etc. So the template is formatted according the setting that is > applicable for the document. > > In your case is not formatted, because it's basically all one string. If you > split the long string into small ones, as I suggest, it will work correctly. You are right. But I should stick to original format, so will reformat it by hand. It's just slect and tab after all. Thanks.