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

org.checkerframework.dataflow.cfg.node.LambdaResultExpressionNode Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java's type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.43.0
Show newest version
package org.checkerframework.dataflow.cfg.node;

import com.sun.source.tree.ExpressionTree;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.javacutil.TreeUtils;

/** A node for the single expression body of a single expression lambda. */
public class LambdaResultExpressionNode extends Node {

  /** Tree for the lambda expression body. */
  protected final ExpressionTree tree;

  /** Final CFG node corresponding to the lambda expression body. */
  protected final Node result;

  /**
   * Creates a LambdaResultExpressionNode.
   *
   * @param t tree for the lambda expression body
   * @param result final CFG node corresponding to the lambda expression body
   */
  public LambdaResultExpressionNode(ExpressionTree t, Node result) {
    super(TreeUtils.typeOf(t));
    this.result = result;
    tree = t;
  }

  /**
   * Returns the final node of the CFG corresponding to the lambda expression body (see {@link
   * #getTree()}).
   *
   * @return the final node of the CFG corresponding to the lambda expression body
   */
  public Node getResult() {
    return result;
  }

  /**
   * Returns the {@link ExpressionTree} corresponding to the body of a lambda expression with an
   * expression body (e.g. X for ({@code o -> X}) where X is an expression and not a {...} block).
   *
   * @return the {@link ExpressionTree} corresponding to the body of a lambda expression with an
   *     expression body
   */
  @Override
  public ExpressionTree getTree() {
    return tree;
  }

  @Override
  public  R accept(NodeVisitor visitor, P p) {
    return visitor.visitLambdaResultExpression(this, p);
  }

  @Override
  public String toString() {
    return "-> " + result;
  }

  @Override
  public boolean equals(@Nullable Object obj) {
    // No need to compare tree, since in a well-formed LambdaResultExpressionNode, result will
    // be the same only when tree is the same (this is similar to ReturnNode).
    if (!(obj instanceof LambdaResultExpressionNode)) {
      return false;
    }
    LambdaResultExpressionNode other = (LambdaResultExpressionNode) obj;
    return Objects.equals(result, other.result);
  }

  @Override
  public int hashCode() {
    // No need to incorporate tree, since in a well-formed LambdaResultExpressionNode, result
    // will be the same only when tree is the same (this is similar to ReturnNode).
    return Objects.hash(LambdaResultExpressionNode.class, result);
  }

  @Override
  public Collection getOperands() {
    return Collections.singletonList(result);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy