Skip to content

Commit

Permalink
fix: Check if record implement TemplateInstance to provide the support
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Jul 12, 2024
1 parent 8a47098 commit 88c1aa1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class HelloResource {

record Hello(String name) implements TemplateInstance {}

record Bonjour(String name) implements TemplateInstance {}

record Status() {}

@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 @@ -20,6 +20,7 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants;
import com.redhat.devtools.lsp4ij.LSPIJUtils;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils;
import com.redhat.devtools.intellij.qute.psi.internal.AnnotationLocationSupport;
Expand Down Expand Up @@ -92,8 +93,8 @@ public AbstractQuteTemplateLinkCollector(PsiFile typeRoot, IPsiUtils utils, Prog
* </p>
*
* @see <a href=
* "https://quarkus.io/guides/qute-reference#quarkus_integration">Quarkus
* Integration</a>
* "https://quarkus.io/guides/qute-reference#quarkus_integration">Quarkus
* Integration</a>
*/
@Override
public void visitField(PsiField node) {
Expand Down Expand Up @@ -154,12 +155,11 @@ public void visitClass(PsiClass node) {
* <p>
*
* @CheckedTemplate public static class Templates { public static native
* TemplateInstance book(Book book);
* </p>
*
* TemplateInstance book(Book book);
* </p>
* @see <a href=
* "https://quarkus.io/guides/qute-reference#typesafe_templates">TypeSafe
* Templates</a>
* "https://quarkus.io/guides/qute-reference#typesafe_templates">TypeSafe
* Templates</a>
*/
private void visitClassType(PsiClass node) {
levelTypeDecl++;
Expand All @@ -184,14 +184,34 @@ private void visitClassType(PsiClass node) {
* Support for "Template Records"
*
* @see <a href=
* "https://quarkus.io/guides/qute-reference#template-records">Template
* Records</a>
* "https://quarkus.io/guides/qute-reference#template-records">Template
* Records</a>
*/
private void visitRecordType(PsiClass node) {
String recordName = node.getName();
collectTemplateLink(null, node, null, node.getContainingClass(), null, recordName, false);
if (isImplementTemplateInstance(node)) {
String recordName = node.getName();
collectTemplateLink(null, node, null, node, null, recordName, false);
}
}

/**
* Returns true if the record implements the "io.quarkus.qute.TemplateInstance"
* interface and false otherwise.
*
* @param node the record node.
* @return true if the record implements the "io.quarkus.qute.TemplateInstance"
* interface and false otherwise.
*/
private static boolean isImplementTemplateInstance(PsiClass node) {
for (var current : node.getImplementsListTypes()) {
if (QuteJavaConstants.TEMPLATE_INSTANCE_INTERFACE.equals(current.getName())) {
return true;
}
}
return false;
}


private static PsiClass getTypeDeclaration(PsiElement node) {
return PsiTreeUtil.getParentOfType(node, PsiClass.class);
}
Expand Down

0 comments on commit 88c1aa1

Please sign in to comment.