Matt Roper
Matt Roper

Reputation: 111

Specify supertype of JvmTypeReference in Xtext grammar

Is it possible to specify a required type (e.g. interface) for a JvmTypeReference in an Xtext grammar?

Example

Instantiation:
    ('new' type=JvmTypeReference (params=Params)?)
;

Where type=JvmTypeReference must be an instanceof some specified class.

Upvotes: 2

Views: 190

Answers (2)

Joko
Joko

Reputation: 590

You could implement a reference to a JvmConstructor!

Instantiation:
    'new' type=[JvmConstructor|QualifiedName] params=Params?;

You should use an XimportSection in your grammar then you can write a scope provider where you can scope directly to any constructor.

Upvotes: 0

Franz Becker
Franz Becker

Reputation: 705

No this is not possible in the grammar, but you can achieve the desired behavior by means of a customized scope provider or a proposal provider, see this blog post: https://kthoms.wordpress.com/2012/03/14/how-to-limit-proposed-java-types-to-implementors-of-an-interface/

Upvotes: 1

Related Questions