Skip to main content
summaryrefslogtreecommitdiffstats
blob: 616ce3a3dc0497c276fde2f72d4131ae342003c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.xtext.glue.partialEditing;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.infra.gmfdiag.xtext.glue.edit.part.PopupXtextEditorHelper;
import org.eclipse.xtext.IGrammarAccess;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;

import com.google.inject.Inject;
import com.google.inject.Provider;

/**
 * @author Sebastian Zarnekow - Initial contribution and API
 */
public class SyntheticResourceProvider implements ISyntheticResourceProvider {

	/**
	 *
	 */
	public static final String SYNTHETIC_SCHEME = "synthetic";
	
	//@Inject 
	//private IResourceSetProvider resourceSetProvider;
	@Inject
	private Provider<XtextResourceSet> resourceSetProvider;
	
	@Inject
	private IGrammarAccess grammarAccess;
	
	
	
	public XtextResource createResource() {
		ResourceSet resourceSet = resourceSetProvider.get();
//		EObject context = PopupXtextEditorHelper.context ;
//		ResourceSet resourceSet = context.eResource().getResourceSet() ;
		Resource grammarResource = resourceSet.createResource(
				URI.createURI(SYNTHETIC_SCHEME + ":/" + grammarAccess.getGrammar().getName() + ".xtext"));
		grammarResource.getContents().add(EcoreUtil.copy(grammarAccess.getGrammar()));
		XtextResource result = (XtextResource) resourceSet.createResource(
				URI.createURI(SYNTHETIC_SCHEME + ":/" + grammarAccess.getGrammar().getName() + "." + PopupXtextEditorHelper.fileExtension));
		resourceSet.getResources().add(result);
		return result ;		

	}
	
}

Back to the top