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 38370 - [50cat] Add UI for marking a Java template as preformatted
Summary: [50cat] Add UI for marking a Java template as preformatted
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: 4.x
Hardware: All All
: P2 blocker with 2 votes (vote)
Assignee: Tomas Zezula
Keywords: UI
: 39784 47466 47562 (view as bug list)
Depends on:
Reported: 2004-01-03 15:51 UTC by gugrim
Modified: 2010-01-11 03:44 UTC (History)
1 user (show)

See Also:
Exception Reporter:

The template I use, as binary to preserve line endings etc (611 bytes, application/octet-stream)
2004-03-21 08:20 UTC, gugrim
A file created from the template, as binary to preserve line endings etc (672 bytes, application/octet-stream)
2004-03-21 08:21 UTC, gugrim
The template (1.91 KB, text/plain)
2004-10-19 17:08 UTC, gugrim
The result (1.84 KB, text/plain)
2004-10-19 17:09 UTC, gugrim

Note You need to log in before you can comment on or make changes to this bug.
Description gugrim 2004-01-03 15:51:04 UTC
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
Comment 1 Miloslav Metelka 2004-01-23 17:15:42 UTC
Added Petr F. to cc. Petre, could you please try to reproduce it? Thanks.
Comment 2 gugrim 2004-02-16 17:49:26 UTC
For what it's worth, I have just verified that the bug still exists in
dev build 200402121900.
Comment 3 pfelenda 2004-03-19 19:10:10 UTC
I can't reproduce it.
Which template do you use ?
Please, can you provide steps to reproduce the issue ?
Comment 4 gugrim 2004-03-21 08:20:18 UTC
Created attachment 14064 [details]
The template I use, as binary to preserve line endings etc
Comment 5 gugrim 2004-03-21 08:21:26 UTC
Created attachment 14065 [details]
A file created from the template, as binary to preserve line endings etc
Comment 6 gugrim 2004-03-21 08:48:43 UTC
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

Hope this info can help you fix the problem!
Comment 7 Dusan Balek 2004-08-27 16:01:34 UTC
*** Issue 47466 has been marked as a duplicate of this issue. ***
Comment 8 Martin Roskanin 2004-10-19 15:50:16 UTC
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.
Comment 9 gugrim 2004-10-19 17:08:07 UTC
I've just tried 200410181800 and it doesn't work. Atatching a sligtly
larger template and the resulting file.
Comment 10 gugrim 2004-10-19 17:08:53 UTC
Created attachment 18382 [details]
The template
Comment 11 gugrim 2004-10-19 17:09:35 UTC
Created attachment 18383 [details]
The result
Comment 12 Martin Roskanin 2004-10-19 17:19:04 UTC
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...
Comment 13 gugrim 2004-10-19 17:25:19 UTC
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?
Comment 14 Martin Roskanin 2004-10-20 15:54:23 UTC
Yes, I can reproduce it. I will look at it.
Comment 15 Martin Roskanin 2004-10-29 15:58:43 UTC
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:
Reassigning to java.
Comment 16 gugrim 2004-12-12 09:56:06 UTC
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.
Comment 17 Martin Matula 2004-12-13 13:53:37 UTC
Dan, please look at this.
Comment 18 gugrim 2005-03-15 19:17:07 UTC
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.
Comment 19 Martin Matula 2005-03-15 21:19:51 UTC
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
2) open ".nbattrs" file in this directory
3) you should see entry for your template - something like:
    <fileobject name="">
        <attr name="template" boolvalue="true"/>
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="">
        <attr name="org-netbeans-modules-java-preformattedSource" boolvalue="true"/>
        <attr name="template" boolvalue="true"/>

4) Save it and start NetBeans. Now it should work file.

Changing this to enhancement to better expose this functionality.
Comment 20 gugrim 2005-03-16 18:12:45 UTC
Great! How long has this option been there? No, don't tell me, I probably don't
want to know...
Comment 21 tomzi 2005-03-17 14:32:26 UTC
why don't you make this option available in the ui? it might be useful for other
users as well....
Comment 22 Martin Matula 2005-03-17 14:49:40 UTC
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.
Comment 23 Jan Becicka 2005-05-06 13:43:26 UTC
We are able to solve this issue on our own hook.
Comment 24 Jesse Glick 2005-06-16 11:34:06 UTC
*** Issue 39784 has been marked as a duplicate of this issue. ***
Comment 25 Jesse Glick 2005-06-16 11:34:24 UTC
*** Issue 47562 has been marked as a duplicate of this issue. ***