Skip to content

Commit

Permalink
update the method in jdt utils
Browse files Browse the repository at this point in the history
  • Loading branch information
aparnamichael committed Dec 5, 2023
1 parent af4e448 commit 726aebe
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 36 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,13 +92,14 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ 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(), null));
}
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 @@ -92,22 +93,9 @@ private List<CodeAction> addConstructor(Diagnostic diagnostic, JavaCodeActionCon
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(), null);
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 @@ -117,7 +117,7 @@ protected void addAttributes(Diagnostic diagnostic, JavaCodeActionContext contex
*/
private void addAttribute(Diagnostic diagnostic, JavaCodeActionContext context, List<CodeAction> codeActions, String name, String... attributes) {
String label = getLabel(name, attributes);
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, label, getParticipantId()));
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, label, getParticipantId(), null));
}

protected PsiModifierListOwner getBinding(PsiElement node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void removeModifier(Diagnostic diagnostic, JavaCodeActionContext context
PsiElement node = context.getCoveredNode();
PsiModifierListOwner modifierListOwner = PsiTreeUtil.getParentOfType(node, PsiModifierListOwner.class);
String label = getLabel(modifierListOwner, modifier);
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, label, getParticipantId()));
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, label, getParticipantId(), null));
}

private String getLabel(PsiModifierListOwner modifierListOwner, String... modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ 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(), null));
}
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 @@ -108,25 +109,14 @@ protected PsiClass getBinding(PsiElement node) {

private List<CodeAction> addConstructor(Diagnostic diagnostic, JavaCodeActionContext context) {
List<CodeAction> codeActions = new ArrayList<>();
String[] constructorNames = {Messages.getMessage("AddNoArgProtectedConstructor"), Messages.getMessage("AddNoArgPublicConstructor")};
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(),
null);
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 @@ -72,7 +72,7 @@ public List<? extends CodeAction> getCodeActions(JavaCodeActionContext context,
String title = Messages.getMessage("LetClassExtend",
parentType.getName(),
ServletConstants.HTTP_SERVLET);
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, title, getParticipantId()));
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, title, getParticipantId(), null));
}
return codeActions;
}
Expand Down

0 comments on commit 726aebe

Please sign in to comment.