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

Generate @Override on save when applicable #2144

Closed
NatoBoram opened this issue Oct 1, 2021 · 4 comments · Fixed by #2768
Closed

Generate @Override on save when applicable #2144

NatoBoram opened this issue Oct 1, 2021 · 4 comments · Fixed by #2768

Comments

@NatoBoram
Copy link

I want to know when a method is overriding its super class by automatically adding the @Override annotation on save.

Current Result
public String toString() {
	return super.toString();
}
Expected Result
@Override
public String toString() {
	return super.toString();
}
Additional Informations

Example config:

{
	"editor.codeActionsOnSave": {
		"source.generate.finalModifiers": true,
		"source.generate.override": true
	}
}
@rgrunber
Copy link
Member

rgrunber commented Oct 4, 2021

Seems like this would just require migrating the https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/tree/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/Java50CleanUp.java , or some portion of it to jdt.core.manipulation. It handles adding the override as needed.

datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 19, 2022
See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 26, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 26, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 26, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 26, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 27, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 27, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 27, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 27, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 27, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 27, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 28, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Oct 28, 2022
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Oct 28, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 28, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Oct 28, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Oct 28, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Oct 28, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Oct 28, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Oct 28, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 3, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 3, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Nov 3, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 3, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 4, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 7, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 7, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 8, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 8, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Nov 8, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Nov 8, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 8, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 8, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Nov 9, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
rgrunber pushed a commit to eclipse-jdtls/eclipse.jdt.ls that referenced this issue Nov 9, 2022
- Add new setting `java.cleanups.enabled` to list which clean ups to run
- Add clean up to prefix all member accesses with `this`
- Add clean up to prefix all static member accesses with class name
- Add clean up to insert missing `@Override`
- Add clean up to insert missing `@Deprecated`

See redhat-developer/vscode-java#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit to datho7561/vscode-java that referenced this issue Nov 9, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes redhat-developer#2144

Signed-off-by: David Thompson <davthomp@redhat.com>
rgrunber pushed a commit that referenced this issue Nov 9, 2022
- Add documentation (accessible through a command) for what each clean up does

Depends on eclipse-jdtls/eclipse.jdt.ls#2298
Closes #2144

Signed-off-by: David Thompson <davthomp@redhat.com>
@rgrunber
Copy link
Member

rgrunber commented Nov 9, 2022

This can now be accomplished by setting :

"java.cleanup.actionsOnSave": [
  "addOverride"
]

in a pre-release build from the marketplace.

Default is currently [] as it's difficult to have something everyone would agree with. Going forward, we should add more of these cleanups though.

@NatoBoram
Copy link
Author

Generally, these actions are there:

{
  "editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.fixAll.eslint": true,
    "source.fixAll.markdownlint": true,
    "source.fixAll.sortJSON": false,
    "source.generate.finalModifiers": true,
    "source.organizeImports": true,
    "source.sortMembers": true
  }
}

@datho7561
Copy link
Contributor

Generally, these actions are there:

I looked into implementing it this way, but this setting and functionality is exclusive to VS Code, and the core of the plugin (the language server) is used in many different editors besides VS Code, such as neovim. We wanted to be able to provide the different clean up actions in a way that all these editors can use. Thanks for mentioning this, though!

@rgrunber rgrunber added this to the End November milestone Nov 30, 2022
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.

3 participants