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.

Translator.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. package javassist;
  17. /**
  18. * An observer of <code>Loader</code>.
  19. * The users can define a class implementing this
  20. * interface and attach an instance of that class to a
  21. * <code>Loader</code> object so that it can translate a class file
  22. * when the class file is loaded into the JVM.
  23. *
  24. * @see Loader#addTranslator(ClassPool, Translator)
  25. */
  26. public interface Translator {
  27. /**
  28. * Is invoked by a <code>Loader</code> for initialization
  29. * when the object is attached to the <code>Loader</code> object.
  30. * This method can be used for getting (for caching) some
  31. * <code>CtClass</code> objects that will be accessed
  32. * in <code>onLoad()</code> in <code>Translator</code>.
  33. *
  34. * @param pool the <code>ClassPool</code> that this translator
  35. * should use.
  36. * @see Loader
  37. * @throws NotFoundException if a <code>CtClass</code> cannot be found.
  38. * @throws CannotCompileException if the initialization by this method
  39. * fails.
  40. */
  41. void start(ClassPool pool)
  42. throws NotFoundException, CannotCompileException;
  43. /**
  44. * Is invoked by a <code>Loader</code> for notifying that
  45. * a class is loaded. The <code>Loader</code> calls
  46. *
  47. * <pre>
  48. * pool.get(classname).toBytecode()</pre>
  49. *
  50. * to read the class file after <code>onLoad()</code> returns.
  51. *
  52. * <p><code>classname</code> may be the name of a class
  53. * that has not been created yet.
  54. * If so, <code>onLoad()</code> must create that class so that
  55. * the <code>Loader</code> can read it after <code>onLoad()</code>
  56. * returns.
  57. *
  58. * @param pool the <code>ClassPool</code> that this translator
  59. * should use.
  60. * @param classname the name of the class being loaded.
  61. * @see Loader
  62. * @throws NotFoundException if a <code>CtClass</code> cannot be found.
  63. * @throws CannotCompileException if the code transformation
  64. * by this method fails.
  65. */
  66. void onLoad(ClassPool pool, String classname)
  67. throws NotFoundException, CannotCompileException;
  68. }