Search in sources :

Example 21 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation 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)

Example 22 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation in project Dyvil by Dyvil.

the class TypeParameterParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case ANNOTATIONS:
            switch(type) {
                case DyvilSymbols.AT:
                    final Annotation annotation = new CodeAnnotation(token.raw());
                    this.attributes.add(annotation);
                    pm.pushParser(new AnnotationParser(annotation));
                    return;
                case DyvilKeywords.TYPE:
                    // type IDENTIFIER
                    // type +IDENTIFIER
                    // type -IDENTIFIER
                    this.mode = VARIANCE;
                    return;
                case BaseSymbols.SEMICOLON:
                    if (token.isInferred()) {
                        return;
                    }
            }
            if (TypeParser.isGenericEnd(token, type)) {
                pm.popParser(true);
                return;
            }
        // Fallthrough
        case VARIANCE:
            {
                if (!Tokens.isIdentifier(type)) {
                    pm.report(token, "type_parameter.identifier");
                    return;
                }
                final Name name = token.nameValue();
                if (Tokens.isIdentifier(token.next().type())) {
                    if (name == Names.plus) {
                        this.mode = NAME;
                        this.variance = Variance.COVARIANT;
                        return;
                    }
                    if (name == Names.minus) {
                        this.mode = NAME;
                        this.variance = Variance.CONTRAVARIANT;
                        return;
                    }
                }
                this.createTypeParameter(token, this.variance);
                return;
            }
        case NAME:
            if (Tokens.isIdentifier(type)) {
                this.createTypeParameter(token, this.variance);
                return;
            }
            pm.report(token, "type_parameter.identifier");
            return;
        case TYPE_BOUNDS:
            switch(type) {
                case DyvilKeywords.EXTENDS:
                case BaseSymbols.COLON:
                    // type T: Super
                    // type T extends Super
                    pm.pushParser(this.newTypeParser());
                    this.setBoundMode(UPPER_BOUND);
                    return;
                case DyvilKeywords.SUPER:
                    pm.pushParser(this.newTypeParser());
                    this.setBoundMode(LOWER_BOUND);
                    return;
            }
            if (BaseSymbols.isTerminator(type) || TypeParser.isGenericEnd(token, type)) {
                if (this.typeParameter != null) {
                    this.typeParameterized.getTypeParameters().add(this.typeParameter);
                }
                pm.popParser(true);
                return;
            }
            if (this.typeParameter != null) {
                this.typeParameterized.getTypeParameters().add(this.typeParameter);
            }
            pm.popParser(true);
            pm.report(token, "type_parameter.bound.invalid");
    }
}
Also used : CodeAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation) AnnotationParser(dyvilx.tools.compiler.parser.annotation.AnnotationParser) CodeAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) Name(dyvil.lang.Name)

Example 23 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation in project Dyvil by Dyvil.

the class TupleExpr method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    final Annotation annotation = type.getAnnotation(LazyFields.TUPLE_CONVERTIBLE);
    if (annotation != null) {
        return new LiteralConversion(this, annotation, this.values).withType(type, typeContext, markers, context);
    }
    final int arity = this.values.size();
    final IClass tupleClass = TupleType.getTupleClass(arity);
    if (!Types.isSuperClass(type, tupleClass.getClassType())) {
        return null;
    }
    // reset type
    this.tupleType = null;
    final TypeParameterList typeParameters = typeParameters(tupleClass, arity);
    for (int i = 0; i < arity; i++) {
        final IType elementType = Types.resolveTypeSafely(type, typeParameters.get(i));
        final IValue value = TypeChecker.convertValue(this.values.get(i), elementType, typeContext, markers, context, LazyFields.ELEMENT_MARKER_SUPPLIER);
        this.values.set(i, value);
    }
    return this;
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) IType(dyvilx.tools.compiler.ast.type.IType)

Example 24 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation in project Dyvil by Dyvil.

the class CodeMethod method cleanup.

@Override
public void cleanup(ICompilableList compilableList, IClassCompilableList classCompilableList) {
    super.cleanup(compilableList, classCompilableList);
    final Annotation intrinsic = this.attributes.getAnnotation(Types.INTRINSIC_CLASS);
    if (intrinsic != null) {
        this.intrinsicData = Intrinsics.readAnnotation(this, intrinsic);
    }
    if (this.typeParameters != null) {
        this.typeParameters.cleanup(compilableList, classCompilableList);
    }
    if (this.thisType != null) {
        this.thisType.cleanup(compilableList, classCompilableList);
    }
    this.parameters.cleanup(compilableList, classCompilableList);
    if (this.exceptions != null) {
        this.exceptions.cleanup(compilableList, classCompilableList);
    }
    if (this.value != null) {
        this.value = this.value.cleanup(compilableList, classCompilableList);
    }
}
Also used : Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation)

Example 25 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation in project Dyvil by Dyvil.

the class IOverloadable method getOverloadPriority.

default int getOverloadPriority() {
    final Annotation annotation = this.getAnnotation(Types.OVERLOADPRIORITY_CLASS);
    if (annotation == null) {
        return 0;
    }
    final IValue value = annotation.getArguments().getFirst();
    return value == null ? OverloadPriority.DEFAULT_PRIORITY : value.intValue();
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation)

Aggregations

Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)25 IType (dyvilx.tools.compiler.ast.type.IType)10 ExternalAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation)9 CodeAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation)6 AnnotationParser (dyvilx.tools.compiler.parser.annotation.AnnotationParser)6 Name (dyvil.lang.Name)4 IValue (dyvilx.tools.compiler.ast.expression.IValue)4 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)4 AnnotationExpr (dyvilx.tools.compiler.ast.expression.AnnotationExpr)3 IToken (dyvilx.tools.parsing.token.IToken)3 Modifier (dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)2 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)2 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)2 ElementType (java.lang.annotation.ElementType)2 Reason (dyvil.annotation.Deprecated.Reason)1 Modifiers (dyvil.reflect.Modifiers)1 MarkerLevel (dyvil.util.MarkerLevel)1 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1