01: package de.loskutov.bco.editors;
02:
03: import java.lang.reflect.Method;
04:
05: import org.eclipse.jdt.core.IBuffer;
06: import org.eclipse.jdt.core.IOpenable;
07: import org.eclipse.jdt.internal.core.BufferManager;
08:
09: /**
10: * This class is a hack that mades JDT <code>BufferManager</code> methods
11: * <code>addBuffer()</code> and <code>removeBuffer()</code> accessible.
12: *
13: * It does NOT modify or replace the instance of default buffer manager, because if they
14: * are more then one plugin which performs such hack, then it will end up in a big bang.
15: *
16: * @author Andrei
17: */
18: public final class BytecodeBufferManager {
19:
20: private BytecodeBufferManager() {
21: super ();
22: }
23:
24: public static IBuffer getBuffer(IOpenable owner) {
25: return BufferManager.getDefaultBufferManager().getBuffer(owner);
26: }
27:
28: public static IBuffer createBuffer(IOpenable owner) {
29: return BufferManager.getDefaultBufferManager().createBuffer(
30: owner);
31: }
32:
33: /**
34: * @see BufferManager#addBuffer(IBuffer)
35: */
36: public static void addBuffer(IBuffer buffer) {
37: BufferManager manager = BufferManager.getDefaultBufferManager();
38: try {
39: Method addMethod = BufferManager.class.getDeclaredMethod(
40: "addBuffer", new Class[] { IBuffer.class });
41: addMethod.setAccessible(true);
42: addMethod.invoke(manager, new Object[] { buffer });
43: } catch (Exception e) {
44: // TODO Auto-generated catch block
45: e.printStackTrace();
46: }
47: }
48:
49: /**
50: * @see BufferManager#removeBuffer(IBuffer)
51: */
52: public static void removeBuffer(IBuffer buffer) {
53: if (buffer != null) {
54: BufferManager manager = BufferManager
55: .getDefaultBufferManager();
56: try {
57: Method removeMethod = BufferManager.class
58: .getDeclaredMethod("removeBuffer",
59: new Class[] { IBuffer.class });
60: removeMethod.setAccessible(true);
61: removeMethod.invoke(manager, new Object[] { buffer });
62: } catch (Exception e) {
63: // TODO Auto-generated catch block
64: e.printStackTrace();
65: }
66: }
67: }
68: }
|