-
Notifications
You must be signed in to change notification settings - Fork 32
Issue 1401: QuickFix for ServerEndpoint paths without a leading slash #1412
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
Merged
venmanyarun
merged 8 commits into
OpenLiberty:lsp4jakarta-0.2.5-integration
from
Joseph-Bineesh:issue_1401_v2
Oct 23, 2025
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b331d0
Update Error code and test case
Joseph-Bineesh 8254e46
PrefixSlash quickfix draft
Joseph-Bineesh 4624db0
Prefix Slash proposal implementation
Joseph-Bineesh 8ebbe9f
Copyright
Joseph-Bineesh 693ee98
Testcase update for PrefixSlashAnnotationQuickFix
Joseph-Bineesh 92a2d4a
Refactor performUpdate
Joseph-Bineesh 435a39a
Copyright Updates
Joseph-Bineesh 075f8ca
Merge branch 'lsp4jakarta-0.2.5' into issue_1401_v2
Joseph-Bineesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
.../tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/PrefixSlashAnnotationProposal.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 IBM Corporation and others. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License v. 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
| package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal; | ||
|
|
||
| import com.intellij.openapi.project.Project; | ||
| import com.intellij.psi.*; | ||
| import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ASTRewriteCorrectionProposal; | ||
| import org.eclipse.lsp4j.CodeActionKind; | ||
|
|
||
| public class PrefixSlashAnnotationProposal extends ASTRewriteCorrectionProposal { | ||
| private final PsiAnnotation fAnnotation; | ||
|
|
||
| public PrefixSlashAnnotationProposal(String name, int relevance, PsiFile sourceCU, PsiElement declaringNode, PsiAnnotation annotationNode) { | ||
| super(name, CodeActionKind.QuickFix, declaringNode, relevance, sourceCU); | ||
| this.fAnnotation = annotationNode; | ||
| } | ||
|
|
||
| @Override | ||
| public void performUpdate() { | ||
| final String FORWARD_SLASH = "/"; | ||
| final String ESCAPE_QUOTE = "\""; | ||
| if (fAnnotation != null) { | ||
| PsiElementFactory factory = JavaPsiFacade.getElementFactory(fAnnotation.getProject()); | ||
| for (PsiNameValuePair pair : fAnnotation.getParameterList().getAttributes()) { | ||
| if (pair.getValue() instanceof PsiLiteralExpression literal && literal.getValue() instanceof String valueText) { | ||
| if (!valueText.startsWith(FORWARD_SLASH)) { | ||
| fAnnotation.setDeclaredAttributeValue(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME, factory.createExpressionFromText( | ||
| String.format("%s%s%s%s", ESCAPE_QUOTE, FORWARD_SLASH, valueText, ESCAPE_QUOTE), | ||
| fAnnotation | ||
| )); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
96 changes: 96 additions & 0 deletions
96
...tellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/PrefixSlashAnnotationQuickFix.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 IBM Corporation and others. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License v. 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
| package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.quickfix; | ||
|
|
||
| import com.intellij.psi.*; | ||
| 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.PrefixSlashAnnotationProposal; | ||
| import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.IJavaCodeActionParticipant; | ||
| import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; | ||
| import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; | ||
| import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; | ||
| import io.openliberty.tools.intellij.util.ExceptionUtil; | ||
| import org.eclipse.lsp4j.CodeAction; | ||
| import org.eclipse.lsp4j.Diagnostic; | ||
| import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.logging.Logger; | ||
|
|
||
| public class PrefixSlashAnnotationQuickFix implements IJavaCodeActionParticipant { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(PrefixSlashAnnotationQuickFix.class.getName()); | ||
|
|
||
| /** | ||
| * Returns the unique identifier of this code action participant. | ||
| * | ||
| * @return the unique identifier of this code action participant | ||
| */ | ||
| @Override | ||
| public String getParticipantId() { | ||
| return PrefixSlashAnnotationQuickFix.class.getName(); | ||
| } | ||
|
|
||
| /** | ||
| * Return the code action list for a given compilation unit and null otherwise. | ||
| * | ||
| * @param context the java code action context. | ||
| * @param diagnostic the diagnostic which must be fixed and null otherwise. | ||
| * @return the code action list for a given compilation unit and null otherwise. | ||
| */ | ||
| @Override | ||
| public List<? extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic) { | ||
| PsiElement node = context.getCoveredNode(); | ||
| PsiElement parentType = getBinding(node); | ||
| if (parentType != null) { | ||
| List<CodeAction> codeActions = new ArrayList<>(); | ||
| codeActions.add(JDTUtils.createCodeAction(context, diagnostic, getLabel(), getParticipantId())); | ||
| return codeActions; | ||
| } | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the code action with the TextEdits filled in. | ||
| * | ||
| * @param context the code action context to resolve | ||
| * @return the code action with the TextEdits filled in | ||
| */ | ||
| @Override | ||
| public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { | ||
| final CodeAction toResolve = context.getUnresolved(); | ||
| final PsiElement node = context.getCoveredNode(); | ||
| PsiElement declaringNode = getBinding(context.getCoveredNode()); | ||
| PsiAnnotation annotationNode = PsiTreeUtil.getParentOfType(node, PsiAnnotation.class); | ||
| String label = getLabel(); | ||
| ChangeCorrectionProposal proposal = new PrefixSlashAnnotationProposal(label, 0, context.getSource().getCompilationUnit(), declaringNode, annotationNode); | ||
| ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action " + label); | ||
| return toResolve; | ||
| } | ||
|
|
||
| protected static PsiElement getBinding(PsiElement node) { | ||
| PsiElement parent = PsiTreeUtil.getParentOfType(node, PsiModifierListOwner.class); | ||
| if (parent != null) { | ||
| return parent; | ||
| } | ||
| return PsiTreeUtil.getParentOfType(node, PsiClass.class); | ||
| } | ||
|
|
||
| protected String getLabel() { | ||
| return Messages.getMessage("PrefixSlashToValueAttribute"); // uses Java syntax | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.