This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 143593
Collapse All | Expand All

(-)a/java.kit/test/qa-functional/src/org/netbeans/test/ide/MemoryValidationTest.java (-1 / +1 lines)
Lines 100-106 Link Here
100
100
101
        conf = conf.addTest("testGCDocuments");
101
        conf = conf.addTest("testGCDocuments");
102
102
103
//        conf = conf.addTest("testGCProjects");
103
        conf = conf.addTest("testGCProjects");
104
        // not in commit suite because it needs net connectivity
104
        // not in commit suite because it needs net connectivity
105
        // suite.addTest(new IDEValidation("testPlugins"));
105
        // suite.addTest(new IDEValidation("testPlugins"));
106
        return NbModuleSuite.create(conf);
106
        return NbModuleSuite.create(conf);
(-)a/parsing.api/src/org/netbeans/modules/parsing/api/Source.java (-4 / +7 lines)
Lines 424-430 Link Here
424
    private final ASourceModificationEvent unspecifiedSourceModificationEvent = new ASourceModificationEvent (this, -1, -1);
424
    private final ASourceModificationEvent unspecifiedSourceModificationEvent = new ASourceModificationEvent (this, -1, -1);
425
    private Map<Class<? extends Scheduler>,? extends SchedulerEvent> schedulerEvents;
425
    private Map<Class<? extends Scheduler>,? extends SchedulerEvent> schedulerEvents;
426
    //GuardedBy(this)
426
    //GuardedBy(this)
427
    private SourceCache     cache;
427
    private Reference<SourceCache>     cache;
428
    //GuardedBy(this)
428
    //GuardedBy(this)
429
    private volatile long eventId;
429
    private volatile long eventId;
430
    //Changes handling
430
    //Changes handling
Lines 627-635 Link Here
627
        public SourceCache getCache (final Source source) {
627
        public SourceCache getCache (final Source source) {
628
            assert source != null;
628
            assert source != null;
629
            synchronized (TaskProcessor.INTERNAL_LOCK) {
629
            synchronized (TaskProcessor.INTERNAL_LOCK) {
630
                if (source.cache == null)
630
                SourceCache sc = source.cache != null ? source.cache.get() : null;
631
                    source.cache = new SourceCache (source, null);
631
                if (sc == null) {
632
                return source.cache;
632
                    sc = new SourceCache (source, null);
633
                    source.cache = new WeakReference<SourceCache>(sc);
634
                }
635
                return sc;
633
            }
636
            }
634
        }
637
        }
635
638
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/CurrentDocumentScheduler.java (-6 / +9 lines)
Lines 39-44 Link Here
39
39
40
package org.netbeans.modules.parsing.impl;
40
package org.netbeans.modules.parsing.impl;
41
41
42
import java.lang.ref.Reference;
43
import java.lang.ref.WeakReference;
42
import javax.swing.text.Document;
44
import javax.swing.text.Document;
43
import javax.swing.text.JTextComponent;
45
import javax.swing.text.JTextComponent;
44
46
Lines 55-71 Link Here
55
 */
57
 */
56
@ServiceProvider(service=Scheduler.class)
58
@ServiceProvider(service=Scheduler.class)
57
public class CurrentDocumentScheduler extends CurrentEditorTaskScheduler {
59
public class CurrentDocumentScheduler extends CurrentEditorTaskScheduler {
58
    
59
    private Document        currentDocument;
60
    private Document        currentDocument;
60
    private Source          source;
61
    private Reference<Source>          source;
61
    
62
    
62
    protected void setEditor (JTextComponent editor) {
63
    protected void setEditor (JTextComponent editor) {
63
        if (editor != null) {
64
        if (editor != null) {
64
            Document document = editor.getDocument ();
65
            Document document = editor.getDocument ();
65
            if (currentDocument == document) return;
66
            if (currentDocument == document) return;
66
            currentDocument = document;
67
            currentDocument = document;
67
            source = Source.create (currentDocument);
68
            Source s = Source.create (currentDocument);
68
            schedule (source, new SchedulerEvent (this) {});
69
            source = new WeakReference<Source>(s);
70
            schedule (s, new SchedulerEvent (this) {});
69
        }
71
        }
70
        else {
72
        else {
71
            currentDocument = null;
73
            currentDocument = null;
Lines 78-84 Link Here
78
     * @param source
80
     * @param source
79
     */
81
     */
80
    void schedule (Source source) {
82
    void schedule (Source source) {
81
        this.source = source;
83
        this.source = new WeakReference<Source>(source);
82
        schedule (source, new SchedulerEvent (this) {});
84
        schedule (source, new SchedulerEvent (this) {});
83
    }
85
    }
84
    
86
    
Lines 89-95 Link Here
89
91
90
    @Override
92
    @Override
91
    protected SchedulerEvent createSchedulerEvent (SourceModificationEvent event) {
93
    protected SchedulerEvent createSchedulerEvent (SourceModificationEvent event) {
92
        if (event.getModifiedSource () == source)
94
        Source s = source == null ? null : source.get();
95
        if (event.getModifiedSource () == s)
93
            return new SchedulerEvent (this) {};
96
            return new SchedulerEvent (this) {};
94
        return null;
97
        return null;
95
    }
98
    }
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/CursorSensitiveScheduler.java (-4 / +8 lines)
Lines 39-44 Link Here
39
39
40
package org.netbeans.modules.parsing.impl;
40
package org.netbeans.modules.parsing.impl;
41
41
42
import java.lang.ref.Reference;
43
import java.lang.ref.WeakReference;
42
import javax.swing.event.CaretEvent;
44
import javax.swing.event.CaretEvent;
43
import javax.swing.event.CaretListener;
45
import javax.swing.event.CaretListener;
44
import javax.swing.text.Document;
46
import javax.swing.text.Document;
Lines 62-68 Link Here
62
    private JTextComponent  currentEditor;
64
    private JTextComponent  currentEditor;
63
    private CaretListener   caretListener;
65
    private CaretListener   caretListener;
64
    private Document        currentDocument;
66
    private Document        currentDocument;
65
    private Source          source;
67
    private Reference<Source>          source;
66
68
67
    
69
    
68
    protected void setEditor (JTextComponent editor) {
70
    protected void setEditor (JTextComponent editor) {
Lines 76-83 Link Here
76
            Document document = editor.getDocument ();
78
            Document document = editor.getDocument ();
77
            if (currentDocument == document) return;
79
            if (currentDocument == document) return;
78
            currentDocument = document;
80
            currentDocument = document;
79
            source = Source.create (currentDocument);
81
            Source s = Source.create (currentDocument);
80
            schedule (source, new CursorMovedSchedulerEvent (this, editor.getCaret ().getDot (), editor.getCaret ().getMark ()) {});
82
            source = new WeakReference<Source>(s);
83
            schedule (s, new CursorMovedSchedulerEvent (this, editor.getCaret ().getDot (), editor.getCaret ().getMark ()) {});
81
        }
84
        }
82
        else {
85
        else {
83
            currentDocument = null;
86
            currentDocument = null;
Lines 92-98 Link Here
92
95
93
    @Override
96
    @Override
94
    protected SchedulerEvent createSchedulerEvent (SourceModificationEvent event) {
97
    protected SchedulerEvent createSchedulerEvent (SourceModificationEvent event) {
95
        if (event.getModifiedSource () == source)
98
        Source s = source == null ? null : source.get();
99
        if (event.getModifiedSource () == s)
96
            return new CursorMovedSchedulerEvent (this, currentEditor.getCaret ().getDot (), currentEditor.getCaret ().getMark ()) {};
100
            return new CursorMovedSchedulerEvent (this, currentEditor.getCaret ().getDot (), currentEditor.getCaret ().getMark ()) {};
97
        return null;
101
        return null;
98
    }
102
    }
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/SelectedNodesScheduler.java (-6 / +12 lines)
Lines 42-47 Link Here
42
import java.beans.PropertyChangeEvent;
42
import java.beans.PropertyChangeEvent;
43
import java.beans.PropertyChangeListener;
43
import java.beans.PropertyChangeListener;
44
44
45
import java.lang.ref.Reference;
46
import java.lang.ref.WeakReference;
45
import org.netbeans.modules.parsing.spi.SchedulerEvent;
47
import org.netbeans.modules.parsing.spi.SchedulerEvent;
46
import org.netbeans.modules.parsing.spi.SourceModificationEvent;
48
import org.netbeans.modules.parsing.spi.SourceModificationEvent;
47
import org.openide.filesystems.FileObject;
49
import org.openide.filesystems.FileObject;
Lines 63-69 Link Here
63
public class SelectedNodesScheduler extends Scheduler {
65
public class SelectedNodesScheduler extends Scheduler {
64
66
65
67
66
    private Source              source;
68
    private Reference<Source>              source;
67
69
68
    public SelectedNodesScheduler () {
70
    public SelectedNodesScheduler () {
69
        TopComponent.getRegistry ().addPropertyChangeListener (new AListener ());
71
        TopComponent.getRegistry ().addPropertyChangeListener (new AListener ());
Lines 81-90 Link Here
81
                    final DataObject dataObject = nodes [0].getLookup ().lookup (DataObject.class);
83
                    final DataObject dataObject = nodes [0].getLookup ().lookup (DataObject.class);
82
                    if (dataObject != null && dataObject.isValid()) {
84
                    if (dataObject != null && dataObject.isValid()) {
83
                        final FileObject fileObject = dataObject.getPrimaryFile ();
85
                        final FileObject fileObject = dataObject.getPrimaryFile ();
84
                        if (fileObject.isValid() && Util.canBeParsed(fileObject.getMIMEType()))
86
                        Source s = null;
85
                        source = Source.create (fileObject);
87
                        if (fileObject.isValid() && Util.canBeParsed(fileObject.getMIMEType())) {
86
                        if (source != null) {
88
                            s = Source.create (fileObject);
87
                            schedule (source, new SchedulerEvent (this) {});
89
                            source = new WeakReference<Source>(s);
90
                        }
91
                        if (s != null) {
92
                            schedule (s, new SchedulerEvent (this) {});
88
                            return;
93
                            return;
89
                        }
94
                        }
90
                    }
95
                    }
Lines 100-106 Link Here
100
105
101
    @Override
106
    @Override
102
    protected SchedulerEvent createSchedulerEvent (SourceModificationEvent event) {
107
    protected SchedulerEvent createSchedulerEvent (SourceModificationEvent event) {
103
        if (event.getModifiedSource () == source)
108
        Source s = source == null ? null : source.get();
109
        if (event.getModifiedSource () == s)
104
            return new SchedulerEvent (this) {};
110
            return new SchedulerEvent (this) {};
105
        return null;
111
        return null;
106
    }
112
    }
(-)a/parsing.api/src/org/netbeans/modules/parsing/spi/Scheduler.java (-14 / +33 lines)
Lines 39-44 Link Here
39
39
40
package org.netbeans.modules.parsing.spi;
40
package org.netbeans.modules.parsing.spi;
41
41
42
import java.lang.ref.Reference;
43
import java.lang.ref.WeakReference;
42
import java.util.HashMap;
44
import java.util.HashMap;
43
import java.util.Map;
45
import java.util.Map;
44
46
Lines 79-85 Link Here
79
     */
81
     */
80
    int                     reparseDelay = DEFAULT_REPARSE_DELAY;
82
    int                     reparseDelay = DEFAULT_REPARSE_DELAY;
81
    
83
    
82
    private Source          source;
84
    private Reference<Source>          source;
83
    
85
    
84
    /**
86
    /**
85
     * This implementations of {@link Scheduler} reschedules all tasks when:
87
     * This implementations of {@link Scheduler} reschedules all tasks when:
Lines 116-123 Link Here
116
    protected final void schedule (
118
    protected final void schedule (
117
        SchedulerEvent      event
119
        SchedulerEvent      event
118
    ) {
120
    ) {
119
        if (source != null)
121
        Reference<Source> obj = source;
120
            schedule (source, event);
122
        Source s = obj == null ? null : obj.get();
123
        if (s != null) {
124
            schedule(s, event);
125
        }
121
    }
126
    }
122
127
123
    private RequestProcessor 
128
    private RequestProcessor 
Lines 141-164 Link Here
141
        if (task != null)
146
        if (task != null)
142
            task.cancel ();
147
            task.cancel ();
143
        task = null;
148
        task = null;
144
        this.source = source;
149
        this.source = new WeakReference<Source>(source);
145
        //if (task == null) {
150
        //if (task == null) {
146
            if (requestProcessor == null)
151
            if (requestProcessor == null)
147
                requestProcessor = new RequestProcessor ();
152
                requestProcessor = new RequestProcessor ();
148
            task = requestProcessor.create (new Runnable () {
153
            task = requestProcessor.create (new Run(this, source, event));
149
                public void run () {
150
                    SourceCache cache = SourceAccessor.getINSTANCE ().getCache (source);
151
                    Map<Class<? extends Scheduler>,SchedulerEvent> events = new HashMap<Class<? extends Scheduler>,SchedulerEvent> ();
152
                    events.put (Scheduler.this.getClass (), event);
153
                    SourceAccessor.getINSTANCE ().setSchedulerEvents (source, events);
154
                    //S ystem.out.println ("\nSchedule tasks (" + Scheduler.this + "):");
155
                    cache.scheduleTasks (Scheduler.this.getClass ());
156
                }
157
            });
158
        //}
154
        //}
159
        task.schedule (reparseDelay);
155
        task.schedule (reparseDelay);
160
    }
156
    }
161
157
158
    private static final class Run implements Runnable {
159
        private final Scheduler scheduler;
160
        private SchedulerEvent event;
161
        private Source source;
162
163
        private Run(Scheduler aThis, Source source, SchedulerEvent ev) {
164
            this.scheduler = aThis;
165
            this.source = source;
166
            this.event = ev;
167
        }
168
169
170
         public void run() {
171
            SourceCache cache = SourceAccessor.getINSTANCE().getCache(source);
172
            Map<Class<? extends Scheduler>, SchedulerEvent> events = new HashMap<Class<? extends Scheduler>, SchedulerEvent>();
173
            events.put(scheduler.getClass(), event);
174
            SourceAccessor.getINSTANCE().setSchedulerEvents(source, events);
175
            //S ystem.out.println ("\nSchedule tasks (" + Scheduler.this + "):");
176
            cache.scheduleTasks(scheduler.getClass());
177
            source = null;
178
        }
179
    }
180
162
    protected abstract SchedulerEvent createSchedulerEvent (SourceModificationEvent event);
181
    protected abstract SchedulerEvent createSchedulerEvent (SourceModificationEvent event);
163
182
164
    private static boolean  notNull (final Iterable<?> it) {
183
    private static boolean  notNull (final Iterable<?> it) {

Return to bug 143593