예제 #1
0
 private void setClass(Node n, byte theClass) {
   Ptg p = (Ptg) n.getValue();
   if (p instanceof AbstractFunctionPtg || !(p instanceof OperationPtg)) {
     p.setClass(theClass);
   } else {
     for (int i = 0; i < n.getNumChildren(); i++) {
       setClass(n.getChild(i), theClass);
     }
   }
 }
예제 #2
0
 private void setParameterRVA(Node n, int expectedClass, int formulaType) {
   Ptg p = (Ptg) n.getValue();
   if (expectedClass == Ptg.CLASS_REF) { // pg 15, table 1
     if (p.getDefaultOperandClass() == Ptg.CLASS_REF) {
       setClass(n, Ptg.CLASS_REF);
     }
     if (p.getDefaultOperandClass() == Ptg.CLASS_VALUE) {
       if (formulaType == FORMULA_TYPE_CELL || formulaType == FORMULA_TYPE_SHARED) {
         setClass(n, Ptg.CLASS_VALUE);
       } else {
         setClass(n, Ptg.CLASS_ARRAY);
       }
     }
     if (p.getDefaultOperandClass() == Ptg.CLASS_ARRAY) {
       setClass(n, Ptg.CLASS_ARRAY);
     }
   } else if (expectedClass == Ptg.CLASS_VALUE) { // pg 15, table 2
     if (formulaType == FORMULA_TYPE_NAMEDRANGE) {
       setClass(n, Ptg.CLASS_ARRAY);
     } else {
       setClass(n, Ptg.CLASS_VALUE);
     }
   } else { // Array class, pg 16.
     if (p.getDefaultOperandClass() == Ptg.CLASS_VALUE
         && (formulaType == FORMULA_TYPE_CELL || formulaType == FORMULA_TYPE_SHARED)) {
       setClass(n, Ptg.CLASS_VALUE);
     } else {
       setClass(n, Ptg.CLASS_ARRAY);
     }
   }
 }
예제 #3
0
 private void setParameterRVA(Node n, int formulaType) {
   Ptg p = n.getValue();
   int numOperands = n.getNumChildren();
   if (p instanceof AbstractFunctionPtg) {
     for (int i = 0; i < numOperands; i++) {
       setParameterRVA(n.getChild(i), ((AbstractFunctionPtg) p).getParameterClass(i), formulaType);
       //                if (n.getChild(i).getValue() instanceof AbstractFunctionPtg) {
       //                    setParameterRVA(n.getChild(i),formulaType);
       //                }
       setParameterRVA(n.getChild(i), formulaType);
     }
   } else {
     for (int i = 0; i < numOperands; i++) {
       setParameterRVA(n.getChild(i), formulaType);
     }
   }
 }
예제 #4
0
 private void setRootLevelRVA(Node n, int formulaType) {
   // Pg 16, excelfileformat.pdf @ openoffice.org
   Ptg p = (Ptg) n.getValue();
   if (formulaType == FormulaParser.FORMULA_TYPE_NAMEDRANGE) {
     if (p.getDefaultOperandClass() == Ptg.CLASS_REF) {
       setClass(n, Ptg.CLASS_REF);
     } else {
       setClass(n, Ptg.CLASS_ARRAY);
     }
   } else {
     setClass(n, Ptg.CLASS_VALUE);
   }
 }
예제 #5
0
  /** Create a tree representation of the RPN token array used to run the class(RVA) change algo */
  private Node createTree() {
    java.util.Stack stack = new java.util.Stack();
    int numPtgs = tokens.size();
    OperationPtg o;
    int numOperands;
    Node[] operands;
    for (int i = 0; i < numPtgs; i++) {
      if (tokens.get(i) instanceof OperationPtg) {

        o = (OperationPtg) tokens.get(i);
        numOperands = o.getNumberOfOperands();
        operands = new Node[numOperands];
        for (int j = 0; j < numOperands; j++) {
          operands[numOperands - j - 1] = (Node) stack.pop();
        }
        Node result = new Node(o);
        result.setChildren(operands);
        stack.push(result);
      } else {
        stack.push(new Node((Ptg) tokens.get(i)));
      }
    }
    return (Node) stack.pop();
  }