Java Code Examples for org.netbeans.api.java.source.JavaSource.Phase#PARSED
The following examples show how to use
org.netbeans.api.java.source.JavaSource.Phase#PARSED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaSourceTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testPhaseCompletionTask () throws MalformedURLException, InterruptedException, IOException { FileObject test = createTestFile ("Test1"); ClassPath bootPath = createBootPath (); ClassPath compilePath = createCompilePath (); ClassPath srcPath = createSourcePath (); JavaSource js = JavaSource.create(ClasspathInfo.create(bootPath, compilePath, srcPath), test); DataObject dobj = DataObject.find(test); EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class); final StyledDocument doc = ec.openDocument(); doc.putProperty(Language.class, JavaTokenId.language()); TokenHierarchy h = TokenHierarchy.get(doc); TokenSequence ts = h.tokenSequence(JavaTokenId.language()); Thread.sleep(500); CountDownLatch[] latches1 = new CountDownLatch[] { new CountDownLatch (1), new CountDownLatch (1) }; CountDownLatch[] latches2 = new CountDownLatch[] { new CountDownLatch (1), new CountDownLatch (1) }; AtomicInteger counter = new AtomicInteger (0); CancellableTask<CompilationInfo> task1 = new DiagnosticTask(latches1, counter, Phase.RESOLVED); CancellableTask<CompilationInfo> task2 = new DiagnosticTask(latches2, counter, Phase.PARSED); JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask(js,task1,Phase.RESOLVED,Priority.HIGH, TaskIndexingMode.ALLOWED_DURING_SCAN); JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask(js,task2,Phase.PARSED,Priority.LOW, TaskIndexingMode.ALLOWED_DURING_SCAN); assertTrue ("Time out",waitForMultipleObjects(new CountDownLatch[] {latches1[0], latches2[0]}, 150000)); assertEquals ("Called more times than expected",2,counter.getAndSet(0)); Thread.sleep(1000); //Making test a more deterministic, when the task is cancelled by DocListener, it's hard for test to recover from it NbDocument.runAtomic (doc, new Runnable () { public void run () { try { String text = doc.getText(0,doc.getLength()); int index = text.indexOf(REPLACE_PATTERN); assertTrue (index != -1); doc.remove(index,REPLACE_PATTERN.length()); doc.insertString(index,"System.out.println();",null); } catch (BadLocationException ble) { ble.printStackTrace(System.out); } } }); assertTrue ("Time out",waitForMultipleObjects(new CountDownLatch[] {latches1[1], latches2[1]}, 15000)); assertEquals ("Called more times than expected",2,counter.getAndSet(0)); JavaSourceAccessor.getINSTANCE().removePhaseCompletionTask (js,task1); JavaSourceAccessor.getINSTANCE().removePhaseCompletionTask (js,task2); }
Example 2
Source File: JavaSourceTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testParsingDelay() throws MalformedURLException, InterruptedException, IOException, BadLocationException { FileObject test = createTestFile ("Test1"); ClassPath bootPath = createBootPath (); ClassPath compilePath = createCompilePath (); ClassPath sourcePath = createSourcePath(); JavaSource js = JavaSource.create(ClasspathInfo.create(bootPath, compilePath, sourcePath), test); DataObject dobj = DataObject.find(test); EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class); final StyledDocument doc = ec.openDocument(); doc.putProperty(Language.class, JavaTokenId.language()); TokenHierarchy h = TokenHierarchy.get(doc); TokenSequence ts = h.tokenSequence(JavaTokenId.language()); Thread.sleep(500); //It may happen that the js is invalidated before the dispatch of task is done and the test of timers may fail CountDownLatch[] latches = new CountDownLatch[] { new CountDownLatch (1), new CountDownLatch (1) }; long[] timers = new long[2]; AtomicInteger counter = new AtomicInteger (0); CancellableTask<CompilationInfo> task = new DiagnosticTask(latches, timers, counter, Phase.PARSED); JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask (js,task,Phase.PARSED, Priority.HIGH, TaskIndexingMode.ALLOWED_DURING_SCAN); assertTrue ("Time out",waitForMultipleObjects(new CountDownLatch[] {latches[0]}, 15000)); assertEquals ("Called more times than expected",1,counter.getAndSet(0)); long start = System.currentTimeMillis(); Thread.sleep(500); //Making test a more deterministic, when the task is cancelled by DocListener, it's hard for test to recover from it NbDocument.runAtomic (doc, new Runnable () { public void run () { try { String text = doc.getText(0,doc.getLength()); int index = text.indexOf(REPLACE_PATTERN); assertTrue (index != -1); doc.remove(index,REPLACE_PATTERN.length()); doc.insertString(index,"System.out.println();",null); } catch (BadLocationException ble) { ble.printStackTrace(System.out); } } }); assertTrue ("Time out",waitForMultipleObjects(new CountDownLatch[] {latches[1]}, 15000)); assertEquals ("Called more times than expected",1,counter.getAndSet(0)); assertTrue("Took less time than expected time=" + (timers[1] - start), (timers[1] - start) >= TestUtil.getReparseDelay()); JavaSourceAccessor.getINSTANCE().removePhaseCompletionTask (js,task); }
Example 3
Source File: JavaSourceTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testJavaSourceIsReclaimable() throws MalformedURLException, InterruptedException, IOException, BadLocationException { FileObject test = createTestFile ("Test1"); ClassPath bootPath = createBootPath (); ClassPath compilePath = createCompilePath (); ClassPath srcPath = createSourcePath(); JavaSource js = JavaSource.create(ClasspathInfo.create(bootPath, compilePath, srcPath), test); DataObject dobj = DataObject.find(test); EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class); final StyledDocument[] doc = new StyledDocument[] {ec.openDocument()}; doc[0].putProperty(Language.class, JavaTokenId.language()); TokenHierarchy h = TokenHierarchy.get(doc[0]); TokenSequence ts = h.tokenSequence(JavaTokenId.language()); Thread.sleep(500); CountDownLatch[] latches = new CountDownLatch[] { new CountDownLatch (1), new CountDownLatch (1) }; AtomicInteger counter = new AtomicInteger (0); CancellableTask<CompilationInfo> task = new DiagnosticTask(latches, counter, Phase.PARSED); JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask (js,task,Phase.PARSED,Priority.HIGH, TaskIndexingMode.ALLOWED_DURING_SCAN); assertTrue ("Time out",waitForMultipleObjects(new CountDownLatch[] {latches[0]}, 15000)); Thread.sleep(500); //Making test a more deterministic, when the task is cancelled by DocListener, it's hard for test to recover from it NbDocument.runAtomic (doc[0], new Runnable () { public void run () { try { String text = doc[0].getText(0,doc[0].getLength()); int index = text.indexOf(REPLACE_PATTERN); assertTrue (index != -1); doc[0].remove(index,REPLACE_PATTERN.length()); doc[0].insertString(index,"System.out.println();",null); } catch (BadLocationException ble) { ble.printStackTrace(System.out); } } }); assertTrue ("Time out",waitForMultipleObjects(new CountDownLatch[] {latches[1]}, 15000)); JavaSourceAccessor.getINSTANCE().removePhaseCompletionTask (js,task); Reference jsWeak = new WeakReference(js); Reference testWeak = new WeakReference(test); SaveCookie sc = (SaveCookie) dobj.getCookie(SaveCookie.class); sc.save(); sc = null; js = null; test = null; dobj = null; ec = null; doc[0] = null; //give the worker thread chance to remove the task: //if the tests starts to fail randomly, try to increment the timeout Thread.sleep(1000); assertGC("JavaSource is reclaimable", jsWeak); //the file objects is held by the timers component //and maybe others: assertGC("FileObject is reclaimable", testWeak); }
Example 4
Source File: JavaSourceTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testChangeInvalidates() throws MalformedURLException, InterruptedException, IOException, BadLocationException { FileObject test = createTestFile ("Test1"); ClassPath bootPath = createBootPath (); ClassPath compilePath = createCompilePath (); ClassPath srcPath = createSourcePath(); JavaSource js = JavaSource.create(ClasspathInfo.create(bootPath, compilePath, srcPath), test); int originalReparseDelay = TestUtil.getReparseDelay(); try { TestUtil.setReparseDelay(JavaSourceAccessor.getINSTANCE().getSources(js).iterator().next(),Integer.MAX_VALUE,false); //never automatically reparse CountDownLatch latch1 = new CountDownLatch (1); final CountDownLatch latch2 = new CountDownLatch (1); AtomicInteger counter = new AtomicInteger (0); CancellableTask<CompilationInfo> task = new DiagnosticTask(new CountDownLatch[] {latch1}, counter, Phase.PARSED); JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask (js,task,Phase.PARSED,Priority.HIGH, TaskIndexingMode.ALLOWED_DURING_SCAN); assertTrue ("Time out",waitForMultipleObjects(new CountDownLatch[] {latch1}, 15000)); DataObject dobj = DataObject.find(test); EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class); final StyledDocument[] doc = new StyledDocument[] {ec.openDocument()}; doc[0].putProperty(Language.class, JavaTokenId.language()); TokenHierarchy h = TokenHierarchy.get(doc[0]); TokenSequence ts = h.tokenSequence(JavaTokenId.language()); Thread.sleep(500); //Making test a more deterministic, when the task is cancelled by DocListener, it's hard for test to recover from it NbDocument.runAtomic (doc[0], new Runnable () { public void run () { try { String text = doc[0].getText(0,doc[0].getLength()); int index = text.indexOf(REPLACE_PATTERN); assertTrue (index != -1); doc[0].remove(index,REPLACE_PATTERN.length()); doc[0].insertString(index,"System.out.println();",null); } catch (BadLocationException ble) { ble.printStackTrace(System.out); } } }); final boolean[] contentCorrect = new boolean[1]; js.runUserActionTask(new Task<CompilationController>() { public void run(CompilationController controler) { try { controler.toPhase(Phase.PARSED); contentCorrect[0] = controler.getText().contains("System.out.println"); latch2.countDown(); } catch (IOException ioe) { ioe.printStackTrace(); } } },true); assertTrue("Time out",waitForMultipleObjects(new CountDownLatch[] {latch2}, 15000)); assertTrue("Content incorrect", contentCorrect[0]); JavaSourceAccessor.getINSTANCE().removePhaseCompletionTask (js,task); } finally { if (js != null) { TestUtil.setReparseDelay(JavaSourceAccessor.getINSTANCE().getSources(js).iterator().next(), originalReparseDelay, true); } } }
Example 5
Source File: EmbeddedHintsCollector.java From netbeans with Apache License 2.0 | 4 votes |
public EmbeddedHintsCollector() { super(Phase.PARSED, TaskIndexingMode.DISALLOWED_DURING_SCAN); }
Example 6
Source File: JavaElementFoldManagerTaskFactory.java From netbeans with Apache License 2.0 | 4 votes |
public JavaElementFoldManagerTaskFactory() { super(Phase.PARSED, Priority.NORMAL, TaskIndexingMode.ALLOWED_DURING_SCAN); }
Example 7
Source File: LookupBasedJavaSourceTaskFactoryTest.java From netbeans with Apache License 2.0 | 4 votes |
public LookupBasedJavaSourceTaskFactoryImpl(int[] changeCount) { super(Phase.PARSED, Priority.MIN); this.changeCount = changeCount; }
Example 8
Source File: JavaSemanticTokenList.java From netbeans with Apache License 2.0 | 4 votes |
public FactoryImpl() { super(Phase.PARSED, Priority.LOW, TaskIndexingMode.ALLOWED_DURING_SCAN); }