當前位置: 首頁>>代碼示例>>Java>>正文


Java XtextResource.load方法代碼示例

本文整理匯總了Java中org.eclipse.xtext.resource.XtextResource.load方法的典型用法代碼示例。如果您正苦於以下問題:Java XtextResource.load方法的具體用法?Java XtextResource.load怎麽用?Java XtextResource.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.xtext.resource.XtextResource的用法示例。


在下文中一共展示了XtextResource.load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getResourceFor

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的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

示例2: parse

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
private XtextResource parse(final String doc) {
  try {
    String _primaryFileExtension = this.fileExtension.getPrimaryFileExtension();
    String _plus = ("dummy." + _primaryFileExtension);
    final URI uri = URI.createURI(_plus);
    Resource _createResource = this.resFactory.createResource(uri);
    final XtextResource res = ((XtextResource) _createResource);
    EList<Resource> _resources = new XtextResourceSet().getResources();
    _resources.add(res);
    if ((this.entryPoint != null)) {
      res.setEntryPoint(this.entryPoint);
    }
    StringInputStream _stringInputStream = new StringInputStream(doc);
    res.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
    this.validator.assertNoErrors(res);
    return res;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:21,代碼來源:ContentAssistContextTestHelper.java

示例3: testBug322875_04

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testBug322875_04() throws Exception {
	String testGrammarNsURI = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
			" import 'http://www.eclipse.org/emf/2002/Ecore'  " +
			"Model returns EClass: name=ID;";
	String testGrammarPlatformPlugin = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
			" import 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore'  " +
			"Model returns EClass: name=ID;";
	XtextResource resourceOk = getResourceFromString(testGrammarNsURI);
	XtextResource resourceOk2 = (XtextResource) resourceOk.getResourceSet().createResource(URI.createURI("unused.xtext"));
	resourceOk2.load(new StringInputStream(testGrammarPlatformPlugin), null);
	Diagnostic diagOK = Diagnostician.INSTANCE.validate(resourceOk.getContents().get(0));
	assertNotNull("diag", diagOK);
	assertEquals(diagOK.toString(), 0, diagOK.getChildren().size());
	diagOK = Diagnostician.INSTANCE.validate(resourceOk2.getContents().get(0));
	assertNotNull("diag", diagOK);
	assertEquals(diagOK.toString(), 0, diagOK.getChildren().size());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:19,代碼來源:XtextValidationTest.java

示例4: testBug_266807

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的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

示例5: test1

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void test1() {
  try {
    this.with(ReferenceGrammarTestLanguageStandaloneSetup.class);
    final String model = "kind (Hugo 13)";
    final ParserRule kindRule = this.<ReferenceGrammarTestLanguageGrammarAccess>get(ReferenceGrammarTestLanguageGrammarAccess.class).getKindRule();
    final XtextResource resource = this.createResource();
    resource.setEntryPoint(kindRule);
    StringInputStream _stringInputStream = new StringInputStream(model);
    resource.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
    Assert.assertTrue(resource.getErrors().isEmpty());
    Assert.assertEquals(kindRule, NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode()));
    final String originalNodeModel = NodeModelUtils.compactDump(resource.getParseResult().getRootNode(), false);
    resource.update(0, model.length(), ((" " + model) + " "));
    final String reparsedNodeModel = NodeModelUtils.compactDump(resource.getParseResult().getRootNode(), false);
    Assert.assertEquals(originalNodeModel, reparsedNodeModel);
    final ParserRule erwachsenerRule = this.<ReferenceGrammarTestLanguageGrammarAccess>get(ReferenceGrammarTestLanguageGrammarAccess.class).getErwachsenerRule();
    resource.setEntryPoint(erwachsenerRule);
    resource.update(0, model.length(), "erwachsener (Peter 30)");
    Assert.assertEquals(erwachsenerRule, NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode()));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:25,代碼來源:SetEntryPointOnXtextResourceTest.java

示例6: testgetReferenceDescriptions

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testgetReferenceDescriptions() throws Exception {
	with(new LangATestLanguageStandaloneSetup());
	XtextResource targetResource = getResource("type C", "bar.langatestlanguage");
	EObject typeC = targetResource.getContents().get(0).eContents().get(0);
	XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
	resource.load(new StringInputStream("type A extends C type B extends A"), null);
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
	Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
	Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
	assertEquals(1,collection.size());
	IReferenceDescription refDesc = descriptions.iterator().next();
	Main m = (Main) resource.getParseResult().getRootASTElement();
	assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc.getSourceEObjectUri(),false));
	assertEquals(typeC, resource.getResourceSet().getEObject(refDesc.getTargetEObjectUri(),false));
	assertEquals(-1,refDesc.getIndexInList());
	assertEquals(LangATestLanguagePackage.Literals.TYPE__EXTENDS,refDesc.getEReference());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:19,代碼來源:DefaultReferenceDescriptionTest.java

示例7: testgetReferenceDescriptionForMultiValue

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testgetReferenceDescriptionForMultiValue() throws Exception {
	with(new LangATestLanguageStandaloneSetup());
	XtextResource targetResource = getResource("type C type D", "bar.langatestlanguage");
	EObject typeC = targetResource.getContents().get(0).eContents().get(0);
	EObject typeD = targetResource.getContents().get(0).eContents().get(1);
	XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
	resource.load(new StringInputStream("type A implements B,C,D type B"), null);
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
	Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
	Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
	assertEquals(2,collection.size());
	Iterator<IReferenceDescription> iterator = descriptions.iterator();
	IReferenceDescription refDesc1 = iterator.next();
	IReferenceDescription refDesc2 = iterator.next();
	Main m = (Main) resource.getParseResult().getRootASTElement();
	assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc1.getSourceEObjectUri(),false));
	assertEquals(typeC,resource.getResourceSet().getEObject(refDesc1.getTargetEObjectUri(),false));
	assertEquals(1,refDesc1.getIndexInList());
	assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS,refDesc1.getEReference());
	assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc2.getSourceEObjectUri(),false));
	assertEquals(typeD,resource.getResourceSet().getEObject(refDesc2.getTargetEObjectUri(),false));
	assertEquals(2,refDesc2.getIndexInList());
	assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS,refDesc2.getEReference());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:26,代碼來源:DefaultReferenceDescriptionTest.java

示例8: getResourceFor

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
public final XtextResource getResourceFor(InputStream stream) {
	try {
		XtextResource result = (XtextResource) getResourceSet().createResource(
				URI.createURI("platform:/resource/" + PROJECT_NAME + "/src/path/Test.n4js"));
		result.load(stream, null);
		return result;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:12,代碼來源:AbstractN4JSContentAssistTest.java

示例9: doSaveDocument

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
		throws CoreException {
	try {
		//System.out.println("doSaveDocument ");
		ResourceSet resourceSet = createResourceSet();
		XtextResource xtextResource = (XtextResource) resourceSet.createResource(URI.createURI("temp.occi"));
		InputStream is = new ByteArrayInputStream(document.get().getBytes());
		xtextResource.load(is, Collections.EMPTY_MAP);
		is.close();
		URI uri = URI.createPlatformResourceURI(
				((org.eclipse.ui.part.FileEditorInput) element).getFile().getFullPath().toString(), true);
		//resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
		//System.out.println("uriii "+uri);
		Resource xmiResource = resourceSet.getResource(uri, true);
		((XMLResource) xmiResource).getDefaultSaveOptions().put(XMLResource.OPTION_URI_HANDLER,
				new URIHandlerImpl.PlatformSchemeAware());
		xmiResource.getContents().clear();
		xmiResource.getContents().addAll(xtextResource.getContents());
		// SUPER IMPORTANT to avoid to have references to temp.occi
		EcoreUtil.resolveAll(xmiResource);			
		xmiResource.save(Collections.EMPTY_MAP);
	} catch (IOException e) {
		throw new CoreException(
				new Status(IStatus.ERROR, "org.occiware.clouddesigner.occi.xtext.ui", "Failed to save", e));
	}
}
 
開發者ID:occiware,項目名稱:OCCI-Studio,代碼行數:28,代碼來源:OCCIDocumentProvider.java

示例10: doGetResource

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
protected XtextResource doGetResource(InputStream in, URI uri) throws Exception {
	XtextResourceSet rs = get(XtextResourceSet.class);
	rs.setClasspathURIContext(getClass());
	XtextResource resource = (XtextResource) factory.createResource(uri);
	rs.getResources().add(resource);
	resource.load(in, null);
	EcoreUtil.resolveAll(resource);
	return resource;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:11,代碼來源:Bug287988WithEagerLinkingTest.java

示例11: doGetResource

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
public XtextResource doGetResource(final InputStream in, final URI uri) throws Exception {
  XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class);
  rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext/", false), URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/"));
  rs.setClasspathURIContext(this.getClass());
  Resource _createResource = this.getResourceFactory().createResource(uri);
  final XtextResource resource = ((XtextResource) _createResource);
  rs.getResources().add(resource);
  XtextLinker linker = new XtextLinker() {
    @Override
    protected Xtext2EcoreTransformer createTransformer(final Grammar grammar, final IDiagnosticConsumer consumer) {
      Xtext2EcoreTransformer result = super.createTransformer(grammar, consumer);
      ErrorAcceptor _errorAcceptor = result.getErrorAcceptor();
      Xtext2EcoreTransformerTest.MyErrorAcceptor _myErrorAcceptor = new Xtext2EcoreTransformerTest.MyErrorAcceptor(_errorAcceptor, Xtext2EcoreTransformerTest.this.errorAcceptorMock);
      result.setErrorAcceptor(_myErrorAcceptor);
      return result;
    }
  };
  ILinker _linker = resource.getLinker();
  linker.setScopeProvider(((XtextLinker) _linker).getScopeProvider());
  ILinker _linker_1 = resource.getLinker();
  linker.setLinkingService(((Linker) _linker_1).getLinkingService());
  ILinker _linker_2 = resource.getLinker();
  linker.setLinkingHelper(((Linker) _linker_2).getLinkingHelper());
  XtextLinker.PackageRemover _packageRemover = new XtextLinker.PackageRemover();
  linker.setPackageRemover(_packageRemover);
  LinkingDiagnosticMessageProvider _linkingDiagnosticMessageProvider = new LinkingDiagnosticMessageProvider();
  linker.setDiagnosticMessageProvider(_linkingDiagnosticMessageProvider);
  OnChangeEvictingCache _onChangeEvictingCache = new OnChangeEvictingCache();
  linker.setCache(_onChangeEvictingCache);
  resource.setLinker(linker);
  resource.load(in, null);
  return resource;
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:41,代碼來源:Xtext2EcoreTransformerTest.java

示例12: testWithImports

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
@Test public void testWithImports() throws Exception {
	SyntheticModelAwareURIConverter uriConverter = new SyntheticModelAwareURIConverter();
	XtextResourceSet resourceSet = get(XtextResourceSet.class);
	resourceSet.setURIConverter(uriConverter);
	
	uriConverter.addModel("a.ignorecaseimportstestlanguage", "a A {}");
	
	XtextResource resource = (XtextResource) getResourceFactory().createResource(URI.createURI("b.ignorecaseimportstestlanguage"));
	resourceSet.getResources().add(resource);
	resource.load(new StringInputStream("'a.ignorecaseimportstestlanguage' b A {}"), null);
	EcoreUtil.resolveAll(resource);
	assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:15,代碼來源:IgnoreCaseLinkingWithURIImportsTest.java

示例13: testUtfBytesWithIsoOptions

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testUtfBytesWithIsoOptions() throws Exception {
	XtextResource resource = createXtextResource();
	try {
		resource.load(new ByteArrayInputStream(utfBytes), isoOptions);
		assertFalse(resource.getErrors().toString(), resource.getErrors().isEmpty());
	} catch (WrappedException e) {
		if (e.getCause() instanceof CharConversionException) {
			// ok
		} else {
			throw e;
		}
	}
	resource.reparse(model);
	assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:16,代碼來源:EncodingTest.java

示例14: testIsoEncoding

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testIsoEncoding() throws Exception {
	XtextResource resource = createXtextResource();
	resource.load(new ByteArrayInputStream(isoBytes), isoOptions);
	assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
	resource.reparse(model);
	assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:8,代碼來源:EncodingTest.java

示例15: testSaveIsoToIso

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testSaveIsoToIso() throws Exception {
	XtextResource resource = createXtextResource();
	resource.load(new ByteArrayInputStream(isoBytes), isoOptions);
	ByteArrayOutputStream isoSaveStream = new ByteArrayOutputStream();
	resource.save(isoSaveStream, null);
	isoSaveStream.close();
	byte[] savedIsoBytes = isoSaveStream.toByteArray();
	assertTrue(Arrays.equals(isoBytes, savedIsoBytes));
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:10,代碼來源:EncodingTest.java


注:本文中的org.eclipse.xtext.resource.XtextResource.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。