Search in sources :

Example 1 with ValueTransient

use of org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient in project xtext-core by eclipse.

the class PartialSerializer method trySerializeSingleValue.

protected List<SerializationStrategy> trySerializeSingleValue(EObject owner, FeatureChange change, IEObjectRegion ownerRegion, IConstraint constraint) {
    List<SerializationStrategy> result = Lists.newArrayList();
    EStructuralFeature feature = change.getFeature();
    IFeatureInfo featureInfo = constraint.getFeatures()[owner.eClass().getFeatureID(feature)];
    List<IConstraintElement> assignments = featureInfo.getAssignments();
    if (assignments.size() != 1) {
        return null;
    }
    boolean optional = assignments.get(0).isOptional();
    IAstRegion featureRegion = findRegion(ownerRegion, change);
    ValueTransient valueTransient = transientValues.isValueTransient(owner, feature);
    switch(valueTransient) {
        case YES:
            if (featureRegion != null) {
                if (optional) {
                    result.add(new DeleteRegionStrategy(featureRegion));
                } else {
                    return null;
                }
            }
            break;
        case PREFERABLY:
            if (featureRegion != null) {
                if (optional) {
                    result.add(new DeleteRegionStrategy(featureRegion));
                } else {
                    SerializationStrategy update = updateSingleValue(owner, feature, featureRegion);
                    if (update != null) {
                        result.add(update);
                    } else {
                        return null;
                    }
                }
            }
            break;
        case NO:
            if (featureRegion == null) {
                return null;
            }
            SerializationStrategy update = updateSingleValue(owner, feature, featureRegion);
            if (update != null) {
                result.add(update);
            } else {
                return null;
            }
            break;
    }
    return result;
}
Also used : IConstraintElement(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraintElement) ValueTransient(org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient) IAstRegion(org.eclipse.xtext.formatting2.regionaccess.IAstRegion) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IFeatureInfo(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IFeatureInfo)

Example 2 with ValueTransient

use of org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient in project xtext-core by eclipse.

the class ContextFinder method isValidValueQuantity.

protected boolean isValidValueQuantity(IConstraint constraint, EObject semanicObj) {
    if (constraint == null)
        return false;
    for (int featureID = 0; featureID < semanicObj.eClass().getFeatureCount(); featureID++) {
        IFeatureInfo featureInfo = constraint.getFeatures()[featureID];
        EStructuralFeature feature = semanicObj.eClass().getEStructuralFeature(featureID);
        if (feature.isMany()) {
            int count = transientValueUtil.countNonTransientListValues(semanicObj, feature);
            if (count > featureInfo.getUpperBound())
                return false;
            if (count < featureInfo.getLowerBound())
                return false;
        } else {
            ValueTransient valueTransient = transientValues.isValueTransient(semanicObj, feature);
            switch(valueTransient) {
                case NO:
                    if (featureInfo == null)
                        return false;
                    if (featureInfo.getUpperBound() <= 0)
                        return false;
                    break;
                case YES:
                    if (featureInfo == null)
                        break;
                    if (featureInfo.getLowerBound() > 0)
                        return false;
                    break;
                case PREFERABLY:
                    break;
            }
        }
    }
    return true;
}
Also used : ValueTransient(org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IConstraint(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint) IFeatureInfo(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IFeatureInfo)

Aggregations

EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 IFeatureInfo (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IFeatureInfo)2 ValueTransient (org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient)2 IAstRegion (org.eclipse.xtext.formatting2.regionaccess.IAstRegion)1 IConstraint (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint)1 IConstraintElement (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraintElement)1