org.eclipse.xtext.XtextFactory Java Examples
The following examples show how to use
org.eclipse.xtext.XtextFactory.
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: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug_282852_08() throws Exception { Grammar base = XtextFactory.eINSTANCE.createGrammar(); AbstractRule ruleFoo = XtextFactory.eINSTANCE.createParserRule(); ruleFoo.setName("Foo"); base.getRules().add(ruleFoo); AbstractRule subRuleFoo = XtextFactory.eINSTANCE.createParserRule(); subRuleFoo.setName("foo"); AbstractRule subRuleFoo2 = XtextFactory.eINSTANCE.createParserRule(); subRuleFoo2.setName("fOO"); AbstractRule subRuleFoo3 = XtextFactory.eINSTANCE.createParserRule(); subRuleFoo3.setName("FOO"); base.getRules().add(subRuleFoo); base.getRules().add(subRuleFoo2); base.getRules().add(subRuleFoo3); XtextValidator validator = get(XtextValidator.class); configureValidator(validator, this, subRuleFoo); validator.checkRuleName(subRuleFoo); assertEquals("A rule's name has to be unique even case insensitive. The conflicting rules are 'FOO', 'Foo' and 'fOO'.", lastMessage); }
Example #2
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug_282852_07() throws Exception { Grammar base = XtextFactory.eINSTANCE.createGrammar(); AbstractRule ruleFoo = XtextFactory.eINSTANCE.createParserRule(); ruleFoo.setName("Foo"); base.getRules().add(ruleFoo); AbstractRule subRuleFoo = XtextFactory.eINSTANCE.createParserRule(); subRuleFoo.setName("foo"); AbstractRule subRuleFoo2 = XtextFactory.eINSTANCE.createParserRule(); subRuleFoo2.setName("Foo"); AbstractRule subRuleFoo3 = XtextFactory.eINSTANCE.createParserRule(); subRuleFoo3.setName("FOO"); base.getRules().add(subRuleFoo); base.getRules().add(subRuleFoo2); base.getRules().add(subRuleFoo3); XtextValidator validator = get(XtextValidator.class); configureValidator(validator, this, subRuleFoo); validator.checkRuleName(subRuleFoo); assertEquals("A rule's name has to be unique even case insensitive. The conflicting rules are 'FOO' and 'Foo'.", lastMessage); }
Example #3
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug_282852_04() throws Exception { Grammar base = XtextFactory.eINSTANCE.createGrammar(); Grammar child = XtextFactory.eINSTANCE.createGrammar(); child.getUsedGrammars().add(base); AbstractRule ruleFoo = XtextFactory.eINSTANCE.createParserRule(); ruleFoo.setName("Foo"); base.getRules().add(ruleFoo); AbstractRule subRuleFoo = XtextFactory.eINSTANCE.createParserRule(); subRuleFoo.setName("foo"); child.getRules().add(subRuleFoo); XtextValidator validator = get(XtextValidator.class); configureValidator(validator, this, subRuleFoo); validator.checkRuleName(subRuleFoo); assertEquals("A rule's name has to be unique even case insensitive. A used grammar contains another rule 'Foo'.", lastMessage); }
Example #4
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug_282852_03() throws Exception { Grammar base = XtextFactory.eINSTANCE.createGrammar(); Grammar child = XtextFactory.eINSTANCE.createGrammar(); child.getUsedGrammars().add(base); AbstractRule ruleFoo = XtextFactory.eINSTANCE.createParserRule(); ruleFoo.setName("Foo"); base.getRules().add(ruleFoo); AbstractRule subRuleFoo = XtextFactory.eINSTANCE.createParserRule(); subRuleFoo.setName("Foo"); child.getRules().add(subRuleFoo); XtextValidator validator = get(XtextValidator.class); validator.setMessageAcceptor(this); validator.checkRuleName(subRuleFoo); assertNull(lastMessage); }
Example #5
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testCheckRuleCallInUnorderedGroup_05() throws Exception { XtextValidator validator = get(XtextValidator.class); UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup(); RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall(); TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef(); typeRef.setClassifier(EcorePackage.Literals.EOBJECT); ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setType(typeRef); ruleCall.setRule(parserRule); Assignment assignment = XtextFactory.eINSTANCE.createAssignment(); assignment.setTerminal(ruleCall); unorderedGroup.getElements().add(assignment); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false); validator.setMessageAcceptor(messageAcceptor); validator.checkRuleCallInUnorderedGroup(ruleCall); messageAcceptor.validate(); }
Example #6
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCheckCrossReferenceTerminal_05() throws Exception { XtextValidator validator = get(XtextValidator.class); CrossReference reference = XtextFactory.eINSTANCE.createCrossReference(); Keyword keyword = XtextFactory.eINSTANCE.createKeyword(); reference.setTerminal(keyword); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false); validator.setMessageAcceptor(messageAcceptor); validator.checkCrossReferenceTerminal(reference); messageAcceptor.validate(); }
Example #7
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCheckCrossReferenceTerminal_01() throws Exception { XtextValidator validator = get(XtextValidator.class); CrossReference reference = XtextFactory.eINSTANCE.createCrossReference(); RuleCall call = XtextFactory.eINSTANCE.createRuleCall(); reference.setTerminal(call); ParserRule rule = XtextFactory.eINSTANCE.createParserRule(); call.setRule(rule); TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef(); rule.setType(typeRef); typeRef.setClassifier(EcorePackage.Literals.ESTRING); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false); validator.setMessageAcceptor(messageAcceptor); validator.checkCrossReferenceTerminal(reference); messageAcceptor.validate(); }
Example #8
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCheckActionInUnorderedGroup_01() throws Exception { XtextValidator validator = get(XtextValidator.class); UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup(); Action action = XtextFactory.eINSTANCE.createAction(); unorderedGroup.getElements().add(action); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(action, true, false); configureValidator(validator, messageAcceptor, action); validator.checkActionInUnorderedGroup(action); messageAcceptor.validate(); }
Example #9
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCheckRuleCallInUnorderedGroup_01() throws Exception { XtextValidator validator = get(XtextValidator.class); UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup(); RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall(); TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef(); typeRef.setClassifier(EcorePackage.Literals.EOBJECT); ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setType(typeRef); ruleCall.setRule(parserRule); unorderedGroup.getElements().add(ruleCall); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(ruleCall, true, false); validator.setMessageAcceptor(messageAcceptor); validator.checkRuleCallInUnorderedGroup(ruleCall); messageAcceptor.validate(); }
Example #10
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCheckRuleCallInUnorderedGroup_02() throws Exception { XtextValidator validator = get(XtextValidator.class); UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup(); RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall(); TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef(); typeRef.setClassifier(EcorePackage.Literals.EBIG_DECIMAL); ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setType(typeRef); ruleCall.setRule(parserRule); unorderedGroup.getElements().add(ruleCall); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false); validator.setMessageAcceptor(messageAcceptor); validator.checkRuleCallInUnorderedGroup(ruleCall); messageAcceptor.validate(); }
Example #11
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCheckRuleCallInUnorderedGroup_03() throws Exception { XtextValidator validator = get(XtextValidator.class); UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup(); RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall(); EnumRule enumRule = XtextFactory.eINSTANCE.createEnumRule(); ruleCall.setRule(enumRule); unorderedGroup.getElements().add(ruleCall); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false); validator.setMessageAcceptor(messageAcceptor); validator.checkRuleCallInUnorderedGroup(ruleCall); messageAcceptor.validate(); }
Example #12
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCheckRuleCallInUnorderedGroup_04() throws Exception { XtextValidator validator = get(XtextValidator.class); UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup(); RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall(); TerminalRule terminalRule = XtextFactory.eINSTANCE.createTerminalRule(); ruleCall.setRule(terminalRule); unorderedGroup.getElements().add(ruleCall); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false); validator.setMessageAcceptor(messageAcceptor); validator.checkRuleCallInUnorderedGroup(ruleCall); messageAcceptor.validate(); }
Example #13
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug318424_01() throws Exception { XtextValidator validator = get(XtextValidator.class); CrossReference reference = XtextFactory.eINSTANCE.createCrossReference(); TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef(); reference.setType(typeRef); typeRef.setClassifier(EcorePackage.Literals.EBOOLEAN); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(typeRef, true, false); validator.setMessageAcceptor(messageAcceptor); validator.checkCrossReferenceType(reference); messageAcceptor.validate(); }
Example #14
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug318424_02() throws Exception { XtextValidator validator = get(XtextValidator.class); Action action = XtextFactory.eINSTANCE.createAction(); TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef(); action.setType(typeRef); typeRef.setClassifier(EcorePackage.Literals.EBOOLEAN); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(typeRef, true, false); validator.setMessageAcceptor(messageAcceptor); validator.checkInstantiatedType(action); messageAcceptor.validate(); }
Example #15
Source File: CrossContainmentTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCrossContainment_01() { XtextResourceSet resourceSet = get(XtextResourceSet.class); resourceSet.setClasspathURIContext(getClass()); Resource resource = resourceSet.createResource(URI.createFileURI("container.xmi")); Resource childResource = resourceSet.createResource(URI.createFileURI("child.xmi")); CrossResourceContainerManyChildren container = PartialParsingTestUtilFactory.eINSTANCE.createCrossResourceContainerManyChildren(); resource.getContents().add(container); Grammar grammar = XtextFactory.eINSTANCE.createGrammar(); childResource.getContents().add(grammar); assertNull(grammar.eContainer()); container.getChildren().add(grammar); assertSame(container, grammar.eContainer()); assertSame(childResource, grammar.eResource()); assertSame(resource, container.eResource()); }
Example #16
Source File: CrossContainmentTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCrossContainment_02() { XtextResourceSet resourceSet = get(XtextResourceSet.class); resourceSet.setClasspathURIContext(getClass()); Resource resource = resourceSet.createResource(URI.createFileURI("container.xmi")); Resource childResource = resourceSet.createResource(URI.createFileURI("child.xmi")); CrossResourceContainerOneChild container = PartialParsingTestUtilFactory.eINSTANCE.createCrossResourceContainerOneChild(); resource.getContents().add(container); Grammar grammar = XtextFactory.eINSTANCE.createGrammar(); childResource.getContents().add(grammar); assertNull(grammar.eContainer()); container.setChild(grammar); assertSame(container, grammar.eContainer()); assertSame(childResource, grammar.eResource()); assertSame(resource, container.eResource()); }
Example #17
Source File: ParseErrorHandlingTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testExpectNoSuchMethodException() throws Exception { IParser parser = get(IParser.class); ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setName("ruleDoesNotExist"); try { parser.parse(parserRule, new StringReader("empty")); fail("Expected WrappedException"); } catch(ParseException e) { assertTrue(e.getCause() instanceof WrappedException); WrappedException cause = (WrappedException) e.getCause(); assertTrue(cause.getCause() instanceof NoSuchMethodException); } }
Example #18
Source File: LazyLinkerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); with(new AbstractModule() { @Override protected void configure() { bind(EPackage.Registry.class).toInstance(EPackage.Registry.INSTANCE); bind(IGrammarAccess.class).toInstance(new IGrammarAccess() { @Override public List<Pair<Keyword, Keyword>> findKeywordPairs(String leftKw, String rightKw) { return Collections.emptyList(); } @Override public List<Keyword> findKeywords(String... keywords) { return Collections.emptyList(); } @Override public List<RuleCall> findRuleCalls(AbstractRule... rules) { return Collections.emptyList(); } @Override public Grammar getGrammar() { return XtextFactory.eINSTANCE.createGrammar(); } }); } }); linker = get(LazyLinker.class); resourceSet = get(XtextResourceSet.class); resourceSet.setClasspathURIContext(getClass()); lazyLinkingPackage = (EPackage) resourceSet.getResource( URI.createURI("classpath:/org/eclipse/xtext/linking/lazy/LazyLinking.ecore"), true).getContents().get(0); }
Example #19
Source File: LazyLinkerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private INode newCrossReferenceAssignmentNode(final String feature) { final LeafNode leafNode = new LeafNode(); final Assignment assignment = XtextFactory.eINSTANCE.createAssignment(); assignment.setFeature(feature); final CrossReference crossReference = XtextFactory.eINSTANCE.createCrossReference(); assignment.setTerminal(crossReference); leafNode.basicSetGrammarElement(crossReference); return leafNode; }
Example #20
Source File: AbstractSGenTest.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected EObject parseExpression(String expression, String ruleName) { XtextResource resource = resourceProvider.get(); resource.setURI(URI.createPlatformPluginURI("path", true)); ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setName(ruleName); IParseResult result = parser.parse(parserRule, new StringReader( expression)); EObject rootASTElement = result.getRootASTElement(); resource.getContents().add(rootASTElement); ListBasedDiagnosticConsumer diagnosticsConsumer = new ListBasedDiagnosticConsumer(); linker.linkModel(result.getRootASTElement(), diagnosticsConsumer); if (result.hasSyntaxErrors()) { StringBuilder errorMessages = new StringBuilder(); Iterable<INode> syntaxErrors = result.getSyntaxErrors(); for (INode iNode : syntaxErrors) { errorMessages.append(iNode.getSyntaxErrorMessage()); errorMessages.append("\n"); } throw new RuntimeException( "Could not parse expression, syntax errors: " + errorMessages); } if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) { throw new RuntimeException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR)); } return rootASTElement; }
Example #21
Source File: STextExpressionParser.java From statecharts with Eclipse Public License 1.0 | 5 votes |
public EObject parseExpression(String expression, String ruleName, String specification) { StextResource resource = getResource(); resource.setURI(URI.createPlatformResourceURI(getUri(), true)); ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setName(ruleName); IParseResult result = parser.parse(parserRule, new StringReader(expression)); EObject rootASTElement = result.getRootASTElement(); resource.getContents().add(rootASTElement); ListBasedDiagnosticConsumer diagnosticsConsumer = new ListBasedDiagnosticConsumer(); Statechart sc = SGraphFactory.eINSTANCE.createStatechart(); sc.setDomainID(domainId); sc.setName("sc"); if (specification != null) { sc.setSpecification(specification); } resource.getContents().add(sc); resource.getLinkingDiagnostics().clear(); linker.linkModel(sc, diagnosticsConsumer); linker.linkModel(rootASTElement, diagnosticsConsumer); resource.resolveLazyCrossReferences(CancelIndicator.NullImpl); resource.resolveLazyCrossReferences(CancelIndicator.NullImpl); Multimap<SpecificationElement, Diagnostic> diagnostics = resource.getLinkingDiagnostics(); if (diagnostics.size() > 0) { throw new LinkingException(diagnostics.toString()); } if (result.hasSyntaxErrors()) { StringBuilder errorMessages = new StringBuilder(); Iterable<INode> syntaxErrors = result.getSyntaxErrors(); for (INode iNode : syntaxErrors) { errorMessages.append(iNode.getSyntaxErrorMessage()); errorMessages.append("\n"); } throw new SyntaxException("Could not parse expression, syntax errors: " + errorMessages); } if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) { throw new LinkingException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR)); } return rootASTElement; }
Example #22
Source File: AbstractSCTResource.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected IParseResult parse(SpecificationElement element, String rule) { ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setName(rule); String specification = element.getSpecification(); IParseResult result = parser.parse(parserRule, new StringReader(specification != null ? specification : "")); createDiagnostics(result, element); return result; }
Example #23
Source File: DefaultEObjectLabelProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetStyledTextFallbackText() throws Exception { DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider(); ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setName("testCreateStyledString"); StyledString styledText = defaultLabelProvider.getStyledText(parserRule); assertEquals("testCreateStyledString", styledText.getString()); }
Example #24
Source File: AbstractTextEditComposerTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testObjectAddition() throws Exception { Resource res = getResource(newTestGrammar()); composer.beginRecording(res); Grammar grammar = (Grammar) res.getContents().get(0); ParserRule rule = (ParserRule) grammar.getRules().get(0); Alternatives alternatives = (Alternatives) rule.getAlternatives(); Keyword keyword = XtextFactory.eINSTANCE.createKeyword(); keyword.setValue("qux"); alternatives.getElements().add(keyword); TextEdit edit = composer.endRecording(); assertMatches("'foo' | 'bar' | 'baz' | \"qux\"", edit); }
Example #25
Source File: AbstractTextEditComposerTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testObjectReplacement() throws Exception { Resource res = getResource(newTestGrammar()); composer.beginRecording(res); Grammar grammar = (Grammar) res.getContents().get(0); ParserRule rule = (ParserRule) grammar.getRules().get(0); Keyword keyword = XtextFactory.eINSTANCE.createKeyword(); keyword.setValue("baz"); rule.setAlternatives(keyword); TextEdit edit = composer.endRecording(); assertMatches("Foo: \"baz\";", edit); }
Example #26
Source File: XtextProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void completeParserRule(EObject model, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) { final Grammar grammar = GrammarUtil.getGrammar(model); for (AbstractMetamodelDeclaration metamodelDeclaration : grammar.getMetamodelDeclarations()) { if (metamodelDeclaration instanceof ReferencedMetamodel) { ReferencedMetamodel referencedMetamodel = (ReferencedMetamodel) metamodelDeclaration; EPackage ePackage = referencedMetamodel.getEPackage(); if (ePackage != null) { for (EClassifier eClassifier : ePackage.getEClassifiers()) { if (isProposeParserRule(eClassifier, grammar)) { String proposal = eClassifier.getName(); String metamodelAlias = referencedMetamodel.getAlias(); if (metamodelAlias != null) { proposal = proposal + " returns " + metamodelAlias + "::" + eClassifier.getName(); } proposal = proposal + ": \n;\n"; ConfigurableCompletionProposal completionProposal = (ConfigurableCompletionProposal) createCompletionProposal( proposal, eClassifier.getName() + " - parser rule", getImage(XtextFactory.eINSTANCE.createParserRule()), context); if (completionProposal != null) { completionProposal.setCursorPosition(proposal.length() - 3); acceptor.accept(completionProposal); } } } } } } }
Example #27
Source File: XtextGrammarQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Fix(EMPTY_ENUM_LITERAL) public void fixEmptyEnumLiteral(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.acceptMulti(issue, "Fix empty enum literal", "Fix empty enum literal", NULL_QUICKFIX_IMAGE, (EObject element) -> { EnumLiteralDeclaration enumLiteralDeclaration = (EnumLiteralDeclaration) element; Keyword keyword = XtextFactory.eINSTANCE.createKeyword(); keyword.setValue(enumLiteralDeclaration.getEnumLiteral().getName().toLowerCase()); enumLiteralDeclaration.setLiteral(keyword); }); }
Example #28
Source File: Xtext2EcoreTransformer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
TypeRef getTypeRef(EClassifier classifier) { TypeRef result = XtextFactory.eINSTANCE.createTypeRef(); result.setClassifier(classifier); EPackage pack = classifier.getEPackage(); for(AbstractMetamodelDeclaration decl: GrammarUtil.allMetamodelDeclarations(grammar)) { if (pack.equals(decl.getEPackage())) { result.setMetamodel(decl); return result; } } return result; }
Example #29
Source File: Xtext2EcoreTransformer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
TypeRef getTypeRef(String qualifiedName) { TypeRef result = XtextFactory.eINSTANCE.createTypeRef(); String[] split = qualifiedName.split("::"); String name = qualifiedName; if (split.length > 1) { result.setMetamodel(findMetamodel(grammar, split[0], split[1])); name = split[1]; } else { result.setMetamodel(findDefaultMetamodel(grammar, qualifiedName)); } if (result.getMetamodel() instanceof ReferencedMetamodel && result.getMetamodel().getEPackage() != null) { result.setClassifier(result.getMetamodel().getEPackage().getEClassifier(name)); } return result; }
Example #30
Source File: FirstSetComputationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void assertFirstSet(String expectation, AbstractRule rule) { RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall(); ruleCall.setRule(rule); List<AbstractElement> firstSet = AntlrGrammarGenUtil.getFirstSet(ruleCall); StringBuilder actual = new StringBuilder(); GrammarElementTitleSwitch stringifier = new GrammarElementTitleSwitch(); for(int i = 0; i < firstSet.size(); i++) { if (i != 0) actual.append(", "); actual.append(stringifier.apply(firstSet.get(i))); } assertEquals(expectation, actual.toString()); }