Using the Foreign Language Interface with Eclipse

This guide describes how to set up an ABS project and a Java project. The Java project contains implementations which override the functionality of ABS classes.

Setting up the ABS project

  1. Create a new ABS project.
  2. Add some code using the Foreign annotation. (See example below.)
  3. Generate the Java sources by clicking the "Generate Java Code" Button.

Example

module Test;
import * from ABS.FLI;

interface Hello {
   String hello(String msg);
}

[Foreign]
class HelloImpl implements Hello {
   String hello(String msg) { 
      return "this is the default implementation, no foreign language was bound at runtime";
   }
}

{
   Hello h = new HelloImpl();
   h.hello("Hi there");
}

Setting up the Java project

  1. Create a new Java project.
  2. Add the ABS runtime library to the build path
    • Convert the Java project to a plugin project by right-clicking on the project and choosing "Configure -> Convert to plugin project".
    • Eclipse will create a MANIFEST.MF file stored in a folder named META-INF. Open this file and go to the "dependencies" tab.
    • Under "Required Plug-ins" you have to add "eu.hatsproject.abs.compiler".
  3. Add the ABS project to the build path
    • Open the project properties for the Java project.
    • Open the "Java Build Path" properties and go to the "Libraries Path" tab.
    • Click on "Add Class Folder..." and add the generated Java sources from the ABS project. By default this is project/gen/java/
  4. Create a Java class which extends your ABS class. (See example below.)
    • The package name has to be equal to the module name in ABS.
    • The extended class has the name of the ABS class with "_c" added to the end.
    • The name of the new class has to match the name of the ABS class with "_impl" added to the end.
    • Methods start with "fli_" followed by the name of the ABS method.
    • Use the print methods defined in the FLIHelper class to print messages to the console. System.out.println will not be visible when the program is started from Eclipse.
  5. If everything was set up correctly eclipse should not show any compiler errors.

Example

package Test;

// included in the ABS runtime
import abs.backend.java.lib.types.ABSString;
import abs.backend.java.lib.runtime.FLIHelper;

// generated by the ABS Java backend
import Test.HelloImpl_c; 

public class HelloImpl_fli extends HelloImpl_c {
   
   @Override
   public ABSString fli_hello(ABSString msg) {
      FLIHelper.println("I got "+msg.getString()+" from ABS");
      return ABSString.fromString("Hello ABS, this is Java");
   }
}

Run Configuration

  1. Create a new ABS run configuration. Select the correct project, product and run-target.
  2. Go to the "FLI classpath" tab.
  3. Add the Java project to the classpath by choosing "Add Projects ...".
  4. Save the run configuration and run it.

Using a properties file

If you do not want to map the Java classes to the ABS classes by using the naming conventions listed above you can use a properties file to declare the mapping. The file has to be named "absfli.properties" and must be located in the classpath. So in step 3 of the run configuration section you also have to add the folder containing your "absfli.properties" file (Use Advanced... Add folders).

A properties file for our small example is shown below. It assumes that there is a Java class named "Hello" in package "Abc".

Test.HelloImpl=Abc.Hello