public static DSLExpression parse(InputStream input) { Parser parser = new Parser(input); DSLExpression result = parser.parseImpl(); if (parser.errors.errors.size() > 0) { StringBuilder msg = new StringBuilder(); for (String error : parser.errors.errors) { msg.append(error).append("\n"); } throw new InvalidExpressionException(msg.toString()); } return result; }
public static DSLExpression parse(InputStream input) { Parser parser = new Parser(input); DSLExpression result = parser.parseImpl(); if (parser.errors.errors.size() > 0) { StringBuilder msg = new StringBuilder(); for (String error : parser.errors.errors) { msg.append(error).append("\n"); } throw new InvalidExpressionException(msg.toString()); } return result; }
public void visitNegate(Negate negate) { TypeMirror booleanType = context.getType(boolean.class); TypeMirror resolvedType = negate.getResolvedType(); if (!ElementUtils.typeEquals(resolvedType, booleanType)) { throw new InvalidExpressionException(String.format("The operator %s is undefined for the argument type %s.", "!", ElementUtils.getSimpleName(resolvedType))); } }
public void visitNegate(Negate negate) { TypeMirror booleanType = context.getType(boolean.class); TypeMirror resolvedType = negate.getResolvedType(); if (!ElementUtils.typeEquals(resolvedType, booleanType)) { throw new InvalidExpressionException(String.format("The operator %s is undefined for the argument type %s.", "!", ElementUtils.getSimpleName(resolvedType))); } }
public void visitBinary(Binary binary) { String operator = binary.getOperator(); TypeMirror leftType = binary.getLeft().getResolvedType(); TypeMirror rightType = binary.getRight().getResolvedType(); if (!ElementUtils.areTypesCompatible(leftType, rightType)) { throw new InvalidExpressionException(String.format("Incompatible operand types %s and %s.", ElementUtils.getSimpleName(leftType), ElementUtils.getSimpleName(rightType))); } TypeMirror booleanType = context.getType(boolean.class); boolean valid; if (LOGIC_OPERATORS.contains(operator)) { valid = ElementUtils.typeEquals(leftType, booleanType); } else if (COMPARABLE_OPERATORS.contains(operator)) { valid = ElementUtils.isPrimitive(leftType); } else if (IDENTITY_OPERATORS.contains(operator)) { valid = leftType.getKind().isPrimitive() || leftType.getKind() == TypeKind.DECLARED || leftType.getKind() == TypeKind.ARRAY; } else { throw new InvalidExpressionException(String.format("The operator %s is undefined.", operator)); } binary.setResolvedType(booleanType); if (!valid) { throw new InvalidExpressionException(String.format("The operator %s is undefined for the argument type(s) %s %s.", operator, ElementUtils.getSimpleName(leftType), ElementUtils.getSimpleName(rightType))); } }
public void visitBinary(Binary binary) { String operator = binary.getOperator(); TypeMirror leftType = binary.getLeft().getResolvedType(); TypeMirror rightType = binary.getRight().getResolvedType(); if (!ElementUtils.areTypesCompatible(leftType, rightType)) { throw new InvalidExpressionException(String.format("Incompatible operand types %s and %s.", ElementUtils.getSimpleName(leftType), ElementUtils.getSimpleName(rightType))); } TypeMirror booleanType = context.getType(boolean.class); boolean valid; if (LOGIC_OPERATORS.contains(operator)) { valid = ElementUtils.typeEquals(leftType, booleanType); } else if (COMPARABLE_OPERATORS.contains(operator)) { valid = ElementUtils.isPrimitive(leftType); } else if (IDENTITY_OPERATORS.contains(operator)) { valid = leftType.getKind().isPrimitive() || leftType.getKind() == TypeKind.DECLARED || leftType.getKind() == TypeKind.ARRAY; } else { throw new InvalidExpressionException(String.format("The operator %s is undefined.", operator)); } binary.setResolvedType(booleanType); if (!valid) { throw new InvalidExpressionException(String.format("The operator %s is undefined for the argument type(s) %s %s.", operator, ElementUtils.getSimpleName(leftType), ElementUtils.getSimpleName(rightType))); } }
public void visitIntLiteral(IntLiteral binary) { try { binary.setResolvedType(context.getType(int.class)); final int base; final String literal; if (binary.getLiteral().startsWith("0x")) { base = 16; literal = binary.getLiteral().substring(2); } else if (binary.getLiteral().startsWith("0b")) { base = 2; literal = binary.getLiteral().substring(2); } else if (binary.getLiteral().startsWith("0")) { base = 8; literal = binary.getLiteral(); } else { base = 10; literal = binary.getLiteral(); } binary.setResolvedValueInt(Integer.parseInt(literal, base)); } catch (NumberFormatException e) { throw new InvalidExpressionException(String.format("Type mismatch: cannot convert from String '%s' to int", binary.getLiteral())); } }
public void visitIntLiteral(IntLiteral binary) { try { binary.setResolvedType(context.getType(int.class)); final int base; final String literal; if (binary.getLiteral().startsWith("0x")) { base = 16; literal = binary.getLiteral().substring(2); } else if (binary.getLiteral().startsWith("0b")) { base = 2; literal = binary.getLiteral().substring(2); } else if (binary.getLiteral().startsWith("0")) { base = 8; literal = binary.getLiteral(); } else { base = 10; literal = binary.getLiteral(); } binary.setResolvedValueInt(Integer.parseInt(literal, base)); } catch (NumberFormatException e) { throw new InvalidExpressionException(String.format("Type mismatch: cannot convert from String '%s' to int", binary.getLiteral())); } }
if (foundWithName == null) { throw new InvalidExpressionException(String.format("The method %s is undefined for the enclosing scope.", call.getName())); } else { StringBuilder arguments = new StringBuilder(); throw new InvalidExpressionException(String.format("The method %s in the type %s is not applicable for the arguments %s.", //
throw new InvalidExpressionException(String.format("%s cannot be resolved.", variable.getName()));
if (foundWithName == null) { throw new InvalidExpressionException(String.format("The method %s is undefined for the enclosing scope.", call.getName())); } else { StringBuilder arguments = new StringBuilder(); throw new InvalidExpressionException(String.format("The method %s in the type %s is not applicable for the arguments %s.", //
throw new InvalidExpressionException(String.format("%s cannot be resolved.", variable.getName()));