use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-eclipse by eclipse.
the class SerializerTester method serialize.
/**
* @since 2.3
*/
protected String serialize(EObject semanticObject, DelegatingSequenceAcceptor... acceptors) {
ISequenceAcceptor debug = null;
try {
ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
ISemanticSequencer semantic = semanticSequencerProvider.get();
ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
ISequenceAcceptor result = new StringBufferSequenceAcceptor();
ISequenceAcceptor out = result;
for (DelegatingSequenceAcceptor delegate : acceptors) {
delegate.setDelegate(out);
out = delegate;
}
out = debug = new DebugSequenceAcceptor(out);
semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
ISerializationContext context = getContext(semanticObject);
syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
hidden.init(context, semanticObject, out, errors);
semantic.createSequence(context, semanticObject);
return result.toString();
} catch (Exception t) {
if (debug != null) {
System.out.println("Serializer debug output:");
System.out.println(debug.toString());
}
Exceptions.sneakyThrow(t);
return "";
}
}
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;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class NamedSerializationContextProvider method getSignificantGrammarElement.
public String getSignificantGrammarElement(Iterable<ISerializationContext> contexts) {
ParserRule rule = null;
int index = Integer.MAX_VALUE;
for (ISerializationContext ctx : contexts) {
ParserRule pr = ctx.getParserRule();
if (pr == null) {
Action action = ctx.getAssignedAction();
if (action != null) {
pr = GrammarUtil.containingParserRule(action);
}
}
if (pr != null) {
Integer i = 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 SequenceFeeder method acceptEObjectRuleCall.
protected void acceptEObjectRuleCall(RuleCall ruleCall, EObject semanticChild, ICompositeNode node) {
if (sequenceAcceptor.enterAssignedParserRuleCall(ruleCall, semanticChild, node)) {
ISerializationContext child = SerializationContext.forChild(context, ruleCall, semanticChild);
masterSequencer.createSequence(child, semanticChild);
sequenceAcceptor.leaveAssignedParserRuleCall(ruleCall, semanticChild);
}
}
use of org.eclipse.xtext.serializer.ISerializationContext 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