• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 1999- 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  * or the Apache License Version 2.0.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  */
16 
17 package javassist.expr;
18 
19 import javassist.CtClass;
20 import javassist.CtConstructor;
21 import javassist.CtMethod;
22 import javassist.NotFoundException;
23 import javassist.bytecode.CodeIterator;
24 import javassist.bytecode.MethodInfo;
25 
26 /**
27  * Constructor call such as <code>this()</code> and <code>super()</code>
28  * within a constructor body.
29  *
30  * @see NewExpr
31  */
32 public class ConstructorCall extends MethodCall {
33     /**
34      * Undocumented constructor.  Do not use; internal-use only.
35      */
ConstructorCall(int pos, CodeIterator i, CtClass decl, MethodInfo m)36     protected ConstructorCall(int pos, CodeIterator i, CtClass decl, MethodInfo m) {
37         super(pos, i, decl, m);
38     }
39 
40     /**
41      * Returns <code>"super"</code> or "<code>"this"</code>.
42      */
43     @Override
getMethodName()44     public String getMethodName() {
45         return isSuper() ? "super" : "this";
46     }
47 
48     /**
49      * Always throws a <code>NotFoundException</code>.
50      *
51      * @see #getConstructor()
52      */
53     @Override
getMethod()54     public CtMethod getMethod() throws NotFoundException {
55         throw new NotFoundException("this is a constructor call.  Call getConstructor().");
56     }
57 
58     /**
59      * Returns the called constructor.
60      */
getConstructor()61     public CtConstructor getConstructor() throws NotFoundException {
62         return getCtClass().getConstructor(getSignature());
63     }
64 
65     /**
66      * Returns true if the called constructor is not <code>this()</code>
67      * but <code>super()</code> (a constructor declared in the super class).
68      */
69     @Override
isSuper()70     public boolean isSuper() {
71         return super.isSuper();
72     }
73 }
74