Instantiating instance of Java Class corresponding to JvmDeclaredType [message #1231565] |
Tue, 14 January 2014 19:24  |
Eclipse User |
|
|
|
Hi,
I have following rule in my grammar (mydsl.xtext):
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes
...
JvmTypeRef:
'ref' ':' jvmtype=[jvmTypes::JvmDeclaredType | FQN]
;
A sample instance file (say 01.mydsl) contains the following:
ref : org.example.try01.Class01
where 01.mydsl is in a general project in workspace that also has a java project having class org.example.try01.Class01
I need to create an instance of the java class org.example.try01.Class01 using reflection (are there other alternatives as well..?) while I compute scope for elements corresponding to other grammar rules.
Is there a way to get instance of java.lang.Class from instance of JvmDeclaredType...?
After reading a bit of xtext code, I feel what I need is an exact reverse of DeclaredTypeFactory#createType(final Class<?> clazz).
Note: jvmtype.eResource.URI gives me 'java:/Objects/org.example.try01.Class01', but I am not sure how to use this to instantiate java.lang.Class.
|
|
|
|
Re: Instantiating instance of Java Class corresponding to JvmDeclaredType [message #1231742 is a reply to message #1231679] |
Wed, 15 January 2014 04:31   |
Eclipse User |
|
|
|
Hi Sven,
Thanks for the warning...
Basically I need the user to refer to some existing java class (java class could potentially be coming from another Java project in the same workspace, or from a jar file) from 01.xtext. Then, in order to compute the scope for some other domain elements, I need to instantiate this Java Class.
At this point I really do not mind have some extra steps in my workflow, so I am willing to export the Java class from project to some jar, if that helps.
Can you provide some more details, pointers, code snippet, on how to create instance of java.lang.Class from IJavaProject or for imported jar...? Thanks.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06998 seconds