Skip to content

Commit

Permalink
Merge pull request #525 from mrglavas/code-action-unification
Browse files Browse the repository at this point in the history
Resolve functional issues with ExtendClassProposal.
  • Loading branch information
mrglavas authored Oct 12, 2023
2 parents 5621fd6 + 02bbbab commit df80990
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,36 @@
*******************************************************************************/
package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal;

import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ASTRewriteCorrectionProposal;
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ImplementInterfaceProposal;
import org.eclipse.lsp4j.CodeActionKind;

public class ExtendClassProposal extends ImplementInterfaceProposal {
public class ExtendClassProposal extends ASTRewriteCorrectionProposal {

public ExtendClassProposal(String name, PsiFile sourceCU, PsiClass binding, PsiFile astRoot,
String interfaceType, int relevance) {
super(null, binding, astRoot, interfaceType, relevance, sourceCU);
private final PsiClass fBinding;
private final String parentClassType;

public ExtendClassProposal(String name, PsiFile targetCU, PsiFile sourceCU,
PsiClass binding, String parentClassType, int relevance) {
super(name, CodeActionKind.QuickFix, targetCU, relevance, sourceCU);
fBinding = binding;
this.parentClassType = parentClassType;
}

@Override
public void performUpdate() {
final Project project = fBinding.getProject();
final PsiClass parentClass = JavaPsiFacade.getInstance(project).
findClass(parentClassType, GlobalSearchScope.allScope(project));
if (parentClass != null) {
final PsiReferenceList extendsList = fBinding.getExtendsList();
if (extendsList != null) {
extendsList.add(PsiElementFactory.getInstance(project).
createClassReferenceElement(parentClass));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public List<? extends CodeAction> getCodeActions(JavaCodeActionContext context,
String title = Messages.getMessage("LetClassExtend",
parentType.getName(),
ServletConstants.HTTP_SERVLET);
ChangeCorrectionProposal proposal = new ExtendClassProposal(title,
context.getSource().getCompilationUnit(), parentType, context.getASTRoot(),
ChangeCorrectionProposal proposal = new ExtendClassProposal(title, context.getCompilationUnit(),
context.getSource().getCompilationUnit(), parentType,
"jakarta.servlet.http.HttpServlet", 0);
CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
if (codeAction != null) {
Expand Down

0 comments on commit df80990

Please sign in to comment.