Java Code Examples for org.mozilla.javascript.Token#IN

The following examples show how to use org.mozilla.javascript.Token#IN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeErrorMessage.java    From SJS with Apache License 2.0 6 votes vote down vote up
public static TypeErrorMessage binaryOperatorMisuse(InfixExpression node, Type t1, Type t2, Type outType) {
    TypeErrorMessage msg = genericTypeError("misuse of binary operator " + AstNode.operatorToString(node.getOperator()) + " in \"" + shortSrc(node) + '"',
            locationOf(node));
    if (node.getOperator() == Token.IN) {
        if (!unconstrained(t1) && !Types.isEqual(t1, StringType.make())) {
            msg = msg.withNote("left operand has type " + describeType(t1) + " instead of " + StringType.make());
        }
        if (!unconstrained(t2) && !Types.isMapType(t2)) {
            msg = msg.withNote("right operand has type " + describeType(t2) + " instead of " + new MapType(new DefaultType()));
        }
    } else {
        if (!unconstrained(t1)) {
            msg = msg.withNote("left operand has type " + describeType(t1));
        }
        if (!unconstrained(t2)) {
            msg = msg.withNote("right operand has type " + describeType(t2));
        }
    }
    if (!unconstrained(outType)) {
        msg = msg.withNote("result type is " + describeType(outType));
    }
    return msg;
}
 
Example 2
Source File: ConstraintVisitor.java    From SJS with Apache License 2.0 4 votes vote down vote up
/**
 *  for infix expressions, we ignore implicit coercions for now. For arithmetic
 *  operators, we assume the type of the entire expression to be the same as that
 *  of either operand. For comparison operators, we require operands to have
 *  the same type, and assume that the result is a boolean. Note that Assignments
 *  are also InfixExpressions and that some property-get operations show up as
 *  InfixExpressions for which the operator is GETPROP.
 */
private ITypeTerm processInfixExpression(InfixExpression i) throws Error {
	int operator = i.getOperator();
	AstNode leftOperand = i.getLeft();
	AstNode rightOperand = i.getRight();
	ITypeTerm iTerm = findOrCreateExpressionTerm(i);
	switch (operator){
		case Token.GETPROP:
			return processPropertyGet(i, leftOperand, rightOperand);
		case Token.ASSIGN:
		case Token.ASSIGN_ADD:
		case Token.ASSIGN_SUB:
		case Token.ASSIGN_MUL:
		case Token.ASSIGN_DIV:
		case Token.ASSIGN_BITAND:
		case Token.ASSIGN_BITOR:
		case Token.ASSIGN_BITXOR:
		case Token.ASSIGN_RSH:
			processAssignment((Assignment)i);
		return iTerm;
		case Token.ADD:
           case Token.SUB:
           case Token.MUL:
           case Token.DIV:
           case Token.MOD:
           case Token.BITOR:
           case Token.EQ:
           case Token.LE:
           case Token.LT:
           case Token.NE:
           case Token.GT:
           case Token.GE:
           case Token.SHNE:
           case Token.SHEQ:
           case Token.AND:
           case Token.OR:
           case Token.BITAND:
           case Token.BITXOR:
           case Token.LSH:
           case Token.RSH:
           case Token.URSH:
           case Token.IN:
			ITypeTerm leftTerm = processExpression(leftOperand);
			ITypeTerm rightTerm = processExpression(rightOperand);
			OperatorTerm opTerm = findOrCreateOperatorTerm(RhinoToIR.decodeRhinoOperator(operator), leftTerm, rightTerm, i.getLineno());
			addTypeEqualityConstraint(iTerm, opTerm, i.getLineno(), (solution) -> binaryOperatorMisuse(i, solution.typeOfTerm(leftTerm), solution.typeOfTerm(rightTerm), solution.typeOfTerm(opTerm)));
			break;
		default:
			error("unexpected infix operator: " + operator + "(" + RhinoToIR.decodeRhinoOperator(operator) + ") in " + i.toSource(), i);
	}
	theMap.put(i, iTerm);
	return iTerm;
}