”Proxy by Name”, a new feature in JNBridgePro 7.3

We’ve added a new feature to JNBridgePro 7.3 that we’re calling “proxy by name”. Proxy by name automatically maps the names of methods and constructor parameters from the underlying Java or .NET code into the generated proxies. It’s been in the top-requested-feature list for some time now, but until recently the .NET and Java APIs that were available haven’t been good enough for us to do a good job on this feature. We’re happy to now be able to make it available.

Proxying parameter names is powerful because it means that the native parameter names will appear in tool tips and IntelliSense in Visual Studio, Eclipse, and other IDEs, rather than a meaningless alias. This helps document the APIs, and presents the information right where it’s used: in the code editor. Previously, the tool tip and IntelliSense pop-ups contained placeholder names like p1, p2, etc., which provided no documentation value.

How it works: Java calling .NET

Here’s how “proxy by name” works. Let’s start in the Java-to-.NET direction. Assume we have a C# class:

public class DotNetClass
{
     public DotNetClass(string myStringParam, int myIntParam, string my2ndStringParam)
     {
     }

     public static void myMethod(float thisIsAFloatParam, long thisIsALongParam)
     {
     }
}

Let’s proxy this in the usual way, then start creating a Java project that uses the proxy jar file.

Note that the code completion pop-ups now show parameter names in the proxied methods and constructors. This wasn’t available in 7.2.

proxyByName1

proxyByName2

proxyByName3

proxyByName4

After the code is entered, the parameter names in the proxies are still available by hovering the cursor over the method name:

proxyByName5

How it works: .NET calling Java

What about .NET-to-Java? Here, things are a little different. Let’s start with Java class similar to the .NET class we’ve been using:

public class JavaClass
{
     public JavaClass(String myStringParam, int myIntParam, String my2ndStringParam)
     {
     }

     public static void myMethod(float thisIsAFloatParam, long thisIsALongParam)
     {
     }
}

You’ll need to compile your code using Java 8 or later, and to target Java 8 binaries. You’ll also need to make sure that you’ve told the compiler to save the parameter metadata. If you’re using Eclipse, for example, your project should have these compilation settings:

proxyByName6

Alternatively, if you’re using the command line, use the -parameters option:

javac -cp classpath_here -parameters classes_to_compile

Again, generate the proxies the usual way, and reference them in a Visual Studio project.

When you enter the names of methods and constructors, or hover the mouse over completed code, IntelliSense and tool tips work just as expected, and include the names of the proxied parameters:

proxyByName7

proxyByName8

proxyByName9

proxyByName10

proxyByName11

We think you’ll find this new feature useful, and expect it’ll help speed up your development efforts. Let us know what you think!