Skip to content

Commit

Permalink
Merge branch '1.1.x' into 1.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskleeh committed Aug 20, 2019
2 parents 42364e9 + 21d50ce commit 60b9a2d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ class InjectTransform implements ASTTransformation, CompilationUnitAware {
} else if (isFactoryClass || isConfigurationProperties || annotationMetadata.hasStereotype(Bean, Scope)) {
defineBeanDefinition(concreteClass)
}
this.isDeclaredBean = isExecutableType || isConfigurationProperties || isFactoryClass || annotationMetadata.hasStereotype(Scope.class) || annotationMetadata.hasStereotype(DefaultScope.class)
this.isDeclaredBean = isExecutableType || isConfigurationProperties || isFactoryClass || annotationMetadata.hasStereotype(Scope.class) || annotationMetadata.hasStereotype(DefaultScope.class) || concreteClass.declaredConstructors.any {
AnnotationMetadata constructorMetadata = AstAnnotationUtils.getAnnotationMetadata(sourceUnit, it)
constructorMetadata.hasStereotype(Inject)
}
}

BeanDefinitionVisitor getBeanWriter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PostConstructCompileSpec extends AbstractBeanDefinitionSpec {

void "test that a @PostConstruct method on a type not defined as a bean doesn't create a bean"() {
when:
buildBeanDefinition('test.Test', '''
BeanDefinition definition = buildBeanDefinition('test.Test', '''
package test;
import javax.annotation.PostConstruct;
Expand All @@ -24,8 +24,6 @@ class Test {

then:
thrown(ClassNotFoundException)


}

void "test visit constructor @Inject"() {
Expand All @@ -48,7 +46,30 @@ class Test {

then:
definition != null
definition.postConstructMethods.empty

}

void "test visit constructor @Inject and @PostConstruct"() {
when:
def definition = buildBeanDefinition('test.Test', '''
package test;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
class Test {
@Inject
Test() { }
@PostConstruct
void init() { }
}
''')

then:
definition != null
definition.postConstructMethods.size() == 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,10 @@ class AnnBeanElementVisitor extends ElementScanner8<Object, Object> {
this.isConfigurationPropertiesType = isConfigurationProperties(concreteClass);
this.isAopProxyType = concreteClassMetadata.hasStereotype(AROUND_TYPE) && !modelUtils.isAbstract(concreteClass);
this.aopSettings = isAopProxyType ? concreteClassMetadata.getValues(AROUND_TYPE, Boolean.class) : OptionalValues.empty();
ExecutableElement constructor = modelUtils.concreteConstructorFor(concreteClass, annotationUtils);
this.constructorParameterInfo = populateParameterData(null, constructor, Collections.emptyMap());
this.isExecutableType = isAopProxyType || concreteClassMetadata.hasStereotype(Executable.class);
this.isDeclaredBean = isExecutableType || isConfigurationPropertiesType || isFactoryType || concreteClassMetadata.hasStereotype(Scope.class) || concreteClassMetadata.hasStereotype(DefaultScope.class);
this.isDeclaredBean = isExecutableType || isConfigurationPropertiesType || isFactoryType || concreteClassMetadata.hasStereotype(Scope.class) || concreteClassMetadata.hasStereotype(DefaultScope.class) || constructorParameterInfo.getAnnotationMetadata().hasStereotype(Inject.class);
}

/**
Expand Down Expand Up @@ -406,8 +408,6 @@ public Object visitType(TypeElement classElement, Object o) {
qualifiedName.equals(classElementQualifiedName)) {

if (qualifiedName.equals(classElementQualifiedName)) {
ExecutableElement constructor = modelUtils.concreteConstructorFor(classElement, annotationUtils);
this.constructorParameterInfo = populateParameterData(null, constructor, Collections.emptyMap());
final boolean isBean = isAopProxyType ||
isConfigurationPropertiesType ||
typeAnnotationMetadata.hasStereotype(ANNOTATION_STEREOTYPES) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,51 @@ class Test {
then:
definition == null
}

void "test visit constructor @Inject"() {
when:
def definition = buildBeanDefinition('test.Test', '''
package test;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
class Test {
@Inject
Test() {
}
}
''')

then:
definition != null
definition.postConstructMethods.empty

}

void "test visit constructor @Inject and @PostConstruct"() {
when:
def definition = buildBeanDefinition('test.Test', '''
package test;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
class Test {
@Inject
Test() { }
@PostConstruct
void init() { }
}
''')

then:
definition != null
definition.postConstructMethods.size() == 1
}
}

0 comments on commit 60b9a2d

Please sign in to comment.