Skip to content

Commit

Permalink
Merge pull request #577 from lgoldstein/apply-generics
Browse files Browse the repository at this point in the history
Apply generic definitions wherever applicable
  • Loading branch information
twall committed Jan 15, 2016
2 parents 3e67635 + 81908ed commit 2ba0d30
Show file tree
Hide file tree
Showing 73 changed files with 2,171 additions and 2,009 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Features
* [#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).
* [#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).
* [#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)
* [#577](https://github.com/java-native-access/jna/pull/577): Apply generic definitions wherever applicable [@lgoldstein](https://github.com/lgoldstein)

Bug Fixes
---------
Expand Down
2 changes: 1 addition & 1 deletion contrib/platform/src/com/sun/jna/platform/FileMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void addWatch(File dir, int mask) throws IOException {
}

public void addWatch(File dir, int mask, boolean recursive) throws IOException {
watched.put(dir, new Integer(mask));
watched.put(dir, Integer.valueOf(mask));
watch(dir, mask, recursive);
}

Expand Down
160 changes: 103 additions & 57 deletions contrib/platform/src/com/sun/jna/platform/WindowUtils.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ public static String getUserName() {

if (!result) {
switch (Kernel32.INSTANCE.GetLastError()) {
case W32Errors.ERROR_INSUFFICIENT_BUFFER:
buffer = new char[len.getValue()];
break;
case W32Errors.ERROR_INSUFFICIENT_BUFFER:
buffer = new char[len.getValue()];
break;

default:
throw new Win32Exception(Native.getLastError());
default:
throw new Win32Exception(Native.getLastError());
}

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

if (lpType.getValue() == WinNT.REG_DWORD) {
result = new Integer(byteData.getInt(0));
result = Integer.valueOf(byteData.getInt(0));
} else if (lpType.getValue() == WinNT.REG_QWORD) {
result = new Long(byteData.getLong(0));
result = Long.valueOf(byteData.getLong(0));
} else if (lpType.getValue() == WinNT.REG_BINARY) {
result = byteData.getByteArray(0, lpcbData.getValue());
} else if ((lpType.getValue() == WinNT.REG_SZ)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TlbCmdlineArgs(String[] args) {

public int getIntParam(String key) {
String param = this.getRequiredParam(key);
return new Integer(param).intValue();
return Integer.parseInt(param);
}

public String getParam(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
// TODO: Auto-generated Javadoc
/**
* The Class TlbFunction.
*
*
* @author Tobias Wolf, wolf.tobias@gmx.net
*/
public class TlbFunctionVTable extends TlbAbstractMethod {

/**
* Instantiates a new tlb function.
*
*
* @param index
* the index
* @param typeLibUtil
Expand Down Expand Up @@ -71,11 +71,6 @@ public TlbFunctionVTable(int count, int index, TypeLibUtil typeLibUtil,
this.replaceVariable("functionCount", String.valueOf(count));
}

/*
* (non-Javadoc)
*
* @see com.sun.jna.platform.win32.COM.tlb.imp.TlbBase#getClassTemplate()
*/
@Override
protected String getClassTemplate() {
return "com/sun/jna/platform/win32/COM/tlb/imp/TlbFunctionVTable.template";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public ProxyObject(Class<?> theInterface, IDispatch rawDispatch, Factory factory
factory.register(this);
}

/** when proxy is created for arguments on a call back, they are already on the
/** when proxy is created for arguments on a call back, they are already on the
* com thread, and hence calling 'getUnknownId' will not work as it uses the ComThread
* however, the unknown pointer value is passed in;
*
*
* @param theInterface
* @param unknownId
* @param rawDispatch
Expand All @@ -94,7 +94,7 @@ public ProxyObject(Class<?> theInterface, IDispatch rawDispatch, Factory factory
int n = this.rawDispatch.AddRef();
factory.register(this);
}

// cached value of the IUnknown interface pointer
// Rules of COM state that querying for the IUnknown interface must return
// an identical pointer value
Expand All @@ -108,15 +108,15 @@ long getUnknownId() {

Thread current = Thread.currentThread();
String tn = current.getName();

HRESULT hr = this.comThread.execute(new Callable<HRESULT>() {
@Override
public HRESULT call() throws Exception {
IID iid = com.sun.jna.platform.win32.COM.IUnknown.IID_IUNKNOWN;
return ProxyObject.this.getRawDispatch().QueryInterface(new REFIID(iid), ppvObject);
}
});

if (WinNT.S_OK.equals(hr)) {
Dispatch dispatch = new Dispatch(ppvObject.getValue());
this.unknownId = Pointer.nativeValue(dispatch.getPointer());
Expand Down Expand Up @@ -159,7 +159,8 @@ public void dispose(int r) {
ComThread comThread;
com.sun.jna.platform.win32.COM.IDispatch rawDispatch;

public com.sun.jna.platform.win32.COM.IDispatch getRawDispatch() {
@Override
public com.sun.jna.platform.win32.COM.IDispatch getRawDispatch() {
return this.rawDispatch;
}

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

@Override
public int hashCode() {
return Long.valueOf(this.getUnknownId()).intValue();
// this returns the native pointer peer value
// return this.getRawDispatch().hashCode();
long id = this.getUnknownId();
return (int) ((id >>> 32) & 0xFFFFFFFF) + (int) (id & 0xFFFFFFFF);
}

@Override
Expand Down Expand Up @@ -379,7 +380,7 @@ public <T> T getProperty(Class<T> returnType, String name, Object... args) {
COMUtils.checkRC(hr);
Object jobj = Convert.toJavaObject(result);
if (IComEnum.class.isAssignableFrom(returnType)) {
return (T) Convert.toComEnum((Class<? extends IComEnum>) returnType, jobj);
return returnType.cast(Convert.toComEnum((Class<? extends IComEnum>) returnType, jobj));
}
if (jobj instanceof IDispatch) {
IDispatch d = (IDispatch) jobj;
Expand All @@ -389,7 +390,7 @@ public <T> T getProperty(Class<T> returnType, String name, Object... args) {
int n = d.Release();
return t;
}
return (T) jobj;
return returnType.cast(jobj);
}

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

Object jobj = Convert.toJavaObject(result);
if (IComEnum.class.isAssignableFrom(returnType)) {
return (T) Convert.toComEnum((Class<? extends IComEnum>) returnType, jobj);
return returnType.cast(Convert.toComEnum((Class<? extends IComEnum>) returnType, jobj));
}
if (jobj instanceof IDispatch) {
IDispatch d = (IDispatch) jobj;
Expand All @@ -419,7 +420,7 @@ public <T> T invokeMethod(Class<T> returnType, String name, Object... args) {
int n = d.Release();
return t;
}
return (T) jobj;
return returnType.cast(jobj);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public class LONGByReference extends ByReference {
* Instantiates a new LONG by reference.
*/
public LONGByReference() {
this(new LONG(0));
this(new LONG(0L));
}

/**
Expand Down
Loading

0 comments on commit 2ba0d30

Please sign in to comment.