From 12d40cec2addfe6d2eac65420b7094291946e540 Mon Sep 17 00:00:00 2001 From: azerr Date: Thu, 7 Nov 2024 14:44:42 +0100 Subject: [PATCH] feat: support for global namespace Signed-off-by: azerr --- .../datamodel/TemplateGlobalAnnotationSupport.java | 3 +++ src/main/resources/META-INF/plugin.xml | 6 ++++-- .../psi/template/TemplateGetDataModelProjectTest.java | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/template/datamodel/TemplateGlobalAnnotationSupport.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/template/datamodel/TemplateGlobalAnnotationSupport.java index 939e6c81e..12890e76a 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/template/datamodel/TemplateGlobalAnnotationSupport.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/template/datamodel/TemplateGlobalAnnotationSupport.java @@ -70,6 +70,8 @@ public class TemplateGlobalAnnotationSupport extends AbstractAnnotationTypeRefer TEMPLATE_GLOBAL_ANNOTATION }; + private static final String GLOBAL_NAMESPACE = "global"; + @Override protected String[] getAnnotationNames() { return ANNOTATION_NAMES; @@ -133,6 +135,7 @@ private void collectResolversForTemplateGlobal(PsiMember member, PsiAnnotation t ValueResolverInfo resolver = new ValueResolverInfo(); resolver.setSourceType(sourceType); resolver.setSignature(typeResolver.resolveSignature(member)); + resolver.setNamespace(GLOBAL_NAMESPACE); resolver.setKind(ValueResolverKind.TemplateGlobal); // Constant value for {@link #name()} indicating that the field/method name // should be used diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index ddd95a22d..7571176f8 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -683,8 +683,10 @@ implementationClass="com.redhat.devtools.intellij.qute.psi.internal.template.datamodel.TemplateDataAnnotationSupport"/> - + 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 72f961656..bc575dda5 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 @@ -345,21 +345,21 @@ private static void testValueResolversFromTemplateGlobal(List // public class Globals { // static int age = 40; - assertValueResolver(null, "age : int", "org.acme.qute.Globals", null, true, resolvers); + assertValueResolver("global", "age : int", "org.acme.qute.Globals", null, true, resolvers); // static String name; - assertValueResolver(null, "name : java.lang.String", "org.acme.qute.Globals", null, true, resolvers); + assertValueResolver("global", "name : java.lang.String", "org.acme.qute.Globals", null, true, resolvers); // static Color[] myColors() { // return new Color[] { Color.RED, Color.BLUE }; // } - assertValueResolver(null, "myColors() : org.acme.qute.Color[]", "org.acme.qute.Globals", null, true, resolvers); + assertValueResolver("global", "myColors() : org.acme.qute.Color[]", "org.acme.qute.Globals", null, true, resolvers); // @TemplateGlobal(name = "currentUser") // static String user() { // return "Mia"; // } - assertValueResolver(null, "user() : java.lang.String", "org.acme.qute.Globals", "currentUser", true, resolvers); + assertValueResolver("global", "user() : java.lang.String", "org.acme.qute.Globals", "currentUser", true, resolvers); // } }