@Override public Injector createInjectorAndDoEMFRegistration() { // register default ePackages if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "ecore", new EcoreResourceFactoryImpl()); if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xmi", new XMIResourceFactoryImpl()); if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xtextbin", new BinaryGrammarResourceFactoryImpl()); if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI)) EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE); Injector injector = createInjector(); register(injector); return injector; }
private void processMetamodelDeclarations(Collection<AbstractMetamodelDeclaration> declarations, ResourceSet resourceSet, Collection<Resource> resourcesToRemove, Collection<Resource> resourcesToUnload, Collection<Resource> referencedResources) { for (AbstractMetamodelDeclaration declaration : declarations) { EPackage pack = (EPackage) declaration.eGet(XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, false); if (pack != null && !pack.eIsProxy()) { Resource packResource = pack.eResource(); if (packResource != null) { resourcesToRemove.add(packResource); if (declaration instanceof ReferencedMetamodel) { resourcesToUnload.add(packResource); } if (isPackageReferenced(resourceSet, pack, declarations)) { referencedResources.add(packResource); } } } } }
@Override public void set(EObject object, String feature, Object value, String ruleName, INode node) throws ValueConverterException { if (object instanceof AbstractElement && XtextPackage.Literals.ABSTRACT_ELEMENT__CARDINALITY.getName().equals(feature)) { AbstractElement casted = (AbstractElement) object; String knownCardinality = casted.getCardinality(); if (knownCardinality != null) { String newCardinality = String.valueOf(getTokenAsStringIfPossible(value)); if ("*".equals(newCardinality)) { casted.setCardinality("*"); } else if ("*".equals(knownCardinality)) { // nothing to do } else if ("+".equals(knownCardinality)) { if ("?".equals(newCardinality)) { casted.setCardinality("*"); } } else if ("?".equals(knownCardinality)) { if ("+".equals(newCardinality)) { casted.setCardinality("*"); } } throw new MoreThanOneCardinalityException(newCardinality, casted.getCardinality(), node); } } super.set(object, feature, value, ruleName, node); }
@Override protected String getUnconvertedLinkText(EObject object, EReference reference, EObject context) { if (reference == XtextPackage.eINSTANCE.getGrammar_UsedGrammars()) return ((Grammar) object).getName(); if (reference == XtextPackage.eINSTANCE.getTypeRef_Metamodel()) { AbstractMetamodelDeclaration casted = (AbstractMetamodelDeclaration) object; return casted.getAlias(); } if (reference == XtextPackage.eINSTANCE.getAbstractMetamodelDeclaration_EPackage()) return ((EPackage) object).getNsURI(); if (object instanceof AbstractRule) { if (reference == XtextPackage.eINSTANCE.getRuleCall_Rule()) { if (((RuleCall)context).isExplicitlyCalled()) { return super.getUnconvertedLinkText(object, reference, context); } } return ((AbstractRule) object).getName(); } return super.getUnconvertedLinkText(object, reference, context); }
@Override public CharSequence getFragmentSegment(final EObject object) { EClass eClass = object.eClass(); EPackage ePackage = eClass.getEPackage(); if (ePackage == XtextPackage.eINSTANCE) { int classifierID = eClass.getClassifierID(); switch (classifierID) { case XtextPackage.GRAMMAR: return getFragmentSegment((Grammar) object); case XtextPackage.ENUM_RULE: case XtextPackage.PARSER_RULE: case XtextPackage.TERMINAL_RULE: return getFragmentSegment((AbstractRule) object); case XtextPackage.KEYWORD: if (((Keyword) object).getValue().equals("selectCardinality")) { return getFragmentSegment((AbstractElement) object); } else { return getFragmentSegment((Keyword) object); } default: return super.getFragmentSegment(object); } } return super.getFragmentSegment(object); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case XtextPackage.PARSER_RULE__DEFINES_HIDDEN_TOKENS: setDefinesHiddenTokens(DEFINES_HIDDEN_TOKENS_EDEFAULT); return; case XtextPackage.PARSER_RULE__HIDDEN_TOKENS: getHiddenTokens().clear(); return; case XtextPackage.PARSER_RULE__PARAMETERS: getParameters().clear(); return; case XtextPackage.PARSER_RULE__FRAGMENT: setFragment(FRAGMENT_EDEFAULT); return; case XtextPackage.PARSER_RULE__WILDCARD: setWildcard(WILDCARD_EDEFAULT); return; } super.eUnset(featureID); }
@Check public void checkTerminalFragmentCalledFromTerminalRule(final RuleCall call) { if (call.getRule() != null && !call.getRule().eIsProxy()) { if (call.getRule() instanceof TerminalRule && ((TerminalRule) call.getRule()).isFragment()) { AbstractRule container = GrammarUtil.containingRule(call); if (!(container instanceof TerminalRule)) { getMessageAcceptor().acceptError( "Only terminal rules may use terminal fragments.", call, XtextPackage.Literals.RULE_CALL__RULE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); } } } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case XtextPackage.PARSER_RULE__DEFINES_HIDDEN_TOKENS: return definesHiddenTokens != DEFINES_HIDDEN_TOKENS_EDEFAULT; case XtextPackage.PARSER_RULE__HIDDEN_TOKENS: return hiddenTokens != null && !hiddenTokens.isEmpty(); case XtextPackage.PARSER_RULE__PARAMETERS: return parameters != null && !parameters.isEmpty(); case XtextPackage.PARSER_RULE__FRAGMENT: return fragment != FRAGMENT_EDEFAULT; case XtextPackage.PARSER_RULE__WILDCARD: return wildcard != WILDCARD_EDEFAULT; } return super.eIsSet(featureID); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case XtextPackage.PARSER_RULE__DEFINES_HIDDEN_TOKENS: setDefinesHiddenTokens((Boolean)newValue); return; case XtextPackage.PARSER_RULE__HIDDEN_TOKENS: getHiddenTokens().clear(); getHiddenTokens().addAll((Collection<? extends AbstractRule>)newValue); return; case XtextPackage.PARSER_RULE__PARAMETERS: getParameters().clear(); getParameters().addAll((Collection<? extends Parameter>)newValue); return; case XtextPackage.PARSER_RULE__FRAGMENT: setFragment((Boolean)newValue); return; case XtextPackage.PARSER_RULE__WILDCARD: setWildcard((Boolean)newValue); return; } super.eSet(featureID, newValue); }
public void inspectKeywordHidesTerminalRule(Keyword keyword) { AbstractRule container = GrammarUtil.containingRule(keyword); if (container instanceof TerminalRule) return; Grammar grammar = GrammarUtil.getGrammar(container); List<TerminalRule> rules = GrammarUtil.allTerminalRules(grammar); for(TerminalRule rule: rules) { if (!rule.isFragment()) { AbstractElement element = rule.getAlternatives(); if (element instanceof Keyword && Strings.isEmpty(element.getCardinality())) { String value = ((Keyword) element).getValue(); if (value.equals(keyword.getValue())) acceptor.acceptError( "The keyword '" + value + "' hides the terminal rule " + rule.getName()+ ".", keyword, XtextPackage.Literals.KEYWORD__VALUE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); } } } }
protected void collectMatchableElements(AbstractElement ele, Collection<AbstractElement> result) { switch (ele.eClass().getClassifierID()) { case XtextPackage.RULE_CALL: assertNoEObjectRuleCall((RuleCall) ele); case XtextPackage.KEYWORD: result.add(ele); break; case XtextPackage.CROSS_REFERENCE: collectMatchableElements(((CrossReference) ele).getTerminal(), result); break; case XtextPackage.ASSIGNMENT: collectMatchableElements(((Assignment) ele).getTerminal(), result); break; case XtextPackage.ALTERNATIVES: case XtextPackage.GROUP: case XtextPackage.UNORDERED_GROUP: for (AbstractElement child : ((CompoundElement) ele).getElements()) collectMatchableElements(child, result); break; } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case XtextPackage.ASSIGNMENT__FEATURE: setFeature(FEATURE_EDEFAULT); return; case XtextPackage.ASSIGNMENT__OPERATOR: setOperator(OPERATOR_EDEFAULT); return; case XtextPackage.ASSIGNMENT__TERMINAL: setTerminal((AbstractElement)null); return; } super.eUnset(featureID); }
protected void validateReferencedMetamodel(final ReferencedMetamodel ref) { if (((ref.getEPackage() != null) && (!ref.getEPackage().eIsProxy()))) { return; } final EReference eref = XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE; final List<INode> nodes = NodeModelUtils.findNodesForFeature(ref, eref); String _xifexpression = null; boolean _isEmpty = nodes.isEmpty(); if (_isEmpty) { _xifexpression = "(unknown)"; } else { _xifexpression = NodeModelUtils.getTokenText(nodes.get(0)); } final String refName = _xifexpression; final String grammarName = GrammarUtil.getGrammar(ref).getName(); final String msg = ((((("The EPackage " + refName) + " in grammar ") + grammarName) + " could not be found. ") + "You might want to register that EPackage in your workflow file."); throw new IllegalStateException(msg); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case XtextPackage.NAMED_ARGUMENT__PARAMETER: setParameter((Parameter)null); return; case XtextPackage.NAMED_ARGUMENT__VALUE: setValue((Condition)null); return; case XtextPackage.NAMED_ARGUMENT__CALLED_BY_NAME: setCalledByName(CALLED_BY_NAME_EDEFAULT); return; } super.eUnset(featureID); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case XtextPackage.ABSTRACT_ELEMENT__CARDINALITY: setCardinality(CARDINALITY_EDEFAULT); return; case XtextPackage.ABSTRACT_ELEMENT__PREDICATED: setPredicated(PREDICATED_EDEFAULT); return; case XtextPackage.ABSTRACT_ELEMENT__FIRST_SET_PREDICATED: setFirstSetPredicated(FIRST_SET_PREDICATED_EDEFAULT); return; } super.eUnset(featureID); }
/** * Contexts: * MyRule returns ParserRule * * Constraint: * name=ID */ protected void sequence_MyRule(ISerializationContext context, ParserRule semanticObject) { if (errorAcceptor != null) { if (transientValues.isValueTransient(semanticObject, XtextPackage.Literals.ABSTRACT_RULE__NAME) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XtextPackage.Literals.ABSTRACT_RULE__NAME)); } SequenceFeeder feeder = createSequencerFeeder(context, semanticObject); feeder.accept(grammarAccess.getMyRuleAccess().getNameIDTerminalRuleCall_0(), semanticObject.getName()); feeder.finish(); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case XtextPackage.NAMED_ARGUMENT__PARAMETER: return parameter != null; case XtextPackage.NAMED_ARGUMENT__VALUE: return value != null; case XtextPackage.NAMED_ARGUMENT__CALLED_BY_NAME: return calledByName != CALLED_BY_NAME_EDEFAULT; } return super.eIsSet(featureID); }
/** * Contexts: * Annotation returns Annotation * * Constraint: * name=ID */ protected void sequence_Annotation(ISerializationContext context, Annotation semanticObject) { if (errorAcceptor != null) { if (transientValues.isValueTransient(semanticObject, XtextPackage.Literals.ANNOTATION__NAME) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XtextPackage.Literals.ANNOTATION__NAME)); } SequenceFeeder feeder = createSequencerFeeder(context, semanticObject); feeder.accept(grammarAccess.getAnnotationAccess().getNameIDTerminalRuleCall_1_0(), semanticObject.getName()); feeder.finish(); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case XtextPackage.ENUM_LITERAL_DECLARATION__LITERAL: return basicSetLiteral(null, msgs); } return super.eInverseRemove(otherEnd, featureID, msgs); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case XtextPackage.COMPOUND_ELEMENT__ELEMENTS: return ((InternalEList<?>)getElements()).basicRemove(otherEnd, msgs); } return super.eInverseRemove(otherEnd, featureID, msgs); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case XtextPackage.NEGATION__VALUE: return value != null; } return super.eIsSet(featureID); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setOperator(String newOperator) { String oldOperator = operator; operator = newOperator; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XtextPackage.ACTION__OPERATOR, oldOperator, operator)); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case XtextPackage.TERMINAL_RULE__FRAGMENT: return fragment != FRAGMENT_EDEFAULT; } return super.eIsSet(featureID); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case XtextPackage.ACTION__TYPE: return basicSetType(null, msgs); } return super.eInverseRemove(otherEnd, featureID, msgs); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case XtextPackage.ENUM_LITERAL_DECLARATION__ENUM_LITERAL: setEnumLiteral((EEnumLiteral)newValue); return; case XtextPackage.ENUM_LITERAL_DECLARATION__LITERAL: setLiteral((Keyword)newValue); return; } super.eSet(featureID, newValue); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) { case XtextPackage.LITERAL_CONDITION__TRUE: return isTrue(); } return super.eGet(featureID, resolve, coreType); }
@Check public void checkGrammarUsesMaxOneOther(Grammar grammar) { if (grammar.getUsedGrammars().size() > 1) { for(int i = 1; i < grammar.getUsedGrammars().size(); i++) { error( "You may not use more than one other grammar.", XtextPackage.Literals.GRAMMAR__USED_GRAMMARS, i); } } }
private boolean doCheckGrammarRecursiveReference(Grammar grammarToCheck, Grammar currentGrammar, int idx, Set<Grammar> visitedGrammars) { if (Strings.equal(grammarToCheck.getName(), currentGrammar.getName())) { error("Invalid recursive reference of grammar.", XtextPackage.Literals.GRAMMAR__USED_GRAMMARS, idx); return false; } if (!visitedGrammars.add(currentGrammar)) return true; for(Grammar usedGrammar: currentGrammar.getUsedGrammars()) { if (!doCheckGrammarRecursiveReference(grammarToCheck, usedGrammar, idx, visitedGrammars)) return false; } return true; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case XtextPackage.GRAMMAR__METAMODEL_DECLARATIONS: return ((InternalEList<?>)getMetamodelDeclarations()).basicRemove(otherEnd, msgs); case XtextPackage.GRAMMAR__RULES: return ((InternalEList<?>)getRules()).basicRemove(otherEnd, msgs); } return super.eInverseRemove(otherEnd, featureID, msgs); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setTerminal(AbstractElement newTerminal) { if (newTerminal != terminal) { NotificationChain msgs = null; if (terminal != null) msgs = ((InternalEObject)terminal).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XtextPackage.ABSTRACT_NEGATED_TOKEN__TERMINAL, null, msgs); if (newTerminal != null) msgs = ((InternalEObject)newTerminal).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XtextPackage.ABSTRACT_NEGATED_TOKEN__TERMINAL, null, msgs); msgs = basicSetTerminal(newTerminal, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XtextPackage.ABSTRACT_NEGATED_TOKEN__TERMINAL, newTerminal, newTerminal)); }
@Check public void checkGeneratedPackageNotEmpty(GeneratedMetamodel metamodel) { EPackage pack = metamodel.getEPackage(); if (pack != null && pack.getEClassifiers().isEmpty()) { getMessageAcceptor().acceptError( "Generated package '" + metamodel.getName() + "' may not be empty.", metamodel, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, EMPTY_GENERATED_PACKAGE); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) { case XtextPackage.ASSIGNMENT__FEATURE: return getFeature(); case XtextPackage.ASSIGNMENT__OPERATOR: return getOperator(); case XtextPackage.ASSIGNMENT__TERMINAL: return getTerminal(); } return super.eGet(featureID, resolve, coreType); }