use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class SerializationContext method forChild.
public static ISerializationContext forChild(ISerializationContext container, RuleCall ruleCall, EObject sem) {
EClass type = sem == null ? null : sem.eClass();
ISerializationContext result = new TypeContext(new RuleContext(null, (ParserRule) ruleCall.getRule()), type);
EList<NamedArgument> arguments = ruleCall.getArguments();
if (!arguments.isEmpty() && container != null) {
Set<Parameter> params = Sets.newLinkedHashSet();
ConditionEvaluator evaluator = new ConditionEvaluator(container.getEnabledBooleanParameters());
for (NamedArgument argument : arguments) {
if (evaluator.evaluate(argument.getValue())) {
params.add(argument.getParameter());
}
}
result = new SerializationContext.ParameterValueContext(result, params);
}
return result;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class SyntacticSequencerPDAProvider method getSyntacticSequencerPDAs.
@Override
public SerializationContextMap<ISynAbsorberState> getSyntacticSequencerPDAs(Grammar grammar) {
SerializationContextMap<ISynAbsorberState> cached = cache.get(grammar);
if (cached != null)
return cached;
SerializationContextMap.Builder<ISynAbsorberState> builder = SerializationContextMap.builder();
SerializationContextMap<Pda<ISerState, RuleCall>> typePDAs = pdaProvider.getContextTypePDAs(grammar);
for (Entry<Pda<ISerState, RuleCall>> e : typePDAs.values()) {
Pda<ISerState, RuleCall> pda = e.getValue();
List<ISerializationContext> contexts = e.getContexts();
try {
EClass type = contexts.get(0).getType();
Map<ISerState, SynAbsorberState> absorbers = Maps.newLinkedHashMap();
Map<SynAbsorberState, Map<ISerState, SynState>> emitters = Maps.newLinkedHashMap();
SynAbsorberState state = createAbsorberState(pda.getStart(), absorbers, emitters, type);
builder.put(contexts, state);
} catch (Exception x) {
String ctxs = Joiner.on(", ").join(contexts);
LOG.error("Error creating PDA for syntactic sequencer for contexts: " + ctxs + ": " + x.getMessage(), x);
}
}
SerializationContextMap<ISynAbsorberState> result = builder.create();
cache.put(grammar, result);
return result;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class SequencerDiagnosticProvider method createInvalidContextOrTypeDiagnostic.
@Override
public ISerializationDiagnostic createInvalidContextOrTypeDiagnostic(EObject sem, ISerializationContext context) {
Set<ISerializationContext> contexts = Sets.newHashSet(contextFinder.findByContentsAndContainer(sem, null));
Set<EClass> validTypes = getValidTypes(context);
List<ISerializationContext> recommendedCtxs = Lists.newArrayList();
List<ISerializationContext> otherValidCtxs = Lists.newArrayList();
for (ISerializationContext ctx : getValidContexts(sem.eClass())) {
if (contexts.contains(ctx))
recommendedCtxs.add(ctx);
else
otherValidCtxs.add(ctx);
}
String semanticType = sem.eClass().getName();
String validTypeNames = Joiner.on(", ").join(Iterables.transform(validTypes, new NamedElement2Name()));
StringBuilder msg = new StringBuilder();
msg.append("The context '" + context + "' is not valid for type '" + semanticType + "'\n");
msg.append("Recommended contexts for type '" + semanticType + "': " + recommendedCtxs + "\n");
if (!otherValidCtxs.isEmpty())
msg.append("Other valid contexts for type '" + semanticType + "': " + otherValidCtxs);
msg.append("The context '" + context + "' is valid for types: " + validTypeNames + "\n");
return new SerializationDiagnostic(INVALID_CONTEXT_OR_TYPE, sem, grammarAccess.getGrammar(), msg.toString());
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class Serializer method serializeToRegions.
public ITextRegionAccess serializeToRegions(EObject obj) {
checkNotNull(obj, "obj must not be null.");
ISerializationContext context = getIContext(obj);
TextRegionAccessBuilder builder = textRegionBuilderProvider.get();
ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
serialize(context, obj, builder.forSequence(context, obj), errors);
ITextRegionAccess regionAccess = builder.create();
return regionAccess;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class AbstractSyntacticSequencer method init.
@Override
@Deprecated
public void init(EObject context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) {
ISerializationContext ctx = SerializationContext.fromEObject(context, semanticObject);
init(ctx, semanticObject, sequenceAcceptor, errorAcceptor);
}
Aggregations