Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Cflow.java 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.runtime;
  17. /**
  18. * A support class for implementing <code>$cflow</code>.
  19. * This support class is required at runtime
  20. * only if <code>$cflow</code> is used.
  21. *
  22. * @see javassist.CtBehavior#useCflow(String)
  23. */
  24. public class Cflow extends ThreadLocal<Cflow.Depth> {
  25. protected static class Depth {
  26. private int depth;
  27. Depth() { depth = 0; }
  28. int value() { return depth; }
  29. void inc() { ++depth; }
  30. void dec() { --depth; }
  31. }
  32. @Override
  33. protected synchronized Depth initialValue() {
  34. return new Depth();
  35. }
  36. /**
  37. * Increments the counter.
  38. */
  39. public void enter() { get().inc(); }
  40. /**
  41. * Decrements the counter.
  42. */
  43. public void exit() { get().dec(); }
  44. /**
  45. * Returns the value of the counter.
  46. */
  47. public int value() { return get().value(); }
  48. }