Bug 46773 - [formatting][templates] template formatting fails if produced code is not valid java syntax
Summary: [formatting][templates] template formatting fails if produced code is not val...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: 3.0 RC1   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 53375 54357 60220 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-11-17 09:30 EST by Nikolay Metchev CLA
Modified: 2004-05-28 06:40 EDT (History)
4 users (show)

See Also:


Attachments
my preferences (189.22 KB, text/plain)
2003-11-19 12:38 EST, Nikolay Metchev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolay Metchev CLA 2003-11-17 09:30:54 EST
I200311050952

using the following template
-----------------------------
public ${enclosing_type}(${arguments}) 
{
      ${cursor}
}
-----------------------------
I get the following error:
!ENTRY org.eclipse.jdt.ui 4 10001 Nov 17, 2003 14:26:29.847
!MESSAGE formatter failed to format (no edit returned). Will use unformatted 
text instead. kind: 0, string: public SetViewer(arguments) 
{
      /*${cursor}*/
}

and the open and close brackets do not show up in the correct columns ( i.e 
don't get formatted).
Comment 1 Dani Megert CLA 2003-11-18 16:00:43 EST
caused by bug 23344

*** This bug has been marked as a duplicate of 23344 ***
Comment 2 Nikolay Metchev CLA 2003-11-19 04:36:05 EST
are you sure that bug 23344 is the problem as you can clearly see in the 
resulting code the ${enclosing_type} variable has been resolved to SetViewer.
Comment 3 Dani Megert CLA 2003-11-19 05:12:54 EST
I guess I assumed that since bug 23344 said it's not expanded at all then this
must be a dup ;-)

Anyway will fix together. Annotated bug 23344 to explicitly check this bug.
Comment 4 Nikolay Metchev CLA 2003-11-19 05:14:54 EST
one other thing I notice is that the other bug is reported agains 2.0.1 and 
this one is reported against 3.0
Comment 5 Dani Megert CLA 2003-11-19 12:25:28 EST
Works for me using I20031119.
Comment 6 Nikolay Metchev CLA 2003-11-19 12:26:39 EST
it doesn't work for me though I20031119! must be a preferences thing!
Comment 7 Dani Megert CLA 2003-11-19 12:35:42 EST
Som you still get an error? I guess we use different formatter options can you
attach me yours.
Comment 8 Nikolay Metchev CLA 2003-11-19 12:38:23 EST
Created attachment 6867 [details]
my preferences
Comment 9 Dani Megert CLA 2003-11-19 12:48:24 EST
Can be reproduced using attached preferences.
Comment 10 Christof Marti CLA 2004-03-08 10:52:19 EST
I20040303

Still reproducible. What happens is:
- "${arguments}" is correctly replaced with "arguments"
- the resulting string has a syntax error, "Types arguments" would work but
template variables (${..}) are not allowed to contain spaces
- code formatting fails due to the syntax error

This is reproducible with similar default templates. Preferences do not appear
to be significant.
Comment 11 Tom Hofmann CLA 2004-03-08 11:14:34 EST
the template formatter uses core formatting currently, which is a problem in not
yet complete code snippets where the formatter does not produce anything usable.
Comment 12 Tom Hofmann CLA 2004-03-10 05:10:59 EST
could be fixed by not having this template:
---------------------------------
public ${enclosing_type}(${}) 
{
      ${cursor}
}
---------------------------------
This way, you still get a tab stop between the parenthesis, but we do have a
syntactically correct pattern to start with and the formatter does not choke on it.

This is just a workaround - not sure though what we can do as long as we use the
core formatter for templates. There may be many more instances where templates
are not correct. 

Another workaround would be to disable using the formatter (on the preference
page) and require people to format the templates as they want them to have
inserted - not too cool for the standard templates.
Comment 13 Tom Hofmann CLA 2004-03-10 05:12:30 EST
> could be fixed by not having this template:
                    ^^^

I meant to say that this template *would* fix this particular problem.
Comment 14 Christof Marti CLA 2004-03-10 05:21:16 EST
What about adding a new variable ${tab_stop}, or similar, that is replaced by
nothing but the tab stop?
Comment 15 Tom Hofmann CLA 2004-03-11 05:41:04 EST
*** Bug 54357 has been marked as a duplicate of this bug. ***
Comment 16 Tom Hofmann CLA 2004-04-07 02:45:28 EDT
*** Bug 53375 has been marked as a duplicate of this bug. ***
Comment 17 Tom Hofmann CLA 2004-05-24 03:13:41 EDT
we should find a solution that at least "usually" works or disable the template
code formatter preference.
Comment 18 Tom Hofmann CLA 2004-05-25 14:56:33 EDT
fixed > 20040525
Comment 19 Tom Hofmann CLA 2004-05-28 04:03:53 EDT
*** Bug 60220 has been marked as a duplicate of this bug. ***
Comment 20 Christof Marti CLA 2004-05-28 05:57:40 EDT
start verifying
Comment 21 Christof Marti CLA 2004-05-28 06:40:57 EDT
I opened bug 64521 for the enhancement in comment 14.