Search in sources :

Example 11 with Marker

use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.

the class CodeTypeParameter method resolveTypes.

@Override
public void resolveTypes(MarkerList markers, IContext context) {
    this.attributes.resolveTypes(markers, context, this);
    if (this.lowerBound != null) {
        this.lowerBound = this.lowerBound.resolveType(markers, context);
    }
    this.upperBound = this.upperBound.resolveType(markers, context);
    this.upperBounds = getUpperBounds(this.upperBound);
    // The first upper bound is meant to be a class bound.
    IType type = this.upperBounds[0];
    IClass typeClass = type.getTheClass();
    if (typeClass != null && !typeClass.isInterface()) {
        // If the first type is a class type (not an interface), it becomes the erasure type.
        this.erasure = type;
    }
    // Check if the remaining upper bounds are interfaces
    for (int i = 1, count = this.upperBounds.length; i < count; i++) {
        type = this.upperBounds[i];
        typeClass = type.getTheClass();
        if (typeClass != null && !typeClass.isInterface()) {
            final Marker marker = Markers.semanticError(type.getPosition(), "type_parameter.bound.class");
            marker.addInfo(Markers.getSemantic("class.declaration", Util.classSignatureToString(typeClass)));
            markers.add(marker);
        }
    }
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 12 with Marker

use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.

the class OperatorElement method checkPosition.

public static void checkPosition(MarkerList markers, SourcePosition position, IOperator operator, byte expectedType) {
    if (!operator.isType(expectedType)) {
        final Marker marker = Markers.semantic(position, "operator.invalid_position", operator.getName(), typeToString(operator.getType()), typeToString(expectedType));
        marker.addInfo(Markers.getSemantic("operator.declaration", operator.toString()));
        markers.add(marker);
    }
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker)

Example 13 with Marker

use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.

the class Deprecation method checkUsageInfo.

private static void checkUsageInfo(IMember member, SourcePosition position, MarkerList markers, Annotation annotation) {
    final ArgumentList arguments = annotation.getArguments();
    final MarkerLevel markerLevel = AnnotationUtil.getEnumValue(arguments, INF_LEVEL_PARAM, MarkerLevel.class);
    if (markerLevel == null || markerLevel == MarkerLevel.IGNORE) {
        return;
    }
    String value = AnnotationUtil.getStringValue(arguments, INF_VALUE_PARAM);
    final String description = AnnotationUtil.getStringValue(arguments, INF_DESC_PARAM);
    value = replaceMember(member, value);
    final Marker marker = Markers.withText(position, markerLevel, value);
    assert marker != null;
    // Description
    if (description != null && !description.isEmpty()) {
        marker.addInfo(Markers.getSemantic("experimental.description", description));
    }
    markers.add(marker);
}
Also used : MarkerLevel(dyvil.util.MarkerLevel) Marker(dyvilx.tools.parsing.marker.Marker) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Example 14 with Marker

use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.

the class CodeConstructor method check.

@Override
public void check(MarkerList markers, IContext context) {
    context = context.push(this);
    super.check(markers, context);
    this.parameters.check(markers, context);
    if (this.exceptions != null) {
        for (int i = 0; i < this.exceptions.size(); i++) {
            final IType exceptionType = this.exceptions.get(i);
            exceptionType.check(markers, context);
            if (!Types.isSuperType(Types.THROWABLE, exceptionType)) {
                final Marker marker = Markers.semanticError(exceptionType.getPosition(), "method.exception.type");
                marker.addInfo(Markers.getSemantic("exception.type", exceptionType));
                markers.add(marker);
            }
        }
    }
    if (this.initializerCall != null) {
        this.initializerCall.check(markers, context);
    }
    if (this.value != null) {
        this.value.check(markers, this);
    } else if (this.initializerCall == null) {
        markers.add(Markers.semanticError(this.position, "constructor.abstract"));
    }
    if (this.isStatic()) {
        markers.add(Markers.semanticError(this.position, "constructor.static", this.name));
    }
    context.pop();
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 15 with Marker

use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.

the class CodeAnnotation method check.

@Override
public void check(MarkerList markers, IContext context, ElementType target) {
    super.check(markers, context, target);
    if (this.type == null || !this.type.isResolved()) {
        return;
    }
    final IClass theClass = this.type.getTheClass();
    if (theClass == null) {
        return;
    }
    if (!theClass.isAnnotation()) {
        markers.add(Markers.semanticError(this.position, "annotation.type", this.type.getName()));
        return;
    }
    if (target == null) {
        return;
    }
    final IClassMetadata metadata = theClass.getMetadata();
    if (!metadata.isTarget(target)) {
        final Marker error = Markers.semanticError(this.position, "annotation.target", this.type.getName());
        error.addInfo(Markers.getSemantic("annotation.target.element", target));
        error.addInfo(Markers.getSemantic("annotation.target.allowed", metadata.getTargets()));
        markers.add(error);
    }
}
Also used : IClassMetadata(dyvilx.tools.compiler.ast.classes.metadata.IClassMetadata) IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker)

Aggregations

Marker (dyvilx.tools.parsing.marker.Marker)46 IType (dyvilx.tools.compiler.ast.type.IType)23 IClass (dyvilx.tools.compiler.ast.classes.IClass)11 IValue (dyvilx.tools.compiler.ast.expression.IValue)7 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)4 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)4 NonNull (dyvil.annotation.internal.NonNull)3 Name (dyvil.lang.Name)3 MarkerLevel (dyvil.util.MarkerLevel)3 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)3 Pattern (dyvilx.tools.compiler.ast.pattern.Pattern)3 TypeList (dyvilx.tools.compiler.ast.type.TypeList)3 SourcePosition (dyvil.source.position.SourcePosition)2 IContext (dyvilx.tools.compiler.ast.context.IContext)2 ITypeContext (dyvilx.tools.compiler.ast.generic.ITypeContext)2 AbstractPattern (dyvilx.tools.compiler.ast.pattern.AbstractPattern)2 Types (dyvilx.tools.compiler.ast.type.builtin.Types)2 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)2 Markers (dyvilx.tools.compiler.util.Markers)2 MarkerList (dyvilx.tools.parsing.marker.MarkerList)2