summaryrefslogtreecommitdiffstats
path: root/docs/adk15ProgGuideDB/miscellaneous.xml
blob: 063c8b816a1448119f2b7797a8b9c80b64b14636 (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
<chapter id="miscellaneous" xreflabel="Miscellaneous Changes">

  <title>Other Changes in AspectJ 5</title>
  
  <sect1>
      <title>Pointcuts</title>
      
      <sect2>
          <title>Binding of formals</title>
          <para>
           AspectJ 5 is more liberal than AspectJ 1.2.1 in accepting pointcut expressions
           that bind context variables in more than one location. For example, AspectJ
           1.2.1 does not allow:
           </para>

       	<programlisting><![CDATA[
       	pointcut foo(Foo foo) : (execution(* *(..)) && this(foo) ) ||
       	                                (set(* *) && target(foo));
		]]></programlisting>
		
		 <para>
		     whereas this expression is permitted in AspectJ 5. Each context variable must
		     be bound exactly once in each branch of a disjunction, and the disjunctive branches
		     must be mutually exclusive. In the above example for instance, no join point
		     can be both an execution join point and a set join point so the two branches
		     are mutually exclusive.
		  </para>
           
      </sect2>
      
      <sect2>
          <title>Additional lint warnings</title>
          <para>
            Discuss detection of common errors -> warning/error, eg. conjunction of more than one
            kind of join point. Differing numbers of args in method signature / args / @args /
            @parameters.
          </para>
      </sect2>
  </sect1>
  
  <sect1 id="declare-soft">
      <title>Declare Soft</title>
      <para>
          The semantics of the <literal>declare soft</literal> statement have been 
          refined in AspectJ 5 to only soften exceptions that are not already runtime 
          exceptions. If the exception type specified in a declare soft statement is <literal>RuntimeException</literal>
          or a subtype of <literal>RuntimeException</literal> then a new XLint warning will be issued:</para>
    
       	<programlisting><![CDATA[
       	  declare soft : SomeRuntimeException : execution(* *(..));
       	  
       	  &gt;&gt; "SomeRuntimeException will not be softened as it is already a RuntimeException" [XLint:runtimeExceptionNotSoftened]
		]]></programlisting>
	
	   <para>
	       This XLint message can be controlled by setting the <literal>runtimeExceptionNotSoftened</literal> XLint parameter.
 	   </para>
	
	   <para>
	      If the exception type specified in a declare soft statement is a super type of <literal>RuntimeException</literal>
	      (such as <literal>Exception</literal> for example) then any <i>checked</i> exception thrown at a matched join point, 
	      where the exception is an instance of the softened exception, will be softened to an 
	      <literal>org.aspectj.lang.SoftException</literal>. 
      </para>
      
       	<programlisting><![CDATA[
       	public aspect SoftenExample {
       	
       	  declare soft : Exception : execution(* Foo.*(..));
       	
       	}
       	
       	class Foo {
       	
       	  public static void main(String[] args) {
       	    Foo foo = new Foo();
       	    foo.foo();   
       	    foo.bar();
       	  }
       	
       	  void foo() throws Exception {
       	    throw new Exception();        // this will be converted to a SoftException
       	  }
       	  
       	  void bar() throws Exception {
       	    throw new RuntimeException();  // this will remain a RuntimeException
       	  }
       	
       	}
		]]></programlisting>
		
      
  </sect1>
</chapter>