Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.testingutil;
  14. import org.aspectj.util.LangUtil;
  15. import java.lang.reflect.Array;
  16. import java.util.ArrayList;
  17. import java.util.LinkedList;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.SortedSet;
  21. import java.util.StringTokenizer;
  22. import java.util.TreeSet;
  23. /**
  24. * This is source for a sample .class file.
  25. * It is compiled and the corresponding .class files are
  26. * checked in under the testdata directory.
  27. * It has no other purpose.
  28. */
  29. public class TestCompareClassFile implements Runnable {
  30. public static final String STATIC_CONST = "STATIC_CONST";
  31. public static void main(String[] args) {
  32. // tc static references
  33. long l = Math.abs(System.currentTimeMillis());
  34. String s = STATIC_CONST + " is constant";
  35. }
  36. public static void runStatic() {
  37. }
  38. private static void privateRunStatic() {
  39. }
  40. static void defaultRunStatic() {
  41. }
  42. protected static void protectedRunStatic() {
  43. }
  44. private long privateLong;
  45. private final Object privateFinalObject;
  46. private TestCompareClassFile() {
  47. super();
  48. privateLong = System.currentTimeMillis();
  49. // method-local inner class
  50. privateFinalObject = new Runnable() { public void run(){}};
  51. }
  52. /** implement Runnable */
  53. public void run() {
  54. }
  55. private void privateRun() {
  56. }
  57. void defaultRun() {
  58. }
  59. protected void protectedRun() {
  60. }
  61. // ------- misc stolen utility code
  62. // Collections Util
  63. public static List getListInMap(Map map, Object key) {
  64. List list = (List)map.get(key);
  65. if (list == null) {
  66. list = new ArrayList();
  67. map.put(key, list);
  68. }
  69. return list;
  70. }
  71. public static SortedSet getSortedSetInMap(Map map, Object key) {
  72. SortedSet list = (SortedSet)map.get(key);
  73. if (list == null) {
  74. list = new TreeSet();
  75. map.put(key, list);
  76. }
  77. return list;
  78. }
  79. // LangUtil
  80. /**
  81. * Make a copy of the array.
  82. * @return an array with the same component type as source
  83. * containing same elements, even if null.
  84. * @throws IllegalArgumentException if source is null
  85. */
  86. public static final Object[] copy(Object[] source) {
  87. final Class c = source.getClass().getComponentType();
  88. Object[] result = (Object[]) Array.newInstance(c, source.length);
  89. System.arraycopy(source, 0, result, 0, result.length);
  90. return result;
  91. }
  92. /**
  93. * Trim ending lines from a StringBuffer,
  94. * clipping to maxLines and further removing any number of
  95. * trailing lines accepted by checker.
  96. * @param stack StringBuffer with lines to elide
  97. * @param maxLines int for maximum number of resulting lines
  98. */
  99. static void elideEndingLines(StringBuffer stack, int maxLines) {
  100. if ((null == stack) || (0 == stack.length())) {
  101. return;
  102. }
  103. final LinkedList lines = new LinkedList();
  104. StringTokenizer st = new StringTokenizer(stack.toString(),"\n\r");
  105. while (st.hasMoreTokens() && (0 < --maxLines)) {
  106. lines.add(st.nextToken());
  107. }
  108. st = null;
  109. String line;
  110. int elided = 0;
  111. while (!lines.isEmpty()) {
  112. line = (String) lines.getLast();
  113. if (null == line) {
  114. break;
  115. } else {
  116. elided++;
  117. lines.removeLast();
  118. }
  119. }
  120. if ((elided > 0) || (maxLines < 1)) {
  121. final int EOL_LEN = LangUtil.EOL.length();
  122. int totalLength = 0;
  123. while (!lines.isEmpty()) {
  124. totalLength += EOL_LEN + ((String) lines.getFirst()).length();
  125. lines.removeFirst();
  126. }
  127. if (stack.length() > totalLength) {
  128. stack.setLength(totalLength);
  129. if (elided > 0) {
  130. stack.append(" (... " + elided + " lines...)");
  131. }
  132. }
  133. }
  134. }
  135. }