Search in sources :

Example 6 with Annotation

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

the class AnnotationMetadata method readRetention.

private void readRetention() {
    final Annotation retention = this.theClass.getAnnotation(Annotation.LazyFields.RETENTION_CLASS);
    if (retention == null) {
        return;
    }
    final IValue value = retention.getArguments().get(0, Names.value);
    if (!(value instanceof EnumValue)) {
        return;
    }
    try {
        final String name = ((EnumValue) value).getName().qualified;
        this.retention = RetentionPolicy.valueOf(name);
    } catch (IllegalArgumentException ignored) {
    // Problematic RetentionPolicy annotation - do not handle this
    }
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) EnumValue(dyvilx.tools.compiler.ast.expression.constant.EnumValue) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation)

Example 7 with Annotation

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

the class AnnotationMetadata method readTargets.

private void readTargets() {
    final Annotation target = this.theClass.getAnnotation(Annotation.LazyFields.TARGET_CLASS);
    if (target == null) {
        return;
    }
    this.targets = EnumSet.noneOf(ElementType.class);
    final IValue argument = target.getArguments().get(0, Names.value);
    if (!(argument instanceof ArrayExpr)) {
        return;
    }
    final ArgumentList values = ((ArrayExpr) argument).getValues();
    final int size = values.size();
    for (int i = 0; i < size; i++) {
        final INamed value = (INamed) values.get(i);
        try {
            this.targets.add(ElementType.valueOf(value.getName().qualified));
        } catch (IllegalArgumentException ignored) {
        // Problematic Target annotation - do not handle this
        }
    }
}
Also used : ElementType(java.lang.annotation.ElementType) ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) IValue(dyvilx.tools.compiler.ast.expression.IValue) INamed(dyvilx.tools.compiler.ast.member.INamed) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation)

Example 8 with Annotation

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

the class AttributeList method resolveTypes.

// Phases
public void resolveTypes(MarkerList markers, IContext context, Attributable annotated) {
    for (int i = 0; i < this.size; i++) {
        final Attribute attribute = this.data[i];
        attribute.resolveTypes(markers, context);
        final IType type = attribute.getType();
        if (type != null) {
            final String internalName = type.getInternalName();
            if (internalName != null && annotated.skipAnnotation(internalName, (Annotation) attribute)) {
                this.removeAt(i--);
            }
        }
    }
}
Also used : Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) IType(dyvilx.tools.compiler.ast.type.IType)

Example 9 with Annotation

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

the class AbstractMethod method checkMutating.

private void checkMutating(MarkerList markers, IValue receiver) {
    final IType receiverType = receiver.getType();
    if (receiverType.getMutability() != Mutability.IMMUTABLE) {
        return;
    }
    final Annotation mutatingAnnotation = this.getAnnotation(Types.MUTATING_CLASS);
    if (mutatingAnnotation == null) {
        return;
    }
    final IValue value = mutatingAnnotation.getArguments().get(0, Names.value);
    final String stringValue = value != null ? value.stringValue() : Mutating.DEFAULT_MESSAGE;
    StringBuilder builder = new StringBuilder(stringValue);
    int index = builder.indexOf("{method}");
    if (index >= 0) {
        builder.replace(index, index + 8, this.name.unqualified);
    }
    index = builder.indexOf("{type}");
    if (index >= 0) {
        builder.replace(index, index + 6, receiverType.toString());
    }
    markers.add(new SemanticError(receiver.getPosition(), builder.toString()));
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) SemanticError(dyvilx.tools.parsing.marker.SemanticError) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) IType(dyvilx.tools.compiler.ast.type.IType)

Example 10 with Annotation

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

the class IParameter method visitAnnotation.

default AnnotationVisitor visitAnnotation(String internalType) {
    if (this.skipAnnotation(internalType, null)) {
        return null;
    }
    IType type = new InternalType(internalType);
    Annotation annotation = new ExternalAnnotation(type);
    return new AnnotationReader(this, annotation);
}
Also used : InternalType(dyvilx.tools.compiler.ast.type.raw.InternalType) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) AnnotationReader(dyvilx.tools.compiler.backend.visitor.AnnotationReader) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) IType(dyvilx.tools.compiler.ast.type.IType)

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