From 18968eea47f64744cf8f2c048f43dd6195ff9687 Mon Sep 17 00:00:00 2001 From: azerr Date: Thu, 4 Jul 2024 11:36:27 +0200 Subject: [PATCH] fix: allow inject: with constructor class which have arguments Signed-off-by: azerr --- .../maven/quarkus3/src/main/java/org/acme/Bean3.java | 9 +++++++++ .../devtools/intellij/qute/psi/utils/CDIUtils.java | 5 ++++- .../devtools/intellij/qute/psi/utils/CDIUtilsTest.java | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 projects/qute/projects/maven/quarkus3/src/main/java/org/acme/Bean3.java diff --git a/projects/qute/projects/maven/quarkus3/src/main/java/org/acme/Bean3.java b/projects/qute/projects/maven/quarkus3/src/main/java/org/acme/Bean3.java new file mode 100644 index 000000000..40e99b326 --- /dev/null +++ b/projects/qute/projects/maven/quarkus3/src/main/java/org/acme/Bean3.java @@ -0,0 +1,9 @@ +package org.acme; + +public class Bean3 { + + // Quarkus can inject Bean1 in the constructor without declaring the bean1 parameter with @Inject + public Bean3(Bean1 bean1) { + + } +} diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/CDIUtils.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/CDIUtils.java index 6db8560d5..9d33b0204 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/CDIUtils.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/CDIUtils.java @@ -79,7 +79,10 @@ public static boolean isValidBean(PsiElement javaElement) { && !type.getModifierList().hasExplicitModifier(PsiModifier.ABSTRACT) && !AnnotationUtils.hasAnnotation(javaElement, JAVAX_DECORATOR_ANNOTATION, JAKARTA_DECORATOR_ANNOTATION) && !AnnotationUtils.hasAnnotation(javaElement, JAVAX_INJECT_VETOED_ANNOTATION, JAKARTA_INJECT_VETOED_ANNOTATION) - && PsiTypeUtils.isClass(type) && hasNoArgConstructor(type)); + && PsiTypeUtils.isClass(type) + // In Quarkus context, all arguments are injected + // See https://github.com/redhat-developer/vscode-quarkus/issues/708 + /* && hasNoArgConstructor(type)*/ ); } catch (Exception e) { return false; } diff --git a/src/test/java/com/redhat/devtools/intellij/qute/psi/utils/CDIUtilsTest.java b/src/test/java/com/redhat/devtools/intellij/qute/psi/utils/CDIUtilsTest.java index 7f288839e..6d19d1d57 100644 --- a/src/test/java/com/redhat/devtools/intellij/qute/psi/utils/CDIUtilsTest.java +++ b/src/test/java/com/redhat/devtools/intellij/qute/psi/utils/CDIUtilsTest.java @@ -90,6 +90,10 @@ public void testIsBeanQuarkus3() throws Exception { PsiClass bean1 = PsiTypeUtils.findType(javaProject, "org.acme.Bean1"); // Empty class is a bean assertTrue(CDIUtils.isValidBean(bean1)); + + PsiClass bean3 = PsiTypeUtils.findType(javaProject, "org.acme.Bean3"); + // Class with constructor is a bean + assertTrue(CDIUtils.isValidBean(bean3)); } }