Lines 45-50
Link Here
|
45 |
package org.netbeans.spi.project.support; |
45 |
package org.netbeans.spi.project.support; |
46 |
|
46 |
|
47 |
import java.beans.PropertyChangeListener; |
47 |
import java.beans.PropertyChangeListener; |
|
|
48 |
import java.io.File; |
49 |
import java.io.IOException; |
50 |
import java.net.URI; |
48 |
import java.util.ArrayList; |
51 |
import java.util.ArrayList; |
49 |
import java.util.Arrays; |
52 |
import java.util.Arrays; |
50 |
import java.util.Collections; |
53 |
import java.util.Collections; |
Lines 55-66
Link Here
|
55 |
import java.util.Map; |
58 |
import java.util.Map; |
56 |
import javax.swing.Icon; |
59 |
import javax.swing.Icon; |
57 |
import javax.swing.event.ChangeListener; |
60 |
import javax.swing.event.ChangeListener; |
|
|
61 |
import org.netbeans.api.annotations.common.NonNull; |
58 |
import org.netbeans.api.project.SourceGroup; |
62 |
import org.netbeans.api.project.SourceGroup; |
59 |
import org.netbeans.api.project.Sources; |
63 |
import org.netbeans.api.project.Sources; |
|
|
64 |
import org.netbeans.api.queries.SharabilityQuery; |
60 |
import org.netbeans.junit.NbTestCase; |
65 |
import org.netbeans.junit.NbTestCase; |
61 |
import org.netbeans.spi.project.ActionProvider; |
66 |
import org.netbeans.spi.project.ActionProvider; |
62 |
import org.netbeans.spi.project.LookupMerger; |
67 |
import org.netbeans.spi.project.LookupMerger; |
63 |
import org.netbeans.spi.project.LookupProvider; |
68 |
import org.netbeans.spi.project.LookupProvider; |
|
|
69 |
import org.netbeans.spi.queries.SharabilityQueryImplementation2; |
64 |
import org.openide.filesystems.FileObject; |
70 |
import org.openide.filesystems.FileObject; |
65 |
import org.openide.util.Lookup; |
71 |
import org.openide.util.Lookup; |
66 |
import org.openide.util.lookup.AbstractLookup; |
72 |
import org.openide.util.lookup.AbstractLookup; |
Lines 252-257
Link Here
|
252 |
assertEquals("[group1, group2, group3]", names.toString()); |
258 |
assertEquals("[group1, group2, group3]", names.toString()); |
253 |
} |
259 |
} |
254 |
|
260 |
|
|
|
261 |
|
262 |
|
263 |
public void testSharabilityQueryMerger() throws IOException { |
264 |
final File wd = getWorkDir(); |
265 |
final File f1 = new File (wd, "f1"); //NOI18N |
266 |
final File f2 = new File (wd, "f2"); //NOI18N |
267 |
final File f3 = new File (wd, "f3"); //NOI18N |
268 |
final File f4 = new File (wd, "f4"); //NOI18N |
269 |
final File f5 = new File (wd, "f5"); //NOI18N |
270 |
|
271 |
final SharabilityQueryImpl impl1 = new SharabilityQueryImpl(Collections.singletonMap(f1.toURI(), SharabilityQuery.Sharability.SHARABLE)); |
272 |
final SharabilityQueryImpl impl2 = new SharabilityQueryImpl(Collections.singletonMap(f2.toURI(), SharabilityQuery.Sharability.NOT_SHARABLE)); |
273 |
final SharabilityQueryImpl impl3 = new SharabilityQueryImpl(new HashMap<URI, SharabilityQuery.Sharability>(){{ |
274 |
put(f3.toURI(),SharabilityQuery.Sharability.SHARABLE); |
275 |
put(f4.toURI(),SharabilityQuery.Sharability.NOT_SHARABLE); |
276 |
}}); |
277 |
final SharabilityQueryImpl impl4 = new SharabilityQueryImpl(Collections.singletonMap(f2.toURI(), SharabilityQuery.Sharability.SHARABLE)); |
278 |
Lookup base = Lookups.fixed(impl1, LookupProviderSupport.createSharabilityQueryMerger()); |
279 |
LookupProviderImpl2 pro2 = new LookupProviderImpl2(); |
280 |
LookupProviderImpl2 pro3 = new LookupProviderImpl2(); |
281 |
LookupProviderImpl2 pro4 = new LookupProviderImpl2(); |
282 |
|
283 |
InstanceContent provInst = new InstanceContent(); |
284 |
Lookup providers = new AbstractLookup(provInst); |
285 |
provInst.add(pro2); |
286 |
provInst.add(pro3); |
287 |
provInst.add(pro4); |
288 |
pro2.ic.add(impl2); |
289 |
pro3.ic.add(impl3); |
290 |
pro4.ic.add(impl4); |
291 |
DelegatingLookupImpl del = new DelegatingLookupImpl(base, providers, "<irrelevant>"); |
292 |
|
293 |
SharabilityQueryImplementation2 sharability = del.lookup(SharabilityQueryImplementation2.class); |
294 |
assertNotNull(sharability); |
295 |
assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability.getSharability(f1.toURI())); |
296 |
assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability.getSharability(f2.toURI())); |
297 |
assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability.getSharability(f3.toURI())); |
298 |
assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability.getSharability(f4.toURI())); |
299 |
assertEquals(SharabilityQuery.Sharability.UNKNOWN, sharability.getSharability(f5.toURI())); |
300 |
} |
301 |
|
255 |
private class LookupProviderImpl2 implements LookupProvider { |
302 |
private class LookupProviderImpl2 implements LookupProvider { |
256 |
InstanceContent ic = new InstanceContent(); |
303 |
InstanceContent ic = new InstanceContent(); |
257 |
AbstractLookup l; |
304 |
AbstractLookup l; |
Lines 350-353
Link Here
|
350 |
return res; |
397 |
return res; |
351 |
} |
398 |
} |
352 |
} |
399 |
} |
|
|
400 |
|
401 |
private static final class SharabilityQueryImpl implements SharabilityQueryImplementation2 { |
402 |
|
403 |
private final Map<URI,SharabilityQuery.Sharability> sharability; |
404 |
|
405 |
SharabilityQueryImpl(@NonNull final Map<URI,SharabilityQuery.Sharability> sharability) { |
406 |
this.sharability = sharability; |
407 |
} |
408 |
|
409 |
@Override |
410 |
@NonNull |
411 |
public SharabilityQuery.Sharability getSharability(@NonNull final URI uri) { |
412 |
SharabilityQuery.Sharability res = sharability.get(uri); |
413 |
if (res == null) { |
414 |
res = SharabilityQuery.Sharability.UNKNOWN; |
415 |
} |
416 |
return res; |
417 |
} |
418 |
} |
353 |
} |
419 |
} |