Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Licensed 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 com.facebook.presto.sql.planner;
Extracts and returns the set of all expression subtrees within an Expression, including Expression itself
public final class SubExpressionExtractor
    private SubExpressionExtractor() {}
    public static List<ExpressionextractAll(Iterable<Expressionexpressions)
    {
        ImmutableList.Builder<Expressionbuilder = ImmutableList.builder();
        for (Expression expression : expressions) {
            extract(builderexpression);
        }
        return builder.build();
    }
    public static List<ExpressionextractAll(Expression expression)
    {
        ImmutableList.Builder<Expressionbuilder = ImmutableList.builder();
        extract(builderexpression);
        return builder.build();
    }
    public static Set<Expressionextract(Expression expression)
    {
        final ImmutableSet.Builder<Expressionbuilder = ImmutableSet.builder();
        extract(builderexpression);
        return builder.build();
    }
    private static void extract(final ImmutableCollection.Builder<ExpressionbuilderExpression expression)
    {
        new DefaultTraversalVisitor<VoidVoid>()
        {
            @Override
            public Void process(Node node, @Nullable Void context)
            {
                Expression expression = (Expressionnode;
                builder.add(expression);
                return super.process(nodecontext);
            }
        }.process(expressionnull);
    }
New to GrepCode? Check out our FAQ X