Skip to content

Commit

Permalink
#408 - Support for package protected bean with AOP aspect
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Oct 9, 2023
1 parent aed3637 commit 0934778
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.example.myapp.aspect.MyTimed;

@Singleton
public class OtherService {
class OtherService {

@MyAround
public String other(String param0, int param1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.example.myapp;

import jakarta.inject.Singleton;

@Singleton
class OtherUserOf {

final OtherService otherService;

OtherUserOf(OtherService otherService) {
this.otherService = otherService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ final class TypeExtendsReader {
private final boolean baseTypeIsInterface;
private final boolean publicAccess;
private final boolean autoProvide;
private final boolean proxyBean;
private boolean closeable;
/**
* The implied qualifier name based on naming convention.
*/
private String qualifierName;
private String providesAspect = "";

TypeExtendsReader(GenericType baseGenericType, TypeElement baseType, boolean factory, ImportTypeMap importTypes) {
TypeExtendsReader(GenericType baseGenericType, TypeElement baseType, boolean factory, ImportTypeMap importTypes, boolean proxyBean) {
this.baseGenericType = baseGenericType;
this.baseType = baseType;
this.extendsInjection = new TypeExtendsInjection(baseType, factory, importTypes);
Expand All @@ -50,6 +51,7 @@ final class TypeExtendsReader {
this.baseTypeIsInterface = baseType.getKind() == ElementKind.INTERFACE;
this.publicAccess = baseType.getModifiers().contains(Modifier.PUBLIC);
this.autoProvide = autoProvide();
this.proxyBean = proxyBean;
}

private boolean autoProvide() {
Expand Down Expand Up @@ -147,7 +149,7 @@ void process(boolean forBean) {
qualifierName = baseName.substring(0, baseName.length() - superName.length()).toLowerCase();
}
}
addSuperType(superElement, superMirror);
addSuperType(superElement, superMirror, proxyBean);
}

providesTypes.addAll(extendsTypes);
Expand All @@ -167,12 +169,12 @@ private String initProvidesAspect() {
return "";
}

private void addSuperType(TypeElement element, TypeMirror mirror) {
private void addSuperType(TypeElement element, TypeMirror mirror, boolean proxyBean) {
readInterfaces(element);
final String fullName = mirror.toString();
if (!JAVA_LANG_OBJECT.equals(fullName) && !JAVA_LANG_RECORD.equals(fullName)) {
final String type = Util.unwrapProvider(fullName);
if (isPublic(element)) {
if (proxyBean || isPublic(element)) {
final var genericType = GenericType.parse(type);
// check if any unknown generic types are in the parameters (T,T2, etc.)
final var knownType =
Expand All @@ -186,7 +188,7 @@ private void addSuperType(TypeElement element, TypeMirror mirror) {

final var superMirror = element.getSuperclass();
final var superElement = asElement(superMirror);
addSuperType(superElement, superMirror);
addSuperType(superElement, superMirror, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ private TypeReader(GenericType genericType, boolean forBean, TypeElement beanTyp
this.forBean = forBean;
this.beanType = beanType;
this.importTypes = importTypes;
this.extendsReader = new TypeExtendsReader(genericType, beanType, factory, importTypes);
final boolean proxyBean = forBean && ProxyPrism.isPresent(beanType);
this.extendsReader = new TypeExtendsReader(genericType, beanType, factory, importTypes, proxyBean);
this.annotationReader = new TypeAnnotationReader(beanType);
}

Expand Down

0 comments on commit 0934778

Please sign in to comment.