Skip to content

Commit

Permalink
Merge branch 'SentryMan-aspect2' into jakarta-master
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Jan 31, 2023
2 parents 0602a5c + 9b32648 commit 391e4cc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ List<MethodReader.MethodParam> initParams(List<? extends VariableElement> parame

void addTargets(Set<String> targets) {
for (AspectPair aspectPair : aspectPairs) {
targets.add(aspectPair.target());
targets.add(aspectPair.annotationShortName());
}
}

Expand Down Expand Up @@ -123,8 +123,7 @@ void writeSetupForMethods(Append writer, String shortName) {
}
writer.append(");").eol();
for (AspectPair aspect : aspectPairs) {
String target = aspect.target();
String name = aspectTargetShortName(target);
String name = Util.initLower(aspect.annotationShortName());
String sn = aspect.annotationShortName();
writer.append(" %s%s = %s.interceptor(%s, %s.getAnnotation(%s.class));", localName, sn, name, localName, localName, sn).eol();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ String target() {
}

void addImports(ImportTypeMap importTypes) {
importTypes.add(target);
importTypes.add("io.avaje.inject.aop.AspectProvider");
importTypes.add(annotationFullName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,41 @@ final class BeanAspects {
static final BeanAspects EMPTY = new BeanAspects();

private final List<AspectMethod> aspectMethods;
private final Set<String> targets;
private final Set<String> aspectNames;

private BeanAspects() {
this.aspectMethods = Collections.emptyList();
this.targets = Collections.emptySet();
this.aspectNames = Collections.emptySet();
}

BeanAspects(List<AspectMethod> aspectMethods) {
this.aspectMethods = aspectMethods;
this.targets = initTargets();
this.aspectNames = initAspectNames();
}

boolean hasAspects() {
return !aspectMethods.isEmpty();
}

Set<String> targets() {
return targets;
Set<String> aspectNames() {
return aspectNames;
}

void extraImports(ImportTypeMap importTypes) {
for (AspectMethod aspectMethod : aspectMethods) {
for (final AspectMethod aspectMethod : aspectMethods) {
aspectMethod.addImports(importTypes);
}
}

Set<String> initTargets() {
Set<String> targets = new LinkedHashSet<>();
for (AspectMethod aspectMethod : aspectMethods) {
Set<String> initAspectNames() {
final Set<String> targets = new LinkedHashSet<>();
for (final AspectMethod aspectMethod : aspectMethods) {
aspectMethod.addTargets(targets);
}
return targets;
}

void writeFields(Append writer) {
for (String target : targets) {
String type = Util.shortName(target);
String name = Util.initLower(type);
writer.append(" private final %s %s;", type, name).eol();
}
writer.eol();
}

List<AspectMethod> methods() {
return aspectMethods;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private void writeMethods() {
}

private void writeFields() {
aspects.writeFields(writer);
for (AspectMethod method : aspects.methods()) {
method.writeSetupFields(writer);
}
Expand All @@ -57,21 +56,17 @@ private void writeFields() {
private void writeConstructor() {
writer.append(" public %s%s(", shortName, suffix);
int count = 0;
for (String target : aspects.targets()) {
for (final String aspectName : aspects.aspectNames()) {
if (count++ > 0) {
writer.append(", ");
}
final String type = Util.shortName(target);
String name = Util.initLower(type);
final var type = "AspectProvider<" + aspectName + ">";
final var name = Util.initLower(aspectName);
writer.append(type).append(" ").append(name);
}
beanReader.writeConstructorParams(writer);
writer.append(") {").eol();
beanReader.writeConstructorInit(writer);
for (String target : aspects.targets()) {
String name = AspectMethod.aspectTargetShortName(target);
writer.append(" this.%s = %s;", name, name).eol();
}
writeSetupForMethods();
writer.append(" }").eol();
}
Expand Down
2 changes: 1 addition & 1 deletion inject/src/main/java/io/avaje/inject/aop/Aspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Specify the {@link AspectProvider} for this aspect.
*/
Class<?> target();
Class<? extends AspectProvider> target();

/**
* Specify the priority ordering when multiple aspects are on a method.
Expand Down

0 comments on commit 391e4cc

Please sign in to comment.