Search in sources :

Example 11 with GrammarElementTitleSwitch

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()));
}
Also used : GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) AbstractElement(org.eclipse.xtext.AbstractElement)

Example 12 with GrammarElementTitleSwitch

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;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 13 with GrammarElementTitleSwitch

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);
        }
    }
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) GrammarAlias(org.eclipse.xtext.serializer.analysis.GrammarAlias)

Aggregations

GrammarElementTitleSwitch (org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch)13 AbstractElement (org.eclipse.xtext.AbstractElement)4 RuleCall (org.eclipse.xtext.RuleCall)4 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)3 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)3 INode (org.eclipse.xtext.nodemodel.INode)3 ISerState (org.eclipse.xtext.serializer.analysis.ISerState)3 PdaListFormatter (org.eclipse.xtext.util.formallang.PdaListFormatter)3 EObject (org.eclipse.emf.ecore.EObject)2 Grammar (org.eclipse.xtext.Grammar)2 Pda (org.eclipse.xtext.util.formallang.Pda)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 AbstractRule (org.eclipse.xtext.AbstractRule)1 CrossReference (org.eclipse.xtext.CrossReference)1 MultilineCommentReplacer (org.eclipse.xtext.formatting2.internal.MultilineCommentReplacer)1 SinglelineCodeCommentReplacer (org.eclipse.xtext.formatting2.internal.SinglelineCodeCommentReplacer)1 SinglelineDocCommentReplacer (org.eclipse.xtext.formatting2.internal.SinglelineDocCommentReplacer)1 ContentAssistContext (org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext)1 SyntaxErrorMessage (org.eclipse.xtext.nodemodel.SyntaxErrorMessage)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1