Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Load classes in user project
Load classes in user project [message #638032] Tue, 09 November 2010 17:01 Go to next message
Fernando Gonz is currently offline Fernando Gonz
Messages: 13
Registered: October 2010
Junior Member
Hi all,

I have this rule to let the user 'refer' to interface methods:

JavaMethodMap:
"maps to" javaClass=[types::JvmType|QualifiedName] '::'
javaMethod=[types::JvmOperation] ";";


I got scoping and linking working after a while but I got stuck in validation. I want to give validation errors if the referred jvmtype is anything other than an interface, so I wrote this code:

JvmType javaClass = javaMethodMap.getJavaClass();
Class<?> clazz = Class.forName(javaClass.getCanonicalName());
if (!clazz.isInterface()) {
...

The problem is that with that code I cannot load the classes that the user creates because "Class.forName" uses the classpath of the plugin, not the one of the project the user is working on.

I would appreciate any help.

Best regards.
Fernando.
Re: Load classes in user project [message #638148 is a reply to message #638032] Wed, 10 November 2010 08:20 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1156
Registered: July 2009
Senior Member
Hi,

you don't need to load the actual class for that check (this information is stored within the JvmType-system). There may be a better way to do it, but the following might work for you.

Test whether your javaClass is an instance of JvmGenericType. If it is, you can make use of its isInterface method.

Alex
Re: Load classes in user project [message #638243 is a reply to message #638148] Wed, 10 November 2010 15:55 Go to previous message
Fernando Gonz is currently offline Fernando Gonz
Messages: 13
Registered: October 2010
Junior Member
I didn't look any deeper in the JvmType hierarchy, but now I've found not only the method isInterface, but also access to all the interface methods, their parameters, etc.

Thank you very much Alex!
Previous Topic:Cannot get GettingStarted to work :(
Next Topic:Integrate Xtext with SWT
Goto Forum:
  


Current Time: Mon Sep 22 00:15:57 GMT 2014

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

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