Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 15, 2020

Conversation

snjeza
Copy link
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 gorkem and fbricon April 6, 2020 16:40
@@ -140,7 +144,7 @@ public SourceAssistProcessor(PreferenceManager preferenceManager) {
}

// Generate Constructors
Optional<Either<Command, CodeAction>> generateConstructors = getGenerateConstructorsAction(params, context, type);
generateConstructors = getGenerateConstructorsAction(params, context, type, JavaCodeActionKind.SOURCE_GENERATE_CONSTRUCTORS);
Copy link
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
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
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
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
Contributor Author

snjeza commented Apr 6, 2020

@fbricon I have updated the PR.

@snjeza
Copy link
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