Skip to content

Commit 2219cc3

Browse files
committed
Formatting.
1 parent d375765 commit 2219cc3

39 files changed

+679
-636
lines changed

rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTKit.java

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.sun.jna.Library;
2323
import com.sun.jna.Native;
2424

25-
@SuppressWarnings("nls")
2625
public interface QTKit extends Library {
2726

2827
QTKit instance = Native.load("QTKit", QTKit.class);

rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMedia.java

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import com.sun.jna.Pointer;
2828

29-
@SuppressWarnings("nls")
3029
public @RunOnMainThread abstract class QTMedia extends NSObject {
3130

3231
public static final String QTMediaDurationAttribute = "QTMediaDurationAttribute";

rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTrack.java

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import com.sun.jna.Pointer;
2828

29-
@SuppressWarnings("nls")
3029
public @RunOnMainThread abstract class QTTrack extends NSObject {
3130

3231
public static final String QTTrackTimeScaleAttribute = "QTTrackTimeScaleAttribute";

rococoa/rococoa-cocoa/src/test/java/org/rococoa/cocoa/qtkit/QTMovieTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import static org.junit.Assert.*;
3434

3535

36-
@SuppressWarnings("nls")
3736
@Ignore
3837
public class QTMovieTest extends RococoaTestCase {
3938

rococoa/rococoa-core/src/main/java/org/rococoa/Foundation.java

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
*
4545
* @author duncan
4646
*/
47-
@SuppressWarnings("nls")
4847
public abstract class Foundation {
4948

5049
private static final Logger logging = Logger.getLogger("org.rococoa.foundation");

rococoa/rococoa-core/src/main/java/org/rococoa/Selector.java

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import com.sun.jna.NativeLong;
2323

24-
@SuppressWarnings("nls")
2524
public class Selector extends NativeLong {
2625

2726
private String name;

rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationMapper.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.rococoa.internal;
2121

2222

23+
import com.sun.jna.Native;
2324
import org.rococoa.cocoa.foundation.NSInvocation;
2425

2526
import com.sun.jna.Memory;
@@ -45,7 +46,7 @@ public String typeString() {
4546
}
4647

4748
public Object readArgumentFrom(NSInvocation invocation, int index, Class<?> type) {
48-
Memory buffer = new Memory(8); // big enough for long or double
49+
Memory buffer = new Memory(Native.LONG_SIZE); // big enough for long or double
4950
invocation.getArgument_atIndex(buffer, index);
5051
return readFrom(buffer, type);
5152
}

rococoa/rococoa-core/src/main/java/org/rococoa/internal/OCInvocationCallbacks.java

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
* @author duncan
5050
*
5151
*/
52-
@SuppressWarnings("nls")
5352
public class OCInvocationCallbacks {
5453

5554
private static final Logger logging = Logger.getLogger("org.rococoa.callback");

rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectInvocationHandler.java

+28-52
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919

2020
package org.rococoa.internal;
2121

22+
import com.sun.jna.Pointer;
23+
import net.sf.cglib.proxy.MethodInterceptor;
24+
import net.sf.cglib.proxy.MethodProxy;
25+
import org.rococoa.*;
26+
import org.rococoa.cocoa.CFIndex;
27+
2228
import java.lang.reflect.AnnotatedElement;
2329
import java.lang.reflect.InvocationHandler;
2430
import java.lang.reflect.Method;
@@ -27,35 +33,15 @@
2733
import java.util.Arrays;
2834
import java.util.List;
2935
import java.util.concurrent.Callable;
30-
31-
import net.sf.cglib.proxy.MethodInterceptor;
32-
import net.sf.cglib.proxy.MethodProxy;
33-
34-
import org.rococoa.Foundation;
35-
import org.rococoa.ID;
36-
import org.rococoa.IDByReference;
37-
import org.rococoa.ObjCObject;
38-
import org.rococoa.ObjCObjectByReference;
39-
import org.rococoa.ReleaseInFinalize;
40-
import org.rococoa.ReturnType;
41-
import org.rococoa.Rococoa;
42-
import org.rococoa.RococoaException;
43-
import org.rococoa.RunOnMainThread;
44-
4536
import java.util.logging.Level;
4637
import java.util.logging.Logger;
4738

48-
import com.sun.jna.Pointer;
49-
import org.rococoa.cocoa.CFIndex;
50-
5139
/**
5240
* Listens to invocations of methods on a Java NSObject, and forwards them to
5341
* its Objective-C counterpart.
5442
*
5543
* @author duncan
56-
*
5744
*/
58-
@SuppressWarnings("nls")
5945
public class ObjCObjectInvocationHandler implements InvocationHandler, MethodInterceptor {
6046

6147
private static final int FINALIZE_AUTORELEASE_BATCH_SIZE = 1000;
@@ -73,16 +59,14 @@ public class ObjCObjectInvocationHandler implements InvocationHandler, MethodInt
7359
OBJECT_HASHCODE = Object.class.getMethod("hashCode");
7460
OBJECT_EQUALS = Object.class.getMethod("equals", Object.class);
7561
OCOBJECT_ID = ObjCObject.class.getMethod("id");
76-
}
77-
catch (Exception x) {
62+
} catch (NoSuchMethodException x) {
7863
throw new RococoaException("Error retrieving method", x);
7964
}
8065
}
8166

8267
private ID ocInstance;
8368
private final String javaClassName;
8469
private final boolean invokeAllMethodsOnMainThread;
85-
8670
private final boolean releaseOnFinalize;
8771
private volatile boolean finalized;
8872

@@ -94,7 +78,7 @@ public ObjCObjectInvocationHandler(final ID ocInstance, Class<? extends ObjCObje
9478

9579
if (logging.isLoggable(Level.FINEST)) {
9680
CFIndex retainCount = Foundation.cfGetRetainCount(ocInstance);
97-
logging.finest(String.format("Creating NSObjectInvocationHandler for id %s, javaclass %s. retain = %s, retainCount = %s",
81+
logging.finest(String.format("Creating ObjCObjectInvocationHandler for id %s, javaclass %s. retain = %s, retainCount = %s",
9882
ocInstance, javaClass, retain, retainCount.intValue()));
9983
}
10084

@@ -104,10 +88,7 @@ public ObjCObjectInvocationHandler(final ID ocInstance, Class<? extends ObjCObje
10488

10589
if (retain) {
10690
if (callAcrossToMainThread()) {
107-
Foundation.runOnMainThread(new Runnable() {
108-
public void run() {
109-
Foundation.cfRetain(ocInstance);
110-
}});
91+
Foundation.runOnMainThread(() -> Foundation.cfRetain(ocInstance));
11192
} else {
11293
Foundation.cfRetain(ocInstance);
11394
}
@@ -131,10 +112,7 @@ protected void finalize() throws Throwable {
131112
}
132113
try {
133114
if (callAcrossToMainThread()) {
134-
Foundation.runOnMainThread(new Runnable() {
135-
public void run() {
136-
release();
137-
}});
115+
Foundation.runOnMainThread(() -> release());
138116
} else {
139117
AutoreleaseBatcher autoreleaseBatcher = AutoreleaseBatcher.forThread(FINALIZE_AUTORELEASE_BATCH_SIZE);
140118
release();
@@ -163,7 +141,7 @@ private void release() {
163141
/**
164142
* Callback from java.lang.reflect proxy
165143
*/
166-
public Object invoke(Object proxy, Method method, Object[] args) throws Exception {
144+
public Object invoke(Object proxy, Method method, Object[] args) throws Exception {
167145
if (logging.isLoggable(Level.FINEST)) {
168146
logging.finest(String.format("invoking [%s %s].%s(%s)",
169147
javaClassName, ocInstance, method.getName(), new VarArgsUnpacker(args)));
@@ -226,7 +204,7 @@ private Object invokeIsEqual(final ID another) {
226204
return sendOnThisOrMainThread(null, ocInstance, "isEqual:", Boolean.class, another);
227205
}
228206

229-
private Object invokeCocoa(final Method method, Object[] args) {
207+
protected Object invokeCocoa(final Method method, Object[] args) {
230208
String selectorName = selectorNameFor(method);
231209
Class<?> returnType = returnTypeFor(method);
232210
Object[] marshalledArgs = marshallArgsFor(args);
@@ -249,14 +227,14 @@ private Object invokeCocoa(final Method method, Object[] args) {
249227
return result;
250228
}
251229

252-
private void handleInitMethod(Object result) {
230+
private void handleInitMethod(Object result) {
253231
// Normally init methods return self, but on error they may return nil.
254232
// In this case the ObjC object for which this is the handler is considered
255233
// freed and should not be released when we are finalized.
256234
if (result != null) {
257235
return;
258236
}
259-
ocInstance = ID.fromLong(0);
237+
ocInstance = ID.fromLong(0);
260238
}
261239

262240
private Object sendOnThisOrMainThread(Method method, final ID id, final String selectorName, final Class<?> returnType, final Object... args) {
@@ -285,7 +263,7 @@ private void fillInReferences(Object[] args, Object[] marshalledArgs) {
285263
continue;
286264
}
287265
((ObjCObjectByReference) original).setObject(
288-
Rococoa.wrap(((IDByReference) marshalled).getValue(), ObjCObject.class));
266+
Rococoa.wrap(((IDByReference) marshalled).getValue(), ObjCObject.class));
289267
}
290268
}
291269
}
@@ -294,8 +272,7 @@ private Class<?> returnTypeFor(final Method method) {
294272
ReturnType annotation = method.getAnnotation(ReturnType.class);
295273
if (annotation == null) {
296274
return method.getReturnType();
297-
}
298-
else {
275+
} else {
299276
return annotation.value();
300277
}
301278
}
@@ -304,14 +281,13 @@ private Object[] marshallArgsFor(Object[] args) {
304281
if (args == null) {
305282
return null;
306283
}
307-
List<Object> result = new ArrayList<Object>(args.length);
308-
for (int i = 0; i < args.length; i++) {
309-
Object marshalled = marshall(args[i]);
284+
List<Object> result = new ArrayList<>(args.length);
285+
for (Object arg : args) {
286+
final Object marshalled = marshall(arg);
310287
if (marshalled instanceof Object[]) {
311288
// flatten varags, it would never(?) make sense to pass Object[] to Cococoa
312289
result.addAll(Arrays.asList((Object[]) marshalled));
313-
}
314-
else {
290+
} else {
315291
result.add(marshalled);
316292
}
317293
}
@@ -325,14 +301,14 @@ private Object marshall(Object arg) {
325301
return null;
326302
}
327303
if (arg instanceof ObjCObjectByReference) {
328-
// Forward conversion (another backwards conversion will take place in fillInReferences)
304+
// Forward conversion (another backwards conversion will take place in fillInReferences)
329305
IDByReference idref = new IDByReference();
330-
ObjCObject ob = ((ObjCObjectByReference)arg).getValueAs(ObjCObject.class);
331-
if (ob != null) {
332-
idref.setValue(ob.id());
306+
ObjCObject ob = ((ObjCObjectByReference) arg).getValueAs(ObjCObject.class);
307+
if (ob != null) {
308+
idref.setValue(ob.id());
333309
}
334-
return idref;
335-
}
310+
return idref;
311+
}
336312
return arg;
337313
}
338314

@@ -352,7 +328,7 @@ private String selectorNameFor(Method method) {
352328
}
353329
return result.toString();
354330
}
355-
331+
356332
private boolean shouldInvokeMethodsOnMainThread(AnnotatedElement element) {
357333
return element != null && element.getAnnotation(RunOnMainThread.class) != null;
358334
}
@@ -362,6 +338,6 @@ private boolean callAcrossToMainThread() {
362338
}
363339

364340
private boolean callAcrossToMainThreadFor(Method m) {
365-
return (invokeAllMethodsOnMainThread || shouldInvokeMethodsOnMainThread(m) ) && !Foundation.isMainThread() ;
341+
return (invokeAllMethodsOnMainThread || shouldInvokeMethodsOnMainThread(m)) && !Foundation.isMainThread();
366342
}
367343
}

rococoa/rococoa-core/src/main/java/org/rococoa/internal/VarArgsUnpacker.java

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.rococoa.internal;
2121

22-
@SuppressWarnings("nls")
2322
public class VarArgsUnpacker {
2423

2524
private static final String SEPERATOR = ", ";

rococoa/rococoa-core/src/main/native/test.m

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ - (double) testPassStructOfStructByValue: (TestStructOfStruct) s {
6969
return s.aStruct.aDouble;
7070
}
7171

72+
- (NSNumber*) testNumberFromInt: (int) aValue {
73+
NSLog(@"Received number %i", aValue);
74+
NSNumber* number = [NSNumber numberWithInt: aValue];
75+
return number;
76+
}
77+
7278
- (void) testNSNumberByReference: (NSNumber**) fillMeIn with: (int) aValue {
7379
NSNumber* number = [NSNumber numberWithInt: aValue];
7480
*fillMeIn = number;

0 commit comments

Comments
 (0)