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


Java XtextResource.save方法代碼示例

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


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

示例1: testWrite

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testWrite() throws Exception {
	XtextResource resource = getResource("", "test.mydsl");
	Model model = UnicodeFactory.eINSTANCE.createModel();
	resource.getContents().add(model);
	GString s0 = UnicodeFactory.eINSTANCE.createGString();
	s0.setName(UMLAUTS);
	model.getStrings().add(s0);
	QuotedString s1 = UnicodeFactory.eINSTANCE.createQuotedString();
	s1.setName(UMLAUTS);
	model.getStrings().add(s1);
	QuotedString s2 = UnicodeFactory.eINSTANCE.createQuotedString();
	s2.setName(QUOTED_UMLAUTS);
	model.getStrings().add(s2);
	QuotedString s3 = UnicodeFactory.eINSTANCE.createQuotedString();
	s3.setName(MIXED_UMLAUTS);
	model.getStrings().add(s3);
	
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	resource.save(outputStream, null);
	String textualModel = new String(outputStream.toByteArray(), getCharsetForTest());
	assertEquals(doubleQuote(UMLAUTS + " \"" + UMLAUTS + "\" \"" + QUOTED_UMLAUTS + "\" \"" + MIXED_UMLAUTS + "\""), textualModel); 
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:23,代碼來源:UnicodeTest.java

示例2: testTheBug2

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testTheBug2() throws Exception {
	with(new Bug302128TestLanguageStandaloneSetup());
	String text = "VARIABLE += value.val value2.val\n" 
			+ "VARIABLE2 += value3.val value4.val\n\n"
			+ "#Comment comment comment\n\n" 
			+ "VARIABLE3 += value5.val value6.val\n"
			+ "VARIABLE4 += value.val value2.val\n" 
			+ "VARIABLE5 += value3.val value4.val\n\n" 
			+ "#Comment comment comment\n\n" +
			  "VARIABLE.varible += value5.val value6.val\n";
	XtextResource resource = getResource(new StringInputStream(text));
	Model model = (Model) resource.getContents().get(0);
	model.getElements().get(2).setValue("+= value5.val value6.val\n");

	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	resource.save(outputStream, null);
	assertEquals(text, new String(outputStream.toByteArray()));
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:19,代碼來源:Bug302128Test.java

示例3: prettyPrint

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
/**
 * @since 2.7
 */
protected void prettyPrint(String absoluteGrammarFileName, Charset encoding) {
	try {
		String content = readFileIntoString(absoluteGrammarFileName, encoding);
		final ILineSeparatorInformation lineSeparatorInformation = new ILineSeparatorInformation() {
			@Override
			public String getLineSeparator() {
				return DebugAntlrGeneratorFragment.this.getLineDelimiter();
			}
		};
		Injector injector = new SimpleAntlrStandaloneSetup() {
			@Override
			public Injector createInjector() {
				return Guice.createInjector(new SimpleAntlrRuntimeModule() {
					@Override
					public void configure(Binder binder) {
						super.configure(binder);
						binder.bind(ILineSeparatorInformation.class).toInstance(lineSeparatorInformation);
					}
				});
			}
		}.createInjectorAndDoEMFRegistration();
		XtextResource resource = injector.getInstance(XtextResource.class);
		resource.setURI(URI.createFileURI(absoluteGrammarFileName));
		resource.load(new StringInputStream(content, encoding.name()),
				Collections.singletonMap(XtextResource.OPTION_ENCODING, encoding.name()));
		if (!resource.getErrors().isEmpty()) {
			String errors = Joiner.on(getLineDelimiter()).join(resource.getErrors());
			throw new GeneratorWarning("Non fatal problem: Debug grammar could not be formatted due to:" + getLineDelimiter() + errors);
		}
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream(content.length());
		resource.save(outputStream, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
		String toBeWritten = new NewlineNormalizer(getLineDelimiter()).normalizeLineDelimiters(
				new String(outputStream.toByteArray(), encoding.name()));
		writeStringIntoFile(absoluteGrammarFileName, toBeWritten, encoding);
	} catch(IOException e) {
		throw new GeneratorWarning(e.getMessage());
	}
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:42,代碼來源:DebugAntlrGeneratorFragment.java

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

示例5: testSaveUtfToUtf

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

示例6: testSaveUtfToIso

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

示例7: testSaveIsoToUtf

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

示例8: doTestSerialization

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
private void doTestSerialization(final String model, final String expectedModel) throws Exception {
  final XtextResource resource = this.getResourceFromString(model);
  Assert.assertTrue(resource.getErrors().isEmpty());
  EObject _rootASTElement = resource.getParseResult().getRootASTElement();
  final Grammar g = ((Grammar) _rootASTElement);
  Assert.assertNotNull(g);
  final OutputStream outputStream = new ByteArrayOutputStream();
  resource.save(outputStream, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
  final String serializedModel = outputStream.toString();
  Assert.assertEquals(LineDelimiters.toPlatform(expectedModel), serializedModel);
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:12,代碼來源:XtextGrammarSerializationTest.java

示例9: testSerializeGrammar

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testSerializeGrammar() throws Exception {
	String string = readFileIntoString("org/eclipse/xtext/parser/unorderedGroups/UnorderedGroupsTestLanguage.xtext");
	XtextResource resource = getResourceFromString(string);
	resource.getResourceSet().getLoadOptions().put(ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.TRUE);
	resource.save(new ByteArrayOutputStream(), null);
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:7,代碼來源:GrammarSerializerTest.java


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