use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class ContextFinder method collectAssignments.
protected Multimap<AbstractElement, ISerializationContext> collectAssignments(Multimap<IConstraint, ISerializationContext> constraints, EStructuralFeature feature) {
Multimap<AbstractElement, ISerializationContext> result = ArrayListMultimap.create();
for (Entry<IConstraint, Collection<ISerializationContext>> e : constraints.asMap().entrySet()) {
IConstraint constraint = e.getKey();
Collection<ISerializationContext> contexts = e.getValue();
IFeatureInfo featureInfo = constraint.getFeatures()[constraint.getType().getFeatureID(feature)];
List<IConstraintElement> assignments = featureInfo.getAssignments();
for (IConstraintElement assignment : assignments) {
result.putAll(assignment.getGrammarElement(), contexts);
}
}
return result;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class ContextFinder method findByContents.
@Override
public Set<ISerializationContext> findByContents(EObject semanticObject, Iterable<ISerializationContext> contextCandidates) {
if (semanticObject == null)
throw new NullPointerException();
initConstraints();
Multimap<IConstraint, ISerializationContext> constraints;
if (contextCandidates != null)
constraints = getConstraints(semanticObject, contextCandidates);
else
constraints = getConstraints(semanticObject);
if (constraints.size() < 2)
return Sets.newLinkedHashSet(constraints.values());
for (IConstraint cand : Lists.newArrayList(constraints.keySet())) if (!isValidValueQuantity(cand, semanticObject))
constraints.removeAll(cand);
if (constraints.size() < 2)
return Sets.newLinkedHashSet(constraints.values());
LinkedHashSet<ISerializationContext> result = Sets.newLinkedHashSet(constraints.values());
for (EStructuralFeature feat : semanticObject.eClass().getEAllStructuralFeatures()) {
if (transientValueUtil.isTransient(semanticObject, feat) != ValueTransient.NO)
continue;
if (feat.isMany() && ((List<?>) semanticObject.eGet(feat)).isEmpty())
continue;
Multimap<AbstractElement, ISerializationContext> assignments = collectAssignments(constraints, feat);
Set<AbstractElement> assignedElements = findAssignedElements(semanticObject, feat, assignments);
Set<ISerializationContext> keep = Sets.newHashSet();
for (AbstractElement ele : assignedElements) keep.addAll(assignments.get(ele));
result.retainAll(keep);
}
return result;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class ContextFinder method getConstraints.
protected Multimap<IConstraint, ISerializationContext> getConstraints(EObject sem) {
EClass type = sem == null ? null : sem.eClass();
Multimap<IConstraint, ISerializationContext> result = ArrayListMultimap.create();
for (SerializationContextMap.Entry<IConstraint> e : constraints.values()) {
IConstraint constraint = e.getValue();
for (ISerializationContext context : e.getContexts()) {
if (constraint.getType() == type) {
result.put(constraint, context);
}
}
}
return result;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class SequenceFeeder method acceptAction.
protected void acceptAction(Action action, EObject semanticChild, ICompositeNode node) {
if (sequenceAcceptor.enterAssignedAction(action, semanticChild, node)) {
ISerializationContext child = SerializationContext.forChild(context, action, semanticChild);
masterSequencer.createSequence(child, semanticChild);
sequenceAcceptor.leaveAssignedAction(action, semanticChild);
}
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class SerializerFragment2 method genMethodCreateSequenceCaseBody.
private StringConcatenationClient genMethodCreateSequenceCaseBody(final Map<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint> superConstraints, final EClass type) {
StringConcatenationClient _xblockexpression = null;
{
final Function1<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>, String> _function = (Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>> it) -> {
return it.getKey().getName();
};
final List<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>> contexts = IterableExtensions.<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>, String>sortBy(this._semanticSequencerExtensions.getGrammarConstraints(this.getGrammar(), type).entrySet(), _function);
final LinkedHashMultimap<EObject, IGrammarConstraintProvider.IConstraint> context2constraint = LinkedHashMultimap.<EObject, IGrammarConstraintProvider.IConstraint>create();
for (final Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>> e : contexts) {
List<ISerializationContext> _value = e.getValue();
for (final ISerializationContext ctx : _value) {
context2constraint.put(((SerializationContext) ctx).getActionOrRule(), e.getKey());
}
}
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
int _size = contexts.size();
boolean _greaterThan = (_size > 1);
if (_greaterThan) {
{
Iterable<Pair<Integer, Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>>> _indexed = IterableExtensions.<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>>indexed(contexts);
for (final Pair<Integer, Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>> ctx : _indexed) {
{
Integer _key = ctx.getKey();
boolean _greaterThan_1 = ((_key).intValue() > 0);
if (_greaterThan_1) {
_builder.append("else ");
}
}
_builder.append("if (");
StringConcatenationClient _genCondition = SerializerFragment2.this.genCondition(ctx.getValue().getValue(), ctx.getValue().getKey(), context2constraint);
_builder.append(_genCondition);
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
StringConcatenationClient _genMethodCreateSequenceCall = SerializerFragment2.this.genMethodCreateSequenceCall(superConstraints, type, ctx.getValue().getKey());
_builder.append(_genMethodCreateSequenceCall, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
}
_builder.append("else break;");
_builder.newLine();
} else {
int _size_1 = contexts.size();
boolean _equals = (_size_1 == 1);
if (_equals) {
StringConcatenationClient _genMethodCreateSequenceCall_1 = SerializerFragment2.this.genMethodCreateSequenceCall(superConstraints, type, IterableExtensions.<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>>head(contexts).getKey());
_builder.append(_genMethodCreateSequenceCall_1);
_builder.newLineIfNotEmpty();
} else {
_builder.append("// error, no contexts. ");
_builder.newLine();
}
}
}
}
};
_xblockexpression = _client;
}
return _xblockexpression;
}
Aggregations