[svn-inject] Installing original source of jabref
[debian/jabref.git] / src / java / net / sf / jabref / aspects / violations / DetectSwingSingleThreadRuleViolations.aj
1 /*
2  * Package package net.sf.jabref.aspects.violations;
3  * Created on Nov 6, 2004
4  * Author mspiegel
5  *
6  */
7 package net.sf.jabref.aspects.violations;
8
9 import java.awt.Component;
10 import java.awt.EventQueue;
11
12 public aspect DetectSwingSingleThreadRuleViolations {
13
14         pointcut guiUpdates(Component component)
15                 :       call(* java..Component+.*(..)) && 
16                     !call(* net..jabref+.*(..)) && target(component);                   
17     
18         pointcut safeGuiCalls()
19                 : call (* javax..JComponent.repaint(..))
20                         || call(* javax..JComponent.revalidate(..))
21                     || call(* javax..JComponent.invalidate(..))
22                     || call(* javax..*.add*Listener(..))
23                     || call(* javax..*.remove*Listener(..));
24                         
25         pointcut unsafeGuiCalls(Component component)
26                 : guiUpdates(component) && !safeGuiCalls();
27     
28     before(Component component) : unsafeGuiCalls(component) 
29         && if (!EventQueue.isDispatchThread() && (component != null) &&
30                         component.isDisplayable() && !Thread.currentThread().getName().equals("main")) {
31             System.err.println( 
32                     "Violation: Swing component method called from nonAWT thread"
33                     + "\nCalled method: " + thisJoinPointStaticPart.getSignature()
34                     + "\nCaller:" + thisEnclosingJoinPointStaticPart.getSignature()
35                     + "\nSource Location:" + thisJoinPointStaticPart.getSourceLocation()
36                     + "\nThread:" + Thread.currentThread() 
37                     + "\nChange code to use EventQueue.invokeLater() or EventQueue.invokeAndWait()"
38                     + "\n");
39         }
40     
41 }