This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 145500 - code completion suggests improper syntax
Summary: code completion suggests improper syntax
Status: RESOLVED FIXED
Alias: None
Product: cnd
Classification: Unclassified
Component: Code Completion (show other bugs)
Version: 7.3
Hardware: PC Linux
: P3 blocker with 2 votes (vote)
Assignee: Vladimir Voskresensky
URL:
Keywords:
: 103472 160699 180292 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-08-28 22:55 UTC by tbrunhoff
Modified: 2015-09-14 11:01 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tbrunhoff 2008-08-28 22:55:06 UTC
Given a c++ class instance 'p' with a member variable 'foo', if I type

    p.

the code completion will suggest the class members, which is correct for java, but wrong for c++.  The same thing is
true the use of 'this' pointer.
Comment 1 Vladimir Voskresensky 2008-08-29 05:24:01 UTC
I'm sorry. I think, I don't understand you.
Could you, please, provide an example?
Comment 2 tbrunhoff 2008-08-29 17:23:58 UTC
class Foo {
private:
    int value;
public:
    void method() {
        this.value; // type 'this.' and the editor suggests 'value'
    }
};

Foo foo;
foo->value++; // type foo-> and the editor suggests 'value'

Foo* foo2 = &foo;
foo2.value++; // type foo. and the editor suggests 'value'

Comment 3 Vladimir Kvashin 2008-08-29 17:48:53 UTC
Thank you for the example.
We'll fix this in a future release.

BTW, we plan to automatically replace "." to "->" and vice versa if need - see
http://cnd.netbeans.org/issues/show_bug.cgi?id=97120  
Comment 4 tbrunhoff 2008-08-29 18:26:47 UTC
When you do add the automatic correction for . and -> be sure you don't make any changes when both usages are
appropriate, such as when operator-> or operator* is defined.

However, I this think there is another bug.  The editor and the internal compiler thinks that 'this.' is valid, which is
entirely independent of code completion.
Comment 5 Vladimir Voskresensky 2008-08-29 20:02:12 UTC
I agree with your comments.
Btw, we support smart pointers in general, so we track overloaded operators *, ->, []
as about "this." I think we need to implement this usecase as part of IZ#97120 in 6.5,
because, it could be useful for Java developers (who occasionally needs some C++ coding) to have autoreplacement of
their this.f| (choose foo()) into "this->foo()"
Comment 6 nnnnnk 2009-03-20 20:26:42 UTC
*** Issue 160699 has been marked as a duplicate of this issue. ***
Comment 7 nnnnnk 2009-09-25 16:29:20 UTC
*** Issue 103472 has been marked as a duplicate of this issue. ***
Comment 8 nnnnnk 2010-02-04 18:02:28 UTC
*** Bug 180292 has been marked as a duplicate of this bug. ***
Comment 9 Vladimir Voskresensky 2011-03-01 16:36:11 UTC
I have implemented "." to "->" conversion.
looks like the last part is "->" to "." conversion/check
Comment 10 Leonid Lenyashin 2012-10-05 18:36:28 UTC
What is the status of this bug? Please evaluate.
Comment 11 tbrunhoff 2012-10-05 19:05:58 UTC
This is halfway fixed, IMHO. Here's what is fixed: Inside a class, if I type 'this.', NB changes it into a ->. In fact it appears impossible to type 'this.'. Very nice. Given a pointer to a class 'p', if I type p., it will suggest members, and if I use the auto completion, by hitting enter, it changes the '.' to a '->'.

However, problems remain: Given a reference to a class, if I type ->, NB suggests members of class, even though access should only come with '.'. It appears to treat '.' and '->' both as appropriate, even though '->' is incorrect (and there is no overload for ->). Also, the code model shown in the editor window does not point out a problem with using -> on a reference.
Comment 12 tbrunhoff 2012-10-05 19:27:50 UTC
My latest comment is based on testing with the version below (not my usual linux) using the WinAVR cross compiler.

Product Version: NetBeans IDE 7.2 (Build nbms-and-javadoc-9355-on-20120802)
Updates: Updates available
Java: 1.6.0_33; Java HotSpot(TM) 64-Bit Server VM 20.8-b03
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
User directory: C:\Users\toddb\AppData\Roaming\NetBeans\7.2
Cache directory: C:\Users\toddb\AppData\Local\NetBeans\Cache\7.2
Comment 13 tbrunhoff 2012-11-07 19:50:48 UTC
As above, partly fixed.
Comment 14 tbrunhoff 2013-04-16 20:56:38 UTC
> BTW, we plan to automatically replace "." to "->" and vice versa if need - see
> http://cnd.netbeans.org/issues/show_bug.cgi?id=97120  

This appeared to be partly fixed in 7.2, But is now broken again in the version below. Specifically, -> is no longer replaced with . when it should be, or is . replaced with -> when it should be. See below for specifics.

Product Version: NetBeans IDE Dev (Build 201303192300)
Java: 1.7.0_17; Java HotSpot(TM) Client VM 23.7-b01
Runtime: Java(TM) SE Runtime Environment 1.7.0_17-b02
System: Linux version 3.6.11-4.fc16.x86_64 running on i386; UTF-8; en_US (nb)
User directory: /home/toddb/.netbeans/dev
Cache directory: /home/toddb/.cache/netbeans/dev
Comment 15 tbrunhoff 2013-04-16 20:59:29 UTC
Correction: . to -> replacement still works. but -> to . replacement does not.
Comment 16 Vladimir Voskresensky 2013-04-17 09:54:40 UTC
Todd, Can you provide construction where "->" to "." worked before and broken now?
To be fair I've never implemented "->" to "." conversion and current fixes where again in "." to "->" domain :-)
Comment 17 tbrunhoff 2013-04-17 19:24:18 UTC
> Can you provide construction where "->" to "." worked before and broken now?

No... this was me running into a variety of problems and trying to decide what to report. This is *not* a regression, but it was the easiest one for me to whine about. Sorry to imply otherwise.
Comment 18 petrk 2015-09-14 11:01:20 UTC
It suppose this bug should be closed, because "." to "->" replacement makes sense because it reduces amount of typing. But if someone typed "->" then it almost certain that the object on the lefthand side is pointer or has overloaded operator. Otherwise there is no need to manually type such a long construction (->). Therefore if IDE replaces it to '.' automatically, it will mess up user's code.