Пример #1
0
 static TclObject getArrayElts(
     Interp interp, // Current interpreter.
     Object arrayObj, // Array to dereference. Must be an array.
     Class arrayClass, // Class object of array to deref
     int index, // First elt to dereference.
     int count, // Number of elts to dereference.
     boolean convert) // Whether the values should be converted
     // into Tcl objects of the closest types.
     throws TclException // May encounter bad index.
     {
   TclObject resultListObj = TclList.newInstance();
   try {
     for (int i = 0; i < count; i++, index++) {
       TclList.append(
           interp, resultListObj, getArrayElt(interp, arrayObj, arrayClass, index, convert));
     }
   } catch (TclException e) {
     resultListObj.release();
     throw e;
   }
   return resultListObj;
 }
Пример #2
0
  private static Object dereferenceArrayDims(
      Interp interp, // Current
      // interpreter.
      Object arrayObj, // Array to dereference. Must be an array.
      int numDerefDims, // Number of dimensions to dereference.
      TclObject indexListObj) // Index to dereference in each dim.
      throws TclException // May encounter bad array index or
        // dereference a null array value.
      {
    // Before derefencing any dimensions, check that the indexList isn't too
    // large--we want to return an array.

    int numDims = JavaInfoCmd.getNumDimsFromClass(arrayObj.getClass());
    if (numDims < numDerefDims) {
      throw new TclException(
          interp,
          "bad indexList \""
              + indexListObj.toString()
              + "\": javaObj only has "
              + numDims
              + " dimension(s)");
    }

    Object subArrayObj = arrayObj;
    for (int dim = 0; dim < numDerefDims - 1; dim++) {

      int index = TclInteger.getInt(interp, TclList.index(interp, indexListObj, dim));
      try {
        subArrayObj = Array.get(subArrayObj, index);
      } catch (ArrayIndexOutOfBoundsException e) {
        int max = Array.getLength(subArrayObj) - 1;
        throw new TclException(
            interp, "array index \"" + index + "\" is out of bounds: must be between 0 and " + max);
      }
      if (subArrayObj == null) {
        throw new TclException(
            interp,
            "null value in dimension " + dim + ": can't dereference " + numDims + " dimensions");
      }
    }
    return subArrayObj;
  }