findFirstAnnotation method
查找元素上的第一个指定类型的注解,返回 ConstantReader
Implementation
ConstantReader? findFirstAnnotation(Element element, Type type) {
final interceptChecker = TypeChecker.typeNamed(type);
for (final annotation in element.metadata.annotations) {
final constantValue = annotation.computeConstantValue();
if (constantValue == null) continue;
final annotationType = constantValue.type;
if (annotationType != null &&
interceptChecker.isAssignableFromType(annotationType)) {
return ConstantReader(constantValue);
}
}
return null;
}