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.
In my templates I use tab characters that are not expanded to spaces. When I create a file from such a template, the result is not pretty. Most tabs are followed by an extra space but a few are instead replaced with a single space. The Java indentation engine are set to not expand tabs and a tab size of 4. I'm not sure but I believe this behaviour started with 3.5.1. Perhaps this bug is in some way related to issue 37669.
Added Petr F. to cc. Petre, could you please try to reproduce it? Thanks.
For what it's worth, I have just verified that the bug still exists in dev build 200402121900.
I can't reproduce it. Which template do you use ? Please, can you provide steps to reproduce the issue ? Thanks
Created attachment 14064 [details] The template I use, as binary to preserve line endings etc
Created attachment 14065 [details] A file created from the template, as binary to preserve line endings etc
As you can see, I have just uploaded the template file and a file created from it, as binaries. While attempting to illustrate the problem with one of the supplied templates, I couldn't. After a lot of experimenting with PC/Unix line endings, tabs vs blanks etc, I found that what triggers the bug is the fact that I place the opening brace on its own line for big stuff such as classes and methods, but on the same line as the opening of a control statement, a style I have used since I started coding C back in the early eighties. This style is sadly not supported by the Java indentation engine. Could there be a connection? Hope this info can help you fix the problem!
*** Issue 47466 has been marked as a duplicate of this issue. ***
I have tested your template file. The created file looks correctly for me in the latest dev builds. (WinXP & jdk1.5) Please try it again and reopen the issue if the problem persists for you. Thanks.
I've just tried 200410181800 and it doesn't work. Atatching a sligtly larger template and the resulting file.
Created attachment 18382 [details] The template
Created attachment 18383 [details] The result
Strange, also your new template works correctly to me. maybe I am doing something wrong during reproduction. I just open default Java Class Template in editor -> Tools/options/Source Creation And Management/Templates/java Classes/Java Class <right-click/open> and replace the default content with your template. After that I created a new java file and I got correctly formatted source in accordance with your template...
The extra space following tabs has disappered, which is an improvement, but several initial tabs are removed. There should be two tabs before "throws Exception" instead of one, and one or more tabs before opening braces. Could it be that your indentation engine settings are different from mine?
Yes, I can reproduce it. I will look at it.
It is not problems of tabs. It is problem of templates indentation. Now, the indent engine is called for each line of template separately. This results into the state where '\n' cannot be removed from previous line, because it has been already written into the underlying writer. You should get the same indented source as if you press Ctrl+Shift+F after template generation. The indentation of course depends on the settings of Java Indentation Engine. (The problem od deleting '\n' is valid only for "Add new line Before Brace" disabled) We cannot fix it in editor module. The indentation should be called once per whole template. Please consider this in the class: org.netbeans.modules.java.IndentFileEntry Reassigning to java.
Just to make sure that there isn't a misunderstanding here: Martin's comment "you should get the same indented source as if you press Ctrl+Shift+F after template generation" confuses me a bit. I certainly don't want that to happen. If I do reformat the code then all newlines before brace are deleted, which is not what I want. I have "Add new line Before Brace" disabled because I don't want newlines before braces in control statements, but I want them before braces after class and method headers. Sorry if this comment is irrelevant because I have misunderstood Martin's.
Dan, please look at this.
After reading up on bug priority guidelines I take the liberty to change the priority to P2. Hope that's OK since I was the one that initially gave it P3. The following quite is motivation enoght I think: "Product feature is significantly affected, a workaround may exist but is difficult to use or impractical". If you have a large template it is so much work fixing up a new file that it is often easier (but more error prone) just to copy some existing source instead.
Sorry, this behavior is intentional, not a bug. If we would change it to fix this issue, we can immediately reopen other issues (e.g. issue 19178). We cannot satisfy everyone. Anyway, there is a workaround for your problem. If you want your template to be used unchanged - i.e. no autoindentation run on it when creating a new file from template - then you can do it as follows: 1) find a directory where your template is defined (somewhere under <nbuser>/config/Templates) 2) open ".nbattrs" file in this directory 3) you should see entry for your template - something like: <fileobject name="YourTemplate.java"> ... <attr name="template" boolvalue="true"/> </fileobject> 4) now add the following element to your template entry: <attr name="org-netbeans-modules-java-preformattedSource" boolvalue="true"/> So, it should finally look like: <fileobject name="YourTemplate.java"> ... <attr name="org-netbeans-modules-java-preformattedSource" boolvalue="true"/> <attr name="template" boolvalue="true"/> </fileobject> 4) Save it and start NetBeans. Now it should work file. Changing this to enhancement to better expose this functionality.
Great! How long has this option been there? No, don't tell me, I probably don't want to know...
why don't you make this option available in the ui? it might be useful for other users as well....
Sure - as you can see, some time ago I changed the summary of this issue to: Add UI for marking a java template as preformatted. That means, we do want to make a UI for that.
We are able to solve this issue on our own hook.
*** Issue 39784 has been marked as a duplicate of this issue. ***
*** Issue 47562 has been marked as a duplicate of this issue. ***