Bug 264442 - Code assist bug when assigning class properties to constants
Summary: Code assist bug when assigning class properties to constants
Status: REOPENED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P1 normal (vote)
Target Milestone: ---   Edit
Assignee: Zhongwei Zhao CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-10 18:36 EST by Tom Walter CLA
Modified: 2020-05-14 10:16 EDT (History)
6 users (show)

See Also:
zhaozhongwei: iplog+
zhaozhongwei: review? (ganoro)
qiangsheng.w: review-
zhaozhongwei: review? (zhaozhongwei)


Attachments
pathc (1.65 KB, patch)
2010-01-24 02:22 EST, Zhongwei Zhao CLA
no flags Details | Diff
Code assist bug when assigning class properties to constants (2.00 KB, patch)
2010-06-14 08:33 EDT, ronen hamias CLA
no flags Details | Diff
patch (1.10 KB, patch)
2010-09-09 23:40 EDT, Zhongwei Zhao CLA
no flags Details | Diff
patch (2.03 KB, patch)
2010-10-22 03:07 EDT, xu jiaxi CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Walter CLA 2009-02-10 18:36:20 EST
Build ID: M20080911-1700

Steps To Reproduce:
<?php
define('AGlobalConst', 1);
class AClass
{
	const AClassConst = 1;
}
class Test
{
	protected $var = A|; // <- cursor
}
?>

Expect to have code assist suggest:
'AClass'
'AGlobalConst'

Actual:
'No completions available' error in status bar.

More information:
Comment 1 Zhongwei Zhao CLA 2010-01-24 02:22:12 EST
Created attachment 157051 [details]
pathc
Comment 2 Zhongwei Zhao CLA 2010-01-24 03:43:51 EST
The patch will cause testClassStatement1.pdtt and testClassStatement2.pdtt fail.
Comment 3 ronen hamias CLA 2010-06-14 08:33:37 EDT
Created attachment 171820 [details]
Code assist bug when assigning class properties to constants
Comment 4 Zhongwei Zhao CLA 2010-06-14 10:11:48 EDT
Hi Ronen

Thanks for your patch!

It seems that your patch is the same as mine,there was unit test failure ,but now it disappears:)

Contributed by Ronen!
Comment 5 Michael Spector CLA 2010-06-17 01:01:02 EDT
The patch could be improved so constants are not suggested in the following case:

class A {
 |
}

but only in a right-hand side of an assignment expression:

class A {
 something = |
}
Comment 6 Zhongwei Zhao CLA 2010-06-17 03:42:44 EDT
Hi Michael


Thanks for your suggestion.

And we can have:
class A {
 echo CONSTANT;
}

So do you mean CONSTANT should not be the first word?
Comment 7 Gadi Goldbarg CLA 2010-06-18 11:22:28 EDT
Still reproducible for PDT-2.2.0.v20100616

The same behavior is looking at this PDT build
No completion available

Reopen this issue
If will have the fix for next build please resolved for them

Reopened by
Teodor Kirkov
teodor.k@zend.com
Comment 8 Zhongwei Zhao CLA 2010-08-29 22:02:44 EDT
works now
Comment 9 Petyo Tanchev CLA 2010-08-31 06:44:35 EDT
Tested on 2.2.1.v20100829

Using the example in the bug description:
AGlobalConst is suggested but AClass is NOT.
Comment 10 Zhongwei Zhao CLA 2010-09-01 20:40:28 EDT
I have a question,if class AClass does not contain any constant do we need to show 'AClass'?
and further,we have the following content:

<?php
define('AGlobalConst', 1);
class AClass
{
const AClassConst = 1;
public static $field;
}
class Test
{
protected $var = AAClass::|; // <- cursor
}
?>

do we need we only to show 'AClassConst'?
Comment 11 Roy Ganor CLA 2010-09-03 17:34:23 EDT
for performance reasons I would not show only the classes that have const but all classes.
Comment 12 Zhongwei Zhao CLA 2010-09-09 23:40:56 EDT
Created attachment 178582 [details]
patch
Comment 13 Q.S. Wang CLA 2010-09-12 23:52:56 EDT
Still issues of namespace

1. The namespace AA is listed and the generated code is broke.
<?php
namespace  AA;


define('AGlobalConst', 1);
class AClass
{
    const AClassConst = 1;
}
class Test
{
  AA\::    
}
?>

2. Select the class AClass, the generated code is broke.

<?php
use AA\AClass;
namespace  AA;


define('AGlobalConst', 1);
class AClass
{
    const AClassConst = 1;
}
class Test
{
AClass::
}
?>
Comment 14 Zhongwei Zhao CLA 2010-09-14 01:37:12 EDT
Hi QS
 
for 1st case,it is not special for this bug,and I have committed code that fixes it.
for 2nd case,I could not reproduce it,I updated to the latest code(head).
Comment 15 Q.S. Wang CLA 2010-09-14 02:06:36 EDT
I'm using the latest code from 7.3 and haven't tried the head code.
I assume that you plan to port the patch back to 7.3, otherwise no review needed at all. 

The original code is as below.

<?php
namespace  AA;


define('AGlobalConst', 1);
class AClass
{
    const AClassConst = 1;
}
class Test
{
AClas | // CA here.
}
?>
Comment 16 Zhongwei Zhao CLA 2010-09-14 02:47:46 EDT
(In reply to comment #15)
> I'm using the latest code from 7.3 and haven't tried the head code.
> I assume that you plan to port the patch back to 7.3, otherwise no review
> needed at all. 
> 
> The original code is as below.
> 
> <?php
> namespace  AA;
> 
> 
> define('AGlobalConst', 1);
> class AClass
> {
>     const AClassConst = 1;
> }
> class Test
> {
> AClas | // CA here.
> }
> ?>

instead insert "use AA\AClass;",I got an exception,and I think the problem is we should not propose anything at '|' as Michael said.I will think about this later:)
Comment 17 xu jiaxi CLA 2010-10-22 03:07:14 EDT
Created attachment 181466 [details]
patch

(In reply to comment #13)
> 2. Select the class AClass, the generated code is broke.
> 
> <?php
> use AA\AClass;
> namespace  AA;
> 
> 
> define('AGlobalConst', 1);
> class AClass
> {
> const AClassConst = 1;
> }
> class Test
> {
> AClass::
> }
> ?>
There is no need to insert the use statement, this patch can fix the issue
Comment 18 Q.S. Wang CLA 2010-11-04 04:01:55 EDT
The patch looks all right. Can you please add unit test for it?
Comment 19 Zhongwei Zhao CLA 2010-11-05 00:46:54 EDT
(In reply to comment #15)
> I'm using the latest code from 7.3 and haven't tried the head code.
> I assume that you plan to port the patch back to 7.3, otherwise no review needed
> at all.
> 
> The original code is as below.
> 
> <?php
> namespace  AA;
> 
> 
> define('AGlobalConst', 1);
> class AClass
> {
> const AClassConst = 1;
> }
> class Test
> {
> AClas | // CA here.
> }
> ?>
The problem is we should not show any proposal at the above location.I have reverted my patch and my patch will cause tests failing.

Xu's patch is based on my wrong patch,sorry for this.