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

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