aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native/KDWindow.c
blob: 682edff24beef5a1b20d7e5f7364f021f839c9e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
 * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * - Redistribution of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 
 * - Redistribution in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * 
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * 
 */

#ifdef _WIN32
  #include <windows.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* This typedef is apparently needed for Microsoft compilers before VC8,
   and on Windows CE */
#if (_MSC_VER < 1400) || defined(UNDER_CE)
    #ifdef _WIN64
        typedef long long intptr_t;
    #else
        typedef int intptr_t;
    #endif
#elif _MSC_VER <= 1500
    #ifdef _WIN64 // [
        typedef __int64           intptr_t;
    #else // _WIN64 ][
        typedef int               intptr_t;
    #endif // _WIN64 ]
#else
    #include <inttypes.h>
#endif

#include <KD/kd.h>
#include <KD/NV_extwindowprops.h>

#include "com_sun_javafx_newt_opengl_kd_KDWindow.h"

#include "EventListener.h"
#include "MouseEvent.h"
#include "KeyEvent.h"

// #define VERBOSE_ON 1

#ifdef VERBOSE_ON
    #define DBG_PRINT(...) fprintf(stdout, __VA_ARGS__)
#else
    #define DBG_PRINT(...)
#endif

#ifdef VERBOSE_ON
    #ifdef _WIN32_WCE
        #define STDOUT_FILE "\\Storage Card\\stdout.txt"
        #define STDERR_FILE "\\Storage Card\\stderr.txt"
    #endif
#endif

#define JOGL_KD_USERDATA_MAGIC 0xDEADBEEF
typedef struct {
    long magic;
    KDWindow * kdWindow;
    jobject javaWindow;
} JOGLKDUserdata;

static jmethodID windowCreatedID = NULL;
static jmethodID sizeChangedID = NULL;
static jmethodID windowDestroyNotifyID = NULL;
static jmethodID windowDestroyedID = NULL;
static jmethodID sendMouseEventID = NULL;
static jmethodID sendKeyEventID = NULL;

/**
 * Display
 */

JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDDisplay_DispatchMessages
  (JNIEnv *env, jobject obj)
{
    const KDEvent * evt;
    int numEvents = 0;

    // Periodically take a break
    while( numEvents<100 && NULL!=(evt=kdWaitEvent(0)) ) {
        KDWindow *kdWindow;
        jobject javaWindow;
        JOGLKDUserdata * userData = (JOGLKDUserdata *)(intptr_t)evt->userptr;
        if(NULL == userData || userData->magic!=JOGL_KD_USERDATA_MAGIC) {
            DBG_PRINT( "event unrelated: evt type: 0x%X\n", evt->type);
            continue;
        }
        kdWindow = userData->kdWindow;
        javaWindow = userData->javaWindow;
        DBG_PRINT( "[DispatchMessages]: userData %p, evt type: 0x%X\n", userData, evt->type);

        numEvents++;

        // FIXME: support resize and window re-positioning events

        switch(evt->type) {
            case KD_EVENT_WINDOW_FOCUS:
                {
                    KDboolean hasFocus;
                    kdGetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_FOCUS, &hasFocus);
                    DBG_PRINT( "event window focus : src: %p\n", userData);
                }
                break;
            case KD_EVENT_WINDOW_CLOSE:
                {
                    DBG_PRINT( "event window close : src: %p\n", userData);
                    (*env)->CallVoidMethod(env, javaWindow, windowDestroyNotifyID);
                    // Called by Window.java: DestroyWindow(wnd);
                    //  (*env)->CallVoidMethod(env, javaWindow, windowDestroyedID);
                }
                break;
            case KD_EVENT_WINDOWPROPERTY_CHANGE:
                {
                    const KDEventWindowProperty* prop = &evt->data.windowproperty;
                    switch (prop->pname) {
                        case KD_WINDOWPROPERTY_SIZE:
                            {
                                KDint32 v[2];
                                if(!kdGetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_SIZE, v)) {
                                    DBG_PRINT( "event window size change : src: %p %dx%d\n", userData, v[0], v[1]);
                                    (*env)->CallVoidMethod(env, javaWindow, sizeChangedID, (jint) v[0], (jint) v[1]);
                                } else {
                                    DBG_PRINT( "event window size change error: src: %p %dx%d\n", userData, v[0], v[1]);
                                }
                            }
                            break;
                        case KD_WINDOWPROPERTY_FOCUS:
                            DBG_PRINT( "event window focus: src: %p\n", userData);
                            break;
                        case KD_WINDOWPROPERTY_VISIBILITY:
                            {
                                KDboolean visible;
                                kdGetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visible);
                                DBG_PRINT( "event window visibility: src: %p, v:%d\n", userData, visible);
                            }
                            break;
                        default:
                            break;
                    }
                }
                break;
            case KD_EVENT_INPUT_POINTER:
                {
                    const KDEventInputPointer* ptr = &(evt->data.inputpointer);
                    // button idx: evt->data.input.index
                    // pressed = ev->data.input.value.i
                    // time = ev->timestamp
                    if(KD_INPUT_POINTER_SELECT==ptr->index) {
                        DBG_PRINT( "event mouse click: src: %p, s:%d, (%d,%d)\n", userData, ptr->select, ptr->x, ptr->y);
                        (*env)->CallVoidMethod(env, javaWindow, sendMouseEventID, 
                                              (ptr->select==0) ? (jint) EVENT_MOUSE_RELEASED : (jint) EVENT_MOUSE_PRESSED, 
                                              (jint) 0,
                                              (jint) ptr->x, (jint) ptr->y, 1, 0);
                    } else {
                        DBG_PRINT( "event mouse: src: %d, s:%p, i:0x%X (%d,%d)\n", userData, ptr->select, ptr->index, ptr->x, ptr->y);
                        (*env)->CallVoidMethod(env, javaWindow, sendMouseEventID, (jint) EVENT_MOUSE_MOVED, 
                                              0,
                                              (jint) ptr->x, (jint) ptr->y, 0, 0);
                    }
                }
                break;
        }
    } 
}

/**
 * Window
 */

JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_kd_KDWindow_initIDs
  (JNIEnv *env, jclass clazz)
{
#ifdef VERBOSE_ON
    #ifdef _WIN32_WCE
        _wfreopen(TEXT(STDOUT_FILE),L"w",stdout);
        _wfreopen(TEXT(STDERR_FILE),L"w",stderr);
    #endif
#endif
    windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(J)V");
    sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
    windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify",    "()V");
    windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
    sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
    sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
    if (windowCreatedID == NULL ||
        sizeChangedID == NULL ||
        windowDestroyNotifyID == NULL ||
        windowDestroyedID == NULL ||
        sendMouseEventID == NULL ||
        sendKeyEventID == NULL) {
        DBG_PRINT( "initIDs failed\n" );
        return JNI_FALSE;
    }
    DBG_PRINT( "initIDs ok\n" );
    return JNI_TRUE;
}

JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_kd_KDWindow_CreateWindow
  (JNIEnv *env, jobject obj, jlong display, jintArray jAttrs)
{
    jint * attrs = NULL;
    jsize attrsLen;
    EGLDisplay dpy  = (EGLDisplay)(intptr_t)display;
    KDWindow *window = 0;

    if(dpy==NULL) {
        fprintf(stderr, "[CreateWindow] invalid display connection..\n");
        return 0;
    }

    attrsLen = (*env)->GetArrayLength(env, jAttrs);
    if(0==attrsLen) {
        fprintf(stderr, "[CreateWindow] attribute array size 0..\n");
        return 0;
    }
    attrs = (*env)->GetIntArrayElements(env, jAttrs, 0);
    if(NULL==attrs) {
        fprintf(stderr, "[CreateWindow] attribute array NULL..\n");
        return 0;
    }

    JOGLKDUserdata * userData = kdMalloc(sizeof(JOGLKDUserdata));
    userData->magic = JOGL_KD_USERDATA_MAGIC;
    window = kdCreateWindow(dpy, attrs, (void *)userData);

    (*env)->ReleaseIntArrayElements(env, jAttrs, attrs, 0);

    if(NULL==window) {
        kdFree(userData);
        fprintf(stderr, "[CreateWindow] failed: 0x%X\n", kdGetError());
    } else {
        userData->javaWindow = (*env)->NewGlobalRef(env, obj);
        userData->kdWindow = window;
        (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) userData);
        DBG_PRINT( "[CreateWindow] ok: %p, userdata %p\n", window, userData);
    }
    return (jlong) (intptr_t) window;
}

JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_kd_KDWindow_RealizeWindow
  (JNIEnv *env, jobject obj, jlong window)
{
    KDWindow *w = (KDWindow*) (intptr_t) window;
    EGLNativeWindowType nativeWindow=0;

    jint res = kdRealizeWindow(w, &nativeWindow);
    if(res) {
        fprintf(stderr, "[RealizeWindow] failed: 0x%X, 0x%X\n", res, kdGetError());
        nativeWindow = NULL;
    }
    DBG_PRINT( "[RealizeWindow] ok: %p\n", nativeWindow);
    return (jlong) (intptr_t) nativeWindow;
}

JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_kd_KDWindow_CloseWindow
  (JNIEnv *env, jobject obj, jlong window, jlong juserData)
{
    KDWindow *w = (KDWindow*) (intptr_t) window;
    JOGLKDUserdata * userData = (JOGLKDUserdata*) (intptr_t) juserData;
    int res = kdDestroyWindow(w);
    (*env)->DeleteGlobalRef(env, userData->javaWindow);
    kdFree(userData);

    DBG_PRINT( "[CloseWindow] res: %d\n", res);
    return res;
}

/*
 * Class:     com_sun_javafx_newt_kd_KDWindow
 * Method:    setVisible0
 * Signature: (JJZ)V
 */
JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setVisible0
  (JNIEnv *env, jobject obj, jlong window, jboolean visible)
{
    KDWindow *w = (KDWindow*) (intptr_t) window;
    KDboolean v = (visible==JNI_TRUE)?KD_TRUE:KD_FALSE;
    kdSetWindowPropertybv(w, KD_WINDOWPROPERTY_VISIBILITY, &v);
    DBG_PRINT( "[setVisible] v=%d\n", visible);
}

JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setFullScreen0
  (JNIEnv *env, jobject obj, jlong window, jboolean fullscreen)
{
    KDWindow *w = (KDWindow*) (intptr_t) window;
    KDboolean v = fullscreen;

    int res = kdSetWindowPropertybv(w, KD_WINDOWPROPERTY_FULLSCREEN_NV, &v);
    DBG_PRINT( "[setFullScreen] v=%d, res=%d\n", fullscreen, res);
    (void)res;
}

JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setSize0
  (JNIEnv *env, jobject obj, jlong window, jint width, jint height)
{
    KDWindow *w = (KDWindow*) (intptr_t) window;
    KDint32 v[] = { width, height };

    int res = kdSetWindowPropertyiv(w, KD_WINDOWPROPERTY_SIZE, v);
    DBG_PRINT( "[setSize] v=%dx%d, res=%d\n", width, height, res);
    (void)res;

    (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height);
}

signatureUsesCPrimitivePointers; } /** * Returns true if the return type or any of the outgoing arguments * in the method's signature represent C arrays. */ public boolean signatureUsesCArrays() { computeSignatureProperties(); return signatureUsesCArrays; } /** * Returns true if the return type or any of the outgoing arguments * in the method's signature represent Java primitive arrays. */ public boolean signatureUsesJavaPrimitiveArrays() { computeSignatureProperties(); return signatureUsesJavaPrimitiveArrays; } /** * Computes summary information about the method's C and Java * signatures. */ protected void computeSignatureProperties() { if (computedSignatureProperties) return; argumentsUseNIO = false; signatureUsesNIO = false; signatureCanUseIndirectNIO = false; signatureUsesCompoundTypeWrappers = false; signatureUsesArraysOfCompoundTypeWrappers = false; signatureUsesCVoidPointers = false; signatureUsesCPrimitivePointers = false; signatureUsesCArrays = false; signatureUsesJavaPrimitiveArrays = false; signatureRequiresStaticInitialization = false; if ( javaReturnType.isCompoundTypeWrapper() ) { // Needs wrapping and/or setting of byte order (neither of which // can be done easily from native code) signatureUsesCompoundTypeWrappers = true; final Type cReturnType = getCReturnType(); if ( !cReturnType.isPointer() ) { // FIXME: Compound call-by-value signatureRequiresStaticInitialization = true; } } if (javaReturnType.isNIOBuffer() || javaReturnType.isArrayOfCompoundTypeWrappers()) { // Needs setting of byte order and possibly viewing as a // different buffer type which can't be done easily from native // code signatureUsesNIO = true; } final Type cRetType = sym.getReturnType(); if (cRetType.isArray()) { // Needs checking of array lengths signatureUsesCArrays = true; if (cRetType.asArray().getElementType().isPrimitive()) { signatureUsesCPrimitivePointers = true; } } if (cRetType.isPointer()) { if (cRetType.asPointer().getTargetType().isPrimitive()) { signatureUsesCPrimitivePointers = true; } else if (cRetType.asPointer().getTargetType().isVoid()) { signatureUsesCVoidPointers = true; } } for (int i = 0; i < getNumArguments(); i++) { final JavaType javaArgType = getJavaArgumentType(i); final Type cArgType = getCArgumentType(i); if (javaArgType.isCompoundTypeWrapper()) { // Needs unwrapping of accessors signatureUsesCompoundTypeWrappers = true; } if (javaArgType.isArrayOfCompoundTypeWrappers()) { // Needs to be duplicated and this array lowered to an array // of Buffers for code emission signatureUsesArraysOfCompoundTypeWrappers = true; } if (javaArgType.isNIOBuffer() || javaArgType.isNIOBufferArray()) { // Needs checking of direct buffer property signatureUsesNIO = true; argumentsUseNIO = true; if (javaArgType.isNIOBuffer()) { // Potential conversion to indirect buffer signatureCanUseIndirectNIO = true; } } if (cArgType.isArray()) { // Needs checking of array lengths signatureUsesCArrays = true; if (cArgType.asArray().getElementType().isPrimitive()) { signatureUsesCPrimitivePointers = true; } } if (cArgType.isPointer()) { // Handle both real C primitive pointers and any constructions // due to opaque directives if (cArgType.asPointer().getTargetType().isPrimitive() || javaArgType.isCPrimitivePointerType()) { signatureUsesCPrimitivePointers = true; } else if (cArgType.asPointer().getTargetType().isVoid()) { signatureUsesCVoidPointers = true; } } if (javaArgType.isPrimitiveArray()) { // Needs getPrimitiveArrayCritical or similar construct // depending on native code calling convention signatureUsesJavaPrimitiveArrays = true; } } computedSignatureProperties = true; } /** * Indicates whether this MethodBinding is for a function pointer * contained in a struct, or to access array- or pointer-data from a struct. * <p> * The native calling convention, i.e. via a 'this' function pointer * or by a static native function must be decided in the * {@link JavaEmitter} handling structs and * passed to the {@link CMethodBindingEmitter#setIsCStructFunctionPointer(boolean)}. * </p> */ public boolean hasContainingType() { return (getContainingType() != null); } /** Retrieves the containing type of this MethodBinding if it is for a function pointer contained in a struct. */ public JavaType getContainingType() { return containingType; } /** Retrieves the containing C type of this MethodBinding if it is for a function pointer contained in a struct. */ public Type getContainingCType() { return containingCType; } /** Find the leftmost argument matching the type of the containing type (for function pointer MethodBindings) and record that as a "this" pointer, meaning that it does not need to be explicitly passed at the Java level. */ public void findThisPointer() { clearThisPointer(); for (int i = 0; i < getNumArguments(); i++) { final JavaType arg = getJavaArgumentType(i); if (arg.equals(containingType)) { thisPointerIndex = i; break; } if (!arg.isJNIEnv()) { break; // this pointer must be leftmost argument excluding JNIEnvs } } } /** Clears any record of a this pointer for this MethodBinding. */ public void clearThisPointer() { thisPointerIndex = -1; } /** Indicates whether the <i>i</i>th argument to this MethodBinding is actually a "this" pointer. */ public boolean isArgumentThisPointer(final int i) { return (thisPointerIndex == i); } @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj == null || ! (obj instanceof MethodBinding)) { return false; } final MethodBinding other = (MethodBinding)obj; if ( !getName().equals(other.getName()) || !sym.getType().equals(other.sym.getType()) ) { return false; } if (!(javaReturnType.equals(other.getJavaReturnType()))) { return false; } if (containingCType != null && other.getContainingCType() != null && (!(containingCType.equals(other.getContainingCType())))) { return false; } if (javaArgumentTypes.size() != other.javaArgumentTypes.size()) { return false; } for (int i = 0; i < javaArgumentTypes.size(); ++i) { final Object typeThis = javaArgumentTypes.get(i); final Object typeOther = other.getJavaArgumentType(i); if (!(typeThis.equals(typeOther))) { return false; } } return true; } @Override public int hashCode() { final StringBuilder buf = new StringBuilder(200); buf.append(getName()); buf.append(sym.getType().getName(true)); buf.append(getJavaReturnType().getName()); if (containingCType != null) { buf.append(containingCType.getName(true)); } for (int i = 0; i < getNumArguments(); i++) { final JavaType type = getJavaArgumentType(i); if (type.isVoid()) { // Make sure this is the only param to the method; if it isn't, // there's something wrong with our parsing of the headers. assert(getNumArguments() == 1); continue; } buf.append(type.getName()); } return buf.toString().hashCode(); } /** Returns the signature of this binding. */ @Override public String toString() { final StringBuilder buf = new StringBuilder(200); buf.append(getJavaReturnType().getName()); buf.append(' '); buf.append(getName()); buf.append('('); boolean needComma = false; for (int i = 0; i < getNumArguments(); i++) { final JavaType type = getJavaArgumentType(i); if (type.isVoid()) { // Make sure this is the only param to the method; if it isn't, // there's something wrong with our parsing of the headers. assert(getNumArguments() == 1); continue; } if (type.isJNIEnv() || isArgumentThisPointer(i)) { // Don't need to expose these at the Java level continue; } if (needComma) { buf.append(", "); } buf.append(type.getName()); buf.append(' '); buf.append(getArgumentName(i)); needComma = true; } buf.append(')'); return buf.toString(); } /** Returns a String containing the descriptor (signature in internal format) of this MethodBinding as it will be emitted. This is used to disambiguate between overloadings when manually specifying prologue and epilogue code, for example. */ public String getDescriptor(final boolean forImplementingMethodCall, final boolean eraseBufferAndArrayTypes) { final StringBuilder buf = new StringBuilder(); buf.append('('); if (forImplementingMethodCall && hasContainingType()) { // Always emit outgoing "this" argument buf.append("Ljava/nio/ByteBuffer;"); } for (int i = 0; i < getNumArguments(); i++) { final JavaType type = getJavaArgumentType(i); if (type.isVoid()) { // Make sure this is the only param to the method; if it isn't, // there's something wrong with our parsing of the headers. if (getNumArguments() != 1) { throw new InternalError( "\"void\" argument type found in " + "multi-argument function \"" + this + "\""); } continue; } if (type.isJNIEnv() || isArgumentThisPointer(i)) { // Don't need to expose these at the Java level continue; } buf.append(erasedTypeDescriptor(type, eraseBufferAndArrayTypes, false)); // Add Buffer and array index offset arguments after each associated argument if (forImplementingMethodCall) { if (type.isNIOBuffer()) { buf.append('I'); } else if (type.isNIOBufferArray()) { buf.append("[I"); } } // Add offset argument after each primitive array if (type.isPrimitiveArray()) { buf.append('I'); } } buf.append(')'); // Emit return type for completeness even though we can't overload // based solely on return type buf.append(erasedTypeDescriptor(getJavaReturnType(), eraseBufferAndArrayTypes, false)); return buf.toString(); } protected String erasedTypeDescriptor(final JavaType type, final boolean eraseBufferAndArrayTypes, final boolean skipBuffers) { if (eraseBufferAndArrayTypes) { if (type.isNIOBuffer() || type.isPrimitiveArray()) { if (!skipBuffers) { // Direct buffers and arrays sent down as Object (but // returned as e.g. ByteBuffer) return "Ljava/lang/Object;"; } } else if (type.isCompoundTypeWrapper()) { // Compound type wrappers are unwrapped to ByteBuffer return "Ljava/nio/ByteBuffer;"; } else if (type.isArrayOfCompoundTypeWrappers()) { return "Ljava/nio/ByteBuffer;"; } } return type.getDescriptor(); } }