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

CodeAction for missing required attribute #1860

Closed
angelozerr opened this issue Aug 27, 2021 · 4 comments · Fixed by #2335
Closed

CodeAction for missing required attribute #1860

angelozerr opened this issue Aug 27, 2021 · 4 comments · Fixed by #2335

Comments

@angelozerr
Copy link

angelozerr commented Aug 27, 2021

Given this class:

package org.acme;

import javax.annotation.Generated;

@Generated
public class Foo {
	
}

The Generated has an error because value is required.:

image

It should be nice to provide a code action which insert this required attribute like Eclipse IDE provides:

image

CodeAction should fix like this:

package org.acme;

import javax.annotation.Generated;

@Generated(value = { "" })
public class Foo {

}
@fbricon
Copy link
Contributor

fbricon commented Aug 27, 2021

@angelozerr are you interested in contributing that feature?

@angelozerr
Copy link
Author

angelozerr commented Aug 27, 2021

For the moment I'm busy, I don't know when I could do that, but I think I know how to implement this issue: we should copy/paste org.eclipse.jdt.internal.ui.text.correction.proposals.MissingAnnotationAttributesProposal inside JDT LS and adapt it.

@datho7561
Copy link
Contributor

@rgrunber I'm interested in looking into this issue. I think it could be helpful for MicroProfile, which uses a lot of annotations.

The other aspect of this issue is adding the required attributes automatically when accepting the completion for the annotation. Is there a setting in Eclipse to do this? If so, then I could take a look into adding it to eclipse.jdt.ls. If it's not already available in Eclipse (jdt.core/jdt.ui), maybe it's worthwhile adding it there first?

@rgrunber
Copy link
Contributor

rgrunber commented Nov 1, 2022

Currently in Eclipse (JDT), there is no code to do this automatically as a cleanup, or on save. Only resolving it on the diagnostic/error marker.

However, the important logic in MissingAnnotationAttributesProposal is purely using rewriteAST(), which is what any cleanup uses. So it should be very easy to move that logic somewhere in core.manipulation and re-use it (in the UI components and JDT-LS).

Only issue I see if we want to move not only the code, but the class as a whole. lt extends LinkedCorrectionProposal which is on the UI side. it's field LinkedProposalModel seems to just use LinkedProposalModelCore now. I'm not sure if ASTRewriteCorrectionProposal can be easily migrated.

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

Successfully merging a pull request may close this issue.

4 participants