Skip to content
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

Fixes#511 Transform the quick fixes which use ImplementInterfaceProposal to implement the code action participant extension point. #726

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Resolved the conflicts after merging from code unification 2 branch
aparnamichael committed Apr 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d57b62311b1f2a6688dce0c9c82f32a548ed5caf
Original file line number Diff line number Diff line change
@@ -219,4 +219,77 @@ public void RemoveDuplicateWebFilterAttributes() throws Exception {
CodeAction ca2 = JakartaForJavaAssert.ca(uri, "Remove the `value` attribute from @WebFilter", d, te2);
JakartaForJavaAssert.assertJavaCodeAction(codeActionParams, utils, ca1, ca2);
}

@Test
public void implementFilter() throws Exception {
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample"));
IPsiUtils utils = PsiUtilsLSImpl.getInstance(myProject);

VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(ModuleUtilCore.getModuleDirPath(module)
+ "/src/main/java/io/openliberty/sample/jakarta/servlet/DontImplementFilter.java");
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString();

JakartaDiagnosticsParams diagnosticsParams = new JakartaDiagnosticsParams();
diagnosticsParams.setUris(Arrays.asList(uri));

Diagnostic d = JakartaForJavaAssert.d(5, 13, 32, "Annotated classes with @WebFilter must implement the Filter interface.",
DiagnosticSeverity.Error, "jakarta-servlet", "ImplementFilter");

JakartaForJavaAssert.assertJavaDiagnostics(diagnosticsParams, utils, d);

if (CHECK_CODE_ACTIONS) {
// test associated quick-fix code action
JakartaJavaCodeActionParams codeActionParams = JakartaForJavaAssert.createCodeActionParams(uri, d);
TextEdit te = JakartaForJavaAssert.te(5, 32, 5, 32, " implements Filter");
CodeAction ca = JakartaForJavaAssert.ca(uri, "Let 'DontImplementFilter' implement 'Filter'", d, te);
JakartaForJavaAssert.assertJavaCodeAction(codeActionParams, utils, ca);
}
}

@Test
public void implementListener() throws Exception {
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample"));
IPsiUtils utils = PsiUtilsLSImpl.getInstance(myProject);

VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(ModuleUtilCore.getModuleDirPath(module)
+ "/src/main/java/io/openliberty/sample/jakarta/servlet/DontImplementListener.java");
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString();

JakartaDiagnosticsParams diagnosticsParams = new JakartaDiagnosticsParams();
diagnosticsParams.setUris(Arrays.asList(uri));

Diagnostic d = JakartaForJavaAssert.d(5, 13, 34, "Annotated classes with @WebListener must implement one or more of the following interfaces: ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener, HttpSessionListener, HttpSessionAttributeListener, or HttpSessionIdListener.",
DiagnosticSeverity.Error, "jakarta-servlet", "ImplementListener");

JakartaForJavaAssert.assertJavaDiagnostics(diagnosticsParams, utils, d);

if (CHECK_CODE_ACTIONS) {
// test associated quick-fix code action
JakartaJavaCodeActionParams codeActionParams = JakartaForJavaAssert.createCodeActionParams(uri, d);

TextEdit te1 = JakartaForJavaAssert.te(5, 34, 5, 34, " implements Listener");
CodeAction ca1 = JakartaForJavaAssert.ca(uri, "Let 'DontImplementListener' implement 'ServletContextListener'", d, te1);

TextEdit te2 = JakartaForJavaAssert.te(5, 34, 5, 34, " implements Listener");
CodeAction ca2 = JakartaForJavaAssert.ca(uri, "Let 'DontImplementListener' implement 'ServletContextAttributeListener'", d, te2);

TextEdit te3 = JakartaForJavaAssert.te(5, 34, 5, 34, " implements Listener");
CodeAction ca3 = JakartaForJavaAssert.ca(uri, "Let 'DontImplementListener' implement 'ServletRequestListener'", d, te3);

TextEdit te4 = JakartaForJavaAssert.te(5, 34, 5, 34, " implements Listener");
CodeAction ca4 = JakartaForJavaAssert.ca(uri, "Let 'DontImplementListener' implement 'ServletRequestAttributeListener'", d, te4);

TextEdit te5 = JakartaForJavaAssert.te(5, 34, 5, 34, " implements Listener");
CodeAction ca5 = JakartaForJavaAssert.ca(uri, "Let 'DontImplementListener' implement 'HttpSessionListener'", d, te5);

TextEdit te6 = JakartaForJavaAssert.te(5, 34, 5, 34, " implements Listener");
CodeAction ca6 = JakartaForJavaAssert.ca(uri, "Let 'DontImplementListener' implement 'HttpSessionAttributeListener'", d, te6);

TextEdit te7 = JakartaForJavaAssert.te(5, 34, 5, 34, " implements Listener");
CodeAction ca7 = JakartaForJavaAssert.ca(uri, "Let 'DontImplementListener' implement 'HttpSessionIdListener'", d, te7);

JakartaForJavaAssert.assertJavaCodeAction(codeActionParams, utils, ca1, ca2, ca3, ca4, ca5, ca6, ca7);
}
}

}