/plugins/JavaSideKick/tags/javasidekick-2-1-1/src/sidekick/java/node/Results.java

# · Java · 116 lines · 48 code · 19 blank · 49 comment · 0 complexity · f33100607ff49b4538ae505a2f36e825 MD5 · raw file

  1. /*
  2. Copyright (c) 2005, Dale Anson
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without modification,
  5. are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. * Neither the name of the <ORGANIZATION> nor the names of its contributors
  12. may be used to endorse or promote products derived from this software without
  13. specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. package sidekick.java.node;
  26. /**
  27. * Accumulates the count of specific node types, that is, this keeps a count
  28. * of the number of classed, interfaces, methods, and fields that the parser
  29. * found.
  30. */
  31. public class Results {
  32. // Parse Counters
  33. private int classCount = 0;
  34. private int interfaceCount = 0;
  35. private int methodCount = 0;
  36. private int referenceFieldCount = 0; // count of fields that are some sort of Object, not a primitive
  37. private int primitiveFieldCount = 0; // count of fields that are some sort of primitive, i.e. int, char, etc.
  38. // Accessor Methods
  39. public int getClassCount() {
  40. return classCount;
  41. }
  42. public int getInterfaceCount() {
  43. return interfaceCount;
  44. }
  45. public int getMethodCount() {
  46. return methodCount;
  47. }
  48. public int getReferenceFieldCount() {
  49. return referenceFieldCount;
  50. }
  51. public int getPrimitiveFieldCount() {
  52. return primitiveFieldCount;
  53. }
  54. // Increment
  55. public void incClassCount() {
  56. classCount++;
  57. }
  58. public void incInterfaceCount() {
  59. interfaceCount++;
  60. }
  61. /**
  62. * Used to count methods
  63. */
  64. public void incMethodCount() {
  65. methodCount++;
  66. }
  67. /**
  68. * Used to count fields that are Objects, for example, <code>public static String DAY = "day";</code>
  69. */
  70. public void incReferenceFieldCount() {
  71. referenceFieldCount++;
  72. }
  73. /**
  74. * Used to count fields that are primitives, for example, <code>private static int x = 2;</code>
  75. */
  76. public void incPrimitiveFieldCount() {
  77. primitiveFieldCount++;
  78. }
  79. /**
  80. * This method resets all the result variables to their initial state,
  81. * i.e. all counts to 0, in anticipation of performing a new parse
  82. * which will use the result object to count what it finds.
  83. */
  84. void reset() {
  85. classCount = 0;
  86. interfaceCount = 0;
  87. methodCount = 0;
  88. referenceFieldCount = 0;
  89. primitiveFieldCount = 0;
  90. }
  91. public String toString() {
  92. return " Classes: " + classCount + ", Interfaces: " + interfaceCount + ", Methods: " + methodCount + ", Fields: " + (referenceFieldCount + primitiveFieldCount);
  93. }
  94. }