Lines 41-53
Link Here
|
41 |
*/ |
41 |
*/ |
42 |
package org.netbeans.modules.parsing.impl.indexing; |
42 |
package org.netbeans.modules.parsing.impl.indexing; |
43 |
|
43 |
|
44 |
import java.awt.Color; |
|
|
45 |
import java.awt.Font; |
46 |
import java.beans.PropertyChangeEvent; |
47 |
import java.io.File; |
44 |
import java.io.File; |
48 |
import java.io.IOException; |
45 |
import java.io.IOException; |
49 |
import java.lang.reflect.Constructor; |
|
|
50 |
import java.lang.reflect.InvocationTargetException; |
51 |
import java.util.ArrayList; |
46 |
import java.util.ArrayList; |
52 |
import java.util.Arrays; |
47 |
import java.util.Arrays; |
53 |
import java.util.Collection; |
48 |
import java.util.Collection; |
Lines 57-85
Link Here
|
57 |
import java.util.List; |
52 |
import java.util.List; |
58 |
import java.util.Map; |
53 |
import java.util.Map; |
59 |
import java.util.Set; |
54 |
import java.util.Set; |
60 |
import java.util.concurrent.CountDownLatch; |
|
|
61 |
import java.util.concurrent.atomic.AtomicReference; |
55 |
import java.util.concurrent.atomic.AtomicReference; |
62 |
import java.util.logging.Level; |
56 |
import java.util.logging.Level; |
63 |
import java.util.logging.Logger; |
57 |
import java.util.logging.Logger; |
64 |
import javax.swing.JEditorPane; |
58 |
import javax.swing.JEditorPane; |
65 |
import javax.swing.SwingUtilities; |
59 |
import javax.swing.SwingUtilities; |
66 |
import javax.swing.event.ChangeListener; |
60 |
import javax.swing.event.ChangeListener; |
67 |
import javax.swing.text.AttributeSet; |
|
|
68 |
import javax.swing.text.BadLocationException; |
69 |
import javax.swing.text.DefaultEditorKit; |
61 |
import javax.swing.text.DefaultEditorKit; |
70 |
import javax.swing.text.Document; |
62 |
import javax.swing.text.Document; |
71 |
import javax.swing.text.EditorKit; |
63 |
import javax.swing.text.EditorKit; |
72 |
import javax.swing.text.Element; |
|
|
73 |
import javax.swing.text.Style; |
74 |
import javax.swing.text.StyledDocument; |
64 |
import javax.swing.text.StyledDocument; |
75 |
import org.netbeans.api.annotations.common.NonNull; |
65 |
import org.netbeans.api.annotations.common.NonNull; |
76 |
import org.netbeans.api.editor.EditorRegistry; |
|
|
77 |
import org.netbeans.api.editor.mimelookup.MimePath; |
66 |
import org.netbeans.api.editor.mimelookup.MimePath; |
78 |
import org.netbeans.api.editor.mimelookup.test.MockMimeLookup; |
67 |
import org.netbeans.api.editor.mimelookup.test.MockMimeLookup; |
79 |
import org.netbeans.api.java.classpath.ClassPath; |
68 |
import org.netbeans.api.java.classpath.ClassPath; |
80 |
import org.netbeans.api.java.classpath.GlobalPathRegistry; |
69 |
import org.netbeans.api.java.classpath.GlobalPathRegistry; |
81 |
import org.netbeans.editor.AtomicLockEvent; |
|
|
82 |
import org.netbeans.editor.BaseDocument; |
83 |
import org.netbeans.editor.GuardedDocument; |
70 |
import org.netbeans.editor.GuardedDocument; |
84 |
import org.netbeans.junit.MockServices; |
71 |
import org.netbeans.junit.MockServices; |
85 |
import org.netbeans.junit.NbTestCase; |
72 |
import org.netbeans.junit.NbTestCase; |
Lines 91-103
Link Here
|
91 |
import org.netbeans.modules.parsing.api.Source; |
78 |
import org.netbeans.modules.parsing.api.Source; |
92 |
import org.netbeans.modules.parsing.api.Task; |
79 |
import org.netbeans.modules.parsing.api.Task; |
93 |
import org.netbeans.modules.parsing.api.UserTask; |
80 |
import org.netbeans.modules.parsing.api.UserTask; |
|
|
81 |
import org.netbeans.modules.parsing.impl.EmbeddingProviderFactory; |
94 |
import org.netbeans.modules.parsing.spi.EmbeddingProvider; |
82 |
import org.netbeans.modules.parsing.spi.EmbeddingProvider; |
95 |
import org.netbeans.modules.parsing.spi.ParseException; |
83 |
import org.netbeans.modules.parsing.spi.ParseException; |
96 |
import org.netbeans.modules.parsing.spi.Parser; |
84 |
import org.netbeans.modules.parsing.spi.Parser; |
97 |
import org.netbeans.modules.parsing.spi.ParserFactory; |
85 |
import org.netbeans.modules.parsing.spi.ParserFactory; |
98 |
import org.netbeans.modules.parsing.spi.SchedulerTask; |
|
|
99 |
import org.netbeans.modules.parsing.spi.SourceModificationEvent; |
86 |
import org.netbeans.modules.parsing.spi.SourceModificationEvent; |
100 |
import org.netbeans.modules.parsing.spi.TaskFactory; |
|
|
101 |
import org.netbeans.modules.parsing.spi.indexing.Context; |
87 |
import org.netbeans.modules.parsing.spi.indexing.Context; |
102 |
import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexer; |
88 |
import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexer; |
103 |
import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexerFactory; |
89 |
import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexerFactory; |
Lines 123-134
Link Here
|
123 |
import org.openide.nodes.AbstractNode; |
109 |
import org.openide.nodes.AbstractNode; |
124 |
import org.openide.nodes.Children; |
110 |
import org.openide.nodes.Children; |
125 |
import org.openide.nodes.Node; |
111 |
import org.openide.nodes.Node; |
126 |
import org.openide.nodes.Node.Cookie; |
|
|
127 |
import org.openide.text.DataEditorSupport; |
112 |
import org.openide.text.DataEditorSupport; |
128 |
import org.openide.text.NbDocument; |
113 |
import org.openide.text.NbDocument; |
129 |
import org.openide.util.Exceptions; |
114 |
import org.openide.util.Exceptions; |
130 |
import org.openide.util.Lookup; |
115 |
import org.openide.util.Lookup; |
131 |
import org.openide.util.lookup.Lookups; |
|
|
132 |
import org.openide.util.test.TestFileUtils; |
116 |
import org.openide.util.test.TestFileUtils; |
133 |
|
117 |
|
134 |
/** |
118 |
/** |
Lines 159-168
Link Here
|
159 |
final FileObject wd = FileUtil.toFileObject(_wd); |
143 |
final FileObject wd = FileUtil.toFileObject(_wd); |
160 |
final FileObject cache = wd.createFolder("cache"); //NOI18N |
144 |
final FileObject cache = wd.createFolder("cache"); //NOI18N |
161 |
CacheFolder.setCacheFolder(cache); |
145 |
CacheFolder.setCacheFolder(cache); |
|
|
146 |
final Map<String,Object> attrMap = new HashMap<String,Object>(); |
147 |
attrMap.put(EmbeddingProviderFactory.ATTR_TARGET_MIME_TYPE, MIME_INNER); |
148 |
attrMap.put(EmbeddingProviderFactory.ATTR_PROVIDER, new TopToInnerEmbProvider()); |
162 |
MockMimeLookup.setInstances( |
149 |
MockMimeLookup.setInstances( |
163 |
MimePath.get(MIME_TOP), |
150 |
MimePath.get(MIME_TOP), |
164 |
new TopParser.Factory(), |
151 |
new TopParser.Factory(), |
165 |
new TopToInnerEmbProvider.Factory(), |
152 |
EmbeddingProviderFactory.create(attrMap), |
166 |
new TopIndexer.Factory()); |
153 |
new TopIndexer.Factory()); |
167 |
MockMimeLookup.setInstances( |
154 |
MockMimeLookup.setInstances( |
168 |
MimePath.get(MIME_INNER), |
155 |
MimePath.get(MIME_INNER), |
Lines 179-185
Link Here
|
179 |
" <A> <B> < A> < >")); //NOI18N |
166 |
" <A> <B> < A> < >")); //NOI18N |
180 |
FileUtil.setMIMEType(EXT_TOP, MIME_TOP); |
167 |
FileUtil.setMIMEType(EXT_TOP, MIME_TOP); |
181 |
RepositoryUpdaterTest.setMimeTypes(MIME_TOP, MIME_INNER); |
168 |
RepositoryUpdaterTest.setMimeTypes(MIME_TOP, MIME_INNER); |
182 |
ClassPathProviderImpl.root = srcRoot; |
169 |
ClassPathProviderImpl.setRoot(srcRoot); |
183 |
RepositoryUpdaterTest.waitForRepositoryUpdaterInit(); |
170 |
RepositoryUpdaterTest.waitForRepositoryUpdaterInit(); |
184 |
} |
171 |
} |
185 |
|
172 |
|
Lines 193-199
Link Here
|
193 |
super.tearDown(); |
180 |
super.tearDown(); |
194 |
} |
181 |
} |
195 |
|
182 |
|
196 |
public void testEmbeddingIndexer() throws Exception { |
183 |
public void testEmbeddingIndexerQueryOnOuterAndInner() throws Exception { |
197 |
RepositoryUpdater ru = RepositoryUpdater.getDefault(); |
184 |
RepositoryUpdater ru = RepositoryUpdater.getDefault(); |
198 |
assertEquals(0, ru.getScannedBinaries().size()); |
185 |
assertEquals(0, ru.getScannedBinaries().size()); |
199 |
assertEquals(0, ru.getScannedBinaries().size()); |
186 |
assertEquals(0, ru.getScannedBinaries().size()); |
Lines 206-211
Link Here
|
206 |
|
193 |
|
207 |
srcCp = ClassPath.getClassPath(srcRoot, PATH_TOP_SOURCES); |
194 |
srcCp = ClassPath.getClassPath(srcRoot, PATH_TOP_SOURCES); |
208 |
assertNotNull(srcCp); |
195 |
assertNotNull(srcCp); |
|
|
196 |
assertEquals(1, srcCp.getRoots().length); |
197 |
assertEquals(srcRoot, srcCp.getRoots()[0]); |
209 |
globalPathRegistry_register(PATH_TOP_SOURCES, srcCp); |
198 |
globalPathRegistry_register(PATH_TOP_SOURCES, srcCp); |
210 |
assertTrue (handler.await()); |
199 |
assertTrue (handler.await()); |
211 |
assertEquals(0, handler.getBinaries().size()); |
200 |
assertEquals(0, handler.getBinaries().size()); |
Lines 267-280
Link Here
|
267 |
assertEquals(1,res.size()); |
256 |
assertEquals(1,res.size()); |
268 |
assertEquals(Boolean.TRUE.toString(), res.iterator().next().getValue("valid")); //NOI18N |
257 |
assertEquals(Boolean.TRUE.toString(), res.iterator().next().getValue("valid")); //NOI18N |
269 |
|
258 |
|
270 |
// sup = QuerySupport.forRoots(InnerIndexer.NAME, InnerIndexer.VERSION, srcRoot); |
259 |
sup = QuerySupport.forRoots(InnerIndexer.NAME, InnerIndexer.VERSION, srcRoot); |
271 |
// res = sup.query("_sn", srcFile.getNameExt(), QuerySupport.Kind.EXACT, (String[]) null); |
260 |
res = sup.query("_sn", srcFile.getNameExt(), QuerySupport.Kind.EXACT, (String[]) null); |
272 |
// assertEquals(5,res.size()); |
261 |
assertEquals(5,res.size()); |
273 |
// count = countModes(res); |
262 |
count = countModes(res); |
274 |
// assertEquals(Integer.valueOf(1), count.get(0)); |
263 |
assertEquals(Integer.valueOf(1), count.get(0)); |
275 |
// assertEquals(Integer.valueOf(2), count.get(1)); |
264 |
assertEquals(Integer.valueOf(2), count.get(1)); |
276 |
// assertEquals(Integer.valueOf(1), count.get(2)); |
265 |
assertEquals(Integer.valueOf(1), count.get(2)); |
277 |
// assertEquals(Integer.valueOf(1), count.get(3)); |
266 |
assertEquals(Integer.valueOf(1), count.get(3)); |
|
|
267 |
} |
268 |
|
269 |
public void testEmbeddingIndexerQueryOnInnerOnly() throws Exception { |
270 |
RepositoryUpdater ru = RepositoryUpdater.getDefault(); |
271 |
assertEquals(0, ru.getScannedBinaries().size()); |
272 |
assertEquals(0, ru.getScannedBinaries().size()); |
273 |
assertEquals(0, ru.getScannedUnknowns().size()); |
274 |
|
275 |
final RepositoryUpdaterTest.TestHandler handler = new RepositoryUpdaterTest.TestHandler(); |
276 |
final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); |
277 |
logger.setLevel (Level.FINEST); |
278 |
logger.addHandler(handler); |
279 |
|
280 |
srcCp = ClassPath.getClassPath(srcRoot, PATH_TOP_SOURCES); |
281 |
assertNotNull(srcCp); |
282 |
assertEquals(1, srcCp.getRoots().length); |
283 |
assertEquals(srcRoot, srcCp.getRoots()[0]); |
284 |
globalPathRegistry_register(PATH_TOP_SOURCES, srcCp); |
285 |
assertTrue (handler.await()); |
286 |
assertEquals(0, handler.getBinaries().size()); |
287 |
assertEquals(1, handler.getSources().size()); |
288 |
assertEquals(srcRoot.toURL(), handler.getSources().get(0)); |
289 |
|
290 |
QuerySupport sup = QuerySupport.forRoots(TopIndexer.NAME, TopIndexer.VERSION, srcRoot); |
291 |
Collection<? extends IndexResult> res = sup.query("_sn", srcFile.getNameExt(), QuerySupport.Kind.EXACT, (String[]) null); |
292 |
assertEquals(1,res.size()); |
293 |
assertEquals(Boolean.TRUE.toString(), res.iterator().next().getValue("valid")); //NOI18N |
294 |
|
295 |
sup = QuerySupport.forRoots(InnerIndexer.NAME, InnerIndexer.VERSION, srcRoot); |
296 |
res = sup.query("_sn", srcFile.getNameExt(), QuerySupport.Kind.EXACT, (String[]) null); |
297 |
assertEquals(4,res.size()); |
298 |
Map<? extends Integer,? extends Integer> count = countModes(res); |
299 |
assertEquals(Integer.valueOf(1), count.get(0)); |
300 |
assertEquals(Integer.valueOf(2), count.get(1)); |
301 |
assertEquals(Integer.valueOf(1), count.get(2)); |
302 |
|
303 |
//Symulate EditorRegistry |
304 |
final Source src = Source.create(srcFile); |
305 |
ParserManager.parse(Collections.<Source>singleton(src), new UserTask() { |
306 |
@Override |
307 |
public void run(ResultIterator resultIterator) throws Exception { |
308 |
} |
309 |
}); |
310 |
final DataObject dobj = DataObject.find(srcFile); |
311 |
final EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class); |
312 |
final StyledDocument doc = ec.openDocument(); |
313 |
SwingUtilities.invokeAndWait(new Runnable() { |
314 |
@Override |
315 |
public void run() { |
316 |
final JEditorPane jp = new JEditorPane() { |
317 |
@Override |
318 |
public boolean isFocusOwner() { |
319 |
return true; |
320 |
} |
321 |
}; |
322 |
jp.setDocument(doc); |
323 |
EditorApiPackageAccessor.get().register(jp); |
324 |
} |
325 |
}); |
326 |
|
327 |
//Do modification |
328 |
NbDocument.runAtomic(doc, new Runnable() { |
329 |
@Override |
330 |
public void run() { |
331 |
try { |
332 |
doc.insertString(doc.getLength(), "<C>", null); //NOI18N |
333 |
} catch (Exception e) { |
334 |
Exceptions.printStackTrace(e); |
335 |
} |
336 |
} |
337 |
}); |
338 |
|
339 |
//Query should be updated |
340 |
sup = QuerySupport.forRoots(InnerIndexer.NAME, InnerIndexer.VERSION, srcRoot); |
341 |
res = sup.query("_sn", srcFile.getNameExt(), QuerySupport.Kind.EXACT, (String[]) null); |
342 |
assertEquals(5,res.size()); |
343 |
count = countModes(res); |
344 |
assertEquals(Integer.valueOf(1), count.get(0)); |
345 |
assertEquals(Integer.valueOf(2), count.get(1)); |
346 |
assertEquals(Integer.valueOf(1), count.get(2)); |
347 |
assertEquals(Integer.valueOf(1), count.get(3)); |
278 |
} |
348 |
} |
279 |
|
349 |
|
280 |
private static Map<? extends Integer, ? extends Integer> countModes(@NonNull final Collection<? extends IndexResult> docs) { |
350 |
private static Map<? extends Integer, ? extends Integer> countModes(@NonNull final Collection<? extends IndexResult> docs) { |
Lines 399-404
Link Here
|
399 |
} else if (text.charAt(i) == 'B') { |
469 |
} else if (text.charAt(i) == 'B') { |
400 |
res.setMode(InnerResult.B); |
470 |
res.setMode(InnerResult.B); |
401 |
break; |
471 |
break; |
|
|
472 |
} else if (text.charAt(i) == 'C') { |
473 |
res.setMode(InnerResult.C); |
474 |
break; |
402 |
} |
475 |
} |
403 |
} |
476 |
} |
404 |
resultCache = res; |
477 |
resultCache = res; |
Lines 480-493
Link Here
|
480 |
@Override |
553 |
@Override |
481 |
public void cancel() { |
554 |
public void cancel() { |
482 |
} |
555 |
} |
483 |
|
|
|
484 |
public static class Factory extends TaskFactory { |
485 |
@Override |
486 |
public Collection<? extends SchedulerTask> create(Snapshot snapshot) { |
487 |
return Collections.<SchedulerTask>singleton(new TopToInnerEmbProvider()); |
488 |
} |
489 |
|
490 |
} |
491 |
} |
556 |
} |
492 |
|
557 |
|
493 |
public static class TopIndexer extends EmbeddingIndexer { |
558 |
public static class TopIndexer extends EmbeddingIndexer { |
Lines 525-531
Link Here
|
525 |
|
590 |
|
526 |
@Override |
591 |
@Override |
527 |
public void filesDirty(Iterable<? extends Indexable> dirty, Context context) { |
592 |
public void filesDirty(Iterable<? extends Indexable> dirty, Context context) { |
528 |
System.out.println("FILES DIRTY!"); |
|
|
529 |
try { |
593 |
try { |
530 |
final IndexingSupport is = IndexingSupport.getInstance(context); |
594 |
final IndexingSupport is = IndexingSupport.getInstance(context); |
531 |
for (Indexable df : dirty) { |
595 |
for (Indexable df : dirty) { |
Lines 591-597
Link Here
|
591 |
|
655 |
|
592 |
@Override |
656 |
@Override |
593 |
public void filesDirty(Iterable<? extends Indexable> dirty, Context context) { |
657 |
public void filesDirty(Iterable<? extends Indexable> dirty, Context context) { |
594 |
System.out.println("INNER DIRTY"); |
|
|
595 |
try { |
658 |
try { |
596 |
final IndexingSupport is = IndexingSupport.getInstance(context); |
659 |
final IndexingSupport is = IndexingSupport.getInstance(context); |
597 |
for (Indexable df : dirty) { |
660 |
for (Indexable df : dirty) { |
Lines 646-669
Link Here
|
646 |
|
709 |
|
647 |
public static class ClassPathProviderImpl implements ClassPathProvider { |
710 |
public static class ClassPathProviderImpl implements ClassPathProvider { |
648 |
|
711 |
|
649 |
static volatile FileObject root; |
712 |
//@GuardedBy("ClassPathProviderImpl.class") |
|
|
713 |
private static FileObject root; |
714 |
//@GuardedBy("ClassPathProviderImpl.class") |
715 |
private static ClassPath cp; |
650 |
|
716 |
|
651 |
private final AtomicReference<ClassPath> cpRef = new AtomicReference<ClassPath>(); |
|
|
652 |
|
717 |
|
|
|
718 |
static synchronized void setRoot(@NonNull final FileObject r) { |
719 |
cp = null; |
720 |
root = r; |
721 |
} |
653 |
|
722 |
|
654 |
@Override |
723 |
@Override |
655 |
public ClassPath findClassPath(FileObject file, String type) { |
724 |
public ClassPath findClassPath(FileObject file, String type) { |
656 |
if (PATH_TOP_SOURCES.equals(type) && |
725 |
synchronized(ClassPathProviderImpl.class) { |
657 |
(FileUtil.isParentOf(root, file) || root.equals(file))) { |
726 |
if (PATH_TOP_SOURCES.equals(type) && |
658 |
ClassPath cp = cpRef.get(); |
727 |
(FileUtil.isParentOf(root, file) || root.equals(file))) { |
659 |
if (cp == null) { |
728 |
if (cp == null) { |
660 |
cp = ClassPathSupport.createClassPath(root); |
729 |
cp = ClassPathSupport.createClassPath(root); |
661 |
if (!cpRef.compareAndSet(null, cp)) { |
|
|
662 |
cp = cpRef.get(); |
663 |
} |
730 |
} |
664 |
} |
731 |
return cp; |
665 |
assert cp != null; |
732 |
} |
666 |
return cp; |
|
|
667 |
} |
733 |
} |
668 |
return null; |
734 |
return null; |
669 |
} |
735 |
} |