use of org.eclipse.xtext.GeneratedMetamodel in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method getOrComputeReturnType.
private TypeRef getOrComputeReturnType(AbstractRule rule) {
TypeRef result = rule.getType();
if (result == null) {
EClassifier classifier = getClassifierFor(rule);
if (classifier == null) {
if (rule.getName() == null)
return null;
result = getTypeRef(rule.getName());
} else
result = getTypeRef(classifier);
if (result.getMetamodel() == null) {
AbstractMetamodelDeclaration bestMatch = null;
for (AbstractMetamodelDeclaration decl : grammar.getMetamodelDeclarations()) {
if (decl instanceof GeneratedMetamodel && Strings.isEmpty(decl.getAlias())) {
bestMatch = decl;
break;
}
}
if (result.getMetamodel() == null)
result.setMetamodel(bestMatch);
}
rule.setType(result);
}
return result;
}
use of org.eclipse.xtext.GeneratedMetamodel in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeAssignment_Feature.
/**
* Not a full featured solution for the computation of available structural features, but it is sufficient for some
* interesting 85%.
*/
@Override
public void completeAssignment_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
AbstractRule rule = EcoreUtil2.getContainerOfType(model, AbstractRule.class);
TypeRef typeRef = rule.getType();
if (typeRef != null && typeRef.getClassifier() instanceof EClass) {
Iterable<EStructuralFeature> features = ((EClass) typeRef.getClassifier()).getEAllStructuralFeatures();
Function<IEObjectDescription, ICompletionProposal> factory = getProposalFactory(grammarAccess.getValidIDRule().getName(), context);
Iterable<String> processedFeatures = completeStructuralFeatures(context, factory, acceptor, features);
if (rule.getType().getMetamodel() instanceof GeneratedMetamodel) {
if (notNull(rule.getName()).toLowerCase().startsWith("import")) {
completeSpecialAttributeAssignment("importedNamespace", 2, processedFeatures, factory, context, acceptor);
completeSpecialAttributeAssignment("importURI", 1, processedFeatures, factory, context, acceptor);
} else {
completeSpecialAttributeAssignment("name", 3, processedFeatures, factory, context, acceptor);
}
}
}
super.completeAssignment_Feature(model, assignment, context, acceptor);
}
Aggregations