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 'hashCode()' and 'equals()' to Show Fixes for type declaration #1842

Merged

Conversation

CsCherrYY
Copy link
Contributor

@@ -555,4 +582,26 @@ public static InnovationContext getInnovationContext(CodeActionParams params, IP
public static ICompilationUnit getCompilationUnit(CodeActionParams params) {
return JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri());
}

public static Optional<Either<Command, CodeAction>> copySourceActionCommand(Optional<Either<Command, CodeAction>> sourceActionCommand) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this utility is not for source action only, i would use a more generic method name such as

public static Optional<Either<Command, CodeAction>> copyCodeActionCommand(Optional<Either<Command, CodeAction>> codeActionCommand)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to #1842 (comment), I'd like to remove this method since currently we don't need it.

if (node instanceof SimpleName) {
ASTNode parent = node.getParent();
if (parent instanceof TypeDeclaration) {
quickAssistHashCodeEquals = getHashCodeEqualsAction(params, JavaCodeActionKind.QUICK_ASSIST);
Copy link
Contributor

Choose a reason for hiding this comment

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

This exposes "Generate Getter and Setter..." code action menu at bulb of type declaration, that looks good to me.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

currently it appears only when i hover at the type name, but not in the other place of the same line.

but if you have a look at "Move", it also appears at the "public" modifier. I think that's better.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2021-08-31 191007

In the above screenshot, we can get the following information, including it's startpotision and length:

  • @entity, @Table(name = "owners") and public: modifiers
  • Owner: Class itself
  • Person: extended class
  • Serializable: implemented interface

For extending the place to show the light bulb, I have the following two plans:

  1. When the covered node or the covering node is one of the above nodes, we offer the light bulb (in the screenshot, the six red squares will be valid)
  2. calculate the first startpotision and the last endpotision as construct a range. If the covered node or the covering node is in the range, we offer the light bulb (in the screenshot, all parts between line 46 - line 49 will be valid)

@testforstephen which one do you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Use 1 to make it consistent with "Move...".

Signed-off-by: Shi Chen <chenshi@microsoft.com>
Signed-off-by: Shi Chen <chenshi@microsoft.com>
@CsCherrYY CsCherrYY force-pushed the cs-quickassist-hashCodeEquals branch from e452f1d to 2385b79 Compare August 31, 2021 06:33
Signed-off-by: Shi Chen <chenshi@microsoft.com>
@CsCherrYY
Copy link
Contributor Author

commit 1ed1d87 supports more places to show this light bulb, see the following gif:
promote appearance

@CsCherrYY
Copy link
Contributor Author

test this please

Signed-off-by: Shi Chen <chenshi@microsoft.com>
Signed-off-by: Shi Chen <chenshi@microsoft.com>
Signed-off-by: Shi Chen <chenshi@microsoft.com>
@CsCherrYY
Copy link
Contributor Author

922df18 optimizes the source location, if we use quickfix out of the class body to generate the source, the generated source location will be the end of the class body. see the following gif:
optimize

Copy link
Contributor

@testforstephen testforstephen left a comment

Choose a reason for hiding this comment

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

LGTM

@testforstephen
Copy link
Contributor

test this please

@testforstephen testforstephen merged commit 91dd9ff into eclipse-jdtls:master Sep 7, 2021
@testforstephen testforstephen added this to the Mid September 2021 milestone Sep 7, 2021
@CsCherrYY CsCherrYY deleted the cs-quickassist-hashCodeEquals branch September 7, 2021 01:46
@Eskibear Eskibear mentioned this pull request Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants