Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » ListRewrite removes whitespace(ListRewrite removes whitespace when removing a modifier but I don't want to do that)
ListRewrite removes whitespace [message #1011931] Wed, 20 February 2013 14:32 Go to next message
Tas Frangoullides is currently offline Tas FrangoullidesFriend
Messages: 16
Registered: July 2009
Junior Member
I'm implementing a shortcut for toggling the final modifier.

Where a final modifier is present I remove it by using a ListRewrite

    ASTRewrite rewrite = ASTRewrite.create(ast);
    ListRewrite listRewrite = rewrite.getListRewrite(declaration, declaration.getModifiersProperty());
    ....
    listRewrite.remove(finalModifier);


However when there are modifiers or annotation on the previous line I get unwanted removal of the carriage return.

E.g.
	@Override
	final void myMethod() {

	}


becomes

	@Override void myMethod() {

	}




Is there a way to preserve the white space or ensure that formatting rules are applied to the list of modifiers?

Thanks,
Tas
Re: ListRewrite removes whitespace [message #1012498 is a reply to message #1011931] Thu, 21 February 2013 17:05 Go to previous messageGo to next message
Tas Frangoullides is currently offline Tas FrangoullidesFriend
Messages: 16
Registered: July 2009
Junior Member
I thought I might have found the solution when I came across setTargetSourceRangeComputer(..) on ASTRewrite. I thought that maybe the whitespace was being considered part of the final modifier's AST node. However when I passed my own implementation I noticed that a correct length of 5 was already being used.

I've taken a look at the text edits return by the rewrite and I get the following
{MultiTextEdit} [53,8] [undefined]
{DeleteEdit} [53,3]
{DeleteEdit} [56,5]

It seems that ASTRewrite has distinctly determined that the whitespace also needs to be deleted ([56,5] is 'final').

I'll dig into ASTRewrite to see if I can understand why it does this. In the meantime if anyone has any suggestions they'd be very welcome.

Thanks,
Tas
Re: ListRewrite removes whitespace [message #1016645 is a reply to message #1012498] Thu, 07 March 2013 09:08 Go to previous messageGo to next message
Tas Frangoullides is currently offline Tas FrangoullidesFriend
Messages: 16
Registered: July 2009
Junior Member
I've not been able to find a suitable way around this and I'm thinking it's a bug in the ASTRewrite which means that formatting rules are not being applied properly for modifiers.

Are there any JDT developers on this group that can confirm this before I go opening a bug?

Thanks,
Tas
Re: ListRewrite removes whitespace [message #1016793 is a reply to message #1016645] Thu, 07 March 2013 17:24 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
which formatter rule do you see violated by this rewrite?
Specifically, what are your settings in the New Lines > Annotations setting of your formatter profile?
Re: ListRewrite removes whitespace [message #1017033 is a reply to message #1016793] Fri, 08 March 2013 17:15 Go to previous messageGo to next message
Tas Frangoullides is currently offline Tas FrangoullidesFriend
Messages: 16
Registered: July 2009
Junior Member
I've been using the built-in default for testing. Under annotations this has insert new life after everything except parameters.

If I have the following
	@Override
	protected void myMethod() {
	}

and use ASTRewrite to remove the visibility modifier I get this:
	@Override void myMethod() {
	}


If I then run Source->Format I get

	@Override
	void myMethod() {
	}

[Updated on: Fri, 08 March 2013 17:16]

Report message to a moderator

Re: ListRewrite removes whitespace [message #1018788 is a reply to message #1017033] Thu, 14 March 2013 13:25 Go to previous message
Tas Frangoullides is currently offline Tas FrangoullidesFriend
Messages: 16
Registered: July 2009
Junior Member
Sounding like a bug? Anyone?
Previous Topic:Improvement proposal for debugger
Next Topic:How does "Open Declaration" work?
Goto Forum:
  


Current Time: Thu Apr 18 14:34:07 GMT 2024

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

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

Back to the top