use of io.quarkiverse.githubaction.Action in project quarkus-github-action by quarkiverse.
the class GitHubActionProcessor method getDispatchingConfiguration.
private static DispatchingConfiguration getDispatchingConfiguration(IndexView index, Collection<EventDefinition> allEventDefinitions) {
DispatchingConfiguration configuration = new DispatchingConfiguration();
Collection<AnnotationInstance> actionInstances = index.getAnnotations(ACTION).stream().filter(ai -> ai.target().kind() == Kind.METHOD).collect(Collectors.toList());
for (AnnotationInstance actionInstance : actionInstances) {
String name = actionInstance.valueWithDefault(index).asString();
MethodInfo methodInfo = actionInstance.target().asMethod();
boolean hasEventListeners = false;
for (EventDefinition eventDefinition : allEventDefinitions) {
Collection<AnnotationInstance> eventSubscriberInstances = methodInfo.annotations(eventDefinition.getAnnotation());
for (AnnotationInstance eventSubscriberInstance : eventSubscriberInstances) {
String action = eventDefinition.getAction() != null ? eventDefinition.getAction() : (eventSubscriberInstance.value() != null ? eventSubscriberInstance.value().asString() : Actions.ALL);
MethodParameterInfo annotatedParameter = eventSubscriberInstance.target().asMethodParameter();
DotName annotatedParameterType = annotatedParameter.method().parameters().get(annotatedParameter.position()).name();
if (!eventDefinition.getPayloadType().equals(annotatedParameterType)) {
throw new IllegalStateException("Parameter subscribing to a GitHub '" + eventDefinition.getEvent() + "' event should be of type '" + eventDefinition.getPayloadType() + "'. Offending method: " + methodInfo.declaringClass().name() + "#" + methodInfo);
}
configuration.getOrCreateActionConfiguration(name, eventDefinition.getEvent(), eventDefinition.getPayloadType().toString()).addEventAnnotation(action, eventSubscriberInstance);
configuration.addActionDispatchingMethod(new ActionDispatchingMethod(name, eventSubscriberInstance, methodInfo));
hasEventListeners = true;
}
}
if (!hasEventListeners) {
configuration.getOrCreateActionConfiguration(name, EventDefinition.ALL, null);
configuration.addActionDispatchingMethod(new ActionDispatchingMethod(name, null, methodInfo));
}
}
// Methods listening to an event but with no @Action annotation, we consider them unnamed.
for (EventDefinition eventDefinition : allEventDefinitions) {
Collection<AnnotationInstance> eventSubscriberInstances = index.getAnnotations(eventDefinition.getAnnotation()).stream().filter(ai -> ai.target().kind() == Kind.METHOD_PARAMETER).filter(ai -> !ai.target().asMethodParameter().method().hasAnnotation(ACTION)).collect(Collectors.toList());
for (AnnotationInstance eventSubscriberInstance : eventSubscriberInstances) {
MethodParameterInfo annotatedParameter = eventSubscriberInstance.target().asMethodParameter();
MethodInfo methodInfo = annotatedParameter.method();
String name = Action.UNNAMED;
String action = eventDefinition.getAction() != null ? eventDefinition.getAction() : (eventSubscriberInstance.value() != null ? eventSubscriberInstance.value().asString() : Actions.ALL);
DotName annotatedParameterType = annotatedParameter.method().parameters().get(annotatedParameter.position()).name();
if (!eventDefinition.getPayloadType().equals(annotatedParameterType)) {
throw new IllegalStateException("Parameter subscribing to a GitHub '" + eventDefinition.getEvent() + "' action should be of type '" + eventDefinition.getPayloadType() + "'. Offending method: " + methodInfo.declaringClass().name() + "#" + methodInfo);
}
configuration.getOrCreateActionConfiguration(name, eventDefinition.getEvent(), eventDefinition.getPayloadType().toString()).addEventAnnotation(action, eventSubscriberInstance);
configuration.addActionDispatchingMethod(new ActionDispatchingMethod(name, eventSubscriberInstance, methodInfo));
}
}
return configuration;
}
Aggregations