You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConstructorCall.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package javassist.expr;
  2. import javassist.CtClass;
  3. import javassist.CtConstructor;
  4. import javassist.CtMethod;
  5. import javassist.NotFoundException;
  6. import javassist.bytecode.CodeIterator;
  7. import javassist.bytecode.MethodInfo;
  8. /**
  9. * Constructor call such as <code>this()</code> and <code>super()</code>
  10. * within a constructor body.
  11. *
  12. * @see NewExpr
  13. */
  14. public class ConstructorCall extends MethodCall {
  15. /**
  16. * Undocumented constructor. Do not use; internal-use only.
  17. */
  18. protected ConstructorCall(int pos, CodeIterator i, CtClass decl, MethodInfo m) {
  19. super(pos, i, decl, m);
  20. }
  21. /**
  22. * Returns <code>"super"</code> or "<code>"this"</code>.
  23. */
  24. public String getMethodName() {
  25. return isSuper() ? "super" : "this";
  26. }
  27. /**
  28. * Always throws a <code>NotFoundException</code>.
  29. *
  30. * @see #getConstructor()
  31. */
  32. public CtMethod getMethod() throws NotFoundException {
  33. throw new NotFoundException("this is a constructor call. Call getConstructor().");
  34. }
  35. /**
  36. * Returns the called constructor.
  37. */
  38. public CtConstructor getConstructor() throws NotFoundException {
  39. return getCtClass().getConstructor(getSignature());
  40. }
  41. /**
  42. * Returns true if the called constructor is not <code>this()</code>
  43. * but <code>super()</code> (a constructor declared in the super class).
  44. */
  45. public boolean isSuper() {
  46. return super.isSuper();
  47. }
  48. }