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);
}
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;
}
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());
}
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;
}
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);
}
Aggregations