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.

Helper.java 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package symbols;
  2. import org.aspectj.testing.Tester;
  3. import org.aspectj.tools.ide.SymbolManager;
  4. import org.aspectj.tools.ide.SourceLine;
  5. import org.aspectj.tools.ide.Declaration;
  6. import java.io.File;
  7. import java.util.StringTokenizer;
  8. public class Helper {
  9. public final SymbolManager sm = SymbolManager.getSymbolManager();
  10. public String file(String fn) {
  11. return new File(new File("symbols"),fn).getAbsolutePath();
  12. }
  13. public boolean allDecsFound = true;
  14. public Declaration getDecl(String fn, int ln) {
  15. Declaration dec = sm.getDeclarationAtLine(file(fn), ln);
  16. if (dec == null) {
  17. allDecsFound = false;
  18. Tester.checkFailed("Declaration at "+fn+":"+ln+" not found");
  19. }
  20. return dec;
  21. }
  22. public void checkPos(Declaration dec, int line1, int col1, int line2, int col2, String fname) {
  23. if (dec == null) return;
  24. Tester.checkEqual(dec.getBeginLine(), line1, "wrond begin line of "+getName(dec));
  25. Tester.checkEqual(dec.getEndLine(), line2, "wrond end line of "+getName(dec));
  26. Tester.checkEqual(dec.getBeginColumn(),col1, "wrond begin column of "+getName(dec));
  27. Tester.checkEqual(dec.getEndColumn(), col2, "wrond end column of "+getName(dec));
  28. Tester.checkEqual(dec.getFilename(), file(fname), "wrond file name of "+getName(dec));
  29. }
  30. public void checkKind(Declaration dec, String kind) {
  31. if (dec == null) return;
  32. Tester.checkEqual(dec.getKind(),kind,"kinds differ");
  33. }
  34. public void checkSignature(Declaration dec, String sig, String fsig) {
  35. if (dec == null) return;
  36. String dsig = dec.getSignature();
  37. String dfsig = dec.getFullSignature();
  38. if (dsig != null) {
  39. dsig = dsig.trim();
  40. if (dsig.startsWith("/*") && dsig.endsWith("*/")) dsig = "";
  41. }
  42. if (dfsig != null) {
  43. dfsig = dfsig.trim();
  44. if (dfsig.startsWith("/*") && dfsig.endsWith("*/")) dfsig = "";
  45. }
  46. Tester.checkEqual(dsig,sig,"signatures of '"+getName(dec)+"' differ");
  47. Tester.checkEqual(dfsig,fsig,"full signatures of '"+getName(dec)+"' differ");
  48. }
  49. public void checkFormalComment(Declaration dec, String comment) {
  50. if (dec == null) return;
  51. String fc = dec.getFormalComment();
  52. if (fc != null) fc = fc.trim();
  53. //Tester.checkEqual(fc,comment,"formal comment differ");
  54. }
  55. public void checkPointsNothing(Declaration dec) {
  56. if (dec == null) return;
  57. Declaration[] points = dec.getPointsTo();
  58. if (points == null) {
  59. Tester.checkFailed(".getPointsTo() for Declaration of "+getName(dec)+" returns 'null'");
  60. return;
  61. }
  62. for (int i=0; i < points.length; i++) {
  63. Tester.checkFailed("unexpected that "+getName(dec)+" points to "+getName(points[i]));
  64. }
  65. }
  66. public void checkPointsTo(Declaration dec, Declaration[] expected) {
  67. if (dec == null) return;
  68. Declaration[] points = dec.getPointsTo();
  69. if (points == null) {
  70. Tester.checkFailed(".getPointsTo() for Declaration of "+getName(dec)+" returns 'null'");
  71. return;
  72. }
  73. int i, j;
  74. for (i=0; i < expected.length; i++) {
  75. if (expected[i] == null) {
  76. Tester.checkFailed("array element ["+i+"] of expected 'points to' declarations of "+getName(dec)+" contains 'null'");
  77. continue;
  78. }
  79. for (j=0; j < points.length; j++) {
  80. if (expected[i].equals(points[j])) break;
  81. }
  82. if (j >= points.length)
  83. Tester.checkFailed("expected that "+getName(dec)+" points to "+getName(expected[i]));
  84. }
  85. for (i=0; i < points.length; i++) {
  86. if (points[i] == null) {
  87. Tester.checkFailed(".getPointsTo() array element ["+i+"] of declaration "+getName(dec)+" contains 'null'");
  88. continue;
  89. }
  90. for (j=0; j < expected.length; j++) {
  91. if (points[i].equals(expected[j])) break;
  92. }
  93. if (j >= expected.length)
  94. Tester.checkFailed("unexpected that "+getName(dec)+" points to "+getName(points[i]));
  95. }
  96. }
  97. public void checkPointedToByNone(Declaration dec) {
  98. if (dec == null) return;
  99. Declaration[] pointed = dec.getPointedToBy();
  100. if (pointed == null) {
  101. Tester.checkFailed(".getPointedToBy() for Declaration of "+getName(dec)+" returns 'null'");
  102. return;
  103. }
  104. for (int i=0; i < pointed.length; i++) {
  105. Tester.checkFailed("unexpected that "+getName(dec)+" pointed by "+getName(pointed[i]));
  106. }
  107. }
  108. public void checkPointedToBy(Declaration dec, Declaration[] expected) {
  109. if (dec == null) return;
  110. Declaration[] pointed = dec.getPointedToBy();
  111. if (pointed == null) {
  112. Tester.checkFailed(".getPointedToBy() for Declaration of "+getName(dec)+" returns 'null'");
  113. return;
  114. }
  115. int i, j;
  116. for (i=0; i < expected.length; i++) {
  117. if (expected[i] == null) {
  118. Tester.checkFailed("array element ["+i+"] of expected 'pointed to by' declarations of "+getName(dec)+" contains 'null'");
  119. continue;
  120. }
  121. for (j=0; j < pointed.length; j++) {
  122. if (pointed[j].equals(expected[i])) break;
  123. }
  124. if (j >= pointed.length)
  125. Tester.checkFailed("expected that "+getName(dec)+" pointed to by "+getName(expected[i]));
  126. }
  127. for (i=0; i < pointed.length; i++) {
  128. if (pointed[i] == null) {
  129. Tester.checkFailed(".getPointedToBy() array element ["+i+"] of declaration "+getName(dec)+" contains 'null'");
  130. continue;
  131. }
  132. for (j=0; j < expected.length; j++) {
  133. if (pointed[i].equals(expected[j])) break;
  134. }
  135. if (j >= expected.length)
  136. Tester.checkFailed("unexpected that "+getName(dec)+" pointed to by "+getName(pointed[i]));
  137. }
  138. }
  139. public void checkModifiers(Declaration dec, String expected_modifiers) {
  140. if (dec == null) return;
  141. StringTokenizer st = new StringTokenizer(expected_modifiers);
  142. String[] expected = new String[st.countTokens()];
  143. for(int i=0; i < expected.length; i++) expected[i] = st.nextToken();
  144. st = new StringTokenizer(dec.getModifiers());
  145. String[] modifiers = new String[st.countTokens()];
  146. for(int i=0; i < modifiers.length; i++) modifiers[i] = st.nextToken();
  147. int i, j;
  148. for (i=0; i < expected.length; i++) {
  149. for (j=0; j < modifiers.length; j++) {
  150. if (modifiers[j].equals(expected[i])) break;
  151. }
  152. if (j >= modifiers.length)
  153. Tester.checkFailed("expected that "+getName(dec)+" has modifier "+expected[i]);
  154. }
  155. for (i=0; i < modifiers.length; i++) {
  156. for (j=0; j < expected.length; j++) {
  157. if (modifiers[i].equals(expected[j])) break;
  158. }
  159. if (j >= expected.length)
  160. Tester.checkFailed("unexpected that "+getName(dec)+" has modifier "+modifiers[i]);
  161. }
  162. }
  163. public void checkAllDecsOf(Declaration dec, Declaration[] decs) {
  164. Declaration[] sdecs = dec.getDeclarations();
  165. if (sdecs == null) {
  166. Tester.checkFailed("unexpected that 'getDeclarations' for "+getName(dec)+" returned 'null'");
  167. return;
  168. }
  169. int i, j;
  170. for (i=0; i < decs.length; i++) {
  171. if (decs[i] == null) continue;
  172. for (j=0; j < sdecs.length; j++) {
  173. if (decs[j].equals(sdecs[i])) break;
  174. }
  175. if (j >= sdecs.length)
  176. Tester.checkFailed("expected that "+getName(dec)+" contains "+getName(decs[i]));
  177. }
  178. for (i=0; i < sdecs.length; i++) {
  179. if (sdecs[i] == null) continue;
  180. for (j=0; j < decs.length; j++) {
  181. if (sdecs[i].equals(decs[j])) break;
  182. }
  183. if (j >= decs.length)
  184. Tester.checkFailed("unexpected that "+getName(dec)+" contains "+getName(sdecs[i]));
  185. }
  186. }
  187. private static String getName(Declaration dec) {
  188. if (dec == null) return "<null>";
  189. String name = dec.getSignature();
  190. if (name != null && name.length() > 0) return name + "(" + getFilePos(dec) + ")";
  191. name = dec.getKind() + " at " + getFilePos(dec);
  192. return name;
  193. }
  194. private static String getFilePos(Declaration dec) {
  195. String longFileName = dec.getFilename();
  196. if (longFileName == null) return "?.java:" + dec.getBeginLine();
  197. int pos = longFileName.lastIndexOf('/');
  198. if (pos < 0) pos = longFileName.lastIndexOf('\\');
  199. if (pos < 0) return longFileName + ":" + dec.getBeginLine();
  200. return longFileName.substring(pos+1) + ":" + dec.getBeginLine();
  201. }
  202. }