Search in sources :

Example 1 with NumericType

use of com.robotoworks.mechanoid.net.netModel.NumericType in project mechanoid by robotoworks.

the class NetModelJavaValidator method checkValueAssignment.

@Check
public void checkValueAssignment(SimpleMemberAssignment assignment) {
    IntrinsicType type = assignment.getMember().getType();
    Literal defaultValue = assignment.getDefaultValue();
    if (defaultValue == null) {
        return;
    }
    if (type instanceof StringType) {
        if (!(defaultValue instanceof StringLiteral)) {
            error("Type mismatch", NetModelPackage.Literals.SIMPLE_MEMBER_ASSIGNMENT__DEFAULT_VALUE);
        }
    } else if (type instanceof BooleanType) {
        if (!(defaultValue instanceof BooleanLiteral)) {
            error("Type mismatch", NetModelPackage.Literals.SIMPLE_MEMBER_ASSIGNMENT__DEFAULT_VALUE);
        }
    // TODO Check each numeric type (double, integer, long, etc)
    } else if (type instanceof NumericType) {
        if (!(defaultValue instanceof NumericLiteral)) {
            error("Type mismatch", NetModelPackage.Literals.SIMPLE_MEMBER_ASSIGNMENT__DEFAULT_VALUE);
        }
    }
}
Also used : NumericType(com.robotoworks.mechanoid.net.netModel.NumericType) IntrinsicType(com.robotoworks.mechanoid.net.netModel.IntrinsicType) StringLiteral(com.robotoworks.mechanoid.net.netModel.StringLiteral) NumericLiteral(com.robotoworks.mechanoid.net.netModel.NumericLiteral) StringType(com.robotoworks.mechanoid.net.netModel.StringType) BooleanLiteral(com.robotoworks.mechanoid.net.netModel.BooleanLiteral) ComplexTypeLiteral(com.robotoworks.mechanoid.net.netModel.ComplexTypeLiteral) StringLiteral(com.robotoworks.mechanoid.net.netModel.StringLiteral) BooleanLiteral(com.robotoworks.mechanoid.net.netModel.BooleanLiteral) NumericLiteral(com.robotoworks.mechanoid.net.netModel.NumericLiteral) Literal(com.robotoworks.mechanoid.net.netModel.Literal) BooleanType(com.robotoworks.mechanoid.net.netModel.BooleanType) Check(org.eclipse.xtext.validation.Check)

Aggregations

BooleanLiteral (com.robotoworks.mechanoid.net.netModel.BooleanLiteral)1 BooleanType (com.robotoworks.mechanoid.net.netModel.BooleanType)1 ComplexTypeLiteral (com.robotoworks.mechanoid.net.netModel.ComplexTypeLiteral)1 IntrinsicType (com.robotoworks.mechanoid.net.netModel.IntrinsicType)1 Literal (com.robotoworks.mechanoid.net.netModel.Literal)1 NumericLiteral (com.robotoworks.mechanoid.net.netModel.NumericLiteral)1 NumericType (com.robotoworks.mechanoid.net.netModel.NumericType)1 StringLiteral (com.robotoworks.mechanoid.net.netModel.StringLiteral)1 StringType (com.robotoworks.mechanoid.net.netModel.StringType)1 Check (org.eclipse.xtext.validation.Check)1