Search in sources :

Example 16 with GeneratedMetamodel

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;
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) TypeRef(org.eclipse.xtext.TypeRef) EClassifier(org.eclipse.emf.ecore.EClassifier) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration)

Example 17 with GeneratedMetamodel

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);
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) EClass(org.eclipse.emf.ecore.EClass) TypeRef(org.eclipse.xtext.TypeRef) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) StyledString(org.eclipse.jface.viewers.StyledString) AbstractRule(org.eclipse.xtext.AbstractRule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

GeneratedMetamodel (org.eclipse.xtext.GeneratedMetamodel)17 Grammar (org.eclipse.xtext.Grammar)8 EPackage (org.eclipse.emf.ecore.EPackage)5 EClass (org.eclipse.emf.ecore.EClass)4 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)3 EnumRule (org.eclipse.xtext.EnumRule)3 TypeRef (org.eclipse.xtext.TypeRef)3 Test (org.junit.Test)3 EObject (org.eclipse.emf.ecore.EObject)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 StyledString (org.eclipse.jface.viewers.StyledString)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)2 AbstractRule (org.eclipse.xtext.AbstractRule)2 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)2 ReferencedMetamodel (org.eclipse.xtext.ReferencedMetamodel)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 GenModel (org.eclipse.emf.codegen.ecore.genmodel.GenModel)1 GenPackage (org.eclipse.emf.codegen.ecore.genmodel.GenPackage)1