Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MDT (Model Development Tools) » [TCS] To invoke Inject from Java
[TCS] To invoke Inject from Java [message #606566] Wed, 01 September 2010 08:57 Go to next message
Alvaro Jimenez Rielo is currently offline Alvaro Jimenez Rielo
Messages: 41
Registered: July 2009
Location: Rey Juan Carlos Universit...
Member
Hello,

I have created a parser for my own language following the steps that shows in
http://wiki.eclipse.org/TCS/Language_Project#Creating_a_Lang uage_Project_For_Plugin_Builder

Now, I want use this parser from Java to inject files to models. To do it, I use this method (based on ActionEBNFInjector):

private void injectRubyTL() {
AtlModelHandler amh = AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
ASMModel pbmm = amh.getBuiltInMetaModel("Problem");
ASMModel pbs = amh.newModel("pbs", "pbs", pbmm);
try {
InputStream in = currentFile.getContents();

ASMModel mm = amh.loadModel("RubyTL", amh.getMof(), this.getClass().getResourceAsStream("../api/resources/RubyTL.ecore "));
ASMModel model = amh.newModel(currentFile.getName(), currentFile.getLocationURI().toString(), mm);


int antlrVersion = 3;

String packageName = "org.eclipse.gmt.tcs.injector.";
String classNamePrefix = "RubyTL";
if(antlrVersion == 3)
classNamePrefix += "_ANTLR3";
String lexerClassName = packageName + classNamePrefix + "Lexer";
String parserClassName = packageName + classNamePrefix + "Parser";
Class lexer = null;
try {
lexer = Class.forName(lexerClassName);
} catch(ClassNotFoundException cnfe) {}
if(lexer == null)
lexer = AM3CorePlugin.getDefault().getLoader().loadClass2(lexerClass Name, true);
Class parser = null;
try {
parser = Class.forName(parserClassName);
} catch(ClassNotFoundException cnfe) {}
if(parser == null)
parser = AM3CorePlugin.getDefault().getLoader().loadClass2(parserClas sName, true);

TCSInjector injector = new TCSInjector();
Map params = new HashMap();
params.put("name", "RubyTL");
params.put("lexerClass", lexer);
params.put("parserClass", parser);
params.put("problems", pbs);
params.put("parserGenerator", "antlr" + antlrVersion);
injector.inject(model, in, params);
if (model != null) {
String name = currentFile.getFullPath().removeFirstSegments(1)
.toString();
name = name.substring(0, name.length() - 3) +".rubytl"; // 3= ".rb"
amh.saveModel(model, name, currentFile.getProject());
}
} catch (CoreException e1) {
System.err.println(e1);
} catch (IOException e1) {
System.err.println(e1);
} catch (ClassNotFoundException e) {
System.err.println(e);
}
}

But I receive the following problem because I don't know where I have to copy "myLanguage-parser.jar", well I really don't know if I have to copy that file, the TCS project completely or another thing:
java.lang.ClassNotFoundException: org.eclipse.gmt.tcs.injector.RubyTL_ANTLR3Lexer

Can you help me? Thanks a lot.

Regards,
Álvaro
Re: [TCS] To invoke Inject from Java [message #606568 is a reply to message #606566] Wed, 01 September 2010 09:12 Go to previous message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 522
Registered: July 2009
Senior Member
You should create a plug-in to register all the resources of your language.
Then you can use the extension point org.eclipse.gmt.tcs.metadata.language to register the different things (syntax, parser&lexer, etc...).

The TCS builder may even build that plug-in.

Once you have that, this will simplify injection/extraction processes :
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint("org.eclipse.gmt.tcs.metadata.language ");//$NON-NLS-1$
IConfigurationElement[] elements = point.getExtensions()[0].getConfigurationElements();
for(int j = 0 ; j < elements.length ; j++){
String pluginId = elements[j].getContributor().getName();
Bundle bundle = Platform.getBundle(pluginId);
metamodelUri = getURI(bundle, elements[j].getAttribute("metamodel"));
parser = getURL(bundle, elements[j], "parser");
}
For the parameters you would then use :
Map injParams = new HashMap();
injParams.put("name", name);
injParams.put("parserGenerator", "antlr3");
injParams.put("extraClasspath", new URL[] {parser});
Previous Topic:[TCS] To invoke Inject from Java
Next Topic:[TCS] Immediate Composite Operation?
Goto Forum:
  


Current Time: Tue Sep 16 01:08:36 GMT 2014

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

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