I have to implement a Macro which replaces the implementation of a class by a class of another implementation, if a library does not exist. The reason is that users might not be willing to install a complex library (say the name is complex.jar). It is very important that the code compiles even if the library is not present.
Practical Example: Think of e.g. a tool for computing complex mathematical functions. Let us assume that we now want to add the functionality of plotting the result. For this we use Matlab (I know there are others, this is just an example). Let us assume that Matlab has a jar file. Since not all users have Matlab installed, I want that my code compiles also without this jar although it uses Methods from this jar.
Example:
@ReplaceMeIfLibDoesNotExist("complex","DefaultConnector.scala")
class ComplexConnector{
import complex._;
def connect(){
complex = new ComplexLibrary(); // part of complex.jar
}
}
class DefaultConnector{
def connect(){
println("Currently not supported. Install complex.jar")
}
}
Would something like that work? How would the Macro implementation look like? Or is there some more elegant way of doing things like that? It would be nice to have a concrete code example.
Thank you very much in advance.