use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.
the class AssignmentFinderTest method findAssignments.
private String findAssignments(EObject obj, Object value, AbstractElement... assignments) {
AbstractElement element = (AbstractElement) NodeModelUtils.getNode(obj).getGrammarElement();
ISerializationContext ctx = SerializationContext.forChild(null, element, obj);
Multimap<AbstractElement, ISerializationContext> ass = ArrayListMultimap.create();
for (AbstractElement e : assignments) ass.put(e, ctx);
List<AbstractElement> found = Lists.newArrayList(finder.findAssignmentsByValue(obj, ass, value, null));
Collections.sort(found, GrammarElementDeclarationOrder.get(GrammarUtil.getGrammar(assignments[0])));
return Joiner.on(", ").join(Iterables.transform(found, new GrammarElementTitleSwitch().showAssignments()));
}
use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.
the class SyntacticSequencerTest method getNodeSequence.
@SuppressWarnings("deprecation")
private List<String> getNodeSequence(EObject model) {
List<String> result = Lists.newArrayList();
GrammarElementTitleSwitch titleSwitch = new GrammarElementTitleSwitch().showAssignments();
org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator ni = new org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator(NodeModelUtils.findActualNodeFor(model));
while (ni.hasNext()) {
INode next = ni.next();
EObject ele = next.getGrammarElement() instanceof CrossReference ? ((CrossReference) next.getGrammarElement()).getTerminal() : next.getGrammarElement();
if (next instanceof ILeafNode || GrammarUtil.isDatatypeRuleCall(ele))
result.add(titleSwitch.doSwitch(ele) + " -> " + next.getText().trim());
else if (next instanceof ICompositeNode)
result.add(titleSwitch.doSwitch(ele));
}
return result;
}
use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.
the class EqualAmbiguousTransitions method ambiguityInsideTransition.
public String ambiguityInsideTransition(final ISyntacticSequencerPDAProvider.ISynTransition trans) {
try {
final GrammarElementTitleSwitch tokenToString = new GrammarElementTitleSwitch().showAssignments().hideCardinality().setValueForNull("");
final ProductionFormatter<GrammarAlias.AbstractElementAlias, AbstractElement> formatter = new ProductionFormatter<GrammarAlias.AbstractElementAlias, AbstractElement>() {
@Override
public String format(final Production<GrammarAlias.AbstractElementAlias, AbstractElement> adapter, final GrammarAlias.AbstractElementAlias grammarElement, final boolean needParenthesis) {
String _switchResult = null;
boolean _matched = false;
boolean _equals = Objects.equal(grammarElement, EqualAmbiguousTransitions.this.elementAlias);
if (_equals) {
_matched = true;
return "(ambiguity)";
}
if (!_matched) {
if (grammarElement instanceof GrammarAlias.TokenAlias) {
boolean _isStart = EqualAmbiguousTransitions.this.isStart(((GrammarAlias.TokenAlias) grammarElement));
if (_isStart) {
_matched = true;
return "(rule start)";
}
}
}
if (!_matched) {
if (grammarElement instanceof GrammarAlias.TokenAlias) {
boolean _isStop = EqualAmbiguousTransitions.this.isStop(((GrammarAlias.TokenAlias) grammarElement));
if (_isStop) {
_matched = true;
return "(rule end)";
}
}
}
if (!_matched) {
_switchResult = super.format(adapter, grammarElement, needParenthesis);
}
return _switchResult;
}
}.setTokenToString(tokenToString).setAutoWrapChars(200).setAutoWrapChildren(20);
GrammarAlias.AbstractElementAlias _ambiguousSyntax = trans.getAmbiguousSyntax();
final GrammarAlias.GrammarAliasAdapter adapter = new GrammarAlias.GrammarAliasAdapter(_ambiguousSyntax);
return formatter.format(adapter, adapter.getRoot(), false);
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e = (Exception) _t;
e.printStackTrace();
return "";
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
Aggregations