我不明白为什么我的代码在这个实例中被标记。
myPlot.plot(serviceRef, frameMax, frameMin);
该行是错误的源位置。它对我没有任何意义,因为代码行中没有 Swing 代码。为什么会发生这种情况呢?
我在下面附上了 Potochkin 的 EDT 违规检查代码:
package testEDT;
import javax.swing.*;
/**
* AspectJ code that checks for Swing component methods being executed OUTSIDE the Event-Dispatch-Thread.
*
* (For info on why this is bad, see: http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html)
*
* From Alexander Potochkin's blog post here:
* http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html
*
*/
aspect EdtRuleChecker{
/** Flag for use */
private boolean isStressChecking = true;
/** defines any Swing method */
public pointcut anySwingMethods(JComponent c):
target(c) && call(* *(..));
/** defines thread-safe methods */
public pointcut threadSafeMethods():
call(* repaint(..)) ||
call(* revalidate()) ||
call(* invalidate()) ||
call(* getListeners(..)) ||
call(* add*Listener(..)) ||
call(* remove*Listener(..));
/** calls of any JComponent method, including subclasses */
before(JComponent c): anySwingMethods(c) &&
!threadSafeMethods() &&
!within(EdtRuleChecker) {
if ( !SwingUtilities.isEventDispatchThread() && (isStressChecking || c.isShowing())) {
System.err.println(thisJoinPoint.getSourceLocation());
System.err.println(thisJoinPoint.getSignature());
System.err.println();
}
}
/** calls of any JComponent constructor, including subclasses */
before(): call(JComponent+.new(..)) {
if (isStressChecking && !SwingUtilities.isEventDispatchThread()) {
System.err.println(thisJoinPoint.getSourceLocation());
System.err.println(thisJoinPoint.getSignature() + " *constructor*");
System.err.println();
}
}
}