1/*
2 * Javassist, a Java-bytecode translator toolkit.
3 * Copyright (C) 1999-2007 Shigeru Chiba. 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 */
15
16package javassist.expr;
17
18import javassist.CtClass;
19import javassist.CtConstructor;
20import javassist.CtMethod;
21import javassist.NotFoundException;
22import javassist.bytecode.CodeIterator;
23import javassist.bytecode.MethodInfo;
24
25/**
26 * Constructor call such as <code>this()</code> and <code>super()</code>
27 * within a constructor body.
28 *
29 * @see NewExpr
30 */
31public class ConstructorCall extends MethodCall {
32    /**
33     * Undocumented constructor.  Do not use; internal-use only.
34     */
35    protected ConstructorCall(int pos, CodeIterator i, CtClass decl, MethodInfo m) {
36        super(pos, i, decl, m);
37    }
38
39    /**
40     * Returns <code>"super"</code> or "<code>"this"</code>.
41     */
42    public String getMethodName() {
43        return isSuper() ? "super" : "this";
44    }
45
46    /**
47     * Always throws a <code>NotFoundException</code>.
48     *
49     * @see #getConstructor()
50     */
51    public CtMethod getMethod() throws NotFoundException {
52        throw new NotFoundException("this is a constructor call.  Call getConstructor().");
53    }
54
55    /**
56     * Returns the called constructor.
57     */
58    public CtConstructor getConstructor() throws NotFoundException {
59        return getCtClass().getConstructor(getSignature());
60    }
61
62    /**
63     * Returns true if the called constructor is not <code>this()</code>
64     * but <code>super()</code> (a constructor declared in the super class).
65     */
66    public boolean isSuper() {
67        return super.isSuper();
68    }
69}
70