aboutsummaryrefslogtreecommitdiffstats
path: root/docs/release/README-1.8.2.adoc
blob: ee3bbc4b6647ccd9b5b0a23f71ba5b3394891d3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
= AspectJ 1.8.2

_© Copyright 2014 Contributors. All rights reserved._

The full list of resolved issues in 1.8.2 is available
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]

_Release info: 1.8.2 available 14-Aug-2014_

== Notable changes

Although only a few bugs have been fixed here, they are quite important
ones:

=== Update to more recent Eclipse Compiler

AspectJ is now based on a more up to date Eclipse compiler level (git
hash 2b07958) so includes all the latest fixes

=== Correct handling of RuntimeInvisibleTypeAnnotations (type annotations without runtime visibility)

For anyone weaving code containing these kind of type annotations, this
is an important fix. Although AspectJ does not currently support
pointcuts matching on these kinds of annotation it was crashing when
they were encountered. That is now fixed.

=== Annotation processing

A very long standing issue, the AspectJ compiler now supports annotation
processors thanks to some work by Sergey Stupin.

Here is a short example, a very basic annotation and application:

==== Marker.java

[source, java]
....
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Marker { }
....

==== Code.java

[source, java]
....
public class Code {

  public static void main(String []argv) {
    new Code().moo();
    new Code().boo();
    new Code().too();
    new Code().woo();
  }

  public void moo() {}

  @Marker
  public void boo() {}

  @Marker
  public void too() {}

  public void woo() {}
}
....

And now a basic annotation processor. This processor will find methods
in the source marked with the annotation Marker and for each one
generate an aspect tailored to advising that method (this *is* a
contrived demo!)

==== DemoProcessor.java

[source, java]
....
import java.io.*;
import javax.tools.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;

@SupportedAnnotationTypes(value= {"*"})
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class DemoProcessor extends AbstractProcessor {

  private Filer filer;

  @Override
  public void init(ProcessingEnvironment env) {
    filer = env.getFiler();
  }

  @Override
  public boolean process(Set elements, RoundEnvironment env) {
    // Discover anything marked with @Marker
    for (Element element: env.getElementsAnnotatedWith(Marker.class)) {
      if (element.getKind() == ElementKind.METHOD) {
        // For any methods we find, create an aspect:
        String methodName = element.getSimpleName().toString();
        String aspectText =
            "public aspect Advise_"+methodName+" {\n"+
            "  before(): execution(* "+methodName+"(..)) {\n"+
            "    System.out.println(\""+methodName+" running\");\n"+
            "  }\n"+
            "}\n";
        try {
          JavaFileObject file = filer.createSourceFile("Advise_"+methodName, element);
          file.openWriter().append(aspectText).close();
          System.out.println("Generated aspect to advise "+element.getSimpleName());
        } catch (IOException ioe) {
          // already creates message can appear if processor runs more than once
          if (!ioe.getMessage().contains("already created")) {
            ioe.printStackTrace();
          }
        }
      }
    }
    return true;
  }
}
....

With those sources, we compile the processor:

[source, text]
....
ajc -1.6 DemoProcessor.java Marker.java
....

Now compile the code with the processor specified:

[source, text]
....
ajc -1.6 -processor DemoProcessor -showWeaveInfo Code.java Marker.java
....

[source, text]
....
Generated aspect to advise too
Generated aspect to advise boo
Join point 'method-execution(void Code.boo())' in Type 'Code' (Code.java:14) advised by before advice from 'Advise_boo' (Advise_boo.java:2)
Join point 'method-execution(void Code.too())' in Type 'Code' (Code.java:17) advised by before advice from 'Advise_too' (Advise_too.java:2)
....

Notice the processor generates the aspects and then they are woven into
the code being compiled immediately.

Finally we can run it:

[source, text]
....
java Code
boo running
too running
....

*Note:* There is still work to be done to get annotation processors
behaving under AJDT.