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.

README-182.html 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  2. <html> <head>
  3. <title>AspectJ 1.8.2 Readme</title>
  4. <style type="text/css">
  5. <!--
  6. P { margin-left: 20px; }
  7. PRE { margin-left: 20px; }
  8. LI { margin-left: 20px; }
  9. H4 { margin-left: 20px; }
  10. H3 { margin-left: 10px; }
  11. -->
  12. </style>
  13. </head>
  14. <body>
  15. <div align="right"><small>
  16. &copy; Copyright 2014 Contributors.
  17. All rights reserved.
  18. </small></div>
  19. <h1>AspectJ 1.8.2 Readme</h1>
  20. <p>The full list of resolved issues in 1.8.2 is available
  21. <a href="https://bugs.eclipse.org/bugs/buglist.cgi?query_format=advanced;bug_status=RESOLVED;bug_status=VERIFIED;bug_status=CLOSED;product=AspectJ;target_milestone=1.8.2;">here</a></h2>.</p>
  22. <ul>
  23. <li>1.8.2 available 14-Aug-2014
  24. </ul>
  25. <h2>Notable changes</h2>
  26. <p>Although only a few bugs have been fixed here, they are quite important ones:</p>
  27. <h3>Update to more recent Eclipse Compiler</h3>
  28. <p>AspectJ is now based on a more up to date Eclipse compiler level (git hash 2b07958) so includes all the latest fixes</p>
  29. <h3>Correct handling of RuntimeInvisibleTypeAnnotations (type annotations without runtime visibility)</h3>
  30. <p>For anyone weaving code containing these kind of type annotations, this is an important fix. Although AspectJ does not currently
  31. support pointcuts matching on these kinds of annotation it was crashing when they were encountered. That is now fixed.</p>
  32. <h3>Annotation processing</h3>
  33. <p>A very long standing issue, the AspectJ compiler now supports annotation processors thanks to some work by Sergey Stupin.</p>
  34. <p>Here is a short example, a very basic annotation and application:</p>
  35. <h4>Marker.java</h4>
  36. <code><pre>
  37. import java.lang.annotation.Retention;
  38. import java.lang.annotation.RetentionPolicy;
  39. @Retention(RetentionPolicy.RUNTIME)
  40. public @interface Marker { }
  41. </pre></code>
  42. <h4>Code.java</h4>
  43. <code><pre>
  44. public class Code {
  45. public static void main(String []argv) {
  46. new Code().moo();
  47. new Code().boo();
  48. new Code().too();
  49. new Code().woo();
  50. }
  51. public void moo() {}
  52. @Marker
  53. public void boo() {}
  54. @Marker
  55. public void too() {}
  56. public void woo() {}
  57. }
  58. </pre></code>
  59. <p>And now a basic annotation processor. This processor will find methods in the source marked with the annotation <tt>Marker</tt> and for
  60. each one generate an aspect tailored to advising that method (this *is* a contrived demo!)</p>
  61. <h4>DemoProcessor.java</h4>
  62. <code><pre>
  63. import java.io.*;
  64. import javax.tools.*;
  65. import java.util.*;
  66. import javax.annotation.processing.*;
  67. import javax.lang.model.*;
  68. import javax.lang.model.element.*;
  69. @SupportedAnnotationTypes(value= {"*"})
  70. @SupportedSourceVersion(SourceVersion.RELEASE_6)
  71. public class DemoProcessor extends AbstractProcessor {
  72. private Filer filer;
  73. @Override
  74. public void init(ProcessingEnvironment env) {
  75. filer = env.getFiler();
  76. }
  77. @Override
  78. public boolean process(Set elements, RoundEnvironment env) {
  79. // Discover anything marked with @Marker
  80. for (Element element: env.getElementsAnnotatedWith(Marker.class)) {
  81. if (element.getKind() == ElementKind.METHOD) {
  82. // For any methods we find, create an aspect:
  83. String methodName = element.getSimpleName().toString();
  84. String aspectText =
  85. "public aspect Advise_"+methodName+" {\n"+
  86. " before(): execution(* "+methodName+"(..)) {\n"+
  87. " System.out.println(\""+methodName+" running\");\n"+
  88. " }\n"+
  89. "}\n";
  90. try {
  91. JavaFileObject file = filer.createSourceFile("Advise_"+methodName, element);
  92. file.openWriter().append(aspectText).close();
  93. System.out.println("Generated aspect to advise "+element.getSimpleName());
  94. } catch (IOException ioe) {
  95. // already creates message can appear if processor runs more than once
  96. if (!ioe.getMessage().contains("already created")) {
  97. ioe.printStackTrace();
  98. }
  99. }
  100. }
  101. }
  102. return true;
  103. }
  104. }
  105. </pre></code>
  106. <p>With those sources, we compile the processor:</p>
  107. <code><pre>ajc -1.6 DemoProcessor.java Marker.java</pre></code>
  108. <p>Now compile the code with the processor specified:</p>
  109. <code><pre>ajc -1.6 -processor DemoProcessor -showWeaveInfo Code.java Marker.java</pre></code>
  110. <code><pre>
  111. Generated aspect to advise too
  112. Generated aspect to advise boo
  113. Join point 'method-execution(void Code.boo())' in Type 'Code' (Code.java:14) advised by before advice from 'Advise_boo' (Advise_boo.java:2)
  114. Join point 'method-execution(void Code.too())' in Type 'Code' (Code.java:17) advised by before advice from 'Advise_too' (Advise_too.java:2)
  115. </pre></code>
  116. <p>Notice the processor generates the aspects and then they are woven into the code being compiled immediately.</p>
  117. <p>Finally we can run it:</p>
  118. <code><pre>java Code
  119. boo running
  120. too running
  121. </pre></code>
  122. <p><b>Note:</b> There is still work to be done to get annotation processors behaving under AJDT.
  123. <!-- ============================== -->
  124. </body>
  125. </html>