当前位置: 首页>>代码示例>>Java>>正文


Java XtextResourceSet.getResource方法代码示例

本文整理汇总了Java中org.eclipse.xtext.resource.XtextResourceSet.getResource方法的典型用法代码示例。如果您正苦于以下问题:Java XtextResourceSet.getResource方法的具体用法?Java XtextResourceSet.getResource怎么用?Java XtextResourceSet.getResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.resource.XtextResourceSet的用法示例。


在下文中一共展示了XtextResourceSet.getResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mergeContent

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
/**
 * Merges the content of two {@link ProjectDescription project description} instances that are representing the
 * actual N4JS manifests.
 *
 * @param fromLocation
 *            the source location. These attributes and references will be merged to the other one given with the
 *            {@code toLocation}.
 * @param toLocation
 *            the target location. The project description that has to be updated with the content of the
 *            {@code fromLocation}.
 * @return the merged project description that has been detached from its resource.
 */
public ProjectDescription mergeContent(final URI fromLocation, final URI toLocation) {

	final XtextResourceSet fromResourceSet = getResourceSet(fromLocation);
	final XtextResourceSet toResourceSet = getResourceSet(toLocation);
	if (null == fromResourceSet || null == toResourceSet) {
		return null;
	}

	try {

		final Resource from = fromResourceSet.getResource(fromLocation, true);
		final Resource to = toResourceSet.getResource(toLocation, true);
		return mergeContent(from, to);

	} catch (final Exception e) {
		LOGGER.error("Error while trying to merge N4JS manifest content. Source URI: " + fromLocation
				+ ". Target URI: " + toLocation + ".", e);
	}
	return null;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:33,代码来源:ManifestMerger.java

示例2: loadGexpressionTestFile

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
public static void loadGexpressionTestFile() {
	// Getting the serializer
	GExpressionsStandaloneSetup setup = new GExpressionsStandaloneSetup();
	Injector injector = setup.createInjectorAndDoEMFRegistration();
	GexpressionsPackage.eINSTANCE.eClass();
	Serializer serializer = injector.getInstance(Serializer.class);

	// Load the model
	URI modelURI = URI
			.createFileURI("/home/flatombe/thesis/gemoc/git/gemoc-dev/org/eclipse/gemoc/GEL/org.eclipse.gemoc.gel.gexpressions.test/model/test.gexpressions");
	XtextResourceSet resSet = injector.getInstance(XtextResourceSet.class);
	resSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
	Resource resource = resSet.getResource(modelURI, true);
	GProgram program = (GProgram) resource.getContents().get(0);

	List<GExpression> exps = program.getExpressions();
	for (GExpression exp : exps) {
		// Serializing
		String s = serializer.serialize(exp);
		System.out.println(s);
	}
}
 
开发者ID:eclipse,项目名称:gemoc-studio,代码行数:23,代码来源:TestXtextSerializer2.java

示例3: convertERDSLtoXMI

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
public static void convertERDSLtoXMI(String inputM, String outputM) {
	Injector injector = new QueryITStandaloneSetup().createInjectorAndDoEMFRegistration();

	XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);


	URI uri = URI.createURI(inputM);
	

	Resource xtextResource = resourceSet.getResource(uri, true);

	EcoreUtil.resolveAll(xtextResource);

	Resource xmiResource = resourceSet.createResource(URI.createURI(outputM));
	xmiResource.getContents().add(xtextResource.getContents().get(0));
	try {
		xmiResource.save(null);
		System.out.println("Saved " + outputM);
    	System.out.println("QueryIT file converted successfully to XMI");
    	System.out.println("-------------------------------------");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:TodorovicNikola,项目名称:SurveyDSL,代码行数:25,代码来源:QueryITToXMIConverter.java

示例4: exportXMI

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
private void exportXMI(String inM, String outM) {
    // change MyLanguage with your language name
    Injector injector = new ODMParameterStandaloneSetupGenerated()
            .createInjectorAndDoEMFRegistration();
    XtextResourceSet resourceSet = injector
            .getInstance(XtextResourceSet.class);

    // .ext is the extension of the model file
    String inputURI =inM;//"tests/movies.odm";
    String outputURI =outM;//"tests/movies_dsl_output.xmi";
    System.out.println(inputURI+" "+outputURI);
    URI uri = URI.createURI(inputURI);
    Resource xtextResource = resourceSet.getResource(uri, true);

    EcoreUtil.resolveAll(xtextResource);

    Resource xmiResource = resourceSet
            .createResource(URI.createURI(outputURI));
    xmiResource.getContents().add(xtextResource.getContents().get(0));
    try {
        xmiResource.save(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:catedrasaes-umu,项目名称:NoSQLDataEngineering,代码行数:26,代码来源:Model_odm2model_xmi.java

示例5: loadResource

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
public static Resource loadResource(String string, XtextResourceSet resourceSet) {
	URI uri = URI.createURI(string);
	Resource resource;
	try {
		resource = resourceSet.getResource(uri, true);
		if (resource == null) {
			throw new IllegalArgumentException("Couldn't create resource for URI : " + uri);
		}
	} catch (Exception e) {
		throw new WrappedException(e);
	}
	EList<EObject> contents = resource.getContents();
	if (contents.size() < 1) {
		throw new IllegalStateException("loading classpath:" + string + " : Expected at least root element but found "
				+ contents.size());
	}
	return resource;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:BaseEPackageAccess.java

示例6: testXtextFormatting

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test public void testXtextFormatting() throws IOException {
	String path = getClass().getPackage().getName().replace('.', '/');
	URI u = URI.createURI("classpath:/" + path + "/XtextFormatterMessy.xtext");
	XtextResourceSet resourceSet = new XtextResourceSet();
	resourceSet.setClasspathURIContext(getClass());
	Resource r = resourceSet.getResource(u, true);
	// System.out.println(r.getWarnings());
	// System.out.println(r.getErrors());
	ByteArrayOutputStream formatted = new ByteArrayOutputStream();
	r.save(formatted, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
	// System.out.println(EmfFormatter.listToStr(r.getContents()));
	// System.out.println(formatted.toString());

	URI expectedURI = URI.createURI("classpath:/" + path + "/XtextFormatterExpected.xtext");
	XtextResource expectedResource = (XtextResource) resourceSet.getResource(expectedURI, true);
	String expected = expectedResource.getParseResult().getRootNode().getText();
	assertEquals(expected.replaceAll(System.lineSeparator(), "\n"), 
	    formatted.toString().replaceAll(System.lineSeparator(), "\n"));
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:20,代码来源:XtextFormatterTest.java

示例7: setUp

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
	super.setUp();
	XtextResourceSet set = new XtextResourceSet();
	set.setClasspathURIContext(getClass());
	Resource resource = set.getResource(URI.createURI("classpath:/org/eclipse/xtext/generator/grammarAccess/ametamodel.ecore"), true);
	metamodel = (EPackage) resource.getContents().get(0);
	fragment = new GrammarAccessFragment();
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:10,代码来源:SubPackageAwareGrammarAccessFragmentTest.java

示例8: setUp

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
	super.setUp();
	XtextResourceSet set = new XtextResourceSet();
	set.setClasspathURIContext(getClass());
	Resource resource = set.getResource(URI.createURI("classpath:/org/eclipse/xtext/generator/grammarAccess/ametamodel.ecore"), true);
	metamodel = (EPackage) resource.getContents().get(0);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:FragmentFakingEcoreResourceTest.java

示例9: testReplaceResourceURIs

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test public void testReplaceResourceURIs() {
	XtextResourceSet xtextResourceSet = get(XtextResourceSet.class);
	xtextResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
	xtextResourceSet.setClasspathURIContext(this);
	Resource grammarResource = xtextResourceSet.getResource(URI.createURI("classpath:/org/eclipse/xtext/generator/grammarAccess/GrammarAccessTestLanguage.xtext"), true);
	EcoreUtil.resolveAll(grammarResource);
	Grammar grammar = (Grammar) grammarResource.getContents().get(0);
	EPackage ePackage = grammar.getMetamodelDeclarations().get(0).getEPackage();
	assertFalse(ePackage.eResource().getURI().equals(URI.createURI(ePackage.getNsURI())));
	fragment.replaceResourceURIsWithNsURIs(grammar, xtextResourceSet);
	assertEquals(ePackage.eResource().getURI(), URI.createURI(ePackage.getNsURI()));
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:13,代码来源:Bug378261Test.java

示例10: cloneGrammarIntoNewResourceSet

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
/**
 * Create a clone of the original grammar. The clone will not refer to a node model.
 */
private Grammar cloneGrammarIntoNewResourceSet(final Grammar original) {
  final Resource originalResource = original.eResource();
  XtextResourceSet _xtextResourceSet = new XtextResourceSet();
  final XtextResourceSet clonedResourceSet = EcoreUtil2.<XtextResourceSet>clone(_xtextResourceSet, originalResource.getResourceSet());
  final Resource clonedResource = clonedResourceSet.getResource(originalResource.getURI(), false);
  EObject _head = IterableExtensions.<EObject>head(clonedResource.getContents());
  return ((Grammar) _head);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:12,代码来源:EMFGeneratorFragment2.java

示例11: grammarFinder

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
private AbstractGrammarElementFinder grammarFinder() {
	final String file = "classpath:/org/eclipse/xtext/generator/grammarAccess/ElementFinderTestLanguage.xtext";
	XtextResourceSet rs = get(XtextResourceSet.class);
	rs.setClasspathURIContext(getClass());
	final Resource r = rs.getResource(URI.createURI(file), true);
	return new AbstractGrammarElementFinder() {
		@Override
		public Grammar getGrammar() {
			return (Grammar) r.getContents().get(0);
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:ElementFinderTest.java

示例12: setUp

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
	super.setUp();
	with(XtextStandaloneSetup.class);
	XtextResourceSet resourceSet = get(XtextResourceSet.class);
	resourceSet.setClasspathURIContext(getClass().getClassLoader());
	Resource resource = resourceSet.getResource(
			URI.createURI("classpath:/org/eclipse/xtext/grammarinheritance/ConcreteTestLanguage.xtext"), true);
	grammar = (Grammar) resource.getContents().get(0);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:11,代码来源:XtextScopingTest.java

示例13: testClasspathURIIsNormalized

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test public void testClasspathURIIsNormalized() {
	XtextResourceSet xtextResourceSet = new XtextResourceSet();
	xtextResourceSet.setClasspathURIContext(this);
	URI classpathURI = URI.createURI("classpath:/org/eclipse/xtext/XtextGrammarTestLanguage.ecore");
	Resource resource = xtextResourceSet.getResource(classpathURI, true);
	IResourceDescription ecoreResourceDescription = createResourceDescription(resource);
	assertNotSame(classpathURI, ecoreResourceDescription.getURI());
	assertEquals(xtextResourceSet.getURIConverter().normalize(classpathURI), ecoreResourceDescription.getURI());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:10,代码来源:DefaultResourceDescription2Test.java

示例14: getResource

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
private XtextResource getResource(String uri) {
	XtextResourceSet set = get(XtextResourceSet.class);
	URI nsURI = URI.createURI(EcorePackage.eNS_URI);
	URI platformURI = URI.createURI("platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore");
	set.getURIConverter().getURIMap().put(platformURI, nsURI);
	set.getURIResourceMap().put(platformURI, set.getResource(nsURI, true));
	set.setClasspathURIContext(getClass().getClassLoader());
	// if(AllTests.isPluginContext) {
	// set.setClasspathUriResolver(new BundleClasspathUriResolver());
	// set.setClasspathURIContext(Activator.getDefault());
	// }
	XtextResource r = (XtextResource) set.getResource(URI.createURI(uri), true);
	return r;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:15,代码来源:ToEcoreTrafoTest.java

示例15: getContext

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
protected Type getContext() {
	XtextResourceSet resourceSet = get(XtextResourceSet.class);
	resourceSet.setClasspathURIContext(getClass().getClassLoader());

	URI uri = URI.createURI("classpath:/org/eclipse/xtext/linking/02.importuritestlanguage");
	Resource resource = resourceSet.getResource(uri, true);
	Main main = (Main) resource.getContents().get(0);
	return main.getTypes().get(0);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:10,代码来源:Bug437669Test.java


注:本文中的org.eclipse.xtext.resource.XtextResourceSet.getResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。