use of kalang.core.FieldDescriptor in project kalang by kasonyang.
the class SemanticAnalyzer method validateAssign.
public boolean validateAssign(AssignableExpr to, ExprNode from, OffsetRange offset) {
if (to instanceof VarExpr) {
LocalVarNode varObject = ((VarExpr) to).getVar();
if (Modifier.isFinal(varObject.modifier)) {
this.diagnosisReporter.report(Diagnosis.Kind.ERROR, String.format("%s is readonly", varObject.getName()), offset);
return false;
}
} else if (to instanceof FieldExpr) {
FieldDescriptor field = ((FieldExpr) to).getField();
if (Modifier.isFinal(field.getModifier())) {
this.diagnosisReporter.report(Diagnosis.Kind.ERROR, String.format("%s is readonly", field.getName()), offset);
return false;
}
}
Type toType = to.getType();
Type fromType = from.getType();
if (!toType.isAssignableFrom(fromType)) {
diagnosisReporter.report(Diagnosis.Kind.ERROR, String.format("incompatible types: %s cannot be converted to %s", fromType, toType), offset);
return false;
}
return true;
}
use of kalang.core.FieldDescriptor in project kalang by kasonyang.
the class ObjectFieldExpr method create.
@Nonnull
public static FieldExpr create(@Nonnull ExprNode target, String fieldName, @Nullable ClassNode caller) throws FieldNotFoundException {
Type type = target.getType();
if (!(type instanceof ObjectType)) {
throw new UnsupportedOperationException("unsupported type:" + type);
}
ObjectType classType = (ObjectType) type;
FieldDescriptor field = getField(classType, fieldName, caller);
if (AstUtil.isStatic(field.getModifier())) {
throw new FieldNotFoundException(fieldName + " is static");
}
return new ObjectFieldExpr(target, field);
}
Aggregations