Skip to content

Commit

Permalink
Qute - incorrect behavior for nested template records
Browse files Browse the repository at this point in the history
Fixes #987

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Aug 29, 2024
1 parent bd201b2 commit 3e697eb
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 115 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bug Fixes

- Qute - incorrect behavior for nested template records. See [#987](https://github.com/redhat-developer/quarkus-ls/issues/987).
- Version 18 release duplicate key issue. See [#975](https://github.com/redhat-developer/quarkus-ls/issues/988).

## [0.19.0](https://github.com/redhat-developer/quarkus-ls/milestone/21?closed=1) (August 26, 2024)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.acme.sample;

import io.quarkus.qute.CheckedTemplate;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
Expand All @@ -18,6 +19,9 @@ record Bonjour(String name) implements TemplateInstance {}

record Status() {}

@CheckedTemplate(basePath="Foo", defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
record HelloWorld(String name) implements TemplateInstance {}

@GET
@Produces(MediaType.TEXT_PLAIN)
public TemplateInstance get(@QueryParam("name") String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ public void templateRecord() throws CoreException, Exception {

// record Status() {}

// @CheckedTemplate(basePath="Foo", defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
// record HelloWorld(String name) implements TemplateInstance {}

IJavaProject javaProject = loadMavenProject(QuteMavenProjectName.qute_record);

QuteJavaCodeLensParams params = new QuteJavaCodeLensParams();
Expand All @@ -426,20 +429,25 @@ public void templateRecord() throws CoreException, Exception {

List<? extends CodeLens> lenses = QuteSupportForJava.getInstance().codeLens(params, getJDTUtils(),
new NullProgressMonitor());
assertEquals(2, lenses.size());
assertEquals(3, lenses.size());

String helloFileUri = javaProject.getProject().getFile("src/main/resources/templates/Hello.html")
String helloFileUri = javaProject.getProject().getFile("src/main/resources/templates/HelloResource/Hello.html")
.getLocationURI().toString();
String boujourFileUri1 = javaProject.getProject().getFile("src/main/resources/templates/Bonjour.html")
String boujourFileUri = javaProject.getProject().getFile("src/main/resources/templates/HelloResource/Bonjour.html")
.getLocationURI().toString();

String helloWorldFileUri = javaProject.getProject().getFile("src/main/resources/templates/Foo/hello-world.html")
.getLocationURI().toString();

assertCodeLens(lenses, //
cl(r(14, 4, 14, 60), //
"Open `src/main/resources/templates/Hello.html`", //
cl(r(15, 4, 15, 60), //
"Open `src/main/resources/templates/HelloResource/Hello.html`", //
"qute.command.open.uri", Arrays.asList(helloFileUri)), //
cl(r(16, 4, 16, 62), //
"Create `src/main/resources/templates/Bonjour.html`", //
"qute.command.generate.template.file", Arrays.asList(boujourFileUri1)));
cl(r(17, 4, 17, 62), //
"Create `src/main/resources/templates/HelloResource/Bonjour.html`", //
"qute.command.generate.template.file", Arrays.asList(boujourFileUri)),
cl(r(21, 4, 22, 65), //
"Create `src/main/resources/templates/Foo/hello-world.html`", //
"qute.command.generate.template.file", Arrays.asList(helloWorldFileUri)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ public void templateRecord() throws Exception {

// record Status() {}

// @CheckedTemplate(basePath="Foo",
// defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
// record HelloWorld(String name) implements TemplateInstance {}

IJavaProject javaProject = loadMavenProject(QuteMavenProjectName.qute_record);

QuteJavaDiagnosticsParams params = new QuteJavaDiagnosticsParams();
Expand All @@ -252,11 +256,14 @@ public void templateRecord() throws Exception {
assertEquals(1, publishDiagnostics.size());

List<Diagnostic> diagnostics = publishDiagnostics.get(0).getDiagnostics();
assertEquals(1, diagnostics.size());
assertEquals(2, diagnostics.size());

assertDiagnostic(diagnostics, //
new Diagnostic(r(16, 11, 16, 18),
"No template matching the path Bonjour could be found for: org.acme.sample.HelloResource$Bonjour",
new Diagnostic(r(17, 11, 17, 18),
"No template matching the path HelloResource/Bonjour could be found for: org.acme.sample.HelloResource$Bonjour",
DiagnosticSeverity.Error, "qute", QuteErrorCode.NoMatchingTemplate.name()), //
new Diagnostic(r(22, 11, 22, 21),
"No template matching the path Foo/HelloWorld could be found for: org.acme.sample.HelloResource$HelloWorld",
DiagnosticSeverity.Error, "qute", QuteErrorCode.NoMatchingTemplate.name()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ public void templateRecord() throws Exception {

// record Status() {}

// @CheckedTemplate(basePath="Foo",
// defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
// record HelloWorld(String name) implements TemplateInstance {}

IJavaProject javaProject = loadMavenProject(QuteMavenProjectName.qute_record);

QuteJavaDocumentLinkParams params = new QuteJavaDocumentLinkParams();
Expand All @@ -255,16 +259,22 @@ public void templateRecord() throws Exception {

List<DocumentLink> links = QuteSupportForJava.getInstance().documentLink(params, getJDTUtils(),
new NullProgressMonitor());
assertEquals(2, links.size());
assertEquals(3, links.size());

String templateFileUri = javaProject.getProject().getFile("src/main/resources/templates/Hello.html")
String helloFileUri = javaProject.getProject().getFile("src/main/resources/templates/HelloResource/Hello.html")
.getLocationURI().toString();
String boujourFileUri = javaProject.getProject()
.getFile("src/main/resources/templates/HelloResource/Bonjour.html").getLocationURI().toString();
String helloWorldFileUri = javaProject.getProject().getFile("src/main/resources/templates/Foo/hello-world.html")
.getLocationURI().toString();

assertDocumentLink(links, //
dl(r(14, 11, 14, 16), //
templateFileUri, "Open `src/main/resources/templates/Hello.html`"), //
dl(r(16, 11, 16, 18), //
templateFileUri, "Create `src/main/resources/templates/Bonjour.html`"));
dl(r(15, 11, 15, 16), //
helloFileUri, "Open `src/main/resources/templates/HelloResource/Hello.html`"), //
dl(r(17, 11, 17, 18), //
boujourFileUri, "Create `src/main/resources/templates/HelloResource/Bonjour.html`"),
dl(r(22, 11, 22, 21), //
helloWorldFileUri, "Create `src/main/resources/templates/Foo/hello-world.html`"));
}

@Test
Expand All @@ -284,12 +294,12 @@ public void checkedTemplateWithDefaultName() throws Exception {
new NullProgressMonitor());
assertEquals(3, links.size());

String helloFileUri = javaProject.getProject().getFile("src/main/resources/templates/ItemResource/HelloWorld.html")
.getLocationURI().toString();
String hello2FileUri = javaProject.getProject().getFile("src/main/resources/templates/ItemResource/hello-world.html")
.getLocationURI().toString();
String hello3FileUri = javaProject.getProject().getFile("src/main/resources/templates/ItemResource/hello_world.html")
.getLocationURI().toString();
String helloFileUri = javaProject.getProject()
.getFile("src/main/resources/templates/ItemResource/HelloWorld.html").getLocationURI().toString();
String hello2FileUri = javaProject.getProject()
.getFile("src/main/resources/templates/ItemResource/hello-world.html").getLocationURI().toString();
String hello3FileUri = javaProject.getProject()
.getFile("src/main/resources/templates/ItemResource/hello_world.html").getLocationURI().toString();

assertDocumentLink(links, //
dl(r(19, 33, 19, 43), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,23 @@ public void quteRecord() throws Exception {
Assert.assertNotNull(project);

// public class HelloResource {

// record Hello(String name) implements TemplateInstance {}

// record Bonjour(String name) implements TemplateInstance {}

// record Status() {}

// @CheckedTemplate(basePath="Foo",
// defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
// record HelloWorld(String name) implements TemplateInstance {}

// Hello ->
// record Hello(String name) implements TemplateInstance {}

// Hello
DataModelTemplate<DataModelParameter> helloTemplate = project
.findDataModelTemplate("src/main/resources/templates/Hello");
.findDataModelTemplate("src/main/resources/templates/HelloResource/Hello");
Assert.assertNotNull(helloTemplate);
Assert.assertEquals("src/main/resources/templates/Hello", helloTemplate.getTemplateUri());
Assert.assertEquals("src/main/resources/templates/HelloResource/Hello", helloTemplate.getTemplateUri());
Assert.assertEquals("org.acme.sample.HelloResource$Hello", helloTemplate.getSourceType());
Assert.assertNull(helloTemplate.getSourceField());
Assert.assertNull(helloTemplate.getSourceMethod());
Expand All @@ -406,12 +416,33 @@ public void quteRecord() throws Exception {

// record Hello(String name) implements TemplateInstance {}
assertParameter("name", "java.lang.String", false, helloParameters, 0);
// public TemplateInstance get(@QueryParam("name") String name) {
// return new Hello(name).data("foo", 100);

// public TemplateInstance get(@QueryParam("name") String name) {
// return new Hello(name).data("foo", 100);
assertParameter("foo", "int", true, helloParameters, 1);

// HelloWorld ->
// @CheckedTemplate(basePath="Foo",
// defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
// record HelloWorld(String name) implements TemplateInstance {}
DataModelTemplate<DataModelParameter> helloWorldTemplate = project
.findDataModelTemplate("src/main/resources/templates/Foo/hello-world");
Assert.assertNotNull(helloWorldTemplate);
Assert.assertEquals("src/main/resources/templates/Foo/hello-world", helloWorldTemplate.getTemplateUri());
Assert.assertEquals("org.acme.sample.HelloResource$HelloWorld", helloWorldTemplate.getSourceType());
Assert.assertNull(helloWorldTemplate.getSourceField());
Assert.assertNull(helloWorldTemplate.getSourceMethod());

List<DataModelParameter> helloWorldParameters = helloWorldTemplate.getParameters();
Assert.assertNotNull(helloWorldParameters);

Assert.assertEquals(1, helloWorldParameters.size());

// record HelloWorld(String name) implements TemplateInstance {}
assertParameter("name", "java.lang.String", false, helloWorldParameters, 0);

}

@Test
public void checkedTemplateWithDefaultName() throws Exception {
loadMavenProject(QuteMavenProjectName.qute_record);
Expand All @@ -423,7 +454,7 @@ public void checkedTemplateWithDefaultName() throws Exception {

// public class HelloResource {
// record Hello(String name) implements TemplateInstance {}

// Hello
DataModelTemplate<DataModelParameter> helloTemplate = project
.findDataModelTemplate("src/main/resources/templates/ItemResource/hello-world.html");
Expand All @@ -441,7 +472,7 @@ public void checkedTemplateWithDefaultName() throws Exception {
// static class Templates2 {
// static native TemplateInstance HelloWorld(String name);
assertParameter("name", "java.lang.String", false, helloParameters, 0);

}

}
Loading

0 comments on commit 3e697eb

Please sign in to comment.