Search in sources :

Example 11 with EnumLiteralDeclaration

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

the class XtextTransientValueService method isTransient.

@Override
public boolean isTransient(EObject owner, EStructuralFeature feature, int index) {
    if (feature == XtextPackage.eINSTANCE.getTypeRef_Metamodel()) {
        final TypeRef typeRef = (TypeRef) owner;
        final AbstractMetamodelDeclaration m = typeRef.getMetamodel();
        if (m == null || Strings.isEmpty(m.getAlias()))
            return true;
    } else if (feature == XtextPackage.eINSTANCE.getAbstractRule_Type()) {
        final AbstractRule rule = (AbstractRule) owner;
        if (rule instanceof ParserRule || rule instanceof EnumRule) {
            final TypeRef returnType = rule.getType();
            if (returnType == null || returnType.getClassifier() == null)
                return true;
            else if (rule.getName().equals(returnType.getClassifier().getName())) {
                return isTransient(returnType, XtextPackage.eINSTANCE.getTypeRef_Metamodel(), -1);
            } else if (GrammarUtil.isDatatypeRule(rule)) {
                return NodeModelUtils.getNode(returnType) == null;
            }
        } else if (rule instanceof TerminalRule) {
            final TypeRef returnType = rule.getType();
            return ((TerminalRule) rule).isFragment() || returnType == null || GrammarUtil.findEString(GrammarUtil.getGrammar(owner)).equals(rule.getType().getClassifier());
        }
    } else if (feature == XtextPackage.eINSTANCE.getCrossReference_Terminal()) {
        final CrossReference ref = (CrossReference) owner;
        if (ref.getTerminal() instanceof RuleCall && ((RuleCall) ref.getTerminal()).getRule() != null && "ID".equals(((RuleCall) ref.getTerminal()).getRule().getName()))
            return true;
    } else if (feature == XtextPackage.eINSTANCE.getEnumLiteralDeclaration_Literal()) {
        final EnumLiteralDeclaration decl = (EnumLiteralDeclaration) owner;
        return decl.getEnumLiteral() != null && decl.getLiteral() != null && Strings.equal(decl.getLiteral().getValue(), decl.getEnumLiteral().getName());
    } else if (feature == XtextPackage.eINSTANCE.getRuleCall_ExplicitlyCalled()) {
        return true;
    } else if (feature == XtextPackage.eINSTANCE.getNamedArgument_Parameter()) {
        return !((NamedArgument) owner).isCalledByName();
    }
    return super.isTransient(owner, feature, index);
}
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) NamedArgument(org.eclipse.xtext.NamedArgument) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Aggregations

EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)11 EnumRule (org.eclipse.xtext.EnumRule)8 EEnum (org.eclipse.emf.ecore.EEnum)5 EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)4 EPackage (org.eclipse.emf.ecore.EPackage)4 CrossReference (org.eclipse.xtext.CrossReference)4 Grammar (org.eclipse.xtext.Grammar)4 RuleCall (org.eclipse.xtext.RuleCall)4 TypeRef (org.eclipse.xtext.TypeRef)4 Keyword (org.eclipse.xtext.Keyword)3 ParserRule (org.eclipse.xtext.ParserRule)3 TerminalRule (org.eclipse.xtext.TerminalRule)3 Test (org.junit.Test)3 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)2 AbstractRule (org.eclipse.xtext.AbstractRule)2 Action (org.eclipse.xtext.Action)2 Assignment (org.eclipse.xtext.Assignment)2 GeneratedMetamodel (org.eclipse.xtext.GeneratedMetamodel)2 NamedArgument (org.eclipse.xtext.NamedArgument)2 ReferencedMetamodel (org.eclipse.xtext.ReferencedMetamodel)2