use of org.eclipse.xtext.util.ITextRegion in project xtext-xtend by eclipse.
the class XtendOutlineWithEditorLinker method findNodesInRange.
protected void findNodesInRange(final IOutlineNode input, final ITextRegion selectedTextRegion, final List<IOutlineNode> nodes) {
final ITextRegion textRegion = input.getFullTextRegion();
if (((textRegion == null) || textRegion.contains(selectedTextRegion))) {
nodes.add(input);
}
List<IOutlineNode> _children = input.getChildren();
for (final IOutlineNode child : _children) {
this.findNodesInRange(child, selectedTextRegion, nodes);
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-xtend by eclipse.
the class XtendLocationInFileProvider method getSignificantTextRegion.
@Override
public ITextRegion getSignificantTextRegion(EObject element) {
if (element instanceof RichStringLiteral) {
ICompositeNode elementNode = findNodeFor(element);
if (elementNode == null) {
return ITextRegion.EMPTY_REGION;
}
ITextRegion result = ITextRegion.EMPTY_REGION;
for (INode node : elementNode.getLeafNodes()) {
if (isHidden(node)) {
continue;
}
EObject grammarElement = node.getGrammarElement();
if (!(grammarElement instanceof RuleCall)) {
continue;
}
RuleCall ruleCall = (RuleCall) grammarElement;
ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation();
int offset = region.getOffset();
int length = region.getLength();
if (grammarAccess.getRICH_TEXTRule() == ruleCall.getRule()) {
offset += 3;
length -= 6;
} else if (grammarAccess.getRICH_TEXT_STARTRule() == ruleCall.getRule()) {
offset += 3;
length -= 4;
} else if (grammarAccess.getRICH_TEXT_ENDRule() == ruleCall.getRule()) {
offset += 1;
length -= 4;
} else if (grammarAccess.getRICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
offset += 1;
length -= 2;
} else if (grammarAccess.getCOMMENT_RICH_TEXT_ENDRule() == ruleCall.getRule()) {
offset += 2;
length -= 5;
} else if (grammarAccess.getCOMMENT_RICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
offset += 2;
length -= 3;
} else {
continue;
}
result = result.merge(toZeroBasedRegion(new TextRegionWithLineInformation(offset, length, region.getLineNumber(), region.getEndLineNumber())));
}
return result;
}
return super.getSignificantTextRegion(element);
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-xtend by eclipse.
the class ValidatingRichStringAcceptor method resetCurrentOffset.
protected void resetCurrentOffset(/* @Nullable */
RichStringLiteral origin) {
if (root == null)
root = origin;
if (origin != null && origin != recent) {
if (wasCurrentOffset == -1)
wasCurrentOffset = currentOffset;
int diff = lastOffsetOfLiteral - currentOffset;
// no actions are involved, we are interested in the real node
recent = origin;
List<INode> featureNodes = NodeModelUtils.findNodesForFeature(origin, XbasePackage.Literals.XSTRING_LITERAL__VALUE);
if (featureNodes.size() == 1) {
INode node = featureNodes.get(0);
ITextRegion textRegion = node.getTextRegion();
currentOffset = textRegion.getOffset();
String nodeText = node.getText();
if (nodeText.endsWith("'''")) {
lastOffsetOfLiteral = currentOffset + textRegion.getLength() - 3;
} else if (nodeText.endsWith("''")) {
lastOffsetOfLiteral = currentOffset + textRegion.getLength() - 2;
} else if (nodeText.endsWith("'") || nodeText.endsWith("\u00AB")) {
lastOffsetOfLiteral = currentOffset + textRegion.getLength() - 1;
}
if (nodeText.charAt(0) == '\'') {
currentOffset += 3;
} else {
currentOffset += 1;
}
}
currentOffset -= diff;
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-xtend by eclipse.
the class FlexTokenRegionProviderTest method testTokenRegionContainsRegion.
@Test
public void testTokenRegionContainsRegion() throws Exception {
String modelAsString = "a1 / /* comment */ b2";
List<CommonToken> tokens = getTokens(modelAsString);
for (int length = 0; length < modelAsString.length(); ++length) {
for (int offset = 0; offset + length < modelAsString.length(); ++offset) {
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(modelAsString, new TextRegion(offset, length));
// System.out.println(offset + ":" + length + " -> " + tokenRegion);
CommonToken firstToken = findTokenStartingAt(tokenRegion.getOffset(), tokens);
assertTrue(firstToken.getStartIndex() <= offset);
if (tokenRegion.getLength() != 0) {
CommonToken lastToken = findTokenStopingAt(tokenRegion.getOffset() + tokenRegion.getLength() - 1, tokens);
assertTrue(lastToken.getStopIndex() >= offset + length - 1);
}
}
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-xtend by eclipse.
the class FlexTokenRegionProviderTest method testTokenMerge.
@Test
public void testTokenMerge() throws Exception {
String model = " ";
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0));
assertEquals(0, tokenRegion.getOffset());
assertEquals(2, tokenRegion.getLength());
}
Aggregations