Lines 42-47
Link Here
|
42 |
|
42 |
|
43 |
package org.netbeans.modules.parsing.spi; |
43 |
package org.netbeans.modules.parsing.spi; |
44 |
|
44 |
|
|
|
45 |
import java.beans.PropertyChangeEvent; |
46 |
import java.beans.PropertyChangeListener; |
47 |
import java.util.logging.Level; |
48 |
import java.util.logging.Logger; |
49 |
import org.netbeans.api.annotations.common.CheckForNull; |
45 |
import org.netbeans.modules.parsing.api.Source; |
50 |
import org.netbeans.modules.parsing.api.Source; |
46 |
import org.netbeans.modules.parsing.impl.CurrentDocumentScheduler; |
51 |
import org.netbeans.modules.parsing.impl.CurrentDocumentScheduler; |
47 |
import org.netbeans.modules.parsing.impl.CursorSensitiveScheduler; |
52 |
import org.netbeans.modules.parsing.impl.CursorSensitiveScheduler; |
Lines 49-57
Link Here
|
49 |
import org.netbeans.modules.parsing.impl.SelectedNodesScheduler; |
54 |
import org.netbeans.modules.parsing.impl.SelectedNodesScheduler; |
50 |
import org.netbeans.modules.parsing.impl.SourceAccessor; |
55 |
import org.netbeans.modules.parsing.impl.SourceAccessor; |
51 |
import org.netbeans.modules.parsing.impl.SourceCache; |
56 |
import org.netbeans.modules.parsing.impl.SourceCache; |
|
|
57 |
import org.openide.filesystems.FileObject; |
58 |
import org.openide.loaders.DataObject; |
59 |
import org.openide.loaders.DataObjectNotFoundException; |
52 |
|
60 |
|
53 |
import org.openide.util.RequestProcessor; |
61 |
import org.openide.util.RequestProcessor; |
54 |
import org.openide.util.RequestProcessor.Task; |
62 |
import org.openide.util.RequestProcessor.Task; |
|
|
63 |
import org.openide.util.WeakListeners; |
55 |
|
64 |
|
56 |
|
65 |
|
57 |
/** |
66 |
/** |
Lines 73-85
Link Here
|
73 |
* Default reparse delay |
82 |
* Default reparse delay |
74 |
*/ |
83 |
*/ |
75 |
public static final int DEFAULT_REPARSE_DELAY = 500; |
84 |
public static final int DEFAULT_REPARSE_DELAY = 500; |
|
|
85 |
|
86 |
private static final Logger LOG = Logger.getLogger(Scheduler.class.getName()); |
87 |
|
88 |
private final PropertyChangeListener listener = new PropertyChangeListener() { |
89 |
@Override |
90 |
public void propertyChange(PropertyChangeEvent evt) { |
91 |
if (DataObject.PROP_PRIMARY_FILE.equals(evt.getPropertyName())) { |
92 |
final DataObject dobj = (DataObject) evt.getSource(); |
93 |
final Source newSource = Source.create(dobj.getPrimaryFile()); |
94 |
if (newSource != null) { |
95 |
LOG.log( |
96 |
Level.FINE, |
97 |
"Rescheduling {0} due to change of primary file.", //NOI18N |
98 |
dobj.getPrimaryFile()); |
99 |
schedule(newSource, new SchedulerEvent(newSource)); |
100 |
} |
101 |
} |
102 |
} |
103 |
}; |
76 |
|
104 |
|
77 |
/** |
105 |
/** |
78 |
* May be changed by unit test |
106 |
* May be changed by unit test |
79 |
*/ |
107 |
*/ |
80 |
int reparseDelay = DEFAULT_REPARSE_DELAY; |
108 |
int reparseDelay = DEFAULT_REPARSE_DELAY; |
81 |
|
109 |
|
|
|
110 |
//@GuardedBy("this") |
82 |
private Source source; |
111 |
private Source source; |
|
|
112 |
//@GuardedBy("this") |
113 |
private PropertyChangeListener wlistener; |
83 |
|
114 |
|
84 |
/** |
115 |
/** |
85 |
* This implementations of {@link Scheduler} reschedules all tasks when: |
116 |
* This implementations of {@link Scheduler} reschedules all tasks when: |
Lines 142-156
Link Here
|
142 |
if (requestProcessor == null) { |
173 |
if (requestProcessor == null) { |
143 |
requestProcessor = new RequestProcessor (); |
174 |
requestProcessor = new RequestProcessor (); |
144 |
} |
175 |
} |
145 |
if (this.source != source && this.source != null) { |
176 |
if (this.source != source) { |
146 |
final SourceCache cache = SourceAccessor.getINSTANCE().getCache(this.source); |
177 |
if (this.source != null) { |
147 |
cache.unscheduleTasks(Scheduler.this.getClass()); |
178 |
final SourceCache cache = SourceAccessor.getINSTANCE().getCache(this.source); |
|
|
179 |
cache.unscheduleTasks(Scheduler.this.getClass()); |
180 |
if (wlistener != null) { |
181 |
final FileObject fo = this.source.getFileObject(); |
182 |
if (fo != null) { |
183 |
try { |
184 |
final DataObject dobj = DataObject.find(fo); |
185 |
dobj.removePropertyChangeListener(wlistener); |
186 |
} catch (DataObjectNotFoundException nfe) { |
187 |
//No DataObject for file - ignore |
188 |
} |
189 |
} |
190 |
} |
191 |
} |
192 |
this.source = source; |
193 |
if (source != null) { |
194 |
final FileObject fo = source.getFileObject(); |
195 |
if (fo != null) { |
196 |
try { |
197 |
final DataObject dobj = DataObject.find(fo); |
198 |
wlistener = WeakListeners.propertyChange(listener, dobj); |
199 |
dobj.addPropertyChangeListener(wlistener); |
200 |
} catch (DataObjectNotFoundException ex) { |
201 |
//No DataObject for file - ignore |
202 |
} |
203 |
} |
204 |
} |
148 |
} |
205 |
} |
149 |
if (source == null) { |
206 |
if (source == null) { |
150 |
this.source = null; |
207 |
return; |
151 |
return ; |
|
|
152 |
} |
208 |
} |
153 |
this.source = source; |
|
|
154 |
task = requestProcessor.create (new Runnable () { |
209 |
task = requestProcessor.create (new Runnable () { |
155 |
@Override |
210 |
@Override |
156 |
public void run () { |
211 |
public void run () { |
Lines 163-168
Link Here
|
163 |
task.schedule (reparseDelay); |
218 |
task.schedule (reparseDelay); |
164 |
} |
219 |
} |
165 |
|
220 |
|
|
|
221 |
/** |
222 |
* Returns active {@link Source}. |
223 |
* The {@link Scheduler} subclasses should use this method to obtain the active |
224 |
* {@link Source} rather than caching the {@link Source} them self. |
225 |
* @return the {@link Source} currently handled by scheduler. |
226 |
* @since 1.69 |
227 |
*/ |
228 |
@CheckForNull |
229 |
protected final synchronized Source getSource() { |
230 |
return this.source; |
231 |
} |
232 |
|
166 |
protected abstract SchedulerEvent createSchedulerEvent (SourceModificationEvent event); |
233 |
protected abstract SchedulerEvent createSchedulerEvent (SourceModificationEvent event); |
167 |
|
234 |
|
168 |
static { |
235 |
static { |