当前位置: 首页>>代码示例>>Java>>正文


Java NbDocument.runAtomic方法代码示例

本文整理汇总了Java中org.openide.text.NbDocument.runAtomic方法的典型用法代码示例。如果您正苦于以下问题:Java NbDocument.runAtomic方法的具体用法?Java NbDocument.runAtomic怎么用?Java NbDocument.runAtomic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.text.NbDocument的用法示例。


在下文中一共展示了NbDocument.runAtomic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: defaultAction

import org.openide.text.NbDocument; //导入方法依赖的package包/类
public void defaultAction(final JTextComponent component) {
    Completion.get().hideCompletion();
    Completion.get().hideDocumentation();
    NbDocument.runAtomic((StyledDocument) component.getDocument(), new Runnable() {
        public void run() {
            Document doc = component.getDocument();
            
            try {
                doc.remove(substituteOffset, component.getCaretPosition() - substituteOffset);
                doc.insertString(substituteOffset, getText(), null);
            } catch (BadLocationException e) {
                ErrorManager.getDefault().notify(e);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:WordCompletionItem.java

示例2: defaultAction

import org.openide.text.NbDocument; //导入方法依赖的package包/类
@Override
public void defaultAction(final JTextComponent component) {
    Completion.get().hideCompletion();
    Completion.get().hideDocumentation();
    NbDocument.runAtomic((StyledDocument) component.getDocument(), new Runnable() {
        @Override
        public void run() {
            Document doc = component.getDocument();

            try {
                doc.remove(0, doc.getLength());
                doc.insertString(0, getText(), null);
            } catch (BadLocationException e) {
                Logger.getLogger(SearchCompletionItem.class.getName()).log(Level.FINE, null, e);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:SearchCompletionItem.java

示例3: defaultAction

import org.openide.text.NbDocument; //导入方法依赖的package包/类
@Override
public void defaultAction(final JTextComponent component) {
    Completion.get().hideCompletion();
    Completion.get().hideDocumentation();
    NbDocument.runAtomic((StyledDocument) component.getDocument(), new Runnable() {
        @Override
        public void run() {
            Document doc = component.getDocument();
            
            try {
                doc.remove(substituteOffset, component.getCaretPosition() - substituteOffset);
                doc.insertString(substituteOffset, getText(), null);
            } catch (BadLocationException e) {
                Logger.getLogger(FXMLCompletionItem.class.getName()).log(Level.FINE, null, e);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:FXMLCompletionItem.java

示例4: regenerateSourceImpl

import org.openide.text.NbDocument; //导入方法依赖的package包/类
void regenerateSourceImpl(StyledDocument doc) {
    NbDocument.runAtomic(doc, new Runnable() {
            public void run()  {
                regenerateBeanDescriptor();
                regenerateProperties();
                regenerateEvents();
                if (!olderVersion) {
                    regenerateMethods();
                }
                regenerateIcons();
                regenerateDefaultIdx();
                regenerateSuperclass();
                isModified = false;
                isIconModified = false;
            }
    } );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:BiAnalyser.java

示例5: close

import org.openide.text.NbDocument; //导入方法依赖的package包/类
public synchronized @Override void close() throws IOException {
    try {
        NbDocument.runAtomic(this.doc,
            new Runnable () {
                @Override
                public void run () {
                    try {
                        doc.remove(0,doc.getLength());
                        doc.insertString(0,new String(
                            data,
                            0,
                            pos,
                            FileEncodingQuery.getEncoding(getHandle().resolveFileObject(false))),
                        null);
                    } catch (BadLocationException e) {
                        if (LOG.isLoggable(Level.SEVERE))
                            LOG.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            });
    } finally {
        resetCaches();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:SourceFileObject.java

示例6: implement

import org.openide.text.NbDocument; //导入方法依赖的package包/类
public ChangeInfo implement() throws Exception {
    NbDocument.runAtomic(doc, new Runnable() {
        public void run() {
            try {
                doc.remove(start, end - start);
                doc.insertString(start, text, null);
            } catch (BadLocationException ex) {
                throw new IllegalStateException(ex);
            }
        }
    });
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:EditorTestPerformer.java

示例7: replace

import org.openide.text.NbDocument; //导入方法依赖的package包/类
private void replace(final StyledDocument doc, final int start, final int length, final String text) {
    NbDocument.runAtomic(doc, new Runnable() {
        @Override    
        public void run() {
            try {
                doc.remove(start, length);
                doc.insertString(start, text, null);
            } catch (BadLocationException e) {
                Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.getMessage(), e);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:EditableDiffView.java

示例8: testSetTextWithGuardMarks

import org.openide.text.NbDocument; //导入方法依赖的package包/类
public void testSetTextWithGuardMarks() throws Throwable {
    final Throwable[] ts = new Throwable[1];
    NbDocument.runAtomic(editor.doc, new Runnable() {
        public void run() {
            try {
                doTestSetTextWithGuardMarks();
            } catch (Throwable ex) {
                ts[0] = ex;
            }
        }
    });
    if (ts[0] != null) {
        throw ts[0];
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:PositionBoundsTest.java

示例9: testDeadlock164258

import org.openide.text.NbDocument; //导入方法依赖的package包/类
public void testDeadlock164258() throws Exception {
    final StyledDocument doc = (StyledDocument) createDocument("text/plain", "");
    final Source source = Source.create(doc);
    assertNotNull("No Source for " + doc, source);
    final CountDownLatch startLatch1 = new CountDownLatch(1);
    final CountDownLatch startLatch2 = new CountDownLatch(1);

    //Prerender
    ParserManager.parse(Collections.singleton(source), new UserTask() {
        @Override
        public void run(ResultIterator resultIterator) throws Exception {
            
        }
    });

    new Thread() {
        public void run () {
            NbDocument.runAtomic(doc, new Runnable() {
                public void run () {
                    try {
                        startLatch1.await();
                        startLatch2.countDown();
                        SourceAccessor.getINSTANCE().getEnvControl(source).sourceChanged(false);
                    } catch (InterruptedException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            });
        }
    }.start();
    synchronized(TaskProcessor.INTERNAL_LOCK) {
        startLatch1.countDown();
        startLatch2.await();
        NbDocument.runAtomic(doc, new Runnable() {
            public void run() {
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:SourceTest.java

示例10: parseLapPlan

import org.openide.text.NbDocument; //导入方法依赖的package包/类
/**
 * Take the {@link DataEditorSupport#getDocument() document} holding the lap
 * plan, parse it and return resulting lap tree.
 *
 * @return Current lap tree.
 */
public PoshPlan parseLapPlan() throws ParseException {
    StyledDocument doc = getEditorSupport().getDocument();
    GetDocumentText getText = new GetDocumentText(doc);
    NbDocument.runAtomic(doc, getText);
    String lapPlan = getText.text;
    PoshParser parser = new PoshParser(new StringReader(lapPlan));
    return parser.parsePlan();
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:15,代码来源:PoshDataObject.java

示例11: testPhaseCompletionTask

import org.openide.text.NbDocument; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:JavaSourceTest.java

示例12: testInterference

import org.openide.text.NbDocument; //导入方法依赖的package包/类
public void testInterference () throws MalformedURLException, IOException, InterruptedException {
    FileObject testFile1 = createTestFile ("Test1");
    FileObject testFile2 = createTestFile ("Test2");
    ClassPath bootPath = createBootPath ();
    ClassPath compilePath = createCompilePath ();
    ClassPath srcPath = createSourcePath();
    JavaSource js1 = JavaSource.create(ClasspathInfo.create(bootPath, compilePath, srcPath), testFile1);
    JavaSource js2 = JavaSource.create(ClasspathInfo.create(bootPath, compilePath, srcPath), testFile2);
    DataObject dobj = DataObject.find(testFile1);
    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),
    };
    CountDownLatch latch3 = new CountDownLatch (1);
    AtomicInteger counter = new AtomicInteger (0);

    DiagnosticTask task1 = new DiagnosticTask(latches1, counter, Phase.RESOLVED);
    CancellableTask<CompilationInfo> task2 = new DiagnosticTask(latches2, counter, Phase.RESOLVED);

    JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask(js1,task1,Phase.RESOLVED,Priority.HIGH, TaskIndexingMode.ALLOWED_DURING_SCAN);
    Thread.sleep(500);  //Making test a more deterministic, when the task is cancelled by DocListener, it's hard for test to recover from it
    js2.runUserActionTask(new CompileControlJob(latch3),true);
    JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask(js2,task2,Phase.RESOLVED,Priority.MAX, TaskIndexingMode.ALLOWED_DURING_SCAN);
    boolean result = waitForMultipleObjects (new CountDownLatch[] {latches1[0], latches2[0], latch3}, 15000);
    if (!result) {
        assertTrue (String.format("Time out, latches1[0]: %d latches2[0]: %d latches3: %d",latches1[0].getCount(), latches2[0].getCount(), latch3.getCount()), false);
    }
    assertEquals ("Called more times than expected",2,counter.getAndSet(0));

    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[] {latches1[1]}, 15000));
    assertEquals ("Called more times than expected",1,counter.getAndSet(0));
    JavaSourceAccessor.getINSTANCE().removePhaseCompletionTask(js1,task1);
    JavaSourceAccessor.getINSTANCE().removePhaseCompletionTask(js2,task2);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:59,代码来源:JavaSourceTest.java

示例13: testDocumentChanges

import org.openide.text.NbDocument; //导入方法依赖的package包/类
public void testDocumentChanges () throws Exception {
    FileObject testFile1 = createTestFile ("Test1");
    ClassPath bootPath = createBootPath ();
    ClassPath compilePath = createCompilePath ();
    ClassPath srcPath = createSourcePath();
    JavaSource js1 = JavaSource.create(ClasspathInfo.create(bootPath, compilePath, srcPath), testFile1);

    final CountDownLatch start = new CountDownLatch (1);
    final CountDownLatch stop =  new CountDownLatch (1);
    final AtomicBoolean last = new AtomicBoolean (false);
    final AtomicInteger counter = new AtomicInteger (0);

    CancellableTask<CompilationInfo> task = new CancellableTask<CompilationInfo>() {

        private int state = 0;

        public void cancel() {
        }

        public void run(CompilationInfo ci) throws Exception {
            switch (state) {
                case 0:
                    state = 1;
                    start.countDown();
                    break;
                case 1:
                    counter.incrementAndGet();
                    if (last.get()) {
                        stop.countDown();
                    }
                    break;
            }
        }
    };
    JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask(js1,task,Phase.PARSED,Priority.HIGH, TaskIndexingMode.ALLOWED_DURING_SCAN);
    start.await();
    Thread.sleep(500);
    final DataObject dobj = DataObject.find(testFile1);
    final 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());
    for (int i=0; i<10; i++) {
        if (i == 9) {
            last.set(true);
        }
        NbDocument.runAtomic (doc,
            new Runnable () {
                public void run () {
                    try {
                        doc.insertString(0," ",null);
                    } catch (BadLocationException ble) {
                        ble.printStackTrace(System.out);
                    }
                }
        });
        Thread.sleep(100);
    }
    assertTrue ("Time out",stop.await(15000, TimeUnit.MILLISECONDS));
    assertEquals("Called more time than expected",1,counter.get());
    JavaSourceAccessor.getINSTANCE().removePhaseCompletionTask(js1,task);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:64,代码来源:JavaSourceTest.java

示例14: testParsingDelay

import org.openide.text.NbDocument; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:JavaSourceTest.java

示例15: testJavaSourceIsReclaimable

import org.openide.text.NbDocument; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:66,代码来源:JavaSourceTest.java


注:本文中的org.openide.text.NbDocument.runAtomic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。