-
Notifications
You must be signed in to change notification settings - Fork 408
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
Add Getter and Setter to Show Fixes for type declaration #1883
Conversation
Signed-off-by: Shi Chen <[email protected]>
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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
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); | ||
} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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]>
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]