Search in sources :

Example 1 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class AbstractRuleImpl method basicSetType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetType(TypeRef newType, NotificationChain msgs) {
    TypeRef oldType = type;
    type = newType;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtextPackage.ABSTRACT_RULE__TYPE, oldType, newType);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : TypeRef(org.eclipse.xtext.TypeRef) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 2 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class CrossReferenceImpl method basicSetType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetType(TypeRef newType, NotificationChain msgs) {
    TypeRef oldType = type;
    type = newType;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtextPackage.CROSS_REFERENCE__TYPE, oldType, newType);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : TypeRef(org.eclipse.xtext.TypeRef) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 3 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class ActionImpl method basicSetType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetType(TypeRef newType, NotificationChain msgs) {
    TypeRef oldType = type;
    type = newType;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtextPackage.ACTION__TYPE, oldType, newType);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : TypeRef(org.eclipse.xtext.TypeRef) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 4 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class Xtext2EcoreTransformer method deriveFeatures.

private Xtext2EcoreInterpretationContext deriveFeatures(final Xtext2EcoreInterpretationContext context, AbstractElement element) {
    XtextSwitch<Xtext2EcoreInterpretationContext> visitor = new XtextSwitch<Xtext2EcoreInterpretationContext>() {

        /*
			 * Used for Alternatives and UnorderedGroups
			 */
        @Override
        public Xtext2EcoreInterpretationContext caseCompoundElement(CompoundElement object) {
            List<Xtext2EcoreInterpretationContext> contexts = new ArrayList<Xtext2EcoreInterpretationContext>();
            for (AbstractElement group : object.getElements()) {
                contexts.add(deriveFeatures(context, group));
            }
            Xtext2EcoreInterpretationContext result = context;
            if (!contexts.isEmpty()) {
                if (GrammarUtil.isOptionalCardinality(object)) {
                    contexts.add(0, result);
                } else {
                    result = contexts.get(0);
                }
                result = result.mergeSpawnedContexts(contexts);
            }
            return result;
        }

        @Override
        public Xtext2EcoreInterpretationContext caseAssignment(Assignment object) {
            try {
                context.addFeature(object);
            } catch (TransformationException ex) {
                reportError(ex);
            }
            return context;
        }

        @Override
        public Xtext2EcoreInterpretationContext caseGroup(Group object) {
            return visitElements(object, object.getElements());
        }

        private Xtext2EcoreInterpretationContext visitElements(AbstractElement caller, List<AbstractElement> elementsToProcess) {
            Xtext2EcoreInterpretationContext result = deriveFeatures(context.spawnContextForGroup(), elementsToProcess);
            if (GrammarUtil.isMultipleCardinality(caller)) {
                result = deriveFeatures(result.spawnContextForGroup(), elementsToProcess);
            }
            if (GrammarUtil.isOptionalCardinality(caller)) {
                result = result.mergeSpawnedContexts(Arrays.asList(context, result));
            }
            return result;
        }

        @Override
        public Xtext2EcoreInterpretationContext caseAlternatives(Alternatives object) {
            List<Xtext2EcoreInterpretationContext> contexts = newArrayList();
            if (GrammarUtil.isOptionalCardinality(object)) {
                contexts.add(context);
            }
            for (AbstractElement alternative : object.getElements()) {
                contexts.add(deriveFeatures(context.spawnContextForGroup(), alternative));
            }
            Xtext2EcoreInterpretationContext result = context.mergeSpawnedContexts(contexts);
            if (GrammarUtil.isMultipleCardinality(object)) {
                for (AbstractElement alternative : object.getElements()) {
                    deriveFeatures(result.spawnContextForGroup(), alternative);
                }
            }
            return result;
        }

        @Override
        public Xtext2EcoreInterpretationContext caseRuleCall(RuleCall object) {
            AbstractRule calledRule = object.getRule();
            if (isWildcardFragment(calledRule)) {
                AbstractElement ruleBody = calledRule.getAlternatives();
                if (ruleBody != null) {
                    return visitElements(object, Collections.singletonList(ruleBody));
                }
                return context;
            }
            if (isParserRuleFragment(calledRule)) {
                return context;
            }
            if (!GrammarUtil.isOptionalCardinality(object)) {
                // announced during the first iteration
                if (calledRule != null && calledRule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) calledRule)) {
                    try {
                        EClassifierInfo eClassifierInfo = findOrCreateEClassifierInfo(calledRule);
                        return context.spawnContextWithCalledRule(eClassifierInfo, object);
                    } catch (TransformationException e) {
                        reportError(e);
                    }
                }
            }
            return context;
        }

        @Override
        public Xtext2EcoreInterpretationContext caseAction(Action object) {
            try {
                TypeRef actionTypeRef = object.getType();
                EClassifierInfo actionType = findOrCreateEClassifierInfo(actionTypeRef, null, true);
                Xtext2EcoreInterpretationContext ctx = context.spawnContextWithReferencedType(actionType, object);
                if (object.getFeature() != null) {
                    ctx.addFeature(object.getFeature(), context, GrammarUtil.isMultipleAssignment(object), true, object);
                }
                return ctx;
            } catch (TransformationException e) {
                reportError(e);
            }
            return context;
        }

        @Override
        public Xtext2EcoreInterpretationContext defaultCase(EObject object) {
            return context;
        }
    };
    return visitor.doSwitch(element);
}
Also used : Group(org.eclipse.xtext.Group) ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) AbstractElement(org.eclipse.xtext.AbstractElement) TypeRef(org.eclipse.xtext.TypeRef) ArrayList(java.util.ArrayList) Alternatives(org.eclipse.xtext.Alternatives) RuleCall(org.eclipse.xtext.RuleCall) Assignment(org.eclipse.xtext.Assignment) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) List(java.util.List) ArrayList(java.util.ArrayList) XtextSwitch(org.eclipse.xtext.util.XtextSwitch) CompoundElement(org.eclipse.xtext.CompoundElement) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 5 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class XtextTransientValueService2 method isValueTransient.

@Override
public ValueTransient isValueTransient(EObject owner, EStructuralFeature feature) {
    if (feature == XtextPackage.eINSTANCE.getTypeRef_Metamodel()) {
        final TypeRef typeRef = (TypeRef) owner;
        final AbstractMetamodelDeclaration m = typeRef.getMetamodel();
        if (m == null || Strings.isEmpty(m.getAlias()))
            return YES;
    } else if (feature == XtextPackage.eINSTANCE.getAbstractRule_Type()) {
        final AbstractRule rule = (AbstractRule) owner;
        if (!GrammarUtil.isDatatypeRule(rule) && (rule instanceof ParserRule || rule instanceof EnumRule)) {
            final TypeRef returnType = rule.getType();
            if (returnType == null || returnType.getClassifier() == null)
                return YES;
            else if (rule.getName().equals(returnType.getClassifier().getName())) {
                if (isValueTransient(returnType, XtextPackage.eINSTANCE.getTypeRef_Metamodel()) == YES)
                    return PREFERABLY;
                else
                    return NO;
            } else if (GrammarUtil.isDatatypeRule(rule)) {
                return NodeModelUtils.getNode(returnType) == null ? YES : NO;
            }
        } else if (rule instanceof TerminalRule || GrammarUtil.isDatatypeRule(rule)) {
            final TypeRef returnType = rule.getType();
            if (returnType == null)
                return YES;
            if (rule instanceof TerminalRule) {
                if (((TerminalRule) rule).isFragment()) {
                    return YES;
                }
            }
            if (GrammarUtil.findEString(GrammarUtil.getGrammar(owner)).equals(rule.getType().getClassifier()))
                return PREFERABLY;
            return NO;
        }
    } else if (feature == XtextPackage.eINSTANCE.getCrossReference_Terminal()) {
        final CrossReference ref = (CrossReference) owner;
        if (ref.getTerminal() instanceof RuleCall && ((RuleCall) ref.getTerminal()).getRule() != null) {
            if ("ID".equals(((RuleCall) ref.getTerminal()).getRule().getName()))
                return PREFERABLY;
            else
                return NO;
        }
        return YES;
    } else if (feature == XtextPackage.eINSTANCE.getEnumLiteralDeclaration_Literal()) {
        final EnumLiteralDeclaration decl = (EnumLiteralDeclaration) owner;
        if (decl.getEnumLiteral() != null && decl.getLiteral() != null) {
            if (Strings.equal(decl.getLiteral().getValue(), decl.getEnumLiteral().getName()))
                return PREFERABLY;
            return NO;
        }
        return YES;
    } else if (feature == XtextPackage.eINSTANCE.getRuleCall_ExplicitlyCalled()) {
        return YES;
    } else if (feature == XtextPackage.eINSTANCE.getNamedArgument_Parameter()) {
        if (((NamedArgument) owner).isCalledByName()) {
            return NO;
        }
        return YES;
    }
    return super.isValueTransient(owner, feature);
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) EnumRule(org.eclipse.xtext.EnumRule) EnumLiteralDeclaration(org.eclipse.xtext.EnumLiteralDeclaration) TypeRef(org.eclipse.xtext.TypeRef) CrossReference(org.eclipse.xtext.CrossReference) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) TerminalRule(org.eclipse.xtext.TerminalRule) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Aggregations

TypeRef (org.eclipse.xtext.TypeRef)32 RuleCall (org.eclipse.xtext.RuleCall)15 ParserRule (org.eclipse.xtext.ParserRule)13 AbstractRule (org.eclipse.xtext.AbstractRule)10 Test (org.junit.Test)9 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)7 CrossReference (org.eclipse.xtext.CrossReference)7 EObject (org.eclipse.emf.ecore.EObject)5 Action (org.eclipse.xtext.Action)5 Assignment (org.eclipse.xtext.Assignment)5 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)4 EnumRule (org.eclipse.xtext.EnumRule)4 Grammar (org.eclipse.xtext.Grammar)4 ReferencedMetamodel (org.eclipse.xtext.ReferencedMetamodel)4 TerminalRule (org.eclipse.xtext.TerminalRule)4 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)4 EClass (org.eclipse.emf.ecore.EClass)3 EClassifier (org.eclipse.emf.ecore.EClassifier)3 EPackage (org.eclipse.emf.ecore.EPackage)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3