dataflow.src.org.checkerframework.dataflow.cfg.block.ExceptionBlockImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checker Show documentation
Show all versions of checker Show documentation
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.
package org.checkerframework.dataflow.cfg.block;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.lang.model.type.TypeMirror;
import org.checkerframework.dataflow.cfg.node.Node;
/**
* Base class of the {@link Block} implementation hierarchy.
*
* @author Stefan Heule
*
*/
public class ExceptionBlockImpl extends SingleSuccessorBlockImpl implements
ExceptionBlock {
/** Set of exceptional successors. */
protected Map> exceptionalSuccessors;
public ExceptionBlockImpl() {
type = BlockType.EXCEPTION_BLOCK;
exceptionalSuccessors = new HashMap<>();
}
/** The node of this block. */
protected Node node;
/**
* Set the node.
*/
public void setNode(Node c) {
node = c;
c.setBlock(this);
}
@Override
public Node getNode() {
return node;
}
/**
* Add an exceptional successor.
*/
public void addExceptionalSuccessor(BlockImpl b,
TypeMirror cause) {
if (exceptionalSuccessors == null) {
exceptionalSuccessors = new HashMap<>();
}
Set blocks = exceptionalSuccessors.get(cause);
if (blocks == null) {
blocks = new HashSet();
exceptionalSuccessors.put(cause, blocks);
}
blocks.add(b);
b.addPredecessor(this);
}
@Override
public Map> getExceptionalSuccessors() {
if (exceptionalSuccessors == null) {
return Collections.emptyMap();
}
return Collections.unmodifiableMap(exceptionalSuccessors);
}
@Override
public String toString() {
return "ExceptionBlock(" + node + ")";
}
}