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