Home » Modeling » TMF (Xtext) » Accessing an external Java class from JvmModelInferrer(newTypeRef(EObject, 'com.my.ExternalClass'))
Accessing an external Java class from JvmModelInferrer [message #1059861] |
Wed, 22 May 2013 02:17 |
|
Hi all,
I've finally gotten the chance to write a grammar that extends Xbase. Yay! I've had a blast seeing Java classes created from my DSL, but I've encountered a problem I can't seem to get around.
As is customary, I created a separate bundle, com.joeymink.norm.lib, which has interfaces and classes that I hope to access from my NormJvmModelInferrer. I've added that bundle as a dependency of com.joeymink.norm (my DSL project/plug-in), and I have the following code (shortened for convenience):
class NormJvmModelInferrer extends AbstractModelInferrer {
@Inject extension JvmTypesBuilder
@Inject extension IQualifiedNameProvider
...
def dispatch void infer(NormFile normFile, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
...
if (normFile.normalizations != null) {
for (norm : normFile.normalizations)
inferNorm(acceptor, norm)
...
}
def protected inferNorm(IJvmDeclaredTypeAcceptor acceptor, Normalization norm) {
acceptor.accept(norm.toClass(norm.fullyQualifiedName)).initializeLater [
// Fields:
members += norm.toField("input_", newTypeRef(norm, 'com.joeymink.norm.lib.INormInput'))
members += norm.toField("output_", newTypeRef(norm, 'com.joeymink.norm.lib.INormOutput'))
...
}
...
}
The members += ... lines above create members of type Object instead of type INormInput/INormOutput. I can't seem to figure out why. When I debug it the newTypeRef calls return null. I don't fully understand the type provider API being used, but I see that the JdtTypeProvider is unable to find the type, com.joeymink.norm.lib.INormInput.
I wonder if there's a fundamental step or configuration I'm missing to make these externally-defined Java classes accessible to my DSL (JvmModelInferrer). Any thoughts?
|
|
|
Re: Accessing an external Java class from JvmModelInferrer [message #1059869 is a reply to message #1059861] |
Wed, 22 May 2013 03:40 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Joey,
Is the library for these classes in the dependencies of the project that
contains the instance of the DSL resource?
On 22/05/2013 4:17 AM, Joey Mink wrote:
> Hi all,
>
> I've finally gotten the chance to write a grammar that extends Xbase.
> Yay! I've had a blast seeing Java classes created from my DSL, but
> I've encountered a problem I can't seem to get around.
>
> As is customary, I created a separate bundle, com.joeymink.norm.lib,
> which has interfaces and classes that I hope to access from my
> NormJvmModelInferrer. I've added that bundle as a dependency of
> com.joeymink.norm (my DSL project/plug-in), and I have the following
> code (shortened for convenience):
>
>
> class NormJvmModelInferrer extends AbstractModelInferrer {
> @Inject extension JvmTypesBuilder
> @Inject extension IQualifiedNameProvider
> ..
> def dispatch void infer(NormFile normFile,
> IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
> ..
> if (normFile.normalizations != null) {
> for (norm : normFile.normalizations)
> inferNorm(acceptor, norm)
> ..
> }
>
> def protected inferNorm(IJvmDeclaredTypeAcceptor acceptor,
> Normalization norm) {
> acceptor.accept(norm.toClass(norm.fullyQualifiedName)).initializeLater [
> // Fields:
> members += norm.toField("input_", newTypeRef(norm,
> 'com.joeymink.norm.lib.INormInput'))
> members += norm.toField("output_", newTypeRef(norm,
> 'com.joeymink.norm.lib.INormOutput'))
> ..
> }
> ..
> }
>
> The members += ... lines above create members of type Object instead
> of type INormInput/INormOutput. I can't seem to figure out why. When I
> debug it the newTypeRef calls return null. I don't fully understand
> the type provider API being used, but I see that the JdtTypeProvider
> is unable to find the type, com.joeymink.norm.lib.INormInput.
>
> I wonder if there's a fundamental step or configuration I'm missing to
> make these externally-defined Java classes accessible to my DSL
> (JvmModelInferrer). Any thoughts?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Accessing an external Java class from JvmModelInferrer [message #1059949 is a reply to message #1059869] |
Wed, 22 May 2013 10:22 |
|
Ed - thanks for the reply!
No, the library (com.joeymink.norm.lib) is not a dependency of the project containing the instance of my DSL resource. The library exists as a plug-in in the Eclipse instance at that point, and the project containing my DSL resource is a Java project (with the Xtext nature).
Is it necessary to setup this dependency? I'm not sure I know how to set such a dependency explicitly...
Any additional details are appreciated
|
|
| | |
Goto Forum:
Current Time: Thu Apr 25 19:07:21 GMT 2024
Powered by FUDForum. Page generated in 0.02942 seconds
|