org.apache.commons.jexl3.internal
Class Scope

java.lang.Object
  extended by org.apache.commons.jexl3.internal.Scope

public final class Scope
extends Object

A script scope, stores the declaration of parameters and local variables as symbols.

Since:
3.0

Nested Class Summary
static class Scope.Frame
          A call frame, created from a scope, stores the arguments and local variables in a "stack frame" (sic).
 
Constructor Summary
Scope(Scope scope, String... parameters)
          Creates a new scope with a list of parameters.
 
Method Summary
 Scope.Frame createFrame(Scope.Frame frame)
          Creates a frame by copying values up to the number of parameters.
 void declareParameter(String name)
          Declares a parameter.
 Integer declareVariable(String name)
          Declares a local variable.
 boolean equals(Object o)
           
 int getArgCount()
          Gets the (maximum) number of arguments this script expects.
 Integer getHoisted(int symbol)
          Gets the hoisted index of a given symbol, ie the target index of a symbol in a child frame.
 String[] getLocalVariables()
          Gets this script local variable, i.e.
 String[] getParameters()
          Gets this script parameters, i.e.
 Integer getSymbol(String name)
          Checks whether an identifier is a local variable or argument, ie a symbol.
 String[] getSymbols()
          Gets this script symbols names, i.e.
 int hashCode()
           
 boolean isHoistedSymbol(int symbol)
          Checks whether a given symbol is hoisted.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scope

public Scope(Scope scope,
             String... parameters)
Creates a new scope with a list of parameters.

Parameters:
scope - the parent scope if any
parameters - the list of parameters
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

getSymbol

public Integer getSymbol(String name)
Checks whether an identifier is a local variable or argument, ie a symbol. If this fails, attempt to solve by hoisting parent stacked.

Parameters:
name - the symbol name
Returns:
the symbol index

isHoistedSymbol

public boolean isHoistedSymbol(int symbol)
Checks whether a given symbol is hoisted.

Parameters:
symbol - the symbol number
Returns:
true if hoisted, false otherwise

declareParameter

public void declareParameter(String name)
Declares a parameter.

This method creates an new entry in the symbol map.

Parameters:
name - the parameter name

declareVariable

public Integer declareVariable(String name)
Declares a local variable.

This method creates an new entry in the symbol map.

Parameters:
name - the variable name
Returns:
the register index storing this variable

createFrame

public Scope.Frame createFrame(Scope.Frame frame)
Creates a frame by copying values up to the number of parameters.

This captures the hoisted variables values.

Parameters:
frame - the caller frame
Returns:
the arguments array

getHoisted

public Integer getHoisted(int symbol)
Gets the hoisted index of a given symbol, ie the target index of a symbol in a child frame.

Parameters:
symbol - the symbol index
Returns:
the target symbol index or null if the symbol is not hoisted

getArgCount

public int getArgCount()
Gets the (maximum) number of arguments this script expects.

Returns:
the number of parameters

getSymbols

public String[] getSymbols()
Gets this script symbols names, i.e. parameters and local variables.

Returns:
the symbol names

getParameters

public String[] getParameters()
Gets this script parameters, i.e. symbols assigned before creating local variables.

Returns:
the parameter names

getLocalVariables

public String[] getLocalVariables()
Gets this script local variable, i.e. symbols assigned to local variables excluding hoisted variables.

Returns:
the local variable names


Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.