函数具体逻辑

@param scope 上下文
@return 计算好的节点
507349
@Override
    public XValue call(Scope scope) {
        List<String> res = new LinkedList<>();
        for (Element e:scope.context()){
            if ("script".equals(e.nodeName())){
                res.add(e.data());
            }else {
                res.add(e.text());
            }
        }
        return XValue.create(res);
    }
1374656
@Override
    public XValue call(Scope scope) {
        NodeTest textFun = Scanner.findNodeTestByName("allText");
        XValue textVal = textFun.call(scope);
        String whole = StringUtils.join(textVal.asList(),"");
        Matcher matcher = numExt.matcher(whole);
        if (matcher.find()){
            String numStr = matcher.group();
            BigDecimal num = new BigDecimal(numStr);
            return XValue.create(num.doubleValue());
        }else {
            return XValue.create(null);
        }
    }
977755
public CompletableFuture<String> getScope(final String scopeName) {
        Preconditions.checkNotNull(scopeName);
        return streamStore.getScopeConfiguration(scopeName);
    }
364265
public TypeUsage.Builder scope(Optional<? extends QualifiedName> scope) {
    if (scope.isPresent()) {
      return scope(scope.get());
    } else {
      return clearScope();
    }
  }
968272
protected Map<String, Object> getReplacedAttributes(int scope) {
        if (replacedAttributes == null) {
            replacedAttributes = new ArrayList<>();
        }
        while (replacedAttributes.size() <= scope) {
            replacedAttributes.add(new HashMap<String, Object>());
        }
        return replacedAttributes.get(scope);
    }
970003
public Object eval(Scope scope) {
		Object value = expr.eval(scope);
		if (value == null) {
			if (scope.getCtrl().isNullSafe()) {
				return null;
			}
			throw new TemplateException("The parameter of \"" + op.value() + "\" operator can not be blank", location);
		}
		if (! (value instanceof Number) ) {
			throw new TemplateException(op.value() + " operator only support int long float double BigDecimal type", location);
		}
		
		switch (op) {
		case ADD:
			return value;
		case SUB:
			Number n = (Number)value;
			if (n instanceof Integer) {
                return Integer.valueOf(-n.intValue());
            }
			if (n instanceof Long) {
                return Long.valueOf(-n.longValue());
            }
			if (n instanceof Float) {
                return Float.valueOf(-n.floatValue());
            }
			if (n instanceof Double) {
                return Double.valueOf(-n.doubleValue());
            }
			if (n instanceof BigDecimal) {
            	return ((BigDecimal)n).negate();
			}
            throw new TemplateException("Unsupported data type: " + n.getClass().getName(), location);
		default :
			throw new TemplateException("Unsupported operator: " + op.value(), location);
		}
	}
299660
@Override
    public List<String> getScopeNames() {
	List<String> scopeNames = new ArrayList<String>();

	if (checkArguments) {
	    scopeNames.add("local");
	    scopeNames.add("arguments");
	}
	scopeNames.add("variables");

	// thread scopes
	if (pc.hasFamily()) {
	    String[] names = pc.getThreadScopeNames();
	    for (int i = 0; i < names.length; i++)
		scopeNames.add(i, names[i]);
	}

	for (int i = 0; i < scopes.length; i++) {
	    scopeNames.add((scopes[i]).getTypeAsString());
	}
	return scopeNames;
    }

    @Override
    public Object getCollection(Key key) throws PageException {
	Object rtn = null;

	if (checkArguments) {
	    rtn = local.get(key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) return rtn;
	    rtn = argument.getFunctionArgument(key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) {
		if (debug) debugCascadedAccess(pc, argument.getTypeAsString(), key);
		return rtn;
	    }
	}

	// get data from queries
	if (allowImplicidQueryCall && pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML && !qryStack.isEmpty()) {
	    rtn = qryStack.getColumnFromACollection(key);
	    if (rtn != null) {
		if (debug) debugCascadedAccess(pc, "query", key);
		return rtn;
	    }
	}

	// variable
	rtn = variable.get(key, NullSupportHelper.NULL());
	if (rtn != NullSupportHelper.NULL()) {
	    if (debug && checkArguments) debugCascadedAccess(pc, variable, rtn, key);
	    return rtn;
	}

	// thread scopes
	if (pc.hasFamily()) {
	    rtn = pc.getThreadScope(key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) {
		if (debug) debugCascadedAccess(pc, "thread", key);
		return rtn;
	    }
	}

	// get a scope value (only CFML is searching addioanl scopes)
	if (pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML) {
	    for (int i = 0; i < scopes.length; i++) {
		rtn = scopes[i].get(key, NullSupportHelper.NULL());
		if (rtn != NullSupportHelper.NULL()) {
		    if (debug) debugCascadedAccess(pc, scopes[i].getTypeAsString(), key);
		    return rtn;
		}
	    }
	}
	throw new ExpressionException("variable [" + key.getString() + "] doesn't exist");
    }

    @Override
    public Object get(Collection.Key key, Object defaultValue) {
	Object rtn = null;
	if (checkArguments) {
	    rtn = local.get(key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) return rtn;

	    rtn = argument.getFunctionArgument(key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) {
		if (debug) debugCascadedAccess(pc, argument.getTypeAsString(), key);
		return rtn;
	    }
	}

	// get data from queries
	if (allowImplicidQueryCall && pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML && !qryStack.isEmpty()) {
	    rtn = qryStack.getDataFromACollection(pc, key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) {
		if (debug) debugCascadedAccess(pc, "query", key);
		return rtn;
	    }
	}

	// variable
	rtn = variable.get(key, NullSupportHelper.NULL());
	if (rtn != NullSupportHelper.NULL()) {
	    if (debug && checkArguments) debugCascadedAccess(pc, variable, rtn, key);
	    return rtn;
	}

	// thread scopes
	if (pc.hasFamily()) {
	    rtn = pc.getThreadScope(key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) {
		if (debug && checkArguments) debugCascadedAccess(pc, "thread", key);
		return rtn;
	    }
	}

	// get a scope value (only CFML is searching additional scopes)
	if (pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML) {
	    for (int i = 0; i < scopes.length; i++) {
		rtn = scopes[i].get(key, NullSupportHelper.NULL());
		if (rtn != NullSupportHelper.NULL()) {
		    if (debug) debugCascadedAccess(pc, scopes[i].getTypeAsString(), key);
		    return rtn;
		}
	    }
	}

	return defaultValue;
    }

    @Override
    public Object getCascading(Collection.Key key) {
	throw new RuntimeException("this method is no longer supported, use getCascading(Collection.Key key, Object defaultValue) instead");
    }

    @Override
    public Object getCascading(Collection.Key key, Object defaultValue) {
	Object rtn;

	// get a scope value (only CFML is searching additional scopes)
	if (pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML) {
	    for (int i = 0; i < scopes.length; i++) {
		rtn = scopes[i].get(key, NullSupportHelper.NULL());
		if (rtn != NullSupportHelper.NULL()) {
		    return rtn;
		}
	    }
	}
	return defaultValue;
    }

    @Override
    public Object setEL(Collection.Key key, Object value) {
	if (checkArguments) {
	    if (localAlways || local.containsKey(key)) return local.setEL(key, value);
	    if (argument.containsFunctionArgumentKey(key)) {
		if (debug) debugCascadedAccess(pc, argument.getTypeAsString(), key);
		return argument.setEL(key, value);
	    }
	}

	if (debug && checkArguments) debugCascadedAccess(pc, variable.getTypeAsString(), key);
	return variable.setEL(key, value);
    }

    @Override
    public Object set(Collection.Key key, Object value) throws PageException {
	if (checkArguments) {
	    if (localAlways || local.containsKey(key)) return local.set(key, value);
	    if (argument.containsFunctionArgumentKey(key)) {
		if (debug) debugCascadedAccess(pc, argument.getTypeAsString(), key);
		return argument.set(key, value);
	    }

	}
	if (debug && checkArguments) debugCascadedAccess(pc, variable.getTypeAsString(), key);
	return variable.set(key, value);
    }

    @Override
    public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
	return variable.toDumpData(pageContext, maxlevel, dp);
    }

    @Override
    public Iterator<Collection.Key> keyIterator() {
	return variable.keyIterator();
    }

    @Override
    public Iterator<String> keysAsStringIterator() {
	return variable.keysAsStringIterator();
    }

    @Override
    public Iterator<Entry<Key, Object>> entryIterator() {
	return variable.entryIterator();
    }

    @Override
    public Iterator<Object> valueIterator() {
	return variable.valueIterator();
    }

    @Override
    public boolean isInitalized() {
	return isInit;
    }

    @Override
    public void initialize(PageContext pc) {
	// if(isInitalized()) return;
	isInit = true;
	variable = pc.variablesScope();
	argument = pc.argumentsScope();
	local = pc.localScope();
	allowImplicidQueryCall = pc.getConfig().allowImplicidQueryCall();
	type = ((PageContextImpl) pc).getScopeCascadingType();
	debug = pc.getConfig().debug() && ((ConfigImpl) pc.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_IMPLICIT_ACCESS);

	// Strict
	if (type == Config.SCOPE_STRICT) {
	    // print.ln("strict");
	    scopes = new Scope[] {};
	}
	// small
	else if (type == Config.SCOPE_SMALL) {
	    // print.ln("small");
	    if (pc.getConfig().mergeFormAndURL()) {
		scopes = new Scope[] { pc.formScope() };
	    }
	    else {
		scopes = new Scope[] { pc.urlScope(), pc.formScope() };
	    }
	}
	// standard
	else {
	    reinitialize(pc);
	}

    }

    @Override
    public void reinitialize(PageContext pc) {
	if (type != Config.SCOPE_STANDARD) return;
	Client cs = pc.clientScopeEL();
	// print.ln("standard");
	if (pc.getConfig().mergeFormAndURL()) {
	    scopes = new Scope[cs == null ? 3 : 4];
	    scopes[0] = pc.cgiScope();
	    scopes[1] = pc.formScope();
	    scopes[2] = pc.cookieScope();
	    if (cs != null) scopes[3] = cs;
	}
	else {
	    scopes = new Scope[cs == null ? 4 : 5];
	    scopes[0] = pc.cgiScope();
	    scopes[1] = pc.urlScope();
	    scopes[2] = pc.formScope();
	    scopes[3] = pc.cookieScope();
	    if (cs != null) scopes[4] = cs;
	}
    }

    @Override
    public final void release(PageContext pc) {
	isInit = false;
	argument = null;
	local = null;
	variable = null;
	scopes = null;
	checkArguments = false;
	localAlways = false;
	if (allowImplicidQueryCall) qryStack.clear();
    }

    @Override
    public Collection duplicate(boolean deepCopy) {
	UndefinedImpl dupl = new UndefinedImpl(pc, type);
	dupl.allowImplicidQueryCall = allowImplicidQueryCall;
	dupl.checkArguments = checkArguments;
	dupl.argument = deepCopy ? (Argument) Duplicator.duplicate(argument, deepCopy) : argument;
	dupl.isInit = isInit;
	dupl.local = deepCopy ? (Local) Duplicator.duplicate(local, deepCopy) : local;
	dupl.localAlways = localAlways;
	dupl.qryStack = (deepCopy ? (QueryStackImpl) Duplicator.duplicate(qryStack, deepCopy) : qryStack);

	dupl.variable = deepCopy ? (Variables) Duplicator.duplicate(variable, deepCopy) : variable;
	dupl.pc = pc;
	dupl.debug = debug;

	// scopes
	if (deepCopy) {
	    dupl.scopes = new Scope[scopes.length];
	    for (int i = 0; i < scopes.length; i++) {
		dupl.scopes[i] = (Scope) Duplicator.duplicate(scopes[i], deepCopy);
	    }
	}
	else dupl.scopes = scopes;

	return dupl;
    }

    @Override
    public boolean containsKey(Key key) {
	return get(key, null) != null;
    }

    @Override
    public String castToString() throws ExpressionException {
	throw new ExpressionException("Can't cast Complex Object Type Struct to String", "Use Built-In-Function \"serialize(Struct):String\" to create a String from Struct");
    }

    @Override
    public String castToString(String defaultValue) {
	return defaultValue;
    }

    @Override
    public boolean castToBooleanValue() throws ExpressionException {
	throw new ExpressionException("Can't cast Complex Object Type Struct to a boolean value");
    }

    @Override
    public Boolean castToBoolean(Boolean defaultValue) {
	return defaultValue;
    }

    @Override
    public double castToDoubleValue() throws ExpressionException {
	throw new ExpressionException("Can't cast Complex Object Type Struct to a number value");
    }

    @Override
    public double castToDoubleValue(double defaultValue) {
	return defaultValue;
    }

    @Override
    public DateTime castToDateTime() throws ExpressionException {
	throw new ExpressionException("Can't cast Complex Object Type Struct to a Date");
    }

    @Override
    public DateTime castToDateTime(DateTime defaultValue) {
	return defaultValue;
    }

    @Override
    public int compareTo(boolean b) throws ExpressionException {
	throw new ExpressionException("can't compare Complex Object Type Struct with a boolean value");
    }

    @Override
    public int compareTo(DateTime dt) throws PageException {
	throw new ExpressionException("can't compare Complex Object Type Struct with a DateTime Object");
    }

    @Override
    public int compareTo(double d) throws PageException {
	throw new ExpressionException("can't compare Complex Object Type Struct with a numeric value");
    }

    @Override
    public int compareTo(String str) throws PageException {
	throw new ExpressionException("can't compare Complex Object Type Struct with a String");
    }

    @Override
    public void setVariableScope(Variables scope) {
	variable = scope;
    }

    @Override
    public int getType() {
	return SCOPE_UNDEFINED;
    }

    @Override
    public String getTypeAsString() {
	return "undefined";
    }

    /**
     * @return the allowImplicidQueryCall
     */
    public boolean isAllowImplicidQueryCall() {
	return allowImplicidQueryCall;
    }

    /**
     * @param allowImplicidQueryCall the allowImplicidQueryCall to set
     */
    @Override
    public boolean setAllowImplicidQueryCall(boolean allowImplicidQueryCall) {
	boolean old = this.allowImplicidQueryCall;
	this.allowImplicidQueryCall = allowImplicidQueryCall;
	return old;
    }

    /**
     * @return the checkArguments
     */
    @Override
    public boolean getCheckArguments() {
	return checkArguments;
    }

    @Override
    public Object call(PageContext pc, final Key methodName, Object[] args) throws PageException {
	Object obj = get(methodName, null); // every none UDF value is fine as default argument
	if (obj instanceof UDFPlus) {
	    return ((UDFPlus) obj).call(pc, methodName, args, false);
	}
	UDF udf = getUDF(pc, methodName);
	if (udf instanceof UDFPlus) {
	    return ((UDFPlus) udf).call(pc, methodName, args, false);
	}
	throw new ExpressionException("No matching function [" + methodName + "] found");
    }

    @Override
    public Object callWithNamedValues(PageContext pc, Key methodName, Struct args) throws PageException {
	Object obj = get(methodName, null);
	if (obj instanceof UDFPlus) {
	    return ((UDFPlus) obj).callWithNamedValues(pc, methodName, args, false);
	}
	UDF udf = getUDF(pc, methodName);
	if (udf instanceof UDFPlus) {
	    return ((UDFPlus) udf).callWithNamedValues(pc, methodName, args, false);
	}
	throw new ExpressionException("No matching function [" + methodName + "] found");
    }

    private UDF getUDF(PageContext pc, Key methodName) throws PageException {
	ApplicationContextSupport ac = (ApplicationContextSupport) pc.getApplicationContext();
	if (ac != null) {
	    List<Resource> dirs = ac.getFunctionDirectories();
	    Resource[] files;
	    if (dirs != null && dirs.size() > 0) {
		Resource file = null;
		Iterator<Resource> it = dirs.iterator();
		Resource dir;
		while (it.hasNext()) {
		    dir = it.next();
		    files = dir.listResources(new ResourceNameFilter() {
			@Override
			public boolean accept(Resource dir, String name) {
			    String[] exts = Constants.getTemplateExtensions();
			    for (String ex: exts) {
				if (name.equalsIgnoreCase(methodName + "." + ex)) return true;
			    }
			    return false;
			}
		    });
		    if (files != null && files.length > 0) {
			file = files[0];
			break;
		    }
		}
		if (file != null) {
		    return CFFunction.loadUDF(pc, file, methodName, pc.getConfig() instanceof ConfigWeb, false);
		}
	    }
	}
	return null;
    }

    public short getScopeCascadingType() {
	return type;
    }
511132
private WebSocketScope getScope(WebSocketConnection conn) {
        if (log.isTraceEnabled()) {
            log.trace("Scopes: {}", scopes);
        }
        log.debug("getScope: {}", conn);
        WebSocketScope wsScope;
        String path = conn.getPath();
        if (!scopes.containsKey(path)) {
            // check for default scope
            if (!scopes.containsKey("default")) {
                wsScope = new WebSocketScope();
                wsScope.setPath(path);
                notifyListeners(WebSocketEvent.SCOPE_CREATED, wsScope);
                addWebSocketScope(wsScope);
                //log.debug("Use the IWebSocketScopeListener interface to be notified of new scopes");
            } else {
                path = "default";
            }
        }
        wsScope = scopes.get(path);
        log.debug("Returning: {}", wsScope);
        return wsScope;
    }
857863
def scopes(self):
        
        if not self.__scopes:
            self.__scopes = Scopes(self.__connection)
        return self.__scopes
1330924
public List<String> getScopes(final int scopeIndex) {
    this.checkInitialized();
    return this.scopes.getOrDefault(Integer.valueOf(scopeIndex), SemanticHighlightingRegistry.UNKNOWN_SCOPES);
  }
477209
public Collection getScopeFor(Collection.Key key, Scope defaultValue) {
	Object rtn = null;

	if (checkArguments) {
	    rtn = local.get(key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) return local;
	    rtn = argument.getFunctionArgument(key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) return argument;
	}

	// get data from queries
	if (allowImplicidQueryCall && pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML && !qryStack.isEmpty()) {
	    QueryColumn qc = qryStack.getColumnFromACollection(key);
	    if (qc != null) return (Query) qc.getParent();
	}

	// variable
	rtn = variable.get(key, NullSupportHelper.NULL());
	if (rtn != NullSupportHelper.NULL()) {
	    return variable;
	}

	// thread scopes
	if (pc.hasFamily()) {
	    Threads t = (Threads) pc.getThreadScope(key, NullSupportHelper.NULL());
	    if (rtn != NullSupportHelper.NULL()) return t;
	}

	// get a scope value (only cfml is searcing additional scopes)
	if (pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML) {
	    for (int i = 0; i < scopes.length; i++) {
		rtn = scopes[i].get(key, NullSupportHelper.NULL());
		if (rtn != NullSupportHelper.NULL()) {
		    return scopes[i];
		}
	    }
	}
	return defaultValue;
    }
692564
public static short getMembershipScope(String scope) {
        if (scope != null) {
            scope = scope.trim();
            if (LdapConstants.LDAP_DIRECT_GROUP_MEMBERSHIP_STRING.equalsIgnoreCase(scope)) {
                return LdapConstants.LDAP_DIRECT_GROUP_MEMBERSHIP;
            } else if (LdapConstants.LDAP_NESTED_GROUP_MEMBERSHIP_STRING.equalsIgnoreCase(scope)) {
                return LdapConstants.LDAP_NESTED_GROUP_MEMBERSHIP;
            } else if (LdapConstants.LDAP_ALL_GROUP_MEMBERSHIP_STRING.equalsIgnoreCase(scope)) {
                return LdapConstants.LDAP_ALL_GROUP_MEMBERSHIP;
            } else {
                return LdapConstants.LDAP_DIRECT_GROUP_MEMBERSHIP;
            }
        } else {
            return LdapConstants.LDAP_DIRECT_GROUP_MEMBERSHIP;
        }
    }
467241
protected String getRealIdScope()
    {
        ServletRequest request = pageContext.getRequest();
        
        // default to the set idScope.
        String idScope = _idScope;

        // if there isn't a set idScope and generate scope is on, generate the scope id.
        if (_idScope == null && _genScope) {
            int id = getNextId(request);
            idScope = "n" + Integer.toString(id);
            _idScope = idScope;
        }
        
        // if there's still no idScope and we're in a ScopedRequest, use the scope-key from the request.
        if (_idScope == null) {
            ScopedRequest scopedRequest = ScopedServletUtils.unwrapRequest(request);
            if (scopedRequest != null) {
                _idScope = scopedRequest.getScopeKey().toString();
                idScope = _idScope;
            }
        }
        
        return idScope;
    }
847405
@Override
    public NGScope scope() {
        NGScope scope = NGScope.create();
        scope.put(getName(), "=");
        return scope;
    }
478455
public void setScope(java.util.Collection<String> scope) {
        if (scope == null) {
            this.scope = null;
            return;
        }

        this.scope = new java.util.ArrayList<String>(scope);
    }
1180636
public String resolvePropertyValue(final String name, final PropertyScope scope) {
        if (null == scope || scope == PropertyScope.Unspecified) {
            throw new IllegalArgumentException("scope must be specified");
        }
        String value = null;
        if (scope.isInstanceLevel()) {
            if (null != instanceScopeResolver) {
                value = instanceScopeResolver.getProperty(name);
                log.trace("resolvePropertyValue(" + scope + ")(I) " + name + " = " + value);
            }
        }
        if (null != value || scope == PropertyScope.InstanceOnly) {
            log.debug("resolvePropertyValue(" + scope + ") " + name + " = " + value);
            return value;
        }

        if (scope.isProjectLevel()) {
            if (null != projectScopeResolver) {
                value = projectScopeResolver.getProperty(name);
                log.trace("resolvePropertyValue(" + scope + ")(P) " + name + " = " + value);
            }
        }
        if (null != value || scope == PropertyScope.ProjectOnly) {
            log.debug("resolvePropertyValue(" + scope + ") " + name + " = " + value);
            return value;
        }
        if (null != frameworkScopeResolver) {
            if (scope.isFrameworkLevel()) {
                value = frameworkScopeResolver.getProperty(name);
                log.trace("resolvePropertyValue(" + scope + ")(F) " + name + " = " + value);
            }
        }
        log.debug("resolvePropertyValue(" + scope + ") " + name + " = " + value);
        return value;
    }
169458
@Benchmark
  @BenchmarkMode(Mode.AverageTime)
  @OutputTimeUnit(TimeUnit.NANOSECONDS)
  public Scope scopeSpan(Data data) {
    try (Scope scope = data.tracer.withSpan(data.spanToScope)) {
      return scope;
    }
  }