All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.painless.node.ELambda Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.elasticsearch.painless.node;

import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.phase.UserTreeVisitor;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * Lambda expression node.
 * 

* This can currently only be the direct argument of a call (method/constructor). * When the argument is of a known type, it uses * * Java's lambda translation. However, if its a def call, then we don't have * enough information, and have to defer this until link time. In that case a placeholder * and all captures are pushed onto the stack and folded into the signature of the parent call. *

* For example: *
* {@code def list = new ArrayList(); int capture = 0; list.sort((x,y) -> x - y + capture)} *
* is converted into a call (pseudocode) such as: *
* {@code sort(list, lambda$0, capture)} *
* At link time, when we know the interface type, this is decomposed with MethodHandle * combinators back into (pseudocode): *
* {@code sort(list, lambda$0(capture))} */ public class ELambda extends AExpression { private final List canonicalTypeNameParameters; private final List parameterNames; private final SBlock blockNode; public ELambda(int identifier, Location location, List canonicalTypeNameParameters, List parameterNames, SBlock blockNode) { super(identifier, location); this.canonicalTypeNameParameters = Collections.unmodifiableList(Objects.requireNonNull(canonicalTypeNameParameters)); this.parameterNames = Collections.unmodifiableList(Objects.requireNonNull(parameterNames)); this.blockNode = Objects.requireNonNull(blockNode); } public List getCanonicalTypeNameParameters() { return canonicalTypeNameParameters; } public List getParameterNames() { return parameterNames; } public SBlock getBlockNode() { return blockNode; } @Override public void visit(UserTreeVisitor userTreeVisitor, Scope scope) { userTreeVisitor.visitLambda(this, scope); } @Override public void visitChildren(UserTreeVisitor userTreeVisitor, Scope scope) { blockNode.visit(userTreeVisitor, scope); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy