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
}
}
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
}
}
}
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--);
}
}
}
}
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()));
}
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);
}
Aggregations