Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » add newline to template?(question.)
add newline to template? [message #1831393] Wed, 19 August 2020 03:22 Go to next message
Blood Eko is currently offline Blood EkoFriend
Messages: 5
Registered: August 2020
Junior Member
Hello!

My question is quite simple, though I can't find the option to configure the template to add an newline.
Whitespaces seem to be trimmed, so that doesn't work. Any ideas?

https://i.ibb.co/sjNTS3W/met.png

[Updated on: Wed, 19 August 2020 04:26]

Report message to a moderator

Re: add newline to template? [message #1831399 is a reply to message #1831393] Wed, 19 August 2020 05:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31469
Registered: July 2009
Senior Member
I wonder if what you're trying to do is more of a Content Assist -> Templates where you can use ${cursor} to specify where the cursor should go? I don't know that ${cursor} works in the Code Style -> Templates.

You might ask specifically on the JDT forum:

https://www.eclipse.org/forums/index.php/f/13/


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: add newline to template? [message #1831414 is a reply to message #1831399] Wed, 19 August 2020 10:23 Go to previous messageGo to next message
Blood Eko is currently offline Blood EkoFriend
Messages: 5
Registered: August 2020
Junior Member
Not quite sure what you mean by content assist. With the cursor I wanted to indicate that indention should also be present.
So that the generated construct can be used directly to write the code on without any further manual formatting.
Aight so the JDT would be right place then to get this solved?
Re: add newline to template? [message #1831417 is a reply to message #1831414] Wed, 19 August 2020 11:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31469
Registered: July 2009
Senior Member
It's not entirely clear to me what you want. In Window -> Preferences -> Java -> Editor -> Content Assist -> Templates there are also templates. And yes, if you have a question specifically about the Java templates those are provided by JDT and the JDT forum is more likely to have an answer.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: add newline to template? [message #1831439 is a reply to message #1831417] Wed, 19 August 2020 19:58 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 3834
Registered: July 2009
Senior Member

Sounds like you're looking for the Code Templates preference page, which affects code generation, and not the Content Assist / Templates preference page, which is more for setting up phrases you can expand into proper expressions using content assist (Cmd/Ctrl+Space).

Nitin Dahyabhai
Eclipse Web Tools Platform

[Updated on: Wed, 19 August 2020 19:59]

Report message to a moderator

Re: add newline to template? [message #1831449 is a reply to message #1831393] Thu, 20 August 2020 04:05 Go to previous messageGo to next message
Blood Eko is currently offline Blood EkoFriend
Messages: 5
Registered: August 2020
Junior Member
    @Override
    public void play(String x) {
        // TODO Auto-generated method stub

    }
    @Override
    public void play(String x) {
    }
    @Override
    public void play(String x) {
        
    }

The first code block is which comes up when auto-implementing methods with default settings under
Preferences -> Java -> Code Style -> Code Templates -> Code -> Method body

When replacing the comment with a newline in the template it becomes the second example.
As newlines seem to be stripped somehow. What I would like to archieve is the third example.

[Updated on: Fri, 21 August 2020 08:02]

Report message to a moderator

Re: add newline to template? [message #1831533 is a reply to message #1831449] Sat, 22 August 2020 00:59 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 3834
Registered: July 2009
Senior Member

Are your code formatter preferences set to leave at least one blank line alone?

Nitin Dahyabhai
Eclipse Web Tools Platform
Re: add newline to template? [message #1831545 is a reply to message #1831533] Sat, 22 August 2020 14:17 Go to previous message
Blood Eko is currently offline Blood EkoFriend
Messages: 5
Registered: August 2020
Junior Member
    @Override
    public void run() {
xxxx
    }
    @Override
    public void run() {
    }
    @Override
    public void run() {
xxxxxxxx
    }

Doesn't seem to help so far. I tried now with these settings, which produce the first block.
Formatter -> Indention -> Empty Lines (yes)
Formatter -> Blank Lines -> At beginning of method body (1)

With the settings it would be worse or equal to the actual settings as now just the
TAB key over the ENTER key needs to be used to archieve the third, desired format.
But actually with the drawback that general formatting is affected in a way it shouldnt.

What seems to be the problem is that newlines/tabs/spaces can be written to the template
but are effectively ignored by the code generator. I wonder if there is any hidden setting
to use them as absolute symbols too.
Previous Topic:What the hell man!
Next Topic:Icons are missing in the Eclipse IDE Help
Goto Forum:
  


Current Time: Mon Sep 21 18:44:09 GMT 2020

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

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

Back to the top