Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.concurrent.Exchanger;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import javax.lang.model.SourceVersion;
import javax.swing.JEditorPane;
import javax.swing.SwingUtilities;
import org.netbeans.NbClipboard;
import org.netbeans.api.java.lexer.JavaTokenId;
import org.netbeans.api.java.source.SourceUtilsTestUtil;
import org.netbeans.api.java.source.SourceUtilsTestUtil2;
import org.netbeans.api.java.source.TestUtilities;
import org.netbeans.api.lexer.Language;
import org.netbeans.core.startup.Main;
import org.netbeans.junit.NbTestCase;
import org.netbeans.modules.java.source.BootClassPathUtil;
import org.netbeans.modules.java.source.parsing.JavacParser;
import org.openide.cookies.EditorCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.util.Lookup;

/**
*
Expand Down Expand Up @@ -155,12 +156,12 @@ private void copyAndPaste(String from, final String to, String golden, String so
try {
source.setSelectionStart(start);
source.setSelectionEnd(end);

source.copy();
syncNbClipboard();

target[0].setCaretPosition(pastePos);

target[0].paste();
syncNbClipboard();
} catch (Exception ex) {
fromAWT[0] = ex;
}
Expand All @@ -179,6 +180,19 @@ private void copyAndPaste(String from, final String to, String golden, String so
assertEquals(golden, actual[0]);
}

// NbClipboard is asynchronoous - this test has to wait for copy/paste to finish
private static void syncNbClipboard() {
NbClipboard nbclip = Lookup.getDefault().lookup(NbClipboard.class);
assertNotNull("active NbClipboard expected", nbclip);
try {
Copy link
Member

@neilcsmith-net neilcsmith-net Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling getContents() might be better here? It should roughly match what was happening before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking on the tasks is the most-direct way to sync on the clipboard. The method is also used from another test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is getContents. I don't think we should change this test, and if we do I think it should use the API.

Method waitFinished = NbClipboard.class.getDeclaredMethod("waitFinished");
waitFinished.setAccessible(true);
waitFinished.invoke(nbclip);
} catch (ReflectiveOperationException ex) {
throw new IllegalStateException("code changed?", ex);
}
}

private JEditorPane paneFor(FileObject src, String fileName, String code, String sourceLevel) throws Exception, DataObjectNotFoundException, IOException {
FileObject fromFO = FileUtil.createData(src, fileName);
TestUtilities.copyStringToFile(fromFO, code);
Expand Down
Loading