下面列出了java.lang.reflect.InvocationTargetException#printStackTrace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void waitForIdle() {
try {
Toolkit.getDefaultToolkit().sync();
sun.awt.SunToolkit.flushPendingEvents();
EventQueue.invokeAndWait( new Runnable() {
public void run() {
// dummy implementation
}
} );
} catch(InterruptedException ite) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ite.printStackTrace();
} catch(InvocationTargetException ine) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ine.printStackTrace();
}
}
private void waitForIdle() {
try {
Toolkit.getDefaultToolkit().sync();
sun.awt.SunToolkit.flushPendingEvents();
EventQueue.invokeAndWait( new Runnable() {
public void run() {
// dummy implementation
}
} );
} catch(InterruptedException ite) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ite.printStackTrace();
} catch(InvocationTargetException ine) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ine.printStackTrace();
}
}
private void waitForIdle() {
try {
Toolkit.getDefaultToolkit().sync();
sun.awt.SunToolkit.flushPendingEvents();
EventQueue.invokeAndWait( new Runnable() {
public void run() {
// dummy implementation
}
} );
} catch(InterruptedException ite) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ite.printStackTrace();
} catch(InvocationTargetException ine) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ine.printStackTrace();
}
}
/**
* Cocoa wants the range of characters that are currently marked. Since Java doesn't store committed and
* text in progress (composed text) together, we have to synthesize it. We know where the text will be
* inserted, so we can return that position, and the length of the text in progress. If there is no marked text
* return null.
*/
synchronized private int[] markedRange() {
if (fCurrentText == null)
return null;
final int[] returnValue = new int[2];
try {
LWCToolkit.invokeAndWait(new Runnable() {
public void run() { synchronized(returnValue) {
// The insert position is always after the composed text, so the range start is the
// insert spot less the length of the composed text.
returnValue[0] = fIMContext.getInsertPositionOffset();
}}
}, fAwtFocussedComponent);
} catch (InvocationTargetException ite) { ite.printStackTrace(); }
returnValue[1] = fCurrentTextLength;
synchronized(returnValue) { return returnValue; }
}
/**
* Waits until all events currently on the event queue have been processed.
* @throws IllegalThreadStateException if called on the AWT event dispatching thread
*/
public synchronized void waitForIdle() {
checkNotDispatchThread();
// post a dummy event to the queue so we know when
// all the events before it have been processed
try {
SunToolkit.flushPendingEvents();
EventQueue.invokeAndWait( new Runnable() {
public void run() {
// dummy implementation
}
} );
} catch(InterruptedException ite) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ite.printStackTrace();
} catch(InvocationTargetException ine) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ine.printStackTrace();
}
}
/**
* Load the task list from the GUI
*
* @throws InterruptedException
*/
private List<Task> loadTasksFromGUI() throws InterruptedException {
try {
EventDispatchThreadRunner.runOnDispatchThread(() -> {
gui = new Gui();
gui.open();
}, true);
} catch (InvocationTargetException e) {
e.printStackTrace();
log("Failed to create GUI");
return Collections.emptyList();
}
if (!gui.isStarted()) {
return Collections.emptyList();
}
return gui.getTasksAsList();
}
private void supportMinOrMaxDimesion(int widthHint, int heightHint, View view, PercentLayoutInfo info) {
try {
Class clazz = view.getClass();
invokeMethod("setMaxWidth", widthHint, heightHint, view, clazz, info.maxWidthPercent);
invokeMethod("setMaxHeight", widthHint, heightHint, view, clazz, info.maxHeightPercent);
invokeMethod("setMinWidth", widthHint, heightHint, view, clazz, info.minWidthPercent);
invokeMethod("setMinHeight", widthHint, heightHint, view, clazz, info.minHeightPercent);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e2) {
e2.printStackTrace();
} catch (IllegalAccessException e3) {
e3.printStackTrace();
}
}
void flushBuffers() {
if (isVisible() && !nativeBounds.isEmpty() && !isFullScreenMode) {
try {
LWCToolkit.invokeAndWait(new Runnable() {
@Override
public void run() {
//Posting an empty to flush the EventQueue without blocking the main thread
}
}, target);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
private void testAwtControls() throws InterruptedException {
try {
for (Component component : getAWTControls()) {
testComponent(component);
}
if (testEmbeddedFrame && !skipTestingEmbeddedFrame) {
testEmbeddedFrame();
}
} catch (InvocationTargetException ex) {
ex.printStackTrace();
fail(ex.getMessage());
}
}
static void benchmarkClassOperations(String className) throws Exception {
Class<?> klazz = loadClassInNewClassLoader(className);
Method[] methods = klazz.getDeclaredMethods();
if (methods.length != METHOD_COUNT) {
throw new AssertionError("unexpected method count: " + methods.length +
" expected: " + METHOD_COUNT);
}
methods = klazz.getMethods();
// returned methods includes those inherited from Object
int objectMethodSlop = 100;
if (methods.length <= METHOD_COUNT ||
methods.length >= METHOD_COUNT + objectMethodSlop) {
throw new AssertionError("unexpected method count: " + methods.length);
}
// Invoke methods to make them appear in the constant pool cache
Object obj = klazz.newInstance();
Object[] args = new Object[0];
for (Method m: methods) {
try {
Class<?>[] types = m.getParameterTypes();
String name = m.getName();
// System.out.println("method: " + name + "; argno: " + types.length);
if (types.length == 0 && name.length() == 2 && name.startsWith("f")) {
m.invoke(obj, args);
}
} catch (InvocationTargetException ex) {
ex.printStackTrace();
}
}
}
/**
* Returns an InterfaceAddress instance with its fields set the the values
* specificed.
*/
static InterfaceAddress createInterfaceAddress(
InetAddress address, InetAddress broadcast, short prefixlength) {
try {
Class<InterfaceAddress> IAClass = InterfaceAddress.class;
InterfaceAddress ia;
Constructor<InterfaceAddress> ctr = IAClass.getDeclaredConstructor();
ctr.setAccessible(true);
Field addressField = IAClass.getDeclaredField("address");
addressField.setAccessible(true);
Field broadcastField = IAClass.getDeclaredField("broadcast");
broadcastField.setAccessible(true);
Field maskLengthField = IAClass.getDeclaredField("maskLength");
maskLengthField.setAccessible(true);
ia = ctr.newInstance();
addressField.set(ia, address);
broadcastField.set(ia, broadcast);
maskLengthField.setShort(ia, prefixlength);
return ia;
} catch (NoSuchFieldException nsfe) {
nsfe.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InstantiationException ie) {
ie.printStackTrace();
} catch (IllegalAccessException iae) {
iae.printStackTrace();
} catch (InvocationTargetException ite) {
ite.printStackTrace();
}
return null;
}
void flushBuffers() {
if (isVisible() && !nativeBounds.isEmpty() && !isFullScreenMode) {
try {
LWCToolkit.invokeAndWait(new Runnable() {
@Override
public void run() {
//Posting an empty to flush the EventQueue without blocking the main thread
}
}, target);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
public static Object invoke(Object o, Method m, Object... objects) {
m.setAccessible(true);
try {
return m.invoke(o, objects);
} catch (IllegalAccessException var4) {
var4.printStackTrace();
} catch (InvocationTargetException var5) {
var5.printStackTrace();
}
return null;
}
private void sendOp() {
Player player = this.<Player>getPlayer().parent;
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
PacketConstructor statusCtr = manager.createPacketConstructor(PacketType.Play.Server.ENTITY_STATUS, player, (byte) 28);
PacketContainer status = statusCtr.createPacket(player, (byte) 28);
try {
manager.sendServerPacket(player, status);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public static ByteBuf decompress(ChannelHandlerContext ctx, ByteBuf bytebuf) {
try {
return (ByteBuf) callDecode((MessageToMessageDecoder) ctx.pipeline().get("decompress"), ctx.pipeline().context("decompress"), bytebuf).get(0);
} catch (InvocationTargetException e) {
e.printStackTrace();
return ctx.alloc().buffer();
}
}
static void invokeLater(final Runnable runnable, final Component c) {
try {
LWCToolkit.invokeLater(runnable, c);
} catch (InvocationTargetException e) { e.printStackTrace(); }
}
static void invokeLater(final Runnable runnable, final Component c) {
try {
LWCToolkit.invokeLater(runnable, c);
} catch (InvocationTargetException e) { e.printStackTrace(); }
}
/**
* Cocoa assumes the marked text and committed text is all stored in the same storage, but
* Java does not. So, we have to see where the request is and based on that return the right
* substring.
*/
synchronized private String attributedSubstringFromRange(final int locationIn, final int lengthIn) {
final String[] retString = new String[1];
try {
LWCToolkit.invokeAndWait(new Runnable() {
public void run() { synchronized(retString) {
int location = locationIn;
int length = lengthIn;
if ((location + length) > (fIMContext.getCommittedTextLength() + fCurrentTextLength)) {
length = fIMContext.getCommittedTextLength() - location;
}
AttributedCharacterIterator theIterator = null;
if (fCurrentText == null) {
theIterator = fIMContext.getCommittedText(location, location + length, null);
} else {
int insertSpot = fIMContext.getInsertPositionOffset();
if (location < insertSpot) {
theIterator = fIMContext.getCommittedText(location, location + length, null);
} else if (location >= insertSpot && location < insertSpot + fCurrentTextLength) {
theIterator = fCurrentText.getIterator(null, location - insertSpot, location - insertSpot +length);
} else {
theIterator = fIMContext.getCommittedText(location - fCurrentTextLength, location - fCurrentTextLength + length, null);
}
}
// Get the characters from the iterator
char selectedText[] = new char[theIterator.getEndIndex() - theIterator.getBeginIndex()];
char current = theIterator.first();
int index = 0;
while (current != CharacterIterator.DONE) {
selectedText[index++] = current;
current = theIterator.next();
}
retString[0] = new String(selectedText);
}}
}, fAwtFocussedComponent);
} catch (InvocationTargetException ite) { ite.printStackTrace(); }
synchronized(retString) { return retString[0]; }
}
/**
* Cocoa assumes the marked text and committed text is all stored in the same storage, but
* Java does not. So, we have to see where the request is and based on that return the right
* substring.
*/
private synchronized String attributedSubstringFromRange(final int locationIn, final int lengthIn) {
final String[] retString = new String[1];
try {
LWCToolkit.invokeAndWait(new Runnable() {
public void run() { synchronized(retString) {
int location = locationIn;
int length = lengthIn;
if ((location + length) > (fIMContext.getCommittedTextLength() + fCurrentTextLength)) {
length = fIMContext.getCommittedTextLength() - location;
}
AttributedCharacterIterator theIterator = null;
if (fCurrentText == null) {
theIterator = fIMContext.getCommittedText(location, location + length, null);
} else {
int insertSpot = fIMContext.getInsertPositionOffset();
if (location < insertSpot) {
theIterator = fIMContext.getCommittedText(location, location + length, null);
} else if (location >= insertSpot && location < insertSpot + fCurrentTextLength) {
theIterator = fCurrentText.getIterator(null, location - insertSpot, location - insertSpot +length);
} else {
theIterator = fIMContext.getCommittedText(location - fCurrentTextLength, location - fCurrentTextLength + length, null);
}
}
// Get the characters from the iterator
char selectedText[] = new char[theIterator.getEndIndex() - theIterator.getBeginIndex()];
char current = theIterator.first();
int index = 0;
while (current != CharacterIterator.DONE) {
selectedText[index++] = current;
current = theIterator.next();
}
retString[0] = new String(selectedText);
}}
}, fAwtFocussedComponent);
} catch (InvocationTargetException ite) { ite.printStackTrace(); }
synchronized(retString) { return retString[0]; }
}
/**
* Cocoa assumes the marked text and committed text is all stored in the same storage, but
* Java does not. So, we have to see where the request is and based on that return the right
* substring.
*/
synchronized private String attributedSubstringFromRange(final int locationIn, final int lengthIn) {
final String[] retString = new String[1];
try {
LWCToolkit.invokeAndWait(new Runnable() {
public void run() { synchronized(retString) {
int location = locationIn;
int length = lengthIn;
if ((location + length) > (fIMContext.getCommittedTextLength() + fCurrentTextLength)) {
length = fIMContext.getCommittedTextLength() - location;
}
AttributedCharacterIterator theIterator = null;
if (fCurrentText == null) {
theIterator = fIMContext.getCommittedText(location, location + length, null);
} else {
int insertSpot = fIMContext.getInsertPositionOffset();
if (location < insertSpot) {
theIterator = fIMContext.getCommittedText(location, location + length, null);
} else if (location >= insertSpot && location < insertSpot + fCurrentTextLength) {
theIterator = fCurrentText.getIterator(null, location - insertSpot, location - insertSpot +length);
} else {
theIterator = fIMContext.getCommittedText(location - fCurrentTextLength, location - fCurrentTextLength + length, null);
}
}
// Get the characters from the iterator
char selectedText[] = new char[theIterator.getEndIndex() - theIterator.getBeginIndex()];
char current = theIterator.first();
int index = 0;
while (current != CharacterIterator.DONE) {
selectedText[index++] = current;
current = theIterator.next();
}
retString[0] = new String(selectedText);
}}
}, fAwtFocussedComponent);
} catch (InvocationTargetException ite) { ite.printStackTrace(); }
synchronized(retString) { return retString[0]; }
}