use of org.eclipse.emf.ecore.EClassifier in project xtext-eclipse by eclipse.
the class XtextProposalProvider method appendReturnType.
protected boolean appendReturnType(final AbstractRule overrideMe, final Grammar grammar, StringBuilder newRuleFragment) {
if (overrideMe instanceof ParserRule && ((ParserRule) overrideMe).isWildcard()) {
newRuleFragment.append(" *");
// no need to add an import to the grammar
return true;
} else {
EClassifier classifier = overrideMe.getType().getClassifier();
final EPackage classifierPackage = classifier.getEPackage();
boolean foundPack = false;
for (AbstractMetamodelDeclaration metamodel : grammar.getMetamodelDeclarations()) {
EPackage available = metamodel.getEPackage();
if (classifierPackage == available) {
EDataType eString = GrammarUtil.findEString(grammar);
if (eString == null)
eString = EcorePackage.Literals.ESTRING;
if (classifier != eString && (!Strings.isEmpty(metamodel.getAlias()) || !classifier.getName().equals(overrideMe.getName()))) {
newRuleFragment.append(" returns ");
if (!Strings.isEmpty(metamodel.getAlias())) {
newRuleFragment.append(metamodel.getAlias()).append("::");
}
newRuleFragment.append(classifier.getName());
}
foundPack = true;
break;
}
}
if (!foundPack) {
EDataType eString = GrammarUtil.findEString(grammar);
if (eString == null)
eString = EcorePackage.Literals.ESTRING;
if (classifier == eString) {
for (AbstractMetamodelDeclaration mm : GrammarUtil.allMetamodelDeclarations(grammar)) {
if (mm.getEPackage() == classifierPackage) {
foundPack = true;
break;
}
}
}
if (!foundPack) {
newRuleFragment.append(" returns ");
newRuleFragment.append(classifierPackage.getName());
newRuleFragment.append("::");
newRuleFragment.append(classifier.getName());
}
}
return foundPack;
}
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeAction_Feature.
@Override
public void completeAction_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
Action action = EcoreUtil2.getContainerOfType(model, Action.class);
if (action != null && action.getType() != null) {
EClassifier classifier = action.getType().getClassifier();
if (classifier instanceof EClass) {
List<EReference> containments = ((EClass) classifier).getEAllContainments();
Function<IEObjectDescription, ICompletionProposal> factory = getProposalFactory(grammarAccess.getValidIDRule().getName(), context);
completeStructuralFeatures(context, factory, acceptor, containments);
}
}
super.completeAction_Feature(model, assignment, context, acceptor);
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeParserRule.
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);
}
}
}
}
}
}
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-eclipse by eclipse.
the class XtextGrammarRefactoringIntegrationTest method testRefactorXtextGrammarWithGeneratedClassifierAndModelWithRefToClassifier.
@Test
public void testRefactorXtextGrammarWithGeneratedClassifierAndModelWithRefToClassifier() throws Exception {
ResourceSet rs = resourceSetProvider.get();
EcoreFactory eInstance = EcoreFactory.eINSTANCE;
Resource ecoreModelResource = createEcoreModel(rs, ecoreURI, initialModelRoot);
EClass greetingClass = getGreetingClass(ecoreModelResource);
EReference greetingRefLocal = getReferenceoGreeting(ecoreModelResource, greetingClass);
String greetingClassFragment = EcoreUtil.getURI(greetingClass).fragment();
String greetingRefFragment = EcoreUtil.getURI(greetingRefLocal).fragment();
EPackage refPackage = eInstance.createEPackage();
refPackage.setName("myDsl2");
refPackage.setNsPrefix("myDsl2");
refPackage.setNsURI("http://testrefactoring2");
EClass modelRefClass = eInstance.createEClass();
refPackage.getEClassifiers().add(modelRefClass);
modelRefClass.setName("ModelRef");
EReference reference = eInstance.createEReference();
reference.setName("ref");
reference.setLowerBound(0);
reference.setUpperBound(-1);
reference.setEType(greetingClass);
modelRefClass.getEStructuralFeatures().add(reference);
Resource refToGreetingResource = createEcoreModel(rs, URI.createPlatformResourceURI(TEST_PROJECT + "/src/org/xtext/example/mydsl/" + "MyDsl2.ecore", true), refPackage);
refToGreetingResource.unload();
ecoreModelResource.unload();
waitForBuild();
waitForDisplay();
XtextEditor editor = openEditor(grammarFile);
doRefactoring(editor);
waitForBuild();
checkConsistenceOfGrammar(editor);
ecoreModelResource.load(null);
String renamedGreetingClassFragment = greetingClassFragment.replaceFirst(CLASSIFIERNAME, REFACTOREDCLASSIFIERNAME);
EObject renamedGreetingClass = ecoreModelResource.getEObject(renamedGreetingClassFragment);
assertNotNull(renamedGreetingClass);
assertEquals(REFACTOREDCLASSIFIERNAME, SimpleAttributeResolver.NAME_RESOLVER.apply(renamedGreetingClass));
EReference greetingReference = (EReference) ecoreModelResource.getEObject(greetingRefFragment);
EClassifier eType = greetingReference.getEType();
assertFalse(eType.eIsProxy());
assertEquals(REFACTOREDCLASSIFIERNAME, eType.getName());
refToGreetingResource.load(null);
EReference externalReferenceToGreeting = getReferenceoGreeting(refToGreetingResource, eType);
assertFalse(externalReferenceToGreeting.getEType().eIsProxy());
assertEquals(REFACTOREDCLASSIFIERNAME, externalReferenceToGreeting.getEType().getName());
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-eclipse by eclipse.
the class GrammarTest method checkConcreteImplRule.
private AbstractRule checkConcreteImplRule(Grammar grammar, String ruleName) {
AbstractRule concreteRule = GrammarUtil.findRuleForName(grammar, ruleName);
assertNotNull(concreteRule);
EClassifier returnType = ((ParserRule) concreteRule).getType().getClassifier();
String returnTypeName = getClassifierName(returnType);
assertEquals(ruleName, returnTypeName + "_Impl");
List<Assignment> assignments = GrammarUtil.containedAssignments(concreteRule);
assertEquals(1, assignments.size());
assertEquals("name", assignments.get(0).getFeature());
assertEquals("=", assignments.get(0).getOperator());
List<Action> containedActions = GrammarUtil.containedActions(concreteRule);
assertEquals(1, containedActions.size());
assertEquals(returnTypeName, getClassifierName(containedActions.get(0).getType().getClassifier()));
List<Keyword> containedKeywords = GrammarUtil.containedKeywords(concreteRule);
assertEquals(1, containedKeywords.size());
assertEquals(returnTypeName, containedKeywords.get(0).getValue());
return concreteRule;
}
Aggregations