You can import nearly any java class or liabry into eol. This can be used any any eol block with EVL,ETL,EGL etc. This can also be used to import standard libaries (more info here)
Setup
Please go to Epsilon Playground. and click download and select Java Maven option. Open this zipped file and create a Java class named ExampleClass within org.eclipse.epsilon.examples folder.
This is the corrisponing function that should be added to the java class.
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class ExampleClass {
public static boolean writeThisToAJavaFile(String input) {
String filePath = "OutputTaskNames.txt"
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true))) {
writer.write(input);
writer.newLine();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}
Then open the program.eo file and add the following to the file
program.eol
//path to an instance java class
var exampleClass = new Native("org.eclipse.epsilon.examples.ExampleClass");
//this will append each of the task titles to a file called All titles
for (task in Task.all){
exampleClass.writeThisToAJavaFile(task.title);
}
Your full program.eol should now look like this
// For every task in the model
var exampleClass = new Native("org.eclipse.epsilon.examples.ExampleClass");
//this will append each of the task titles to a file called All titles
for (task in Task.all){
task.title.println();
exampleClass.writeThisToAJavaFile(task.title);
}
for (t in Task.all) {
// Print the title and the total person-months of the task
(t.title + ": " + t.getTotalEffort()).println();
}
// Count the tasks that are undertaken by a single person
Task.all.select(t|t.effort.size() = 1).size().
println("One-person tasks: ");
// Returns the total person-months for a task
operation Task getTotalEffort() {
return self.effort.
collect(e|self.duration*e.percentage/100.0).sum();
}
Run
Then you should be able to run and the file will be appened with the task names.
mvn compile exec:java
Using static methods
This can be done in a simlar way by defining the methods as static in java and then change the Naive type to this:
//path to an instance java class
var exampleClass = Native("org.eclipse.epsilon.examples.ExampleClass");