aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/checker_framework_dataflow/java/org/checkerframework/dataflow/cfg/block/ExceptionBlockImpl.java
blob: 2148e060cd32a9448b311ac02b83910455b55755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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<TypeMirror, Set<Block>> 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<Block> blocks = exceptionalSuccessors.get(cause);
        if (blocks == null) {
            blocks = new HashSet<Block>();
            exceptionalSuccessors.put(cause, blocks);
        }
        blocks.add(b);
        b.addPredecessor(this);
    }

    @Override
    public Map<TypeMirror, Set<Block>> getExceptionalSuccessors() {
        if (exceptionalSuccessors == null) {
            return Collections.emptyMap();
        }
        return Collections.unmodifiableMap(exceptionalSuccessors);
    }

    @Override
    public String toString() {
        return "ExceptionBlock(" + node + ")";
    }

}