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 Getter and Setter to Show Fixes for type declaration #1883

Merged
merged 4 commits into from
Sep 27, 2021

Conversation

CsCherrYY
Copy link
Contributor

getset

Part of redhat-developer/vscode-java#2057

And a follow of redhat-developer/vscode-java#2057 (comment), IMO it's better to make all the QuickPick items (for generating getter and setter) picked by default. Does it make sense?

cc: @nickzhums, @testforstephen

Signed-off-by: Shi Chen [email protected]

Optional<Either<Command, CodeAction>> getterSetter = getGetterSetterAction(params, context, type);
addSourceActionCommand($, params.getContext(), getterSetter);
// Generate Getter and Setter QuickAssist
if (isInTypeDeclaration(context)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isInTypeDeclaration(context) is called multiple times in source action handler, you can assign it to a local variable boolean isInTypeDeclaration = isInTypeDeclaration(context); for reuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

Comment on lines 282 to 288
ASTNode declarationNode = null;
CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(type.getCompilationUnit(), CoreASTProvider.WAIT_YES, monitor);
Range range = params.getRange();
if (astRoot != null && range != null) {
ASTNode node = NodeFinder.perform(astRoot, DiagnosticsHelper.getStartOffset(type.getCompilationUnit(), range), DiagnosticsHelper.getLength(type.getCompilationUnit(), range));
declarationNode = SourceAssistProcessor.getDeclarationNode(node);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This block of code is used to check if the cursor is in a position of type declaration. Since the external invoker has already checked the cursor position, why not to pass it to getGetterSetterAction function directly?

Signed-off-by: Shi Chen <[email protected]>
@@ -37,6 +37,7 @@
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.NodeFinder;
Copy link
Contributor

Choose a reason for hiding this comment

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

unused import

@@ -74,6 +75,7 @@
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Range;
Copy link
Contributor

Choose a reason for hiding this comment

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

unused import

codeActions = server.codeAction(params).join();
Assert.assertNotNull(codeActions);
quickAssistActions = CodeActionHandlerTest.findActions(codeActions, JavaCodeActionKind.QUICK_ASSIST);
Assert.assertFalse(quickAssistActions.isEmpty());
Copy link
Contributor

Choose a reason for hiding this comment

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

this assert is not relevant with this test case. You could remove it.

Signed-off-by: Shi Chen <[email protected]>
@testforstephen testforstephen merged commit 6a473a3 into eclipse-jdtls:master Sep 27, 2021
@testforstephen testforstephen added this to the End September 2021 milestone Sep 27, 2021
@CsCherrYY CsCherrYY deleted the cs-getset-improve branch May 11, 2022 08:14
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.

2 participants