createTemplateDataModel(String templateUri, PsiMethod method, PsiClass type) {
String methodName = method.getName();
diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/template/datamodel/TemplateRecordsSupport.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/template/datamodel/TemplateRecordsSupport.java
index 9e87ba28e..23b62e6cf 100644
--- a/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/template/datamodel/TemplateRecordsSupport.java
+++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/template/datamodel/TemplateRecordsSupport.java
@@ -12,6 +12,7 @@
package com.redhat.devtools.intellij.qute.psi.internal.template.datamodel;
import com.intellij.openapi.progress.ProgressIndicator;
+import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiRecordComponent;
import com.redhat.devtools.intellij.qute.psi.internal.template.TemplateDataSupport;
@@ -26,6 +27,7 @@
import java.util.List;
import static com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants.TEMPLATE_INSTANCE_INTERFACE;
+import static com.redhat.devtools.intellij.qute.psi.internal.template.datamodel.CheckedTemplateSupport.*;
import static com.redhat.devtools.intellij.qute.psi.utils.PsiQuteProjectUtils.getTemplatePath;
/**
@@ -36,6 +38,9 @@
*
* record Hello(String name) implements TemplateInstance {}
*
+ *
+ * @CheckedTemplate(basePath="Foo", defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
+ * record HelloWorld(String name) implements TemplateInstance {}
* ...
*
*
@@ -76,13 +81,18 @@ private static void collectDataModelTemplateForTemplateRecord(PsiClass type,
templates.add(template);
}
- private static DataModelTemplate createTemplateDataModel(PsiClass type,
+ private static DataModelTemplate createTemplateDataModel(PsiClass recordType,
String relativeTemplateBaseDir,
ProgressIndicator monitor) {
- String recordName = type.getName();
+ PsiAnnotation checkedTemplateAnnotation = getCheckedAnnotation(recordType);
+ boolean ignoreFragments = isIgnoreFragments(checkedTemplateAnnotation);
+ String basePath = getBasePath(checkedTemplateAnnotation);
+ TemplateNameStrategy templateNameStrategy = getDefaultName(checkedTemplateAnnotation);
+ String className = getParentClassName(recordType);
+ String recordName = recordType.getName();
// src/main/resources/templates/${recordName}.qute.html
- String templateUri = getTemplatePath(relativeTemplateBaseDir, null, null, recordName, true, TemplateNameStrategy.ELEMENT_NAME).getTemplateUri();
+ String templateUri = getTemplatePath(relativeTemplateBaseDir, basePath, className, recordName, ignoreFragments, templateNameStrategy).getTemplateUri();
// Create template data model with:
// - template uri : Qute template file which must be bind with data model.
@@ -91,10 +101,10 @@ private static DataModelTemplate createTemplateDataModel(Psi
DataModelTemplate template = new DataModelTemplate();
template.setParameters(new ArrayList<>());
template.setTemplateUri(templateUri);
- template.setSourceType(type.getQualifiedName());
+ template.setSourceType(recordType.getQualifiedName());
// Collect data parameters from the record fields
- for (PsiRecordComponent field : type.getRecordComponents()) {
+ for (PsiRecordComponent field : recordType.getRecordComponents()) {
DataModelParameter parameter = new DataModelParameter();
parameter.setKey(field.getName());
parameter.setSourceType(PsiTypeUtils.resolveSignature(field.getType(), field.isVarArgs()));
@@ -106,7 +116,7 @@ private static DataModelTemplate createTemplateDataModel(Psi
}
// Collect data parameters for the given template
- TemplateDataSupport.collectParametersFromDataMethodInvocation(type, template, monitor);
+ TemplateDataSupport.collectParametersFromDataMethodInvocation(recordType, template, monitor);
return template;
}
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 4a95c30ce..35c11a0ae 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -6,6 +6,11 @@
2.0.2
+
+ - Fixed incorrect behavior for nested Qute template records
+
+ Learn more in the changelog.
2.0.1
- Fixed gradle-powered project failing to 'Run Dev'
diff --git a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaCodeLensTest.java b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaCodeLensTest.java
index a985e0b54..349b58859 100644
--- a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaCodeLensTest.java
+++ b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaCodeLensTest.java
@@ -353,6 +353,10 @@ public void testTemplateRecord() throws Exception {
// record Bonjour(String name) implements TemplateInstance {}
// record Status() {}
+
+ // @CheckedTemplate(basePath="Foo", defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
+ // record HelloWorld(String name) implements TemplateInstance {}
+
var module = loadMavenProject(QuteMavenProjectName.qute_record);
QuteJavaCodeLensParams params = new QuteJavaCodeLensParams();
@@ -362,16 +366,20 @@ public void testTemplateRecord() throws Exception {
List extends CodeLens> lenses = QuteSupportForJava.getInstance().codeLens(params, PsiUtilsLSImpl.getInstance(myProject),
new EmptyProgressIndicator());
- String helloFileUri = LSPIJUtils.toUri(module).resolve("/src/main/resources/templates/Hello.html").toASCIIString();
- String bonjourFileUri = LSPIJUtils.toUri(module).resolve("/src/main/resources/templates/Bonjour.html").toASCIIString();
+ String helloFileUri = LSPIJUtils.toUri(module).resolve("/src/main/resources/templates/HelloResource/Hello.html").toASCIIString();
+ String bonjourFileUri = LSPIJUtils.toUri(module).resolve("/src/main/resources/templates/HelloResource/Bonjour.html").toASCIIString();
+ String helloWorldFileUri = LSPIJUtils.toUri(module).resolve("/src/main/resources/templates/Foo/hello-world.html").toASCIIString();
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(bonjourFileUri)));
+ cl(r(17, 4, 17, 62), //
+ "Create `src/main/resources/templates/HelloResource/Bonjour.html`", //
+ "qute.command.generate.template.file", Arrays.asList(bonjourFileUri)), //
+ cl(r(21, 4, 22, 65), //
+ "Create `src/main/resources/templates/Foo/hello-world.html`", //
+ "qute.command.generate.template.file", Arrays.asList(helloWorldFileUri)));
}
@Test
diff --git a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDiagnosticsTest.java b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDiagnosticsTest.java
index 1b6ff7e92..26213a1b7 100644
--- a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDiagnosticsTest.java
+++ b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDiagnosticsTest.java
@@ -265,6 +265,9 @@ public void testTemplateRecord() throws Exception {
// record Status() {}
+ // @CheckedTemplate(basePath="Foo", defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
+ // record HelloWorld(String name) implements TemplateInstance {}
+
var module = loadMavenProject(QuteMavenProjectName.qute_record);
QuteJavaDiagnosticsParams params = new QuteJavaDiagnosticsParams();
String javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/sample/HelloResource.java").toASCIIString();
@@ -272,14 +275,17 @@ public void testTemplateRecord() throws Exception {
List publishDiagnostics = QuteSupportForJava.getInstance().diagnostics(params,
PsiUtilsLSImpl.getInstance(myProject), new EmptyProgressIndicator());
- assertEquals(1, publishDiagnostics.size());
+ assertEquals(2, publishDiagnostics.size());
List diagnostics = publishDiagnostics.get(0).getDiagnostics();
assertEquals(1, 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()));
}
diff --git a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDocumentLinkTest.java b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDocumentLinkTest.java
index 4f7ff9b34..3c430e0d3 100644
--- a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDocumentLinkTest.java
+++ b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDocumentLinkTest.java
@@ -290,6 +290,10 @@ public void testTemplateRecord() throws Exception {
// record Bonjour(String name) implements TemplateInstance {}
// record Status() {}
+
+ // @CheckedTemplate(basePath="Foo", defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
+ // record HelloWorld(String name) implements TemplateInstance {}
+
var module = loadMavenProject(QuteMavenProjectName.qute_record);
QuteJavaDocumentLinkParams params = new QuteJavaDocumentLinkParams();
String javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/sample/HelloResource.java").toASCIIString();
@@ -297,15 +301,19 @@ public void testTemplateRecord() throws Exception {
List links = QuteSupportForJava.getInstance().documentLink(params, PsiUtilsLSImpl.getInstance(myProject),
new EmptyProgressIndicator());
- assertEquals(2, links.size());
+ assertEquals(3, links.size());
- String templateFileUri = LSPIJUtils.toUri(module).resolve("src/main/resources/templates/Hello.html").toASCIIString();
+ String helloFileUri = LSPIJUtils.toUri(module).resolve("/src/main/resources/templates/HelloResource/Hello.html").toASCIIString();
+ String bonjourFileUri = LSPIJUtils.toUri(module).resolve("/src/main/resources/templates/HelloResource/Bonjour.html").toASCIIString();
+ String helloWorldFileUri = LSPIJUtils.toUri(module).resolve("/src/main/resources/templates/Foo/hello-world.html").toASCIIString();
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), //
+ bonjourFileUri, "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
diff --git a/src/test/java/com/redhat/devtools/intellij/qute/psi/template/TemplateGetDataModelProjectTest.java b/src/test/java/com/redhat/devtools/intellij/qute/psi/template/TemplateGetDataModelProjectTest.java
index 2a60da69d..b92a73c67 100644
--- a/src/test/java/com/redhat/devtools/intellij/qute/psi/template/TemplateGetDataModelProjectTest.java
+++ b/src/test/java/com/redhat/devtools/intellij/qute/psi/template/TemplateGetDataModelProjectTest.java
@@ -383,13 +383,21 @@ public void testQuteRecord() throws Exception {
Assert.assertNotNull(project);
// public class HelloResource {
+
// record Hello(String name) implements TemplateInstance {}
- // Hello
+ // record Bonjour(String name) implements TemplateInstance {}
+
+ // record Status() {}
+
+ // @CheckedTemplate(basePath="Foo", defaultName=CheckedTemplate.HYPHENATED_ELEMENT_NAME)
+ // record HelloWorld(String name) implements TemplateInstance {}
+
+ // Hello ->
DataModelTemplate helloTemplate = project
- .findDataModelTemplate("src/main/resources/templates/Hello");
+ .findDataModelTemplate("src/main/resources/HelloResource/templates/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());
@@ -405,6 +413,26 @@ public void testQuteRecord() throws Exception {
// 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 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 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