@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); }
@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); }
@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); }
@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); }
@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(); }
@SuppressWarnings("unchecked") private static <T> ParserResults<T> parse(String parseRuleName, String versionNo) { final ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setName(parseRuleName); final N4MFParser parser = getService(N4MFParser.class, getRandomURI()); final IParseResult result = parser.parse(parserRule, new StringReader(versionNo)); final ParserResults<T> res = new ParserResults<>(); res.ast = (T) result.getRootASTElement(); result.getSyntaxErrors().forEach(n -> { SyntaxErrorMessage syntaxErrorMessage = n.getSyntaxErrorMessage(); res.addErrors(syntaxErrorMessage.getMessage()); }); return res; }
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; }
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; }
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()); }
@Before public void setUp() throws Exception { errorAcceptorMock = new FailOnErrorAcceptor(); metamodel = XtextFactory.eINSTANCE.createGeneratedMetamodel(); Grammar grammar = XtextFactory.eINSTANCE.createGrammar(); grammar.getMetamodelDeclarations().add(metamodel); infos = new EClassifierInfos(grammar); INT = EcoreFactory.eINSTANCE.createEDataType(); STRING = EcoreFactory.eINSTANCE.createEDataType(); EPackage pack = EcoreFactory.eINSTANCE.createEPackage(); pack.setNsURI("myURI"); pack.setName("myName"); pack.setNsPrefix("myPrefix"); metamodel.setEPackage(pack); }
@Test public void testBug_282852_05() 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"); base.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. This grammar contains another rule 'Foo'.", lastMessage); }
@Test public void testBug_282852_06() 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"); base.getRules().add(subRuleFoo); XtextValidator validator = get(XtextValidator.class); configureValidator(validator, this, subRuleFoo); validator.checkRuleName(subRuleFoo); assertEquals("A rule's name has to be unique.", lastMessage); }
@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(); }
@Test public void testCheckCrossReferenceTerminal_02() 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.EINT); ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(call, true, false); validator.setMessageAcceptor(messageAcceptor); validator.checkCrossReferenceTerminal(reference); messageAcceptor.validate(); }
@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(); }
@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(); }
@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(); }
@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(); }
@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(); }
@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(); }
@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(); }
@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(); }
@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()); }
@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()); }
@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); } }
@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); }
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; }
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; }
public EObject parseExpression(String expression, String ruleName, String specification) { StextResource resource = getResource(); resource.setURI(URI.createURI(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); 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; }
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; }
public void accept(ICompletionProposal proposal) { if (proposal instanceof ConfigurableCompletionProposal) { Keyword keyword = XtextFactory.eINSTANCE.createKeyword(); keyword.setValue(proposal.getDisplayString()); ((ConfigurableCompletionProposal) proposal).setAdditionalProposalInfo(keyword); ((ConfigurableCompletionProposal) proposal).setHover(STextProposalProvider.this.getHover()); } delegate.accept(proposal); }
private void deriveEnums(EnumRule rule) { EEnum returnType = (EEnum) rule.getType().getClassifier(); if (returnType != null) { List<EnumLiteralDeclaration> decls = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class); for(EnumLiteralDeclaration decl : decls) { if (decl.getEnumLiteral() == null) { List<INode> nodes = NodeModelUtils.findNodesForFeature(decl, XtextPackage.Literals.ENUM_LITERAL_DECLARATION__ENUM_LITERAL); if (!nodes.isEmpty()) { if (nodes.size() > 1) throw new IllegalStateException("Unexpected nodes found: " + nodes); INode node = nodes.get(0); String text = node.getText(); EEnumLiteral literal = null; if (rule.getType().getMetamodel() instanceof ReferencedMetamodel) { literal = returnType.getEEnumLiteral(text); } else { EEnumLiteral existing = returnType.getEEnumLiteral(text); if (existing == null) { literal = EcoreFactory.eINSTANCE.createEEnumLiteral(); int index = returnType.getELiterals().size(); returnType.getELiterals().add(literal); literal.setName(text); literal.setValue(index); if (decl.getLiteral() != null) { literal.setLiteral(decl.getLiteral().getValue()); } else { literal.setLiteral(text); } } else { literal = existing; } SourceAdapter.adapt(literal, decl); } if (literal == null) { reportError(new TransformationException(TransformationErrorCode.InvalidFeature, "Enum literal '" + text + "' does not exist.", decl)); } else { decl.setEnumLiteral(literal); } } } if (decl.getLiteral() == null && decl.getEnumLiteral() != null) { Keyword kw = XtextFactory.eINSTANCE.createKeyword(); kw.setValue(decl.getEnumLiteral().getLiteral()); decl.setLiteral(kw); } } } }
@Override protected void setDefaultValueImpl(EObject obj, EReference ref, IDiagnosticProducer producer) { if (XtextPackage.eINSTANCE.getTypeRef_Metamodel() == ref) { final TypeRef typeRef = (TypeRef) obj; final String typeRefName = GrammarUtil.getTypeRefName(typeRef); final List<EObject> metamodels = XtextMetamodelReferenceHelper.findBestMetamodelForType(typeRef, "", typeRefName, scopeProvider.getScope(typeRef, ref)); if (metamodels.isEmpty() || metamodels.size() > 1) producer.addDiagnostic(new DiagnosticMessage("Cannot find meta model for type '" + typeRefName + "'", Severity.ERROR, null)); else typeRef.setMetamodel((AbstractMetamodelDeclaration) metamodels.get(0)); } else if (XtextPackage.eINSTANCE.getCrossReference_Terminal() == ref) { AbstractRule rule = GrammarUtil.findRuleForName(GrammarUtil.getGrammar(obj), "ID"); if (rule == null) producer.addDiagnostic(new DiagnosticMessage("Cannot resolve implicit reference to rule 'ID'", Severity.ERROR, null)); else { RuleCall call = XtextFactory.eINSTANCE.createRuleCall(); call.setRule(rule); ((CrossReference) obj).setTerminal(call); } } else if (XtextPackage.eINSTANCE.getNamedArgument_Parameter() == ref) { final NamedArgument argument = (NamedArgument) obj; if (!argument.isCalledByName()) { RuleCall ruleCall = EcoreUtil2.getContainerOfType(argument, RuleCall.class); AbstractRule calledRule = ruleCall.getRule(); if (!(calledRule instanceof ParserRule)) { producer.addDiagnostic(new DiagnosticMessage("Arguments can only be used with parser rules.", Severity.ERROR, null)); return; } if (!calledRule.eIsProxy()) { ParserRule casted = (ParserRule) calledRule; int idx = ruleCall.getArguments().indexOf(argument); if (idx < casted.getParameters().size()) { argument.setParameter(casted.getParameters().get(idx)); return; } else if (casted.getParameters().size() == 0) { producer.addDiagnostic(new DiagnosticMessage( "Rule " + calledRule.getName() + " has no arguments.", Severity.ERROR, null)); } else { String message = "Invalid number of arguments for rule " + calledRule.getName() + ", expecting " + casted.getParameters().size() + " but was " + (idx+1); producer.addDiagnostic(new DiagnosticMessage(message, Severity.ERROR, null)); } } } } else { super.setDefaultValueImpl(obj, ref, producer); } }
/** * @since 2.10 */ protected EObject getGrammarElement(EObject obj, EReference eRef, String crossRefString, int offset, int length) { return XtextFactory.eINSTANCE.createKeyword(); }
public Scope createInternalScope(String contextScope) { ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setName(InternalScope.class.getSimpleName()); IParseResult result = parser.parse(parserRule, new StringReader(contextScope)); return (Scope) result.getRootASTElement(); }
public Scope createInterfaceScope(String contextScope) { ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setName(InterfaceScope.class.getSimpleName()); IParseResult result = parser.parse(parserRule, new StringReader(contextScope)); return (Scope) result.getRootASTElement(); }
/** * Creates an instance of the model <b>Package</b>, registered with * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package * package URI value. * <p>Note: the correct way to create the package is via the static * factory method {@link #init init()}, which also performs * initialization of the package, or returns the registered package, * if one already exists. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see org.eclipse.emf.ecore.EPackage.Registry * @see org.eclipse.xtext.XtextPackage#eNS_URI * @see #init() * @generated */ private XtextPackageImpl() { super(eNS_URI, XtextFactory.eINSTANCE); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public XtextFactory getXtextFactory() { return (XtextFactory)getEFactoryInstance(); }