Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Add Include working without a selection?

Thanks for explaining that. That's a ... creative ... way to implement
isEmpty().

Looking at the documentation for it
(http://git.eclipse.org/c/platform/eclipse.platform.text.git/tree/org.ec
lipse.jface.text/src/org/eclipse/jface/text/TextSelection.java#n96 ), I
see: "A selection of length 0 is not an empty text selection as it
describes, e.g., the cursor position in a viewer." which mostly makes
sense, but still seems an odd way to handle things.

 Can you or someone else explain further when (and why)
selection.isEmpty() actually *would* return true, and what the reference
to "backwards compatibility" might be?

Also, how can *this* be null (as is checked for in the first branch of
the code)? (See
http://stackoverflow.com/questions/3789528/can-this-ever-be-null-in-java
for examples of people who think this can't happen)

Jesse

-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx]
On Behalf Of Andrew Eidsness
Sent: Wednesday, March 20, 2013 6:53 PM
To: cdt-dev@xxxxxxxxxxx
Subject: Re: [cdt-dev] Add Include working without a selection?

The implementation of TextSelection.isEmpty is:

public boolean isEmpty() {
	return this == NULL || /* backwards compatibility: */ fOffset <
0 || fLength < 0; }

In your case (nothing selected), fLength is 0; so the selection says
that it is not empty.

-Andrew

On 13-03-20 09:37 PM, Jesse Weinstein wrote:
> I'm confused about whether Add Include will work without anything 
> selected. It appears to do so (details below), but my reading of the 
> code suggests that it shouldn't. So I'm confused.
>
> Here's the code that makes me think it shouldn't do anything if there 
> is no selection:
>
> if (selection.isEmpty() || !(selection instanceof ITextSelection)) {
>
> return;
>
> }
>
> from
> http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/tree/core/org.eclipse
> .cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAc
> tion.java#n166
>
> And here's how I seem to be able to make it do things:
>
> I have a class implementation file: someClass.cpp, containing an 
> implementation of a single method, and without any #includes. If I run

> "Add Include" without anything selected, it adds an include for the 
> header file where the class is declared, #include "someClass.h".
>
> What's going on here?
>
> (Asked on the forum, with no response, here:
> http://www.eclipse.org/forums/index.php/m/1012152 )
>
>
>
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top