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

org.checkerframework.dataflow.cfg.node.ObjectCreationNode 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.NewClassTree;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.javacutil.TreeUtils;
import org.plumelib.util.StringsPlume;

/**
 * A node for new object creation.
 *
 * 
 *   new constructor(arg1, arg2, ...)
 * 
*/ public class ObjectCreationNode extends Node { protected final NewClassTree tree; protected final Node constructor; protected final List arguments; // Class body for anonymous classes, otherwise null. protected final @Nullable ClassDeclarationNode classbody; public ObjectCreationNode( NewClassTree tree, Node constructor, List arguments, @Nullable ClassDeclarationNode classbody) { super(TreeUtils.typeOf(tree)); this.tree = tree; this.constructor = constructor; this.arguments = arguments; this.classbody = classbody; } public Node getConstructor() { return constructor; } public List getArguments() { return arguments; } public Node getArgument(int i) { return arguments.get(i); } public @Nullable Node getClassBody() { return classbody; } @Override public NewClassTree getTree() { return tree; } @Override public R accept(NodeVisitor visitor, P p) { return visitor.visitObjectCreation(this, p); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("new " + constructor + "("); sb.append(StringsPlume.join(", ", arguments)); sb.append(")"); if (classbody != null) { // TODO: maybe this can be done nicer... sb.append(" "); sb.append(classbody.toString()); } return sb.toString(); } @Override public boolean equals(@Nullable Object obj) { if (!(obj instanceof ObjectCreationNode)) { return false; } ObjectCreationNode other = (ObjectCreationNode) obj; if (constructor == null && other.getConstructor() != null) { return false; } return getConstructor().equals(other.getConstructor()) && getArguments().equals(other.getArguments()); } @Override public int hashCode() { return Objects.hash(constructor, arguments); } @Override public Collection getOperands() { ArrayList list = new ArrayList<>(1 + arguments.size()); list.add(constructor); list.addAll(arguments); return list; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy