Skip to content

Commit

Permalink
fix: Qute fragments doesn't work with non inner Templates Java file
Browse files Browse the repository at this point in the history
Fixes redhat-developer#937

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Jul 29, 2024
1 parent f80700e commit 3a1c1ba
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.acme.qute;

import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.TemplateInstance;

import java.util.List;

@CheckedTemplate
public class ItemTemplates {

static native TemplateInstance items(List<Item> items);
static native TemplateInstance items$id1(List<Item> items);
static native TemplateInstance items3$id2(List<Item> items);
static native TemplateInstance items3$(List<Item> items);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.acme.qute;

import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.TemplateInstance;

import java.util.List;

@CheckedTemplate(ignoreFragments = true)
public class ItemTemplatesIgnoreFragments {

static native TemplateInstance items2(List<Item> items);
static native TemplateInstance items2$id1(List<Item> items);
static native TemplateInstance items2$id2(List<Item> items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,78 @@ public void checkedTemplateInInnerClass() throws CoreException, Exception {
"qute.command.generate.template.file", Arrays.asList(items2Uri)));
}

@Test
public void checkedTemplateWithFragment() throws Exception {

// @CheckedTemplate
// public class ItemTemplates {
//
// static native TemplateInstance items(List<Item> items);
// static native TemplateInstance items$id1(List<Item> items);
// static native TemplateInstance items3$id2(List<Item> items);
// static native TemplateInstance items3$(List<Item> items);
// }

IJavaProject javaProject = loadMavenProject(QuteMavenProjectName.qute_quickstart);

QuteJavaCodeLensParams params = new QuteJavaCodeLensParams();
IFile javaFile = javaProject.getProject().getFile(new Path("src/main/java/org/acme/qute/ItemTemplates.java"));
params.setUri(javaFile.getLocation().toFile().toURI().toString());

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

String itemsUri = javaProject.getProject().getFile("src/main/resources/templates/items.html").getLocationURI()
.toString();
String items3Uri = javaProject.getProject().getFile("src/main/resources/templates/items3.html").getLocationURI()
.toString();

assertCodeLens(lenses, //
cl(r(10, 4, 10, 59), //
"Open `src/main/resources/templates/items.html`", //
"qute.command.open.uri", Arrays.asList(itemsUri)), //
cl(r(11, 4, 11, 63), //
"Open `id1` fragment of `src/main/resources/templates/items.html`", //
"qute.command.open.uri", Arrays.asList(itemsUri, "id1")), //
cl(r(12, 4, 12, 64), //
"Create `src/main/resources/templates/items3.html`", //
"qute.command.generate.template.file", Arrays.asList(items3Uri)));

// @CheckedTemplate(ignoreFragments = true)
// public class ItemTemplatesIgnoreFragments {
//
// static native TemplateInstance items2(List<Item> items);
// static native TemplateInstance items2$id1(List<Item> items);
// static native TemplateInstance items2$id2(List<Item> items);
// }
params = new QuteJavaCodeLensParams();
javaFile = javaProject.getProject()
.getFile(new Path("src/main/java/org/acme/qute/ItemTemplatesIgnoreFragments.java"));
params.setUri(javaFile.getLocation().toFile().toURI().toString());

lenses = QuteSupportForJava.getInstance().codeLens(params, getJDTUtils(), new NullProgressMonitor());
assertEquals(3, lenses.size());

String items2Uri = javaProject.getProject().getFile("src/main/resources/templates/items2.html").getLocationURI()
.toString();
String items2Uri_id1 = javaProject.getProject().getFile("src/main/resources/templates/items2$id1.html")
.getLocationURI().toString();
String items2Uri_id2 = javaProject.getProject().getFile("src/main/resources/templates/items2$id2.html")
.getLocationURI().toString();

assertCodeLens(lenses, //
cl(r(10, 4, 10, 60), //
"Open `src/main/resources/templates/items2.html`", //
"qute.command.open.uri", Arrays.asList(items2Uri)), //
cl(r(11, 4, 11, 64), //
"Open `src/main/resources/templates/items2$id1.html`", //
"qute.command.open.uri", Arrays.asList(items2Uri_id1)), //
cl(r(12, 4, 12, 64), //
"Create `src/main/resources/templates/items2$id2.html`", //
"qute.command.generate.template.file", Arrays.asList(items2Uri_id2)));
}

@Test
public void checkedTemplateWithCustomBasePath() throws Exception {

Expand Down Expand Up @@ -285,7 +357,7 @@ public void checkedTemplateInInnerClassWithCustomBasePath() throws Exception {
}

@Test
public void checkedTemplateWithFragment() throws CoreException, Exception {
public void checkedTemplateInInnerClassWithFragment() throws CoreException, Exception {

IJavaProject javaProject = loadMavenProject(QuteMavenProjectName.qute_quickstart);

Expand Down

0 comments on commit 3a1c1ba

Please sign in to comment.