mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
[serializer] check value ranges properly to determine context
Signed-off-by: Moritz Eysholdt <moritz.eysholdt@itemis.de>
This commit is contained in:
parent
24845d80a5
commit
77e153e61a
2 changed files with 44 additions and 20 deletions
|
@ -162,7 +162,8 @@ public class ContextFinder implements IContextFinder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<ISerializationContext> findByContentsAndContainer(EObject semanticObject, Iterable<ISerializationContext> contextCandidates) {
|
||||
public Set<ISerializationContext> findByContentsAndContainer(EObject semanticObject,
|
||||
Iterable<ISerializationContext> contextCandidates) {
|
||||
initConstraints();
|
||||
contextCandidates = findContextsByContainer(semanticObject, contextCandidates);
|
||||
if (contextCandidates != null && Iterables.size(contextCandidates) < 2)
|
||||
|
@ -225,8 +226,7 @@ public class ContextFinder implements IContextFinder {
|
|||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Iterable<EObject> findContextsByContentsAndContainer(EObject semanticObject,
|
||||
Iterable<EObject> contextCandidates) {
|
||||
public Iterable<EObject> findContextsByContentsAndContainer(EObject semanticObject, Iterable<EObject> contextCandidates) {
|
||||
List<ISerializationContext> candidates = fromEObjects(contextCandidates, semanticObject);
|
||||
return fromIContexts(findByContentsAndContainer(semanticObject, candidates));
|
||||
}
|
||||
|
@ -283,24 +283,31 @@ public class ContextFinder implements IContextFinder {
|
|||
return false;
|
||||
for (int featureID = 0; featureID < semanicObj.eClass().getFeatureCount(); featureID++) {
|
||||
IFeatureInfo featureInfo = constraint.getFeatures()[featureID];
|
||||
EStructuralFeature structuralFeature = semanicObj.eClass().getEStructuralFeature(featureID);
|
||||
// TODO validated bounds of lists properly
|
||||
ValueTransient trans = transientValueUtil.isTransient(semanicObj, structuralFeature);
|
||||
switch (trans) {
|
||||
case NO:
|
||||
if (featureInfo == null)
|
||||
return false;
|
||||
if (featureInfo.getUpperBound() <= 0)
|
||||
return false;
|
||||
break;
|
||||
case YES:
|
||||
if (featureInfo == null)
|
||||
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;
|
||||
if (featureInfo.getLowerBound() > 0)
|
||||
return false;
|
||||
break;
|
||||
case PREFERABLY:
|
||||
break;
|
||||
case YES:
|
||||
if (featureInfo == null)
|
||||
break;
|
||||
if (featureInfo.getLowerBound() > 0)
|
||||
return false;
|
||||
break;
|
||||
case PREFERABLY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -61,6 +61,23 @@ public class TransientValueUtil {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public int countNonTransientListValues(EObject container, EStructuralFeature feature) {
|
||||
switch (transientValues.isListTransient(container, feature)) {
|
||||
case SOME:
|
||||
int result = 0;
|
||||
List<?> values = (List<?>) container.eGet(feature);
|
||||
for (int i = 0; i < values.size(); i++)
|
||||
if (!transientValues.isValueInListTransient(container, i, feature))
|
||||
result++;
|
||||
return result;
|
||||
case NO:
|
||||
return ((List<?>) container.eGet(feature)).size();
|
||||
case YES:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ValueTransient isTransient(EObject obj, EStructuralFeature feature) {
|
||||
if (feature.isMany())
|
||||
switch (transientValues.isListTransient(obj, feature)) {
|
||||
|
|
Loading…
Reference in a new issue