Skip to content

Commit 4eb408f

Browse files
committed
Merge remote-tracking branch 'refs/remotes/java-native-access/master'
2 parents c1a171d + 2ba0d30 commit 4eb408f

File tree

73 files changed

+2172
-2010
lines changed

Some content is hidden

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

73 files changed

+2172
-2010
lines changed

CHANGES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Features
3030
* [#563](https://github.com/java-native-access/jna/pull/563): Added `com.sun.jna.platform.win32.Wininet` with the following 4 methods: `FindFirstUrlCacheEntry`, `DeleteUrlCacheEntry`, `FindCloseUrlCache`, `FindNextUrlCacheEntry`, and the `INTERNET_CACHE_ENTRY_INFO` structure, and a helper in `com.sun.jna.platform.win32.WininetUtil` for parsing WinInet's cache - [@mlfreeman2](https://github.com/mlfreeman2).
3131
* [#567](https://github.com/java-native-access/jna/pull/567): Added `PrintWindow`, `IsWindowEnabled`, `IsWindow`, `FindWindowEx`, `GetAncestor`, `GetCursorPos`, `SetCursorPos`, `SetWinEventHook`, `UnhookWinEvent`, `CopyIcon`, and `GetClassLong` to `com.sun.jna.platform.win32.User32` and supporting constants to `com.sun.jna.platform.win32.WinUser` - [@mlfreeman2](https://github.com/mlfreeman2).
3232
* [#573](https://github.com/java-native-access/jna/pull/573): Added `EnumProcessModules`, `GetModuleInformation`, and `GetProcessImageFileName` to `com.sun.jna.platform.win32.Psapi` and added `ExtractIconEx` to `com.sun.jna.platform.win32.Shell32` - [@mlfreeman2](https://github.com/mlfreeman2).
33-
* [#574](https://github.com/java-native-access/jna/pull/574): Using static final un-modifiable List of field names for structure(s) [@lgoldstein](https://github.com/lgoldstein).
33+
* [#574](https://github.com/java-native-access/jna/pull/574): Using static final un-modifiable List of field names for structure(s) - [@lgoldstein](https://github.com/lgoldstein).
34+
* [#577](https://github.com/java-native-access/jna/pull/577): Apply generic definitions wherever applicable - [@lgoldstein](https://github.com/lgoldstein).
3435
* [#569](https://github.com/java-native-access/jna/pull/569): Added `com.sun.jna.platform.win32.Winspool.PRINTER_INFO_2` support. Added GetPrinter and ClosePrinter functions in `com.sun.jna.platform.win32.Winspool` - [@IvanRF](https://github.com/IvanRF).
3536

3637
Bug Fixes

contrib/platform/src/com/sun/jna/platform/FileMonitor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void addWatch(File dir, int mask) throws IOException {
7979
}
8080

8181
public void addWatch(File dir, int mask, boolean recursive) throws IOException {
82-
watched.put(dir, new Integer(mask));
82+
watched.put(dir, Integer.valueOf(mask));
8383
watch(dir, mask, recursive);
8484
}
8585

contrib/platform/src/com/sun/jna/platform/WindowUtils.java

+103-57
Large diffs are not rendered by default.

contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ public static String getUserName() {
131131

132132
if (!result) {
133133
switch (Kernel32.INSTANCE.GetLastError()) {
134-
case W32Errors.ERROR_INSUFFICIENT_BUFFER:
135-
buffer = new char[len.getValue()];
136-
break;
134+
case W32Errors.ERROR_INSUFFICIENT_BUFFER:
135+
buffer = new char[len.getValue()];
136+
break;
137137

138-
default:
139-
throw new Win32Exception(Native.getLastError());
138+
default:
139+
throw new Win32Exception(Native.getLastError());
140140
}
141141

142142
result = Advapi32.INSTANCE.GetUserNameW(buffer, len);
@@ -975,9 +975,9 @@ public static Object registryGetValue(HKEY hkKey, String subKey,
975975
byteData.write(0, lpData, 0, lpcbData.getValue());
976976

977977
if (lpType.getValue() == WinNT.REG_DWORD) {
978-
result = new Integer(byteData.getInt(0));
978+
result = Integer.valueOf(byteData.getInt(0));
979979
} else if (lpType.getValue() == WinNT.REG_QWORD) {
980-
result = new Long(byteData.getLong(0));
980+
result = Long.valueOf(byteData.getLong(0));
981981
} else if (lpType.getValue() == WinNT.REG_BINARY) {
982982
result = byteData.getByteArray(0, lpcbData.getValue());
983983
} else if ((lpType.getValue() == WinNT.REG_SZ)

contrib/platform/src/com/sun/jna/platform/win32/COM/tlb/imp/TlbCmdlineArgs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public TlbCmdlineArgs(String[] args) {
2323

2424
public int getIntParam(String key) {
2525
String param = this.getRequiredParam(key);
26-
return new Integer(param).intValue();
26+
return Integer.parseInt(param);
2727
}
2828

2929
public String getParam(String key) {

contrib/platform/src/com/sun/jna/platform/win32/COM/tlb/imp/TlbFunctionVTable.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
// TODO: Auto-generated Javadoc
2121
/**
2222
* The Class TlbFunction.
23-
*
23+
*
2424
* @author Tobias Wolf, wolf.tobias@gmx.net
2525
*/
2626
public class TlbFunctionVTable extends TlbAbstractMethod {
2727

2828
/**
2929
* Instantiates a new tlb function.
30-
*
30+
*
3131
* @param index
3232
* the index
3333
* @param typeLibUtil
@@ -71,11 +71,6 @@ public TlbFunctionVTable(int count, int index, TypeLibUtil typeLibUtil,
7171
this.replaceVariable("functionCount", String.valueOf(count));
7272
}
7373

74-
/*
75-
* (non-Javadoc)
76-
*
77-
* @see com.sun.jna.platform.win32.COM.tlb.imp.TlbBase#getClassTemplate()
78-
*/
7974
@Override
8075
protected String getClassTemplate() {
8176
return "com/sun/jna/platform/win32/COM/tlb/imp/TlbFunctionVTable.template";

contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java

+17-16
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public ProxyObject(Class<?> theInterface, IDispatch rawDispatch, Factory factory
7474
factory.register(this);
7575
}
7676

77-
/** when proxy is created for arguments on a call back, they are already on the
77+
/** when proxy is created for arguments on a call back, they are already on the
7878
* com thread, and hence calling 'getUnknownId' will not work as it uses the ComThread
7979
* however, the unknown pointer value is passed in;
80-
*
80+
*
8181
* @param theInterface
8282
* @param unknownId
8383
* @param rawDispatch
@@ -94,7 +94,7 @@ public ProxyObject(Class<?> theInterface, IDispatch rawDispatch, Factory factory
9494
int n = this.rawDispatch.AddRef();
9595
factory.register(this);
9696
}
97-
97+
9898
// cached value of the IUnknown interface pointer
9999
// Rules of COM state that querying for the IUnknown interface must return
100100
// an identical pointer value
@@ -108,15 +108,15 @@ long getUnknownId() {
108108

109109
Thread current = Thread.currentThread();
110110
String tn = current.getName();
111-
111+
112112
HRESULT hr = this.comThread.execute(new Callable<HRESULT>() {
113113
@Override
114114
public HRESULT call() throws Exception {
115115
IID iid = com.sun.jna.platform.win32.COM.IUnknown.IID_IUNKNOWN;
116116
return ProxyObject.this.getRawDispatch().QueryInterface(new REFIID(iid), ppvObject);
117117
}
118118
});
119-
119+
120120
if (WinNT.S_OK.equals(hr)) {
121121
Dispatch dispatch = new Dispatch(ppvObject.getValue());
122122
this.unknownId = Pointer.nativeValue(dispatch.getPointer());
@@ -159,7 +159,8 @@ public void dispose(int r) {
159159
ComThread comThread;
160160
com.sun.jna.platform.win32.COM.IDispatch rawDispatch;
161161

162-
public com.sun.jna.platform.win32.COM.IDispatch getRawDispatch() {
162+
@Override
163+
public com.sun.jna.platform.win32.COM.IDispatch getRawDispatch() {
163164
return this.rawDispatch;
164165
}
165166

@@ -168,12 +169,13 @@ public com.sun.jna.platform.win32.COM.IDispatch getRawDispatch() {
168169
/*
169170
* The QueryInterface rule state that 'a call to QueryInterface with
170171
* IID_IUnknown must always return the same physical pointer value.'
171-
*
172+
*
172173
* [http://msdn.microsoft.com/en-us/library/ms686590%28VS.85%29.aspx]
173-
*
174+
*
174175
* therefore we can compare the pointers
175176
*/
176-
public boolean equals(Object arg) {
177+
@Override
178+
public boolean equals(Object arg) {
177179
if (null == arg) {
178180
return false;
179181
} else if (arg instanceof ProxyObject) {
@@ -200,9 +202,8 @@ public boolean equals(Object arg) {
200202

201203
@Override
202204
public int hashCode() {
203-
return Long.valueOf(this.getUnknownId()).intValue();
204-
// this returns the native pointer peer value
205-
// return this.getRawDispatch().hashCode();
205+
long id = this.getUnknownId();
206+
return (int) ((id >>> 32) & 0xFFFFFFFF) + (int) (id & 0xFFFFFFFF);
206207
}
207208

208209
@Override
@@ -379,7 +380,7 @@ public <T> T getProperty(Class<T> returnType, String name, Object... args) {
379380
COMUtils.checkRC(hr);
380381
Object jobj = Convert.toJavaObject(result);
381382
if (IComEnum.class.isAssignableFrom(returnType)) {
382-
return (T) Convert.toComEnum((Class<? extends IComEnum>) returnType, jobj);
383+
return returnType.cast(Convert.toComEnum((Class<? extends IComEnum>) returnType, jobj));
383384
}
384385
if (jobj instanceof IDispatch) {
385386
IDispatch d = (IDispatch) jobj;
@@ -389,7 +390,7 @@ public <T> T getProperty(Class<T> returnType, String name, Object... args) {
389390
int n = d.Release();
390391
return t;
391392
}
392-
return (T) jobj;
393+
return returnType.cast(jobj);
393394
}
394395

395396
@Override
@@ -409,7 +410,7 @@ public <T> T invokeMethod(Class<T> returnType, String name, Object... args) {
409410

410411
Object jobj = Convert.toJavaObject(result);
411412
if (IComEnum.class.isAssignableFrom(returnType)) {
412-
return (T) Convert.toComEnum((Class<? extends IComEnum>) returnType, jobj);
413+
return returnType.cast(Convert.toComEnum((Class<? extends IComEnum>) returnType, jobj));
413414
}
414415
if (jobj instanceof IDispatch) {
415416
IDispatch d = (IDispatch) jobj;
@@ -419,7 +420,7 @@ public <T> T invokeMethod(Class<T> returnType, String name, Object... args) {
419420
int n = d.Release();
420421
return t;
421422
}
422-
return (T) jobj;
423+
return returnType.cast(jobj);
423424
}
424425

425426
@Override

contrib/platform/src/com/sun/jna/platform/win32/WinDef.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public class LONGByReference extends ByReference {
237237
* Instantiates a new LONG by reference.
238238
*/
239239
public LONGByReference() {
240-
this(new LONG(0));
240+
this(new LONG(0L));
241241
}
242242

243243
/**

0 commit comments

Comments
 (0)