use of dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation in project Dyvil by Dyvil.
the class Deprecation method checkDeprecation.
private static void checkDeprecation(IMember member, SourcePosition position, MarkerList markers) {
Annotation annotation = member.getAnnotation(DEPRECATED_CLASS);
if (annotation == null) {
annotation = new ExternalAnnotation(DEPRECATED);
}
final ArgumentList arguments = annotation.getArguments();
final MarkerLevel markerLevel = AnnotationUtil.getEnumValue(arguments, DEP_LEVEL_PARAM, MarkerLevel.class);
if (markerLevel == null || markerLevel == MarkerLevel.IGNORE) {
return;
}
String value = AnnotationUtil.getStringValue(arguments, DEP_VALUE_PARAM);
final String description = AnnotationUtil.getStringValue(arguments, DEP_DESC_PARAM);
final String since = AnnotationUtil.getStringValue(arguments, DEP_SINCE_PARAM);
final String forRemoval = AnnotationUtil.getStringValue(arguments, DEP_UNTIL_PARAM);
value = replaceMember(member, value);
if (since != null) {
value = value.replace("{since}", since);
}
if (forRemoval != null) {
value = value.replace("{forRemoval}", forRemoval);
}
final Marker marker = Markers.withText(position, markerLevel, value);
assert marker != null;
// Description
if (description != null && !description.isEmpty()) {
marker.addInfo(Markers.getSemantic("deprecated.description", description));
}
// Since
if (since != null && !since.isEmpty()) {
marker.addInfo(Markers.getSemantic("deprecated.since", since));
}
if (forRemoval != null && !forRemoval.isEmpty()) {
marker.addInfo(Markers.getSemantic("deprecated.forRemoval", forRemoval));
}
// Until
// Reasons
final Reason[] reasons = getReasons(arguments);
if (reasons != null) {
final int reasonCount = reasons.length;
// more than one reason
if (reasonCount == 1) {
marker.addInfo(Markers.getSemantic("deprecated.reason", reasonName(reasons[0])));
} else if (reasonCount > 0) {
final StringBuilder builder = new StringBuilder(reasonName(reasons[0]));
for (int i = 1; i < reasonCount; i++) {
builder.append(", ").append(reasonName(reasons[i]));
}
marker.addInfo(Markers.getSemantic("deprecated.reasons", builder.toString()));
}
}
// Replacements
final String[] replacements = getReplacements(arguments);
if (replacements != null) {
for (String replacement : replacements) {
marker.addInfo("\t\t" + replacement);
}
marker.addInfo(Markers.getSemantic("deprecated.replacements"));
}
markers.add(marker);
}
Aggregations