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.

Bug 199376 - Wrong indention of code templates
Summary: Wrong indention of code templates
Status: RESOLVED WONTFIX
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 7.0
Hardware: PC Linux
: P3 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-13 07:20 UTC by umpirsky
Modified: 2011-06-13 16:32 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description umpirsky 2011-06-13 07:20:28 UTC
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.
Comment 1 Petr Pisl 2011-06-13 11:43:01 UTC
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.
Comment 2 umpirsky 2011-06-13 11:54:32 UTC
(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.
Comment 3 Petr Pisl 2011-06-13 15:53:44 UTC
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.
Comment 4 umpirsky 2011-06-13 16:32:37 UTC
(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.