noAccountUser
noAccountUser

Reputation: 3

Eclipse equivalent of Intellij Dynamic Properties

in our development team we have both Eclipse & Intellij IDEA users, with my team working mainly in Groovy.

We junior developers on this specific team, while working on an IDE with full access to all the relevant classes we need, still copy-paste the scripts into our web-ui, which internally runs them based on the specific rules and settings.

Since the script runner, afaik, injects certain variables into the environment, they are available for use in the scripts but are unavailable for the IDE to autocomplete. In Intellij, we declare them as Dynamic Properties for each script on the IDE level, so that the IntelliSense treats these as objects of the type they are, but I am not able to find an equivalent functionality in Eclipse, nor much information about anyone with a similar situation.

For example, in the following script:

def location = locationService.findLocationById(123)

Where locationService is an object of a type which implements ILocationService. When ran on the server, location is correctly identified as of type Location, but the IDE cannot infer it, of course. In Intellij, I can add a Dynamic Property for locationService, identifying it as of type 'ILocationService'.

Is that even possible on Eclipe?

Thanks!

Upvotes: 0

Views: 212

Answers (1)

emilles
emilles

Reputation: 1179

If you want to add type inference suggestions to the editor so that it can provide content assist for variable expressions, there are a couple possibilities within Eclipse:

  1. Place caret (cursor) over "location" in your script, press Ctrl+1 to open Quick Assist menu and choose Add inferencing suggestion. In the dialog, set Type to the fully-qualified type of the variable. This assist may not be offered unless you have DSLD support enabled in your workspace (Window > Preferences > Groovy > DSLD > Disable DSLD Support in your workspace must be unchecked).

  2. Create a DSLD for your scripts that supplies the type. This is a bit more complicated but is much more flexible in handling delegate types and so forth. See https://github.com/groovy/groovy-eclipse/wiki/DSL-Descriptors (IntelliJ has GDSL which is very similar).

  3. Cast or coerce the variable in your script. May be a little heavy handed, but certainly the easiest to implement.

  4. I think you can provide a BaseScript annotation that could give some additional hints at what will be present in the script's Binding.

Upvotes: 1

Related Questions