Skip to content

Commit f650ebd

Browse files
author
Olivier Chafik
committed
BridJ: bulk format
1 parent 18db26e commit f650ebd

172 files changed

Lines changed: 11401 additions & 9034 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libraries/BridJ/src/main/java/org/bridj/AbstractBridJRuntime.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,63 +38,76 @@
3838

3939
/**
4040
* Base class for implementation of runtimes
41+
*
4142
* @author Olivier
4243
*/
4344
public abstract class AbstractBridJRuntime implements BridJRuntime {
44-
//@Override
45-
public void unregister(Type type) {
46-
// TODO !!!
47-
}
45+
//@Override
46+
47+
public void unregister(Type type) {
48+
// TODO !!!
49+
}
4850

49-
//@Override
51+
//@Override
5052
public Type getType(NativeObject instance) {
51-
if (instance == null)
53+
if (instance == null) {
5254
return null;
55+
}
5356
return Utils.getClass(instance.getClass());
5457
}
5558

5659
protected java.lang.reflect.Constructor findConstructor(Class<?> type, int constructorId, boolean onlyWithAnnotation) throws SecurityException, NoSuchMethodException {
57-
for (java.lang.reflect.Constructor<?> c : type.getDeclaredConstructors()) {
60+
for (java.lang.reflect.Constructor<?> c : type.getDeclaredConstructors()) {
5861
org.bridj.ann.Constructor ca = c.getAnnotation(org.bridj.ann.Constructor.class);
59-
if (ca == null)
60-
continue;
61-
if (ca.value() == constructorId)
62+
if (ca == null) {
63+
continue;
64+
}
65+
if (ca.value() == constructorId) {
6266
return c;
67+
}
6368
}
6469
if (constructorId < 0)// && args.length == 0)
70+
{
6571
return type.getConstructor();
72+
}
6673
Class<?> sup = type.getSuperclass();
6774
if (sup != null) {
6875
try {
6976
java.lang.reflect.Constructor c = findConstructor(sup, constructorId, onlyWithAnnotation);
70-
if (onlyWithAnnotation && c != null)
77+
if (onlyWithAnnotation && c != null) {
7178
return c;
72-
79+
}
80+
7381
Type[] params = c.getGenericParameterTypes();
7482
Constructor<?>[] ccs = type.getDeclaredConstructors();
7583
for (java.lang.reflect.Constructor cc : ccs) {
7684
Type[] ccparams = cc.getGenericParameterTypes();
7785
int overrideOffset = Utils.getEnclosedConstructorParametersOffset(cc);
78-
if (isOverridenSignature(params, ccparams, overrideOffset))
86+
if (isOverridenSignature(params, ccparams, overrideOffset)) {
7987
return cc;
88+
}
8089
}
8190
} catch (Throwable th) {
8291
th.printStackTrace();
8392
}
8493
}
85-
throw new NoSuchMethodException("Cannot find constructor with index " + constructorId);
86-
}
94+
throw new NoSuchMethodException("Cannot find constructor with index " + constructorId);
95+
}
96+
8797
public static boolean isOverridenSignature(Type[] parentSignature, Type[] overrideSignature, int overrideOffset) {
8898
int n = parentSignature.length;
89-
if (overrideSignature.length - overrideOffset != n)
99+
if (overrideSignature.length - overrideOffset != n) {
90100
return false;
91-
for (int i = 0; i < n; i++)
92-
if (!isOverride(parentSignature[i], overrideSignature[overrideOffset + i]))
101+
}
102+
for (int i = 0; i < n; i++) {
103+
if (!isOverride(parentSignature[i], overrideSignature[overrideOffset + i])) {
93104
return false;
105+
}
106+
}
94107
return true;
95108
}
109+
96110
protected static boolean isOverride(Type parentSignature, Type overrideSignature) {
97111
return Utils.getClass(parentSignature).isAssignableFrom(Utils.getClass(overrideSignature));
98112
}
99-
100113
}

libraries/BridJ/src/main/java/org/bridj/AbstractIntegral.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,27 @@
3232

3333
/**
3434
* Base class for custom integral numbers
35+
*
3536
* @author Olivier
3637
*/
3738
class AbstractIntegral extends Number {
38-
39-
protected final long value;
39+
40+
protected final long value;
41+
4042
public AbstractIntegral(long value) {
4143
this.value = value;
4244
}
45+
private static final long HIGH_NEG = 0xffffffff00000000L;
4346

44-
private static final long HIGH_NEG = 0xffffffff00000000L;
45-
public static int safeIntCast(long value) {
46-
long high = value & HIGH_NEG;
47-
if (high != 0 && high != HIGH_NEG)
48-
//if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE)
47+
public static int safeIntCast(long value) {
48+
long high = value & HIGH_NEG;
49+
if (high != 0 && high != HIGH_NEG) //if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE)
50+
{
4951
throw new RuntimeException("Value " + value + " = 0x" + Long.toHexString(value) + " is not within the int range");
50-
51-
return (int)(value & 0xffffffff);
52-
}
52+
}
53+
54+
return (int) (value & 0xffffffff);
55+
}
5356

5457
@Override
5558
public int intValue() {
@@ -70,23 +73,25 @@ public float floatValue() {
7073
public double doubleValue() {
7174
return value;
7275
}
73-
76+
7477
@Override
7578
public boolean equals(Object o) {
76-
if (o == null || !(o instanceof AbstractIntegral))
77-
return false;
78-
if (!o.getClass().equals(getClass()))
79-
return false;
80-
return value == ((AbstractIntegral)o).value;
79+
if (o == null || !(o instanceof AbstractIntegral)) {
80+
return false;
81+
}
82+
if (!o.getClass().equals(getClass())) {
83+
return false;
84+
}
85+
return value == ((AbstractIntegral) o).value;
8186
}
82-
87+
8388
@Override
8489
public int hashCode() {
85-
return ((Long)value).hashCode();
90+
return ((Long) value).hashCode();
8691
}
87-
92+
8893
@Override
8994
public String toString() {
90-
return getClass().getSimpleName() + "(" + value + ")";
95+
return getClass().getSimpleName() + "(" + value + ")";
9196
}
9297
}

libraries/BridJ/src/main/java/org/bridj/AndroidClassDefiner.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,22 @@ class AndroidClassDefiner implements ClassDefiner {
5151

5252
protected final File cacheDir;
5353
protected final ClassLoader parentClassLoader;
54+
5455
public AndroidClassDefiner(File cacheDir, ClassLoader parentClassLoader) throws IOException {
5556
this.cacheDir = cacheDir;
5657
this.parentClassLoader = parentClassLoader;
5758
}
5859

5960
static void delete(File f) {
6061
File[] fs = f.listFiles();
61-
if (fs != null)
62-
for (File ff : fs)
62+
if (fs != null) {
63+
for (File ff : fs) {
6364
delete(ff);
65+
}
66+
}
6467
f.delete();
6568
}
66-
69+
6770
private static final byte[] dex(String className, byte[] classData) throws ClassFormatError {
6871
try {
6972
DexOptions dexOptions = new DexOptions();
@@ -72,13 +75,15 @@ private static final byte[] dex(String className, byte[] classData) throws Class
7275
dxFile.add(CfTranslator.translate(className.replace('.', '/') + ".class", classData, cfOptions, dexOptions));
7376
StringWriter out = BridJ.debug ? new StringWriter() : null;
7477
byte[] dexData = dxFile.toDex(out, false);
75-
if (BridJ.debug)
78+
if (BridJ.debug) {
7679
BridJ.info("Dex output for class " + className + " : " + out);
80+
}
7781
return dexData;
7882
} catch (IOException ex) {
7983
throw new ClassFormatError("Unable to convert class data to Dalvik code using Dex : " + ex);
8084
}
8185
}
86+
8287
public Class<?> defineClass(String className, byte[] classData) throws ClassFormatError {
8388
byte[] dexData = dex(className, classData);
8489

@@ -105,12 +110,14 @@ public Class<?> defineClass(String className, byte[] classData) throws ClassForm
105110
} catch (Throwable th) {
106111
throw new RuntimeException("Failed with tempFile = " + apkFile + " : " + th, th);
107112
} finally {
108-
if (apkFile != null)
113+
if (apkFile != null) {
109114
delete(apkFile);
115+
}
110116

111-
if (tempDir != null)
117+
if (tempDir != null) {
112118
delete(tempDir);
119+
}
113120
}
114-
121+
115122
}
116123
}

0 commit comments

Comments
 (0)