Skip to content

Add 'Generate constructor' option to 'Show Fixes' options for fields#1405

Merged
fbricon merged 1 commit intoeclipse-jdtls:masterfrom
snjeza:issue-1358
Apr 15, 2020
Merged

Add 'Generate constructor' option to 'Show Fixes' options for fields#1405
fbricon merged 1 commit intoeclipse-jdtls:masterfrom
snjeza:issue-1358

Conversation

@snjeza
Copy link
Copy Markdown
Contributor

@snjeza snjeza commented Apr 6, 2020

Fixes redhat-developer/vscode-java#1358

Signed-off-by: Snjezana Peco [email protected]

@snjeza snjeza requested review from fbricon and gorkem April 6, 2020 16:40

// Generate Constructors
Optional<Either<Command, CodeAction>> generateConstructors = getGenerateConstructorsAction(params, context, type);
generateConstructors = getGenerateConstructorsAction(params, context, type, JavaCodeActionKind.SOURCE_GENERATE_CONSTRUCTORS);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're basically recomputing the actions a 2nd time, seems suboptimal. Couldn't we just copy the ones we have already and change their kind?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@fbricon
Copy link
Copy Markdown
Contributor

fbricon commented Apr 6, 2020

Starting from

public class Foo {

	private String name;

}

After applying the code action to generate the constructor, I get:

public class Foo {

	private String name;

	public Foo(String name) {
		this.name = name;
	}

}

So far so good, but then, the Generate Constructor... code actions is still available on name. And for sure, lets you generate a duplicate constructor. In IntelliJ IDEA, the Generate constructor quick fix is no longer available, after generating the constructor.

@snjeza
Copy link
Copy Markdown
Contributor Author

snjeza commented Apr 6, 2020

So far so good, but then, the Generate Constructor... code actions is still available. And for sure, lets you generate a duplicate constructor. In IntelliJ IDEA, the Generate constructor quick fix is no longer available, after generating the constructor.

The code to compute constructors is in GenerateConstructorsHandler, so we can fix it

@snjeza
Copy link
Copy Markdown
Contributor Author

snjeza commented Apr 6, 2020

@fbricon I have updated the PR.

@snjeza
Copy link
Copy Markdown
Contributor Author

snjeza commented Apr 15, 2020

In IntelliJ IDEA, the Generate constructor quick fix is no longer available, after generating the constructor.
The code to compute constructors is in GenerateConstructorsHandler, so we can fix it

IntelliJ IDEA creates only one constructor when existing more fields. Eclipse/Java LS creates multiple constructors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "Generate constructor" option in "Show Fixes" options for fields

2 participants