示例#1
0
文件: Path.java 项目: runeengh/basex
  @Override
  public final Expr compile(final QueryContext qc, final VarScope scp) throws QueryException {
    if (root != null) root = root.compile(qc, scp);
    // no steps
    if (steps.length == 0) return root == null ? new Context(info) : root;

    final Value init = qc.value, cv = initial(qc);
    final boolean doc = cv != null && cv.type == NodeType.DOC;
    qc.value = cv;
    try {
      final int sl = steps.length;
      for (int s = 0; s < sl; s++) {
        Expr e = steps[s];

        // axis step: if input is a document, its type is temporarily generalized
        final boolean as = e instanceof Step;
        if (as && s == 0 && doc) cv.type = NodeType.NOD;

        e = e.compile(qc, scp);
        if (e.isEmpty()) return optPre(qc);
        steps[s] = e;

        // no axis step: invalidate context value
        if (!as) qc.value = null;
      }
    } finally {
      if (doc) cv.type = NodeType.DOC;
      qc.value = init;
    }
    // optimize path
    return optimize(qc, scp);
  }
示例#2
0
 private static Register create(Value constant) {
   Register result = Register.createConstant(next--, constant.type());
   constants.put(constant, result);
   values.add(constant);
   Trace.trace(Item.COMPILER, "Acquire new constant, %s = %s", result, constant);
   return result;
 }
  private static SourcePosition calcPosition(
      final ValueDescriptor descriptor, final DebugProcessImpl debugProcess)
      throws ClassNotLoadedException {
    final Value value = descriptor.getValue();
    if (value == null) {
      return null;
    }

    Type type = value.type();
    if (type == null) {
      return null;
    }

    try {
      if (type instanceof ArrayType) {
        type = ((ArrayType) type).componentType();
      }
      if (type instanceof ClassType) {
        final ClassType clsType = (ClassType) type;
        final List<Location> locations = clsType.allLineLocations();
        if (locations.size() > 0) {
          final Location location = locations.get(0);
          return ApplicationManager.getApplication()
              .runReadAction(
                  new Computable<SourcePosition>() {
                    @Override
                    public SourcePosition compute() {
                      SourcePosition position =
                          debugProcess.getPositionManager().getSourcePosition(location);
                      // adjust position for non-anonymous classes
                      if (clsType.name().indexOf('$') < 0) {
                        final PsiClass classAt =
                            position != null ? JVMNameUtil.getClassAt(position) : null;
                        if (classAt != null) {
                          final SourcePosition classPosition =
                              SourcePosition.createFromElement(classAt);
                          if (classPosition != null) {
                            position = classPosition;
                          }
                        }
                      }
                      return position;
                    }
                  });
        }
      }
    } catch (ClassNotPreparedException e) {
      LOG.debug(e);
    } catch (AbsentInformationException e) {
      LOG.debug(e);
    }
    return null;
  }
示例#4
0
  @SuppressWarnings({"HardCodedStringLiteral"})
  public static boolean isCharOrIntegerArray(Value value) {
    if (value == null) return false;
    if (myCharOrIntegers == null) {
      myCharOrIntegers = new HashSet<String>();
      myCharOrIntegers.add("C");
      myCharOrIntegers.add("B");
      myCharOrIntegers.add("S");
      myCharOrIntegers.add("I");
      myCharOrIntegers.add("J");
    }

    String signature = value.type().signature();
    int i;
    for (i = 0; signature.charAt(i) == '['; i++) ;
    if (i == 0) return false;
    signature = signature.substring(i, signature.length());
    return myCharOrIntegers.contains(signature);
  }
示例#5
0
 @Override
 protected JsonArray serve(String filter, int limit) {
   JsonArray array = new JsonArray();
   Key[] keys = new Key[limit];
   int len = 0;
   // Gather some keys that pass all filters
   for (Key key : H2O.keySet()) {
     if (filter != null
         && // Have a filter?
         key.toString().indexOf(filter) == -1) continue; // Ignore this filtered-out key
     if (!key.user_allowed()) // Also filter out for user-keys
     continue;
     Value val = DKV.get(key);
     if (val == null) continue; // Deleted key?
     if (_typeid != 0 && val.type() != _typeid) continue; // Wrong type?
     if (!shouldIncludeKey(key)) continue; // Generic override
     keys[len++] = key; // Capture the key
     if (len == keys.length) break;
   }
   // sort the keys, for pretty display & reliable ordering
   Arrays.sort(keys, 0, len);
   for (int i = 0; i < len; ++i) array.add(new JsonPrimitive(keys[i].toString()));
   return array;
 }
  @Nullable
  public static BufferedImage getBitmap(EvaluationContextImpl evaluationContext, Value bitmap)
      throws EvaluateException {
    // retrieve the bitmap from bitmap drawables
    String fqcn = bitmap.type().name();
    if (BitmapDrawableRenderer.BITMAP_DRAWABLE_FQCN.equals(fqcn)) {
      bitmap = getBitmapFromDrawable(evaluationContext, (ObjectReference) bitmap);
      if (bitmap == null) {
        throw new RuntimeException("Unable to obtain bitmap from drawable");
      }
    }

    String config = getBitmapConfigName((ObjectReference) bitmap, evaluationContext);
    if (!"\"ARGB_8888\"".equals(config)) {
      throw new RuntimeException("Unsupported bitmap configuration: " + config);
    }

    Dimension size = getDimension(evaluationContext, bitmap);
    if (size == null) {
      throw new RuntimeException("Unable to determine image dimensions.");
    }

    // if the image is rather large, then scale it down
    if (size.width > MAX_DIMENSION || size.height > MAX_DIMENSION) {
      LOG.debug("Scaling down bitmap");
      bitmap = createScaledBitmap(evaluationContext, (ObjectReference) bitmap, size);
      if (bitmap == null) {
        throw new RuntimeException("Unable to create scaled bitmap");
      }

      size = getDimension(evaluationContext, bitmap);
      if (size == null) {
        throw new RuntimeException("Unable to obtained scaled bitmap's dimensions");
      }
    }

    List<Value> pixelValues;

    Field bufferField = ((ObjectReference) bitmap).referenceType().fieldByName("mBuffer");
    if (bufferField != null) {
      // if the buffer field is available, we can directly copy over the values
      Value bufferValue = ((ObjectReference) bitmap).getValue(bufferField);
      if (!(bufferValue instanceof ArrayReference)) {
        throw new RuntimeException("Image Buffer is not an array");
      }
      pixelValues = ((ArrayReference) bufferValue).getValues();
    } else {
      // if there is no buffer field (on older platforms that store data on native heap), then
      // resort to creating a new buffer,
      // and invoking copyPixelsToBuffer to copy the pixel data into the newly created buffer
      pixelValues = copyToBuffer(evaluationContext, (ObjectReference) bitmap, size);
      if (pixelValues == null) {
        throw new RuntimeException("Unable to extract image data: Bitmap has no buffer field.");
      }
    }

    byte[] argb = new byte[pixelValues.size()];
    for (int i = 0; i < pixelValues.size(); i++) {
      Value pixelValue = pixelValues.get(i);
      if (pixelValue instanceof ByteValue) {
        argb[i] = ((ByteValue) pixelValue).byteValue();
      }
    }

    return createBufferedImage(size.width, size.height, argb);
  }