Подтвердить что ты не робот

AspectJ EDT-Checker Code Question

В настоящее время я использую Alexander Potochkin AspectJ Код EDTChecker (соответствующий код внизу сообщения).

Этот код (из того, что мало мне известно о AspectJ) жалуется на любой вызов или вызов конструктора JComponent, который не встречается в EDT Swing.

Однако, только JList-конструктор жалуется только на конструктор JFrame. Может ли кто-нибудь сказать мне, почему? Спасибо!

package testEDT;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;

public class TestEDT{

    JList list;
    final JFrame frame;

    public TestEDT() {
        DefaultListModel dlm = new DefaultListModel();
        list = new JList(dlm);
        frame = new JFrame("TestEDT");
    }

    public static void main(String args[]) {
        TestEDT t = new TestEDT();
        t.frame.setVisible(true);
    }
}

Александр Поточкин AspectJ код:

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 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();
        }
    }
}
4b9b3361

Ответ 1

JFrame не является подклассом JComponent, но JList является.