1
+ /*******************************************************************************
2
+ * Copyright (c) 2025 Red Hat, Inc.
3
+ * Distributed under license by Red Hat, Inc. All rights reserved.
4
+ * This program is made available under the terms of the
5
+ * Eclipse Public License v2.0 which accompanies this distribution,
6
+ * and is available at http://www.eclipse.org/legal/epl-v20.html
7
+ *
8
+ * Contributors:
9
+ * Red Hat, Inc. - initial API and implementation
10
+ ******************************************************************************/
11
+ package com .redhat .devtools .lsp4ij .features .codeAction ;
12
+
13
+ import com .redhat .devtools .lsp4ij .fixtures .LSPCodeActionFixtureTestCase ;
14
+
15
+ /**
16
+ * Test case for InvalidWebFilter quick fix
17
+ */
18
+ public class WebFilterQuickFixTest extends LSPCodeActionFixtureTestCase {
19
+
20
+ // NOTE: Using an extension other than "java" here to avoid having native Java language support skew results
21
+ private static final String NOT_JAVA_EXTENSION = "javax" ;
22
+ private static final String TEST_FILE_NAME = "InvalidWebFilter." + NOT_JAVA_EXTENSION ;
23
+
24
+ public WebFilterQuickFixTest () {
25
+ super ("*." + NOT_JAVA_EXTENSION );
26
+ }
27
+
28
+ public void testWebFilterQuickFix () {
29
+ var allQuickFixes = assertCodeActions (TEST_FILE_NAME ,
30
+ // language=JAVA
31
+ """
32
+ package io.openliberty.sample.jakarta.servlet;
33
+ import jakarta.servlet.Filter;
34
+ import jakarta.servlet.annotation.WebFilter;
35
+ @WebFilter(<caret>)
36
+ public abstract class InvalidWebFilter implements Filter {
37
+ }
38
+
39
+
40
+
41
+ """ ,
42
+ // language=JSON
43
+ """
44
+ [
45
+ {
46
+ "title": "Add the `servletNames` attribute to @WebFilter",
47
+ "kind": "quickfix",
48
+ "diagnostics": [
49
+ {
50
+ "range": {
51
+ "start": {
52
+ "line": 5,
53
+ "character": 0
54
+ },
55
+ "end": {
56
+ "line": 5,
57
+ "character": 12
58
+ }
59
+ },
60
+ "severity": 1,
61
+ "code": "CompleteWebFilterAttributes",
62
+ "source": "jakarta-servlet",
63
+ "message": "The annotation @WebFilter must define the attribute \\ u0027urlPatterns\\ u0027, \\ u0027servletNames\\ u0027 or \\ u0027value\\ u0027."
64
+ }
65
+ ],
66
+ "data": {
67
+ "participantId": "io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.CompleteFilterAnnotationQuickFix",
68
+ "documentUri": "unused",
69
+ "range": {
70
+ "start": {
71
+ "line": 5,
72
+ "character": 0
73
+ },
74
+ "end": {
75
+ "line": 5,
76
+ "character": 12
77
+ }
78
+ },
79
+ "extendedData": {
80
+ "annotation": "jakarta.servlet.annotation.WebFilter",
81
+ "attribute": "servletNames",
82
+ "diagnosticCode": "CompleteWebFilterAttributes"
83
+ },
84
+ "resourceOperationSupported": true,
85
+ "commandConfigurationUpdateSupported": false
86
+ }
87
+ },
88
+ {
89
+ "title": "Add the `urlPatterns` attribute to @WebFilter",
90
+ "kind": "quickfix",
91
+ "diagnostics": [
92
+ {
93
+ "range": {
94
+ "start": {
95
+ "line": 5,
96
+ "character": 0
97
+ },
98
+ "end": {
99
+ "line": 5,
100
+ "character": 12
101
+ }
102
+ },
103
+ "severity": 1,
104
+ "code": "CompleteWebFilterAttributes",
105
+ "source": "jakarta-servlet",
106
+ "message": "The annotation @WebFilter must define the attribute \\ u0027urlPatterns\\ u0027, \\ u0027servletNames\\ u0027 or \\ u0027value\\ u0027."
107
+ }
108
+ ],
109
+ "data": {
110
+ "participantId": "io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.CompleteFilterAnnotationQuickFix",
111
+ "documentUri": "unused",
112
+ "range": {
113
+ "start": {
114
+ "line": 5,
115
+ "character": 0
116
+ },
117
+ "end": {
118
+ "line": 5,
119
+ "character": 12
120
+ }
121
+ },
122
+ "extendedData": {
123
+ "annotation": "jakarta.servlet.annotation.WebFilter",
124
+ "attribute": "urlPatterns",
125
+ "diagnosticCode": "CompleteWebFilterAttributes"
126
+ },
127
+ "resourceOperationSupported": true,
128
+ "commandConfigurationUpdateSupported": false
129
+ }
130
+ },
131
+ {
132
+ "title": "Add the `value` attribute to @WebFilter",
133
+ "kind": "quickfix",
134
+ "diagnostics": [
135
+ {
136
+ "range": {
137
+ "start": {
138
+ "line": 5,
139
+ "character": 0
140
+ },
141
+ "end": {
142
+ "line": 5,
143
+ "character": 12
144
+ }
145
+ },
146
+ "severity": 1,
147
+ "code": "CompleteWebFilterAttributes",
148
+ "source": "jakarta-servlet",
149
+ "message": "The annotation @WebFilter must define the attribute \\ u0027urlPatterns\\ u0027, \\ u0027servletNames\\ u0027 or \\ u0027value\\ u0027."
150
+ }
151
+ ],
152
+ "data": {
153
+ "participantId": "io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.CompleteFilterAnnotationQuickFix",
154
+ "documentUri": "unused",
155
+ "range": {
156
+ "start": {
157
+ "line": 5,
158
+ "character": 0
159
+ },
160
+ "end": {
161
+ "line": 5,
162
+ "character": 12
163
+ }
164
+ },
165
+ "extendedData": {
166
+ "annotation": "jakarta.servlet.annotation.WebFilter",
167
+ "attribute": "value",
168
+ "diagnosticCode": "CompleteWebFilterAttributes"
169
+ },
170
+ "resourceOperationSupported": true,
171
+ "commandConfigurationUpdateSupported": false
172
+ }
173
+ }
174
+ ]"""
175
+ ,
176
+ "Add the `servletNames` attribute to @WebFilter" ,
177
+ "Add the `urlPatterns` attribute to @WebFilter" ,
178
+ "Add the `value` attribute to @WebFilter" );
179
+
180
+ // Get 'Add the `servletNames` attribute to @WebFilter' quick fix
181
+ var addServletNameQuickFix = assertGetQuickFixByName ("Add the `servletNames` attribute to @WebFilter" , allQuickFixes );
182
+
183
+ // Apply 'Add the `servletNames` attribute to @WebFilter' quick fix
184
+ assertApplyCodeAction ("package io.openliberty.sample.jakarta.servlet;\\ n\\ nimport jakarta.servlet.Filter;\\ nimport jakarta.servlet.annotation.WebFilter;\\ n\\ n@WebFilter(servletNames=\" <caret>\" )\\ npublic abstract class InvalidWebFilter implements Filter {\\ n\\ n}\\ n\\ n\\ n" ,
185
+ // language=JSON
186
+ """
187
+ {
188
+ "title": "Add the `servletNames` attribute to @WebFilter",
189
+ "kind": "quickfix",
190
+ "diagnostics": [
191
+ {
192
+ "range": {
193
+ "start": {
194
+ "line": 5,
195
+ "character": 0
196
+ },
197
+ "end": {
198
+ "line": 5,
199
+ "character": 12
200
+ }
201
+ },
202
+ "severity": 1,
203
+ "code": "CompleteWebFilterAttributes",
204
+ "source": "jakarta-servlet",
205
+ "message": "The annotation @WebFilter must define the attribute \\ u0027urlPatterns\\ u0027, \\ u0027servletNames\\ u0027 or \\ u0027value\\ u0027."
206
+ }
207
+ ],
208
+ "edit": {
209
+ "changes": {},
210
+ "documentChanges": [
211
+ {
212
+ "textDocument": {
213
+ "version": 0,
214
+ "uri": "file:///Users/dessina/Documents/Workspace/IntelliJ/liberty-tools-intellij/src/test/resources/projects/maven/jakarta-sample/src/main/java/io/openliberty/sample/jakarta/servlet/InvalidWebFilter.java"
215
+ },
216
+ "edits": [
217
+ {
218
+ "range": {
219
+ "start": {
220
+ "line": 0,
221
+ "character": 0
222
+ },
223
+ "end": {
224
+ "line": 11,
225
+ "character": 0
226
+ }
227
+ },
228
+ "newText": "package io.openliberty.sample.jakarta.servlet;\\ n\\ nimport jakarta.servlet.Filter;\\ nimport jakarta.servlet.annotation.WebFilter;\\ n\\ n@WebFilter(servletNames\\ u003d\\ "\\ ")\\ npublic abstract class InvalidWebFilter implements Filter {\\ n\\ n}\\ n\\ n\\ n"
229
+ }
230
+ ]
231
+ }
232
+ ]
233
+ },
234
+ "data": {
235
+ "participantId": "io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.CompleteFilterAnnotationQuickFix",
236
+ "documentUri": "file:///Users/dessina/Documents/Workspace/IntelliJ/liberty-tools-intellij/src/test/resources/projects/maven/jakarta-sample/src/main/java/io/openliberty/sample/jakarta/servlet/InvalidWebFilter.java",
237
+ "range": {
238
+ "start": {
239
+ "line": 5,
240
+ "character": 0
241
+ },
242
+ "end": {
243
+ "line": 5,
244
+ "character": 12
245
+ }
246
+ },
247
+ "extendedData": {
248
+ "annotation": "jakarta.servlet.annotation.WebFilter",
249
+ "attribute": "servletNames",
250
+ "diagnosticCode": "CompleteWebFilterAttributes"
251
+ },
252
+ "resourceOperationSupported": true,
253
+ "commandConfigurationUpdateSupported": false
254
+ }
255
+ }
256
+ """ ,
257
+ addServletNameQuickFix );
258
+ }
259
+
260
+ }
0 commit comments