Search in sources :

Example 16 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.

the class ContentAssistContextFactory method doCreateContext.

public ContentAssistContext.Builder doCreateContext(INode lastCompleteNode, EObject currentModel, EObject previousModel, INode currentNode, String prefix) {
    ContentAssistContext.Builder context = contentAssistContextProvider.get();
    context.setRootNode(rootNode);
    context.setLastCompleteNode(lastCompleteNode);
    context.setCurrentNode(currentNode);
    context.setRootModel(parseResult.getRootASTElement());
    context.setCurrentModel(currentModel);
    context.setPreviousModel(previousModel);
    context.setOffset(completionOffset);
    context.setPrefix(prefix);
    int regionLength = prefix.length();
    if (selection.getLength() > 0) {
        regionLength = regionLength + selection.getLength();
    }
    ITextRegion region = new TextRegion(completionOffset - prefix.length(), regionLength);
    if (selection.getOffset() >= 0 && selection.getLength() >= 0) {
        context.setSelectedText(document.substring(selection.getOffset(), selection.getOffset() + selection.getLength()));
    }
    context.setReplaceRegion(region);
    context.setResource(resource);
    return context;
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ContentAssistContext(org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext) Builder(org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext.Builder)

Example 17 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.

the class DefaultFoldingRangeProvider method acceptObjectFolding.

protected void acceptObjectFolding(EObject eObject, IFoldingRangeAcceptor foldingRangeAcceptor) {
    ITextRegion region = locationInFileProvider.getFullTextRegion(eObject);
    if (region != null) {
        INode eObjectNode = NodeModelUtils.getNode(eObject);
        ITextRegion significant = buildSignificantRegion(locationInFileProvider.getSignificantTextRegion(eObject), eObjectNode);
        foldingRangeAcceptor.accept(region.getOffset(), region.getLength(), null, false, significant);
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 18 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.

the class DocumentExtensions method newLocation.

public Location newLocation(EObject owner, EStructuralFeature feature, int indexInList) {
    Resource resource = owner.eResource();
    ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(owner, feature, indexInList);
    return newLocation(resource, textRegion);
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 19 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.

the class IndentationAwareCompletionPrefixProvider method getLastCompleteNodeByOffset.

protected INode getLastCompleteNodeByOffset(INode node, int offset) {
    BidiTreeIterator<INode> iterator = node.getRootNode().getAsTreeIterable().iterator();
    INode result = node;
    ITextRegion candidateTextRegion = node.getTextRegion();
    while (iterator.hasNext()) {
        INode candidate = iterator.next();
        ITextRegion textRegion = candidate.getTextRegion();
        if (textRegion.getOffset() >= offset && !(textRegion.getOffset() == offset && textRegion.getLength() == 0)) {
            if (!candidateTextRegion.equals(textRegion) && candidate instanceof ILeafNode && textRegion.getLength() + textRegion.getOffset() >= offset) {
                break;
            }
        }
        if ((candidate instanceof ILeafNode) && (candidate.getGrammarElement() == null || candidate.getGrammarElement() instanceof AbstractElement || candidate.getGrammarElement() instanceof ParserRule)) {
            if (textRegion.getLength() == 0) {
                if (candidateTextRegion.getOffset() + candidateTextRegion.getLength() < offset || candidateTextRegion.getLength() == 0 && candidateTextRegion.getOffset() <= offset) {
                    result = candidate;
                    candidateTextRegion = candidate.getTextRegion();
                }
            } else {
                result = candidate;
                candidateTextRegion = candidate.getTextRegion();
            }
        }
    }
    return result;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) AbstractElement(org.eclipse.xtext.AbstractElement) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 20 with ITextRegion

use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.

the class DefaultSemanticHighlightingCalculator method highlightNode.

/**
 * Highlights the non-hidden parts of {@code node} with the styles given by the {@code styleIds}
 */
protected void highlightNode(IHighlightedPositionAcceptor acceptor, INode node, String... styleIds) {
    if (node == null)
        return;
    if (node instanceof ILeafNode) {
        ITextRegion textRegion = node.getTextRegion();
        acceptor.addPosition(textRegion.getOffset(), textRegion.getLength(), styleIds);
    } else {
        for (ILeafNode leaf : node.getLeafNodes()) {
            if (!leaf.isHidden()) {
                ITextRegion leafRegion = leaf.getTextRegion();
                acceptor.addPosition(leafRegion.getOffset(), leafRegion.getLength(), styleIds);
            }
        }
    }
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Aggregations

ITextRegion (org.eclipse.xtext.util.ITextRegion)122 TextRegion (org.eclipse.xtext.util.TextRegion)44 EObject (org.eclipse.emf.ecore.EObject)33 Test (org.junit.Test)20 INode (org.eclipse.xtext.nodemodel.INode)19 XtextResource (org.eclipse.xtext.resource.XtextResource)17 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)15 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)15 BadLocationException (org.eclipse.jface.text.BadLocationException)11 Region (org.eclipse.jface.text.Region)9 XExpression (org.eclipse.xtext.xbase.XExpression)9 IOException (java.io.IOException)8 CoreException (org.eclipse.core.runtime.CoreException)8 IParseResult (org.eclipse.xtext.parser.IParseResult)7 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)7 IRegion (org.eclipse.jface.text.IRegion)6 ITextSelection (org.eclipse.jface.text.ITextSelection)6 Collection (java.util.Collection)5 ArrayList (java.util.ArrayList)4 TextSelection (org.eclipse.jface.text.TextSelection)4