 |
Creating Eclipse Warnings with AspectJ
Posted by felipegaucho on March 09, 2006 at 03:48 AM | Comments (6)
Debugging with println is an ancient habit in programming - even
the novice developers know about how fragile is such strategy facing the
robust debugging tools provided by the most common IDEs. Despite that,
everybody sometimes includes some commands like
System.out.println("step #1"), or
System.out.println("remember to remove this...")
. The code smell gets unveiled when a client observes his console printing
friendly words like this is just a test or even worst when a system
administrator opens a server log and finds hundreds of debug lines printed with
undeciphered numbers and letters. The most common strategy to avoid such programming
deviation is to use guard tools like Checkstyle and PMD. These tools are excellent
vigilants on the best practices of the code-style and patterns usage - but they seem weak
facing non-Java concerns like the disabling println policy.
On the
Cejug-Classifieds Project, we have made some experiments with the creation
of an Eclipse Warning to detect the usage of the println
into the code. Every time a developer type System.out.prinltn(...)
the warning icon appears beside his code - and we are very proud about the
zero-warning status of our code. One can ask why do not simply require the developers
to adopt the project code-style?. The answer is simple: it doesn't work, never
worked and I don't believe a human being is able to obey such non intuitive
rules whithout an ubiquitous advisor. The code-style maintenance can be a very boring
task and every time a developer becomes tired he will try to get past the rules. An IDE
guard can be (and must be) a good friend of the developers. The image below shows an
example of warning generated when the developer types println anywhere on the code:

Image 1: The Eclipse Problems View
Creating an Eclipse
W rning
with AspectJ
The decision about using a pure Java implementation, based on annotations,
or about using an external tool like AspectJ is very controversial
(1,
2,
3, 4,
...).
I will leave this discussion to a further blog entry - for now I will simply
enumerate the steps required to create a new warning on the Eclipse IDE.
- Download and install your preferred flavor of the Eclipe 3.1.+ (I'm using the WTP 0.7).
- Use the Help/Software Update feature to be sure you have the AspectJ installed in your Eclipse.
- Create a Java Project.
- Right Click on the project name and choose Convert to AspectJ Project.
- Done! You are ready to start to write the aspects definitions.
A demonstration Project
For a demonstration, I created a simple project with just one class and one aspect definition.
The project can be downloaded here. Just download the demo and use
the Import feature for assembling the project into your Eclipse. A tip: after installing
the project on the eclipse, type some println commands on the test class, and observe the
behaviour of the IDE.
Below is the aspect code used in the example project. Note the call(* *.println(..)))
- this command indicates that every println command executed by the JVM will be intercepted by
the aspect definition. Other interesting code fragment is the warning definition, which declares
a warning guard for the Eclipse View.
package net.java.dev.aop;
public aspect Test {
/** Everything outside the aspect package. */
pointcut not_aspect(): !within(net.java.dev.blogger.aop..*);
/** Pointcut to get any 'println' occurence (except in aspects). */
pointcut all_print_not_aspect():
(call(* *.println(..))) && not_aspect();
/** A warning definition. */
declare warning : all_print_not_aspect() :
"Sorry, we can't use println in our project";
}
Simple, isn't it? Not that much, the above example is just a bit of AOP. More sophisticated
controls over the code, including complete use cases implementations are deeply discussed
for a while by the software community. The aim of this blog entry is just registering an
approach we are adopting in our project to try a better code-style and to evaluate its
impact on the day by day of developers. Cejug-Classifieds has a lot of aspect definitions right now,
and we would like to invite you to visit our project and to test by yourself - your
feedback is very important to us.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Just to complete the information about installing AspectJ in Eclipse. The Update Site URL for AJDT (the AspectJ compiler in Eclipse) is http://download.eclipse.org/technology/ajdt/31/update
Posted by: rodrigolopes on March 09, 2006 at 04:23 AM
-
Following this approach, the coding rules specified by Sun Code Conventions can be customized by project. For instance, commands that sounds "bad" like "goto" can be avoided or specific rules like namespace definitions of identifiers about classes, interfaces and variables can be applied through AOP.
The result is much more quality of code.
Posted by: rubensgama on March 09, 2006 at 05:32 AM
-
This approach can be taken to implement many "policy enforcements". For example, you can ensure that EJB or Swing policies aren't violated inadvertently. My book "AspectJ in Action" has a whole chapter on this topic. You can download sources from http://manning.com/books/laddad/source. The code for policy enforcement is in chapter 6.
-Ramnivas
Posted by: ramnivas on March 09, 2006 at 06:53 AM
-
Awesome article. I will soon be known as the println Stazi at my work.
Posted by: phlogistic on March 09, 2006 at 09:33 AM
-
The subject of a very wonderful and distinct
I thank you for continuing excellence
Thank you
=========================================================================
ليبيا
شباب ليبيا
libya
منتديات
منتديات ليبية
غرائب وحقائق
أحاديث شريفة
برامج اسلامية للجوال
مفاتيح الديجيتل
الشيرنج
الرسيفرات
كتب إسلامية
خلفيات للموبيل
الشعر الشعبي
الصحة والطب
طب اسنان
كتب طب اسنان مجانية
برامج طبية
تعلم الإنكليزية
اللغة الفرنسية
طب الإعشاب
الخواطرالادبية
الازياء والمكياج
تعليم الطبخ
الاثاث الحديث
مقاطع كرة قدم
المصارعه الحرة
اهداف كوره
الفوتوشوب
اروع البرامج
الدوري الليبي
خلفيات رياضية
المصارعة
كورة عربية
كرة قدم عالمية
الدوري الإيطالي
الدوري الاسباني
الدوري الإنجليزي
صور المشاهير
انواع الحلويات
افلام كوميدية
احدث الافلام
افلام
التقنية
تحميل افلام
برامج
اخر برامج الجوال
kaspersky
أفلام كرتون عربية
برامج برامج كمبيوتر
برامج حماية
برامج اختراق
برامج صوت
برامج تحميل برامج احدث البرامج
محادثة
خلفيات الطبيعة
برامج مبايل للتحميل
اخبار الفن
احدث الافلام للتحميل
تحميل افلام رعب
ترجمةأفلام
الكامات
برامج جوال
برامج محاسبة
برامج
kasper
games
برامج
برامج
انترنت
برامج صوتية
شبكات الحاسوب
خلفيات للويندوز
تطويرالمواقع
العاب
العاب الفيديو
games
شفرات
برامج مسنجر
خلفيات شاشة
صور ترحيبيه
الفوتوشوب
خلفيات طبيعة
تطويرالمواقع
الفوتوشوب
مقاطع البلوتوت
مسجات ليبية
خلفيات
الفلاش
التصميم الثلاثي
برامج الجوال
العاب الجوال
فيديو كليب
مسجات
ترددات ستالايت
نغمات
Posted by: libyan on May 30, 2008 at 03:22 PM
-
Thanks so much for this! This is exactly what I was looking for.
///////////////////////////FLV to AVI converterFLV to WMV
FLV to MPEG
FLV Converter
SWF to FLV
M4V converter
Ipod to PC
Ipod to PC transfer
DVD to iPod AVI to SWF site has all solution on FLV to SWF,
WMV to SWF, MPEG to SWF,
3GP to SWF, DivX to SWF,AVI to FLV
and other video to SWF, FLV ecoded by Java.
May it Gadgets helpful To your lifestyle... Enjoy!
Posted by: quinceseed on June 19, 2008 at 08:02 PM
|