use of io.micronaut.data.processor.visitors.finders.MethodMatcher in project micronaut-data by micronaut-projects.
the class RepositoryTypeElementVisitor method visitMethod.
@Override
public void visitMethod(MethodElement element, VisitorContext context) {
if (currentRepository == null || failing) {
return;
}
ClassElement genericReturnType = element.getGenericReturnType();
if (queryEncoder != null && currentClass != null && element.isAbstract() && !element.isStatic() && methodsMatchers != null) {
ParameterElement[] parameters = element.getParameters();
Map<String, Element> parametersInRole = new HashMap<>(2);
for (ParameterElement parameter : parameters) {
ClassElement type = parameter.getType();
this.typeRoles.entrySet().stream().filter(entry -> {
String roleType = entry.getKey();
return type.isAssignable(roleType);
}).forEach(entry -> parametersInRole.put(entry.getValue(), parameter));
}
if (element.hasDeclaredAnnotation(DataMethod.class)) {
// explicitly handled
return;
}
MatchContext matchContext = new MatchContext(queryEncoder, currentRepository, context, element, typeRoles, genericReturnType, parameters);
try {
SourcePersistentEntity entity = resolvePersistentEntity(element, parametersInRole);
MethodMatchContext methodMatchContext = new MethodMatchContext(queryEncoder, currentRepository, entity, context, genericReturnType, element, parametersInRole, typeRoles, parameters, entityResolver);
for (MethodMatcher finder : methodsMatchers) {
MethodMatcher.MethodMatch matcher = finder.match(methodMatchContext);
if (matcher == null) {
continue;
}
MethodMatchInfo methodInfo = matcher.buildMatchInfo(methodMatchContext);
if (methodInfo == null) {
continue;
}
processMethodInfo(methodMatchContext, methodInfo);
return;
}
if (matchContext.isPossiblyFailing()) {
matchContext.logPossibleFailures();
} else {
String messageStart = matchContext.getUnableToImplementMessage();
context.fail(messageStart + "No possible implementations found.", element);
}
this.failing = true;
} catch (MatchFailedException e) {
context.fail(matchContext.getUnableToImplementMessage() + e.getMessage(), e.getElement() == null ? element : e.getElement());
this.failing = true;
} catch (Exception e) {
matchContext.fail(e.getMessage());
this.failing = true;
}
}
}
Aggregations