Search in sources :

Example 6 with Variable

use of org.apache.xpath.operations.Variable in project j2objc by google.

the class RedundentExprEliminator method changeToVarRef.

/**
   * Change the expression owned by the owner argument to a variable reference 
   * of the given name.
   * 
   * Warning: For global vars, this function relies on the variable declaration 
   * to which it refers having been added just prior to this function being called,
   * so that the reference index can be determined from the size of the global variables 
   * list minus one.
   * 
   * @param varName The name of the variable which will be referenced.
   * @param owner The owner of the expression which will be replaced by a variable ref.
   * @param paths The paths list that the iterator came from, mainly to determine
   *              if this is a local or global reduction.
   * @param psuedoVarRecipient The element within whose scope the variable is 
   *                           being inserted, possibly a StylesheetRoot.
   */
protected void changeToVarRef(QName varName, ExpressionOwner owner, Vector paths, ElemTemplateElement psuedoVarRecipient) {
    Variable varRef = (paths == m_absPaths) ? new VariableSafeAbsRef() : new Variable();
    varRef.setQName(varName);
    if (paths == m_absPaths) {
        StylesheetRoot root = (StylesheetRoot) psuedoVarRecipient;
        Vector globalVars = root.getVariablesAndParamsComposed();
        // Assume this operation is occuring just after the decl has 
        // been added.
        varRef.setIndex(globalVars.size() - 1);
        varRef.setIsGlobal(true);
    }
    owner.setExpression(varRef);
}
Also used : Variable(org.apache.xpath.operations.Variable) VariableSafeAbsRef(org.apache.xpath.operations.VariableSafeAbsRef) Vector(java.util.Vector)

Aggregations

Variable (org.apache.xpath.operations.Variable)6 Vector (java.util.Vector)4 QName (org.apache.xml.utils.QName)2 AxesWalker (org.apache.xpath.axes.AxesWalker)2 FilterExprIteratorSimple (org.apache.xpath.axes.FilterExprIteratorSimple)2 FilterExprWalker (org.apache.xpath.axes.FilterExprWalker)2 XString (org.apache.xpath.objects.XString)2 VariableSafeAbsRef (org.apache.xpath.operations.VariableSafeAbsRef)2