Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

idioms.xml 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <chapter id="idioms" xreflabel="Idioms">
  2. <title>Idioms</title>
  3. <sect1 id="idioms-intro">
  4. <title>Introduction</title>
  5. <para>
  6. This chapter consists of very short snippets of AspectJ code,
  7. typically pointcuts, that are particularly evocative or useful.
  8. This section is a work in progress.
  9. </para>
  10. <para>
  11. Here's an example of how to enfore a rule that code in the
  12. java.sql package can only be used from one particular package in
  13. your system. This doesn't require any access to code in the
  14. java.sql package.
  15. </para>
  16. <programlisting><![CDATA[
  17. /* Any call to methods or constructors in java.sql */
  18. pointcut restrictedCall():
  19. call(* java.sql.*.*(..)) || call(java.sql.*.new(..));
  20. /* Any code in my system not in the sqlAccess package */
  21. pointcut illegalSource():
  22. within(com.foo..*) && !within(com.foo.sqlAccess.*);
  23. declare error: restrictedCall() && illegalSource():
  24. "java.sql package can only be accessed from com.foo.sqlAccess";
  25. ]]></programlisting>
  26. <para>Any call to an instance of a subtype of AbstractFacade whose class is
  27. not exactly equal to AbstractFacade:</para>
  28. <programlisting><![CDATA[
  29. pointcut nonAbstract(AbstractFacade af):
  30. call(* *(..))
  31. && target(af)
  32. && !if(af.getClass() == AbstractFacade.class);
  33. ]]></programlisting>
  34. <para> If AbstractFacade is an abstract class or an interface, then every
  35. instance must be of a subtype and you can replace this with: </para>
  36. <programlisting><![CDATA[
  37. pointcut nonAbstract(AbstractFacade af):
  38. call(* *(..))
  39. && target(af);
  40. ]]></programlisting>
  41. <para> Any call to a method which is defined by a subtype of
  42. AbstractFacade, but which isn't defined by the type AbstractFacade itself:
  43. </para>
  44. <programlisting><![CDATA[
  45. pointcut callToUndefinedMethod():
  46. call(* AbstractFacade+.*(..))
  47. && !call(* AbstractFacade.*(..));
  48. ]]></programlisting>
  49. <para> The execution of a method that is defined in the source code for a
  50. type that is a subtype of AbstractFacade but not in AbstractFacade itself:
  51. </para>
  52. <programlisting><![CDATA[
  53. pointcut executionOfUndefinedMethod():
  54. execution(* *(..))
  55. && within(AbstractFacade+)
  56. && !within(AbstractFacade)
  57. ]]></programlisting>
  58. </sect1>
  59. </chapter>