Search in sources :

Example 91 with AbstractElement

use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.

the class ContentAssistFragment2 method handleAssignmentOptions.

private StringConcatenationClient handleAssignmentOptions(final Iterable<AbstractElement> terminals) {
    StringConcatenationClient _xblockexpression = null;
    {
        final HashSet<EClass> processedTerminals = CollectionLiterals.<EClass>newHashSet();
        final Function2<ArrayList<AbstractElement>, AbstractElement, ArrayList<AbstractElement>> _function = (ArrayList<AbstractElement> candidates, AbstractElement terminal) -> {
            ArrayList<AbstractElement> _xblockexpression_1 = null;
            {
                boolean _contains = processedTerminals.contains(terminal.eClass());
                boolean _not = (!_contains);
                if (_not) {
                    EClass _eClass = terminal.eClass();
                    processedTerminals.add(_eClass);
                    candidates.add(terminal);
                }
                _xblockexpression_1 = candidates;
            }
            return _xblockexpression_1;
        };
        final ArrayList<AbstractElement> candidates = IterableExtensions.<AbstractElement, ArrayList<AbstractElement>>fold(terminals, CollectionLiterals.<AbstractElement>newArrayList(), _function);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                {
                    for (final AbstractElement terminal : candidates) {
                        _builder.append("if (assignment.getTerminal() instanceof ");
                        Class<?> _instanceClass = terminal.eClass().getInstanceClass();
                        _builder.append(_instanceClass);
                        _builder.append(") {");
                        _builder.newLineIfNotEmpty();
                        _builder.append("\t");
                        StringConcatenationClient _client = new StringConcatenationClient() {

                            @Override
                            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                                _builder.append("assignment.getTerminal()");
                            }
                        };
                        StringConcatenationClient _assignmentTerminal = ContentAssistFragment2.this.assignmentTerminal(terminal, _client);
                        _builder.append(_assignmentTerminal, "\t");
                        _builder.newLineIfNotEmpty();
                        _builder.append("}");
                        _builder.newLine();
                    }
                }
            }
        };
        _xblockexpression = _client;
    }
    return _xblockexpression;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ArrayList(java.util.ArrayList) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) HashSet(java.util.HashSet)

Example 92 with AbstractElement

use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.

the class ContentAssistFragment2 method handleAssignment.

private StringConcatenationClient handleAssignment(final Assignment assignment) {
    StringConcatenationClient _xblockexpression = null;
    {
        final Function1<Assignment, Boolean> _function = (Assignment it) -> {
            String _feature = it.getFeature();
            String _feature_1 = assignment.getFeature();
            return Boolean.valueOf(Objects.equal(_feature, _feature_1));
        };
        final Function1<Assignment, AbstractElement> _function_1 = (Assignment it) -> {
            return it.getTerminal();
        };
        final List<AbstractElement> terminals = IterableExtensions.<AbstractElement>toList(IterableExtensions.<Assignment, AbstractElement>map(IterableExtensions.<Assignment>filter(GrammarUtil.containedAssignments(GrammarUtil.containingParserRule(assignment)), _function), _function_1));
        final Function1<AbstractElement, EClass> _function_2 = (AbstractElement it) -> {
            return it.eClass();
        };
        final Set<EClass> terminalTypes = IterableExtensions.<EClass>toSet(ListExtensions.<AbstractElement, EClass>map(terminals, _function_2));
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("public void complete");
                String _fQFeatureName = ContentAssistFragment2.this.getFQFeatureName(assignment);
                _builder.append(_fQFeatureName);
                _builder.append("(");
                _builder.append(EObject.class);
                _builder.append(" model, ");
                _builder.append(Assignment.class);
                _builder.append(" assignment, ");
                TypeReference _contentAssistContextClass = ContentAssistFragment2.this.getContentAssistContextClass();
                _builder.append(_contentAssistContextClass);
                _builder.append(" context, ");
                TypeReference _iCompletionProposalAcceptorClass = ContentAssistFragment2.this.getICompletionProposalAcceptorClass();
                _builder.append(_iCompletionProposalAcceptorClass);
                _builder.append(" acceptor) {");
                _builder.newLineIfNotEmpty();
                {
                    int _size = terminalTypes.size();
                    boolean _greaterThan = (_size > 1);
                    if (_greaterThan) {
                        _builder.append("\t");
                        StringConcatenationClient _handleAssignmentOptions = ContentAssistFragment2.this.handleAssignmentOptions(terminals);
                        _builder.append(_handleAssignmentOptions, "\t");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t");
                        AbstractElement _terminal = assignment.getTerminal();
                        StringConcatenationClient _client = new StringConcatenationClient() {

                            @Override
                            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                                _builder.append("assignment.getTerminal()");
                            }
                        };
                        StringConcatenationClient _assignmentTerminal = ContentAssistFragment2.this.assignmentTerminal(_terminal, _client);
                        _builder.append(_assignmentTerminal, "\t");
                        _builder.newLineIfNotEmpty();
                    }
                }
                _builder.append("}");
                _builder.newLine();
            }
        };
        _xblockexpression = _client;
    }
    return _xblockexpression;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Assignment(org.eclipse.xtext.Assignment) EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 93 with AbstractElement

use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.

the class SyntheticTerminalDetector method isSyntheticTerminalRule.

/**
 * Answers {@code true} if the given terminal rule is synthetic. That is,
 * the tokens for this rule will not be produced by the generated Antlr lexer
 * but manually in a custom token source.
 */
public boolean isSyntheticTerminalRule(final TerminalRule rule) {
    AbstractElement _alternatives = rule.getAlternatives();
    if ((_alternatives instanceof Keyword)) {
        AbstractElement _alternatives_1 = rule.getAlternatives();
        String value = ((Keyword) _alternatives_1).getValue();
        String _name = AntlrGrammarGenUtil.<TerminalRule>getOriginalElement(rule).getName();
        String _plus = ("synthetic:" + _name);
        return Objects.equal(_plus, value);
    }
    return false;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) Keyword(org.eclipse.xtext.Keyword)

Example 94 with AbstractElement

use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.

the class GrammarPDAProviderTest method assertNoLeakedGrammarElements.

private void assertNoLeakedGrammarElements(final Grammar grammar, final Pda<ISerState, RuleCall> pda) {
    final Function1<ISerState, AbstractElement> _function = (ISerState it) -> {
        return it.getGrammarElement();
    };
    Iterable<AbstractElement> _filterNull = IterableExtensions.<AbstractElement>filterNull(IterableExtensions.<ISerState, AbstractElement>map(new NfaUtil().<ISerState>collect(pda), _function));
    for (final AbstractElement ele : _filterNull) {
        {
            final Grammar actual = GrammarUtil.getGrammar(ele);
            if ((actual != grammar)) {
                String _objPath = EmfFormatter.objPath(ele);
                String _plus = ("Element " + _objPath);
                String _plus_1 = (_plus + " leaked!");
                Assert.fail(_plus_1);
            }
        }
    }
}
Also used : ISerState(org.eclipse.xtext.serializer.analysis.ISerState) AbstractElement(org.eclipse.xtext.AbstractElement) NfaUtil(org.eclipse.xtext.util.formallang.NfaUtil) Grammar(org.eclipse.xtext.Grammar)

Example 95 with AbstractElement

use of org.eclipse.xtext.AbstractElement 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)

Aggregations

AbstractElement (org.eclipse.xtext.AbstractElement)126 EObject (org.eclipse.emf.ecore.EObject)39 AbstractRule (org.eclipse.xtext.AbstractRule)34 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)31 RuleCall (org.eclipse.xtext.RuleCall)26 ParserRule (org.eclipse.xtext.ParserRule)18 Grammar (org.eclipse.xtext.Grammar)17 EList (org.eclipse.emf.common.util.EList)15 Assignment (org.eclipse.xtext.Assignment)15 Test (org.junit.Test)14 Group (org.eclipse.xtext.Group)13 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)13 List (java.util.List)12 ArrayList (java.util.ArrayList)11 XtextResource (org.eclipse.xtext.resource.XtextResource)11 Action (org.eclipse.xtext.Action)10 TerminalRule (org.eclipse.xtext.TerminalRule)10 Alternatives (org.eclipse.xtext.Alternatives)9 EClassifier (org.eclipse.emf.ecore.EClassifier)8 InternalEObject (org.eclipse.emf.ecore.InternalEObject)8