FileDocCategorySizeDatePackage
VariableRefBase.javaAPI DocJava SE 6 API4510Tue Jun 10 00:22:30 BST 2008com.sun.org.apache.xalan.internal.xsltc.compiler

VariableRefBase

public class VariableRefBase extends Expression
author
Morten Jorgensen
author
Santiago Pericas-Geertsen

Fields Summary
protected VariableBase
_variable
A reference to the associated variable.
protected Closure
_closure
A reference to the enclosing expression/instruction for which a closure is needed (Predicate, Number or Sort).
Constructors Summary
public VariableRefBase(VariableBase variable)


       
	_variable = variable;
	variable.addReference(this);
    
public VariableRefBase()

	_variable = null;
    
Methods Summary
public voidaddParentDependency()
If this variable reference is in a top-level element like another variable, param or key, add a dependency between that top-level element and the referenced variable. For example, and assuming this class represents "$x", add a reference between variable y and variable x.

	SyntaxTreeNode node = this;
	while (node != null && node instanceof TopLevelElement == false) {
	    node = node.getParent();
	}
        
        TopLevelElement parent = (TopLevelElement) node;        
        if (parent != null) {
            VariableBase var = _variable;
            if (_variable._ignore) {
                if (_variable instanceof Variable) {
                    var = parent.getSymbolTable()
                                .lookupVariable(_variable._name);
                } else if (_variable instanceof Param) {
                    var = parent.getSymbolTable().lookupParam(_variable._name);
                }
            }
            
            parent.addDependency(var);
        }        
    
public booleanequals(java.lang.Object obj)
Two variable references are deemed equal if they refer to the same variable.

	try {
	    return (_variable == ((VariableRefBase) obj)._variable);
	} 
	catch (ClassCastException e) {
	    return false;
	}
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.VariableBasegetVariable()
Returns a reference to the associated variable

	return _variable;
    
public java.lang.StringtoString()
Returns a string representation of this variable reference on the format 'variable-ref()'.

return
Variable reference description

	return "variable-ref("+_variable.getName()+'/"+_variable.getType()+')";
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypetypeCheck(com.sun.org.apache.xalan.internal.xsltc.compiler.SymbolTable stable)

	// Returned cached type if available
	if (_type != null) return _type;

	// Find nearest closure to add a variable reference
	if (_variable.isLocal()) {
	    SyntaxTreeNode node = getParent();
	    do {
		if (node instanceof Closure) {
		    _closure = (Closure) node;
		    break;
		}
		if (node instanceof TopLevelElement) {
		    break;	// way up in the tree
		}
		node = node.getParent();
	    } while (node != null);

	    if (_closure != null) {
		_closure.addVariable(this);
	    }
	}

        // Attempt to get the cached variable type
        _type = _variable.getType();

        // If that does not work we must force a type-check (this is normally
        // only needed for globals in included/imported stylesheets
        if (_type == null) {
            _variable.typeCheck(stable);
            _type = _variable.getType();
        }

        // If in a top-level element, create dependency to the referenced var
        addParentDependency();
        
        // Return the type of the referenced variable
        return _type;