Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.PreludeTypeConstants


        }

        ValueNode returnVN = null;
        TypeExpr typeExpr = getValueNode().getTypeExpr();
       
        PreludeTypeConstants typeConstants = valueEditorManager.getValueNodeBuilderHelper().getPreludeTypeConstants();
       
        if (typeExpr.sameType(typeConstants.getByteType())) {

            Double unRoundedVal = new Double(getDisplayField().getText());
            Byte byteVal = new Byte((byte) Math.round(unRoundedVal.doubleValue()));

            returnVN = new LiteralValueNode(byteVal, getValueNode().getTypeExpr());
           
        } else if (typeExpr.sameType(typeConstants.getShortType())) {

            Double unRoundedVal = new Double(getDisplayField().getText());
            Short shortVal = new Short((short) Math.round(unRoundedVal.doubleValue()));

            returnVN = new LiteralValueNode(shortVal, getValueNode().getTypeExpr());
           
        } else if (typeExpr.sameType(typeConstants.getIntType())) {

            Double unRoundedVal = new Double(getDisplayField().getText());
            Integer integerVal = new Integer((int) Math.round(unRoundedVal.doubleValue()));

            returnVN = new LiteralValueNode(integerVal, getValueNode().getTypeExpr());                              
           
        } else if (typeExpr.sameType(typeConstants.getIntegerType())) {

            BigDecimal unRoundedVal = new BigDecimal(getDisplayField().getText());
           
            // Ridiculously, BigDecimal has 8 rounding modes, not one of which is equivalent
            // to the mode used by Math.round!  ROUND_HALF_CEILING is what such a mode would
            // be called if it existed; we can fake it out by using a different rounding mode
            // depending upon the sign of the unrounded value.
            BigInteger bigIntegerVal;
           
            if(unRoundedVal.signum() >= 0) {
                bigIntegerVal = unRoundedVal.setScale(0, BigDecimal.ROUND_HALF_UP).toBigInteger();
            } else {
                bigIntegerVal = unRoundedVal.setScale(0, BigDecimal.ROUND_HALF_DOWN).toBigInteger();
            }

            returnVN = new LiteralValueNode(bigIntegerVal, getValueNode().getTypeExpr());                              
       
        } else if (typeExpr.sameType(typeConstants.getDecimalType())) {

            BigDecimal decimalVal = new BigDecimal(getDisplayField().getText());
            returnVN = new LiteralValueNode(decimalVal, getValueNode().getTypeExpr());

        } else if (typeExpr.sameType(typeConstants.getLongType())) {

            Double unRoundedVal = new Double(getDisplayField().getText());
            Long longVal = new Long(Math.round(unRoundedVal.doubleValue()));

            returnVN = new LiteralValueNode(longVal, getValueNode().getTypeExpr());
           
        } else if (typeExpr.sameType(typeConstants.getFloatType())) {

            Float floatVal = new Float(getDisplayField().getText());
            returnVN = new LiteralValueNode(floatVal, getValueNode().getTypeExpr());

        } else if (typeExpr.sameType(typeConstants.getDoubleType())) {

            Double doubleVal = new Double(getDisplayField().getText());
            returnVN = new LiteralValueNode(doubleVal, getValueNode().getTypeExpr());
                       
        } else {
View Full Code Here


         */
        @Override
        public boolean canHandleValue(ValueNode valueNode, SupportInfo providerSupportInfo) {
            TypeExpr typeExpr = valueNode.getTypeExpr();
           
            PreludeTypeConstants typeConstants = getValueEditorManager().getValueNodeBuilderHelper().getPreludeTypeConstants();
           
            // Integer and Decimal are not built-in types, so we cannot compare them to static
            // constants the way we can for the other types.
            return valueNode instanceof LiteralValueNode &&
                        (typeExpr.sameType(typeConstants.getByteType()) ||
                         typeExpr.sameType(typeConstants.getShortType()) ||
                         typeExpr.sameType(typeConstants.getIntType()) ||
                         typeExpr.sameType(typeConstants.getIntegerType()) ||
                         typeExpr.sameType(typeConstants.getDecimalType()) ||
                         typeExpr.sameType(typeConstants.getLongType()) ||
                         typeExpr.sameType(typeConstants.getFloatType()) ||
                         typeExpr.sameType(typeConstants.getDoubleType()));
        }
View Full Code Here

       
       
        // TODO: is there a more flexible way of doing this?
        //       Probably should use the ValueNodeBuilderHelper.
       
        PreludeTypeConstants preludeTypeConstants = calServices.getPreludeTypeConstants();
       
        if (value instanceof Character) {
            return new LiteralValueNode(value, preludeTypeConstants.getCharType());
        }
        else if (value instanceof Boolean) {
            return new LiteralValueNode(value, preludeTypeConstants.getBooleanType());
        }
        else if (value instanceof Byte) {
            return new LiteralValueNode(value, preludeTypeConstants.getByteType());
        }
        else if (value instanceof Short) {
            return new LiteralValueNode(value, preludeTypeConstants.getShortType());
        }
        else if (value instanceof Integer) {
            return new LiteralValueNode(value, preludeTypeConstants.getIntType());
        }
        else if (value instanceof Long) {
            return new LiteralValueNode(value, preludeTypeConstants.getLongType());
        }
        else if (value instanceof Float) {
            return new LiteralValueNode(value, preludeTypeConstants.getFloatType());
        }
        else if (value instanceof Double) {
            return new LiteralValueNode(value, preludeTypeConstants.getDoubleType());
        }
        else if (value instanceof String) {
            return new LiteralValueNode(value, preludeTypeConstants.getStringType());
        }
        else if (value instanceof Color) {       
            TypeExpr colourType = calServices.getTypeFromQualifiedName(CAL_Color.TypeConstructors.Color);
            if (colourType == null) {
                return null;
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.PreludeTypeConstants

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.