Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Jave 3.3 code formatter question
Jave 3.3 code formatter question [message #246284] Fri, 27 July 2007 16:04 Go to next message
Eclipse UserFriend
Hi all,

I would like to invoke the code formatter when I save a file, but I'm
running into one annoyance I can't seem to work around. I want to
format method parameters manually, e.g.

void myMethod(int a, int b,
int c, double d) {
....
}

but Eclipse 3.3 won't let me. If I have the formatter on, it insists on
unwrapping the declaration to

void myMethod(int a, int b, int c, double d) {
....
}

and rewrapping if that violates the line length. This is with the
relevant formatter preference set to no wrapping; any of the other
wrapping options wraps it differently, but not the way I want.

The smart money says I'm missing something. Is there a way to tell the
code formatter to ignore parameter lists when formatting the code, or a
way to insert a "hard" line break that is inviolable?

TIA,
Paul
Re: Jave 3.3 code formatter question [message #246369 is a reply to message #246284] Mon, 30 July 2007 16:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jacek.pospychala.pl.ibm.com

hi Paul,
sorry, currently there is no way to do what you want. Would you agree
with me, that formatting you'd like to have is very specific? I wonder
what should be a more general rule, that would fit your needs.
Regarding inserting "hard" line break. Where would you actually expect
it? After 29th column, after 2 argument, after second "," in line?
Maybe it would be better to select certain types of source code (like
method declarations), that should not be formatted.
I'd say, that you could raise an enhancement request here
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT& component=Text
however keep in mind, that there are also voices, that formatter is
already too difficult to configure because of huge number of options it
offers.

Paul A. Rubin wrote:
> Hi all,
>
> I would like to invoke the code formatter when I save a file, but I'm
> running into one annoyance I can't seem to work around. I want to
> format method parameters manually, e.g.
>
> void myMethod(int a, int b,
> int c, double d) {
> ...
> }
>
> but Eclipse 3.3 won't let me. If I have the formatter on, it insists
> on unwrapping the declaration to
>
> void myMethod(int a, int b, int c, double d) {
> ...
> }
>
> and rewrapping if that violates the line length. This is with the
> relevant formatter preference set to no wrapping; any of the other
> wrapping options wraps it differently, but not the way I want.
>
> The smart money says I'm missing something. Is there a way to tell
> the code formatter to ignore parameter lists when formatting the code,
> or a way to insert a "hard" line break that is inviolable?
>
> TIA,
> Paul
Re: Jave 3.3 code formatter question [message #246384 is a reply to message #246369] Mon, 30 July 2007 19:47 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jacek,

Jacek Pospychala wrote:
> hi Paul,
> sorry, currently there is no way to do what you want. Would you agree
> with me, that formatting you'd like to have is very specific?

Yes -- definitely a matter of personal taste, and my taste may be out of
the mainstream.

> I wonder what should be a more general rule, that would fit your needs.
> Regarding inserting "hard" line break. Where would you actually expect
> it? After 29th column, after 2 argument, after second "," in line?

I was thinking that it would be entered manually. For instance, in some
word processors ctrl-enter means "break the line and don't alter that
when you reflow the text". So perhaps ctrl-enter here could mean "line
break not to be altered during a reformat".

> Maybe it would be better to select certain types of source code (like
> method declarations), that should not be formatted.

That would work, but I suppose the list of things to opt into/out of
formatting could get rather long.

> I'd say, that you could raise an enhancement request here
> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT& component=Text
> however keep in mind, that there are also voices, that formatter is
> already too difficult to configure because of huge number of options it
> offers.

I'm sympathetic to that, having just gone through configuration of the
formatter. Perhaps I'll suggest ctrl-enter as a possibility; it doesn't
require another setting.

Thanks,
Paul
Re: Jave 3.3 code formatter question [message #246472 is a reply to message #246384] Wed, 01 August 2007 16:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wharley.bea.com

"Paul A. Rubin" <rubin@msu.edu> wrote in message
news:f8ltaq$3ni$1@build.eclipse.org...
> I was thinking that it would be entered manually. For instance, in some
> word processors ctrl-enter means "break the line and don't alter that when
> you reflow the text". So perhaps ctrl-enter here could mean "line break
> not to be altered during a reformat".

How would that "non-wrapping line break" be represented in the .java file?
It has to be something that will not trip up the compiler.

If you put a // comment at the end of the line you don't want wrapped, does
the formatter still wrap it? I don't see how it could, so perhaps that's
your answer.
Re: Jave 3.3 code formatter question [message #246482 is a reply to message #246472] Wed, 01 August 2007 21:32 Go to previous messageGo to next message
Eclipse UserFriend
Walter Harley wrote:
> "Paul A. Rubin" <rubin@msu.edu> wrote in message
> news:f8ltaq$3ni$1@build.eclipse.org...
>> I was thinking that it would be entered manually. For instance, in some
>> word processors ctrl-enter means "break the line and don't alter that when
>> you reflow the text". So perhaps ctrl-enter here could mean "line break
>> not to be altered during a reformat".
>
> How would that "non-wrapping line break" be represented in the .java file?
> It has to be something that will not trip up the compiler.

Good question. I don't know enough about javac to answer. Is there a
whitespace character other than space and tab that occupies just one
column and isn't visible in the display? (Maybe Unicode. Do the French
have an accented space? ;-))
>
> If you put a // comment at the end of the line you don't want wrapped, does
> the formatter still wrap it? I don't see how it could, so perhaps that's
> your answer.

Good idea, but sadly it finds a way. I tried

public void foo(FunkyClass arg1, //
FunkyClass arg2)
throws Exception {

and after a save (and on-save formatting) ended up with

public void foo(FunkyClass arg1, //
FunkyClass arg2) throws Exception {

I'm not sure if it's related to another cosmic annoyance. In the
Formatter -> Comments tab, I've unchecked everything. I even exited and
did a -clean restart to make sure this was absorbed. Nonetheless,

double xyz; // comment 1
double abcdefg; // comment 2

turns into

double xyz; // comment 1
double abcdefg; // comment 2

after a save. I even tried turning off the option to clean up
end-of-line whitespace. Didn't help.

I can't help thinking that somewhere I've got a setting (of which I'm
blissfully unaware) that's interfering with the ones mentioned above.

/Paul
Re: Jave 3.3 code formatter question [message #246492 is a reply to message #246482] Thu, 02 August 2007 11:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wharley.bea.com

"Paul A. Rubin" <rubin@msu.edu> wrote in message
news:f8rc6f$rcf$1@build.eclipse.org...
> Is there a whitespace character other than space and tab that occupies
> just one column and isn't visible in the display? (Maybe Unicode.

Unfortunately even though Java programs are ostensibly written in Unicode,
and Unicode does include some characters that could be used this way [1],
such as Line Separator (LS = 0x2028), the Java Language Specification [2]
defines the line terminators as just being CR and LF. So I'm not sure
whether existing Java compilers would properly interpret this.

[1] http://unicode.org/reports/tr13/tr13-9.html

[2] http://java.sun.com/docs/books/jls/third_edition/html/lexica l.html#3.4


> I'm not sure if it's related to another cosmic annoyance. In the
> Formatter -> Comments tab, I've unchecked everything. I even exited and
> did a -clean restart to make sure this was absorbed. Nonetheless,
>
> double xyz; // comment 1
> double abcdefg; // comment 2
>
> turns into
>
> double xyz; // comment 1
> double abcdefg; // comment 2
>
> after a save. I even tried turning off the option to clean up end-of-line
> whitespace. Didn't help.

Huh, that seems very peculiar that you would be getting formatting on save
with your formatting options turned off. That sure sounds like there's
still something turned on. Make sure you don't have some sort of workspace
setting interfering, or some kind of autoformatting plug-in (possibly
associated with your version control system?) present.
Re: Jave 3.3 code formatter question [message #246823 is a reply to message #246492] Tue, 14 August 2007 14:11 Go to previous message
Eclipse UserFriend
Walter Harley wrote:

>> I'm not sure if it's related to another cosmic annoyance. In the
>> Formatter -> Comments tab, I've unchecked everything. I even exited and
>> did a -clean restart to make sure this was absorbed. Nonetheless,
>>
>> double xyz; // comment 1
>> double abcdefg; // comment 2
>>
>> turns into
>>
>> double xyz; // comment 1
>> double abcdefg; // comment 2
>>
>> after a save. I even tried turning off the option to clean up end-of-line
>> whitespace. Didn't help.
>
> Huh, that seems very peculiar that you would be getting formatting on save
> with your formatting options turned off. That sure sounds like there's
> still something turned on. Make sure you don't have some sort of workspace
> setting interfering, or some kind of autoformatting plug-in (possibly
> associated with your version control system?) present.
>

Sorry, meant to finish this thread of sooner but got side-tracked. I
only have one workspace (and I'm tweaking settings at the workspace
level), I don't have any project-specific settings, I don't have any
plug-ins beyond what came with Europa, and I don't have a VCS (I'm a one
man band). Beyond Mylyn, whose precise function I don't know (but which
doesn't seem to be the culprit here), I don't know why I had so much
trouble controlling formatting.

Ultimately, though, I turned off code formatting in the clean-up
function. It's a nice feature, but I lived without it before.

Thanks,
Paul
Previous Topic:Monitor Code-changes with IElementChangedListener
Next Topic:How to remove parameter using ASTParser
Goto Forum:
  


Current Time: Mon Jun 23 16:07:50 EDT 2025

Powered by FUDForum. Page generated in 0.05021 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top