use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.
the class LiveContainerTestLanguageSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == LiveContainerTestLanguagePackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case LiveContainerTestLanguagePackage.MODEL:
sequence_Model(context, (Model) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.
the class XtextGrammarTestLanguageSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == XtextTestPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case XtextTestPackage.ACTION:
if (rule == grammarAccess.getActionRule()) {
sequence_Action(context, (org.eclipse.xtext.xtextTest.Action) semanticObject);
return;
} else if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_Action_Cardinalities(context, (org.eclipse.xtext.xtextTest.Action) semanticObject);
return;
} else
break;
case XtextTestPackage.ALTERNATIVES:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_Alternatives_Cardinalities(context, (Alternatives) semanticObject);
return;
} else if (rule == grammarAccess.getAssignableTerminalRule() || rule == grammarAccess.getParenthesizedAssignableElementRule() || rule == grammarAccess.getAssignableAlternativesRule() || action == grammarAccess.getAssignableAlternativesAccess().getAlternativesElementsAction_1_0()) {
sequence_AssignableAlternatives(context, (Alternatives) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Cardinalities_TerminalAlternatives(context, (Alternatives) semanticObject);
return;
} else if (rule == grammarAccess.getEnumLiteralsRule()) {
sequence_EnumLiterals(context, (Alternatives) semanticObject);
return;
} else
break;
case XtextTestPackage.ASSIGNMENT:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_Assignment_Cardinalities_Predicate(context, (Assignment) semanticObject);
return;
} else if (rule == grammarAccess.getAssignmentRule()) {
sequence_Assignment_Predicate(context, (Assignment) semanticObject);
return;
} else
break;
case XtextTestPackage.CHARACTER_RANGE:
if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Cardinalities_CharacterRange(context, (CharacterRange) semanticObject);
return;
} else if (rule == grammarAccess.getCharacterRangeRule()) {
sequence_CharacterRange(context, (CharacterRange) semanticObject);
return;
} else
break;
case XtextTestPackage.CONDITIONAL_BRANCH:
sequence_Cardinalities_ConditionalBranch(context, (ConditionalBranch) semanticObject);
return;
case XtextTestPackage.CROSS_REFERENCE:
sequence_CrossReference(context, (CrossReference) semanticObject);
return;
case XtextTestPackage.EOF:
if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Cardinalities_EOF(context, (EOF) semanticObject);
return;
} else if (rule == grammarAccess.getEOFRule()) {
sequence_EOF(context, (EOF) semanticObject);
return;
} else
break;
case XtextTestPackage.ENUM_LITERAL_DECLARATION:
sequence_EnumLiteralDeclaration(context, (EnumLiteralDeclaration) semanticObject);
return;
case XtextTestPackage.ENUM_RULE:
sequence_EnumRule_ReturnsClause(context, (EnumRule) semanticObject);
return;
case XtextTestPackage.GENERATED_METAMODEL:
sequence_GeneratedMetamodel(context, (GeneratedMetamodel) semanticObject);
return;
case XtextTestPackage.GRAMMAR:
sequence_Grammar_HiddenClause(context, (Grammar) semanticObject);
return;
case XtextTestPackage.GROUP:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_Cardinalities_Group_Predicate_PredicatedGroup(context, (Group) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Cardinalities_TerminalGroup(context, (Group) semanticObject);
return;
} else if (rule == grammarAccess.getPredicatedGroupRule()) {
sequence_Predicate_PredicatedGroup(context, (Group) semanticObject);
return;
} else
break;
case XtextTestPackage.KEYWORD:
if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Cardinalities_Keyword(context, (Keyword) semanticObject);
return;
} else if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_Cardinalities_Keyword_Predicate_PredicatedKeyword(context, (Keyword) semanticObject);
return;
} else if (rule == grammarAccess.getKeywordRule() || rule == grammarAccess.getAssignableTerminalRule() || rule == grammarAccess.getParenthesizedAssignableElementRule() || rule == grammarAccess.getAssignableAlternativesRule() || action == grammarAccess.getAssignableAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getCrossReferenceableTerminalRule() || rule == grammarAccess.getCharacterRangeRule() || action == grammarAccess.getCharacterRangeAccess().getCharacterRangeLeftAction_1_0()) {
sequence_Keyword(context, (Keyword) semanticObject);
return;
} else if (rule == grammarAccess.getPredicatedKeywordRule()) {
sequence_Predicate_PredicatedKeyword(context, (Keyword) semanticObject);
return;
} else
break;
case XtextTestPackage.NAMED_ARGUMENT:
sequence_NamedArgument(context, (NamedArgument) semanticObject);
return;
case XtextTestPackage.NEGATED_TOKEN:
if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Cardinalities_NegatedToken(context, (NegatedToken) semanticObject);
return;
} else if (rule == grammarAccess.getAbstractNegatedTokenRule() || rule == grammarAccess.getNegatedTokenRule()) {
sequence_NegatedToken(context, (NegatedToken) semanticObject);
return;
} else
break;
case XtextTestPackage.PARAMETER:
sequence_Parameter(context, (org.eclipse.xtext.xtextTest.Parameter) semanticObject);
return;
case XtextTestPackage.PARSER_RULE:
sequence_HiddenClause_ParserRule_ReturnsClause_RuleNameAndParams(context, (org.eclipse.xtext.xtextTest.ParserRule) semanticObject);
return;
case XtextTestPackage.REFERENCED_METAMODEL:
sequence_ReferencedMetamodel(context, (ReferencedMetamodel) semanticObject);
return;
case XtextTestPackage.RULE_CALL:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_Cardinalities_Predicate_PredicatedRuleCall_RuleCall(context, (RuleCall) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Cardinalities_TerminalRuleCall(context, (RuleCall) semanticObject);
return;
} else if (rule == grammarAccess.getPredicatedRuleCallRule()) {
sequence_Predicate_PredicatedRuleCall(context, (RuleCall) semanticObject);
return;
} else if (rule == grammarAccess.getRuleCallRule() || rule == grammarAccess.getAssignableTerminalRule() || rule == grammarAccess.getParenthesizedAssignableElementRule() || rule == grammarAccess.getAssignableAlternativesRule() || action == grammarAccess.getAssignableAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getCrossReferenceableTerminalRule()) {
sequence_RuleCall(context, (RuleCall) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalRuleCallRule()) {
sequence_TerminalRuleCall(context, (RuleCall) semanticObject);
return;
} else
break;
case XtextTestPackage.TERMINAL_RULE:
sequence_ReturnsClause_TerminalRule(context, (TerminalRule) semanticObject);
return;
case XtextTestPackage.TYPE_REF:
sequence_TypeRef(context, (TypeRef) semanticObject);
return;
case XtextTestPackage.UNORDERED_GROUP:
sequence_Cardinalities_UnorderedGroup(context, (UnorderedGroup) semanticObject);
return;
case XtextTestPackage.UNTIL_TOKEN:
if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Cardinalities_UntilToken(context, (UntilToken) semanticObject);
return;
} else if (rule == grammarAccess.getAbstractNegatedTokenRule() || rule == grammarAccess.getUntilTokenRule()) {
sequence_UntilToken(context, (UntilToken) semanticObject);
return;
} else
break;
case XtextTestPackage.WILDCARD:
if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Cardinalities_Wildcard(context, (Wildcard) semanticObject);
return;
} else if (rule == grammarAccess.getWildcardRule()) {
sequence_Wildcard(context, (Wildcard) semanticObject);
return;
} else
break;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.
the class XtextLinkingService method getPackage.
private List<EObject> getPackage(ReferencedMetamodel context, ILeafNode text) {
String nsUri = getMetamodelNsURI(text);
if (nsUri == null)
return Collections.emptyList();
Grammar grammar = GrammarUtil.getGrammar(context);
Set<Grammar> visitedGrammars = new HashSet<Grammar>();
for (Grammar usedGrammar : grammar.getUsedGrammars()) {
List<EObject> result = getPackage(nsUri, usedGrammar, visitedGrammars);
if (result != null)
return result;
}
QualifiedName packageNsURI = QualifiedName.create(nsUri);
EPackage pack = findPackageInScope(context, packageNsURI);
if (pack == null) {
pack = findPackageInAllDescriptions(context, packageNsURI);
if (pack == null) {
pack = loadEPackage(nsUri, context.eResource().getResourceSet());
}
}
if (pack != null)
return Collections.<EObject>singletonList(pack);
return Collections.emptyList();
}
use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.
the class XtextValidator method checkExternalPackage.
protected void checkExternalPackage(ReferencedMetamodel metamodelReference, String importURI) {
EPackage referencedPackage = metamodelReference.getEPackage();
if (referencedPackage.eIsProxy() || isRuntime(metamodelReference))
return;
if (isRegisteredPackage(referencedPackage)) {
addIssue("The imported package is not on the classpath of this project which may lead to follow-up errors.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_NOT_ON_CLASSPATH, importURI);
return;
}
if (!importURI.equals(referencedPackage.getNsURI())) {
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(metamodelReference.eResource());
Iterable<IEObjectDescription> packagesInIndex = descriptions.getExportedObjects(EcorePackage.Literals.EPACKAGE, QualifiedName.create(referencedPackage.getNsURI()), false);
if (!Iterables.isEmpty(packagesInIndex)) {
addIssue("Packages should be imported by their namespace URI.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_EXTERNAL, referencedPackage.getNsURI());
} else if (!ClasspathUriUtil.isClasspathUri(URI.createURI(importURI))) {
addIssue("The imported package is not on the classpath of this project which may lead to follow-up errors.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_NOT_ON_CLASSPATH, importURI);
return;
} else {
return;
}
}
Map<EObject, Collection<Setting>> allReferences = EcoreUtil.CrossReferencer.find(Collections.singletonList(referencedPackage));
Set<Object> allReferencedInstances = Sets.newHashSet();
for (Setting setting : Iterables.concat(allReferences.values())) {
Object referenced = setting.get(true);
if (allReferencedInstances.add(referenced) && referenced instanceof EObject) {
EPackage transitive = EcoreUtil2.getContainerOfType((EObject) referenced, EPackage.class);
if (isRegisteredPackage(transitive)) {
if (referenced instanceof EDataType)
continue;
if (referenced == EcorePackage.Literals.EOBJECT)
continue;
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(metamodelReference.eResource());
Iterable<IEObjectDescription> packagesInIndex = descriptions.getExportedObjects(EcorePackage.Literals.EPACKAGE, QualifiedName.create(importURI), false);
if (!Iterables.isEmpty(packagesInIndex)) {
if (setting.getEObject().eResource().getURI().isPlatformResource())
addIssue("The imported package refers to elements in the package registry instead of using the instances from the workspace", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_EXTERNAL, referencedPackage.getNsURI());
else
addIssue("The imported package refers to elements in the package registry instead of using the instances from the workspace", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_EXTERNAL);
return;
} else {
addIssue("The imported package refers to elements that are not on the classpath of this project. The package '" + transitive.getNsURI() + "' was loaded from the registry.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_NOT_ON_CLASSPATH, referencedPackage.getNsURI());
return;
}
}
}
}
}
use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.
the class InjectableValidatorTest method testArbitraryEPackage.
@Test
public void testArbitraryEPackage() throws Exception {
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
xtextResource.getContents().add(ePackage);
assertFalse(languageSpecificValidator.validate(ePackage, new BasicDiagnostic(), null));
assertFalse(languageSpecificValidator.validate(ePackage, new BasicDiagnostic(), context));
assertEquals(xtextResource.getLanguageName(), context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));
context.clear();
assertFalse(languageAgnosticValidator.validate(ePackage, new BasicDiagnostic(), null));
assertFalse(languageAgnosticValidator.validate(ePackage, new BasicDiagnostic(), context));
assertNull(context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));
}
Aggregations