Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anusreelakshmi934 committed Jan 24, 2024
1 parent 84dc0f7 commit 3c9e3cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ private void insertAndReplaceAnnotation(Diagnostic diagnostic, JavaCodeActionCon
}
if (diagnosticCode.equals(ServletConstants.DIAGNOSTIC_CODE_FILTER_DUPLICATE_ATTRIBUTES)) {
for (String attribute : attributes) {
String name = getLabel(annotation, attribute, "Remove");
Map<String, Object> extendedData = new HashMap<>();
extendedData.put(DIAGNOSTIC_CODE_KEY, diagnosticCode);
extendedData.put(ATTRIBUTE_KEY, attribute);
extendedData.put(ANNOTATION_KEY, annotation);
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, name, getParticipantId(), extendedData));
if (!attribute.equals("servletNames")) {
String name = getLabel(annotation, attribute, "Remove");
Map<String, Object> extendedData = new HashMap<>();
extendedData.put(DIAGNOSTIC_CODE_KEY, diagnosticCode);
extendedData.put(ATTRIBUTE_KEY, attribute);
extendedData.put(ANNOTATION_KEY, annotation);
codeActions.add(JDTUtils.createCodeAction(context, diagnostic, name, getParticipantId(), extendedData));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ public void RemoveDuplicateWebFilterAttributes() throws Exception {
DiagnosticSeverity.Error, "jakarta-servlet", "InvalidWebFilterAttribute");

JakartaForJavaAssert.assertJavaDiagnostics(diagnosticsParams, utils, d);
String newText = "package io.openliberty.sample.jakarta.servlet;\n\nimport jakarta.servlet.annotation.WebFilter;\n" +
"import jakarta.servlet.Filter;\n\n@WebFilter(urlPatterns = \"\", value = \"\")\n" +
"public abstract class DuplicateAttributeWebFilter implements Filter {\n\n}\n\n";
String newText1 = "package io.openliberty.sample.jakarta.servlet;\n\nimport jakarta.servlet.annotation.WebFilter;\n" +
"import jakarta.servlet.Filter;\n\n@WebFilter( value = \"\")\n" +
"public abstract class DuplicateAttributeWebFilter implements Filter {\n\n}\n\n";
Expand All @@ -214,14 +211,12 @@ public void RemoveDuplicateWebFilterAttributes() throws Exception {
"public abstract class DuplicateAttributeWebFilter implements Filter {\n\n}\n\n";

JakartaJavaCodeActionParams codeActionParams = JakartaForJavaAssert.createCodeActionParams(uri, d);
TextEdit te1 = JakartaForJavaAssert.te(0, 0, 10, 0, newText);
CodeAction ca1 = JakartaForJavaAssert.ca(uri, "Remove the `servletNames` attribute from @WebFilter", d, te1);

TextEdit te2 = JakartaForJavaAssert.te(0, 0, 10, 0, newText1);
CodeAction ca2 = JakartaForJavaAssert.ca(uri, "Remove the `urlPatterns` attribute from @WebFilter", d, te2);
TextEdit te1 = JakartaForJavaAssert.te(0, 0, 10, 0, newText1);
CodeAction ca1 = JakartaForJavaAssert.ca(uri, "Remove the `urlPatterns` attribute from @WebFilter", d, te1);

TextEdit te3 = JakartaForJavaAssert.te(0, 0, 10, 0, newText2);
CodeAction ca3 = JakartaForJavaAssert.ca(uri, "Remove the `value` attribute from @WebFilter", d, te3);
JakartaForJavaAssert.assertJavaCodeAction(codeActionParams, utils, ca1, ca2, ca3);
TextEdit te2 = JakartaForJavaAssert.te(0, 0, 10, 0, newText2);
CodeAction ca2 = JakartaForJavaAssert.ca(uri, "Remove the `value` attribute from @WebFilter", d, te2);
JakartaForJavaAssert.assertJavaCodeAction(codeActionParams, utils, ca1, ca2);
}
}

0 comments on commit 3c9e3cc

Please sign in to comment.