Skip to content

Commit

Permalink
Merge pull request #64 from sashirestela/63-error-with-compound-strea…
Browse files Browse the repository at this point in the history
…mtype-annotation

Fixing error with compound StreamType
  • Loading branch information
sashirestela authored Mar 24, 2024
2 parents 4228bac + 7936d3b commit 94b2506
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.sashirestela</groupId>
<artifactId>cleverclient</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
<packaging>jar</packaging>

<name>cleverclient</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public class ReturnType {
Expand Down Expand Up @@ -50,25 +51,30 @@ private void setClassByEventIfExists(Method method) {
this.classByEvent = calculateClassByEvent(
new StreamType[] { method.getDeclaredAnnotation(StreamType.class) });
} else {
var annotations = method.getDeclaredAnnotations();
if (isAnnotationPresent(annotations, StreamType.List.class)) {
var innerStreamTypeList = getInnerAnnotationIfExists(method, StreamType.List.class);
if (innerStreamTypeList.isPresent()) {
this.classByEvent = calculateClassByEvent(
Arrays.stream(annotations)
.map(a -> a.annotationType().getDeclaredAnnotation(StreamType.List.class).value())
.findFirst()
.orElse(null));
} else if (isAnnotationPresent(annotations, StreamType.class)) {
this.classByEvent = calculateClassByEvent(
new StreamType[] { Arrays.stream(annotations)
.map(a -> a.annotationType().getDeclaredAnnotation(StreamType.class))
.findFirst()
.orElse(null) });
innerStreamTypeList.get()
.annotationType()
.getDeclaredAnnotation(StreamType.List.class)
.value());
} else {
var innerStreamType = getInnerAnnotationIfExists(method, StreamType.class);
if (innerStreamType.isPresent()) {
this.classByEvent = calculateClassByEvent(
new StreamType[] { innerStreamType.get()
.annotationType()
.getDeclaredAnnotation(StreamType.class) });
}
}
}
}

private boolean isAnnotationPresent(Annotation[] annotations, Class<? extends Annotation> clazz) {
return Arrays.stream(annotations).anyMatch(a -> a.annotationType().isAnnotationPresent(clazz));
private Optional<? extends Annotation> getInnerAnnotationIfExists(Method method,
Class<? extends Annotation> clazz) {
return Arrays.stream(method.getDeclaredAnnotations())
.filter(a -> a.annotationType().isAnnotationPresent(clazz))
.findFirst();
}

private Map<String, Class<?>> calculateClassByEvent(StreamType[] streamTypeList) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.sashirestela.cleverclient.support;

import io.github.sashirestela.cleverclient.Event;
import io.github.sashirestela.cleverclient.annotation.POST;
import org.junit.jupiter.api.Test;

import java.io.InputStream;
Expand Down Expand Up @@ -88,6 +89,7 @@ void shouldReturnMapClassByEventWhenTheMethodIsAnnotatedWithCompositeSingleStrea

static interface TestInterface {

@POST
@CompositeTwo
CompletableFuture<Stream<Event>> asyncStreamEventMethod();

Expand Down

0 comments on commit 94b2506

Please sign in to comment.