Search in sources :

Example 36 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class ContentAssistContextFactory method computeCurrentModel.

protected Multimap<EObject, AbstractElement> computeCurrentModel(EObject currentModel, INode lastCompleteNode, Collection<AbstractElement> followElements) {
    Multimap<EObject, AbstractElement> result = LinkedHashMultimap.create();
    ICompositeNode currentParserNode = NodeModelUtils.getNode(currentModel);
    if (currentParserNode == null) {
        result.putAll(currentModel, followElements);
        return result;
    }
    EObject currentGrammarElement = currentParserNode.getGrammarElement();
    AbstractRule currentRule = getRule(currentGrammarElement);
    for (AbstractElement grammarElement : followElements) {
        AbstractRule rule = currentRule;
        ICompositeNode loopParserNode = currentParserNode;
        EObject loopLastGrammarElement = lastCompleteNode.getGrammarElement();
        while (!canBeCalledAfter(rule, loopLastGrammarElement, lastCompleteNode.getText(), grammarElement) && loopParserNode.getParent() != null) {
            loopLastGrammarElement = loopParserNode.getGrammarElement();
            loopParserNode = loopParserNode.getParent();
            while (loopParserNode.getGrammarElement() == null && loopParserNode.getParent() != null) loopParserNode = loopParserNode.getParent();
            EObject loopGrammarElement = loopParserNode.getGrammarElement();
            rule = getRule(loopGrammarElement);
        }
        EObject context = loopParserNode.getSemanticElement();
        result.put(context, grammarElement);
    }
    return result;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 37 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class XtextLinkingService method getLinkedMetaModel.

private List<EObject> getLinkedMetaModel(TypeRef context, EReference ref, ILeafNode text) throws IllegalNodeException {
    final ICompositeNode parentNode = text.getParent();
    BidiIterator<INode> iterator = parentNode.getChildren().iterator();
    while (iterator.hasPrevious()) {
        INode child = iterator.previous();
        if (child instanceof ILeafNode) {
            ILeafNode leaf = (ILeafNode) child;
            if (text == leaf)
                return super.getLinkedObjects(context, ref, text);
            if (!(leaf.getGrammarElement() instanceof Keyword) && !leaf.isHidden()) {
                IScope scope = getScope(context, ref);
                return XtextMetamodelReferenceHelper.findBestMetamodelForType(context, text.getText(), leaf.getText(), scope);
            }
        }
    }
    return Collections.emptyList();
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) Keyword(org.eclipse.xtext.Keyword) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) IScope(org.eclipse.xtext.scoping.IScope)

Example 38 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class SyntacticSequencerTestLanguageSyntacticSequencer method emit_MandatoryManyTransition_KW1ParserRuleCall_1_p.

/**
 * Syntax: KW1+
 */
@Override
protected void emit_MandatoryManyTransition_KW1ParserRuleCall_1_p(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
    ICompositeNode node = (ICompositeNode) nodes.get(0);
    acceptUnassignedDatatype(ga.getMandatoryManyTransitionAccess().getKW1ParserRuleCall_1(), "matched 4", node);
}
Also used : ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 39 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class SyntacticSequencerTestLanguageSyntacticSequencer method emit_AlternativeTransition_KW1ParserRuleCall_1_0_or_Kw2Keyword_1_1.

/**
 * Syntax: 'kw2' | KW1
 */
@Override
protected void emit_AlternativeTransition_KW1ParserRuleCall_1_0_or_Kw2Keyword_1_1(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
    ICompositeNode node = (ICompositeNode) nodes.get(0);
    acceptUnassignedDatatype(ga.getAlternativeTransitionAccess().getKW1ParserRuleCall_1_0(), "matched 5", node);
}
Also used : ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 40 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.

the class Bug250313Test method testDatatypeConversion_01.

@Test
public void testDatatypeConversion_01() throws Exception {
    Model model = (Model) getModel("1 foo - bar");
    assertEquals("str", model.getValue());
    assertEquals("org.eclipse.xtext.valueconverter.Bug250313.Datatype", lexerRule);
    assertTrue(node instanceof ICompositeNode);
    assertEquals(6, Iterables.size(((ICompositeNode) node).getChildren()));
    assertEquals("foo - bar", string);
    assertEquals(1, convertCallCount);
}
Also used : Model(org.eclipse.xtext.valueconverter.bug250313.Model) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Aggregations

ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)263 Test (org.junit.Test)87 INode (org.eclipse.xtext.nodemodel.INode)79 EObject (org.eclipse.emf.ecore.EObject)70 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)57 XtextResource (org.eclipse.xtext.resource.XtextResource)41 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)24 ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)20 Resource (org.eclipse.emf.ecore.resource.Resource)19 Model (org.eclipse.xtext.valueconverter.bug250313.Model)15 IParseResult (org.eclipse.xtext.parser.IParseResult)14 ParserRule (org.eclipse.xtext.ParserRule)12 ITextRegion (org.eclipse.xtext.util.ITextRegion)12 RuleCall (org.eclipse.xtext.RuleCall)11 CrossReference (org.eclipse.xtext.CrossReference)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)8 AbstractRule (org.eclipse.xtext.AbstractRule)8 Keyword (org.eclipse.xtext.Keyword)8