use of org.eclipse.xtext.serializer.analysis.SerializationContext.TypeContext in project xtext-core by eclipse.
the class ContextTypePDAProvider method getContextTypePDAs.
@Override
public SerializationContextMap<Pda<ISerState, RuleCall>> getContextTypePDAs(Grammar grammar) {
SerializationContextMap<Pda<ISerState, RuleCall>> cached = cache.get(grammar);
if (cached != null)
return cached;
SerializationContextMap.Builder<Pda<ISerState, RuleCall>> builder = SerializationContextMap.builder();
SerializationContextMap<Pda<ISerState, RuleCall>> contextPDAs = pdaProvider.getContextPDAs(grammar);
for (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> e : contextPDAs.values()) {
List<ISerializationContext> parents = e.getContexts();
Pda<ISerState, RuleCall> contextPDA = e.getValue();
try {
Map<ISerState, Integer> distances = nfaUtil.distanceToFinalStateMap(contextPDA);
Set<EClass> types = collectTypes(contextPDA, distances);
if (types.size() == 1) {
for (ISerializationContext parent : parents) {
TypeContext ctx = new TypeContext(parent, types.iterator().next());
builder.put(ctx, contextPDA);
}
} else {
for (EClass type : types) {
Pda<ISerState, RuleCall> filtered = filterByType(contextPDA, type, distances);
for (ISerializationContext parent : parents) {
TypeContext typeContext = new TypeContext(parent, type);
builder.put(typeContext, filtered);
}
}
}
} catch (Exception x) {
LOG.error("Error extracting PDAs for types for context '" + parents + "': " + x.getMessage(), x);
}
}
SerializationContextMap<Pda<ISerState, RuleCall>> result = builder.create();
cache.put(grammar, result);
return result;
}
Aggregations