clamp API

clamp.method(return_type, arg_types=[], name=None)[source]

Decorate a clamp method with Java type information

Parameters:
  • return_type (java.lang.reflect.Type) – method return type
  • arg_types (array of java.lang.reflect.Type) – argument types that the method accepts
  • name (str) – alternative method name. You can use this to support polymorphism.

Examples...

Simple method with Void.TYPE as the return type:

public void returnsVoid()
@clamp.method(Void.TYPE)
def returnsVoid(self):
    pass

This polymorphism example will generate a Java method with the following signature:

public int add(int a, int b)
public long add(long a, long b)
@clamp.method(int.TYPE, [int.TYPE, int.TYPE])
def add(self, a, b):
    return a + b
    
# we override the method name to "add", which will indicate that we want
# create a method with the same name
@clamp.method(long.TYPE, [long.TYPE, long.TYPE], name="add")
def addLong(self, a, b):
    return a_long + b_long
clamp.throws(*exceptions)[source]

Declare what Java exceptions this method throws

Parameters:exceptions (a list of java.lang.Throwable) – accepts a list of exceptions as arguments

Example:

public void writeList() throws IOException, NoSuchFieldException
@clamp.throws(IOException, NoSuchFieldException)
@clamp.method(Void.TYPE)
def writeList(self):
    raise IOException("message")
    raise NoSuchFieldException("other message")
clamp.annotated(annotation, **kwargs)[source]

Annotate the Java version of the method with Java annotation

Parameters:
  • annotation (java.lang.annotation.Annotation) – Java annotation
  • kwargs (java.lang.Object) – keword arguments to pass to the annotation

Example annotation:

@junit.Test
public void test()
@clamp.annotated(Test)
@clamp.method(Void.TYPE)
def test(self):
    pass