Bug 558621 - [content assist] Eclipse suggests 'new' for qualified allocation even if no inner class exists.
Summary: [content assist] Eclipse suggests 'new' for qualified allocation even if no i...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.15   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-25 09:43 EST by Ori Marko CLA
Modified: 2023-12-07 00:21 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ori Marko CLA 2019-12-25 09:43:51 EST
When adding inner static class 

  public static BuilderExampleBuilder builder() {
     return new BuilderExampleBuilder();
  }

  public static class BuilderExampleBuilder {
    BuilderExampleBuilder() {}
  }

And using auto suggest on builder methods by 

    MyClass.BuilderExampleBuilder.build().

Eclipse suggest `new` as part of the methods (with wait(),...)

I think Eclipse shouldn't suggest new, because it's irrelevant
Comment 2 Stephan Herrmann CLA 2019-12-25 12:05:59 EST
S.t. seems to be missing in your example.
Given:    MyClass.builder()
Required: MyClass.BuilderExampleBuilder.build()

I am guessing the following:
//---
public class MyClass {
	public static BuilderExampleBuilder builder() {
		return new BuilderExampleBuilder();
	}

	public static class BuilderExampleBuilder {
		BuilderExampleBuilder() { }
	}

	void test() {
		MyClass.builder().|
	}
}
//---

Completing at '|'

In this case the keyword 'new' is proposed, because the LHS could be the receiver of a qualified allocation.

Assume we have a non-static inner class InnerBuilder inside BuilderExampleBuilder, then the following would be legal:
    MyClass.builder().new InnerBuilder();
    


Am I missing anything?
Comment 3 Stephan Herrmann CLA 2019-12-25 12:09:22 EST
It is indeed wrong to propose 'new' even if no inner class of the LHS type exists.
Comment 4 Ori Marko CLA 2019-12-26 01:18:21 EST
From your comments, you agree it's a bug so suggest new because there's no non-static inner class exists, right?
Comment 5 Stephan Herrmann CLA 2019-12-26 04:05:22 EST
(In reply to Ori Marko from comment #4)
> From your comments, you agree it's a bug so suggest new because there's no
> non-static inner class exists, right?

*If* there is no non-static inner class, yes. But from comment 0 I could not see what exactly is your case, because your code wouldn't compile anyway.
Comment 6 Ori Marko CLA 2019-12-26 04:11:52 EST
Yes, I can't edit comment, but there's no inner class, full class example:

    public class MyClass {
	public static BuilderExampleBuilder builder() {
	    return new BuilderExampleBuilder();
	  }
	  public static class BuilderExampleBuilder {
	    BuilderExampleBuilder() {}
	  }
	  public static void main(String[] args) {	
		  MyClass.builder();
	  }
   }

 MyClass.builder(). shouldn't propose new as an option
Comment 7 Eclipse Genie CLA 2021-12-16 08:37:20 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 8 Ori Marko CLA 2021-12-16 08:55:02 EST
problem still occurs on latest Eclipse, I still want the feature
Comment 9 Eclipse Genie CLA 2023-12-07 00:21:12 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.