169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/* 269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Javassist, a Java-bytecode translator toolkit. 369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Copyright (C) 1999-2007 Shigeru Chiba. All Rights Reserved. 469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * The contents of this file are subject to the Mozilla Public License Version 669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1.1 (the "License"); you may not use this file except in compliance with 769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the License. Alternatively, the contents of this file may be used under 869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the terms of the GNU Lesser General Public License Version 2.1 or later. 969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Software distributed under the License is distributed on an "AS IS" basis, 1169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 1269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * for the specific language governing rights and limitations under the 1369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * License. 1469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 1569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 1669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpackage javassist.expr; 1769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 1869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport javassist.CtClass; 1969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport javassist.CtConstructor; 2069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport javassist.CtMethod; 2169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport javassist.NotFoundException; 2269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport javassist.bytecode.CodeIterator; 2369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport javassist.bytecode.MethodInfo; 2469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 2569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/** 2669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Constructor call such as <code>this()</code> and <code>super()</code> 2769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * within a constructor body. 2869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 2969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @see NewExpr 3069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 3169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpublic class ConstructorCall extends MethodCall { 3269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 3369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Undocumented constructor. Do not use; internal-use only. 3469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 3569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal protected ConstructorCall(int pos, CodeIterator i, CtClass decl, MethodInfo m) { 3669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal super(pos, i, decl, m); 3769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 3869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 3969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 4069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns <code>"super"</code> or "<code>"this"</code>. 4169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 4269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public String getMethodName() { 4369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return isSuper() ? "super" : "this"; 4469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 4569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 4669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 4769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Always throws a <code>NotFoundException</code>. 4869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 4969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @see #getConstructor() 5069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 5169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public CtMethod getMethod() throws NotFoundException { 5269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal throw new NotFoundException("this is a constructor call. Call getConstructor()."); 5369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 5469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 5569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 5669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns the called constructor. 5769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 5869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public CtConstructor getConstructor() throws NotFoundException { 5969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return getCtClass().getConstructor(getSignature()); 6069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 6169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 6269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 6369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns true if the called constructor is not <code>this()</code> 6469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * but <code>super()</code> (a constructor declared in the super class). 6569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 6669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public boolean isSuper() { 6769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return super.isSuper(); 6869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 6969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal} 70