ExpressionSequence parseExpressionSequence(
      final Arguments arguments, final String input, final boolean preprocess) {

    final String trimmedInput = input.trim();

    final String preprocessedInput =
        (preprocess ? preprocess(arguments, trimmedInput) : trimmedInput);

    final ExpressionSequence cachedExpressionSequence =
        CACHE.getExpressionSequenceFromCache(arguments.getConfiguration(), preprocessedInput);
    if (cachedExpressionSequence != null) {
      return cachedExpressionSequence;
    }

    final ExpressionSequence expressionSequence = ExpressionSequence.parse(preprocessedInput);

    if (expressionSequence == null) {
      throw new TemplateProcessingException(
          "Could not parse as expression sequence: \"" + input + "\"");
    }

    CACHE.putExpressionSequenceIntoCache(
        arguments.getConfiguration(), preprocessedInput, expressionSequence);

    return expressionSequence;
  }
  FragmentSelection parseFragmentSelection(
      final Arguments arguments, final String input, final boolean preprocess) {

    final String trimmedInput = input.trim();

    final String preprocessedInput =
        (preprocess ? preprocess(arguments, trimmedInput) : trimmedInput);

    final FragmentSelection cachedFragmentSelection =
        CACHE.getFragmentSelectionFromCache(arguments.getConfiguration(), preprocessedInput);
    if (cachedFragmentSelection != null) {
      return cachedFragmentSelection;
    }

    final FragmentSelection fragmentSelection = FragmentSelection.parse(preprocessedInput);

    if (fragmentSelection == null) {
      throw new TemplateProcessingException(
          "Could not parse as fragment selection: \"" + input + "\"");
    }

    CACHE.putFragmentSelectionIntoCache(
        arguments.getConfiguration(), preprocessedInput, fragmentSelection);

    return fragmentSelection;
  }
  AssignationSequence parseAssignationSequence(
      final Arguments arguments,
      final String input,
      final boolean preprocess,
      final boolean allowParametersWithoutValue) {

    final String trimmedInput = input.trim();

    final String preprocessedInput =
        (preprocess ? preprocess(arguments, trimmedInput) : trimmedInput);

    final AssignationSequence cachedAssignationSequence =
        CACHE.getAssignationSequenceFromCache(arguments.getConfiguration(), preprocessedInput);
    if (cachedAssignationSequence != null) {
      return cachedAssignationSequence;
    }

    final AssignationSequence assignationSequence =
        AssignationSequence.parse(preprocessedInput, allowParametersWithoutValue);

    if (assignationSequence == null) {
      throw new TemplateProcessingException(
          "Could not parse as assignation sequence: \"" + input + "\"");
    }

    CACHE.putAssignationSequenceIntoCache(
        arguments.getConfiguration(), preprocessedInput, assignationSequence);

    return assignationSequence;
  }
 String getCurrentPackageName() {
   String s = null;
   try {
     Integer o = (Integer) m_cache.get(DebugCLI.LIST_MODULE);
     s = m_cache.getPackageName(o.intValue());
   } catch (NullPointerException npe) {
   } catch (ClassCastException cce) {
   }
   return s;
 }
 // used to assign a value to an internal variable
 private void assignInternal(InternalProperty var, Value v)
     throws NoSuchVariableException, NumberFormatException, PlayerDebugException {
   // otherwise set it
   if (v.getType() != VariableType.NUMBER) throw new NumberFormatException(v.getValueAsString());
   long l = Long.parseLong(v.getValueAsString());
   m_cache.put(var.getName(), (int) l);
 }
  Each parseEach(final Arguments arguments, final String input, final boolean preprocess) {

    final String trimmedInput = input.trim();

    final String preprocessedInput =
        (preprocess ? preprocess(arguments, trimmedInput) : trimmedInput);

    final Each cachedEach = CACHE.getEachFromCache(arguments.getConfiguration(), preprocessedInput);
    if (cachedEach != null) {
      return cachedEach;
    }

    final Each each = Each.parse(preprocessedInput);

    if (each == null) {
      throw new TemplateProcessingException("Could not parse as each: \"" + input + "\"");
    }

    CACHE.putEachIntoCache(arguments.getConfiguration(), preprocessedInput, each);

    return each;
  }
  /* returns a string consisting of formatted member names and values */
  public Object lookupMembers(Object o) throws NoSuchVariableException {
    Variable var = null;
    Value val = null;
    Variable[] mems = null;
    try {
      var = resolveToVariable(o);
      if (var != null) val = var.getValue();
      else val = resolveToValue(o);
      mems = val.getMembers(getSession());
    } catch (NullPointerException npe) {
      throw new NoSuchVariableException(o);
    } catch (PlayerDebugException pde) {
      throw new NoSuchVariableException(o); // not quite right...
    }

    StringBuilder sb = new StringBuilder();

    if (var != null) m_cache.appendVariable(sb, var, m_isolateId);
    else m_cache.appendVariableValue(sb, val, m_isolateId);

    boolean attrs = m_cache.propertyEnabled(DebugCLI.DISPLAY_ATTRIBUTES);
    if (attrs && var != null) ExpressionCache.appendVariableAttributes(sb, var);

    // [mmorearty] experimenting with hierarchical display of members
    String[] classHierarchy = val.getClassHierarchy(false);
    if (classHierarchy != null
        && getSession().getPreference(SessionManager.PREF_HIERARCHICAL_VARIABLES) != 0) {
      for (int c = 0; c < classHierarchy.length; ++c) {
        String classname = classHierarchy[c];
        sb.append(m_newline + "(Members of " + classname + ")"); // $NON-NLS-1$ //$NON-NLS-2$
        for (int i = 0; i < mems.length; ++i) {
          if (classname.equals(mems[i].getDefiningClass())) {
            sb.append(m_newline + " "); // $NON-NLS-1$
            m_cache.appendVariable(sb, mems[i], m_isolateId);
            if (attrs) ExpressionCache.appendVariableAttributes(sb, mems[i]);
          }
        }
      }
    } else {
      for (int i = 0; i < mems.length; i++) {
        sb.append(m_newline + " "); // $NON-NLS-1$
        m_cache.appendVariable(sb, mems[i], m_isolateId);
        if (attrs) ExpressionCache.appendVariableAttributes(sb, mems[i]);
      }
    }

    return sb.toString();
  }
  InternalProperty resolveToInternalProperty(Object o) {
    if (o instanceof String && ((String) o).charAt(0) == '$') {
      String key = (String) o;
      Object value = null;

      try {
        value = m_cache.get(key);
      } catch (Exception e) {
      }
      return new InternalProperty(key, value);
    }

    return null;
  }
 public Session getSession() {
   return m_cache.getSession();
 }
Example #10
0
  /**
   * All the really good stuff about finding where name exists goes here!
   *
   * <p>If name is not null, then it implies that we use the existing m_current to find a member of
   * m_current. If m_current is null Then we need to probe variable context points attempting to
   * locate name. When we find a match we set the m_current to this context
   *
   * <p>If name is null then we simply return the current context.
   */
  long determineContext(String name) throws PlayerDebugException {
    long id = Value.UNKNOWN_ID;

    // have we already resolved our context...
    if (m_current != null) {
      id = toValue().getId();
    }

    // nothing to go on, so we're done
    else if (name == null) ;

    // use the name and try and resolve where we are...
    else {
      // Each stack frame has a root variable under (BASE_ID-depth)
      // where depth is the depth of the stack.
      // So we query for our current stack depth and use that
      // as the context for our base computation
      long baseId = Value.BASE_ID;
      int depth = ((Integer) m_cache.get(DebugCLI.DISPLAY_FRAME_NUMBER)).intValue();
      baseId -= depth;

      // obtain data about our current state
      Variable contextVar = null;
      Value contextVal = null;
      Value val = null;

      // look for 'name' starting from local scope
      if ((val = locateParentForNamed(baseId, name, false)) != null) ;

      // get the this pointer, then look for 'name' starting from that point
      else if (((contextVar = locateForNamed(baseId, "this", false)) != null)
          && //$NON-NLS-1$
          (setName("this")
              && (val = locateParentForNamed(contextVar.getValue().getId(), name, true))
                  != null)) //$NON-NLS-1$
      ;

      // now try to see if 'name' exists off of _root
      else if (setName("_root")
          && (val = locateParentForNamed(Value.ROOT_ID, name, true)) != null) // $NON-NLS-1$
      ;

      // now try to see if 'name' exists off of _global
      else if (setName("_global")
          && (val = locateParentForNamed(Value.GLOBAL_ID, name, true)) != null) // $NON-NLS-1$
      ;

      // now try off of class level, if such a thing can be found
      else if (((contextVal = locate(Value.GLOBAL_ID, getCurrentPackageName(), false)) != null)
          && (setName("_global." + getCurrentPackageName())
              && (val = locateParentForNamed(contextVal.getId(), name, true))
                  != null)) //$NON-NLS-1$
      ;

      // if we found it then stake this as our context!
      if (val != null) {
        id = val.getId();
        pushName(name);
        lockName();
      }
    }

    return id;
  }
Example #11
0
 /**
  * Resolves the current expression, possibly into a different expression object. This is loosely
  * equivalent to the serialization protocol's <code>readResolve</code> method. Situations where
  * this may be used are:
  *
  * <ul>
  *   <li>Caching frequently-used expression objects
  *   <li>Evaluating constant expressions, and returning a constant reference
  * </ul>
  */
 public Expression resolveExpression() {
   return ExpressionCache.cacheExpression(this);
 }
Example #12
0
 /**
  * For serialization purposes, resolve a deserialized instance to an instance in the expression
  * cache.
  */
 private Object readResolve() throws ObjectStreamException {
   return ExpressionCache.cacheExpression(this);
 }
Example #13
0
 /**
  * For serialization purposes, resolve a deserialized instance to an instance in the expression
  * cache.
  */
 private Object readResolve() throws ObjectStreamException {
   if (isComplete()) {
     return ExpressionCache.cacheExpression(this);
   }
   return this;
 }