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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (c) 2005 Contributors
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Created on 25.03.2005
  10. *
  11. * Contributors
  12. * Oliver Boehm initial implementation
  13. */
  14. import java.io.Serializable;
  15. import org.aspectj.lang.annotation.SuppressAjWarnings;
  16. /**
  17. * Test Aspect to check the different Xlint warnings
  18. */
  19. aspect XlintTest {
  20. /*
  21. * examples for "invalidAbsoluteTypeName"
  22. */
  23. pointcut correctName() :
  24. call(String java.lang.Object.toString());
  25. pointcut wrongPackageName() :
  26. call(String java.xxx.Object.toString());
  27. pointcut wrongTypeName() :
  28. call(String java.lang.Xxx.toString());
  29. /** no warning!!! */
  30. pointcut wrongMethodName() :
  31. call(String java.lang.Object.xxx());
  32. @SuppressAjWarnings
  33. after() : call(String java.lang.Xxx.toString()) {
  34. System.out.println(thisJoinPoint);
  35. }
  36. /*
  37. * no example for "invalidWildcardTypeName"
  38. *
  39. * Never signalled anywhere in the codebase
  40. * @see https://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01404.html
  41. */
  42. /*
  43. * example for "unresolvableMember"
  44. *
  45. * hard to reproduce - I tried different things but at last I give up
  46. * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59596#c2
  47. */
  48. /*
  49. * example for "typeNotExposedToWeaver"
  50. */
  51. public int Object.dummy = 0;
  52. /*
  53. * no example for "shadowNotInStructure"
  54. *
  55. * Signalled if the structure model is broken, probably can't happen
  56. * @see https://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01404.html
  57. */
  58. /*
  59. * example for "unmatchedSuperTypeInCall"
  60. */
  61. pointcut unmatchedToStringCall() :
  62. call(String Car.toString());
  63. pointcut matchedToStringCall() :
  64. call(String Object.toString()) && target(Car);
  65. before() : unmatchedToStringCall() && !within(XlintTest) {
  66. System.out.println(thisJoinPoint);
  67. }
  68. @SuppressAjWarnings
  69. before() : call(String Car.toString()) {
  70. System.out.println(thisJoinPoint);
  71. }
  72. @SuppressAjWarnings({"adviceDidNotMatch"})
  73. before() : call(* java.lang.String.helloWorld()) {
  74. System.out.println(thisJoinPoint);
  75. }
  76. /*
  77. * example for "canNotImplementLazyTjp"
  78. *
  79. * This example is from the README-1.2.html. To get the warning you must
  80. * compile it with "-XlazyTjp"
  81. *
  82. * NOTE: The expected warnung does not appear. I don't know why.
  83. * Here is the commandline:
  84. * ajc -XlazyTjp -Xlint:warning -inpath src -d classes src
  85. */
  86. public static boolean enabled = false;
  87. pointcut toBeTraced() : execution(* *(..)) && !within(XlintTest);
  88. Object around() : toBeTraced() && if(enabled) {
  89. Object[] args = thisJoinPoint.getArgs();
  90. System.out.println(thisJoinPoint + ", arg's: " + args.length);
  91. return proceed();
  92. }
  93. /*
  94. * example for "needsSerialVersionUIDField"
  95. */
  96. declare parents : Main implements java.io.Serializable;
  97. /*
  98. * example for "brokeSerialVersionCompatibility"
  99. *
  100. * NOTE: I don't see this warning inside Eclipse with
  101. * AJDT 1.2.0.20050308091611 although I activate the warning
  102. * via the project properties.
  103. * I see it only when I start the compiler from the commandline
  104. * (ajc -XlazyTjp -Xlint:warning -inpath src -d classes src/x/...)
  105. */
  106. public int Car.breakSerial = 1;
  107. /*
  108. * example for "noInterfaceCtorJoinpoint"
  109. */
  110. pointcut interfaceConstructor() :
  111. execution(java.util.List.new());
  112. }
  113. class Car implements Serializable {}
  114. public class Main extends Object {
  115. /**
  116. * @param args
  117. */
  118. public static void main(String[] args) {
  119. new Main().run();
  120. Long l = new Long(1);
  121. String s = l.toString();
  122. }
  123. public void run() {
  124. new Car().toString();
  125. }
  126. }