use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class ClientTypesRule method validate.
@Override
public RouteValidationResult validate(List<UriMatchTemplate> templates, ParameterElement[] parameters, MethodElement method) {
String[] errors = new String[] {};
if (method.hasAnnotation(Client.class)) {
final Stream.Builder<ClassElement> builder = Stream.<ClassElement>builder().add(method.getReturnType());
for (ParameterElement param : method.getParameters()) {
builder.add(param.getType());
}
errors = builder.build().filter(type -> {
for (Class<?> clazz : SERVER_TYPES) {
if (type.isAssignable(clazz)) {
return true;
}
}
return false;
}).map(type -> "The type [" + type + "] must not be used in declarative client methods. The type is specific to server based usages.").toArray(String[]::new);
}
return new RouteValidationResult(errors);
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class WebSocketVisitor method isInvalidParameter.
private boolean isInvalidParameter(List<String> variables, ParameterElement parameter, String... validTypes) {
String parameterName = parameter.getName();
ClassElement parameterType = parameter.getType();
return !parameter.hasStereotype(Bindable.class) && !variables.contains(parameterName) && Arrays.stream(validTypes).noneMatch(parameterType::isAssignable);
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AbstractGroovyElement method getGenericElement.
/**
* Get a generic element for the given element and data.
* @param sourceUnit The source unit
* @param type The type
* @param rawElement A raw element to fall back to
* @param genericsSpec The generics spec
* @return The element, never null.
*/
@NonNull
protected ClassElement getGenericElement(@NonNull SourceUnit sourceUnit, @NonNull ClassNode type, @NonNull ClassElement rawElement, @NonNull Map<String, ClassNode> genericsSpec) {
if (CollectionUtils.isNotEmpty(genericsSpec)) {
ClassElement classNode = resolveGenericType(genericsSpec, type);
if (classNode != null) {
return classNode;
} else {
GenericsType[] genericsTypes = type.getGenericsTypes();
GenericsType[] redirectTypes = type.redirect().getGenericsTypes();
if (genericsTypes != null && redirectTypes != null) {
genericsSpec = alignNewGenericsInfo(genericsTypes, redirectTypes, genericsSpec);
return new GroovyClassElement(visitorContext, type, annotationMetadata, Collections.singletonMap(type.getName(), genericsSpec), 0);
}
}
}
return rawElement;
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class GroovyVisitorContext method getClassElement.
@Override
public Optional<ClassElement> getClassElement(Class<?> type) {
final ClassNode classNode = ClassHelper.makeCached(type);
final AnnotationMetadata annotationMetadata = AstAnnotationUtils.getAnnotationMetadata(sourceUnit, compilationUnit, classNode);
final ClassElement classElement = groovyElementFactory.newClassElement(classNode, annotationMetadata);
return Optional.of(classElement);
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class JavaVisitorContext method populateClassElements.
private void populateClassElements(@NonNull String[] stereotypes, PackageElement packageElement, List<ClassElement> classElements) {
final List<? extends Element> enclosedElements = packageElement.getEnclosedElements();
boolean includeAll = Arrays.equals(stereotypes, new String[] { "*" });
for (Element enclosedElement : enclosedElements) {
if (enclosedElement instanceof TypeElement) {
final AnnotationMetadata annotationMetadata = annotationUtils.getAnnotationMetadata(enclosedElement);
if (includeAll || Arrays.stream(stereotypes).anyMatch(annotationMetadata::hasStereotype)) {
JavaClassElement classElement = elementFactory.newClassElement((TypeElement) enclosedElement, annotationMetadata);
if (!classElement.isAbstract()) {
classElements.add(classElement);
}
}
} else if (enclosedElement instanceof PackageElement) {
populateClassElements(stereotypes, (PackageElement) enclosedElement, classElements);
}
}
}
Aggregations