Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 Go to previous messageGo to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

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 Smile
Re: Accessing an external Java class from JvmModelInferrer [message #1059976 is a reply to message #1059949] Wed, 22 May 2013 12:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Joey,

Comments below.
On 22/05/2013 12:22 PM, Joey Mink wrote:
> 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.
I needs to be on the classpath and how you do that depends on if it's a
PDE project (that's easier to manage via dependencies in the
MANIFEST.MF) or a plain old Java project (that involves setting up all
the build path's library which is more work).
> 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?
Yes for the classes to be visible in the project and hence visible to
the model you're inferring.
> I'm not sure I know how to set such a dependency explicitly...
If you can make it a PDE project you can edit the MANIFEST.MF
>
> Any additional details are appreciated :)


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Accessing an external Java class from JvmModelInferrer [message #1059985 is a reply to message #1059976] Wed, 22 May 2013 12:52 Go to previous message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Ed,

Thanks a ton! My DSL resource is now in a Plug-in Project with a dependency on com.joeymink.norm.lib. My types are found!
Previous Topic:Integration of GMF and Xtext -> Problem with ResourceDescription
Next Topic:Applying (uml) stereotypes?
Goto Forum:
  


Current Time: Thu Apr 25 19:07:21 GMT 2024

Powered by FUDForum. Page generated in 0.02942 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top