1/*
2 * Javassist, a Java-bytecode translator toolkit.
3 * Copyright (C) 1999-2007 Shigeru Chiba, and others. All Rights Reserved.
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License.  Alternatively, the contents of this file may be used under
8 * the terms of the GNU Lesser General Public License Version 2.1 or later.
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 */
15package javassist.bytecode.analysis;
16
17import java.util.ArrayList;
18import java.util.Collection;
19import java.util.HashSet;
20import java.util.List;
21import java.util.Set;
22
23/**
24 * Represents a nested method subroutine (marked by JSR and RET).
25 *
26 * @author Jason T. Greene
27 */
28public class Subroutine {
29    //private Set callers = new HashSet();
30    private List callers = new ArrayList();
31    private Set access = new HashSet();
32    private int start;
33
34    public Subroutine(int start, int caller) {
35        this.start = start;
36        callers.add(new Integer(caller));
37    }
38
39    public void addCaller(int caller) {
40        callers.add(new Integer(caller));
41    }
42
43    public int start() {
44        return start;
45    }
46
47    public void access(int index) {
48        access.add(new Integer(index));
49    }
50
51    public boolean isAccessed(int index) {
52        return access.contains(new Integer(index));
53    }
54
55    public Collection accessed() {
56        return access;
57    }
58
59    public Collection callers() {
60        return callers;
61    }
62
63    public String toString() {
64        return "start = " + start + " callers = " + callers.toString();
65    }
66}