Search in sources :

Example 16 with CrossReference

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

the class IdeContentProposalProvider method _createProposals.

protected void _createProposals(final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
    final AbstractElement terminal = assignment.getTerminal();
    if ((terminal instanceof CrossReference)) {
        this.createProposals(terminal, context, acceptor);
    } else {
        if ((terminal instanceof RuleCall)) {
            final AbstractRule rule = ((RuleCall) terminal).getRule();
            if (((rule instanceof TerminalRule) && context.getPrefix().isEmpty())) {
                String _xifexpression = null;
                String _name = rule.getName();
                boolean _equals = Objects.equal(_name, "STRING");
                if (_equals) {
                    String _feature = assignment.getFeature();
                    String _plus = ("\"" + _feature);
                    _xifexpression = (_plus + "\"");
                } else {
                    _xifexpression = assignment.getFeature();
                }
                final String proposal = _xifexpression;
                final Procedure1<ContentAssistEntry> _function = (ContentAssistEntry it) -> {
                    String _name_1 = rule.getName();
                    boolean _equals_1 = Objects.equal(_name_1, "STRING");
                    if (_equals_1) {
                        ArrayList<TextRegion> _editPositions = it.getEditPositions();
                        int _offset = context.getOffset();
                        int _plus_1 = (_offset + 1);
                        int _length = proposal.length();
                        int _minus = (_length - 2);
                        TextRegion _textRegion = new TextRegion(_plus_1, _minus);
                        _editPositions.add(_textRegion);
                        it.setKind(ContentAssistEntry.KIND_TEXT);
                    } else {
                        ArrayList<TextRegion> _editPositions_1 = it.getEditPositions();
                        int _offset_1 = context.getOffset();
                        int _length_1 = proposal.length();
                        TextRegion _textRegion_1 = new TextRegion(_offset_1, _length_1);
                        _editPositions_1.add(_textRegion_1);
                        it.setKind(ContentAssistEntry.KIND_VALUE);
                    }
                    it.setDescription(rule.getName());
                };
                final ContentAssistEntry entry = this.proposalCreator.createProposal(proposal, context, _function);
                acceptor.accept(entry, this.proposalPriorities.getDefaultPriority(entry));
            }
        }
    }
}
Also used : ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry) AbstractElement(org.eclipse.xtext.AbstractElement) TextRegion(org.eclipse.xtext.util.TextRegion) ArrayList(java.util.ArrayList) CrossReference(org.eclipse.xtext.CrossReference) TerminalRule(org.eclipse.xtext.TerminalRule) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 17 with CrossReference

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

the class BaseContentAssistParser method getEntryGrammarElement.

protected AbstractElement getEntryGrammarElement(ICompositeNode entryPoint) {
    EObject grammarElement = entryPoint.getGrammarElement();
    if (grammarElement instanceof RuleCall) {
        AbstractRule rule = ((RuleCall) grammarElement).getRule();
        if (rule instanceof ParserRule) {
            if (!GrammarUtil.isMultipleCardinality(rule.getAlternatives())) {
                grammarElement = rule.getAlternatives();
            }
        }
    } else if (grammarElement instanceof ParserRule) {
        grammarElement = ((ParserRule) grammarElement).getAlternatives();
    } else if (grammarElement instanceof CrossReference) {
        grammarElement = GrammarUtil.containingAssignment(grammarElement);
    }
    AbstractElement result = (AbstractElement) grammarElement;
    if (result instanceof Action) {
        return getEntryGrammarElement((ICompositeNode) entryPoint.getFirstChild());
    }
    return result;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 18 with CrossReference

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

the class SemanticSequencerNfaProvider method isContentValidationNeeded.

protected boolean isContentValidationNeeded(Collection<AbstractElement> ass) {
    if (ass == null || ass.size() < 2)
        return false;
    Iterator<AbstractElement> it = ass.iterator();
    AbstractElement first = it.next();
    CrossReference firstRef = GrammarUtil.containingCrossReference(first);
    while (it.hasNext()) {
        AbstractElement next = it.next();
        if (next instanceof Action)
            return true;
        if (!EcoreUtil.equals(first, next))
            return true;
        if (firstRef != null) {
            CrossReference nextRef = GrammarUtil.containingCrossReference(next);
            if (nextRef != null && nextRef.getType().getClassifier() != firstRef.getType().getClassifier())
                return true;
        }
    }
    return false;
}
Also used : Action(org.eclipse.xtext.Action) AbstractElement(org.eclipse.xtext.AbstractElement) CrossReference(org.eclipse.xtext.CrossReference)

Example 19 with CrossReference

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

the class HiddenTokenSequencer method getHiddenNodesBetween.

/**
 * @return null if the whitespace between these nodes is unknown.
 * In this case, the formatter needs to decide.
 */
protected List<INode> getHiddenNodesBetween(INode from, INode to) {
    if (from == null && to == null)
        return null;
    List<INode> out = Lists.newArrayList();
    Set<EObject> deletedSemanticElements = Sets.newHashSet();
    if (to == null) {
        NodeIterator ni = new NodeIterator(from);
        while (ni.hasNext()) {
            INode next = ni.next();
            if (next.getTotalOffset() > rootEndOffset) {
                break;
            }
            if (next == lastEmittedNode) {
                break;
            } else if (tokenUtil.isWhitespaceOrCommentNode(next)) {
                out.add(next);
            } else if (belongsToDeletedElement(next)) {
                handleDeletedElement(out, deletedSemanticElements, next);
                ni.prune();
            } else {
                break;
            }
        }
    } else if (from == null) {
        NodeIterator ni = new NodeIterator(to);
        while (ni.hasPrevious()) {
            INode prev = ni.previous();
            if (prev.getTotalEndOffset() < rootOffset) {
                break;
            }
            if (prev == lastEmittedNode) {
                break;
            } else if (tokenUtil.isWhitespaceOrCommentNode(prev)) {
                out.add(0, prev);
            } else if (belongsToDeletedElement(prev)) {
                handleDeletedElement(out, deletedSemanticElements, prev);
                ni.prune();
            } else {
                break;
            }
        }
    } else {
        NodeIterator ni = new NodeIterator(from);
        while (ni.hasNext()) {
            INode next = ni.next();
            if (tokenUtil.isWhitespaceOrCommentNode(next)) {
                out.add(next);
            } else if (next.equals(to)) {
                if (next instanceof ICompositeNode && (GrammarUtil.isDatatypeRuleCall(next.getGrammarElement()) || GrammarUtil.isEnumRuleCall(next.getGrammarElement()) || next.getGrammarElement() instanceof CrossReference)) {
                    while (ni.hasNext()) {
                        INode next2 = ni.next();
                        if (tokenUtil.isWhitespaceOrCommentNode(next2)) {
                            out.add(next2);
                        } else if (next2 instanceof ILeafNode) {
                            break;
                        }
                    }
                    break;
                } else {
                    break;
                }
            } else if (belongsToDeletedElement(next)) {
                handleDeletedElement(out, deletedSemanticElements, next);
                ni.prune();
            } else if (tokenUtil.isToken(next)) {
                break;
            }
        }
    }
    if ((from == null || to == null) && out.isEmpty()) {
        return null;
    } else {
        return filterNodesOfDeletedElements(out, deletedSemanticElements);
    }
}
Also used : NodeIterator(org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) CrossReference(org.eclipse.xtext.CrossReference)

Example 20 with CrossReference

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

the class AbstractElementFinder method findCrossReferences.

public List<CrossReference> findCrossReferences(EClassifier... targetEClassifiers) {
    Set<EClassifier> classifiers = new HashSet<EClassifier>(Arrays.asList(targetEClassifiers));
    Collection<EClass> classes = Lists.newArrayList(Iterables.filter(classifiers, EClass.class));
    ArrayList<CrossReference> r = new ArrayList<CrossReference>();
    for (AbstractRule ar : getRules()) {
        TreeIterator<EObject> i = ar.eAllContents();
        while (i.hasNext()) {
            EObject o = i.next();
            if (o instanceof CrossReference) {
                CrossReference c = (CrossReference) o;
                if (classifiers.contains(c.getType().getClassifier()))
                    r.add(c);
                else if (c.getType().getClassifier() instanceof EClass)
                    for (EClass cls : classes) if (EcoreUtil2.isAssignableFrom(cls, (EClass) c.getType().getClassifier())) {
                        r.add(c);
                        break;
                    }
                i.prune();
            }
        }
    }
    return r;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) EClassifier(org.eclipse.emf.ecore.EClassifier) CrossReference(org.eclipse.xtext.CrossReference) AbstractRule(org.eclipse.xtext.AbstractRule) HashSet(java.util.HashSet)

Aggregations

CrossReference (org.eclipse.xtext.CrossReference)29 RuleCall (org.eclipse.xtext.RuleCall)13 EObject (org.eclipse.emf.ecore.EObject)12 AbstractRule (org.eclipse.xtext.AbstractRule)9 ParserRule (org.eclipse.xtext.ParserRule)8 EReference (org.eclipse.emf.ecore.EReference)7 Assignment (org.eclipse.xtext.Assignment)7 TypeRef (org.eclipse.xtext.TypeRef)7 Test (org.junit.Test)7 AbstractElement (org.eclipse.xtext.AbstractElement)6 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)6 INode (org.eclipse.xtext.nodemodel.INode)6 Action (org.eclipse.xtext.Action)5 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)4 TerminalRule (org.eclipse.xtext.TerminalRule)4 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)4 ArrayList (java.util.ArrayList)3 EClass (org.eclipse.emf.ecore.EClass)3 EnumRule (org.eclipse.xtext.EnumRule)3 Keyword (org.eclipse.xtext.Keyword)3