Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Desired Editing Feature
Desired Editing Feature [message #120614] Mon, 24 November 2003 22:09 Go to next message
Eclipse UserFriend
Originally posted by: dcorbin.machturtle.com

Is there an editing feature that will slap braces around the selection, and
indent the block contents if appropriate?

David
Re: Desired Editing Feature [message #120712 is a reply to message #120614] Tue, 25 November 2003 03:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.tkilla.ch

David Corbin wrote:
> Is there an editing feature that will slap braces around the selection, and
> indent the block contents if appropriate?

Select the lines you want and invoke quick assist (Ctrl+1 - turn on
"Java->Work in Progress->Enable lightbulb for quick assists" to get a
visual cue for its availability), then select one of the offered
templates (surround with if etc.).

-tom
Re: Desired Editing Feature [message #121657 is a reply to message #120712] Tue, 25 November 2003 08:34 Go to previous messageGo to next message
Eclipse UserFriend
Tom Eicher wrote:

> David Corbin wrote:
>> Is there an editing feature that will slap braces around the selection,
>> and indent the block contents if appropriate?
>
> Select the lines you want and invoke quick assist (Ctrl+1 - turn on
> "Java->Work in Progress->Enable lightbulb for quick assists" to get a
> visual cue for its availability), then select one of the offered
> templates (surround with if etc.).
>
> -tom


Not quite what I wanted.

I have a statement that reads:

if (a)
b();

I want a keystroke that turns that into:
if (a)
{
b();
}

And, I don't want to have to select the line to do it. It should just
operate on the current line.

David
Re: Desired Editing Feature [message #121683 is a reply to message #121657] Tue, 25 November 2003 09:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.forritan.net

It's actually already there.

Example:

You have this:

....
b();
....

and then you want make this call conditional, you write "if(a){" in
front of "b();" - i.e. the curser is now in front of "b" :

....
if(a){b();
....

press enter and you got:
....
if(a){
b();
}
....

Regards,
-eyðun


David Corbin wrote:
> Tom Eicher wrote:
>
>
>>David Corbin wrote:
>>
>>>Is there an editing feature that will slap braces around the selection,
>>>and indent the block contents if appropriate?
>>
>>Select the lines you want and invoke quick assist (Ctrl+1 - turn on
>>"Java->Work in Progress->Enable lightbulb for quick assists" to get a
>>visual cue for its availability), then select one of the offered
>>templates (surround with if etc.).
>>
>>-tom
>
>
>
> Not quite what I wanted.
>
> I have a statement that reads:
>
> if (a)
> b();
>
> I want a keystroke that turns that into:
> if (a)
> {
> b();
> }
>
> And, I don't want to have to select the line to do it. It should just
> operate on the current line.
>
> David
Re: Desired Editing Feature [message #121745 is a reply to message #121683] Tue, 25 November 2003 11:55 Go to previous messageGo to next message
Eclipse UserFriend
Eyðun Nielsen wrote:

> It's actually already there.
>
> Example:
>
> You have this:
>
> ...
> b();

No, I don't. I already HAVE the if statement. I simply wish to turn a
single statement into a blockstatement.
Re: Desired Editing Feature [message #122166 is a reply to message #121745] Wed, 26 November 2003 03:01 Go to previous messageGo to next message
Eclipse UserFriend
David Corbin wrote:
> Ey
Re: Desired Editing Feature [message #122748 is a reply to message #121745] Thu, 27 November 2003 13:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.forritan.net

David Corbin wrote:
> Eyðun Nielsen wrote:
>
>
>>It's actually already there.
>>
>>Example:
>>
>>You have this:
>>
>>...
>>b();
>
>
> No, I don't. I already HAVE the if statement. I simply wish to turn a
> single statement into a blockstatement.
>
>
Oh, sorry - I think I misunderstood you...

Well, I took the challange... ;-) It's actually quite easy to implement.
(I have never worked with the internals of jdt before - and I came up
with this after a couple of hours today)


1. In org.eclipse.jdt.internal.ui.text.correction.QuickAssistProce ssor
make a new method:

<code>
private boolean getAddThenProposals(
IInvocationContext context,
ASTNode node,
Collection resultingCollections)
throws CoreException {
Statement statement= ASTResolving.findParentStatement(node);
if (!(statement instanceof IfStatement)) {
return false;
}
IfStatement ifStatement= (IfStatement) statement;
if (ifStatement.getThenStatement() instanceof Block) {
return false;
}

if (resultingCollections == null) {
return true;
}
AST ast= statement.getAST();
ASTRewrite rewrite= new ASTRewrite(statement);

ASTNode thenStatement=
ASTNode.copySubtree(ast, ifStatement.getThenStatement());
Block replacingBody= ast.newBlock();
replacingBody.statements().add(thenStatement);
rewrite.markAsInsert(
ifStatement,
ASTNodeConstants.THEN_STATEMENT,
replacingBody,
null);

String label=
CorrectionMessages.getString("QuickAssistProcessor.addthenblock.description ");
//$NON-NLS-1$
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD);
ASTRewriteCorrectionProposal proposal=
new ASTRewriteCorrectionProposal(
label,
context.getCompilationUnit(),
rewrite,
1,
image);
proposal.ensureNoModifications();
resultingCollections.add(proposal);
return true;
}
</code>

and make appropriate calls to this new method in

hasAssists(IInvocationContext)

and in

getAssists(IInvocationContext context, IProblemLocation[] locations)

also in org.eclipse.jdt.internal.ui.text.correction.QuickAssistProce ssor

2. add one line in
org.eclipse.jdt.internal.ui.text.correction.CorrectionMessag es.properties:
<code>
QuickAssistProcessor.addthenblock.description=Add then block
</code>

And thats it... Compile and be happy... ;-)

Regards,
-eyðun
Re: Desired Editing Feature [message #122753 is a reply to message #122748] Thu, 27 November 2003 13:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.tkilla.ch

Eyðun Nielsen wrote:
> And thats it... Compile and be happy...

... and attach your patch to a PR and make everyone else happy...

;-) tom
Re: Desired Editing Feature [message #122770 is a reply to message #122753] Thu, 27 November 2003 14:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.forritan.net

Done.

Bugzilla Bug 47657:
Quick Assist Suggestion: add block to single-line then-statement

https://bugs.eclipse.org/bugs/show_bug.cgi?id=47657

:-)
-eyðun

Tom Eicher wrote:

> Eyðun Nielsen wrote:
>
>> And thats it... Compile and be happy...
>
>
> ... and attach your patch to a PR and make everyone else happy...
>
> ;-) tom
>
Re: Desired Editing Feature [message #122816 is a reply to message #122770] Fri, 28 November 2003 06:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.forritan.net

And FIXED as from 3.0 M6 ;-)

Eyðun Nielsen wrote:
> Done.
>
> Bugzilla Bug 47657:
> Quick Assist Suggestion: add block to single-line then-statement
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=47657
>
> :-)
> -eyðun
>
> Tom Eicher wrote:
>
>> Eyðun Nielsen wrote:
>>
>>> And thats it... Compile and be happy...
>>
>>
>>
>> ... and attach your patch to a PR and make everyone else happy...
>>
>> ;-) tom
>>
>
Re: Desired Editing Feature [message #122840 is a reply to message #122816] Fri, 28 November 2003 08:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dcorbin.machturtle.com

Thanks. But it looks like you took my request VERY litterally, and it's
limited to if statements. I think the same should be doable for while and
for statements.

I'm pretty sure that covers all the cases where blocks are optional, short
of just adding blocks for scoping sakes.

Davdi

Eyðun Nielsen wrote:

> And FIXED as from 3.0 M6 ;-)
>
> Eyðun Nielsen wrote:
>> Done.
>>
>> Bugzilla Bug 47657:
>> Quick Assist Suggestion: add block to single-line then-statement
>>
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=47657
>>
>> :-)
>> -eyðun
>>
>> Tom Eicher wrote:
>>
>>> Eyðun Nielsen wrote:
>>>
>>>> And thats it... Compile and be happy...
>>>
>>>
>>>
>>> ... and attach your patch to a PR and make everyone else happy...
>>>
>>> ;-) tom
>>>
>>
Re: Desired Editing Feature [message #122852 is a reply to message #122840] Fri, 28 November 2003 08:35 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.forritan.net

David Corbin wrote:
> Thanks. But it looks like you took my request VERY litterally, and it's
> limited to if statements. I think the same should be doable for while and
> for statements.

Well, that only shows how carefull you should be when you make a wish!!! ;-)

>
> I'm pretty sure that covers all the cases where blocks are optional, short
> of just adding blocks for scoping sakes.

Well you are in luck, because so did Martin Aeschlimann (who committed
the code into the stream) :-)

*
*
*
Bugzilla Bug 47657:
Quick Assist Suggestion: add block to single-line then-statement

https://bugs.eclipse.org/bugs/show_bug.cgi?id=47657
*
------- Additional Comment #2 From Martin Aeschlimann 2003-11-28 05:07
-------

nice! I added the code and made some changes to complete it:

- added support for else block; while, do and for statements
- use 'createMove()' instead of ASTNode.copySubtree (otherwise you loose
all
formatting and comments of the body statement.

you can submit changes as a patch (in the TEAM menu), that's the most
easiest
way for me to take fixes.

Thanks a lot!

*
*
*

>
> Davdi
>
> Eyðun Nielsen wrote:
>
>
>>And FIXED as from 3.0 M6 ;-)
>>
>>Eyðun Nielsen wrote:
>>
>>>Done.
>>>
>>>Bugzilla Bug 47657:
>>>Quick Assist Suggestion: add block to single-line then-statement
>>>
>>>https://bugs.eclipse.org/bugs/show_bug.cgi?id=47657
>>>
>>>:-)
>>>-eyðun
>>>
>>>Tom Eicher wrote:
>>>
>>>
>>>>Eyðun Nielsen wrote:
>>>>
>>>>
>>>>>And thats it... Compile and be happy...
>>>>
>>>>
>>>>
>>>>... and attach your patch to a PR and make everyone else happy...
>>>>
>>>>;-) tom
>>>>
>>>
>
Previous Topic:CVS Outgoing Information
Next Topic:How to force Eclipse-CVS to use LF for line-endings?
Goto Forum:
  


Current Time: Wed May 07 15:24:17 EDT 2025

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

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

Back to the top