private boolean checkParameterCount(Node expr, Keywords keyword) { int paramCount = getCallParamCount(expr); if (paramCount < keyword.minParamCount) { warnMissingParam(keyword.name, expr); return false; } if (paramCount > keyword.maxParamCount) { warnExtraParam(keyword.name, expr); return false; } return true; }
private boolean checkParameterCount(Node expr, Keywords keyword) { int paramCount = getCallParamCount(expr); if (paramCount < keyword.minParamCount) { warnMissingParam(keyword.name, expr); return false; } if (paramCount > keyword.maxParamCount) { warnExtraParam(keyword.name, expr); return false; } return true; }
/** * A Union type expression must be a valid type variable or * a union(TTLExp, TTLExp, ...) */ private boolean validUnionTypeExpression(Node expr) { // The expression must have at least three children: The union keyword and // two type expressions if (!checkParameterCount(expr, Keywords.UNION)) { return false; } int paramCount = getCallParamCount(expr); // Check if each of the members of the union is a valid type expression for (int i = 0; i < paramCount; i++) { if (!validTypeTransformationExpression(getCallArgument(expr, i))) { warnInvalidInside("union type", expr); return false; } } return true; }
/** * A record type expression must be of the form: * record(RecordExp, RecordExp, ...) */ private boolean validRecordTypeExpression(Node expr) { // The expression must have at least two children. The record keyword and // a record expression if (!checkParameterCount(expr, Keywords.RECORD)) { return false; } // Each child must be a valid record for (int i = 0; i < getCallParamCount(expr); i++) { if (!validRecordParam(getCallArgument(expr, i))) { warnInvalidInside(Keywords.RECORD.name, expr); return false; } } return true; }
/** * A record type expression must be of the form: * record(RecordExp, RecordExp, ...) */ private boolean validRecordTypeExpression(Node expr) { // The expression must have at least two children. The record keyword and // a record expression if (!checkParameterCount(expr, Keywords.RECORD)) { return false; } // Each child must be a valid record for (int i = 0; i < getCallParamCount(expr); i++) { if (!validRecordParam(getCallArgument(expr, i))) { warnInvalidInside(Keywords.RECORD.name, expr); return false; } } return true; }
/** * A Union type expression must be a valid type variable or * a union(TTLExp, TTLExp, ...) */ private boolean validUnionTypeExpression(Node expr) { // The expression must have at least three children: The union keyword and // two type expressions if (!checkParameterCount(expr, Keywords.UNION)) { return false; } int paramCount = getCallParamCount(expr); // Check if each of the members of the union is a valid type expression for (int i = 0; i < paramCount; i++) { if (!validTypeTransformationExpression(getCallArgument(expr, i))) { warnInvalidInside("union type", expr); return false; } } return true; }
return validTypePredicate(expr, getCallParamCount(expr)); case STRING_PREDICATE: return validStringPredicate(expr, getCallParamCount(expr)); case TYPEVAR_PREDICATE: return validTypevarPredicate(expr, getCallParamCount(expr)); default: throw new IllegalStateException("Invalid boolean expression");
return validTypePredicate(expr, getCallParamCount(expr)); case STRING_PREDICATE: return validStringPredicate(expr, getCallParamCount(expr)); case TYPEVAR_PREDICATE: return validTypevarPredicate(expr, getCallParamCount(expr)); default: throw new IllegalStateException("Invalid boolean expression");
/** * A template type expression must be of the form type(typename, TTLExp,...) * or type(typevar, TTLExp...) */ private boolean validTemplateTypeExpression(Node expr) { // The expression must have at least three children the type keyword, // a type name (or type variable) and a type expression if (!checkParameterCount(expr, Keywords.TYPE)) { return false; } int paramCount = getCallParamCount(expr); // The first parameter must be a type variable or a type name Node firstParam = getCallArgument(expr, 0); if (!isTypeVar(firstParam) && !isTypeName(firstParam)) { warnInvalid("type name or type variable", expr); warnInvalidInside("template type operation", expr); return false; } // The rest of the parameters must be valid type expressions for (int i = 1; i < paramCount; i++) { if (!validTypeTransformationExpression(getCallArgument(expr, i))) { warnInvalidInside("template type operation", expr); return false; } } return true; }
/** * A template type expression must be of the form type(typename, TTLExp,...) * or type(typevar, TTLExp...) */ private boolean validTemplateTypeExpression(Node expr) { // The expression must have at least three children the type keyword, // a type name (or type variable) and a type expression if (!checkParameterCount(expr, Keywords.TYPE)) { return false; } int paramCount = getCallParamCount(expr); // The first parameter must be a type variable or a type name Node firstParam = getCallArgument(expr, 0); if (!isTypeVar(firstParam) && !isTypeName(firstParam)) { warnInvalid("type name or type variable", expr); warnInvalidInside("template type operation", expr); return false; } // The rest of the parameters must be valid type expressions for (int i = 1; i < paramCount; i++) { if (!validTypeTransformationExpression(getCallArgument(expr, i))) { warnInvalidInside("template type operation", expr); return false; } } return true; }