Search in sources :

Example 51 with ITextRegion

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

the class ProposalConflictHelper method existsConflict.

@Override
public boolean existsConflict(String proposal, ContentAssistContext context) {
    // hidden node between lastCompleteNode and currentNode?
    INode lastCompleteNode = context.getLastCompleteNode();
    ITextRegion replaceRegion = context.getReplaceRegion();
    int nodeEnd = lastCompleteNode.getEndOffset();
    if (nodeEnd < replaceRegion.getOffset())
        return false;
    return existsConflict(lastCompleteNode, replaceRegion.getOffset(), proposal, context);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 52 with ITextRegion

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

the class ContentAssistContextFactory method doComputePrefix.

public boolean doComputePrefix(ICompositeNode node, StringBuilder result) {
    List<ILeafNode> hiddens = Lists.newArrayListWithCapacity(2);
    for (INode child : node.getChildren()) {
        if (child instanceof ICompositeNode) {
            if (!doComputePrefix((ICompositeNode) child, result))
                return false;
        } else {
            ILeafNode leaf = (ILeafNode) child;
            ITextRegion leafRegion = leaf.getTextRegion();
            if (leafRegion.getOffset() > completionOffset)
                return false;
            if (leaf.isHidden()) {
                if (result.length() != 0)
                    hiddens.add((ILeafNode) child);
            } else {
                Iterator<ILeafNode> iter = hiddens.iterator();
                while (iter.hasNext()) {
                    result.append(iter.next().getText());
                }
                hiddens.clear();
                result.append(getNodeTextUpToCompletionOffset(leaf));
                if (leafRegion.getOffset() + leafRegion.getLength() > completionOffset)
                    return false;
            }
        }
    }
    return true;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ITextRegion(org.eclipse.xtext.util.ITextRegion) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 53 with ITextRegion

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

the class Bug306325Test method performTestWithEncoding.

protected void performTestWithEncoding(String encoding) throws UnsupportedEncodingException, IOException {
    String model = "�cl�p� M�d�l�ng Pr�j�kt";
    byte[] utfBytes = model.getBytes(encoding);
    XtextResource resource = createXtextResource();
    resource.load(new ByteArrayInputStream(utfBytes), Collections.singletonMap(XtextResource.OPTION_ENCODING, encoding));
    Model root = (Model) resource.getContents().get(0);
    EList<Word> words = root.getWords();
    assertEquals(3, words.size());
    String[] lexemes = model.split(" ");
    ILocationInFileProvider locationInFileProvider = getInjector().getInstance(ILocationInFileProvider.class);
    ITextRegion location0 = locationInFileProvider.getSignificantTextRegion(words.get(0));
    assertEquals(0, location0.getOffset());
    assertEquals(lexemes[0].length(), location0.getLength());
    ITextRegion location1 = locationInFileProvider.getSignificantTextRegion(words.get(1));
    assertEquals(lexemes[0].length() + 1, location1.getOffset());
    assertEquals(lexemes[1].length(), location1.getLength());
    ITextRegion location2 = locationInFileProvider.getSignificantTextRegion(words.get(2));
    assertEquals(lexemes[0].length() + lexemes[1].length() + 2, location2.getOffset());
    assertEquals(lexemes[2].length(), location2.getLength());
}
Also used : Word(org.eclipse.xtext.parser.encoding.encodingTest.Word) ByteArrayInputStream(java.io.ByteArrayInputStream) ITextRegion(org.eclipse.xtext.util.ITextRegion) Model(org.eclipse.xtext.parser.encoding.encodingTest.Model)

Example 54 with ITextRegion

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

the class RegionComparator method compare.

@Override
public int compare(T t1, T t2) {
    ITextRegion o1 = regionAccess.apply(t1);
    ITextRegion o2 = regionAccess.apply(t2);
    int cmp1 = o1.getOffset() - o2.getOffset();
    if (cmp1 != 0)
        return cmp1;
    int cmp2 = o1.getLength() - o2.getLength();
    if (cmp2 != 0)
        return cmp2;
    return 0;
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 55 with ITextRegion

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

the class TracingSugar method location.

/**
 * @return ILocationData covering the <code>fullTextRegion</code> of the given EObject.
 */
public ILocationData location(final EObject obj) {
    final ITextRegion region = this.locationProvider.getFullTextRegion(obj);
    final SourceRelativeURI uri = this.traceURIConverter.getURIForTrace(obj.eResource());
    return new LocationData(((ITextRegionWithLineInformation) region), uri);
}
Also used : ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) LocationData(org.eclipse.xtext.generator.trace.LocationData) ILocationData(org.eclipse.xtext.generator.trace.ILocationData) ITextRegion(org.eclipse.xtext.util.ITextRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Aggregations

ITextRegion (org.eclipse.xtext.util.ITextRegion)59 TextRegion (org.eclipse.xtext.util.TextRegion)24 Test (org.junit.Test)14 INode (org.eclipse.xtext.nodemodel.INode)11 EObject (org.eclipse.emf.ecore.EObject)9 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)9 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)9 Collection (java.util.Collection)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)4 CommonToken (org.antlr.runtime.CommonToken)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)3 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)3 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 CoreException (org.eclipse.core.runtime.CoreException)2 URI (org.eclipse.emf.common.util.URI)2