Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow inject: with constructor class which have arguments #1351

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}

}
Loading