Skip to content

Commit

Permalink
Merge pull request #1084 from anusreelakshmi934/Issue#870
Browse files Browse the repository at this point in the history
Display short names for Quick fixes - Issue#870
  • Loading branch information
anusreelakshmi934 authored Nov 13, 2024
2 parents 3e3c97c + 00520e6 commit 0c6faa2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ protected static boolean nameEndsWith(String fqName, String name) {
* @param fqName a fully qualified name or simple name
* @return simple name for given fully qualified name
*/
protected static String getSimpleName(String fqName) {
public static String getSimpleName(String fqName) {
int idx = fqName.lastIndexOf('.');
if (idx != -1 && idx != fqName.length() - 1) {
return fqName.substring(idx + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.AbstractDiagnosticsCollector;
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.ModifyModifiersProposal;
Expand Down Expand Up @@ -81,7 +82,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
private void removeConstraintAnnotationsCodeActions(Diagnostic diagnostic, JavaCodeActionContext context, List<CodeAction> codeActions) {

final String annotationName = diagnostic.getData().toString().replace("\"", "");
final String name = Messages.getMessage("RemoveConstraintAnnotation", annotationName);
final String name = Messages.getMessage("RemoveConstraintAnnotation", AbstractDiagnosticsCollector.getSimpleName(annotationName));
Map<String, Object> extendedData = new HashMap<>();
extendedData.put(ANNOTATION_NAME, annotationName);
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, name, getParticipantId(), extendedData));
Expand Down Expand Up @@ -150,6 +151,7 @@ private void removeStaticModifierCodeActions(Diagnostic diagnostic, JavaCodeActi
final String name = Messages.getMessage("RemoveStaticModifier");
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, name, getParticipantId()));
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public List<? extends CodeAction> getCodeActions(JavaCodeActionContext context,
private String getLabel(PsiParameter parameter,List<String> annotationsToRemove) {
final StringBuilder sb = new StringBuilder();
// Java annotations in comma delimited list, assume that is ok.
sb.append("'@").append(getShortName(annotationsToRemove.get(0))).append("'");
sb.append("@").append(getShortName(annotationsToRemove.get(0)));
for (int j = 1; j < annotationsToRemove.size(); ++j) {
sb.append(", '@").append(getShortName(annotationsToRemove.get(j))).append("'");
sb.append(", @").append(getShortName(annotationsToRemove.get(j)));
}
return Messages.getMessage("RemoveTheModifierFromParameter", sb.toString(), parameter.getName().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ InsertItem = Insert {0}
RemoveItem = Remove {0}

# RemoveParamAnnotationQuickFix
RemoveTheModifierFromParameter = Remove the {0} modifier from parameter ''{1}''
RemoveTheModifierFromParameter = Remove the {0} modifier from parameter {1}

# RemoveModifierConflictQuickFix
RemoveTheModifierFromThisVariable = Remove the ''{0}'' modifier from this variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void fieldConstraintValidation() throws Exception {

JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d1);
TextEdit te = te(0, 0, 64, 1, newText);
CodeAction ca = ca(uri, "Remove constraint annotation jakarta.validation.constraints.AssertTrue from element", d1, te);
CodeAction ca = ca(uri, "Remove constraint annotation AssertTrue from element", d1, te);

assertJavaCodeAction(codeActionParams, utils, ca);

Expand Down Expand Up @@ -215,7 +215,7 @@ public void fieldConstraintValidation() throws Exception {
JakartaJavaCodeActionParams codeActionParams2 = createCodeActionParams(uri, d19);
TextEdit te1 = te(0, 0, 64, 1, newText6);
TextEdit te2 = te(0, 0, 64, 1, newText7);
CodeAction ca1 = ca(uri, "Remove constraint annotation jakarta.validation.constraints.AssertTrue from element", d19, te1);
CodeAction ca1 = ca(uri, "Remove constraint annotation AssertTrue from element", d19, te1);
CodeAction ca2 = ca(uri, "Remove static modifier from element", d19, te2);

assertJavaCodeAction(codeActionParams2, utils, ca1, ca2);
Expand Down Expand Up @@ -250,7 +250,7 @@ public void fieldConstraintValidation() throws Exception {
JakartaJavaCodeActionParams codeActionParams3 = createCodeActionParams(uri, d20);
TextEdit te3 = te(0, 0, 64, 1, newText8);
TextEdit te4 = te(0, 0, 64, 1, newText9);
CodeAction ca3 = ca(uri, "Remove constraint annotation jakarta.validation.constraints.Past from element", d20, te3);
CodeAction ca3 = ca(uri, "Remove constraint annotation Past from element", d20, te3);
CodeAction ca4 = ca(uri, "Remove static modifier from element", d20, te4);

assertJavaCodeAction(codeActionParams3, utils, ca3, ca4);
Expand All @@ -271,7 +271,7 @@ public void fieldConstraintValidation() throws Exception {

JakartaJavaCodeActionParams codeActionParams4 = createCodeActionParams(uri, d18);
TextEdit te5 = te(0, 0, 64, 1, newText10);
CodeAction ca5 = ca(uri, "Remove constraint annotation jakarta.validation.constraints.PositiveOrZero from element", d1, te5);
CodeAction ca5 = ca(uri, "Remove constraint annotation PositiveOrZero from element", d1, te5);

assertJavaCodeAction(codeActionParams4, utils, ca5);
}
Expand Down Expand Up @@ -316,7 +316,7 @@ public void methodConstraintValidation() throws Exception {
JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d1);
TextEdit te = te(0, 0, 34, 1, newText1);
TextEdit te2 = te(0, 0, 34, 1, newText2);
CodeAction ca = ca(uri, "Remove constraint annotation jakarta.validation.constraints.AssertTrue from element", d1, te);
CodeAction ca = ca(uri, "Remove constraint annotation AssertTrue from element", d1, te);
CodeAction ca2 = ca(uri, "Remove static modifier from element", d1, te2);

assertJavaCodeAction(codeActionParams, utils, ca, ca2);
Expand All @@ -331,7 +331,7 @@ public void methodConstraintValidation() throws Exception {

codeActionParams = createCodeActionParams(uri, d2);
te = te(0, 0, 34, 1, newText3);
ca = ca(uri, "Remove constraint annotation jakarta.validation.constraints.AssertTrue from element", d2, te);
ca = ca(uri, "Remove constraint annotation AssertTrue from element", d2, te);

assertJavaCodeAction(codeActionParams, utils, ca);

Expand All @@ -355,7 +355,7 @@ public void methodConstraintValidation() throws Exception {
codeActionParams = createCodeActionParams(uri, d3);
te = te(0, 0, 34, 1, newText4);
te2 = te(0, 0, 34, 1, newText5);
ca = ca(uri, "Remove constraint annotation jakarta.validation.constraints.AssertFalse from element", d3, te);
ca = ca(uri, "Remove constraint annotation AssertFalse from element", d3, te);
ca2 = ca(uri, "Remove static modifier from element", d3, te2);

assertJavaCodeAction(codeActionParams, utils, ca, ca2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void injectAndDisposesObservesObservesAsync() throws Exception {
TextEdit te1 = te(0, 0, 55, 0, newText);
TextEdit te2 = te(0, 0, 55, 0, newText0);
CodeAction ca1 = ca(uri, "Remove @Inject", d1, te1);
CodeAction ca2 = ca(uri, "Remove the '@Disposes' modifier from parameter 'name'", d1, te2);
CodeAction ca2 = ca(uri, "Remove the @Disposes modifier from parameter name", d1, te2);

assertJavaCodeAction(codeActionParams1, utils, ca1, ca2);

Expand Down Expand Up @@ -399,7 +399,7 @@ public void injectAndDisposesObservesObservesAsync() throws Exception {
TextEdit te3 = te(0, 0, 55, 0, newText1);
TextEdit te4 = te(0, 0, 55, 0, newText2);
CodeAction ca3 = ca(uri, "Remove @Inject", d2, te3);
CodeAction ca4 = ca(uri, "Remove the '@Observes' modifier from parameter 'name'", d2, te4);
CodeAction ca4 = ca(uri, "Remove the @Observes modifier from parameter name", d2, te4);

assertJavaCodeAction(codeActionParams2, utils, ca3, ca4);

Expand Down Expand Up @@ -445,7 +445,7 @@ public void injectAndDisposesObservesObservesAsync() throws Exception {
TextEdit te5 = te(0, 0, 55, 0, newText19);
TextEdit te6 = te(0, 0, 55, 0, newText3);
CodeAction ca5 = ca(uri, "Remove @Inject", d3, te5);
CodeAction ca6 = ca(uri, "Remove the '@ObservesAsync' modifier from parameter 'name'", d3, te6);
CodeAction ca6 = ca(uri, "Remove the @ObservesAsync modifier from parameter name", d3, te6);

assertJavaCodeAction(codeActionParams3, utils, ca5, ca6);

Expand Down Expand Up @@ -504,8 +504,8 @@ public void injectAndDisposesObservesObservesAsync() throws Exception {
TextEdit te8 = te(0, 0, 55, 0, newText5);
TextEdit te9 = te(0, 0, 55, 0, newText6);
CodeAction ca7 = ca(uri, "Remove @Inject", d4, te7);
CodeAction ca8 = ca(uri, "Remove the '@Disposes' modifier from parameter 'name1'", d4, te8);
CodeAction ca9 = ca(uri, "Remove the '@Observes' modifier from parameter 'name2'", d4, te9);
CodeAction ca8 = ca(uri, "Remove the @Disposes modifier from parameter name1", d4, te8);
CodeAction ca9 = ca(uri, "Remove the @Observes modifier from parameter name2", d4, te9);

assertJavaCodeAction(codeActionParams4, utils, ca7, ca8, ca9);

Expand Down Expand Up @@ -564,8 +564,8 @@ public void injectAndDisposesObservesObservesAsync() throws Exception {
TextEdit te11 = te(0, 0, 55, 0, newText8);
TextEdit te12 = te(0, 0, 55, 0, newText9);
CodeAction ca10 = ca(uri, "Remove @Inject", d5, te10);
CodeAction ca11 = ca(uri, "Remove the '@Observes' modifier from parameter 'name1'", d5, te11);
CodeAction ca12 = ca(uri, "Remove the '@ObservesAsync' modifier from parameter 'name2'", d5, te12);
CodeAction ca11 = ca(uri, "Remove the @Observes modifier from parameter name1", d5, te11);
CodeAction ca12 = ca(uri, "Remove the @ObservesAsync modifier from parameter name2", d5, te12);

assertJavaCodeAction(codeActionParams5, utils, ca10, ca11, ca12);

Expand Down Expand Up @@ -626,8 +626,8 @@ public void injectAndDisposesObservesObservesAsync() throws Exception {
TextEdit te14 = te(0, 0, 55, 0, newText11);
TextEdit te15 = te(0, 0, 55, 0, newText12);
CodeAction ca13 = ca(uri, "Remove @Inject", d6, te13);
CodeAction ca14 = ca(uri, "Remove the '@Disposes' modifier from parameter 'name1'", d6, te14);
CodeAction ca15 = ca(uri, "Remove the '@ObservesAsync' modifier from parameter 'name2'", d6, te15);
CodeAction ca14 = ca(uri, "Remove the @Disposes modifier from parameter name1", d6, te14);
CodeAction ca15 = ca(uri, "Remove the @ObservesAsync modifier from parameter name2", d6, te15);

assertJavaCodeAction(codeActionParams6, utils, ca13, ca14, ca15);

Expand Down Expand Up @@ -703,9 +703,9 @@ public void injectAndDisposesObservesObservesAsync() throws Exception {
TextEdit te18 = te(0, 0, 55, 0, newText15);
TextEdit te19 = te(0, 0, 55, 0, newText16);
CodeAction ca16 = ca(uri, "Remove @Inject", d7, te16);
CodeAction ca17 = ca(uri, "Remove the '@Disposes' modifier from parameter 'name1'", d7, te17);
CodeAction ca18 = ca(uri, "Remove the '@Observes' modifier from parameter 'name2'", d7, te18);
CodeAction ca19 = ca(uri, "Remove the '@ObservesAsync' modifier from parameter 'name3'", d7, te19);
CodeAction ca17 = ca(uri, "Remove the @Disposes modifier from parameter name1", d7, te17);
CodeAction ca18 = ca(uri, "Remove the @Observes modifier from parameter name2", d7, te18);
CodeAction ca19 = ca(uri, "Remove the @ObservesAsync modifier from parameter name3", d7, te19);

assertJavaCodeAction(codeActionParams7, utils, ca16, ca17, ca18, ca19);

Expand Down Expand Up @@ -748,7 +748,7 @@ public void injectAndDisposesObservesObservesAsync() throws Exception {
TextEdit te20 = te(0, 0, 55, 0, newText17);
TextEdit te21 = te(0, 0, 55, 0, newText18);
CodeAction ca20 = ca(uri, "Remove @Inject", d8, te20);
CodeAction ca21 = ca(uri, "Remove the '@Disposes', '@Observes', '@ObservesAsync' modifier from parameter 'name'", d8, te21);
CodeAction ca21 = ca(uri, "Remove the @Disposes, @Observes, @ObservesAsync modifier from parameter name", d8, te21);

assertJavaCodeAction(codeActionParams8, utils, ca20, ca21);
}
Expand Down Expand Up @@ -865,7 +865,7 @@ public void producesAndDisposesObservesObservesAsync() throws Exception {
TextEdit te1 = te(0, 0, 58, 0, newText);
TextEdit te2 = te(0, 0, 58, 0, newText1);
CodeAction ca1 = ca(uri, "Remove @Produces", d1, te1);
CodeAction ca2 = ca(uri, "Remove the '@Disposes' modifier from parameter 'name'", d1, te2);
CodeAction ca2 = ca(uri, "Remove the @Disposes modifier from parameter name", d1, te2);

assertJavaCodeAction(codeActionParams1, utils, ca1, ca2);

Expand Down Expand Up @@ -915,7 +915,7 @@ public void producesAndDisposesObservesObservesAsync() throws Exception {
TextEdit te3 = te(0, 0, 58, 0, newText2);
TextEdit te4 = te(0, 0, 58, 0, newText3);
CodeAction ca3 = ca(uri, "Remove @Produces", d2, te3);
CodeAction ca4 = ca(uri, "Remove the '@Observes' modifier from parameter 'name'", d2, te4);
CodeAction ca4 = ca(uri, "Remove the @Observes modifier from parameter name", d2, te4);

assertJavaCodeAction(codeActionParams2, utils, ca3, ca4);

Expand Down Expand Up @@ -963,7 +963,7 @@ public void producesAndDisposesObservesObservesAsync() throws Exception {
TextEdit te5 = te(0, 0, 58, 0, newText4);
TextEdit te6 = te(0, 0, 58, 0, newText5);
CodeAction ca5 = ca(uri, "Remove @Produces", d3, te5);
CodeAction ca6 = ca(uri, "Remove the '@ObservesAsync' modifier from parameter 'name'", d3, te6);
CodeAction ca6 = ca(uri, "Remove the @ObservesAsync modifier from parameter name", d3, te6);

assertJavaCodeAction(codeActionParams3, utils, ca5, ca6);

Expand Down Expand Up @@ -1026,8 +1026,8 @@ public void producesAndDisposesObservesObservesAsync() throws Exception {
TextEdit te8 = te(0, 0, 58, 0, newText7);
TextEdit te9 = te(0, 0, 58, 0, newText8);
CodeAction ca7 = ca(uri, "Remove @Produces", d4, te7);
CodeAction ca8 = ca(uri, "Remove the '@Disposes' modifier from parameter 'name1'", d4, te8);
CodeAction ca9 = ca(uri, "Remove the '@Observes' modifier from parameter 'name2'", d4, te9);
CodeAction ca8 = ca(uri, "Remove the @Disposes modifier from parameter name1", d4, te8);
CodeAction ca9 = ca(uri, "Remove the @Observes modifier from parameter name2", d4, te9);

assertJavaCodeAction(codeActionParams4, utils, ca7, ca8, ca9);

Expand Down Expand Up @@ -1092,8 +1092,8 @@ public void producesAndDisposesObservesObservesAsync() throws Exception {
TextEdit te11 = te(0, 0, 58, 0, newText10);
TextEdit te12 = te(0, 0, 58, 0, newText11);
CodeAction ca10 = ca(uri, "Remove @Produces", d5, te10);
CodeAction ca11 = ca(uri, "Remove the '@Observes' modifier from parameter 'name1'", d5, te11);
CodeAction ca12 = ca(uri, "Remove the '@ObservesAsync' modifier from parameter 'name2'", d5, te12);
CodeAction ca11 = ca(uri, "Remove the @Observes modifier from parameter name1", d5, te11);
CodeAction ca12 = ca(uri, "Remove the @ObservesAsync modifier from parameter name2", d5, te12);

assertJavaCodeAction(codeActionParams5, utils, ca10, ca11, ca12);

Expand Down Expand Up @@ -1160,8 +1160,8 @@ public void producesAndDisposesObservesObservesAsync() throws Exception {
TextEdit te14 = te(0, 0, 58, 0, newText13);
TextEdit te15 = te(0, 0, 58, 0, newText14);
CodeAction ca13 = ca(uri, "Remove @Produces", d6, te13);
CodeAction ca14 = ca(uri, "Remove the '@Disposes' modifier from parameter 'name1'", d6, te14);
CodeAction ca15 = ca(uri, "Remove the '@ObservesAsync' modifier from parameter 'name2'", d6, te15);
CodeAction ca14 = ca(uri, "Remove the @Disposes modifier from parameter name1", d6, te14);
CodeAction ca15 = ca(uri, "Remove the @ObservesAsync modifier from parameter name2", d6, te15);

assertJavaCodeAction(codeActionParams6, utils, ca13, ca14, ca15);

Expand Down Expand Up @@ -1246,9 +1246,9 @@ public void producesAndDisposesObservesObservesAsync() throws Exception {
TextEdit te18 = te(0, 0, 58, 0, newText17);
TextEdit te19 = te(0, 0, 58, 0, newText18);
CodeAction ca16 = ca(uri, "Remove @Produces", d7, te16);
CodeAction ca17 = ca(uri, "Remove the '@Disposes' modifier from parameter 'name1'", d7, te17);
CodeAction ca18 = ca(uri, "Remove the '@Observes' modifier from parameter 'name2'", d7, te18);
CodeAction ca19 = ca(uri, "Remove the '@ObservesAsync' modifier from parameter 'name3'", d7, te19);
CodeAction ca17 = ca(uri, "Remove the @Disposes modifier from parameter name1", d7, te17);
CodeAction ca18 = ca(uri, "Remove the @Observes modifier from parameter name2", d7, te18);
CodeAction ca19 = ca(uri, "Remove the @ObservesAsync modifier from parameter name3", d7, te19);

assertJavaCodeAction(codeActionParams7, utils, ca16, ca17, ca18, ca19);

Expand Down Expand Up @@ -1296,7 +1296,7 @@ public void producesAndDisposesObservesObservesAsync() throws Exception {
TextEdit te20 = te(0, 0, 58, 0, newText19);
TextEdit te21 = te(0, 0, 58, 0, newText20);
CodeAction ca20 = ca(uri, "Remove @Produces", d8, te20);
CodeAction ca21 = ca(uri, "Remove the '@Disposes', '@Observes', '@ObservesAsync' modifier from parameter 'name'", d8, te21);
CodeAction ca21 = ca(uri, "Remove the @Disposes, @Observes, @ObservesAsync modifier from parameter name", d8, te21);

assertJavaCodeAction(codeActionParams8, utils, ca20, ca21);
}
Expand Down

0 comments on commit 0c6faa2

Please sign in to comment.