use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class NullableType method withAnnotation.
@Override
public IType withAnnotation(Annotation annotation) {
switch(annotation.getTypeDescriptor()) {
case AnnotationUtil.NOTNULL_INTERNAL:
return this.type;
case AnnotationUtil.NULLABLE_INTERNAL:
return this;
}
final IType withAnnotation = this.type.withAnnotation(annotation);
if (withAnnotation == null) {
return null;
}
this.type = withAnnotation;
return this;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class ResolvedGenericType method checkType.
@Override
public void checkType(MarkerList markers, IContext context, int position) {
ModifierUtil.checkVisibility(this.theClass, this.position, markers, context);
// Check if the Type Variable Bounds accept the supplied Type Arguments
final int count = Math.min(this.arguments.size(), this.theClass.typeArity());
final TypeParameterList classTypeParams = this.theClass.getTypeParameters();
for (int i = 0; i < count; i++) {
final ITypeParameter typeParameter = classTypeParams.get(i);
final IType typeArgument = this.resolveType(typeParameter);
if (typeArgument.isResolved() && !typeParameter.isAssignableFrom(typeArgument, null)) {
final Marker marker = Markers.semanticError(typeArgument.getPosition(), "type.generic.incompatible", typeParameter.getName().qualified, this.theClass.getFullName());
marker.addInfo(Markers.getSemantic("type.generic.argument", typeArgument));
marker.addInfo(Markers.getSemantic("type_parameter.declaration", typeParameter));
markers.add(marker);
}
}
if ((position & TypePosition.GENERIC_FLAG) == 0) {
markers.add(Markers.semanticError(this.position, "type.generic.class"));
}
super.checkType(markers, context, position);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class NamedType method resolveTopLevel.
private IType resolveTopLevel(MarkerList markers, IContext context) {
final IType primitive = Types.resolvePrimitive(this.name);
if (primitive != null) {
return primitive.atPosition(this.position);
}
IType type = this.resolveTopLevelWith(markers, context);
if (type != null) {
return type;
}
type = this.resolveTopLevelWith(markers, Types.BASE_CONTEXT);
if (type != null) {
return type;
}
if (markers == null) {
// FieldAccess support
return null;
}
markers.add(Markers.semanticError(this.position, "resolve.type", this.name));
return this;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class NamedType method resolveTopLevelWith.
private IType resolveTopLevelWith(@SuppressWarnings("UnusedParameters") MarkerList markers, IContext context) {
final MatchList<ITypeAlias> typeAliases = IContext.resolveTypeAlias(context, null, this.name, TypeList.EMPTY);
if (typeAliases.hasCandidate()) {
final ITypeAlias typeAlias = typeAliases.getBestMember();
final IType type = typeAlias.getType();
if (!type.isResolved() && markers != null) {
markers.add(Markers.semanticError(this.position, "type.alias.unresolved", this.name));
return type.atPosition(this.position);
}
return type.getConcreteType(ITypeContext.DEFAULT).atPosition(this.position);
}
final IClass theClass = context.resolveClass(this.name);
if (theClass != null) {
return new ResolvedClassType(theClass, this.position);
}
final ITypeParameter typeParameter = context.resolveTypeParameter(this.name);
if (typeParameter != null) {
return new ResolvedTypeVarType(typeParameter, this.position);
}
final Package thePackage = context.resolvePackage(this.name);
if (thePackage != null) {
return new PackageType(thePackage).atPosition(this.position);
}
return null;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class TypeAlias method checkMatch.
// Resolution
@Override
public void checkMatch(MatchList<ITypeAlias> matches, IType receiver, Name name, TypeList arguments) {
if (name != this.name && name != null) {
return;
}
if (arguments == null) {
matches.add(new Candidate<>(this));
return;
}
final int size = arguments.size();
if (size != this.typeArity()) {
matches.add(new Candidate<>(this, true));
return;
}
final int[] matchValues = new int[size];
final IType[] matchTypes = new IType[size];
boolean invalid = false;
for (int i = 0; i < size; i++) {
final IType bound = this.typeParameters.get(i).getUpperBound();
final IType argument = arguments.get(i);
final int match = Types.getTypeMatch(bound, argument);
if (match == IValue.MISMATCH) {
invalid = true;
}
matchValues[i] = match;
matchTypes[i] = bound;
}
matches.add(new Candidate<>(this, matchValues, matchTypes, 0, 0, invalid));
}
Aggregations