Skip to content

Commit

Permalink
Merge pull request OpenLiberty#594 from aparnamichael/issue-582_Creat…
Browse files Browse the repository at this point in the history
…eCodeAction_Update

Fixes OpenLiberty#582 - Update createcodeaction method in JDTutils to support different extended data.
  • Loading branch information
aparnamichael authored Dec 6, 2023
2 parents 199a332 + a82170a commit 563529b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class JDTUtils {
// Percent encoding obtained from: https://en.wikipedia.org/wiki/Percent-encoding#Reserved_characters
Expand Down Expand Up @@ -91,15 +92,21 @@ public static List<PsiMethod> getFieldAccessors(PsiJavaFile unit, PsiField field
* @return CodeAction
*/
public static CodeAction createCodeAction(JavaCodeActionContext context, Diagnostic diagnostic,
String quickFixMessage, String participantId) {
String quickFixMessage, String participantId,
Map<String, Object> extendedData) {
ExtendedCodeAction codeAction = new ExtendedCodeAction(quickFixMessage);
codeAction.setRelevance(0);
codeAction.setDiagnostics(Collections.singletonList(diagnostic));
codeAction.setKind(CodeActionKind.QuickFix);
codeAction.setData(new CodeActionResolveData(context.getUri(), participantId,
context.getParams().getRange(), Collections.emptyMap(),
context.getParams().getRange(), extendedData != null ? extendedData : Collections.emptyMap(),
context.getParams().isResourceOperationSupported(),
context.getParams().isCommandConfigurationUpdateSupported()));
return codeAction;
}

public static CodeAction createCodeAction(JavaCodeActionContext context, Diagnostic diagnostic,
String quickFixMessage, String participantId) {
return createCodeAction(context, diagnostic, quickFixMessage, participantId, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public List<? extends CodeAction> getCodeActions(JavaCodeActionContext context,
final PsiMethod parentType = getBinding(node);

if (parentType != null) {
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, TITLE_MESSAGE, getParticipantId()));
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, TITLE_MESSAGE,
getParticipantId()));
}
return codeActions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.Messages;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.AddConstructorProposal;
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.ExtendedCodeAction;
Expand Down Expand Up @@ -89,25 +90,14 @@ protected PsiClass getBinding(PsiElement node) {

private List<CodeAction> addConstructor(Diagnostic diagnostic, JavaCodeActionContext context) {
List<CodeAction> codeActions = new ArrayList<>();
String[] constructorNames = {Messages.getMessage("AddProtectedConstructor"), Messages.getMessage("AddPublicConstructor")};
String[] constructorNames = {Messages.getMessage("AddProtectedConstructor"),
Messages.getMessage("AddPublicConstructor")};

for (String name : constructorNames) {
CodeAction codeAction = createCodeAction(context, diagnostic, name);
CodeAction codeAction = JDTUtils.createCodeAction(context, diagnostic, name,
getParticipantId());
codeActions.add(codeAction);
}
return codeActions;
}

private CodeAction createCodeAction(JavaCodeActionContext context, Diagnostic diagnostic, String label) {
ExtendedCodeAction codeAction = new ExtendedCodeAction(label);
codeAction.setRelevance(0);
codeAction.setDiagnostics(Collections.singletonList(diagnostic));
codeAction.setKind(CodeActionKind.QuickFix);
codeAction.setTitle(label);
codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(),
context.getParams().getRange(), Collections.emptyMap(),
context.getParams().isResourceOperationSupported(),
context.getParams().isCommandConfigurationUpdateSupported()));
return codeAction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public List<? extends CodeAction> getCodeActions(JavaCodeActionContext context,
final PsiMethod parentMethod = PsiTreeUtil.getParentOfType(node, PsiMethod.class);

if (parentMethod != null) {
return Collections.singletonList(JDTUtils.createCodeAction(context, diagnostic, TITLE_MESSAGE, getParticipantId()));
return Collections.singletonList(JDTUtils.createCodeAction(context, diagnostic, TITLE_MESSAGE,
getParticipantId()));
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.Messages;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.AddConstructorProposal;
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.ExtendedCodeAction;
Expand Down Expand Up @@ -111,22 +112,9 @@ private List<CodeAction> addConstructor(Diagnostic diagnostic, JavaCodeActionCon
String[] constructorNames = {Messages.getMessage("AddNoArgProtectedConstructor"), Messages.getMessage("AddNoArgPublicConstructor")};

for (String name : constructorNames) {
CodeAction codeAction = createCodeAction(context, diagnostic, name);
CodeAction codeAction = JDTUtils.createCodeAction(context, diagnostic, name, getParticipantId());
codeActions.add(codeAction);
}
return codeActions;
}

private CodeAction createCodeAction(JavaCodeActionContext context, Diagnostic diagnostic, String label) {
ExtendedCodeAction codeAction = new ExtendedCodeAction(label);
codeAction.setRelevance(0);
codeAction.setDiagnostics(Collections.singletonList(diagnostic));
codeAction.setKind(CodeActionKind.QuickFix);
codeAction.setTitle(label);
codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(),
context.getParams().getRange(), Collections.emptyMap(),
context.getParams().isResourceOperationSupported(),
context.getParams().isCommandConfigurationUpdateSupported()));
return codeAction;
}
}

0 comments on commit 563529b

Please sign in to comment.