diff options
author | Silenio Quarti | 2008-08-28 05:00:12 +0000 |
---|---|---|
committer | Silenio Quarti | 2008-08-28 05:00:12 +0000 |
commit | 0aacda90abbcb51098f23f44879ca1521b464bdd (patch) | |
tree | d0dd9e8992875aeb8a0922e20b21ccffb279278f | |
parent | 97df84a659356a3e86e34b09ded90dfba2d404a4 (diff) | |
download | eclipse.platform.swt-0aacda90abbcb51098f23f44879ca1521b464bdd.tar.gz eclipse.platform.swt-0aacda90abbcb51098f23f44879ca1521b464bdd.tar.xz eclipse.platform.swt-0aacda90abbcb51098f23f44879ca1521b464bdd.zip |
*** empty log message ***
4 files changed, 72 insertions, 28 deletions
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectField.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectField.java index ffa15917f0..04d3bc433a 100644 --- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectField.java +++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectField.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.swt.tools.internal; +import java.io.File; import java.lang.reflect.Field; import java.util.Iterator; @@ -27,7 +28,8 @@ public ReflectField(final ReflectClass declaringClass, final Field field) { this.declaringClass = declaringClass; this.field = field; final Class clazz = field.getType(); - if (false && canChange64(clazz)) { + boolean changes = canChange64(clazz); + if (changes && new File(declaringClass.sourcePath).exists()) { ASTNode ast = declaringClass.getDOM(); final Class[] result = new Class[1]; ast.accept(new ASTVisitor() { @@ -44,6 +46,7 @@ public ReflectField(final ReflectClass declaringClass, final Field field) { else if (clazz == long[].class && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) result[0] = int[].class; else if (clazz == float[].class && (s.indexOf("float /*double*/") != -1|| s.indexOf("float[] /*double[]*/") != -1)) result[0] = double[].class; else if (clazz == double[].class && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) result[0] = float[].class; + else result[0] = clazz; return false; } } diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectMethod.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectMethod.java index 43f625212b..e8a7670924 100644 --- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectMethod.java +++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectMethod.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.swt.tools.internal; +import java.io.File; import java.lang.reflect.Method; import java.util.List; @@ -39,7 +40,7 @@ public ReflectMethod(ReflectClass declaringClass, final Method method) { } } } - if (changes) { + if (changes && new File(declaringClass.sourcePath).exists()) { final String name = method.getName(); ASTNode ast = declaringClass.getDOM(); final MethodDeclaration[] decl = new MethodDeclaration[1]; @@ -60,6 +61,7 @@ public ReflectMethod(ReflectClass declaringClass, final Method method) { return false; } }); + boolean swap = false; ReflectType[] params = new ReflectType[paramTypes.length]; ReflectType[] params64 = new ReflectType[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { @@ -68,14 +70,28 @@ public ReflectMethod(ReflectClass declaringClass, final Method method) { Class clazz = paramTypes[i]; SingleVariableDeclaration node = (SingleVariableDeclaration)decl[0].parameters().get(i); String s = declaringClass.source.substring(node.getStartPosition(), node.getStartPosition() + node.getLength()); - if (clazz == int.class && s.indexOf("int /*long*/") != -1) params64[0] = new ReflectType(long.class); - else if (clazz == long.class && s.indexOf("long /*int*/") != -1) params64[0] = new ReflectType(int.class); - else if (clazz == float.class && s.indexOf("float /*double*/") != -1) params64[0] = new ReflectType(double.class); - else if (clazz == double.class && s.indexOf("double /*float*/") != -1) params64[0] = new ReflectType(float.class); - else if (clazz == int[].class && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) params64[0] = new ReflectType(long[].class); - else if (clazz == long[].class && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) params64[0] = new ReflectType(int[].class); - else if (clazz == float[].class && (s.indexOf("float /*double*/") != -1|| s.indexOf("float[] /*double[]*/") != -1)) params64[0] = new ReflectType(double[].class); - else if (clazz == double[].class && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) params64[0] = new ReflectType(float[].class); + if (clazz == int.class && s.indexOf("int /*long*/") != -1) params64[i] = new ReflectType(long.class); + else if (clazz == int[].class && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) params64[i] = new ReflectType(long[].class); + else if (clazz == float.class && s.indexOf("float /*double*/") != -1) params64[i] = new ReflectType(double.class); + else if (clazz == float[].class && (s.indexOf("float /*double*/") != -1|| s.indexOf("float[] /*double[]*/") != -1)) params64[i] = new ReflectType(double[].class); + else if (clazz == long.class && s.indexOf("long /*int*/") != -1) { + swap = true; + params64[i] = new ReflectType(int.class); + } + else if (clazz == double.class && s.indexOf("double /*float*/") != -1) { + swap = true; + params64[i] = new ReflectType(float.class); + } + else if (clazz == long[].class && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) { + swap = true; + params64[i] = new ReflectType(int[].class); + } + else if (clazz == double[].class && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) { + swap = true; + params64[i] = new ReflectType(float[].class); + } else { + params64[i] = params[i]; + } } else { params64[i] = params[i]; } @@ -84,10 +100,42 @@ public ReflectMethod(ReflectClass declaringClass, final Method method) { this.paramTypes64 = params64; this.returnType = new ReflectType(returnType); if (canChange64(returnType)) { - //TODO + Class clazz = returnType; + ASTNode node = decl[0].getReturnType2(); + String s = declaringClass.source.substring(node.getStartPosition(), decl[0].getName().getStartPosition()); + if (clazz == int.class && s.indexOf("int /*long*/") != -1) this.returnType64 = new ReflectType(long.class); + else if (clazz == int[].class && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) this.returnType64 = new ReflectType(long[].class); + else if (clazz == float.class && s.indexOf("float /*double*/") != -1) this.returnType64 = new ReflectType(double.class); + else if (clazz == float[].class && (s.indexOf("float /*double*/") != -1|| s.indexOf("float[] /*double[]*/") != -1)) this.returnType64 = new ReflectType(double[].class); + else if (clazz == long.class && s.indexOf("long /*int*/") != -1) { + swap = true; + this.returnType64 = new ReflectType(int.class); + } + else if (clazz == double.class && s.indexOf("double /*float*/") != -1) { + swap = true; + this.returnType64 = new ReflectType(float.class); + } + else if (clazz == long[].class && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) { + swap = true; + this.returnType64 = new ReflectType(int[].class); + } + else if (clazz == double[].class && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) { + swap = true; + this.returnType64 = new ReflectType(float[].class); + } else { + this.returnType64 = this.returnType; + } } else { this.returnType64 = this.returnType; } + if (swap) { + ReflectType temp = this.returnType; + this.returnType = this.returnType64; + this.returnType64 = temp; + ReflectType[] tempParams = this.paramTypes; + this.paramTypes = this.paramTypes64; + this.paramTypes64 = tempParams; + } } else { this.returnType = this.returnType64 = new ReflectType(returnType); ReflectType[] params = new ReflectType[paramTypes.length]; diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectType.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectType.java index cc4b76de8f..a190b1aa99 100644 --- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectType.java +++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectType.java @@ -70,9 +70,9 @@ public String getTypeSignature1(boolean define) { public String getTypeSignature2(boolean define) { if (clazz == Void.TYPE) return "void"; - if (clazz == Integer.TYPE) return define ? "SWT_jnit" : "jint"; + if (clazz == Integer.TYPE) return define ? "SWT_jint" : "jint"; if (clazz == Boolean.TYPE) return "jboolean"; - if (clazz == Long.TYPE) return define ? "SWT_jnit" : "jlong"; + if (clazz == Long.TYPE) return define ? "SWT_jint" : "jlong"; if (clazz == Short.TYPE) return "jshort"; if (clazz == Character.TYPE) return "jchar"; if (clazz == Byte.TYPE) return "jbyte"; @@ -105,9 +105,9 @@ public String getTypeSignature3(boolean define) { public String getTypeSignature4(boolean define, boolean struct) { if (clazz == Void.TYPE) return "void"; - if (clazz == Integer.TYPE) return define ? "SWT_jnit" : "jint"; + if (clazz == Integer.TYPE) return define ? "SWT_jint" : "jint"; if (clazz == Boolean.TYPE) return "jboolean"; - if (clazz == Long.TYPE) return define ? "SWT_jnit" : "jlong"; + if (clazz == Long.TYPE) return define ? "SWT_jint" : "jlong"; if (clazz == Short.TYPE) return "jshort"; if (clazz == Character.TYPE) return "jchar"; if (clazz == Byte.TYPE) return "jbyte"; diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/StructsGenerator.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/StructsGenerator.java index 649203afdb..ff42486248 100644 --- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/StructsGenerator.java +++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/StructsGenerator.java @@ -353,12 +353,9 @@ void generateGetFields(JNIClass clazz) { } output(accessor); output(")"); - int byteCount = componentType.getByteCount(); - if (byteCount > 1) { - output(" / "); - output(String.valueOf(byteCount)); - } - output(", ("); + output(" / sizeof("); + output(componentType.getTypeSignature2(!componentType.equals(componentType64))); + output("), ("); output(type.getTypeSignature4(!type.equals(type64), false)); output(")lpStruct->"); output(accessor); @@ -502,13 +499,9 @@ void generateSetFields(JNIClass clazz) { } output(accessor); output(")"); - //TODO - int byteCount = componentType.getByteCount(); - if (byteCount > 1) { - output(" / "); - output(String.valueOf(byteCount)); - } - output(", ("); + output(" / sizeof("); + output(componentType.getTypeSignature2(!componentType.equals(componentType64))); + output("), ("); output(type.getTypeSignature4(!type.equals(type64), false)); output(")lpStruct->"); output(accessor); |