Aspects Every Where

1,391 views
1,333 views

Published on

EclipseCon 2009 slides for Aspects Everywhere: Language Extensibility for JDT through Equinox Aspects

http://www.eclipsecon.org/2009/sessions?id=648

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,391
On SlideShare
0
From Embeds
0
Number of Embeds
256
Actions
Shares
0
Downloads
49
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Aspects Every Where

  1. 1. Aspects Everywhere: Language Extensibility for JDT through Equinox Aspects Andrew Eisenberg AJDT Committer AspectJ Project Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  2. 2. AJDT is an extension of JDT Extension AJDT JDT of AspectJ JPython support for support for Groovy And other Tool Tool Scala Java-like language JRuby Extension AspectJ Java of public class Ship { public aspect ShipAccessor { // ... // ... } } 2 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  3. 3. A little more about AspectJ • Aspects – like classes, but can have pointcuts and advice • Pointcuts – define interesting parts of the (execution of) program • Advice – define extra behavior at interesting parts of the program • Weaving (performed by a weaver) – makes sure advice runs at right time 3 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  4. 4. Demo 1 • AJDT 1.6.1 – Provides AspectJ-specific editor – But does not fully integrate with JDT 4 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  5. 5. The problem • Aspects are not in Open Type dialogs 5 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  6. 6. The problem • What I really want is this 6 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  7. 7. JDT is not really extensible • The problem runs deep – Need to plug into JDT's Java model, but can't – Need to plug into JDT's source indexing, but can't – Need to plug into JDT's parser, but can't 7 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  8. 8. First attempt: Raise a bug! • Bug 36939: Improve support for Java-like source files – Many patches submitted – 37 votes – but not resolved • Outside the scope of JDT 8 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  9. 9. Second attempt: eat our own dogfood! JDT Weaving Service • Use AspectJ – add hooks to JDT – toggles JDT or extended functionality • Wrapped in Eclipse extension points – make extensible to third parties • Equinox Aspects to support load time weaving in OSGi environment • AJDT 1.6.2 and later 9 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  10. 10. Demo 2 • AJDT 1.6.4 – Uses JDT Weaving service – More fully integrated with JDT 10 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  11. 11. How does this work? Uses AJDT JDT extension UI UI Weaves points JDT into Weaving JDT AJDT Service Core Core Other Load Time bundles... Weaving class loading Equinox & Aspects OSGi, everything In is a bundle extension support Equinox-OSGi 11 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  12. 12. Equinox Aspects uses AspectJ weaver • The weaver is careful which bundles to touch • Weaving happens lazily as classes are loaded – little effect on startup time • Once woven, weaver has no more role 12 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  13. 13. Example: Plug into JDT's Java model • For when it's like Java, but it really isn't • Need to plug into JDT's Java element hierarchy – IJavaElement --- generic Java entity – ICompilationUnit --- A Java source file • Objects need to be instantiated at the right time 13 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  14. 14. Example: Plug into JDT's Java model 1. Define extension: <extension point=quot;org.eclipse.contribution.weaving.jdt.cuproviderquot;> <provider class=quot;org.eclipse.ajdt.eclipsecon2009.ShipCUProviderquot; file_extension=quot;shipquot;/> </extension> 2. Define compilation unit provider: public class ShipCUProvider implements ICompilationUnitProvider { public CompilationUnit create(PackageFragment parent, String name, WorkingCopyOwner owner) { return new ShipCompilationUnit(parent, name, owner); } 14 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  15. 15. Demo 3/4 • Simple Ship editor – Icons – Searching – Open type • Ship Editor source code – plugin.xml – Java source code 15 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  16. 16. JDT Weaving Service • JDT functionality is exposed – AspectJ advice and pointcuts – exposed as extension points – no need to be AspectJ aware – simple and Eclipse-friendly • Available for download – with AJDT or separately http://download.eclipse.org/tools/ajdt/34/update • Useful for any Java-like language – Scala Eclipse plugin using this now 16 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  17. 17. That's it! • Links – AJDT : http://eclipse.org/ajdt – Equinox Aspects : http://www.eclipse.org/equinox/incubator/aspects/index.php – Source code and more implementation details : http://contraptionsforprogramming.blogspot.com – AspectJ in Action by Ramnivas Laddad available at bookstore 17 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  18. 18. CompilationUnitProviderAspect pointcut compilationUnitCreations(PackageFragment parent, String name, WorkingCopyOwner owner) : call(public CompilationUnit.new(PackageFragment, String, WorkingCopyOwner)) && args(parent, name, owner); CompilationUnit around(PackageFragment parent, String name, WorkingCopyOwner owner) : compilationUnitCreations(parent, name, owner) { String fileExtension = findFileExtension(name); ICompilationUnitProvider provider = CompilationUnitProviderRegistry.getInstance() .getProvider(fileExtension); if (provider != null) return provider.create(parent, name, owner); return proceed(parent, name, owner); } 18 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

×