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

org.checkerframework.dataflow.cfg.node.ArrayCreationNode 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.44.0
Show newest version
package org.checkerframework.dataflow.cfg.node;

import com.sun.source.tree.NewArrayTree;
import com.sun.source.tree.Tree;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import javax.lang.model.type.TypeMirror;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.plumelib.util.StringsPlume;

/**
 * A node for new array creation.
 *
 * 
 *   new type[1][2]
 *   new type[] = { expr1, expr2, ... }
 * 
*/ public class ArrayCreationNode extends Node { /** The tree is null when an array is created for variable arity method calls. */ protected final @Nullable NewArrayTree tree; /** * The length of this list is the number of dimensions in the array. Each element is the size of * the given dimension. It can be empty if initializers is non-empty, as in {@code new SomeType[] * = { expr1, expr2, ... }}. */ protected final List dimensions; protected final List initializers; public ArrayCreationNode( @Nullable NewArrayTree tree, TypeMirror type, List dimensions, List initializers) { super(type); this.tree = tree; this.dimensions = dimensions; this.initializers = initializers; } public List getDimensions() { return dimensions; } public Node getDimension(int i) { return dimensions.get(i); } public List getInitializers() { return initializers; } public Node getInitializer(int i) { return initializers.get(i); } @Override public @Nullable Tree getTree() { return tree; } @Override public R accept(NodeVisitor visitor, P p) { return visitor.visitArrayCreation(this, p); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("new " + type); if (!dimensions.isEmpty()) { sb.append(" ("); sb.append(StringsPlume.join(", ", dimensions)); sb.append(")"); } if (!initializers.isEmpty()) { sb.append(" = {"); sb.append(StringsPlume.join(", ", initializers)); sb.append("}"); } return sb.toString(); } @Override public boolean equals(@Nullable Object obj) { if (!(obj instanceof ArrayCreationNode)) { return false; } ArrayCreationNode other = (ArrayCreationNode) obj; return getDimensions().equals(other.getDimensions()) && getInitializers().equals(other.getInitializers()); } @Override public int hashCode() { return Objects.hash(dimensions, initializers); } @Override public Collection getOperands() { ArrayList list = new ArrayList<>(dimensions.size() + initializers.size()); list.addAll(dimensions); list.addAll(initializers); return list; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy