TelluIoT / ThingML

The ThingML modelling language
https://github.com/TelluIoT/ThingML
Apache License 2.0
101 stars 32 forks source link

Java generator ignores annotations on included Things #268

Closed ffleurey closed 5 years ago

ffleurey commented 5 years ago

When including things, the annotations such as @maven_dep, @java_import and @java_features are discarded. They should be included since it allows to nicely package function libraries.

brice-morin commented 5 years ago

Indeed :-)

brice-morin commented 5 years ago

looks at least like @maven_dep should not be problematic. Looking at the others now

brice-morin commented 5 years ago

Actually, we should add this information in the annotation registry, whether or not a given annotation should be inherited (as I remember some discussions when in some cases, we did not want annotations to be inherited)

ffleurey commented 5 years ago

I am not sure there are any left which we do not want to inherit. I think it was when we had fragments on the configurations that we had that pb... We should think about it.

ffleurey commented 5 years ago

It does not seems to be solved. Here is a test:

thing fragment ToInclude 
@maven_dep `        
    <dependency>
        <groupId>org.influxdb</groupId>
        <artifactId>influxdb-java</artifactId>
        <version>2.14</version>
    </dependency>`

@java_import `import org.influxdb.*;`
@java_import `import org.influxdb.dto.*;`
@java_import `import java.util.concurrent.TimeUnit;`
@java_import `import java.util.logging.Level;`
@java_import `import java.util.logging.Logger;`

@java_features `protected InfluxDB _influxDB = null;`

{

    function initdb() do
        println "Initilize the db"
    end

}

thing TestJavaInclude includes ToInclude 
{

    function doSomething() do
        if (`_influxDB == null`) initdb()

        `Point p = Point.measurement("gw_events")
            .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
            .tag("host", "localhost")
            .addField("event", 1)
            .build();`

        println "do Something using the java library"

    end

    statechart init Init {

        on entry doSomething()

        state Init {}
    }

}

configuration TestJavaInclude {
    instance m : TestJavaInclude
}
brice-morin commented 5 years ago

OK, seems like it works for @java_import and @java_features, but not for @maven_dep, unlike what I thought originally... Will fix that.

Note that you can probably group your @java_import into one annotation, but anyway