Java Code Examples for org.eclipse.xtext.testing.util.ParseHelper#parse()
The following examples show how to use
org.eclipse.xtext.testing.util.ParseHelper#parse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug776Test.java From sarl with Apache License 2.0 | 6 votes |
@Test public void parsing_08() throws Exception { ParseHelper<SarlScript> parser = getParseHelper(); SarlScript mas1 = parser.parse(multilineString( "package io.sarl.lang.tests.bug776.b", "class Toto{}")); SarlScript mas2 = parser.parse(multilineString( "package io.sarl.lang.tests.bug776", "import io.sarl.lang.tests.bug776.b.Toto", "class X {", "}", "class Y extends Z {", " static class YX {", " var a : Toto", " }", "}", "class Z {", "}", ""), mas1.eResource().getResourceSet()); XtendClass container = ((XtendClass) mas2.getXtendTypes().get(1).getMembers().get(0)); JvmTypeReference typeRef = ((SarlField) container.getMembers().get(0)).getType(); assertEquals("Toto", this.strings.referenceToString(typeRef, "Object")); }
Example 2
Source File: Bug661Test.java From sarl with Apache License 2.0 | 6 votes |
@RepeatedTest(5) public void isSubtypeOf_01() throws Exception { ParseHelper<SarlScript> helper = getParseHelper(); SarlScript mas0 = helper.parse(SNIPSET1); ResourceSet resourceSet = mas0.eResource().getResourceSet(); SarlScript mas1 = helper.parse(SNIPSET1, resourceSet); assertSame(mas0.eResource().getResourceSet(), mas1.eResource().getResourceSet()); JvmTypeReference reference0 = this.typeReferences.getTypeForName("boolean", mas0); StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, mas1); LightweightTypeReference reference1 = owner.newParameterizedTypeReference(this.typeReferences.findDeclaredType("boolean", mas1)); assertTrue(reference1.isSubtypeOf(reference0.getType())); }
Example 3
Source File: Bug661Test.java From sarl with Apache License 2.0 | 6 votes |
@RepeatedTest(5) public void isAssignableFrom_01() throws Exception { ParseHelper<SarlScript> helper = getParseHelper(); SarlScript mas0 = helper.parse(SNIPSET1); ResourceSet resourceSet = mas0.eResource().getResourceSet(); SarlScript mas1 = helper.parse(SNIPSET1, resourceSet); assertSame(mas0.eResource().getResourceSet(), mas1.eResource().getResourceSet()); JvmTypeReference reference0 = this.typeReferences.getTypeForName("boolean", mas0); StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, mas1); LightweightTypeReference reference1 = owner.newParameterizedTypeReference(this.typeReferences.findDeclaredType("boolean", mas1)); assertTrue(reference1.isAssignableFrom(reference0.getType())); }
Example 4
Source File: AnotherFormatterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void loadModel() { try { final ParseHelper<Root> parseHelper = this.getInjector().<ParseHelper<Root>>getInstance(Key.<ParseHelper<Root>>get(new TypeLiteral<ParseHelper<Root>>() { })); final INodeModelFormatter formatter = this.getInjector().<INodeModelFormatter>getInstance(INodeModelFormatter.class); StringConcatenation _builder = new StringConcatenation(); _builder.append("test sample {"); _builder.newLine(); _builder.append("// just a comment"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final Root root = parseHelper.parse(_builder); Assert.assertNotNull(root); final EList<Resource.Diagnostic> errors = root.eResource().getErrors(); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("Unexpected errors: "); String _join = IterableExtensions.join(errors, ", "); _builder_1.append(_join); Assert.assertTrue(_builder_1.toString(), errors.isEmpty()); Resource _eResource = root.eResource(); ICompositeNode rootNode = ((XtextResource) _eResource).getParseResult().getRootNode(); StringConcatenation _builder_2 = new StringConcatenation(); _builder_2.append("test sample {"); _builder_2.newLine(); _builder_2.newLine(); _builder_2.append("// just a comment"); _builder_2.newLine(); _builder_2.append("}"); final String expected = _builder_2.toString(); INodeModelFormatter.IFormattedRegion formattedRegion = formatter.format(rootNode, rootNode.getTotalOffset(), rootNode.getTotalLength()); Assert.assertEquals(expected, formattedRegion.getFormattedText()); formattedRegion = formatter.format(rootNode, rootNode.getTotalOffset(), rootNode.getTotalLength()); Assert.assertEquals(expected, formattedRegion.getFormattedText()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 5
Source File: OperatorExtensions.java From sarl with Apache License 2.0 | 2 votes |
/** Parse the given SARL code and replies the EMF tree. * * @param code the SARL code to parse and convert to EMF. * @return the EMF tree. * @throws Exception if the code cannot be parsed. */ private static SarlScript scriptToEMF(String code) throws Exception { final ParseHelper<SarlScript> parser = getParseHelper(); return parser.parse(code); }