private boolean deriveFeatures() { boolean result = true; for (AbstractRule rule : grammar.getRules()) { try { if (rule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) rule) && !isWildcardFragment(rule)) { deriveFeatures((ParserRule) rule); } else if (rule instanceof EnumRule) { deriveEnums((EnumRule) rule); } } catch (TransformationException e) { result = false; reportError(e); } } return result; }
/** * Verify that only rule self directives are used for terminal, enum and data type rules. * * @param model * the GrammarRule */ @Check public void checkDataTypeOrEnumRule(final GrammarRule model) { if (model.getTargetRule() instanceof TerminalRule || model.getTargetRule() instanceof EnumRule || (model.getTargetRule() instanceof ParserRule && GrammarUtil.isDatatypeRule((ParserRule) model.getTargetRule()))) { Iterator<EObject> grammarElementAccessors = collectGrammarElementAccessors(model); boolean selfAccessOnly = Iterators.all(grammarElementAccessors, new Predicate<EObject>() { @Override public boolean apply(final EObject input) { return input instanceof GrammarElementReference && ((GrammarElementReference) input).getSelf() != null; } }); if (!selfAccessOnly) { error(NLS.bind("For data type, enum or terminal rule {0} only ''rule'' directive may be used", model.getTargetRule().getName()), FormatPackage.Literals.GRAMMAR_RULE__DIRECTIVES, ILLEGAL_DIRECTIVE_CODE); } } }
@Override public Boolean caseRuleCall(RuleCall object) { AbstractRule calledRule = object.getRule(); if (calledRule == null || calledRule.eIsProxy() || calledRule instanceof TerminalRule || calledRule instanceof EnumRule) return Boolean.FALSE; ParserRule parserRule = (ParserRule) calledRule; if (GrammarUtil.isDatatypeRule(parserRule)) return Boolean.FALSE; if (parserRule.isFragment()) { visitFragment(object); if (GrammarUtil.isMultipleCardinality(object)) visitFragment(object); } if (!addVisited(parserRule)) return Boolean.FALSE; Multimap<String, AbstractElement> prevAssignedFeatures = assignedFeatures; assignedFeatures = newMultimap(); doSwitch(parserRule.getAlternatives()); for (String feature : assignedFeatures.keySet()) prevAssignedFeatures.put(feature, object); assignedFeatures = prevAssignedFeatures; removeVisited(parserRule); return Boolean.FALSE; }
protected void acceptRuleCall(RuleCall rc, Object value, String token, int index, INode node) { CrossReference crossRef = GrammarUtil.containingCrossReference(rc); if (crossRef != null) { if (rc.getRule() instanceof ParserRule) sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index, getCompositeNode(node)); else if (rc.getRule() instanceof TerminalRule) sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, getLeafNode(node)); else if (rc.getRule() instanceof EnumRule) sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, getCompositeNode(node)); } else { if (rc.getRule() instanceof ParserRule) { AbstractRule rule = rc.getRule(); if (rule.getType() != null && rule.getType().getClassifier() instanceof EClass) acceptEObjectRuleCall(rc, (EObject) value, getCompositeNode(node)); else sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, getCompositeNode(node)); } else if (rc.getRule() instanceof TerminalRule) sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, getLeafNode(node)); else if (rc.getRule() instanceof EnumRule) sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, getCompositeNode(node)); } }
protected void acceptNode(INode node) { Object ge = node.getGrammarElement(); if (ge instanceof Keyword) acceptUnassignedKeyword((Keyword) ge, node.getText(), (ILeafNode) node); else if (ge instanceof RuleCall) { RuleCall rc = (RuleCall) ge; if (rc.getRule() instanceof TerminalRule) acceptUnassignedTerminal(rc, node.getText(), (ILeafNode) node); else if (rc.getRule() instanceof ParserRule) { StringBuilder text = new StringBuilder(); for (ILeafNode leaf : node.getLeafNodes()) if (text.length() > 0 || !leaf.isHidden()) text.append(leaf.getText()); acceptUnassignedDatatype(rc, text.toString(), (ICompositeNode) node); } else if (rc.getRule() instanceof EnumRule) acceptUnassignedEnum(rc, node.getText(), (ICompositeNode) node); } else if (ge instanceof Action) acceptUnassignedAction((Action) ge); else throw new RuntimeException("Unexpected grammar element: " + node.getGrammarElement()); }
protected Set<AbstractElement> findValidValueAssignments(EObject semanticObj, Iterable<AbstractElement> assignedElements, Object value) { Set<AbstractElement> result = Sets.newLinkedHashSet(); for (AbstractElement ass : assignedElements) { if (ass instanceof Keyword && keywordSerializer.isValid(semanticObj, (Keyword) ass, value, null)) result.add(ass); else if (ass instanceof RuleCall) { RuleCall rc = (RuleCall) ass; if (rc.getRule() instanceof EnumRule) { if (enumLiteralSerializer.isValid(semanticObj, rc, value, null)) result.add(ass); } else if (valueSerializer.isValid(semanticObj, rc, value, null)) result.add(ass); } } return result; }
protected CharSequence compileRule(final Object it, final Grammar grammar, final AntlrOptions options) { if (it instanceof Alternatives) { return _compileRule((Alternatives)it, grammar, options); } else if (it instanceof Group) { return _compileRule((Group)it, grammar, options); } else if (it instanceof UnorderedGroup) { return _compileRule((UnorderedGroup)it, grammar, options); } else if (it instanceof Assignment) { return _compileRule((Assignment)it, grammar, options); } else if (it instanceof EnumRule) { return _compileRule((EnumRule)it, grammar, options); } else if (it instanceof ParserRule) { return _compileRule((ParserRule)it, grammar, options); } else if (it instanceof TerminalRule) { return _compileRule((TerminalRule)it, grammar, options); } else if (it instanceof String) { return _compileRule((String)it, grammar, options); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, grammar, options).toString()); } }
protected String crossrefEbnf(final AbstractRule it, final RuleCall call, final CrossReference ref, final boolean supportActions) { String _switchResult = null; boolean _matched = false; if (it instanceof EnumRule) { _matched=true; } if (!_matched) { if (it instanceof ParserRule) { _matched=true; } } if (!_matched) { if (it instanceof TerminalRule) { _matched=true; } } if (_matched) { _switchResult = this._grammarAccessExtensions.ruleName(it); } if (!_matched) { throw new IllegalStateException(("crossrefEbnf is not supported for " + it)); } return _switchResult; }
protected String _assignmentEbnf(final RuleCall it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) { String _switchResult = null; AbstractRule _rule = it.getRule(); final AbstractRule rule = _rule; boolean _matched = false; if (rule instanceof EnumRule) { _matched=true; } if (!_matched) { if (rule instanceof ParserRule) { _matched=true; } } if (!_matched) { if (rule instanceof TerminalRule) { _matched=true; } } if (_matched) { _switchResult = this._grammarAccessExtensions.ruleName(rule); } if (!_matched) { throw new IllegalStateException(("assignmentEbnf is not supported for " + rule)); } return _switchResult; }
protected StringConcatenationClient _cache(final EnumRule it) { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("private final "); String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it); _builder.append(_gaRuleAccessorClassName); _builder.append(" "); String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it); _builder.append(_gaRuleAccessorLocalVarName); _builder.append(";"); _builder.newLineIfNotEmpty(); } }; return _client; }
protected StringConcatenationClient _initializer(final EnumRule it) { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("this."); String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it); _builder.append(_gaRuleAccessorLocalVarName); _builder.append(" = new "); String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it); _builder.append(_gaRuleAccessorClassName); _builder.append("();"); _builder.newLineIfNotEmpty(); } }; return _client; }
protected String getRuleNameForErrorMessage(AbstractRule rule) { String ruleName = "datatype "; if (rule instanceof TerminalRule) ruleName = "terminal "; else if (rule instanceof EnumRule) ruleName = "enum "; return ruleName; }
@Check public void checkUnassignedRuleCallAllowed(final RuleCall call) { if (call.getRule() != null && !call.getRule().eIsProxy() && GrammarUtil.containingAssignment(call) == null) { AbstractRule container = GrammarUtil.containingRule(call); if (call.getRule() instanceof ParserRule) { if (container instanceof TerminalRule) { getMessageAcceptor().acceptError( "Cannot call parser rule from terminal rule.", call, XtextPackage.Literals.RULE_CALL__RULE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); } else { ParserRule parserRule = (ParserRule) call.getRule(); if (!GrammarUtil.isDatatypeRule(parserRule) && !parserRule.isFragment()) { checkCurrentMustBeUnassigned(call); } } } if (call.getRule() instanceof EnumRule) { if (container instanceof TerminalRule) { getMessageAcceptor().acceptError( "Cannot call enum rule from terminal rule.", call, XtextPackage.Literals.RULE_CALL__RULE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); } } } }
@Check public void checkEnumLiteralIsUnique(EnumLiteralDeclaration decl) { EnumRule rule = GrammarUtil.containingEnumRule(decl); List<EnumLiteralDeclaration> declarations = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class); String literal = decl.getLiteral().getValue(); if (literal != null) { for (EnumLiteralDeclaration otherDecl : declarations) { if (otherDecl != decl && literal.equals(otherDecl.getLiteral().getValue())) { error("Enum literal '" + literal + "' is used multiple times in enum rule '" + rule.getName() + "'.", XtextPackage.Literals.ENUM_LITERAL_DECLARATION__LITERAL); } } } }
private String getDefaultAntlrRuleName(AbstractRule rule) { if (rule instanceof ParserRule || rule instanceof EnumRule) { return "rule" + rule.getName(); } if (rule instanceof TerminalRule) { return "RULE_" + rule.getName().toUpperCase(); } throw new IllegalArgumentException(rule.eClass().getName()); }
protected String getDiagnosticMessage(AssignmentToken token) { Assignment ass = (Assignment) token.getGrammarElement(); Object value = token.getEObjectConsumer().getConsumable(ass.getFeature(), false); if (value == null) { EStructuralFeature f = token.getEObjectConsumer().getEObject().eClass() .getEStructuralFeature(ass.getFeature()); if (f == null) return "The current object of type '" + token.getEObjectConsumer().getEObject().eClass().getName() + "' does not have a feature named '" + ass.getFeature() + "'"; String cls = f.getEContainingClass() == token.getEObjectConsumer().getEObject().eClass() ? f .getEContainingClass().getName() : f.getEContainingClass().getName() + "(" + token.getEObjectConsumer().getEObject().eClass().getName() + ")"; String feat = cls + "." + f.getName(); if (f.isMany()) { int size = ((List<?>) token.getEObjectConsumer().getEObject().eGet(f)).size(); return "All " + size + " values of " + feat + " have been consumed. " + "More are needed to continue here."; } else return feat + " is not set."; } else { ErrorAcceptor err = new ErrorAcceptor(); for (RuleCall ruleCall : GrammarUtil.containedRuleCalls(token.getGrammarElement())) { if (ruleCall.getRule() instanceof EnumRule) { if (enumSerializer.isValid(token.getEObject(), ruleCall, value, err)) return null; } else if (ruleCall.getRule().getType().getClassifier() instanceof EDataType) { if (valueSerializer.isValid(token.getEObject(), ruleCall, value, err)) return null; } } return err.getMessage(); } }
private BiMap<CharSequence, String> createKeywordMap(Grammar grammar) { List<ParserRule> parserRules = GrammarUtil.allParserRules(grammar); List<EnumRule> enumRules = GrammarUtil.allEnumRules(grammar); Iterator<EObject> iter = Iterators.concat( EcoreUtil.<EObject>getAllContents(parserRules), EcoreUtil.<EObject>getAllContents(enumRules)); Iterator<Keyword> filtered = Iterators.filter(iter, Keyword.class); Iterator<String> transformed = Iterators.transform(filtered, new Function<Keyword, String>() { @Override public String apply(Keyword from) { return from.getValue(); } }); TreeSet<String> treeSet = Sets.newTreeSet(new Comparator<String>() { @Override public int compare(String o1, String o2) { if (o1.length() == o2.length()) return o1.compareTo(o2); return Integer.valueOf(o1.length()).compareTo(Integer.valueOf(o2.length())); } }); Iterators.addAll(treeSet, transformed); BiMap<CharSequence, String> result = HashBiMap.create(); for(String s: treeSet) { CharSequence key = createKey(s); String readableName = toAntlrTokenIdentifier(s); if (result.containsValue(readableName)) { int i = 1; String next = readableName + "_" + i; while(result.containsValue(next)) { i++; next = readableName + "_" + i; } readableName = next; } result.put(key, readableName); } return result; }
protected CharSequence compileRule(final Object it, final Grammar grammar, final AntlrOptions options) { if (it instanceof EnumRule) { return _compileRule((EnumRule)it, grammar, options); } else if (it instanceof ParserRule) { return _compileRule((ParserRule)it, grammar, options); } else if (it instanceof TerminalRule) { return _compileRule((TerminalRule)it, grammar, options); } else if (it instanceof String) { return _compileRule((String)it, grammar, options); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, grammar, options).toString()); } }
@Override protected CharSequence compileRules(final Grammar g, final AntlrOptions options) { StringConcatenation _builder = new StringConcatenation(); { List<ParserRule> _allParserRules = GrammarUtil.allParserRules(g); List<EnumRule> _allEnumRules = GrammarUtil.allEnumRules(g); Iterable<AbstractRule> _plus = Iterables.<AbstractRule>concat(_allParserRules, _allEnumRules); Collection<? extends AbstractElement> _allAlternatives = GrammarUtil.getAllAlternatives(g); Iterable<EObject> _plus_1 = Iterables.<EObject>concat(_plus, _allAlternatives); Collection<? extends AbstractElement> _allGroups = GrammarUtil.getAllGroups(g); Iterable<EObject> _plus_2 = Iterables.<EObject>concat(_plus_1, _allGroups); Collection<? extends AbstractElement> _allUnorderedGroups = GrammarUtil.getAllUnorderedGroups(g); Iterable<EObject> _plus_3 = Iterables.<EObject>concat(_plus_2, _allUnorderedGroups); Collection<? extends AbstractElement> _allAssignments = GrammarUtil.getAllAssignments(g); final Function1<EObject, Boolean> _function = (EObject it) -> { return Boolean.valueOf(this._grammarAccessExtensions.isCalled(GrammarUtil.containingRule(it), g)); }; Iterable<EObject> _filter = IterableExtensions.<EObject>filter(Iterables.<EObject>concat(_plus_3, _allAssignments), _function); for(final EObject rule : _filter) { _builder.newLine(); CharSequence _compileRule = this.compileRule(rule, g, options); _builder.append(_compileRule); _builder.newLineIfNotEmpty(); } } { boolean _isCombinedGrammar = this.isCombinedGrammar(); if (_isCombinedGrammar) { CharSequence _compileTerminalRules = this.compileTerminalRules(g, options); _builder.append(_compileTerminalRules); _builder.newLineIfNotEmpty(); } } return _builder; }
@Override protected CharSequence _compileRule(final EnumRule it, final Grammar grammar, final AntlrOptions options) { StringConcatenation _builder = new StringConcatenation(); _builder.append("// Rule "); String _name = AntlrGrammarGenUtil.<EnumRule>getOriginalElement(it).getName(); _builder.append(_name); _builder.newLineIfNotEmpty(); String _ruleName = this._grammarAccessExtensions.ruleName(it); _builder.append(_ruleName); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("@init {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("int stackSize = keepStackSize();"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append(":"); _builder.newLine(); _builder.append("\t"); String _ebnf = this.ebnf(it.getAlternatives(), options, false); _builder.append(_ebnf, "\t"); _builder.newLineIfNotEmpty(); _builder.append(";"); _builder.newLine(); _builder.append("finally {"); _builder.newLine(); _builder.append("\t"); _builder.append("restoreStackSize(stackSize);"); _builder.newLine(); _builder.append("}"); _builder.newLine(); return _builder; }
protected String crossrefEbnf(final AbstractRule it, final RuleCall call, final CrossReference ref, final boolean supportActions) { if (it instanceof EnumRule) { return _crossrefEbnf((EnumRule)it, call, ref, supportActions); } else if (it instanceof TerminalRule) { return _crossrefEbnf((TerminalRule)it, call, ref, supportActions); } else if (it != null) { return _crossrefEbnf(it, call, ref, supportActions); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, call, ref, supportActions).toString()); } }
protected StringConcatenationClient cache(final AbstractRule it) { if (it instanceof EnumRule) { return _cache((EnumRule)it); } else if (it instanceof ParserRule) { return _cache((ParserRule)it); } else if (it instanceof TerminalRule) { return _cache((TerminalRule)it); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it).toString()); } }
protected StringConcatenationClient initializer(final AbstractRule it) { if (it instanceof EnumRule) { return _initializer((EnumRule)it); } else if (it instanceof ParserRule) { return _initializer((ParserRule)it); } else if (it instanceof TerminalRule) { return _initializer((TerminalRule)it); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it).toString()); } }
protected StringConcatenationClient getter(final AbstractRule it, final Grammar original) { if (it instanceof EnumRule) { return _getter((EnumRule)it, original); } else if (it instanceof ParserRule) { return _getter((ParserRule)it, original); } else if (it instanceof TerminalRule) { return _getter((TerminalRule)it, original); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, original).toString()); } }
protected String gaRuleAccessorLocalVarName(final AbstractRule rule) { if (rule instanceof EnumRule) { return _gaRuleAccessorLocalVarName((EnumRule)rule); } else if (rule instanceof ParserRule) { return _gaRuleAccessorLocalVarName((ParserRule)rule); } else if (rule instanceof TerminalRule) { return _gaRuleAccessorLocalVarName((TerminalRule)rule); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(rule).toString()); } }
@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 testEnum_04() throws Exception { String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/4'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName;"; Grammar grammar = (Grammar) getModel(modelAsString); assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty()); checkEnums(grammar); EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage(); assertEquals("http://www.eclipse.org/2009/tmf/xtext/EnumRulesTestLanguage/imported", pack.getNsURI()); EEnum eEnum = (EEnum) pack.getEClassifier("ExistingEnum"); assertNotNull(eEnum); assertEquals(3, eEnum.getELiterals().size()); EEnumLiteral value = eEnum.getELiterals().get(0); assertEquals(ExistingEnum.SAME_NAME.getName(), value.getName()); assertEquals(ExistingEnum.SAME_NAME.getValue(), value.getValue()); assertEquals(ExistingEnum.SAME_NAME.getLiteral(), value.getLiteral()); EnumRule rule = (EnumRule) grammar.getRules().get(1); assertEquals(eEnum, rule.getType().getClassifier()); EnumLiteralDeclaration decl = (EnumLiteralDeclaration) rule.getAlternatives(); assertEquals(value, decl.getEnumLiteral()); assertNotNull(decl.getLiteral()); assertEquals(value.getLiteral(), decl.getLiteral().getValue()); }
@Test public void testEnum_05() throws Exception { String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/5'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName = 'value';"; Grammar grammar = (Grammar) getModel(modelAsString); assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty()); checkEnums(grammar); EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage(); assertEquals("http://www.eclipse.org/2009/tmf/xtext/EnumRulesTestLanguage/imported", pack.getNsURI()); EEnum eEnum = (EEnum) pack.getEClassifier("ExistingEnum"); assertNotNull(eEnum); assertEquals(3, eEnum.getELiterals().size()); EEnumLiteral value = eEnum.getELiterals().get(0); assertEquals(ExistingEnum.SAME_NAME.getName(), value.getName()); assertEquals(ExistingEnum.SAME_NAME.getValue(), value.getValue()); assertEquals(ExistingEnum.SAME_NAME.getLiteral(), value.getLiteral()); EnumRule rule = (EnumRule) grammar.getRules().get(1); assertEquals(eEnum, rule.getType().getClassifier()); EnumLiteralDeclaration decl = (EnumLiteralDeclaration) rule.getAlternatives(); assertEquals(value, decl.getEnumLiteral()); assertNotNull(decl.getLiteral()); assertEquals("value", decl.getLiteral().getValue()); }
@Test public void testEnum_10() throws Exception { String modelAsString = "grammar TestLanguage with org.eclipse.xtext.enumrules.EnumRulesTestLanguage\n" + "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/10'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName;"; Grammar grammar = (Grammar) getModel(modelAsString); assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty()); checkEnums(grammar); EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage(); assertEquals("http://www.eclipse.org/2009/tmf/xtext/EnumRulesTestLanguage/imported", pack.getNsURI()); EEnum eEnum = (EEnum) pack.getEClassifier("ExistingEnum"); assertNotNull(eEnum); assertEquals(3, eEnum.getELiterals().size()); EEnumLiteral value = eEnum.getELiterals().get(0); assertEquals(ExistingEnum.SAME_NAME.getName(), value.getName()); assertEquals(ExistingEnum.SAME_NAME.getValue(), value.getValue()); assertEquals(ExistingEnum.SAME_NAME.getLiteral(), value.getLiteral()); EnumRule rule = (EnumRule) grammar.getRules().get(1); assertEquals(eEnum, rule.getType().getClassifier()); EnumLiteralDeclaration decl = (EnumLiteralDeclaration) rule.getAlternatives(); assertEquals(value, decl.getEnumLiteral()); assertNotNull(decl.getLiteral()); assertEquals("SameName", decl.getLiteral().getValue()); }
public EnumRule getTypeAccessModifierRule() { return getTypeAccessModifierAccess().getRule(); }
public EnumRule getMemberAccessModifierRule() { return getMemberAccessModifierAccess().getRule(); }
public EnumRule getVariableStatementKeywordRule() { return getVariableStatementKeywordAccess().getRule(); }
public EnumRule getPostfixOperatorRule() { return getPostfixOperatorAccess().getRule(); }
public EnumRule getUnaryOperatorRule() { return getUnaryOperatorAccess().getRule(); }
public EnumRule getMultiplicativeOperatorRule() { return getMultiplicativeOperatorAccess().getRule(); }
public EnumRule getAdditiveOperatorRule() { return getAdditiveOperatorAccess().getRule(); }
public EnumRule getEqualityOperatorRule() { return getEqualityOperatorAccess().getRule(); }
public EnumRule getN4ModifierRule() { return getN4ModifierAccess().getRule(); }