Skip to main content


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 #556411] Wed, 01 September 2010 08:57 Go to next message
Eclipse UserFriend
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(lexerClassName, true);
			Class parser = null;
			try {
				parser = Class.forName(parserClassName);
			} catch(ClassNotFoundException cnfe) {}
			if(parser == null)
				parser = AM3CorePlugin.getDefault().getLoader().loadClass2(parserClassName, 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!

Regards,
Álvaro

[Updated on: Wed, 01 September 2010 09:03] by Moderator

Report message to a moderator

Re: [TCS] To invoke Inject from Java [message #556415 is a reply to message #556411] Wed, 01 September 2010 09:12 Go to previous message
Eclipse UserFriend
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:[BPMN2] Using the BPMN2 editor XML as input for ATL
Next Topic:[TCS] To invoke Inject from Java
Goto Forum:
  


Current Time: Thu Feb 13 13:54:06 GMT 2025

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

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

Back to the top