Package nexj.core.meta

Examples of nexj.core.meta.TypeMismatchException


      {
         long lValue;

         if (!(value instanceof Number))
         {
            throw new TypeMismatchException(getSymbol());
         }

         if (value instanceof Float || value instanceof Double)
         {
            Number num = (Number)value;

            lValue = num.longValue();

            if (lValue != num.doubleValue())
            {
               throw new TypeMismatchException(getSymbol());
            }
         }
         else if (value instanceof BigDecimal)
         {
            BigDecimal dec = (BigDecimal)value;

            if (dec.compareTo(dec.setScale(0, BigDecimal.ROUND_DOWN)) != 0)
            {
               throw new TypeMismatchException(getSymbol());
            }

            lValue = dec.longValue();
         }
         else
View Full Code Here


       */
      protected BigInteger getBigInteger(Object value)
      {
         if (!(value instanceof Number))
         {
            throw new TypeMismatchException(getSymbol());
         }

         if (value instanceof BigDecimal)
         {
            BigDecimal dec = (BigDecimal)value;

            if (dec.compareTo(dec.setScale(0, BigDecimal.ROUND_DOWN)) != 0)
            {
               throw new TypeMismatchException(getSymbol());
            }

            return dec.toBigInteger();
         }

         Number num = (Number)value;
         long lValue = num.longValue();

         if (lValue != num.doubleValue())
         {
            throw new TypeMismatchException(getSymbol());
         }

         return BigInteger.valueOf(lValue);
      }
View Full Code Here

            ObjectException e = (ObjectException)((ClassObject)machine.getArg(0, nArgCount)).createObject();
            Object err = machine.getArg(1, nArgCount);

            if (!(err instanceof String))
            {
               throw new TypeMismatchException("new");
            }

            Object[] argArray = null;
            Throwable cause = null;
View Full Code Here

         Object left = machine.getArg(0, nArgCount);

         if (!(left instanceof Character))
         {
            throw new TypeMismatchException(getSymbol());
         }

         char chLeft = ((Character)left).charValue();

         for (int i = 1; i < nArgCount; ++i)
         {
            Object right = machine.getArg(i, nArgCount);

            if (!(right instanceof Character))
            {
               throw new TypeMismatchException(getSymbol());
            }

            char chRight = ((Character)right).charValue();

            if (!cmp(chLeft, chRight))
View Full Code Here

         boolean bInexactLeft;
         int nOrdinal = 0;

         if (!(left instanceof Number))
         {
            throw new TypeMismatchException(getSymbol());
         }

         if (left instanceof Float || left instanceof Double)
         {
            Number num = (Number)left;

            lLeft = num.longValue();
            intLeft = null;
            bInexactLeft = true;
            nOrdinal = (left instanceof Float) ? Primitive.FLOAT_ORDINAL : Primitive.DOUBLE_ORDINAL;

            if (lLeft != num.doubleValue())
            {
               throw new TypeMismatchException(getSymbol());
            }
         }
         else if (left instanceof BigDecimal)
         {
            BigDecimal dec = (BigDecimal)left;

            if (dec.compareTo(dec.setScale(0, BigDecimal.ROUND_DOWN)) != 0)
            {
               throw new TypeMismatchException(getSymbol());
            }

            lLeft = 0;
            intLeft = dec.toBigInteger();
            bInexactLeft = (dec.scale() >= Primitive.MAX_SCALE);
            nOrdinal = Primitive.DECIMAL_ORDINAL;
         }
         else
         {
            lLeft = ((Number)left).longValue();
            intLeft = null;
            bInexactLeft = false;
            nOrdinal = (left instanceof Long) ? Primitive.LONG_ORDINAL : Primitive.INTEGER_ORDINAL;
         }

         BigInteger[] intResults = null;
         long[] lResults = null;
         int nResultCount = getResultCount();

         if (nResultCount > 1)
         {
            if (intLeft != null)
            {
               intResults = new BigInteger[nResultCount];
            }
            else
            {
               lResults = new long[nResultCount];
            }
         }

         if (nArgCount == 1)
         {
            if (intLeft != null)
            {
               if (nResultCount < 2)
               {
                  intLeft = getOneArgResult(intLeft)
               }
               else
               {
                  getOneArgResult(intLeft, intResults);
               }
            }
            else
            {
               if (nResultCount < 2)
               {
                  lLeft = getOneArgResult(lLeft);
               }
               else
               {
                  getOneArgResult(lLeft, lResults);
               }
            }
         }
         else
         {
            for (int i = 1; i < nArgCount; ++i)
            {
               long lRight = 0;
               BigInteger intRight = null;
               boolean bInexactRight;
               Object right = machine.getArg(i, nArgCount);

               if (right == null)
               {
                  machine.returnValue(null, nArgCount);
               }

               if (!(right instanceof Number))
               {
                  throw new TypeMismatchException(getSymbol());
               }

               if (right instanceof Float || right instanceof Double)
               {
                  Number num = (Number)right;

                  lRight = num.longValue();
                  intRight = null;
                  bInexactRight = true;
                  nOrdinal = Math.max(nOrdinal, (right instanceof Float) ? Primitive.FLOAT_ORDINAL : Primitive.DOUBLE_ORDINAL);

                  if (lRight != num.doubleValue())
                  {
                     throw new TypeMismatchException(getSymbol());
                  }
               }
               else if (right instanceof BigDecimal)
               {
                  BigDecimal dec = (BigDecimal)right;

                  if (dec.compareTo(dec.setScale(0, BigDecimal.ROUND_DOWN)) != 0)
                  {
                     throw new TypeMismatchException(getSymbol());
                  }

                  lRight = 0;
                  intRight = dec.toBigInteger();
                  bInexactRight = (dec.scale() >= Primitive.MAX_SCALE);
View Full Code Here

                        if (obj instanceof byte[])
                        {
                           if (!(value instanceof Number))
                           {
                              throw new TypeMismatchException(Symbol.BYTEVECTOR_U8_SET);
                           }

                           byte nValue = ((Number)value).byteValue();

                           ((byte[])obj)[i] = nValue;
View Full Code Here

                  case CAR:
                     value = m_stack[m_nTop - 1];

                     if (!(value instanceof Pair))
                     {
                        throw new TypeMismatchException(Symbol.CAR);
                     }

                     m_stack[m_nTop - 1] = ((Pair)value).getHead();

                     break;

                  case CDR:
                     value = m_stack[m_nTop - 1];

                     if (!(value instanceof Pair))
                     {
                        throw new TypeMismatchException(Symbol.CDR);
                     }

                     m_stack[m_nTop - 1] = ((Pair)value).getTail();

                     break;
View Full Code Here

           
            Object name = machine.getArg(0, nArgCount);
           
            if (!(name instanceof String))
            {
               throw new TypeMismatchException(getSymbol());
            }

            InvocationContext context = (InvocationContext)machine.getContext();
            PrimitivePrivilege privilege = context.getMetadata().getPrimitivePrivilege((String)name);
View Full Code Here

            Object classObj = machine.getArg(0, nArgCount);
            Object oidArray = machine.getArg(1, nArgCount);
           
            if (!(classObj instanceof Metaclass))
            {
               throw new TypeMismatchException(getSymbol());
            }
           
            InvocationContext context = (InvocationContext)machine.getContext();
            Metaclass metaclass = (Metaclass)classObj;
            Instance instance;

            if (oidArray != null)
            {
               OID oid;
              
               if (oidArray instanceof Object[])
               {
                  oid = new OID((Object[])oidArray);
               }
               else if (oidArray instanceof OID)
               {
                  oid = (OID)oidArray;
               }
               else
               {
                  throw new TypeMismatchException(getSymbol());
               }

               instance = context.findInstance(metaclass, oid);

               if (instance == null)
               {
                  instance = new Instance(metaclass, context);
                  instance.cache(oid);
               }
            }
            else
            {
               instance = new Instance(metaclass, context);
               instance.setNew();
            }

            for (int i = 2; i < nArgCount; ++i)
            {
               Object obj = machine.getArg(i, nArgCount);

               if (!(obj instanceof Pair))
               {
                  throw new TypeMismatchException(getSymbol());
               }

               Pair pair = (Pair)obj;
              
               if (!(pair.getHead() instanceof Symbol))
               {
                  throw new TypeMismatchException(getSymbol());
               }

               Attribute attribute = metaclass.getAttribute((Symbol)pair.getHead());

               if (attribute.isStatic())
View Full Code Here

            {
               Object instance = machine.getArg(i, nArgCount);

               if (!(instance instanceof Instance))
               {
                  throw new TypeMismatchException(getSymbol());
               }

               list.add(instance);
            }
View Full Code Here

TOP

Related Classes of nexj.core.meta.TypeMismatchException

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.