Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt.tools')
-rw-r--r--bundles/org.eclipse.swt.tools/.settings/org.eclipse.pde.prefs2
-rw-r--r--bundles/org.eclipse.swt.tools/Icon Exe/org/eclipse/swt/tools/internal/IconExe.java26
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTField.java16
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTMethod.java32
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupClass.java4
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupConstants.java4
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupNatives.java2
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/JNIGeneratorApp.java2
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/LockGenerator.java4
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java12
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectField.java16
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ReflectMethod.java32
-rw-r--r--bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java1014
-rw-r--r--bundles/org.eclipse.swt.tools/META-INF/MANIFEST.MF6
-rw-r--r--bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java694
-rw-r--r--bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGeneratorUI.java78
-rw-r--r--bundles/org.eclipse.swt.tools/plugin.xml32
-rw-r--r--bundles/org.eclipse.swt.tools/pom.xml4
-rw-r--r--bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/Activator.java68
-rw-r--r--bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/builders/Check64CompilationParticipant.java373
-rw-r--r--bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/builders/Check64EnableAction.java40
21 files changed, 851 insertions, 1610 deletions
diff --git a/bundles/org.eclipse.swt.tools/.settings/org.eclipse.pde.prefs b/bundles/org.eclipse.swt.tools/.settings/org.eclipse.pde.prefs
new file mode 100644
index 0000000000..2d3d6b7f98
--- /dev/null
+++ b/bundles/org.eclipse.swt.tools/.settings/org.eclipse.pde.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+compilers.p.unresolved-ex-points=1 \ No newline at end of file
diff --git a/bundles/org.eclipse.swt.tools/Icon Exe/org/eclipse/swt/tools/internal/IconExe.java b/bundles/org.eclipse.swt.tools/Icon Exe/org/eclipse/swt/tools/internal/IconExe.java
index 547a8dc03e..27e488390b 100644
--- a/bundles/org.eclipse.swt.tools/Icon Exe/org/eclipse/swt/tools/internal/IconExe.java
+++ b/bundles/org.eclipse.swt.tools/Icon Exe/org/eclipse/swt/tools/internal/IconExe.java
@@ -28,11 +28,11 @@ import org.eclipse.swt.*;
*/
public class IconExe {
- /**
+ /**
* Replace the Desktop icons provided in the Windows executable program
* with matching icons provided by the user.
*
- * Takes 2 arguments
+ * Takes 2 arguments
* argument 0: the Windows executable e.g c:/eclipse/eclipse.exe
* argument 1: The .ico file to write to the given executable e.g. c:/myApp.ico
*
@@ -258,7 +258,7 @@ void dumpResourceDirectory(RandomAccessFile raf, int imageResourceDirectoryOffse
}
}
}
- }
+ }
}
static ImageData parseIcon(RandomAccessFile raf, int offset) throws IOException {
@@ -2616,13 +2616,13 @@ static class LEDataInputStream extends InputStream {
}
/**
- * Reads at most <code>length</code> bytes from this LEDataInputStream and
- * stores them in byte array <code>buffer</code> starting at <code>offset</code>.
- * <p>
- * Answer the number of bytes actually read or -1 if no bytes were read and
- * end of stream was encountered. This implementation reads bytes from
- * the pushback buffer first, then the target stream if more bytes are required
- * to satisfy <code>count</code>.
+ * Reads at most <code>length</code> bytes from this LEDataInputStream and
+ * stores them in byte array <code>buffer</code> starting at <code>offset</code>.
+ * <p>
+ * Answer the number of bytes actually read or -1 if no bytes were read and
+ * end of stream was encountered. This implementation reads bytes from
+ * the pushback buffer first, then the target stream if more bytes are required
+ * to satisfy <code>count</code>.
* </p>
* @param buffer the byte array in which to store the read bytes.
* @param offset the offset in <code>buffer</code> to store the read bytes.
@@ -2635,9 +2635,9 @@ static class LEDataInputStream extends InputStream {
private int readData(byte[] buffer, int offset, int length) throws IOException {
if (buf == null) throw new IOException();
if (offset < 0 || offset > buffer.length ||
- length < 0 || (length > buffer.length - offset)) {
- throw new ArrayIndexOutOfBoundsException();
- }
+ length < 0 || (length > buffer.length - offset)) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
int cacheCopied = 0;
int newOffset = offset;
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTField.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTField.java
index 0696cefe95..91bcb310fa 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTField.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTField.java
@@ -47,14 +47,14 @@ public ASTField(ASTClass declaringClass, String source, FieldDeclaration field,
type64 = this.type;
if (GEN64) {
String s = source.substring(field.getStartPosition(), field.getStartPosition() + field.getLength());
- if (type.isType("int") && s.indexOf("int /*long*/") != -1) type64 = new ASTType("J");
- else if (type.isType("float") && s.indexOf("float /*double*/") != -1) type64 = new ASTType("D");
- else if (type.isType("[I") && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) type64 = new ASTType("[J");
- else if (type.isType("[F") && (s.indexOf("float /*double*/") != -1|| s.indexOf("float[] /*double[]*/") != -1)) type64 = new ASTType("[D");
- else if (type.isType("long") && s.indexOf("long /*int*/") != -1) type = new ASTType("I");
- else if (type.isType("double") && s.indexOf("double /*float*/") != -1) type = new ASTType("F");
- else if (type.isType("[J") && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) type = new ASTType("[I");
- else if (type.isType("[D") && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) type = new ASTType("[F");
+ if (type.isType("int") && s.contains("int /*long*/")) type64 = new ASTType("J");
+ else if (type.isType("float") && s.contains("float /*double*/")) type64 = new ASTType("D");
+ else if (type.isType("[I") && (s.contains("int /*long*/") || s.contains("int[] /*long[]*/"))) type64 = new ASTType("[J");
+ else if (type.isType("[F") && (s.contains("float /*double*/")|| s.contains("float[] /*double[]*/"))) type64 = new ASTType("[D");
+ else if (type.isType("long") && s.contains("long /*int*/")) type = new ASTType("I");
+ else if (type.isType("double") && s.contains("double /*float*/")) type = new ASTType("F");
+ else if (type.isType("[J") && (s.contains("long /*int*/")|| s.contains("long[] /*int[]*/"))) type = new ASTType("[I");
+ else if (type.isType("[D") && (s.contains("double /*float*/")|| s.contains("double[] /*float[]*/"))) type = new ASTType("[F");
}
}
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTMethod.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTMethod.java
index c3613d746f..28953f2def 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTMethod.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTMethod.java
@@ -52,14 +52,14 @@ public ASTMethod(ASTClass declaringClass, String source, MethodDeclaration metho
returnType64 = returnType;
if (GEN64) {
String s = source.substring(method.getReturnType2().getStartPosition(), method.getName().getStartPosition());
- if (returnType.isType("int") && s.indexOf("int /*long*/") != -1) returnType64 = new ASTType("J");
- else if (returnType.isType("float") && s.indexOf("float /*double*/") != -1) returnType64 = new ASTType("D");
- else if (returnType.isType("[I") && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) returnType64 = new ASTType("[J");
- else if (returnType.isType("[F") && (s.indexOf("float /*double*/") != -1|| s.indexOf("float[] /*double[]*/") != -1)) returnType64 = new ASTType("[D");
- else if (returnType.isType("long") && s.indexOf("long /*int*/") != -1) returnType = new ASTType("I");
- else if (returnType.isType("double") && s.indexOf("double /*float*/") != -1) returnType = new ASTType("F");
- else if (returnType.isType("[J") && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) returnType = new ASTType("[I");
- else if (returnType.isType("[D") && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) returnType = new ASTType("[F");
+ if (returnType.isType("int") && s.contains("int /*long*/")) returnType64 = new ASTType("J");
+ else if (returnType.isType("float") && s.contains("float /*double*/")) returnType64 = new ASTType("D");
+ else if (returnType.isType("[I") && (s.contains("int /*long*/") || s.contains("int[] /*long[]*/"))) returnType64 = new ASTType("[J");
+ else if (returnType.isType("[F") && (s.contains("float /*double*/")|| s.contains("float[] /*double[]*/"))) returnType64 = new ASTType("[D");
+ else if (returnType.isType("long") && s.contains("long /*int*/")) returnType = new ASTType("I");
+ else if (returnType.isType("double") && s.contains("double /*float*/")) returnType = new ASTType("F");
+ else if (returnType.isType("[J") && (s.contains("long /*int*/")|| s.contains("long[] /*int[]*/"))) returnType = new ASTType("[I");
+ else if (returnType.isType("[D") && (s.contains("double /*float*/")|| s.contains("double[] /*float[]*/"))) returnType = new ASTType("[F");
}
List<SingleVariableDeclaration> parameters = method.parameters();
@@ -74,14 +74,14 @@ public ASTMethod(ASTClass declaringClass, String source, MethodDeclaration metho
this.parameters[i] = new ASTParameter(this, i, param.getName().getIdentifier());
if (GEN64) {
String s = source.substring(param.getStartPosition(), param.getStartPosition() + param.getLength());
- if (paramTypes[i].isType("int") && s.indexOf("int /*long*/") != -1) paramTypes64[i] = new ASTType("J");
- else if (paramTypes[i].isType("float") && s.indexOf("float /*double*/") != -1) paramTypes64[i] = new ASTType("D");
- else if (paramTypes[i].isType("[I") && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) paramTypes64[i] = new ASTType("[J");
- else if (paramTypes[i].isType("[F") && (s.indexOf("float /*double*/") != -1|| s.indexOf("float[] /*double[]*/") != -1)) paramTypes64[i] = new ASTType("[D");
- else if (paramTypes[i].isType("long") && s.indexOf("long /*int*/") != -1) paramTypes[i] = new ASTType("I");
- else if (paramTypes[i].isType("double") && s.indexOf("double /*float*/") != -1) paramTypes[i] = new ASTType("F");
- else if (paramTypes[i].isType("[J") && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) paramTypes[i] = new ASTType("[I");
- else if (paramTypes[i].isType("[D") && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) paramTypes[i] = new ASTType("[F");
+ if (paramTypes[i].isType("int") && s.contains("int /*long*/")) paramTypes64[i] = new ASTType("J");
+ else if (paramTypes[i].isType("float") && s.contains("float /*double*/")) paramTypes64[i] = new ASTType("D");
+ else if (paramTypes[i].isType("[I") && (s.contains("int /*long*/") || s.contains("int[] /*long[]*/"))) paramTypes64[i] = new ASTType("[J");
+ else if (paramTypes[i].isType("[F") && (s.contains("float /*double*/")|| s.contains("float[] /*double[]*/"))) paramTypes64[i] = new ASTType("[D");
+ else if (paramTypes[i].isType("long") && s.contains("long /*int*/")) paramTypes[i] = new ASTType("I");
+ else if (paramTypes[i].isType("double") && s.contains("double /*float*/")) paramTypes[i] = new ASTType("F");
+ else if (paramTypes[i].isType("[J") && (s.contains("long /*int*/")|| s.contains("long[] /*int[]*/"))) paramTypes[i] = new ASTType("[I");
+ else if (paramTypes[i].isType("[D") && (s.contains("double /*float*/")|| s.contains("double[] /*float[]*/"))) paramTypes[i] = new ASTType("[F");
}
if (tags != null) {
String name = param.getName().getIdentifier();
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupClass.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupClass.java
index 43a9e7035e..d582f8f1b0 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupClass.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupClass.java
@@ -37,8 +37,8 @@ String[] getArgNames(JNIMethod method) {
int parantesesStart = classSource.indexOf("(", index);
if (classSource.substring(index + name.length(), parantesesStart).trim().length() == 0) {
int parantesesEnd = classSource.indexOf(")", parantesesStart);
- params = classSource.substring(parantesesStart + 1, parantesesEnd);
- break;
+ params = classSource.substring(parantesesStart + 1, parantesesEnd);
+ break;
}
}
String[] names = new String[n_args];
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupConstants.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupConstants.java
index 19f1147190..5b8c1af1a2 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupConstants.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupConstants.java
@@ -27,7 +27,7 @@ String getFieldValue(JNIField field) {
int equalsIndex = classSource.indexOf("=", index);
if (classSource.substring(index + name.length(), equalsIndex).trim().length() == 0) {
int semiIndex = classSource.indexOf(";", equalsIndex);
- return classSource.substring(equalsIndex + 1, semiIndex).trim();
+ return classSource.substring(equalsIndex + 1, semiIndex).trim();
}
}
}
@@ -53,7 +53,7 @@ public void generate(JNIField[] fields) {
public void generate(JNIField field) {
String name = field.getName();
for (String str : files.values()) {
- if (str.indexOf(name) != -1) {
+ if (str.contains(name)) {
int modifiers = field.getModifiers();
String modifiersStr = Modifier.toString(modifiers);
output("\t");
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupNatives.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupNatives.java
index fd2186fa53..c2f6c3529c 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupNatives.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/CleanupNatives.java
@@ -42,7 +42,7 @@ public void generate(JNIMethod[] methods) {
public void generate(JNIMethod method) {
String name = method.getName();
for (String str : files.values()) {
- if (str.indexOf(name) != -1) {
+ if (str.contains(name)) {
// int modifiers = method.getModifiers();
// Class clazz = method.getDeclaringClass();
// String modifiersStr = Modifier.toString(modifiers);
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/JNIGeneratorApp.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/JNIGeneratorApp.java
index 8b194b08f6..857d0cb935 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/JNIGeneratorApp.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/JNIGeneratorApp.java
@@ -371,6 +371,8 @@ JNIClass[] getASTClasses() {
if (cce.getMessage().startsWith(EnumDeclaration.class.getName())) {
// this can be ignored since enums don't affect native files
}
+ } catch (IndexOutOfBoundsException e) {
+ // ignore, can also happen because of enums
}
}
}
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/LockGenerator.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/LockGenerator.java
index e70a747a6f..c0157d9d08 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/LockGenerator.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/LockGenerator.java
@@ -35,8 +35,8 @@ String getParams(JNIMethod method) {
int parantesesStart = classSource.indexOf("(", index);
if (classSource.substring(index + name.length(), parantesesStart).trim().length() == 0) {
int parantesesEnd = classSource.indexOf(")", parantesesStart);
- params = classSource.substring(parantesesStart + 1, parantesesEnd);
- break;
+ params = classSource.substring(parantesesStart + 1, parantesesEnd);
+ break;
}
}
return params;
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java
index 5e67b4285b..0af18e99f6 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java
@@ -262,7 +262,7 @@ void generateNativeMacro(JNIClass clazz) {
outputln();
}
-boolean generateGetParameter(JNIMethod method, JNIParameter param, boolean critical, int indent) {
+boolean generateGetParameter(JNIParameter param, boolean critical, int indent) {
JNIType paramType = param.getType(), paramType64 = param.getType64();
if (paramType.isPrimitive() || isSystemClass(paramType)) return false;
String iStr = String.valueOf(param.getParameter());
@@ -505,13 +505,13 @@ boolean generateLocalVars(JNIParameter[] params, JNIType returnType, JNIType ret
return needsReturn;
}
-boolean generateGetters(JNIMethod method, JNIParameter[] params) {
+boolean generateGetters(JNIParameter[] params) {
boolean genFailTag = false;
int criticalCount = 0;
for (int i = 0; i < params.length; i++) {
JNIParameter param = params[i];
if (!isCritical(param)) {
- genFailTag |= generateGetParameter(method, param, false, 1);
+ genFailTag |= generateGetParameter(param, false, 1);
} else {
criticalCount++;
}
@@ -520,7 +520,7 @@ boolean generateGetters(JNIMethod method, JNIParameter[] params) {
for (int i = 0; i < params.length; i++) {
JNIParameter param = params[i];
if (isCritical(param)) {
- genFailTag |= generateGetParameter(method, param, true, 2);
+ genFailTag |= generateGetParameter(param, true, 2);
}
}
}
@@ -763,7 +763,7 @@ void generateFunctionCall(JNIMethod method, JNIParameter[] params, JNIType retur
output(cast);
} else {
output("(");
- output(name.substring(0, name.indexOf("_")));
+ output(name.substring(0, name.indexOf('_')));
output(" *)");
}
outputln("arg0;");
@@ -912,7 +912,7 @@ void generateFunctionBody(JNIMethod method, String function, String function64,
} else {
boolean needsReturn = generateLocalVars(params, returnType, returnType64);
generateEnterExitMacro(method, function, function64, true);
- boolean genFailTag = generateGetters(method, params);
+ boolean genFailTag = generateGetters(params);
if (method.getFlag(FLAG_DYNAMIC)) {
generateDynamicFunctionCall(method, params, returnType, returnType64, needsReturn);
} else {
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 c2c48e4b49..37937b0185 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
@@ -41,14 +41,14 @@ public ReflectField(ReflectClass declaringClass, Field field, String source, Com
VariableDeclarationFragment decl = (VariableDeclarationFragment) iterator.next();
if (decl.getName().getIdentifier().equals(field.getName())) {
String s = source.substring(node.getStartPosition(), node.getStartPosition() + node.getLength());
- if (clazz == int.class && s.indexOf("int /*long*/") != -1) type64 = new ReflectType(long.class);
- else if (clazz == float.class && s.indexOf("float /*double*/") != -1) type64 = new ReflectType(double.class);
- else if (clazz == int[].class && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) type64 = new ReflectType(long[].class);
- else if (clazz == float[].class && (s.indexOf("float /*double*/") != -1|| s.indexOf("float[] /*double[]*/") != -1)) type = new ReflectType(double[].class);
- else if (clazz == long.class && s.indexOf("long /*int*/") != -1) type = new ReflectType(int.class);
- else if (clazz == double.class && s.indexOf("double /*float*/") != -1) type = new ReflectType(float.class);
- else if (clazz == long[].class && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) type = new ReflectType(int[].class);
- else if (clazz == double[].class && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) type = new ReflectType(float[].class);
+ if (clazz == int.class && s.contains("int /*long*/")) type64 = new ReflectType(long.class);
+ else if (clazz == float.class && s.contains("float /*double*/")) type64 = new ReflectType(double.class);
+ else if (clazz == int[].class && (s.contains("int /*long*/") || s.contains("int[] /*long[]*/"))) type64 = new ReflectType(long[].class);
+ else if (clazz == float[].class && (s.contains("float /*double*/")|| s.contains("float[] /*double[]*/"))) type = new ReflectType(double[].class);
+ else if (clazz == long.class && s.contains("long /*int*/")) type = new ReflectType(int.class);
+ else if (clazz == double.class && s.contains("double /*float*/")) type = new ReflectType(float.class);
+ else if (clazz == long[].class && (s.contains("long /*int*/")|| s.contains("long[] /*int[]*/"))) type = new ReflectType(int[].class);
+ else if (clazz == double[].class && (s.contains("double /*float*/")|| s.contains("double[] /*float[]*/"))) type = new ReflectType(float[].class);
break;
}
}
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 08f9ccd6c7..107103cff8 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
@@ -73,28 +73,28 @@ public ReflectMethod(ReflectClass declaringClass, Method method, String source,
Class<?> clazz = paramTypes[i];
SingleVariableDeclaration node = (SingleVariableDeclaration)decl.parameters().get(i);
String s = source.substring(node.getStartPosition(), node.getStartPosition() + node.getLength());
- if (clazz == int.class && s.indexOf("int /*long*/") != -1) this.paramTypes64[i] = new ReflectType(long.class);
- else if (clazz == int[].class && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) this.paramTypes64[i] = new ReflectType(long[].class);
- else if (clazz == float.class && s.indexOf("float /*double*/") != -1) this.paramTypes64[i] = new ReflectType(double.class);
- else if (clazz == float[].class && (s.indexOf("float /*double*/") != -1|| s.indexOf("float[] /*double[]*/") != -1)) this.paramTypes64[i] = new ReflectType(double[].class);
- else if (clazz == long.class && s.indexOf("long /*int*/") != -1) this.paramTypes[i] = new ReflectType(int.class);
- else if (clazz == long[].class && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) this.paramTypes[i] = new ReflectType(int[].class);
- else if (clazz == double.class && s.indexOf("double /*float*/") != -1) this.paramTypes[i] = new ReflectType(float.class);
- else if (clazz == double[].class && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) this.paramTypes[i] = new ReflectType(float[].class);
+ if (clazz == int.class && s.contains("int /*long*/")) this.paramTypes64[i] = new ReflectType(long.class);
+ else if (clazz == int[].class && (s.contains("int /*long*/") || s.contains("int[] /*long[]*/"))) this.paramTypes64[i] = new ReflectType(long[].class);
+ else if (clazz == float.class && s.contains("float /*double*/")) this.paramTypes64[i] = new ReflectType(double.class);
+ else if (clazz == float[].class && (s.contains("float /*double*/")|| s.contains("float[] /*double[]*/"))) this.paramTypes64[i] = new ReflectType(double[].class);
+ else if (clazz == long.class && s.contains("long /*int*/")) this.paramTypes[i] = new ReflectType(int.class);
+ else if (clazz == long[].class && (s.contains("long /*int*/")|| s.contains("long[] /*int[]*/"))) this.paramTypes[i] = new ReflectType(int[].class);
+ else if (clazz == double.class && s.contains("double /*float*/")) this.paramTypes[i] = new ReflectType(float.class);
+ else if (clazz == double[].class && (s.contains("double /*float*/")|| s.contains("double[] /*float[]*/"))) this.paramTypes[i] = new ReflectType(float[].class);
}
}
if (canChange64(returnType)) {
Class<?> clazz = returnType;
ASTNode node = decl.getReturnType2();
String s = source.substring(node.getStartPosition(), decl.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) this.returnType = new ReflectType(int.class);
- else if (clazz == long[].class && (s.indexOf("long /*int*/") != -1|| s.indexOf("long[] /*int[]*/") != -1)) this.returnType = new ReflectType(int[].class);
- else if (clazz == double.class && s.indexOf("double /*float*/") != -1) this.returnType = new ReflectType(float.class);
- else if (clazz == double[].class && (s.indexOf("double /*float*/") != -1|| s.indexOf("double[] /*float[]*/") != -1)) this.returnType = new ReflectType(float[].class);
+ if (clazz == int.class && s.contains("int /*long*/")) this.returnType64 = new ReflectType(long.class);
+ else if (clazz == int[].class && (s.contains("int /*long*/") || s.contains("int[] /*long[]*/"))) this.returnType64 = new ReflectType(long[].class);
+ else if (clazz == float.class && s.contains("float /*double*/")) this.returnType64 = new ReflectType(double.class);
+ else if (clazz == float[].class && (s.contains("float /*double*/")|| s.contains("float[] /*double[]*/"))) this.returnType64 = new ReflectType(double[].class);
+ else if (clazz == long.class && s.contains("long /*int*/")) this.returnType = new ReflectType(int.class);
+ else if (clazz == long[].class && (s.contains("long /*int*/")|| s.contains("long[] /*int[]*/"))) this.returnType = new ReflectType(int[].class);
+ else if (clazz == double.class && s.contains("double /*float*/")) this.returnType = new ReflectType(float.class);
+ else if (clazz == double[].class && (s.contains("double /*float*/")|| s.contains("double[] /*float[]*/"))) this.returnType = new ReflectType(float[].class);
}
}
}
diff --git a/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java b/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java
index 0e055fc1e4..e955362c41 100644
--- a/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java
+++ b/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java
@@ -1,508 +1,508 @@
-package org.eclipse.swt.tools.internal;
-
-import java.io.*;
-import java.util.*;
-import java.util.Map.*;
-
-import org.eclipse.jdt.core.dom.*;
-import org.eclipse.jface.text.*;
-
-/**
- * Bashes the javadoc from one source tree into another. Only produces new
- * source files for compilation units that have changed.
- *
- * How to use: 1) make sure you have the latest org.eclipse.swt (master branch)
- * in your workspace, and that you have no outstanding org.eclipse.swt changes
- * 2) create a Bugzilla bug called
- * "Do the annual javadoc/copyright bash for x.x" 3) make a version (tag) of the
- * org.eclipse.swt project before you bash here is a sample tag name:
- * BEFORE_JAVADOC_BASH_FOR_43RC3 use the Bugzilla bug for the tag comment 4)
- * modify the code in main, below, so that 'workspaceDir' and 'outputDir' point
- * to the (git) directory that contains org.eclipse.swt in your workspace,
- * typically C:/git/eclipse.platform.swt/bundles (prior to 3.8/4.2, these
- * pointed to the workspace directory) 5) make sure 'sourceSubdir' (usually
- * win32), 'targetSubdirs' (all others), and 'folders' are correct (note: there
- * are typically a few new targetSubdirs and folders every year... although
- * nothing new for 4.3) 6) run JavadocBasher (for a more verbose output, set
- * fVerbose to true) 7) refresh (F5) the org.eclipse.swt project inside eclipse
- * 8) search for *** in console output to see results of API consistency
- * checking 9) synchronize, carefully reviewing every change. Watch out for: -
- * duplicated comments - // comments that have been removed (if they appear
- * before a javadoc comment) 10) use the Bugzilla bug as the commit comment for
- * javadoc and copyright bash commits 11) make a version of the org.eclipse.swt
- * project after bashing (use tag name AFTER_...)
- *
- * 12) Copyright bash (tag before and after): NOTE: JavadocBasher does not fix
- * copyrights. Use the "Fix Copyrights" tool in org.eclipse.releng.tools for
- * that (always fix copyrights after bash). Use Help->Install New Software... to
- * install "Releng Tools" from the "Eclipse Project Updates" site (for release -
- * 1). Select org.eclipse.swt project and choose "Fix Copyrights" from the
- * context menu. See http://wiki.eclipse.org/Development_Resources/
- * How_to_Use_Eclipse_Copyright_Tool for more info. NOTE: The copyright tool
- * takes about 45 minutes to run (for SWT). NOTE 2: Check console for possible
- * errors/warnings, refresh (F5), synchronize, and browse all changes. Use
- * keyboard (Ctrl+.) for next diff instead of mouse (keyboard is faster because
- * there are fewer focus changes). Only use git History view as needed - if it
- * is open and linked with editor, it gets bogged down and lags behind. NOTE 3:
- * SWT anomalies that confuse the tool: - Some ns*.h files in
- * Mozilla/common/library do not contain the word "copyright" so the tool tries
- * to add one - don't keep it (the text is fine as-is). - Other ns*.h files in
- * Mozilla/common/library have a copyright line that should not be updated
- * (Initial Developer) - don't keep the change suggested by the tool (the text
- * is fine as-is). - The ns*.java and some other *.java files in
- * internal/mozilla have 2 copyright lines and the tool tries to change the 1st
- * - don't keep the 1st change (Netscape 1998-2015), but update the 2nd (IBM)
- * manually.
- *
- * NOTE: JavadocBasher now does a fairly good job of checking API consistency.
- * We used to use org.eclipse.swt.diff for API consistency checking, but it was
- * difficult to maintain.
+package org.eclipse.swt.tools.internal;
+
+import java.io.*;
+import java.util.*;
+import java.util.Map.*;
+
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jface.text.*;
+
+/**
+ * Bashes the javadoc from one source tree into another. Only produces new
+ * source files for compilation units that have changed.
+ *
+ * How to use: 1) make sure you have the latest org.eclipse.swt (master branch)
+ * in your workspace, and that you have no outstanding org.eclipse.swt changes
+ * 2) create a Bugzilla bug called
+ * "Do the annual javadoc/copyright bash for x.x" 3) make a version (tag) of the
+ * org.eclipse.swt project before you bash here is a sample tag name:
+ * BEFORE_JAVADOC_BASH_FOR_43RC3 use the Bugzilla bug for the tag comment 4)
+ * modify the code in main, below, so that 'workspaceDir' and 'outputDir' point
+ * to the (git) directory that contains org.eclipse.swt in your workspace,
+ * typically C:/git/eclipse.platform.swt/bundles (prior to 3.8/4.2, these
+ * pointed to the workspace directory) 5) make sure 'sourceSubdir' (usually
+ * win32), 'targetSubdirs' (all others), and 'folders' are correct (note: there
+ * are typically a few new targetSubdirs and folders every year... although
+ * nothing new for 4.3) 6) run JavadocBasher (for a more verbose output, set
+ * fVerbose to true) 7) refresh (F5) the org.eclipse.swt project inside eclipse
+ * 8) search for *** in console output to see results of API consistency
+ * checking 9) synchronize, carefully reviewing every change. Watch out for: -
+ * duplicated comments - // comments that have been removed (if they appear
+ * before a javadoc comment) 10) use the Bugzilla bug as the commit comment for
+ * javadoc and copyright bash commits 11) make a version of the org.eclipse.swt
+ * project after bashing (use tag name AFTER_...)
+ *
+ * 12) Copyright bash (tag before and after): NOTE: JavadocBasher does not fix
+ * copyrights. Use the "Fix Copyrights" tool in org.eclipse.releng.tools for
+ * that (always fix copyrights after bash). Use Help->Install New Software... to
+ * install "Releng Tools" from the "Eclipse Project Updates" site (for release -
+ * 1). Select org.eclipse.swt project and choose "Fix Copyrights" from the
+ * context menu. See http://wiki.eclipse.org/Development_Resources/
+ * How_to_Use_Eclipse_Copyright_Tool for more info. NOTE: The copyright tool
+ * takes about 45 minutes to run (for SWT). NOTE 2: Check console for possible
+ * errors/warnings, refresh (F5), synchronize, and browse all changes. Use
+ * keyboard (Ctrl+.) for next diff instead of mouse (keyboard is faster because
+ * there are fewer focus changes). Only use git History view as needed - if it
+ * is open and linked with editor, it gets bogged down and lags behind. NOTE 3:
+ * SWT anomalies that confuse the tool: - Some ns*.h files in
+ * Mozilla/common/library do not contain the word "copyright" so the tool tries
+ * to add one - don't keep it (the text is fine as-is). - Other ns*.h files in
+ * Mozilla/common/library have a copyright line that should not be updated
+ * (Initial Developer) - don't keep the change suggested by the tool (the text
+ * is fine as-is). - The ns*.java and some other *.java files in
+ * internal/mozilla have 2 copyright lines and the tool tries to change the 1st
+ * - don't keep the 1st change (Netscape 1998-2015), but update the 2nd (IBM)
+ * manually.
+ *
+ * NOTE: JavadocBasher now does a fairly good job of checking API consistency.
+ * We used to use org.eclipse.swt.diff for API consistency checking, but it was
+ * difficult to maintain.
*/
-public class JavadocBasher {
- static final boolean fVerbose = false; // set to true for verbose output
- List<String> fBashed;
- List<String> fUnchanged;
- List<String> fSkipped;
-
- public JavadocBasher() {
- fBashed = new ArrayList<>();
- fUnchanged = new ArrayList<>();
- fSkipped = new ArrayList<>();
- }
-
- public static class Edit {
- int start, length;
- String text;
-
- public Edit(int start, int length, String text) {
- this.start = start;
- this.length = length;
- this.text = text;
- }
- }
-
- public static void main(String[] args) {
- String workspaceDir = ".."; // use forward slashes, no final slash
- String outputDir = ".."; // can point to another directory for debugging
- String[] folders = new String[] { // commented folders do not need to be
- // bashed
- "Eclipse SWT", "Eclipse SWT Accessibility",
- "Eclipse SWT AWT",
- "Eclipse SWT Browser",
- // "Eclipse SWT Custom Widgets",
- "Eclipse SWT Drag and Drop", "Eclipse SWT Effects",
- // "Eclipse SWT OLE Win32",
- "Eclipse SWT OpenGL",
- // "Eclipse SWT PI",
- "Eclipse SWT Printing", "Eclipse SWT Program",
- "Eclipse SWT Theme", "Eclipse SWT WebKit", };
- String sourceSubdir = "win32";
- String[] targetSubdirs = new String[] { "cairo", // used by gtk
- "cocoa",
- // "common",
- // "common_j2me",
- // "common_j2se",
- "emulated", "emulated/bidi", // used by carbon, cocoa
- "emulated/coolbar", // used by cocoa, gtk
- "emulated/expand", // used by cocoa
- "emulated/taskbar", // used by gtk
- "emulated/tooltip", // used by cocoa (?!)
- "glx", // used by gtk
- "gtk"
- };
-
- System.out.println("==== Start Bashing ====");
- int totalBashed = 0;
- for (int t = 0; t < targetSubdirs.length; t++) {
- for (int f = 0; f < folders.length; f++) {
- String targetSubdir = folders[f] + "/" + targetSubdirs[t];
- File source = new File(workspaceDir + "/org.eclipse.swt/"
- + folders[f] + "/" + sourceSubdir);
- File target = new File(workspaceDir + "/org.eclipse.swt/"
- + targetSubdir);
- File out = new File(outputDir + "/org.eclipse.swt/"
- + targetSubdir);
- JavadocBasher basher = new JavadocBasher();
- System.out.println("\n==== Start Bashing " + targetSubdir);
- basher.bashJavaSourceTree(source, target, out);
- List<String> bashedList = basher.getBashed();
- basher.status("Bashed", bashedList, targetSubdir);
- if (bashedList.size() > 0) {
- totalBashed += bashedList.size();
- if (fVerbose)
- basher.status("Didn't change", basher.getUnchanged(),
- targetSubdir);
- basher.status("Skipped", basher.getSkipped(), targetSubdir);
- }
- System.out.println("==== Done Bashing " + targetSubdir);
- }
- }
- System.out.println("\n==== Done Bashing (Bashed " + totalBashed
- + " files in total) - Be sure to Refresh (F5) project(s) ====");
- }
-
- void status(String label, List<String> list, String targetSubdir) {
- int count = list.size();
- System.out.println(label + " " + count
- + ((count == 1) ? " file" : " files") + " in " + targetSubdir
- + ((count > 0) ? ":" : "."));
- if (count > 0) {
- for(String s : list)
- System.out.println(label + ": " + s);
- System.out.println();
- }
- }
-
- char[] readFile(File file) {
- try (Reader in = new FileReader(file)) {
- CharArrayWriter storage = new CharArrayWriter();
- char[] chars = new char[8192];
- int read = in.read(chars);
- while (read > 0) {
- storage.write(chars, 0, read);
- storage.flush();
- read = in.read(chars);
- }
- return storage.toCharArray();
- } catch (IOException ioe) {
- System.out.println("*** Could not read " + file);
- }
- return null;
- }
-
- void writeFile(char[] contents, File file) {
- try (Writer out = new FileWriter(file)) {
- out.write(contents);
- out.flush();
- } catch (IOException ioe) {
- System.out.println("*** Could not write to " + file);
- if (fVerbose) {
- System.out.println("<dump filename=\"" + file + "\">");
- System.out.println(contents);
- System.out.println("</dump>");
- }
- }
- }
-
- void bashJavaSourceTree(File sourceDir, File targetDir, File outDir) {
- if (fVerbose)
- System.out.println("Reading source javadoc from " + sourceDir);
- if (!sourceDir.exists()) {
- System.out.println("Source: " + sourceDir + " was missing");
- return;
- }
- if (!targetDir.exists()) {
- System.out.println("Target: " + targetDir + " was missing");
- return;
- }
-
- String[] list = sourceDir.list();
- if (list != null) {
- int count = list.length;
- for (int i = 0; i < count; i++) {
- String filename = list[i];
- if (filename.equals("CVS") || filename.equals("internal")
- || filename.equals("library"))
- continue;
- File source = new File(sourceDir, filename);
- File target = new File(targetDir, filename);
- File out = new File(outDir, filename);
- if (source.exists() && target.exists()) {
- if (source.isDirectory()) {
- if (target.isDirectory()) {
- bashJavaSourceTree(source, target, out);
- } else {
- System.out.println("*** " + target
- + " should have been a directory.");
- }
- } else {
- if (filename.toLowerCase().endsWith(".java")) {
- bashFile(source, target, out);
- } else {
- fSkipped.add(source + " (not a java file)");
- }
- }
- } else {
- if (source.exists()) {
- fSkipped.add(target + " (does not exist)");
- } else {
- fSkipped.add(source + " (does not exist)");
- }
- }
- }
- }
- }
-
-
- void bashFile(final File source, final File target, File out) {
- char[] contents = readFile(source);
- if (contents == null) return;
- ASTParser parser = ASTParser.newParser(AST.JLS8);
- final Document sourceDocument = new Document(new String(contents));
- parser.setSource(contents);
- CompilationUnit sourceUnit = (CompilationUnit)parser.createAST(null);
-
- contents = readFile(target);
- if (contents == null) return;
- String targetContents = new String(contents);
- final Document targetDocument = new Document(targetContents);
- parser.setSource(contents);
- CompilationUnit targetUnit = (CompilationUnit)parser.createAST(null);
-
- final HashMap<String, String> comments = new HashMap<>();
- sourceUnit.accept(new ASTVisitor() {
- String prefix = "";
- @Override
- public boolean visit(Block node) {
- return false;
- }
- @Override
- public boolean visit(VariableDeclarationFragment node) {
- FieldDeclaration field = (FieldDeclaration)node.getParent();
- int mods = field.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = field.getJavadoc();
- if (field.fragments().size() > 1 && javadoc != null) {
- System.err.println("Field declaration with multiple variables is not supported. -> " + source + " " + node.getName().getFullyQualifiedName());
- }
- try {
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
- } catch (BadLocationException e) {}
- return true;
- }
- return false;
- }
- @Override
- public boolean visit(MethodDeclaration node) {
- int mods = node.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = node.getJavadoc();
- try {
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- for (Iterator<SingleVariableDeclaration> iterator = node.parameters().iterator(); iterator.hasNext();) {
- SingleVariableDeclaration param = iterator.next();
- key += param.getType().toString();
- }
- comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
- } catch (BadLocationException e) {}
- return true;
- }
- return false;
- }
- @Override
- public boolean visit(TypeDeclaration node) {
- int mods = node.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = node.getJavadoc();
- try {
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
- } catch (BadLocationException e) {}
- prefix = node.getName().getFullyQualifiedName();
- return true;
- }
- return false;
- }
- });
-
-
- final List<Edit> edits = new ArrayList<>();
- targetUnit.accept(new ASTVisitor() {
- String prefix = "";
- @Override
- public boolean visit(Block node) {
- return false;
- }
- @Override
- public boolean visit(VariableDeclarationFragment node) {
- FieldDeclaration field = (FieldDeclaration)node.getParent();
- int mods = field.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = field.getJavadoc();
- if (field.fragments().size() > 1 && javadoc != null) {
- System.err.println("Field declaration with multiple variables is not supported. -> " + target + " " + node.getName().getFullyQualifiedName());
- }
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- String newComment = comments.get(key);
- if (newComment != null) {
- comments.remove(key);
- if (javadoc != null) {
- edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
- } else {
- edits.add(new Edit(field.getStartPosition(), 0, newComment));
- }
- }
- return true;
- }
- return false;
- }
- @Override
- public boolean visit(MethodDeclaration node) {
- int mods = node.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = node.getJavadoc();
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- for (Iterator<SingleVariableDeclaration> iterator = node.parameters().iterator(); iterator.hasNext();) {
- SingleVariableDeclaration param = iterator.next();
- key += param.getType().toString();
- }
- String newComment = comments.get(key);
- if (newComment != null) {
- comments.remove(key);
- if (javadoc != null) {
- edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
- } else {
- edits.add(new Edit(node.getStartPosition(), 0, newComment));
- }
- }
- return true;
- }
- return false;
- }
- @Override
- public boolean visit(TypeDeclaration node) {
- int mods = node.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = node.getJavadoc();
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- String newComment = comments.get(key);
- if (newComment != null) {
- comments.remove(key);
- if (javadoc != null) {
- edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
- } else {
- edits.add(new Edit(node.getStartPosition(), 0, newComment));
- }
- }
- prefix = node.getName().getFullyQualifiedName();
- return true;
- }
- return false;
- }
- });
-
- for (int i = edits.size() - 1; i >=0 ; i--) {
- Edit edit = edits.get(i);
- try {
- targetDocument.replace(edit.start, edit.length, edit.text);
- } catch (BadLocationException e) {
- e.printStackTrace();
- }
- }
- /* Rudimentary API consistency checker.
- * This assumes that:
- * a) the sourceSubdir (typically win32) API is correct
- * b) all sourceSubdir API classes, methods and fields do have a comment
- * c) names that are in the filter list are never API,
- * or they are old API that is defined in the super on some platforms
- */
- if (comments.size() > 0) {
- String [] filter = new String [] {
- "Color.win32_newDeviceint",
- "Cursor.win32_newDeviceint",
- "Device.hPalette",
- "Font.win32_newDevicelong",
- "FontData.data",
- "FontData.win32_newLOGFONTfloat",
- "FontMetrics.handle",
- "FontMetrics.win32_newTEXTMETRIC",
- "GC.win32_newlongGCData",
- "GC.win32_newDrawableGCData",
- "Image.win32_newDeviceintlong",
- "Pattern.handle",
- "Region.win32_newDeviceint",
- "Control.handle",
- "Display.getSystemFont",
- "Display.msg",
- "Menu.handle",
- "Shell.win32_newDisplaylong",
- "Accessible.internal_WM_GETOBJECTlonglong",
- "TransferData.result",
- "TransferData.stgmedium",
- "TransferData.pIDataObject",
- "TransferData.formatetc",
- "Printer.handle",
- "Printer.checkDevice",
- "TableDragSourceEffect.dragFinishedDragSourceEvent",
- "TableDragSourceEffect.dragStartDragSourceEvent",
- "TableDropTargetEffect.dragOverDropTargetEvent",
- "TableDropTargetEffect.dragEnterDropTargetEvent",
- "TableDropTargetEffect.dragLeaveDropTargetEvent",
- "Transfer.validateObject",
- "TransferData.result",
- "TransferData.stgmedium",
- "TransferData.pIDataObject",
- "TransferData.formatetc",
- "TreeDragSourceEffect.dragFinishedDragSourceEvent",
- "TreeDragSourceEffect.dragStartDragSourceEvent",
- "TreeDropTargetEffect.dragLeaveDropTargetEvent",
- "TreeDropTargetEffect.dragEnterDropTargetEvent",
- "TreeDropTargetEffect.dragOverDropTargetEvent",
- "Printer.createDeviceData",
- "Printer.internal_dispose_GClongGCData",
- "Printer.release",
- "Printer.destroy",
- "Image.handle",
- "Display.getClientArea",
- "TreeItem.handle",
- };
- for (Entry<String, String> entry: comments.entrySet()) {
- String name = entry.getKey();
- if (entry.getValue().length() > 0){
- int i = 0;
- for (i = 0; i < filter.length; i++) {
- if (name.equals(filter[i])) break;
- }
- if (i >= filter.length) {
- System.err.println("***No target for " + name);
- }
- }
- }
- }
-
- String newContents = targetDocument.get();
- if (!targetContents.equals(newContents)) {
- if (makeDirectory(out.getParentFile())) {
- writeFile(newContents.toCharArray(), out);
- fBashed.add(target.toString());
- } else {
- System.out.println("*** Could not create " + out.getParent());
- }
- } else {
- fUnchanged.add(target.toString());
- }
- }
-
- int getJavadocLength(Document sourceDocument, Javadoc javadoc) {
- return skipWhitespace(sourceDocument, javadoc.getStartPosition() + javadoc.getLength()) - javadoc.getStartPosition();
- }
-
- int skipWhitespace(Document doc, int offset) {
- try {
- while (Character.isWhitespace(doc.getChar(offset))){
- offset++;
- }
- } catch (BadLocationException e) {
- }
- return offset;
- }
-
- boolean makeDirectory(File directory) {
- if (directory.exists())
- return true;
- return directory.mkdirs();
- }
-
- List<String> getBashed() {
- return fBashed;
- }
-
- List<String> getUnchanged() {
- return fUnchanged;
- }
-
- List<String> getSkipped() {
- return fSkipped;
- }
-}
+public class JavadocBasher {
+ static final boolean fVerbose = false; // set to true for verbose output
+ List<String> fBashed;
+ List<String> fUnchanged;
+ List<String> fSkipped;
+
+ public JavadocBasher() {
+ fBashed = new ArrayList<>();
+ fUnchanged = new ArrayList<>();
+ fSkipped = new ArrayList<>();
+ }
+
+ public static class Edit {
+ int start, length;
+ String text;
+
+ public Edit(int start, int length, String text) {
+ this.start = start;
+ this.length = length;
+ this.text = text;
+ }
+ }
+
+ public static void main(String[] args) {
+ String workspaceDir = ".."; // use forward slashes, no final slash
+ String outputDir = ".."; // can point to another directory for debugging
+ String[] folders = new String[] { // commented folders do not need to be
+ // bashed
+ "Eclipse SWT", "Eclipse SWT Accessibility",
+ "Eclipse SWT AWT",
+ "Eclipse SWT Browser",
+ // "Eclipse SWT Custom Widgets",
+ "Eclipse SWT Drag and Drop", "Eclipse SWT Effects",
+ // "Eclipse SWT OLE Win32",
+ "Eclipse SWT OpenGL",
+ // "Eclipse SWT PI",
+ "Eclipse SWT Printing", "Eclipse SWT Program",
+ "Eclipse SWT Theme", "Eclipse SWT WebKit", };
+ String sourceSubdir = "win32";
+ String[] targetSubdirs = new String[] { "cairo", // used by gtk
+ "cocoa",
+ // "common",
+ // "common_j2me",
+ // "common_j2se",
+ "emulated", "emulated/bidi", // used by carbon, cocoa
+ "emulated/coolbar", // used by cocoa, gtk
+ "emulated/expand", // used by cocoa
+ "emulated/taskbar", // used by gtk
+ "emulated/tooltip", // used by cocoa (?!)
+ "glx", // used by gtk
+ "gtk"
+ };
+
+ System.out.println("==== Start Bashing ====");
+ int totalBashed = 0;
+ for (int t = 0; t < targetSubdirs.length; t++) {
+ for (int f = 0; f < folders.length; f++) {
+ String targetSubdir = folders[f] + "/" + targetSubdirs[t];
+ File source = new File(workspaceDir + "/org.eclipse.swt/"
+ + folders[f] + "/" + sourceSubdir);
+ File target = new File(workspaceDir + "/org.eclipse.swt/"
+ + targetSubdir);
+ File out = new File(outputDir + "/org.eclipse.swt/"
+ + targetSubdir);
+ JavadocBasher basher = new JavadocBasher();
+ System.out.println("\n==== Start Bashing " + targetSubdir);
+ basher.bashJavaSourceTree(source, target, out);
+ List<String> bashedList = basher.getBashed();
+ basher.status("Bashed", bashedList, targetSubdir);
+ if (bashedList.size() > 0) {
+ totalBashed += bashedList.size();
+ if (fVerbose)
+ basher.status("Didn't change", basher.getUnchanged(),
+ targetSubdir);
+ basher.status("Skipped", basher.getSkipped(), targetSubdir);
+ }
+ System.out.println("==== Done Bashing " + targetSubdir);
+ }
+ }
+ System.out.println("\n==== Done Bashing (Bashed " + totalBashed
+ + " files in total) - Be sure to Refresh (F5) project(s) ====");
+ }
+
+ void status(String label, List<String> list, String targetSubdir) {
+ int count = list.size();
+ System.out.println(label + " " + count
+ + ((count == 1) ? " file" : " files") + " in " + targetSubdir
+ + ((count > 0) ? ":" : "."));
+ if (count > 0) {
+ for(String s : list)
+ System.out.println(label + ": " + s);
+ System.out.println();
+ }
+ }
+
+ char[] readFile(File file) {
+ try (Reader in = new FileReader(file)) {
+ CharArrayWriter storage = new CharArrayWriter();
+ char[] chars = new char[8192];
+ int read = in.read(chars);
+ while (read > 0) {
+ storage.write(chars, 0, read);
+ storage.flush();
+ read = in.read(chars);
+ }
+ return storage.toCharArray();
+ } catch (IOException ioe) {
+ System.out.println("*** Could not read " + file);
+ }
+ return null;
+ }
+
+ void writeFile(char[] contents, File file) {
+ try (Writer out = new FileWriter(file)) {
+ out.write(contents);
+ out.flush();
+ } catch (IOException ioe) {
+ System.out.println("*** Could not write to " + file);
+ if (fVerbose) {
+ System.out.println("<dump filename=\"" + file + "\">");
+ System.out.println(contents);
+ System.out.println("</dump>");
+ }
+ }
+ }
+
+ void bashJavaSourceTree(File sourceDir, File targetDir, File outDir) {
+ if (fVerbose)
+ System.out.println("Reading source javadoc from " + sourceDir);
+ if (!sourceDir.exists()) {
+ System.out.println("Source: " + sourceDir + " was missing");
+ return;
+ }
+ if (!targetDir.exists()) {
+ System.out.println("Target: " + targetDir + " was missing");
+ return;
+ }
+
+ String[] list = sourceDir.list();
+ if (list != null) {
+ int count = list.length;
+ for (int i = 0; i < count; i++) {
+ String filename = list[i];
+ if (filename.equals("CVS") || filename.equals("internal")
+ || filename.equals("library"))
+ continue;
+ File source = new File(sourceDir, filename);
+ File target = new File(targetDir, filename);
+ File out = new File(outDir, filename);
+ if (source.exists() && target.exists()) {
+ if (source.isDirectory()) {
+ if (target.isDirectory()) {
+ bashJavaSourceTree(source, target, out);
+ } else {
+ System.out.println("*** " + target
+ + " should have been a directory.");
+ }
+ } else {
+ if (filename.toLowerCase().endsWith(".java")) {
+ bashFile(source, target, out);
+ } else {
+ fSkipped.add(source + " (not a java file)");
+ }
+ }
+ } else {
+ if (source.exists()) {
+ fSkipped.add(target + " (does not exist)");
+ } else {
+ fSkipped.add(source + " (does not exist)");
+ }
+ }
+ }
+ }
+ }
+
+
+ void bashFile(final File source, final File target, File out) {
+ char[] contents = readFile(source);
+ if (contents == null) return;
+ ASTParser parser = ASTParser.newParser(AST.JLS8);
+ final Document sourceDocument = new Document(new String(contents));
+ parser.setSource(contents);
+ CompilationUnit sourceUnit = (CompilationUnit)parser.createAST(null);
+
+ contents = readFile(target);
+ if (contents == null) return;
+ String targetContents = new String(contents);
+ final Document targetDocument = new Document(targetContents);
+ parser.setSource(contents);
+ CompilationUnit targetUnit = (CompilationUnit)parser.createAST(null);
+
+ final HashMap<String, String> comments = new HashMap<>();
+ sourceUnit.accept(new ASTVisitor() {
+ String prefix = "";
+ @Override
+ public boolean visit(Block node) {
+ return false;
+ }
+ @Override
+ public boolean visit(VariableDeclarationFragment node) {
+ FieldDeclaration field = (FieldDeclaration)node.getParent();
+ int mods = field.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = field.getJavadoc();
+ if (field.fragments().size() > 1 && javadoc != null) {
+ System.err.println("Field declaration with multiple variables is not supported. -> " + source + " " + node.getName().getFullyQualifiedName());
+ }
+ try {
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
+ } catch (BadLocationException e) {}
+ return true;
+ }
+ return false;
+ }
+ @Override
+ public boolean visit(MethodDeclaration node) {
+ int mods = node.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = node.getJavadoc();
+ try {
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ for (Iterator<SingleVariableDeclaration> iterator = node.parameters().iterator(); iterator.hasNext();) {
+ SingleVariableDeclaration param = iterator.next();
+ key += param.getType().toString();
+ }
+ comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
+ } catch (BadLocationException e) {}
+ return true;
+ }
+ return false;
+ }
+ @Override
+ public boolean visit(TypeDeclaration node) {
+ int mods = node.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = node.getJavadoc();
+ try {
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
+ } catch (BadLocationException e) {}
+ prefix = node.getName().getFullyQualifiedName();
+ return true;
+ }
+ return false;
+ }
+ });
+
+
+ final List<Edit> edits = new ArrayList<>();
+ targetUnit.accept(new ASTVisitor() {
+ String prefix = "";
+ @Override
+ public boolean visit(Block node) {
+ return false;
+ }
+ @Override
+ public boolean visit(VariableDeclarationFragment node) {
+ FieldDeclaration field = (FieldDeclaration)node.getParent();
+ int mods = field.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = field.getJavadoc();
+ if (field.fragments().size() > 1 && javadoc != null) {
+ System.err.println("Field declaration with multiple variables is not supported. -> " + target + " " + node.getName().getFullyQualifiedName());
+ }
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ String newComment = comments.get(key);
+ if (newComment != null) {
+ comments.remove(key);
+ if (javadoc != null) {
+ edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
+ } else {
+ edits.add(new Edit(field.getStartPosition(), 0, newComment));
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+ @Override
+ public boolean visit(MethodDeclaration node) {
+ int mods = node.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = node.getJavadoc();
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ for (Iterator<SingleVariableDeclaration> iterator = node.parameters().iterator(); iterator.hasNext();) {
+ SingleVariableDeclaration param = iterator.next();
+ key += param.getType().toString();
+ }
+ String newComment = comments.get(key);
+ if (newComment != null) {
+ comments.remove(key);
+ if (javadoc != null) {
+ edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
+ } else {
+ edits.add(new Edit(node.getStartPosition(), 0, newComment));
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+ @Override
+ public boolean visit(TypeDeclaration node) {
+ int mods = node.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = node.getJavadoc();
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ String newComment = comments.get(key);
+ if (newComment != null) {
+ comments.remove(key);
+ if (javadoc != null) {
+ edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
+ } else {
+ edits.add(new Edit(node.getStartPosition(), 0, newComment));
+ }
+ }
+ prefix = node.getName().getFullyQualifiedName();
+ return true;
+ }
+ return false;
+ }
+ });
+
+ for (int i = edits.size() - 1; i >=0 ; i--) {
+ Edit edit = edits.get(i);
+ try {
+ targetDocument.replace(edit.start, edit.length, edit.text);
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+ /* Rudimentary API consistency checker.
+ * This assumes that:
+ * a) the sourceSubdir (typically win32) API is correct
+ * b) all sourceSubdir API classes, methods and fields do have a comment
+ * c) names that are in the filter list are never API,
+ * or they are old API that is defined in the super on some platforms
+ */
+ if (comments.size() > 0) {
+ String [] filter = new String [] {
+ "Color.win32_newDeviceint",
+ "Cursor.win32_newDeviceint",
+ "Device.hPalette",
+ "Font.win32_newDevicelong",
+ "FontData.data",
+ "FontData.win32_newLOGFONTfloat",
+ "FontMetrics.handle",
+ "FontMetrics.win32_newTEXTMETRIC",
+ "GC.win32_newlongGCData",
+ "GC.win32_newDrawableGCData",
+ "Image.win32_newDeviceintlong",
+ "Pattern.handle",
+ "Region.win32_newDeviceint",
+ "Control.handle",
+ "Display.getSystemFont",
+ "Display.msg",
+ "Menu.handle",
+ "Shell.win32_newDisplaylong",
+ "Accessible.internal_WM_GETOBJECTlonglong",
+ "TransferData.result",
+ "TransferData.stgmedium",
+ "TransferData.pIDataObject",
+ "TransferData.formatetc",
+ "Printer.handle",
+ "Printer.checkDevice",
+ "TableDragSourceEffect.dragFinishedDragSourceEvent",
+ "TableDragSourceEffect.dragStartDragSourceEvent",
+ "TableDropTargetEffect.dragOverDropTargetEvent",
+ "TableDropTargetEffect.dragEnterDropTargetEvent",
+ "TableDropTargetEffect.dragLeaveDropTargetEvent",
+ "Transfer.validateObject",
+ "TransferData.result",
+ "TransferData.stgmedium",
+ "TransferData.pIDataObject",
+ "TransferData.formatetc",
+ "TreeDragSourceEffect.dragFinishedDragSourceEvent",
+ "TreeDragSourceEffect.dragStartDragSourceEvent",
+ "TreeDropTargetEffect.dragLeaveDropTargetEvent",
+ "TreeDropTargetEffect.dragEnterDropTargetEvent",
+ "TreeDropTargetEffect.dragOverDropTargetEvent",
+ "Printer.createDeviceData",
+ "Printer.internal_dispose_GClongGCData",
+ "Printer.release",
+ "Printer.destroy",
+ "Image.handle",
+ "Display.getClientArea",
+ "TreeItem.handle",
+ };
+ for (Entry<String, String> entry: comments.entrySet()) {
+ String name = entry.getKey();
+ if (entry.getValue().length() > 0){
+ int i = 0;
+ for (i = 0; i < filter.length; i++) {
+ if (name.equals(filter[i])) break;
+ }
+ if (i >= filter.length) {
+ System.err.println("***No target for " + name);
+ }
+ }
+ }
+ }
+
+ String newContents = targetDocument.get();
+ if (!targetContents.equals(newContents)) {
+ if (makeDirectory(out.getParentFile())) {
+ writeFile(newContents.toCharArray(), out);
+ fBashed.add(target.toString());
+ } else {
+ System.out.println("*** Could not create " + out.getParent());
+ }
+ } else {
+ fUnchanged.add(target.toString());
+ }
+ }
+
+ int getJavadocLength(Document sourceDocument, Javadoc javadoc) {
+ return skipWhitespace(sourceDocument, javadoc.getStartPosition() + javadoc.getLength()) - javadoc.getStartPosition();
+ }
+
+ int skipWhitespace(Document doc, int offset) {
+ try {
+ while (Character.isWhitespace(doc.getChar(offset))){
+ offset++;
+ }
+ } catch (BadLocationException e) {
+ }
+ return offset;
+ }
+
+ boolean makeDirectory(File directory) {
+ if (directory.exists())
+ return true;
+ return directory.mkdirs();
+ }
+
+ List<String> getBashed() {
+ return fBashed;
+ }
+
+ List<String> getUnchanged() {
+ return fUnchanged;
+ }
+
+ List<String> getSkipped() {
+ return fSkipped;
+ }
+}
diff --git a/bundles/org.eclipse.swt.tools/META-INF/MANIFEST.MF b/bundles/org.eclipse.swt.tools/META-INF/MANIFEST.MF
index da08e73873..9c54147f0d 100644
--- a/bundles/org.eclipse.swt.tools/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.swt.tools/META-INF/MANIFEST.MF
@@ -2,11 +2,9 @@ Manifest-Version: 1.0
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.swt.tools; singleton:=true
-Bundle-Version: 3.107.400.qualifier
-Bundle-Activator: org.eclipse.swt.tools.Activator
+Bundle-Version: 3.108.100.qualifier
Bundle-ManifestVersion: 2
-Export-Package: org.eclipse.swt.tools,
- org.eclipse.swt.tools.internal; x-internal:=true
+Export-Package: org.eclipse.swt.tools.internal; x-internal:=true
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java b/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java
index 90cf587667..22cb881b86 100644
--- a/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java
+++ b/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java
@@ -16,36 +16,26 @@ package org.eclipse.swt.tools.internal;
import java.io.*;
import java.util.*;
import java.util.Map.*;
-import java.util.stream.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
-import org.w3c.dom.Node;
import org.xml.sax.*;
+
@SuppressWarnings("unchecked")
public class MacGenerator {
String[] xmls;
Document[] documents;
String outputDir, outputLibDir, extrasDir, mainClassName, selectorEnumName;
String delimiter = System.getProperty("line.separator");
- boolean generate64Code;
PrintWriter out;
+ HashSet<String> knownConstTypes = new HashSet<>();
public static boolean BUILD_C_SOURCE = true;
public static boolean GENERATE_ALLOC = true;
- public static boolean GENERATE_STRUCTS = false;
+ public static boolean GENERATE_STRUCTS = true;
public static boolean USE_SYSTEM_BRIDGE_FILES = false;
- static final char[] INT_LONG = "int /*long*/".toCharArray();
- static final char[] INT_LONG_ARRAY = "int[] /*long[]*/".toCharArray();
- static final char[] FLOAT_DOUBLE = "float /*double*/".toCharArray();
- static final char[] FLOAT_DOUBLE_ARRAY = "float[] /*double[]*/".toCharArray();
- static final char[] LONG_INT = "long /*int*/".toCharArray();
- static final char[] LONG_INT_ARRAY = "long[] /*int[]*/".toCharArray();
- static final char[] DOUBLE_FLOAT = "double /*float*/".toCharArray();
- static final char[] DOUBLE_FLOAT_ARRAY = "double[] /*float[]*/".toCharArray();
-
public MacGenerator() {
}
@@ -66,55 +56,9 @@ static void list(File path, ArrayList<String> list) {
}
}
-static int indexOf(final char[] toBeFound, final char[] array, final int start) {
- final int arrayLength = array.length;
- final int toBeFoundLength = toBeFound.length;
- if (toBeFoundLength > arrayLength || start < 0) return -1;
- if (toBeFoundLength == 0) return 0;
- if (toBeFoundLength == arrayLength) {
- for (int i = start; i < arrayLength; i++) {
- if (array[i] != toBeFound[i]) return -1;
- }
- return 0;
- }
- arrayLoop: for (int i = start, max = arrayLength - toBeFoundLength + 1; i < max; i++) {
- if (array[i] == toBeFound[0]) {
- for (int j = 1; j < toBeFoundLength; j++) {
- if (array[i + j] != toBeFound[j]) continue arrayLoop;
- }
- return i;
- }
- }
- return -1;
-}
-
-static boolean replace(char[] source, char[] src, char[] dest) {
- boolean changed = false;
- int start = 0;
- while (start < source.length) {
- int index = indexOf(src, source, start);
- if (index == -1) break;
- changed |= true;
- System.arraycopy(dest, 0, source, index, dest.length);
- start = index + 1;
- }
- return changed;
-}
-
void output(String fileName, char[] source) {
try {
if (source.length > 0) {
- if (generate64Code) {
- replace(source, INT_LONG, LONG_INT);
- replace(source, INT_LONG_ARRAY, LONG_INT_ARRAY);
- replace(source, FLOAT_DOUBLE, DOUBLE_FLOAT);
- replace(source, FLOAT_DOUBLE_ARRAY, DOUBLE_FLOAT_ARRAY);
- } else {
- replace(source, LONG_INT, INT_LONG);
- replace(source, LONG_INT_ARRAY, INT_LONG_ARRAY);
- replace(source, DOUBLE_FLOAT, FLOAT_DOUBLE);
- replace(source, DOUBLE_FLOAT_ARRAY, FLOAT_DOUBLE_ARRAY);
- }
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(out);
stream.print(source);
@@ -256,8 +200,8 @@ String getParamName(Node param, int i) {
if (swtName != null) {
paramName = swtName.getNodeValue();
} else {
- Node node = paramAttributes.getNamedItem("name");
- if (node != null) paramName = node.getNodeValue();
+ Node node = paramAttributes.getNamedItem("name");
+ if (node != null) paramName = node.getNodeValue();
}
if (paramName.length() == 0) {
Node node = paramAttributes.getNamedItem("index");
@@ -277,39 +221,65 @@ void generateFields(ArrayList<Node> fields) {
for (Node field : fields) {
NamedNodeMap fieldAttributes = field.getAttributes();
String fieldName = fieldAttributes.getNamedItem("name").getNodeValue();
- String type = getJavaType(field), type64 = getJavaType64(field);
- out("\t");
- out("public ");
- out(type);
- if (!type.equals(type64)) {
- out(" /*");
- out(type64);
- out("*/");
+ String fieldType = getJavaType(field);
+ if (!isStruct(field)) {
+ out("\t/** @field cast=(");
+ out(getCType(field));
+ out(") */");
+ outln();
}
+ out("\tpublic ");
+ out(fieldType);
out(" ");
out(fieldName);
if (isStruct(field)) {
out(" = new ");
- String clazz = getDeclaredType(fieldAttributes, field);
- out (clazz);
- out ("()");
+ out(fieldType);
+ out("()");
}
out(";");
outln();
}
}
+void generateToString(String className, ArrayList<Node> fields) {
+ outln();
+ out("\t@Override");
+ outln();
+ out("\tpublic String toString() {");
+ outln();
+ out("\t\treturn \"");
+ out(className);
+ out("{\"");
+ boolean first = true;
+ for (Node field : fields) {
+ if (!first) {
+ out(" + \",\"");
+ }
+ NamedNodeMap fieldAttributes = field.getAttributes();
+ String fieldName = fieldAttributes.getNamedItem("name").getNodeValue();
+ out(" + ");
+ out(fieldName);
+ first = false;
+ }
+ out(" + \"}\";");
+ outln();
+ out("\t}");
+ outln();
+}
+
private String getDeclaredType(NamedNodeMap map, Node location) {
- Node declaredType = map.getNamedItem("declared_type");
- String value = declaredType != null ? declaredType.getNodeValue() : null;
- if(value == null) {
+ Node declaredType = map.getNamedItem("declared_type64");
+ if (declaredType == null) declaredType = map.getNamedItem("declared_type");
+ if (declaredType == null) {
System.err.printf("Unable to detect declared_type. Check bridge file! It might have been removed, inheritance changed, etc. It could also be an issue with gen_bridge_metadata. Location: %s %n", toDebugLocation(location));
return "nodeclaredtype";
}
+ String value = declaredType.getNodeValue();
// strip any _Nullable and _Nonnull annotations
value = value.replace("_Nullable", "").replace("_Nonnull", "").replace("_Null_unspecified", "");
-
+
// strip greater-than (>) sign
value = value.replace(">", "");
@@ -324,7 +294,7 @@ private String getDeclaredType(NamedNodeMap map, Node location) {
value = value.replace("struct ", "");
// also remove any white spaces
- value = value.chars().filter((c)->!Character.isWhitespace(c)).mapToObj(c -> String.valueOf((char)c)).collect(Collectors.joining());
+ value = value.replaceAll("\\s", "");
return value;
}
@@ -334,36 +304,22 @@ void generateMethods(String className, ArrayList<Node> methods) {
NamedNodeMap mthAttributes = method.getAttributes();
String sel = mthAttributes.getNamedItem("selector").getNodeValue();
if ("NSObject".equals(className)) {
- if ("alloc".equals(sel) || "dealloc".equals(sel)) continue;
+ if ("alloc".equals(sel) || "dealloc".equals(sel)) continue;
}
out("public ");
boolean isStatic = isStatic(method);
if (isStatic) out("static ");
- Node returnNode = getReturnNode(method.getChildNodes());
- if (getType(returnNode).equals("void")) returnNode = null;
- String returnType = "", returnType64 = "";
- if (returnNode != null) {
- String type = returnType = getJavaType(returnNode), type64 = returnType64 = getJavaType64(returnNode);
-
- // convert "instancetype" to class name
- if(type.equals("instancetype")) {
- type = returnType = className;
- type64 = returnType64 = className;
- }
-
- out(type);
- if (!type.equals(type64)) {
- out(" /*");
- out(type64);
- out("*/");
- }
- out(" ");
- } else {
- out("void ");
+ Node returnNode = getReturnNode(method);
+ String returnType = getJavaType(returnNode);
+ // convert "instancetype" to class name
+ if (returnType.equals("instancetype")) {
+ returnType = className;
}
+ out(returnType);
+ out(" ");
String methodName = sel;
if (isUnique(method, methods)) {
- int index = methodName.indexOf(":");
+ int index = methodName.indexOf(':');
if (index != -1) methodName = methodName.substring(0, index);
} else {
//TODO improve this selector
@@ -379,21 +335,15 @@ void generateMethods(String className, ArrayList<Node> methods) {
Node param = params.item(k);
if ("arg".equals(param.getNodeName())) {
if (!first) out(", ");
- String type = getJavaType(param), type64 = getJavaType64(param);
- out( type);
- if (!type.equals(type64)) {
- out(" /*");
- out(type64);
- out("*/");
- }
first = false;
+ out(getJavaType(param));
out(" ");
out(getParamName(param, argIndex++));
}
}
out(") {");
outln();
- if (returnNode != null && isStruct(returnNode)) {
+ if (isStruct(returnNode)) {
out("\t");
out(returnType);
out(" result = new ");
@@ -401,33 +351,22 @@ void generateMethods(String className, ArrayList<Node> methods) {
out("();");
outln();
out("\tOS.objc_msgSend_stret(result, ");
- } else if (returnNode != null && isBoolean(returnNode)) {
- out("\treturn ");
- out("OS.objc_msgSend_bool(");
- } else if (returnNode != null && isFloatingPoint(returnNode)) {
- out("\treturn ");
- String type = getType(returnNode), type64 = getType64(returnNode);
- if (type.equals(type64) && type.equals("float")) {
- out("OS.objc_msgSend_floatret(");
- } else {
- if (returnType.equals("float")) out("(float /*double*/)");
- out("OS.objc_msgSend_fpret(");
- }
- } else if (returnNode != null && isObject(returnNode)) {
- out("\tint /*long*/ result = OS.objc_msgSend(");
+ } else if (isObject(returnNode)) {
+ out("\tlong result = OS.objc_msgSend(");
+ } else if (returnType.equals("void")) {
+ out("\tOS.objc_msgSend(");
+ } else if (returnType.equals("boolean")) {
+ out("\treturn OS.objc_msgSend_bool(");
+ } else if (returnType.equals("float")) {
+ out("\treturn OS.objc_msgSend_floatret(");
+ } else if (returnType.equals("double")) {
+ out("\treturn OS.objc_msgSend_fpret(");
} else {
- if (returnNode != null) {
- out("\treturn ");
- if ((returnType.equals("int") && returnType64.equals("int")) || !returnType.equals("int")) {
- out("(");
- out(returnType);
- out(")");
- }
- if (returnType.equals("int") && returnType64.equals("int")) {
- out("/*64*/");
- }
- } else {
- out("\t");
+ out("\treturn ");
+ if (!returnType.equals("long")) {
+ out("(");
+ out(returnType);
+ out(")");
}
out("OS.objc_msgSend(");
}
@@ -460,7 +399,7 @@ void generateMethods(String className, ArrayList<Node> methods) {
out(")");
out(";");
outln();
- if (returnNode != null && isObject(returnNode)) {
+ if (isObject(returnNode)) {
if (!isStatic && returnType.equals(className)) {
out("\treturn result == this.id ? this : (result != 0 ? new ");
out(returnType);
@@ -477,7 +416,7 @@ void generateMethods(String className, ArrayList<Node> methods) {
out("(result) : null;");
}
outln();
- } else if (returnNode != null && isStruct(returnNode)) {
+ } else if (isStruct(returnNode)) {
out("\treturn result;");
outln();
}
@@ -490,35 +429,8 @@ void generateMethods(String className, ArrayList<Node> methods) {
void generateExtraFields(String className) {
/* sizeof field */
out("\t");
- out("public static int sizeof = OS." + className + "_sizeof();");
+ out("public static final int sizeof = OS." + className + "_sizeof();");
outln();
- if ("CGSize".equals(className)) {
- outln();
- out("\tpublic String toString () {");
- outln();
- out("\t\treturn \"CGSize {\" + width + \" \" + height + \"}\";");
- outln();
- out("\t}");
- outln();
- }
- if ("CGRect".equals(className)) {
- outln();
- out("\tpublic String toString () {");
- outln();
- out("\t\treturn \"CGRect {\" + origin.x + \" \" + origin.y + \" \" + size.width + \" \" + size.height + \"}\";");
- outln();
- out("\t}");
- outln();
- }
- if ("CGPoint".equals(className)) {
- outln();
- out("\tpublic String toString () {");
- outln();
- out("\t\treturn \"CGPoint {\" + x + \" \" + y + \"}\";");
- outln();
- out("\t}");
- outln();
- }
}
void generateExtraMethods(String className) {
@@ -535,7 +447,7 @@ void generateExtraMethods(String className) {
/* pointer constructor */
out("public ");
out(className);
- out("(int /*long*/ id) {");
+ out("(long id) {");
outln();
out("\tsuper(id);");
outln();
@@ -571,7 +483,7 @@ void generateExtraMethods(String className) {
/* Get java string */
out("public String getString() {");
outln();
- out("\tchar[] buffer = new char[(int)/*64*/length()];");
+ out("\tchar[] buffer = new char[(int)length()];");
outln();
out("\tgetCharacters(buffer);");
outln();
@@ -705,7 +617,7 @@ String getSuperclassName (Node node) {
Node superclass = attributes.getNamedItem("swt_superclass");
if (superclass != null) {
return superclass.getNodeValue();
- }
+ }
Node name = attributes.getNamedItem("name");
if (name.getNodeValue().equals("NSObject")) {
return "id";
@@ -765,7 +677,8 @@ void generateStructs() {
String className = structEntry.getKey();
Object[] clazz = structEntry.getValue();
- ArrayList<Node> methods = (ArrayList<Node>)clazz[1];
+ Node field = (Node) clazz[0];
+ ArrayList<Node> fields = (ArrayList<Node>)clazz[1];
out("package ");
String packageName = getPackageName();
out(packageName);
@@ -776,8 +689,11 @@ void generateStructs() {
out(className);
out(" {");
outln();
- generateFields(methods);
+ generateFields(fields);
generateExtraFields(className);
+ if (getGenToString(field)) {
+ generateToString(className, fields);
+ }
out("}");
outln();
@@ -816,7 +732,6 @@ void generateMainClass() {
int end = str.indexOf(section, start);
header = str.substring(0, start);
footer = end == -1 ? "\n}" : str.substring(end);
- generate64Code = str.indexOf("long /*int*/") != -1;
input.close();
} catch (IOException e) {
}
@@ -899,9 +814,9 @@ void generateSelectorEnum() {
outln();
generateSelectorsEnumLiteral();
-
+
out(";"); outln();
-
+
String mainClassShortName = mainClassName.substring(mainClassName.lastIndexOf('.')+1);
out(" final String name;"); outln();
out(" final long value;"); outln();
@@ -915,7 +830,7 @@ void generateSelectorEnum() {
out(" public static Selector valueOf(long value) {"); outln();
out(" return "+mainClassShortName+".getSelector(value);"); outln();
out(" }"); outln();
-
+
out(footer);
this.out.flush();
output(fileName, out.toCharArray());
@@ -1059,6 +974,8 @@ public String[] getExtraAttributeNames(Node node) {
}
} else if (name.equals("class")) {
return new String[]{"swt_superclass"};
+ } else if (name.equals("struct")) {
+ return new String[]{"swt_gen_memmove", "swt_gen_tostring"};
} else if (name.equals("retval")) {
return new String[]{"swt_java_type", "swt_java_type64", "swt_alloc"};
} else if (name.equals("arg")) {
@@ -1163,7 +1080,7 @@ void out(String str) {
void outln() {
PrintWriter out = this.out;
- out.println();
+ out.print(delimiter);
}
void generateConstants() {
@@ -1180,18 +1097,13 @@ void generateConstants() {
out("/** @method flags=const */");
outln();
out("public static final native ");
- String type = getType(node), type64 = getType64(node);
- out(type);
- if (!type.equals(type64)) {
- out(" /*");
- out(type64);
- out("*/");
- }
+ out(getType(node));
out(" ");
out(constName);
out("();");
outln();
- if (getDeclaredType(attributes, node).equals("NSString*")) {
+ // Assume that all object-typed constants are strings
+ if (isObject(node)) {
out("public static final NSString ");
out(constName);
out(" = new NSString(");
@@ -1200,9 +1112,13 @@ void generateConstants() {
outln();
}
}
+ if (isObject(node)) {
+ knownConstTypes.add(getCType(node));
+ }
}
}
}
+ knownConstTypes.remove("id");
}
void generateEnums() {
@@ -1215,7 +1131,8 @@ void generateEnums() {
if ("enum".equals(node.getNodeName())) {
if (getGen(node)) {
NamedNodeMap attributes = node.getAttributes();
- Node valueNode = attributes.getNamedItem("value");
+ Node valueNode = attributes.getNamedItem("value64");
+ if (valueNode == null) valueNode = attributes.getNamedItem("value");
if (valueNode != null) {
String value = valueNode.getNodeValue();
out("public static final ");
@@ -1226,6 +1143,9 @@ void generateEnums() {
if (value.equals("4294967295")) {
out("int ");
value = "-1";
+ } else if (value.equals("18446744073709551615")) {
+ out("long ");
+ value = "-1L";
} else {
try {
Integer.parseInt(value);
@@ -1272,6 +1192,20 @@ boolean getGenCallback(Node node) {
return gen != null && !gen.getNodeValue().equals("false");
}
+boolean getGenMemmove(Node node) {
+ NamedNodeMap attributes = node.getAttributes();
+ if (attributes == null) return false;
+ Node gen = attributes.getNamedItem("swt_gen_memmove");
+ return gen != null && !gen.getNodeValue().equals("false");
+}
+
+boolean getGenToString(Node node) {
+ NamedNodeMap attributes = node.getAttributes();
+ if (attributes == null) return false;
+ Node gen = attributes.getNamedItem("swt_gen_tostring");
+ return gen != null && !gen.getNodeValue().equals("false");
+}
+
boolean isStatic(Node node) {
NamedNodeMap attributes = node.getAttributes();
Node isStatic = attributes.getNamedItem("class_method");
@@ -1279,35 +1213,15 @@ boolean isStatic(Node node) {
}
boolean isStruct(Node node) {
- NamedNodeMap attributes = node.getAttributes();
- Node type = attributes.getNamedItem("type");
- if (type == null) return false;
- String code = type.getNodeValue();
- return code.startsWith("{");
+ return getTypeCode(node) == '{';
}
-boolean isFloatingPoint(Node node) {
- NamedNodeMap attributes = node.getAttributes();
- Node type = attributes.getNamedItem("type");
- if (type == null) return false;
- String code = type.getNodeValue();
- return code.equals("f") || code.equals("d");
+boolean isPointer(Node node) {
+ return getTypeCode(node) == '^';
}
boolean isObject(Node node) {
- NamedNodeMap attributes = node.getAttributes();
- Node type = attributes.getNamedItem("type");
- if (type == null) return false;
- String code = type.getNodeValue();
- return code.equals("@");
-}
-
-boolean isBoolean(Node node) {
- NamedNodeMap attributes = node.getAttributes();
- Node type = attributes.getNamedItem("type");
- if (type == null) return false;
- String code = type.getNodeValue();
- return code.equals("B");
+ return getTypeCode(node) == '@';
}
void buildLookup(Node node, HashMap<String, Node> table) {
@@ -1332,7 +1246,7 @@ boolean isUnique(Node method, ArrayList<Node> methods) {
signature += getJavaType(param);
}
}
- int index = methodName.indexOf(":");
+ int index = methodName.indexOf(':');
if (index != -1) methodName = methodName.substring(0, index);
for (Node other : methods) {
NamedNodeMap attributes = other.getAttributes();
@@ -1340,7 +1254,7 @@ boolean isUnique(Node method, ArrayList<Node> methods) {
if (attributes != null) otherSel = attributes.getNamedItem("selector");
if (other != method && otherSel != null) {
String otherName = otherSel.getNodeValue();
- index = otherName.indexOf(":");
+ index = otherName.indexOf(':');
if (index != -1) otherName = otherName.substring(0, index);
if (methodName.equals(otherName)) {
NodeList otherParams = other.getChildNodes();
@@ -1399,7 +1313,7 @@ void generateSelectorsConst() {
out ("}"); outln();
for (String sel : set) {
String selConst = getSelConst(sel);
- out("public static final int /*long*/ ");
+ out("public static final long ");
out(selConst);
out(" = ");
out("Selector."+selConst+".value;");
@@ -1443,17 +1357,26 @@ void generateSelectorsEnumLiteral() {
void generateStructNatives() {
TreeSet<String> set = new TreeSet<>();
+ TreeSet<String> memmoveSet = new TreeSet<>();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null) continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
- if ("struct".equals(node.getNodeName()) && getGen(node)) {
- set.add(getIDAttribute(node).getNodeValue());
+ if ("struct".equals(node.getNodeName())) {
+ String className = getIDAttribute(node).getNodeValue();
+ if (getGen(node)) {
+ set.add(className);
+ }
+ if (getGenMemmove(node)) {
+ memmoveSet.add(className);
+ }
}
}
}
+ set.addAll(memmoveSet);
+
out("/** Sizeof natives */");
outln();
for (String struct : set) {
@@ -1466,7 +1389,7 @@ void generateStructNatives() {
out("/** Memmove natives */");
outln();
outln();
- for (String struct : set) {
+ for (String struct : memmoveSet) {
out("/**");
outln();
out(" * @param dest cast=(void *),flags=no_in critical");
@@ -1477,9 +1400,9 @@ void generateStructNatives() {
out(" */");
outln();
out("public static final native void memmove(");
- out("int /*long*/ dest, ");
+ out("long dest, ");
out(struct);
- out(" src, int /*long*/ size);");
+ out(" src, long size);");
outln();
out("/**");
outln();
@@ -1492,69 +1415,44 @@ void generateStructNatives() {
outln();
out("public static final native void memmove(");
out(struct);
- out(" dest, int /*long*/ src, int /*long*/ size);");
+ out(" dest, long src, long size);");
outln();
}
}
-String buildSend(Node method, boolean tags, boolean only64, boolean superCall) {
- Node returnNode = getReturnNode(method.getChildNodes());
+String buildSend(Node method, boolean superCall) {
+ Node returnNode = getReturnNode(method);
+ String returnType = getJavaType(returnNode);
StringBuilder buffer = new StringBuilder();
buffer.append("public static final native ");
- if (returnNode != null && isStruct(returnNode)) {
+ if (isStruct(returnNode)) {
buffer.append("void ");
buffer.append(superCall ? "objc_msgSendSuper_stret" : "objc_msgSend_stret");
buffer.append("(");
- buffer.append(getJavaType(returnNode));
+ buffer.append(returnType);
buffer.append(" result, ");
- } else if (returnNode != null && isFloatingPoint(returnNode)) {
- String type = getType(returnNode), type64 = getType64(returnNode);
- if (type.equals(type64) && type.equals("float")) {
- buffer.append("float ");
- buffer.append(superCall ? "objc_msgSendSuper_floatret" : "objc_msgSend_floatret");
- } else {
- buffer.append("double ");
- buffer.append(superCall ? "objc_msgSendSuper_fpret" : "objc_msgSend_fpret");
- }
+ } else if (returnType.equals("float")) {
+ buffer.append("float ");
+ buffer.append(superCall ? "objc_msgSendSuper_floatret" : "objc_msgSend_floatret");
+ buffer.append("(");
+ } else if (returnType.equals("double")) {
+ buffer.append("double ");
+ buffer.append(superCall ? "objc_msgSendSuper_fpret" : "objc_msgSend_fpret");
buffer.append("(");
- } else if (returnNode != null && isBoolean(returnNode)) {
+ } else if (returnType.equals("boolean")) {
buffer.append("boolean ");
buffer.append(superCall ? "objc_msgSendSuper_bool" : "objc_msgSend_bool");
buffer.append("(");
} else {
- if (only64) {
- buffer.append("long");
- } else {
- if (tags) {
- buffer.append("int /*long*/");
- } else {
- buffer.append("int");
- }
- }
+ buffer.append("long");
buffer.append(" ");
buffer.append(superCall ? "objc_msgSendSuper" : "objc_msgSend");
buffer.append("(");
}
if (superCall) {
- if (only64) {
- buffer.append("objc_super superId, long sel");
- } else {
- if (tags) {
- buffer.append("objc_super superId, int /*long*/ sel");
- } else {
- buffer.append("objc_super superId, int sel");
- }
- }
+ buffer.append("objc_super superId, long sel");
} else {
- if (only64) {
- buffer.append("long id, long sel");
- } else {
- if (tags) {
- buffer.append("int /*long*/ id, int /*long*/ sel");
- } else {
- buffer.append("int id, int sel");
- }
- }
+ buffer.append("long id, long sel");
}
NodeList params = method.getChildNodes();
boolean first = false;
@@ -1563,20 +1461,10 @@ String buildSend(Node method, boolean tags, boolean only64, boolean superCall) {
Node param = params.item(k);
if ("arg".equals(param.getNodeName())) {
if (!first) buffer.append(", ");
- if (isStruct(param)) {
- buffer.append(getJavaType(param));
- } else {
- String type = getType(param), type64 = getType64(param);
- buffer.append(only64 ? type64 : type);
- if (!only64 && tags && !type.equals(type64)) {
- buffer.append(" /*");
- buffer.append(type64);
- buffer.append("*/");
- }
- }
first = false;
+ buffer.append(getType(param));
buffer.append(" arg");
- buffer.append(String.valueOf(count++));
+ buffer.append(count++);
}
}
buffer.append(");");
@@ -1643,8 +1531,8 @@ void generateCustomCallbacks() {
}
String nativeMth = key.replaceAll(":", "_");
out("/** @method callback_types=");
- Node returnNode = getReturnNode(method.getChildNodes());
- out(returnNode == null ? "void" : getCType(returnNode));
+ Node returnNode = getReturnNode(method);
+ out(getCType(returnNode));
out(";id;SEL;");
NodeList params = method.getChildNodes();
for (int k = 0; k < params.getLength(); k++) {
@@ -1655,7 +1543,7 @@ void generateCustomCallbacks() {
}
}
out(",callback_flags=");
- out(returnNode != null && isStruct(returnNode) ? "struct" : "none");
+ out(isStruct(returnNode) ? "struct" : "none");
out(";none;none;");
for (int k = 0; k < params.getLength(); k++) {
Node param = params.item(k);
@@ -1666,16 +1554,15 @@ void generateCustomCallbacks() {
}
out(" */");
outln();
- out("public static final native int /*long*/ CALLBACK_");
+ out("public static final native long CALLBACK_");
out(nativeMth);
- out("(int /*long*/ func);");
+ out("(long func);");
outln();
}
}
void generateSends(boolean superCall) {
TreeMap<String, Node> set = new TreeMap<>();
- TreeMap<String, Node> set64 = new TreeMap<>();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null) continue;
@@ -1687,44 +1574,18 @@ void generateSends(boolean superCall) {
for (int j = 0; j < methods.getLength(); j++) {
Node method = methods.item(j);
if ("method".equals(method.getNodeName()) && getGen(method) && (!superCall || getGenSuper(method))) {
- String code = buildSend(method, false, false, superCall);
- String code64 = buildSend(method, false, true, superCall);
+ String code = buildSend(method, superCall);
if (set.get(code) == null) {
set.put(code, method);
}
- if (set64.get(code64) == null) {
- set64.put(code64, method);
- }
}
}
}
}
}
outln();
- TreeMap<String, Node> tagsSet = new TreeMap<>();
- for (Iterator<String> iterator = set.keySet().iterator(); iterator.hasNext();) {
- String key = iterator.next();
- Node method = set.get(key);
- String tagCode = buildSend(method, false, true, superCall);
- if (set64.get(tagCode) != null) {
- tagsSet.put(key, method);
- iterator.remove();
- set64.remove(tagCode);
- }
- }
- TreeMap<String, Node> all = new TreeMap<>();
- for (String key : tagsSet.keySet()) {
- Node method = tagsSet.get(key);
- all.put(buildSend(method, true, false, superCall), method);
- }
for (String key : set.keySet()) {
- all.put(key, set.get(key));
- }
- for (String key : set64.keySet()) {
- all.put(key, set64.get(key));
- }
- for (String key : all.keySet()) {
- Node method = all.get(key);
+ Node method = set.get(key);
NodeList params = method.getChildNodes();
ArrayList<String> tags = new ArrayList<>();
int count = 0;
@@ -1778,7 +1639,7 @@ void generateClassesConst() {
}
for (String cls : set) {
String clsConst = "class_" + cls;
- out("public static final int /*long*/ ");
+ out("public static final long ");
out(clsConst);
out(" = ");
out("objc_getClass(\"");
@@ -1807,7 +1668,7 @@ void generateProtocolsConst() {
}
for (String cls : set) {
String clsConst = "protocol_" + cls;
- out("public static final int /*long*/ ");
+ out("public static final long ");
out(clsConst);
out(" = ");
out("objc_getProtocol(\"");
@@ -1829,33 +1690,41 @@ String getClassName() {
return mainClassName.substring(dot + 1);
}
-Node getReturnNode(NodeList list) {
+Node getReturnNode(Node method) {
+ NodeList list = method.getChildNodes();
for (int j = 0; j < list.getLength(); j++) {
Node node = list.item(j);
if ("retval".equals(node.getNodeName())) {
return node;
}
}
- return null;
+ return method;
}
+
String getType(Node node) {
+ return getType(node, false);
+}
+
+String getJavaType(Node node) {
+ return getType(node, true);
+}
+
+char getTypeCode(Node node) {
NamedNodeMap attributes = node.getAttributes();
- Node javaType = attributes.getNamedItem("swt_java_type");
- if (javaType != null) return javaType.getNodeValue();
- Node type = attributes.getNamedItem("type");
- if (type == null) {
- System.err.printf("Unable to detect type. Check bridge file! It might have been removed, inheritance changed, etc. Location: %s %n", toDebugLocation(node));
- return "notype";
- }
+ Node type = attributes.getNamedItem("type64");
+ if (type == null) type = attributes.getNamedItem("type");
+ if (type == null) return '?';
String code = type.getNodeValue();
- return getType(code, attributes, false, node);
+ if (code.startsWith("V")) code = code.substring(1);
+ if (code.isEmpty()) return '?';
+ return code.charAt(0);
}
private String toDebugLocation(Node location) {
StringBuilder result = new StringBuilder();
- while(location != null) {
- if(result.length() > 0) {
+ while (location != null) {
+ if (result.length() > 0) {
result.insert(0, " > ");
}
result.insert(0, getNodeInfo(location));
@@ -1885,147 +1754,46 @@ private String getNodeInfo(Node location) {
return location.toString();
}
-String getType64(Node node) {
- NamedNodeMap attributes = node.getAttributes();
- Node javaType = attributes.getNamedItem("swt_java_type");
- if (javaType != null) {
- Node javaType64 = attributes.getNamedItem("swt_java_type64");
- return javaType64 != null ? javaType64.getNodeValue() : javaType.getNodeValue();
- }
- Node attrib = attributes.getNamedItem("type");
- if (attrib == null) return "notype";
- String code = attrib.getNodeValue();
- Node attrib64 = attributes.getNamedItem("type64");
- if (attrib64 != null) code = attrib64.getNodeValue();
- return getType(code, attributes, true, node);
-}
-
-String getType(String code, NamedNodeMap attributes, boolean is64, Node location) {
- if (code.equals("c")) return "byte";
- if (code.equals("i")) return "int";
- if (code.equals("s")) return "short";
- if (code.equals("l")) return "int";
- if (code.equals("q")) return "long";
- if (code.equals("C")) return "byte";
- if (code.equals("I")) return "int";
- if (code.equals("S")) return "short";
- if (code.equals("L")) return "int";
- if (code.equals("Q")) return "long";
- if (code.equals("f")) return "float";
- if (code.equals("d")) return "double";
- if (code.equals("B")) return "boolean";
- if (code.equals("v")) return "void";
- if (code.equals("*")) return is64 ? "long" : "int";
- if (code.equals("@")) return is64 ? "long" : "int";
- if (code.equals("#")) return is64 ? "long" : "int";
- if (code.equals(":")) return is64 ? "long" : "int";
- if (code.startsWith("^")) return is64 ? "long" : "int";
- if (code.startsWith("{")) {
- return getDeclaredType(attributes, location);
- }
- if (code.startsWith("@?")) {
- return is64 ? "long" : "int";
- }
- return "BAD " + code;
-}
-
-String getJNIType(Node node) {
- NamedNodeMap attributes = node.getAttributes();
- String code = attributes.getNamedItem("type").getNodeValue();
- if (code.equals("c")) return "B";
- if (code.equals("i")) return "I";
- if (code.equals("s")) return "S";
- if (code.equals("l")) return "I";
- if (code.equals("q")) return "J";
- if (code.equals("C")) return "B";
- if (code.equals("I")) return "I";
- if (code.equals("S")) return "S";
- if (code.equals("L")) return "I";
- if (code.equals("Q")) return "J";
- if (code.equals("f")) return "F";
- if (code.equals("d")) return "D";
- if (code.equals("B")) return "Z";
- if (code.equals("v")) return "V";
- if (code.equals("*")) return "I";
- if (code.equals("@")) return "I";
- if (code.equals("#")) return "I";
- if (code.equals(":")) return "I";
- if (code.startsWith("^")) return "I";
- if (code.startsWith("@?")) return "I";
- if (code.startsWith("[")) return "BAD " + code;
- if (code.startsWith("{")) {
- return "BAD " + code;
- }
- if (code.startsWith("(")) return "BAD " + code;
- return "BAD " + code;
-}
+String getType(Node node, boolean withObjects) {
+ char typeCode = getTypeCode(node);
+ if (typeCode == '@' && !withObjects) return "long";
-String getJavaType(Node node) {
NamedNodeMap attributes = node.getAttributes();
- Node javaType = attributes.getNamedItem("swt_java_type");
- if (javaType != null) return javaType.getNodeValue().trim();
- Node type = attributes.getNamedItem("type");
- if (type == null) return "notype";
- String code = type.getNodeValue();
- return getJavaType(code, attributes, false, node);
-}
+ Node javaType = attributes.getNamedItem("swt_java_type64");
+ if (javaType == null) javaType = attributes.getNamedItem("swt_java_type");
+ if (javaType != null) return javaType.getNodeValue();
-String getJavaType64(Node node) {
- NamedNodeMap attributes = node.getAttributes();
- Node javaType = attributes.getNamedItem("swt_java_type");
- if (javaType != null) {
- Node javaType64 = attributes.getNamedItem("swt_java_type64");
- return javaType64 != null ? javaType64.getNodeValue() : javaType.getNodeValue();
- }
- Node attrib = attributes.getNamedItem("type");
- if (attrib == null) return "notype";
- String code = attrib.getNodeValue();
- Node attrib64 = attributes.getNamedItem("type64");
- if (attrib64 != null) code = attrib64.getNodeValue();
- return getJavaType(code, attributes, true, node);
-}
-
-String getJavaType(String code, NamedNodeMap attributes, boolean is64, Node location) {
- if (code.equals("c")) return "byte";
- if (code.equals("i")) return "int";
- if (code.equals("s")) return "short";
- if (code.equals("l")) return "int";
- if (code.equals("q")) return "long";
- if (code.equals("C")) return "byte";
- if (code.equals("I")) return "int";
- if (code.equals("S")) return "short";
- if (code.equals("L")) return "int";
- if (code.equals("Q")) return "long";
- if (code.equals("f")) return "float";
- if (code.equals("d")) return "double";
- if (code.equals("B")) return "boolean";
- if (code.equals("v")) return "void";
- if (code.equals("*")) return is64 ? "long" : "int";
- if (code.equals("#")) return is64 ? "long" : "int";
- if (code.equals(":")) return is64 ? "long" : "int";
- if (code.startsWith("^")) return is64 ? "long" : "int";
- if (code.equals("@")) {
- String type = getDeclaredType(attributes, location);
+ switch (typeCode) {
+ case 'v': return "void";
+ case 'B': return "boolean";
+ case 'c': return "byte";
+ case 'C': return "byte";
+ case 's': return "short";
+ case 'S': return "short";
+ case 'i': return "int";
+ case 'I': return "int";
+ case 'l': return "int";
+ case 'L': return "int";
+ case 'q': return "long";
+ case 'Q': return "long";
+ case 'f': return "float";
+ case 'd': return "double";
+ case '*': return "long";
+ case '#': return "long";
+ case ':': return "long";
+ case '^': return "long";
+ case '{': return getDeclaredType(attributes, node);
+ case '@': {
+ String type = getDeclaredType(attributes, node);
int index = type.indexOf('*');
if (index != -1) type = type.substring(0, index);
index = type.indexOf('<');
if (index != -1) type = type.substring(0, index);
- return type.trim();
+ type = type.trim();
+ return knownConstTypes.contains(type) ? "NSString" : type;
}
- if (code.startsWith("{")) {
- return getDeclaredType(attributes, location).trim();
+ default: return "notype";
}
- if (code.startsWith("@?")) return is64 ? "long" : "int";
- return "BAD " + code;
-}
-
-static String[] split(String str, String separator) {
- StringTokenizer tk = new StringTokenizer(str, separator);
- ArrayList<String> result = new ArrayList<>();
- while (tk.hasMoreTokens()) {
- result.add(tk.nextToken());
- }
- return result.toArray(new String[result.size()]);
}
void generateFunctions() {
@@ -2076,19 +1844,9 @@ void generateFunctions() {
outln();
}
out("public static final native ");
- Node returnNode = getReturnNode(node.getChildNodes());
- if (returnNode != null) {
- String type = getType(returnNode), type64 = getType64(returnNode);
- out(type);
- if (!type.equals(type64)) {
- out(" /*");
- out(type64);
- out("*/");
- }
- out(" ");
- } else {
- out("void ");
- }
+ Node returnNode = getReturnNode(node);
+ out(getType(returnNode));
+ out(" ");
out(name);
out("(");
params = node.getChildNodes();
@@ -2099,13 +1857,7 @@ void generateFunctions() {
if ("arg".equals(param.getNodeName())) {
if (!first) out(", ");
first = false;
- String type = getType(param), type64 = getType64(param);
- out(type);
- if (!type.equals(type64)) {
- out(" /*");
- out(type64);
- out("*/");
- }
+ out(getType(param));
out(" ");
out(getParamName(param, argIndex++));
}
@@ -2126,7 +1878,7 @@ void generateVariadics(Node node) {
Node variadicTypes = attributes.getNamedItem("swt_variadic_java_types");
String[] types = null;
if (variadicTypes != null) {
- types = split(variadicTypes.getNodeValue(), ",");
+ types = variadicTypes.getNodeValue().split(",");
}
int varCount = 0;
try {
@@ -2139,7 +1891,7 @@ void generateVariadics(Node node) {
} else if (types != null && types[types.length - 1].equals("*")) {
out(types[types.length - 2]);
} else {
- out("int /*long*/");
+ out("long");
}
out(" varArg");
out("" + j);
diff --git a/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGeneratorUI.java b/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGeneratorUI.java
index 918d05bb35..f371d127fc 100644
--- a/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGeneratorUI.java
+++ b/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGeneratorUI.java
@@ -68,25 +68,25 @@ public class MacGeneratorUI {
}
void checkPath(TreeItem item, boolean checked, boolean grayed) {
- if (item == null) return;
- if (grayed) {
- checked = true;
- } else {
- int index = 0;
- TreeItem[] items = item.getItems();
- while (index < items.length) {
- TreeItem child = items[index];
- if (child.getGrayed() || checked != child.getChecked()) {
- checked = grayed = true;
- break;
- }
- index++;
- }
- }
- item.setChecked(checked);
- item.setGrayed(grayed);
- updateGenAttribute(item);
- checkPath(item.getParentItem(), checked, grayed);
+ if (item == null) return;
+ if (grayed) {
+ checked = true;
+ } else {
+ int index = 0;
+ TreeItem[] items = item.getItems();
+ while (index < items.length) {
+ TreeItem child = items[index];
+ if (child.getGrayed() || checked != child.getChecked()) {
+ checked = grayed = true;
+ break;
+ }
+ index++;
+ }
+ }
+ item.setChecked(checked);
+ item.setGrayed(grayed);
+ updateGenAttribute(item);
+ checkPath(item.getParentItem(), checked, grayed);
}
void checkItem(Node node, TreeItem item) {
@@ -139,22 +139,22 @@ public class MacGeneratorUI {
}
void checkItems(TreeItem item, boolean checked) {
- item.setGrayed(false);
- item.setChecked(checked);
- updateGenAttribute(item);
- TreeItem[] items = item.getItems();
- if (items.length == 1 && items[0].getData() == null) {
- /* Update model only if view is not created */
+ item.setGrayed(false);
+ item.setChecked(checked);
+ updateGenAttribute(item);
+ TreeItem[] items = item.getItems();
+ if (items.length == 1 && items[0].getData() == null) {
+ /* Update model only if view is not created */
Node node = (Node)item.getData();
NodeList childNodes = node.getChildNodes();
for (int i = 0, length = childNodes.getLength(); i < length; i++) {
checkNodes(childNodes.item(i), checked);
}
- } else {
- for (int i = 0; i < items.length; i++) {
- checkItems(items[i], checked);
- }
- }
+ } else {
+ for (int i = 0; i < items.length; i++) {
+ checkItems(items[i], checked);
+ }
+ }
}
void checkNodes(Node node, boolean checked) {
@@ -209,9 +209,9 @@ public class MacGeneratorUI {
}
boolean checked = item.getChecked();
item.getParent().setRedraw(false);
- checkItems(item, checked);
- checkPath(item.getParentItem(), checked, false);
- item.getParent().setRedraw(true);
+ checkItems(item, checked);
+ checkPath(item.getParentItem(), checked, false);
+ item.getParent().setRedraw(true);
});
nodesTree.addListener(SWT.Expand, event -> checkChildren((TreeItem)event.item));
@@ -403,8 +403,8 @@ public class MacGeneratorUI {
}
Document[] documents = gen.getDocuments();
if (node == null && documents.length > 0) {
- int index = 0;
- while (index < documents.length && (node = documents[index]) == null) index++;
+ int index = 0;
+ while (index < documents.length && (node = documents[index]) == null) index++;
}
if (flatNodes == null) {
flatNodes = new ArrayList<>();
@@ -564,10 +564,10 @@ public class MacGeneratorUI {
gen.setXmls(null);
flatNodes = null;
nodesTree.getDisplay().asyncExec(() -> {
- if (nodesTree == null || nodesTree.isDisposed()) return;
- nodesTree.removeAll();
- attribTable.removeAll();
- updateNodes();
+ if (nodesTree == null || nodesTree.isDisposed()) return;
+ nodesTree.removeAll();
+ attribTable.removeAll();
+ updateNodes();
});
}
diff --git a/bundles/org.eclipse.swt.tools/plugin.xml b/bundles/org.eclipse.swt.tools/plugin.xml
index f3393759e6..cc6cd0b9df 100644
--- a/bundles/org.eclipse.swt.tools/plugin.xml
+++ b/bundles/org.eclipse.swt.tools/plugin.xml
@@ -29,36 +29,4 @@
</builder>
</extension>
- <extension
- point="org.eclipse.jdt.core.compilationParticipant">
- <compilationParticipant
- class="org.eclipse.swt.tools.builders.Check64CompilationParticipant"
- id="org.eclipse.swt.tools.Check64CompilationParticipant">
- </compilationParticipant>
- </extension>
-
- <extension
- point="org.eclipse.ui.popupMenus">
- <objectContribution
- objectClass="org.eclipse.jdt.core.IJavaProject"
- id="org.eclipse.swt.tools.contribution">
- <menu
- label="%pluginName"
- path="additions"
- id="org.eclipse.swt.tools.menu">
- <separator
- name="group1">
- </separator>
- </menu>
- <action
- label="%enableCheck64Name"
- class="org.eclipse.swt.tools.builders.Check64EnableAction"
- menubarPath="org.eclipse.swt.tools.menu/group1"
- style="toggle"
- enablesFor="1"
- id="org.eclipse.swt.tools.check64EnableAction">
- </action>
- </objectContribution>
- </extension>
-
</plugin>
diff --git a/bundles/org.eclipse.swt.tools/pom.xml b/bundles/org.eclipse.swt.tools/pom.xml
index 1f4aa876a0..55759a71e9 100644
--- a/bundles/org.eclipse.swt.tools/pom.xml
+++ b/bundles/org.eclipse.swt.tools/pom.xml
@@ -14,11 +14,11 @@
<parent>
<artifactId>eclipse.platform.swt.localbuild</artifactId>
<groupId>eclipse.platform.swt</groupId>
- <version>4.12.0-SNAPSHOT</version>
+ <version>4.14.0-SNAPSHOT</version>
<relativePath>../../local-build/local-build-parent/</relativePath>
</parent>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.tools</artifactId>
- <version>3.107.400-SNAPSHOT</version>
+ <version>3.108.100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/Activator.java b/bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/Activator.java
deleted file mode 100644
index b60bb5b957..0000000000
--- a/bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/Activator.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2016 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.tools;
-
-import org.eclipse.jface.resource.*;
-import org.eclipse.ui.plugin.*;
-import org.osgi.framework.*;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.swt.tools";
-
- // The shared instance
- private static Activator plugin;
-
- /**
- * The constructor
- */
- public Activator() {
- }
-
- @Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- }
-
- @Override
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
- /**
- * Returns an image descriptor for the image file at the given
- * plug-in relative path
- *
- * @param path the path
- * @return the image descriptor
- */
- public static ImageDescriptor getImageDescriptor(String path) {
- return imageDescriptorFromPlugin(PLUGIN_ID, path);
- }
-}
diff --git a/bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/builders/Check64CompilationParticipant.java b/bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/builders/Check64CompilationParticipant.java
deleted file mode 100644
index da81c110fc..0000000000
--- a/bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/builders/Check64CompilationParticipant.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2018 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.tools.builders;
-
-import java.io.*;
-import java.util.*;
-
-import javax.xml.parsers.*;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.jdt.core.*;
-import org.eclipse.jdt.core.compiler.*;
-import org.eclipse.jdt.core.compiler.batch.*;
-import org.eclipse.jdt.core.dom.*;
-import org.eclipse.swt.tools.*;
-import org.w3c.dom.*;
-import org.xml.sax.*;
-
-public class Check64CompilationParticipant extends CompilationParticipant {
- HashSet<String> sources;
-
- static final char[] INT_LONG = "int /*long*/".toCharArray();
- static final char[] INT_LONG_ARRAY = "int[] /*long[]*/".toCharArray();
- static final char[] FLOAT_DOUBLE = "float /*double*/".toCharArray();
- static final char[] FLOAT_DOUBLE_ARRAY = "float[] /*double[]*/".toCharArray();
- static final char[] LONG_INT = "long /*int*/".toCharArray();
- static final char[] LONG_INT_ARRAY = "long[] /*int[]*/".toCharArray();
- static final char[] DOUBLE_FLOAT = "double /*float*/".toCharArray();
- static final char[] DOUBLE_FLOAT_ARRAY = "double[] /*float[]*/".toCharArray();
- static final String buildDir = "/.build64/";
- static final String pluginDir = "/org.eclipse.swt/";
- static final String plugin = "org.eclipse.swt";
- static final String SOURCE_ID = "JNI";
- static final String CHECK_64_ENABLED = Activator.PLUGIN_ID + "CHECK_64_ENABLED";
-
-static String loadFile (String file) {
- if (file == null) return null;
- try (FileReader fr = new FileReader(file);
- BufferedReader br = new BufferedReader(fr)) {
- StringBuilder str = new StringBuilder();
- char[] buffer = new char[1024];
- int read;
- while ((read = br.read(buffer)) != -1) {
- str.append(buffer, 0, read);
- }
- fr.close();
- return str.toString();
- } catch (IOException e) {
- throw new RuntimeException("File not found:" + file, e);
- }
-}
-
-void build(IJavaProject project, String root) throws CoreException {
- try {
- StringBuilder sourcePath = new StringBuilder(), cp = new StringBuilder();
- IClasspathEntry[] entries = project.getResolvedClasspath(true);
- for (int i = 0; i < entries.length; i++) {
- IClasspathEntry entry = entries[i];
- String path = entry.getPath().toPortableString();
- if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
- if (path.startsWith(pluginDir)) {
- if (sourcePath.length() > 0) sourcePath.append(File.pathSeparatorChar);
- String dir = root + path.substring(pluginDir.length());
- sourcePath.append(dir);
- }
- } else {
- if (cp.length() > 0) cp.append(File.pathSeparator);
- cp.append(path);
- }
- }
- String bin = root + "/bin";
- if (cp.length() > 0) cp.append(File.pathSeparator);
- cp.append(bin);
- ArrayList<String> args = new ArrayList<>();
- args.addAll(Arrays.asList(new String[]{
- "-nowarn",
- "-1.8",
-// "-verbose",
- "-d", bin,
- "-cp", cp.toString(),
- "-log", root + "/log.xml",
- "-sourcepath", sourcePath.toString(),
- }));
- args.addAll(sources);
- try (PrintWriter writer = new PrintWriter(new BufferedOutputStream(new FileOutputStream(root + "/out.txt")))) {
- BatchCompiler.compile(args.toArray(new String[args.size()]), writer, writer, null);
- }
- project.getProject().findMember(new Path(buildDir)).refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Problem building 64-bit code", e));
- }
-}
-
-void create(IContainer file) throws CoreException {
- if (file.exists()) return;
- switch (file.getType()) {
- case IResource.FOLDER:
- create(file.getParent());
- ((IFolder)file).create(true, true, null);
- }
-}
-
-IResource getResourceWithoutErrors(IProject proj, String path, boolean deleteJNI) throws CoreException {
- path = path.replaceAll(buildDir, "/");
- String projPath = proj.getLocation().toPortableString();
- if (path.startsWith(projPath)) {
- path = path.substring(projPath.length());
- }
- IResource resource = proj.findMember(new Path(path));
- boolean hasProblems = false;
- IMarker[] markers = resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
- for (int m = 0; m < markers.length; m++) {
- IMarker marker = markers[m];
- if (SOURCE_ID.equals(marker.getAttribute(IMarker.SOURCE_ID))) {
- if (deleteJNI) marker.delete();
- } else {
- Object severity = marker.getAttribute(IMarker.SEVERITY);
- hasProblems |= severity != null && ((Integer)severity).intValue() == IMarker.SEVERITY_ERROR;
- }
- }
- return hasProblems ? null : resource;
-}
-
-void createProblem(IResource resource, String message, int start, int end) throws CoreException {
- IMarker marker = resource.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
- int severity = IMarker.SEVERITY_ERROR;
- marker.setAttributes(
- new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IMarker.CHAR_START, IMarker.CHAR_END, IMarker.SOURCE_ID},
- new Object[] {"[32/64] " + message, Integer.valueOf(severity), Integer.valueOf(start), Integer.valueOf(end), SOURCE_ID});
-}
-
-void createProblems(IJavaProject project, String root) throws CoreException {
- try (InputStream is = new BufferedInputStream(new FileInputStream(root + "/log.xml"))) {
- Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(is));
- is.close();
- IProject proj = project.getProject();
- NodeList sources = doc.getDocumentElement().getElementsByTagName("sources");
- for (int i = 0; i < sources.getLength(); i++) {
- NodeList src = ((Element)sources.item(i)).getElementsByTagName("source");
- for (int j = 0; j < src.getLength(); j++) {
- Element source = (Element)src.item(j);
- String path = source.getAttribute("path").replace('\\', '/');
- IResource resource = getResourceWithoutErrors(proj, path, true);
- if (resource != null) {
- NodeList problems = source.getElementsByTagName("problems");
- for (int k = 0; k < problems.getLength(); k++) {
- NodeList problem = ((Element)problems.item(k)).getElementsByTagName("problem");
- for (int l = 0; l < problem.getLength(); l++) {
- Element node = (Element)problem.item(l);
- if (resource != null) {
- int start = Integer.parseInt(node.getAttribute("charStart"));
- int end = Integer.parseInt(node.getAttribute("charEnd"));
- String message = ((Element)node.getElementsByTagName("message").item(0)).getAttribute("value");
- createProblem(resource, message, start, end);
- }
- }
- }
- }
- }
- }
- } catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Problem creating 64-bit problems", e));
- }
-}
-
-String resolvePath(String sourcePath, String simpleName) {
- String basePath = sourcePath.substring(0, sourcePath.lastIndexOf("/"));
- File file = new File(basePath + "/" + simpleName + ".java");
- if (file.exists()) {
- return file.getAbsolutePath();
- }
-// System.out.println("failed=" + simpleName + " " + sourcePath);
- return null;
-}
-
-TypeDeclaration loadType(HashMap<String, TypeDeclaration> cache, String path) {
- if (path == null) return null;
- Object value = cache.get(path);
- if (value != null) return (TypeDeclaration)value;
- ASTParser parser = ASTParser.newParser(AST.JLS8);
- parser.setSource(loadFile(path).toCharArray());
- CompilationUnit unit = (CompilationUnit)parser.createAST(null);
- TypeDeclaration type = (TypeDeclaration)unit.types().get(0);
- cache.put(path, type);
- return type;
-}
-
-boolean is64Type(String type) {
- return type.equals("int") || type.equals("long") || type.equals("float") || type.equals("double") ||
- type.equals("int[]") || type.equals("long[]") || type.equals("float[]") || type.equals("double[]");
-}
-
-void createBadOverwrittenMethodProblems(IJavaProject project) throws CoreException {
- if (sources == null) return;
- IProject proj = project.getProject();
- HashMap<String, TypeDeclaration> cache = new HashMap<>();
- for (String path: sources) {
- IResource resource = getResourceWithoutErrors(proj, path, false);
- if (resource == null) continue;
- TypeDeclaration type = loadType(cache, path);
- MethodDeclaration[] methods = type.getMethods();
- List<TypeDeclaration> superclasses = new ArrayList<>();
- TypeDeclaration temp = type;
- while (true) {
- Type supertype = temp.getSuperclassType();
- if (supertype == null) break;
- TypeDeclaration stype = loadType(cache, resolvePath(path, supertype.toString()));
- if (stype == null) break;
- superclasses.add(stype);
- temp = stype;
- }
- for (int i = 0; i < methods.length; i++) {
- MethodDeclaration method = methods[i];
- for (TypeDeclaration supertype : superclasses) {
- MethodDeclaration[] supermethods = supertype.getMethods();
- for (int j = 0; j < supermethods.length; j++) {
- MethodDeclaration supermethod = supermethods[j];
- if (method.getName().getIdentifier().equals(supermethod.getName().getIdentifier()) && method.parameters().size() == supermethod.parameters().size()) {
- List<SingleVariableDeclaration> mParams = method.parameters();
- List<SingleVariableDeclaration> sParams = supermethod.parameters();
- for (int k=0; k<sParams.size(); k++) {
- SingleVariableDeclaration p1 = mParams.get(k);
- SingleVariableDeclaration p2 = sParams.get(k);
- String r1 = p1.getType().toString();
- String r2 = p2.getType().toString();
- if (is64Type(r1) && is64Type(r2)) {
- if (!r1.equals(r2) && p1.getName().getIdentifier().equals(p2.getName().getIdentifier())) {
- String message = "\"" + p1.getName().getIdentifier() + "\" parameter type does not match super declaration";
- createProblem(resource, message, p1.getStartPosition(), p1.getStartPosition() + p1.toString().length());
- }
- }
- }
- }
- }
- }
- }
- }
-}
-
-boolean replace(char[] source, char[] src, char[] dest) {
- boolean changed = false;
- int start = 0;
- while (start < source.length) {
- int index = CharOperation.indexOf(src, source, true, start);
- if (index == -1) break;
- changed |= true;
- System.arraycopy(dest, 0, source, index, dest.length);
- start = index + 1;
- }
- return changed;
-}
-
-boolean replace(char[] source) {
- boolean changed = false;
- changed |= replace(source, LONG_INT, INT_LONG);
- changed |= replace(source, LONG_INT_ARRAY, INT_LONG_ARRAY);
- changed |= replace(source, DOUBLE_FLOAT, FLOAT_DOUBLE);
- changed |= replace(source, DOUBLE_FLOAT_ARRAY, FLOAT_DOUBLE_ARRAY);
- if (!changed) {
- changed |= replace(source, INT_LONG, LONG_INT);
- changed |= replace(source, INT_LONG_ARRAY, LONG_INT_ARRAY);
- changed |= replace(source, FLOAT_DOUBLE, DOUBLE_FLOAT);
- changed |= replace(source, FLOAT_DOUBLE_ARRAY, DOUBLE_FLOAT_ARRAY);
- }
- return changed;
-}
-
-public static boolean getEnabled() {
- return Activator.getDefault().getPreferenceStore().getBoolean(CHECK_64_ENABLED);
-}
-
-public static void setEnabled(boolean enabled) {
- Activator.getDefault().getPreferenceStore().setValue(CHECK_64_ENABLED, enabled);
-}
-
-boolean is64bit(IJavaProject project) {
- try {
- IClasspathEntry[] entries = project.getResolvedClasspath(true);
- for (int i = 0; i < entries.length; i++) {
- IClasspathEntry entry = entries[i];
- if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
- String path = entry.getPath().toPortableString();
- if (path.equals(pluginDir + "Eclipse SWT PI/win32") ||
- path.equals(pluginDir + "Eclipse SWT PI/cocoa") ||
- path.equals(pluginDir + "Eclipse SWT PI/gtk")
- )
- {
- return true;
- }
- }
- }
- } catch (JavaModelException e) {}
- return false;
-}
-
-@Override
-public void buildFinished(IJavaProject project) {
- try {
- if (sources == null) return;
- if (!getEnabled() || !is64bit(project)) return;
-// long time = System.currentTimeMillis();
- String root = project.getProject().getLocation().toPortableString() + buildDir;
- build(project, root);
- createProblems(project, root);
- createBadOverwrittenMethodProblems(project);
- sources = null;
-// System.out.println("compiling time=" + (System.currentTimeMillis() - time));
- } catch (Exception e) {
- e.printStackTrace();
- }
-}
-
-@Override
-public void buildStarting(BuildContext[] files, boolean isBatch) {
- if (sources == null) sources = new HashSet<>();
-// long time = System.currentTimeMillis();
- for (int i = 0; i < files.length; i++) {
- BuildContext context = files[i];
- IFile file = context.getFile();
- IProject project = file.getProject();
- Path path = new Path(buildDir + file.getProjectRelativePath().toPortableString());
- IFile newFile = project.getFile(path);
- sources.add(newFile.getLocation().toPortableString());
- try {
- if (newFile.exists()) {
- newFile.delete(true, null);
- }
- create(newFile.getParent());
- char[] source = context.getContents();
- replace(source);
- newFile.create(new ByteArrayInputStream(new String(source).getBytes()), true, null);
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
-// System.out.println("copying time=" + (System.currentTimeMillis() - time));
-}
-
-@Override
-public void cleanStarting(IJavaProject project) {
- if (!isActive(project)) return;
- sources = null;
- IResource resource = project.getProject().findMember(new Path(buildDir));
- if (resource != null) {
- try {
- resource.delete(true, null);
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
-}
-
-@Override
-public boolean isActive(IJavaProject project) {
- if (project.getProject().getName().equals(plugin)) {
- return true;
- }
- return super.isActive(project);
-}
-
-}
diff --git a/bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/builders/Check64EnableAction.java b/bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/builders/Check64EnableAction.java
deleted file mode 100644
index 68e3e79b13..0000000000
--- a/bundles/org.eclipse.swt.tools/src/org/eclipse/swt/tools/builders/Check64EnableAction.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2015 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.tools.builders;
-
-import org.eclipse.jface.action.*;
-import org.eclipse.jface.viewers.*;
-import org.eclipse.ui.*;
-
-public class Check64EnableAction implements IObjectActionDelegate {
-
- public Check64EnableAction() {
- super();
- }
-
- @Override
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- action.setChecked(Check64CompilationParticipant.getEnabled());
- }
-
- @Override
- public void run(IAction action) {
- Check64CompilationParticipant.setEnabled(action.isChecked());
- }
-
- @Override
- public void selectionChanged(IAction action, ISelection selection) {
- }
-
-}

Back to the top