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


Java XtextResourceSet.createResource方法代码示例

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


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

示例1: 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

示例2: resourceSet

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
/**
 * creates a fresh resource set with the given resources
 * 
 * @param resources - pairs of file names and their contents 
 * @return a ResourceSet, containing the given resources.
 * @throws IOException if the resource loading fails 
 */
public ResourceSet resourceSet(Pair<String,? extends CharSequence> ...resources ) throws IOException {
	XtextResourceSet result = resourceSetProvider.get();
	result.setClasspathURIContext(classpathUriContext);
	FileProjectConfig projectConfig = new FileProjectConfig(new File(workspaceRoot,PROJECT_NAME), PROJECT_NAME);
	projectConfig.addSourceFolder("src");
	ProjectConfigAdapter.install(result, projectConfig);
	for (Pair<String, ? extends CharSequence> entry : resources) {
		URI uri = copyToWorkspace(getSourceFolderPath()+"/"+entry.getKey(), entry.getValue());
		Resource resource = result.createResource(uri);
		if (resource == null)
			throw new IllegalStateException("Couldn't create resource for URI "+uri+". Resource.Factory not registered?");
		resource.load(newHashMap());
	}
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:23,代码来源:CompilationTestHelper.java

示例3: doTest

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
public void doTest(final URI usedPrimaryURI, final URI initialReferencedURI, final URI usedReferencedURI) {
  this.referencedResource.setURI(initialReferencedURI);
  final byte[] primaryBytes = this.getBytes(this.primaryResource);
  final byte[] referencedBytes = this.getBytes(this.referencedResource);
  final XtextResourceSet otherResourceSet = this.getNewResourceSet();
  final Resource newPrimaryResource = otherResourceSet.createResource(usedPrimaryURI);
  this.load(newPrimaryResource, primaryBytes);
  final Resource newReferencedResource = otherResourceSet.createResource(usedReferencedURI);
  this.load(newReferencedResource, referencedBytes);
  EcoreUtil.resolveAll(otherResourceSet);
  int _size = otherResourceSet.getResources().size();
  boolean _notEquals = (_size != 2);
  if (_notEquals) {
    throw new UnexpectedResourcesException(otherResourceSet);
  }
  final Map<EObject, Collection<EStructuralFeature.Setting>> unresolved = EcoreUtil.UnresolvedProxyCrossReferencer.find(otherResourceSet);
  boolean _isEmpty = unresolved.isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    throw new UnexpectedProxiesException(unresolved);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:23,代码来源:AbstractURIHandlerTest.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: testContainsURI

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test
public void testContainsURI() {
	String fileExtension = fep.getPrimaryFileExtension();
	XtextResourceSet xtextResourceSet1 = rsp.get();
	xtextResourceSet1.createResource(URI.createURI("/a/x." + fileExtension));
	xtextResourceSet1.createResource(URI.createURI("/b/x1." + fileExtension));
	ResourceSetBasedResourceDescriptions liveState = new ResourceSetBasedResourceDescriptions();
	liveState.setContext(xtextResourceSet1);
	liveState.setRegistry(registry);
	Multimap<String, URI> container2Uris = ArrayListMultimap.create();
	container2Uris.put("a", URI.createURI("/a/x." + fileExtension));
	container2Uris.put("a", URI.createURI("/a/y." + fileExtension));
	container2Uris.put("b", URI.createURI("/b/x1." + fileExtension));
	container2Uris.put("b", URI.createURI("/b/x2." + fileExtension));
	IAllContainersState containersState = containerStateProvider.get(liveState,
			new FakeAllContainerState(container2Uris));
	assertTrue(containersState.containsURI("a", URI.createURI("/a/x." + fileExtension)));
	assertTrue(containersState.containsURI("a", URI.createURI("/a/y." + fileExtension)));
	assertFalse(containersState.containsURI("b", URI.createURI("/a/x." + fileExtension)));
	assertFalse(containersState.containsURI("b", URI.createURI("/a/y." + fileExtension)));
	assertTrue(containersState.containsURI("b", URI.createURI("/b/x1." + fileExtension)));
	assertTrue(containersState.containsURI("b", URI.createURI("/b/x2." + fileExtension)));
	assertFalse(containersState.containsURI("a", URI.createURI("/b/x1." + fileExtension)));
	assertFalse(containersState.containsURI("a", URI.createURI("/b/x2." + fileExtension)));
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:26,代码来源:LiveShadowedAllContainerStateTest.java

示例6: getResourceFor

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public XtextResource getResourceFor(final InputStream stream) {
  try {
    XtextResourceSet set = get(XtextResourceSet.class);
    XtextResource resource = (XtextResource) set.createResource(URI.createURI("Test." + getFileExtension()));
    resource.load(stream, null);
    initializeTypeProvider(set);
    return resource;
    // CHECKSTYLE:OFF
  } catch (Exception e) {
    // CHECKSTYLE:ON
    fail(e.getMessage());
  }
  return null;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:17,代码来源:AbstractCheckContentAssistBugTest.java

示例7: testSimple

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test public void testSimple() throws Exception {
	// this fails see bug #252181
	String model = "grammar foo with org.eclipse.xtext.common.Terminals Honolulu : name=ID;";

	// load grammar model
	XtextResourceSet rs = get(XtextResourceSet.class);
	Resource resource = rs.createResource(URI.createURI("foo.xtext"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	resource.load(new StringInputStream(model), null);
	Grammar object = (Grammar) resource.getContents().get(0);

	// modify first rule
	object.getRules().get(0).setName("HONOLULU");

	// save
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	resource.save(out, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
	String result = new String(out.toByteArray());

	// check
	assertFalse(model.equals(result));
	String expectedModel = LineDelimiters.toPlatform("grammar foo with org.eclipse.xtext.common.Terminals\n\nHONOLULU:\n	name=ID;");
	assertEquals(expectedModel, result);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:XtextGrammarReconcilationTest.java

示例8: testBug_266807

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test
public void testBug_266807() throws Exception {
  final XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class);
  rs.setClasspathURIContext(this.getClass());
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("classpath:/");
  String _replace = this.getClass().getPackage().getName().replace(Character.valueOf('.').charValue(), Character.valueOf('/').charValue());
  _builder.append(_replace);
  _builder.append("/Test.xtext");
  Resource _createResource = rs.createResource(
    URI.createURI(_builder.toString()), 
    ContentHandler.UNSPECIFIED_CONTENT_TYPE);
  final XtextResource resource = ((XtextResource) _createResource);
  resource.load(null);
  EList<Resource.Diagnostic> _errors = resource.getErrors();
  for (final Resource.Diagnostic d : _errors) {
    Assert.fail(d.getMessage());
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:20,代码来源:Xtext2EcoreTransformerTest.java

示例9: unLoadedResourceSet

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
/**
 * same as {@link #resourceSet(Pair...)} but without actually loading the created resources.
 */
public ResourceSet unLoadedResourceSet(Pair<String,? extends CharSequence> ...resources ) throws IOException {
	XtextResourceSet result = resourceSetProvider.get();
	for (Pair<String, ? extends CharSequence> entry : resources) {
		URI uri = copyToWorkspace(getSourceFolderPath()+"/"+entry.getKey(), entry.getValue());
		Resource resource = result.createResource(uri);
		if (resource == null)
			throw new IllegalStateException("Couldn't create resource for URI "+uri+". Resource.Factory not registered?");
	}
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:14,代码来源:CompilationTestHelper.java

示例10: newResource

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Override
protected Resource newResource(final CharSequence input) throws IOException {
  final XtextResourceSet resourceSet = this.resourceSetProvider.get();
  final Resource resource = resourceSet.createResource(URI.createURI("Test.___xbase"));
  String _string = input.toString();
  StringInputStream _stringInputStream = new StringInputStream(_string);
  resource.load(_stringInputStream, null);
  return resource;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:10,代码来源:JvmModelTest.java

示例11: recordWorkspaceEdit

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
private WorkspaceEdit recordWorkspaceEdit(final Document doc, final XtextResource resource, final IChangeSerializer.IModification<Resource> mod) {
  try {
    final XtextResourceSet rs = new XtextResourceSet();
    final Resource copy = rs.createResource(resource.getURI());
    String _text = resource.getParseResult().getRootNode().getText();
    StringInputStream _stringInputStream = new StringInputStream(_text);
    copy.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
    this.serializer.<Resource>addModification(copy, mod);
    final ArrayList<IEmfResourceChange> documentchanges = CollectionLiterals.<IEmfResourceChange>newArrayList();
    this.serializer.applyModifications(CollectionBasedAcceptor.<IEmfResourceChange>of(documentchanges));
    WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
    final Procedure1<WorkspaceEdit> _function = (WorkspaceEdit it) -> {
      Iterable<ITextDocumentChange> _filter = Iterables.<ITextDocumentChange>filter(documentchanges, ITextDocumentChange.class);
      for (final ITextDocumentChange documentchange : _filter) {
        {
          final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
            TextEdit _textEdit = new TextEdit();
            final Procedure1<TextEdit> _function_2 = (TextEdit it_1) -> {
              it_1.setNewText(replacement.getReplacementText());
              Position _position = doc.getPosition(replacement.getOffset());
              Position _position_1 = doc.getPosition(replacement.getEndOffset());
              Range _range = new Range(_position, _position_1);
              it_1.setRange(_range);
            };
            return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
          };
          final List<TextEdit> edits = ListExtensions.<ITextReplacement, TextEdit>map(documentchange.getReplacements(), _function_1);
          it.getChanges().put(documentchange.getNewURI().toString(), edits);
        }
      }
    };
    return ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:37,代码来源:CodeActionService.java

示例12: testCrossContainment_01

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test public void testCrossContainment_01() {
	XtextResourceSet resourceSet = get(XtextResourceSet.class);
	resourceSet.setClasspathURIContext(getClass());
	Resource resource = resourceSet.createResource(URI.createFileURI("container.xmi"));
	Resource childResource = resourceSet.createResource(URI.createFileURI("child.xmi"));
	CrossResourceContainerManyChildren container = PartialParsingTestUtilFactory.eINSTANCE.createCrossResourceContainerManyChildren();
	resource.getContents().add(container);
	Grammar grammar = XtextFactory.eINSTANCE.createGrammar();
	childResource.getContents().add(grammar);
	assertNull(grammar.eContainer());
	container.getChildren().add(grammar);
	assertSame(container, grammar.eContainer());
	assertSame(childResource, grammar.eResource());
	assertSame(resource, container.eResource());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:16,代码来源:CrossContainmentTest.java

示例13: testCrossContainment_02

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test public void testCrossContainment_02() {
	XtextResourceSet resourceSet = get(XtextResourceSet.class);
	resourceSet.setClasspathURIContext(getClass());
	Resource resource = resourceSet.createResource(URI.createFileURI("container.xmi"));
	Resource childResource = resourceSet.createResource(URI.createFileURI("child.xmi"));
	CrossResourceContainerOneChild container = PartialParsingTestUtilFactory.eINSTANCE.createCrossResourceContainerOneChild();
	resource.getContents().add(container);
	Grammar grammar = XtextFactory.eINSTANCE.createGrammar();
	childResource.getContents().add(grammar);
	assertNull(grammar.eContainer());
	container.setChild(grammar);
	assertSame(container, grammar.eContainer());
	assertSame(childResource, grammar.eResource());
	assertSame(resource, container.eResource());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:16,代码来源:CrossContainmentTest.java

示例14: testValidExternalLink

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test public void testValidExternalLink() throws Exception {
	XtextResourceSet rs = get(XtextResourceSet.class);
	Resource res1 = rs.createResource(URI.createURI("foo.langatestlanguage"));
	res1.load(new StringInputStream("type Foo"), null);
	
	XtextResource res2 = (XtextResource) rs.createResource(URI.createURI("bar.langatestlanguage"));
	res2.load(new StringInputStream("import 'foo.langatestlanguage'" +
	"type Bar extends Foo"), null);
	
	EcoreUtil.resolveAll(res2);
	Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
	assertEquals(QualifiedName.create("foo"),names.iterator().next());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:DefaultResourceDescription2Test.java

示例15: testValidLocalLink

import org.eclipse.xtext.resource.XtextResourceSet; //导入方法依赖的package包/类
@Test public void testValidLocalLink() throws Exception {
	XtextResourceSet rs = get(XtextResourceSet.class);
	Resource res1 = rs.createResource(URI.createURI("foo.langatestlanguage"));
	res1.load(new StringInputStream("type Foo"), null);
	
	XtextResource res2 = (XtextResource) rs.createResource(URI.createURI("bar.langatestlanguage"));
	res2.load(new StringInputStream("import 'foo.langatestlanguage'" +
	"type Foo type Bar extends Foo"), null);
	
	EcoreUtil.resolveAll(res2);
	Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
	assertFalse(names.iterator().hasNext());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:DefaultResourceDescription2Test.java


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