Search in sources :

Example 6 with ExternalAnnotation

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);
}
Also used : ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) MarkerLevel(dyvil.util.MarkerLevel) Marker(dyvilx.tools.parsing.marker.Marker) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) Reason(dyvil.annotation.Deprecated.Reason)

Aggregations

Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)6 ExternalAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation)6 AnnotationExpr (dyvilx.tools.compiler.ast.expression.AnnotationExpr)3 Reason (dyvil.annotation.Deprecated.Reason)1 MarkerLevel (dyvil.util.MarkerLevel)1 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)1 IType (dyvilx.tools.compiler.ast.type.IType)1 InternalType (dyvilx.tools.compiler.ast.type.raw.InternalType)1 AnnotationReader (dyvilx.tools.compiler.backend.visitor.AnnotationReader)1 Marker (dyvilx.tools.parsing.marker.Marker)1