Skip to content

Commit

Permalink
fix: allow inject: with constructor class which have arguments
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr authored and fbricon committed Jul 8, 2024
1 parent 302b789 commit af4b299
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}

0 comments on commit af4b299

Please sign in to comment.