private void addVariable(IVariable var, NesCVariableNameParser varPars, TreeParent parent) {
      try {
        IValue val = var.getValue();
        String cVarName = var.getName();
        String name = varPars.getVariableName(cVarName);
        TreeNode node = parent.hasChild(name);
        if (val.hasVariables()) {
          // var consists of multiple inner variables... (like for example a struct)
          if (node == null) {
            node = new TreeParent(name);
            node.setData(var);
            parent.addChild(node);
          }
          for (IVariable innerVar : val.getVariables()) {
            addVariable(innerVar, varPars, (TreeParent) node);
          }
        } else {
          if (node == null) {
            node = new TreeParent(name); // Leaf
            node.setData(var);
            parent.addChild(node);
          }
        }

      } catch (DebugException e) {
        TinyOSDebugPlugin.getDefault().log("Exception while adding variable to tree.", e);
      }
    }
  /* (non-Javadoc)
   * @see org.eclipse.jface.text.ITextHoverExtension2#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
   */
  public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
    IJavaScriptStackFrame frame = getFrame();
    if (frame != null) {
      IDocument document = textViewer.getDocument();
      if (document != null) {
        try {
          String variableName = document.get(hoverRegion.getOffset(), hoverRegion.getLength());
          IVariable var = findLocalVariable(frame, variableName);
          if (var != null) {
            return var;
          }

          // might be in 'this'
          var = frame.getThisObject();
          try {
            IValue val = var == null ? null : var.getValue();
            if (val != null) {
              IVariable[] vars = val.getVariables();
              for (int i = 0; i < vars.length; i++) {
                if (vars[i].getName().equals(variableName)) {
                  return vars[i];
                }
              }
            }
          } catch (DebugException de) {
            return null;
          }

        } catch (BadLocationException e) {
          return null;
        }
      }
    }
    return null;
  }
 public Object[] getChildren(Object obj) {
   try {
     Object[] variables = null;
     if (obj != null
         && obj instanceof IJavaObject
         && "org.drools.reteoo.ReteooStatefulSession"
             .equals(((IJavaObject) obj).getReferenceTypeName())) {
       variables = getAgendaElements((IJavaObject) obj);
     } else if (obj instanceof IVariable) {
       if (view.isShowLogicalStructure()) {
         IValue value = getLogicalValue(((IVariable) obj).getValue(), new ArrayList());
         variables = value.getVariables();
       }
       if (variables == null) {
         variables = ((IVariable) obj).getValue().getVariables();
       }
     }
     if (variables == null) {
       return new Object[0];
     } else {
       cache(obj, variables);
       return variables;
     }
   } catch (DebugException e) {
     DroolsEclipsePlugin.log(e);
     return new Object[0];
   }
 }
Example #4
0
 /**
  * Returns children for the given value, creating array partitions if required
  *
  * @param parent expression or variable containing the given value
  * @param value the value to retrieve children for
  * @param context the context in which children have been requested
  * @return children for the given value, creating array partitions if required
  * @throws CoreException
  */
 protected Object[] getValueChildren(
     IDebugElement parent, IValue value, IPresentationContext context) throws CoreException {
   if (value == null) {
     return EMPTY;
   }
   IValue logicalValue = getLogicalValue(value, context);
   if (logicalValue instanceof IIndexedValue) {
     IIndexedValue indexedValue = (IIndexedValue) logicalValue;
     int partitionSize = computeParitionSize(indexedValue);
     if (partitionSize > 1) {
       int offset = indexedValue.getInitialOffset();
       int length = indexedValue.getSize();
       int numPartitions = length / partitionSize;
       int remainder = length % partitionSize;
       if (remainder > 0) {
         numPartitions++;
       }
       IVariable[] partitions = new IVariable[numPartitions];
       for (int i = 0; i < (numPartitions - 1); i++) {
         partitions[i] = new IndexedVariablePartition(parent, indexedValue, offset, partitionSize);
         offset = offset + partitionSize;
       }
       if (remainder == 0) {
         remainder = partitionSize;
       }
       partitions[numPartitions - 1] =
           new IndexedVariablePartition(parent, indexedValue, offset, remainder);
       return partitions;
     }
   }
   if (logicalValue == null) {
     // safeguard against an structure type returning null
     logicalValue = value;
   }
   return logicalValue.getVariables();
 }