public void genConversionOperation( FixedPrecisionType type, Context ctx, TabbedWriter out, AsExpression arg) { Type toType = arg.getEType(); Type fromType = arg.getObjectExpr().getType(); if ((arg.getConversionOperation() != null) && TypeUtils.isNumericType(fromType)) { if (needsConversion(fromType, toType) && CommonUtilities.proceedWithConversion(ctx, arg.getConversionOperation())) { out.print(ctx.getNativeImplementationMapping(toType) + '.'); out.print(CommonUtilities.getOpName(ctx, arg.getConversionOperation())); out.print("("); Expression objectExpr = arg.getObjectExpr(); if (objectExpr instanceof BoxingExpression) { objectExpr = ((BoxingExpression) objectExpr).getExpr(); } ctx.invoke(genExpression, objectExpr, ctx, out); ctx.invoke(genTypeDependentOptions, arg.getEType(), ctx, out, arg); out.print(")"); } else { ctx.invoke(genExpression, arg.getObjectExpr(), ctx, out); } } else { // we need to invoke the logic in type template to call back to the other conversion // situations ctx.invokeSuper(this, genConversionOperation, type, ctx, out, arg); } }
protected boolean needsConversion(Operation conOp) { boolean result = true; Type fromType = conOp.getParameters().get(0).getType(); Type toType = conOp.getReturnType(); // don't convert matching types if (CommonUtilities.getEglNameForTypeCamelCase(toType) .equals(CommonUtilities.getEglNameForTypeCamelCase(fromType))) result = false; if (toType.getTypeSignature().equalsIgnoreCase("eglx.lang.ENumber")) result = true; else if (TypeUtils.isNumericType(fromType) && (TypeUtils.Type_DECIMAL.equals(fromType) || TypeUtils.Type_MONEY.equals(fromType))) result = conOp.isNarrowConversion(); return result; }
public void validate( Node errorNode, Node target, Element targetElement, Map<String, Object> allAnnotationsAndFields, IProblemRequestor problemRequestor, ICompilerOptions compilerOptions) { Type type = null; if (targetElement instanceof Type) { type = (Type) targetElement; } else if (targetElement instanceof TypedElement) { type = ((TypedElement) targetElement).getType(); } if (type == null) { return; } // Numerics cannot have decimals. if (type instanceof FixedPrecisionType) { if (((FixedPrecisionType) type).getDecimals() > 0) { problemRequestor.acceptProblem( errorNode, RUIResourceKeys.PROPERTY_INVALID_FOR_DECIMALS, IMarker.SEVERITY_ERROR, new String[] {IEGLConstants.PROPERTY_TIMEFORMAT}, RUIResourceKeys.getResourceBundleForKeys()); } return; } if (type instanceof ParameterizedType) { type = ((ParameterizedType) type).getParameterizableType(); } // string, time, and numerics are valid. everything else is invalid. if (TypeUtils.Type_STRING.equals(type) || TypeUtils.Type_TIME.equals(type) || TypeUtils.isNumericType(type)) { return; } problemRequestor.acceptProblem( errorNode, RUIResourceKeys.PROPERTY_INVALID_FOR_TYPE, IMarker.SEVERITY_ERROR, new String[] { IEGLConstants.PROPERTY_TIMEFORMAT, BindingUtil.getShortTypeString(type, false) }, RUIResourceKeys.getResourceBundleForKeys()); }
protected boolean needsConversion(Type fromType, Type toType) { boolean result = true; if (TypeUtils.isNumericType(fromType) && !CommonUtilities.needsConversion(fromType, toType)) result = !CommonUtilities.isJavaScriptBigDecimal(toType); return result; }