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


Java XtextResource.update方法代碼示例

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


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

示例1: testUpdateTwice

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testUpdateTwice() {
  try {
    final ContentAssistFragmentTestLanguageRoot result = this.parseHelper.parse("");
    Resource _eResource = result.eResource();
    final XtextResource res = ((XtextResource) _eResource);
    new InvariantChecker().checkInvariant(res.getParseResult().getRootNode());
    res.update(0, 0, "newArrayList()");
    final EObject first = IterableExtensions.<EObject>head(res.getContents());
    Assert.assertTrue(first.eClass().getName(), (first instanceof ContentAssistFragmentTestLanguageRoot));
    res.update("newArrayList(".length(), 0, "1");
    final EObject second = IterableExtensions.<EObject>head(res.getContents());
    Assert.assertTrue(second.eClass().getName(), (second instanceof ContentAssistFragmentTestLanguageRoot));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:18,代碼來源:Bug480686Test.java

示例2: testBrokenInput_02

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testBrokenInput_02() {
  try {
    final ContentAssistFragmentTestLanguageRoot result = this.parseHelper.parse("}} abc");
    Resource _eResource = result.eResource();
    final XtextResource res = ((XtextResource) _eResource);
    final InvariantChecker invariantChecker = new InvariantChecker();
    invariantChecker.checkInvariant(res.getParseResult().getRootNode());
    res.update(0, 0, "newArrayList()");
    invariantChecker.checkInvariant(res.getParseResult().getRootNode());
    final EObject first = IterableExtensions.<EObject>head(res.getContents());
    Assert.assertTrue(first.eClass().getName(), (first instanceof ContentAssistFragmentTestLanguageRoot));
    res.update("newArrayList(".length(), 0, "1");
    invariantChecker.checkInvariant(res.getParseResult().getRootNode());
    final EObject second = IterableExtensions.<EObject>head(res.getContents());
    Assert.assertTrue(second.eClass().getName(), (second instanceof ContentAssistFragmentTestLanguageRoot));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:21,代碼來源:Bug480686Test.java

示例3: testAllGrammarElementsUniqueAfterReparse

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testAllGrammarElementsUniqueAfterReparse() {
  try {
    final ContentAssistFragmentTestLanguageRoot result = this.parseHelper.parse("");
    Resource _eResource = result.eResource();
    final XtextResource res = ((XtextResource) _eResource);
    res.update(0, 0, "newArrayList()");
    final ICompositeNode root = res.getParseResult().getRootNode();
    final HashSet<EObject> set = CollectionLiterals.<EObject>newHashSet();
    BidiTreeIterable<INode> _asTreeIterable = root.getAsTreeIterable();
    for (final INode node : _asTreeIterable) {
      if ((node instanceof ICompositeNode)) {
        EObject _grammarElement = ((ICompositeNode)node).getGrammarElement();
        boolean _tripleNotEquals = (_grammarElement != null);
        if (_tripleNotEquals) {
          Assert.assertTrue(((ICompositeNode)node).getGrammarElement().toString(), set.add(((ICompositeNode)node).getGrammarElement()));
        } else {
          Assert.fail("node without grammar element");
        }
      }
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:26,代碼來源:Bug480686Test.java

示例4: testBug273209_02

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=273209
 */
@Test public void testBug273209_02() throws Exception {
	with(XtextStandaloneSetup.class);
	String model = "grammar org.eclipse.Bug273209_01 with org.eclipse.xtext.common.Terminals \n" +
			"generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/partialParsing/Bug273209/2'\n" +
			"importa : \n" +
			"        name=ID;\n" +
			"Model : \n" +
			"        import;";
	XtextResource resource = getResourceFromStringAndExpect(model, 1);
	assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
	model = resource.getParseResult().getRootNode().getText();
	resource.update(model.indexOf("import;") + "import".length(), 1, "");
	assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
	model = resource.getParseResult().getRootNode().getText();
	resource.update(model.indexOf(" import") + " import".length(), 0, "a");
	assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
	model = resource.getParseResult().getRootNode().getText();
	resource.update(model.indexOf(" importa") + " importa".length(), 0, ";");
	assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:24,代碼來源:PartialParserTest.java

示例5: testCompareNodeModel_04

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testCompareNodeModel_04() {
  try {
    final ContentAssistFragmentTestLanguageRoot result = this.parseHelper.parse(((((("{  val Object o = \'foo\'    switch(o) {\n" + 
      "        String: \"\".  oString\n") + 
      "    }\n") + 
      "    switch(o) {\n") + 
      "        String: \"\"\n") + 
      "    }}"));
    Resource _eResource = result.eResource();
    final XtextResource res = ((XtextResource) _eResource);
    res.update(60, 1, "t");
    final ContentAssistFragmentTestLanguageRoot fresh = this.parseHelper.parse(((((("{  val Object o = \'foo\'    switch(o) {\n" + 
      "        String: \"\".  tString\n") + 
      "    }\n") + 
      "    switch(o) {\n") + 
      "        String: \"\"\n") + 
      "    }}"));
    Resource _eResource_1 = fresh.eResource();
    this.assertEqual(res.getParseResult(), ((XtextResource) _eResource_1).getParseResult());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:25,代碼來源:Bug480686Test.java

示例6: compareWithFullParse

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
protected void compareWithFullParse(String model, int offset, int length, String newText) throws Exception {
	XtextResource resource = getResourceFromStringAndExpect(model, UNKNOWN_EXPECTATION);
	resource.update(offset, length, newText);
	String text = resource.getParseResult().getRootNode().getText();
	XtextResource newResource = getResourceFromStringAndExpect(text, UNKNOWN_EXPECTATION);
	assertEquals(text, resource.getContents().size(), newResource.getContents().size());
	EcoreUtil.resolveAll(resource);
	EcoreUtil.resolveAll(newResource);
	for(int i = 0; i < resource.getContents().size(); i++) {
		assertEquals(text, EmfFormatter.objToStr(newResource.getContents().get(i)), EmfFormatter.objToStr(resource.getContents().get(i)));
	}
	
	ICompositeNode rootNode = resource.getParseResult().getRootNode();
	ICompositeNode newRootNode = newResource.getParseResult().getRootNode();
	Iterator<INode> iterator = rootNode.getAsTreeIterable().iterator();
	Iterator<INode> newIterator = newRootNode.getAsTreeIterable().iterator();
	while(iterator.hasNext()) {
		assertTrue(newIterator.hasNext());
		assertEqualNodes(text, iterator.next(), newIterator.next());
	}
	assertFalse(iterator.hasNext());
	assertFalse(newIterator.hasNext());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:24,代碼來源:Bug419429Test.java

示例7: testBug273209_03

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=273209
 */
@Test public void testBug273209_03() throws Exception {
	with(XtextStandaloneSetup.class);
	String model = "grammar org.eclipse.Bug273209_01 with org.eclipse.xtext.common.Terminals \n" +
			"generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/partialParsing/Bug273209/3'\n" +
			"Model : \n" +
			"        ('model' ':' name=ID ';'*);";
	XtextResource resource = getResourceFromString(model);
	assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
	model = resource.getParseResult().getRootNode().getText();
	resource.update(model.indexOf("*);") + 1, 2, "");
	assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
	model = resource.getParseResult().getRootNode().getText();
	resource.update(model.indexOf("*") + 1, 0, " ");
	assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
	model = resource.getParseResult().getRootNode().getText();
	resource.update(model.indexOf("* ") + 2, 0, ");");
	assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:22,代碼來源:PartialParserTest.java

示例8: testPartialParseConcreteRuleInnermostToken_01

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testPartialParseConcreteRuleInnermostToken_01() throws Exception {
	with(PartialParserTestLanguageStandaloneSetup.class);
	String model = 
			"container c1 {\n" +
			"  children {\n" +
			"    -> C ( ch1 )\n" +
			"  }" +
			"}";
	XtextResource resource = getResourceFromString(model);
	assertTrue(resource.getErrors().isEmpty());
	ICompositeNode root = resource.getParseResult().getRootNode();
	ILeafNode childrenLeaf = findLeafNodeByText(root, model, "children");
	ILeafNode ch1Leaf = findLeafNodeByText(root, model, "ch1");
	resource.update(model.indexOf("ch1") + 1, 1, "h");
	resource.update(model.indexOf("ch1") + 1, 1, "h");
	assertSame(root, resource.getParseResult().getRootNode());
	assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
	assertSame(ch1Leaf, findLeafNodeByText(root, model, "ch1"));
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:20,代碼來源:PartialParserTest.java

示例9: testPartialParseConcreteRuleInnermostToken_02

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testPartialParseConcreteRuleInnermostToken_02() throws Exception {
	with(PartialParserTestLanguageStandaloneSetup.class);
	String model = 
			"container c1 {\n" +
			"  children {\n" +
			"    -> C ( ch1 )\n" +
			"  }" +
			"}";
	XtextResource resource = getResourceFromString(model);
	assertTrue(resource.getErrors().isEmpty());
	ICompositeNode root = resource.getParseResult().getRootNode();
	ILeafNode childrenLeaf = findLeafNodeByText(root, model, "children");
	ILeafNode ch1Leaf = findLeafNodeByText(root, model, "ch1");
	// change the model and undo the change
	resource.update(model.indexOf("ch1") + 1, 1, "x");
	resource.update(model.indexOf("ch1") + 1, 1, "h");
	assertSame(root, resource.getParseResult().getRootNode());
	assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
	assertNotSame(ch1Leaf, findLeafNodeByText(root, model, "ch1"));
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:21,代碼來源:PartialParserTest.java

示例10: testPartialParseConcreteRuleInnerToken

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testPartialParseConcreteRuleInnerToken() throws Exception {
	with(PartialParserTestLanguageStandaloneSetup.class);
	String model = "container c1 {\n" +
			"  children {\n" +
			"    -> C ( ch1 )\n" +
			"  }" +
			"}";
	XtextResource resource = getResourceFromString(model);
	assertTrue(resource.getErrors().isEmpty());
	ICompositeNode root = resource.getParseResult().getRootNode();
	ILeafNode childrenLeaf = findLeafNodeByText(root, model, "children");
	ILeafNode cLeaf = findLeafNodeByText(root, model, "C");
	resource.update(model.indexOf("C"), 1, "C");
	resource.update(model.indexOf("C"), 1, "C");
	assertSame(root, resource.getParseResult().getRootNode());
	assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
	assertNotSame(cLeaf, findLeafNodeByText(root, model, "ch1"));
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:19,代碼來源:PartialParserTest.java

示例11: testPartialParseConcreteRuleFirstInnerToken_01

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testPartialParseConcreteRuleFirstInnerToken_01() throws Exception {
	with(PartialParserTestLanguageStandaloneSetup.class);
	String model = "container c1 {\n" +
			"  children {\n" +
			"    -> C ( ch1 )\n" +
			"  }" +
			"}";
	XtextResource resource = getResourceFromString(model);
	assertTrue(resource.getErrors().isEmpty());
	ICompositeNode root = resource.getParseResult().getRootNode();
	ILeafNode childrenLeaf = findLeafNodeByText(root, model, "children");
	ILeafNode arrowLeaf = findLeafNodeByText(root, model, "->");
	resource.update(model.indexOf("->"), 2, "->");
	resource.update(model.indexOf("->"), 2, "->");
	assertSame(root, resource.getParseResult().getRootNode());
	assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
	assertSame(arrowLeaf, findLeafNodeByText(root, model, "->"));
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:19,代碼來源:PartialParserTest.java

示例12: testPartialParseConcreteRuleFirstInnerToken_02

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testPartialParseConcreteRuleFirstInnerToken_02() throws Exception {
	with(PartialParserTestLanguageStandaloneSetup.class);
	String model = "container c1 {\n" +
			"  children {\n" +
			"    -> C ( ch1 )\n" +
			"  }" +
			"}";
	XtextResource resource = getResourceFromString(model);
	assertTrue(resource.getErrors().isEmpty());
	ICompositeNode root = resource.getParseResult().getRootNode();
	ILeafNode childrenLeaf = findLeafNodeByText(root, model, "children");
	ILeafNode arrowLeaf = findLeafNodeByText(root, model, "->");
	// change the model and undo the change
	resource.update(model.indexOf("->"), 2, "-> ");
	resource.update(model.indexOf("->"), 3, "->");
	assertSame(root, resource.getParseResult().getRootNode());
	assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
	assertNotSame(arrowLeaf, findLeafNodeByText(root, model, "->"));
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:20,代碼來源:PartialParserTest.java

示例13: testIssue219

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testIssue219() throws Exception {
	with(PartialParserTestLanguageStandaloneSetup.class);
	String model = "container c1 {\n" + "  children {\n" + "-> C ( ch1 )\n" + "  }" + "}";
	XtextResource resource = getResourceFromString(model);
	assertTrue(resource.getErrors().isEmpty());
	((PartialParsingHelper) ((AbstractAntlrParser) resource.getParser()).getPartialParser())
			.setTokenRegionProvider(null);
	resource.update(model.indexOf("ch1") + 1, 1, "x");
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:11,代碼來源:PartialParsingHelperIssue219Test.java

示例14: testCompareNodeModel_01

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testCompareNodeModel_01() {
  try {
    final ContentAssistFragmentTestLanguageRoot result = this.parseHelper.parse("");
    Resource _eResource = result.eResource();
    final XtextResource res = ((XtextResource) _eResource);
    res.update(0, 0, "newArrayList()");
    final ContentAssistFragmentTestLanguageRoot fresh = this.parseHelper.parse("newArrayList()");
    Resource _eResource_1 = fresh.eResource();
    this.assertEqual(res.getParseResult(), ((XtextResource) _eResource_1).getParseResult());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:15,代碼來源:Bug480686Test.java

示例15: testBug486454

import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test public void testBug486454() throws Exception {
	with(SimpleExpressionsTestLanguageStandaloneSetup.class);
	String model = "tim";
	XtextResource resource = getResourceFromString(model);
	resource.update(1, 2, "");
	assertEquals("t", resource.getParseResult().getRootNode().getText());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:8,代碼來源:PartialParserTest.java


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