Skip to content

Commit

Permalink
Merge pull request #483 from lgoldstein/duplicate-methods
Browse files Browse the repository at this point in the history
Found and fixed duplicate method definitions for the same API
  • Loading branch information
dblock committed Aug 10, 2015
2 parents ab7eea6 + 70288cc commit ec988a2
Show file tree
Hide file tree
Showing 12 changed files with 1,037 additions and 1,025 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Features
* Loosen OSGI OS name matching to accommodate Windows 8 family - Niels Bertram.
* [#436] (https://github.com/twall/jna/pull/469): Added basic Pdh API implementation to 'com.sun.jna.platform.win32' - [@lgoldstein](https://github.com/lgoldstein).
* [#481] (https://github.com/twall/jna/pull/481): Added volume management functions to 'com.sun.jna.platform.win32' - [@lgoldstein](https://github.com/lgoldstein).
* [#483] (https://github.com/twall/jna/pull/483): Found and fixed duplicate method definitions for the same API in 'com.sun.jna.platform.win32' - [@lgoldstein](https://github.com/lgoldstein).

Bug Fixes
---------
Expand Down
584 changes: 235 additions & 349 deletions contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java

Large diffs are not rendered by default.

625 changes: 268 additions & 357 deletions contrib/platform/src/com/sun/jna/platform/win32/User32.java

Large diffs are not rendered by default.

28 changes: 21 additions & 7 deletions contrib/platform/src/com/sun/jna/platform/win32/WinDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.sun.jna.ptr.ByReference;
import com.sun.jna.win32.StdCallLibrary;

// TODO: Auto-generated Javadoc
/**
* Ported from Windef.h (various macros and types). Microsoft Windows SDK 6.0A.
*
Expand Down Expand Up @@ -358,6 +357,18 @@ public HICON() {

}

/**
* Instantiates a new hicon from a handle - this is required since
* in Win32 API HANDLE and HICON are the same, whereas in Java they
* are not, so in order to "cast" the handle we need this
* constructor
*
* @param handle The {@link HANDLE} to cast
*/
public HICON(HANDLE handle) {
this(handle.getPointer());
}

/**
* Instantiates a new hicon.
*
Expand Down Expand Up @@ -743,6 +754,7 @@ public class RECT extends Structure {
*
* @see com.sun.jna.Structure#getFieldOrder()
*/
@Override
protected List getFieldOrder() {
return Arrays.asList(new String[] { "left", "top", "right",
"bottom" });
Expand All @@ -762,6 +774,7 @@ public Rectangle toRectangle() {
*
* @see com.sun.jna.Structure#toString()
*/
@Override
public String toString() {
return "[(" + left + "," + top + ")(" + right + "," + bottom + ")]";
}
Expand Down Expand Up @@ -1062,6 +1075,7 @@ public POINT(int x, int y) {
*
* @see com.sun.jna.Structure#getFieldOrder()
*/
@Override
protected List getFieldOrder() {
return Arrays.asList(new String[] { "x", "y" });
}
Expand Down Expand Up @@ -1513,14 +1527,14 @@ public CHAR getValue() {
* handle to an OpenGL rendering context
*/
public static class HGLRC extends HANDLE {

/**
* Instantiates a new HGLRC .
*/
public HGLRC() {

}

/**
* Instantiates a new HGLRC .
*
Expand All @@ -1531,7 +1545,7 @@ public HGLRC(Pointer p) {
super(p);
}
}

/**
* handle to an OpenGL rendering context
*/
Expand All @@ -1555,6 +1569,6 @@ public HGLRCByReference(HGLRC h) {
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,52 @@
*/
package com.sun.jna.platform.win32;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.sun.jna.platform.AbstractPlatformTestSupport;
import com.sun.jna.platform.win32.WinNT.HANDLE;

/**
* @author lgoldstein
*/
public abstract class AbstractWin32TestSupport extends AbstractPlatformTestSupport {
protected AbstractWin32TestSupport() {
super();
}

/**
* Makes sure that the method names (which represent APIs) do not repeat
* themselves. This check is in order where APIs are WIN32 API <U>functions</U>
* since these are C functions - which means no overloading is possible.
*
* @param ifc The interface (not checked) class to test
* @see #detectDuplicateMethods(Class)
*/
public static final void assertNoDuplicateMethodsNames(Class<?> ifc) {
Collection<String> dupSet = detectDuplicateMethods(ifc);
assertTrue("Duplicate names found in " + ifc.getSimpleName() + ": " + dupSet, dupSet.isEmpty());
}

/**
* Checks if there are methods with the same name - regardless of the signature
*
* @param ifc The interface (not checked) class to test
* @return The {@link Set} of duplicate names - empty if no duplicates
*/
public static final Set<String> detectDuplicateMethods(Class<?> ifc) {
Method[] methods = ifc.getMethods();
Set<String> nameSet = new HashSet<String>(methods.length);
Set<String> dupSet = new HashSet<String>();
for (Method m : methods) {
String name = m.getName();
if (!nameSet.add(name)) {
dupSet.add(name);
}
}

return dupSet;
}

/**
* Checks if the API call result is {@code true}. If not, then calls
* {@link Kernel32#GetLastError()} and fails with the error code.
Expand All @@ -35,15 +70,15 @@ public static final void assertCallSucceeded(String message, boolean result) {
if (result) {
return;
}

int hr = Kernel32.INSTANCE.GetLastError();
if (hr == WinError.ERROR_SUCCESS) {
fail(message + " failed with unknown reason code");
} else {
fail(message + " failed: hr=" + hr + " - 0x" + Integer.toHexString(hr));
}
}

/**
* Checks if the status code is ERROR_SUCCESS
* @param message Message to display if code is an error
Expand All @@ -59,7 +94,7 @@ public static final void assertErrorSuccess(String message, int statusCode, bool
assertEquals(message, WinError.ERROR_SUCCESS, statusCode);
}
}

/**
* Makes sure that the handle argument is not {@code null} or {@link WinBase#INVALID_HANDLE_VALUE}.
* If invalid handle detected, then it invokes {@link Kernel32#GetLastError()}
Expand Down
Loading

0 comments on commit ec988a2

Please sign in to comment.