Search in sources :

Example 31 with ICompositeNode

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

the class DocumentExtensions method newPosition.

public Position newPosition(final Resource resource, final int offset) {
    if ((resource instanceof XtextResource)) {
        final ICompositeNode rootNode = ((XtextResource) resource).getParseResult().getRootNode();
        final LineAndColumn lineAndColumn = NodeModelUtils.getLineAndColumn(rootNode, offset);
        int _line = lineAndColumn.getLine();
        int _minus = (_line - 1);
        int _column = lineAndColumn.getColumn();
        int _minus_1 = (_column - 1);
        return new Position(_minus, _minus_1);
    }
    return null;
}
Also used : Position(org.eclipse.lsp4j.Position) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) LineAndColumn(org.eclipse.xtext.util.LineAndColumn)

Example 32 with ICompositeNode

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

the class EntryPointFinder method normalizeToParent.

protected ICompositeNode normalizeToParent(ICompositeNode result) {
    if (result == null) {
        return result;
    }
    ICompositeNode parent = result.getParent();
    while (parent != null && parent.getFirstChild().equals(result) && parent.getLookAhead() == result.getLookAhead()) {
        result = parent;
        parent = result.getParent();
    }
    return result;
}
Also used : ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 33 with ICompositeNode

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

the class DefaultHierarchyNodeLocationProvider method toTextRegionWithLineInformation.

protected ITextRegionWithLineInformation toTextRegionWithLineInformation(final EObject obj, final ITextRegion textRegion) {
    if ((textRegion == null)) {
        return ITextRegionWithLineInformation.EMPTY_REGION;
    }
    if ((textRegion instanceof ITextRegionWithLineInformation)) {
        return ((ITextRegionWithLineInformation) textRegion);
    }
    final ICompositeNode node = NodeModelUtils.getNode(obj);
    if ((node == null)) {
        int _offset = textRegion.getOffset();
        int _length = textRegion.getLength();
        return new TextRegionWithLineInformation(_offset, _length, 0, 0);
    }
    int _line = NodeModelUtils.getLineAndColumn(node, textRegion.getOffset()).getLine();
    final int startLine = (_line - 1);
    int _offset_1 = textRegion.getOffset();
    int _length_1 = textRegion.getLength();
    int _plus = (_offset_1 + _length_1);
    int _line_1 = NodeModelUtils.getLineAndColumn(node, _plus).getLine();
    final int endLine = (_line_1 - 1);
    int _offset_2 = textRegion.getOffset();
    int _length_2 = textRegion.getLength();
    return new TextRegionWithLineInformation(_offset_2, _length_2, startLine, endLine);
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation)

Example 34 with ICompositeNode

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

the class AbstractCompletePrefixProviderTest method assertLastCompleteNode.

private void assertLastCompleteNode(final String model, final String expectation) {
    try {
        int offset = model.indexOf("<|>");
        if ((offset == (-1))) {
            offset = model.length();
        }
        int completionOffset = model.indexOf("<|>", offset);
        if ((completionOffset == (-1))) {
            completionOffset = offset;
        }
        final Tree tree = this.parseHelper.parse(model.replace("<|>", ""));
        final ICompositeNode nodeModel = NodeModelUtils.findActualNodeFor(tree);
        final INode completeNode = this.getTestee().getLastCompleteNodeByOffset(nodeModel, offset, completionOffset);
        this.assertNodeModel(expectation, completeNode);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Tree(org.eclipse.xtext.ide.tests.testlanguage.indentationAwareUiTestLanguage.Tree) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 35 with ICompositeNode

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

the class BaseContentAssistParser method getFollowElements.

public Collection<FE> getFollowElements(IParseResult parseResult, EntryPointFinder entryPointFinder, int offset, boolean strict) {
    ICompositeNode entryPoint = entryPointFinder.findEntryPoint(parseResult, offset);
    if (entryPoint != null) {
        String parseMe = getTextToParse(parseResult, entryPoint, offset);
        TokenSource tokenSource = createTokenSource(parseMe);
        InternalParser parser = createParser();
        parser.setStrict(strict);
        ObservableXtextTokenStream tokens = new ObservableXtextTokenStream(tokenSource, parser);
        tokens.setInitialHiddenTokens(getInitialHiddenTokens());
        parser.setTokenStream(tokens);
        IUnorderedGroupHelper helper = createUnorderedGroupHelper();
        parser.setUnorderedGroupHelper(helper);
        helper.initializeWith(parser);
        tokens.setListener(parser);
        try {
            Collection<FE> followElements = getFollowElements(parser, getEntryGrammarElement(entryPoint));
            return Lists.newArrayList(followElements);
        } catch (InfiniteRecursion infinite) {
            return Lists.newArrayList(parser.getFollowElements());
        }
    } else {
        String text = parseResult.getRootNode().getText();
        String parseMe = text.substring(0, offset);
        initializeFor(NodeModelUtils.getEntryParserRule(parseResult.getRootNode()));
        Collection<FE> followElements = getFollowElements(parseMe, strict);
        return followElements;
    }
}
Also used : TokenSource(org.antlr.runtime.TokenSource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) InfiniteRecursion(org.eclipse.xtext.ide.editor.contentassist.antlr.internal.InfiniteRecursion) IUnorderedGroupHelper(org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper)

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