use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class AssignmentFinder method findValidAssignmentsForContainmentRef.
protected Set<AbstractElement> findValidAssignmentsForContainmentRef(EObject semanticObj, Multimap<AbstractElement, ISerializationContext> assignments, EObject value) {
Multimap<ISerializationContext, AbstractElement> children = ArrayListMultimap.create();
for (Entry<AbstractElement, Collection<ISerializationContext>> e : assignments.asMap().entrySet()) {
AbstractElement ele = e.getKey();
if (ele instanceof RuleCall) {
EClassifier classifier = ((RuleCall) ele).getRule().getType().getClassifier();
if (!classifier.isInstance(value))
continue;
}
for (ISerializationContext container : e.getValue()) {
ISerializationContext child = SerializationContext.forChild(container, ele, value);
children.put(child, ele);
}
}
if (children.size() < 2)
return Sets.newHashSet(children.values());
Set<ISerializationContext> found = contextFinder.findByContents(value, children.keySet());
Set<AbstractElement> result = Sets.newLinkedHashSet();
for (ISerializationContext ctx : children.keySet()) if (found.contains(ctx))
result.addAll(children.get(ctx));
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, Iterable<ISerializationContext> contextCandidates) {
EClass type = sem == null ? null : sem.eClass();
Multimap<IConstraint, ISerializationContext> result = ArrayListMultimap.create();
for (ISerializationContext ctx : contextCandidates) {
IConstraint constraint = constraints.get(ctx);
if (constraint != null && constraint.getType() == type) {
result.put(constraint, ctx);
}
}
return result;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class ContextFinder method findContextsByContainer.
protected Iterable<ISerializationContext> findContextsByContainer(EObject sem, Iterable<ISerializationContext> contextCandidates) {
if (sem.eResource() != null && sem.eResource().getContents().contains(sem))
return Collections.singleton(getRootContext(sem));
EReference ref = sem.eContainmentFeature();
if (ref == null || (contextCandidates != null && Iterables.size(contextCandidates) < 2))
return contextCandidates;
Multimap<IConstraint, ISerializationContext> containerConstraints = getConstraints(sem.eContainer());
int refID = sem.eContainer().eClass().getFeatureID(ref);
Set<ISerializationContext> childContexts = Sets.newLinkedHashSet();
for (Entry<IConstraint, Collection<ISerializationContext>> e : Lists.newArrayList(containerConstraints.asMap().entrySet())) {
IConstraint constraint = e.getKey();
Collection<ISerializationContext> contexts = e.getValue();
if (constraint.getFeatures()[refID] == null)
containerConstraints.removeAll(constraint);
else {
childContexts.addAll(createContextsForFeatures(contexts, constraint.getFeatures()[refID], sem));
}
}
Set<ISerializationContext> result;
if (contextCandidates != null) {
result = Sets.newLinkedHashSet(contextCandidates);
result.retainAll(childContexts);
} else
result = childContexts;
if (result.size() < 2)
return result;
Iterable<ISerializationContext> filteredContexts = findContextsByContainer(sem.eContainer(), containerConstraints.values());
childContexts = Sets.newLinkedHashSet();
for (Entry<IConstraint, Collection<ISerializationContext>> e : Lists.newArrayList(containerConstraints.asMap().entrySet())) if (intersect(filteredContexts, e.getValue()))
childContexts.addAll(createContextsForFeatures(e.getValue(), e.getKey().getFeatures()[refID], sem));
result.retainAll(childContexts);
return result;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class NamedSerializationContextProvider method getSignificantGrammarElement.
public String getSignificantGrammarElement(final Iterable<ISerializationContext> contexts) {
ParserRule rule = null;
int index = Integer.MAX_VALUE;
for (final ISerializationContext ctx : contexts) {
{
ParserRule pr = ctx.getParserRule();
if ((pr == null)) {
final Action action = ctx.getAssignedAction();
if ((action != null)) {
pr = GrammarUtil.containingParserRule(action);
}
}
if ((pr != null)) {
final Integer i = this.rules.get(pr);
if (((i).intValue() < index)) {
index = (i).intValue();
rule = pr;
}
}
}
}
if ((rule != null)) {
return rule.getName();
}
return "unknown";
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class SerializerFragment2 method genMethodSequenceComment.
private StringConcatenationClient genMethodSequenceComment(final IGrammarConstraintProvider.IConstraint c) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("// This method is commented out because it has the same signature as another method in this class.");
_builder.newLine();
_builder.append("// This is probably a bug in Xtext\'s serializer, please report it here: ");
_builder.newLine();
_builder.append("// https://bugs.eclipse.org/bugs/enter_bug.cgi?product=TMF");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// Contexts:");
_builder.newLine();
_builder.append("// ");
String _replaceAll = IterableExtensions.join(IterableExtensions.<ISerializationContext>sort(c.getContexts()), "\n").replaceAll("\\n", "\n// ");
_builder.append(_replaceAll);
_builder.newLineIfNotEmpty();
_builder.append("//");
_builder.newLine();
_builder.append("// Constraint:");
_builder.newLine();
_builder.append("// ");
{
IGrammarConstraintProvider.IConstraintElement _body = c.getBody();
boolean _tripleEquals = (_body == null);
if (_tripleEquals) {
_builder.append("{");
String _name = c.getType().getName();
_builder.append(_name);
_builder.append("}");
} else {
String _replaceAll_1 = c.getBody().toString().replaceAll("\\n", "\n// ");
_builder.append(_replaceAll_1);
}
}
_builder.newLineIfNotEmpty();
_builder.append("//");
_builder.newLine();
_builder.append("// protected void sequence_");
String _simpleName = c.getSimpleName();
_builder.append(_simpleName);
_builder.append("(");
_builder.append(ISerializationContext.class);
_builder.append(" context, ");
EClass _type = c.getType();
_builder.append(_type);
_builder.append(" semanticObject) { }");
_builder.newLineIfNotEmpty();
}
};
return _client;
}
Aggregations