org.eclipse.xtext.testing.util.ParseHelper Java Examples
The following examples show how to use
org.eclipse.xtext.testing.util.ParseHelper.
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: 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 #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: 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 #4
Source File: FormatterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void serializeToTokenBuffer(String model, ITokenStream out) throws Exception { EObject semanticObject = get(ParseHelper.class).parse(model); ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR; ISemanticSequencer semantic = get(ISemanticSequencer.class); ISyntacticSequencer syntactic = get(ISyntacticSequencer.class); IHiddenTokenSequencer hidden = get(IHiddenTokenSequencer.class); TokenStreamSequenceAdapter tokenstream = new TokenStreamSequenceAdapter(out, getGrammarAccess().getGrammar(), errors); semantic.init((ISemanticSequenceAcceptor) syntactic, errors); ISerializationContext context = new SerializationContext.RuleContext(null, (ParserRule) get(IGrammarAccess.class).getGrammar().getRules().get(0)); syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors); hidden.init(context, semanticObject, tokenstream, errors); tokenstream.init(context); semantic.createSequence(context, semanticObject); }
Example #5
Source File: TestEObjects.java From sarl with Apache License 2.0 | 5 votes |
/** Create an instance of class. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the content of the file. * @param resourceSet the set of resources in which the file is created. * @return the SARL script extracted from the file content. * @since 0.9 */ public static SarlScript file(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string, ResourceSet resourceSet) throws Exception { assert parser != null; SarlScript script; if (resourceSet == null) { script = parser.parse(string); } else { script = parser.parse(string, resourceSet); } if (validationHelper != null) { Resource resource = script.eResource(); ResourceSet resourceSet0 = resource.getResourceSet(); if (resourceSet0 instanceof XtextResourceSet) { ((XtextResourceSet) resourceSet0).setClasspathURIContext(TestEObjects.class); } assertEquals(0, resource.getErrors().size(), () -> resource.getErrors().toString()); Collection<Issue> issues = Collections2.filter(issues(validationHelper, resource), new Predicate<Issue>() { @Override public boolean apply(Issue input) { return input.getSeverity() == Severity.ERROR; } }); assertTrue(issues.isEmpty(), () -> "Resource contained errors : " + issues.toString()); } return script; }
Example #6
Source File: ResourceSetGlobalCompilationContext.java From sarl with Apache License 2.0 | 5 votes |
/** Constructor. * * @param basePackage the name of the package that is the root for all the resources. * @param injector the injector. * @param parser the SARL parser. * @param validator the validator. */ ResourceSetGlobalCompilationContext(String basePackage, Injector injector, ParseHelper<SarlScript> parser, SarlValidationTestHelper validator) { assert basePackage != null; assert injector != null; assert parser != null; assert validator != null; this.basePackage = basePackage; this.injector = injector; this.parser = parser; this.validator = validator; }
Example #7
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 #8
Source File: OperatorExtensions.java From sarl with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private static ParseHelper<SarlScript> getParseHelper() { if (parser == null) { parser = (Provider) getInjector().getProvider(ParseHelper.class); loggerOff(ProcessorInstanceForJvmTypeProvider.class, "logger"); //$NON-NLS-1$ } return parser.get(); }
Example #9
Source File: N4JSStandaloneTestsModule.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** */ public Class<? extends ParseHelper<Script>> bindParseHelperScript() { return SmokeTestWriter.class; }
Example #10
Source File: TestEObjects.java From sarl with Apache License 2.0 | 3 votes |
/** Create a type reference with the SARL parser. * * @param parser the SARL parser. * @param typeName the fully qualified name of the type. * @param prefix the set of lines to put before the class declaration of the function. * @return the type reference. */ public static JvmTypeReference getType(ParseHelper<SarlScript> parser, String typeName, String... prefix) throws Exception { SarlAgent agent = agent(parser, IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator()) + TestUtils.getLineSeparator() + "agent Foo { var fooAttr : " + typeName + " }"); return ((SarlField) agent.getMembers().get(0)).getType(); }
Example #11
Source File: TestEObjects.java From sarl with Apache License 2.0 | 3 votes |
/** Create an instance of behavior unit. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the SARL behavior unit. */ public static SarlBehaviorUnit behaviorUnit(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string, String... prefix) throws Exception { SarlAgent agent = agent(parser, validationHelper, IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator()) + TestUtils.getLineSeparator() + "agent Foo { " + string + "}"); return (SarlBehaviorUnit) agent.getMembers().get(0); }
Example #12
Source File: TestEObjects.java From sarl with Apache License 2.0 | 3 votes |
/** Create an instance of field. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the SARL field. */ public static SarlField field(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string, String... prefix) throws Exception { SarlClass clazz = clazz(parser, validationHelper, IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator()) + TestUtils.getLineSeparator() + "class Foo { " + string + "}"); return (SarlField) clazz.getMembers().get(0); }
Example #13
Source File: TestEObjects.java From sarl with Apache License 2.0 | 3 votes |
/** Create an instance of function. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the SARL function. */ public static SarlAction function(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string, String... prefix) throws Exception { SarlClass clazz = clazz(parser, validationHelper, IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator()) + TestUtils.getLineSeparator() + "class Foo { " + string + "}"); return (SarlAction) clazz.getMembers().get(0); }
Example #14
Source File: TestEObjects.java From sarl with Apache License 2.0 | 3 votes |
/** Create an instance of JVM constructor. * * @param parser the SARL parser. * @param associations the provider of associations between the JVM and the SARL Ecores. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the JVM constructor. */ public static JvmConstructor jvmConstructor(ParseHelper<SarlScript> parser, Provider<SarlJvmModelAssociations> associations, ValidationTestHelper validationHelper, String string, String... prefix) throws Exception { assert associations != null; SarlConstructor constructor = constructor(parser, validationHelper, string, prefix); return (JvmConstructor) associations.get().getPrimaryJvmElement(constructor); }
Example #15
Source File: TestEObjects.java From sarl with Apache License 2.0 | 3 votes |
/** Create an instance of constructor. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the SARL constructor. */ public static SarlConstructor constructor(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string, String... prefix) throws Exception { SarlClass clazz = clazz(parser, validationHelper, IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator()) + TestUtils.getLineSeparator() + "class Foo { " + string + "}"); return (SarlConstructor) clazz.getMembers().get(0); }
Example #16
Source File: TestEObjects.java From sarl with Apache License 2.0 | 3 votes |
/** Create an instance of JVM function. * * @param parser the SARL parser. * @param associations the provider of associations between the JVM and the SARL Ecores. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the JVM operation. */ public static JvmOperation jvmOperation(ParseHelper<SarlScript> parser, Provider<SarlJvmModelAssociations> associations, ValidationTestHelper validationHelper, String string, String... prefix) throws Exception { assert associations != null; SarlAction action = function(parser, validationHelper, string, prefix); return (JvmOperation) associations.get().getPrimaryJvmElement(action); }
Example #17
Source File: TestEObjects.java From sarl with Apache License 2.0 | 3 votes |
/** Create an instance of JVM function. * * @param parser the SARL parser. * @param associations the provider of associations between the JVM and the SARL Ecores. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the JVM operation signature. */ public static JvmOperation jvmOperationSignature(ParseHelper<SarlScript> parser, Provider<SarlJvmModelAssociations> associations, ValidationTestHelper validationHelper, String string, String... prefix) throws Exception { assert associations != null; SarlAction action = functionSignature(parser, validationHelper, string, prefix); return (JvmOperation) associations.get().getPrimaryJvmElement(action); }
Example #18
Source File: TestEObjects.java From sarl with Apache License 2.0 | 3 votes |
/** Create an instance of function signature. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the SARL action. */ public static SarlAction functionSignature(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string, String... prefix) throws Exception { SarlInterface interfaze = interfaze(parser, validationHelper, IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator()) + TestUtils.getLineSeparator() + "interface Foo { " + string + "}"); return (SarlAction) interfaze.getMembers().get(0); }
Example #19
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of enumeration. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @return the SARL enumeration. */ public static SarlEnumeration enumeration(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception { List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes(); return (SarlEnumeration) decls.get(decls.size() - 1); }
Example #20
Source File: AbstractSarlTest.java From sarl with Apache License 2.0 | 2 votes |
/** Replies the parse helper. * * @return the parse helper. * @since 0.7 */ protected ParseHelper<SarlScript> getParseHelper() { return this.parser; }
Example #21
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of JVM function. * * @param parser the SARL parser. * @param associations the provider of associations between the JVM and the SARL Ecores. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the JVM operation. */ public static JvmOperation jvmOperation(ParseHelper<SarlScript> parser, Provider<SarlJvmModelAssociations> associations, String string, String... prefix) throws Exception { return jvmOperation(parser, associations, null, string, prefix); }
Example #22
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of function signature. * * @param parser the SARL parser. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the SARL action. */ public static SarlAction functionSignature(ParseHelper<SarlScript> parser, String string, String... prefix) throws Exception { return functionSignature(parser, null, string, prefix); }
Example #23
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of JVM function. * * @param parser the SARL parser. * @param associations the provider of associations between the JVM and the SARL Ecores. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the JVM operation signature. */ public static JvmOperation jvmOperationSignature(ParseHelper<SarlScript> parser, Provider<SarlJvmModelAssociations> associations, String string, String... prefix) throws Exception { return jvmOperationSignature(parser, associations, null, string, prefix); }
Example #24
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of constructor. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the SARL constructor. */ public static SarlConstructor constructor(ParseHelper<SarlScript> parser, String string, String... prefix) throws Exception { return constructor(parser, null, string, prefix); }
Example #25
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of JVM constructor. * * @param parser the SARL parser. * @param associations the provider of associations between the JVM and the SARL Ecores. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the JVM constructor. */ public static JvmConstructor jvmConstructor(ParseHelper<SarlScript> parser, Provider<SarlJvmModelAssociations> associations, String string, String... prefix) throws Exception { return jvmConstructor(parser, associations, null, string, prefix); }
Example #26
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of field. * * @param parser the SARL parser. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the SARL field. */ public static SarlField field(ParseHelper<SarlScript> parser, String string, String... prefix) throws Exception { return field(parser, null, string, prefix); }
Example #27
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of behavior unit. * * @param parser the SARL parser. * @param string the file content to parse. * @param prefix the set of lines to put before the class declaration of the function. * @return the SARL behavior unit. */ public static SarlBehaviorUnit behaviorUnit(ParseHelper<SarlScript> parser, String string, String... prefix) throws Exception { return behaviorUnit(parser, null, string, prefix); }
Example #28
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of skill. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the file content to parse. * @return the SARL skill. */ public static SarlSkill skill(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception { List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes(); return (SarlSkill) decls.get(decls.size() - 1); }
Example #29
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); }
Example #30
Source File: TestEObjects.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of class. * * @param parser the SARL parser. * @param validationHelper the validation test helper. If it is {@code null}, no validation. * @param string the content of the file. * @return the SARL script extracted from the file content. */ public static SarlScript file(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception { return file(parser, validationHelper, string, null); }