use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-eclipse by eclipse.
the class XbaseEditor method selectAndReveal.
@Override
protected void selectAndReveal(final int selectionStart, final int selectionLength, final int revealStart, final int revealLength) {
try {
reentrantCallFromSelf++;
if (expectJavaSelection > 0) {
try {
ITrace traceToSource = getTraceStorage();
if (traceToSource != null) {
IResource javaResource = typeRoot.getResource();
if (expectLineSelection && javaResource instanceof IStorage) {
if (isCompiledWithJSR45()) {
try {
String string = Files.readStreamIntoString(((IStorage) javaResource).getContents());
Document javaDocument = new Document(string);
int line = getLineInJavaDocument(javaDocument, selectionStart, selectionLength);
if (line != -1) {
int startOffsetOfContents = getStartOffsetOfContentsInJava(javaDocument, line);
if (startOffsetOfContents != -1) {
ILocationInResource bestSelection = traceToSource.getBestAssociatedLocation(new TextRegion(startOffsetOfContents, 0));
if (bestSelection != null) {
final ITextRegionWithLineInformation textRegion = bestSelection.getTextRegion();
if (textRegion != null) {
int lineToSelect = textRegion.getLineNumber();
try {
IRegion lineInfo = getDocument().getLineInformation(lineToSelect);
super.selectAndReveal(lineInfo.getOffset(), lineInfo.getLength(), lineInfo.getOffset(), lineInfo.getLength());
return;
} catch (BadLocationException e) {
log.error(e.getMessage(), e);
}
}
}
}
}
} catch (BadLocationException e) {
// do nothing
} catch (CoreException e) {
// do nothing
}
}
} else if (selectionStart >= 0 && selectionLength >= 0) {
ILocationInResource bestSelection = traceToSource.getBestAssociatedLocation(new TextRegion(selectionStart, selectionLength));
if (bestSelection != null) {
ILocationInResource bestReveal = bestSelection;
if (selectionStart != revealStart || selectionLength != revealLength) {
bestReveal = traceToSource.getBestAssociatedLocation(new TextRegion(revealStart, revealLength));
if (bestReveal == null) {
bestReveal = bestSelection;
}
}
ITextRegion fixedSelection = bestSelection.getTextRegion();
if (fixedSelection != null) {
ITextRegion fixedReveal = bestReveal.getTextRegion();
if (fixedReveal == null) {
fixedReveal = fixedSelection;
}
super.selectAndReveal(fixedSelection.getOffset(), fixedSelection.getLength(), fixedReveal.getOffset(), fixedReveal.getLength());
return;
}
}
}
}
} finally {
expectLineSelection = false;
expectJavaSelection--;
}
}
super.selectAndReveal(selectionStart, selectionLength, revealStart, revealLength);
} finally {
reentrantCallFromSelf--;
}
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation 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.ITextRegionWithLineInformation in project xtext-xtend by eclipse.
the class CompilerTraceTest method merge.
public AbstractTraceRegion merge(final List<AbstractTraceRegion> regions) {
boolean _isEmpty = regions.isEmpty();
boolean _not = (!_isEmpty);
Assert.assertTrue(_not);
int _size = regions.size();
boolean _greaterThan = (_size > 1);
if (_greaterThan) {
ITextRegionWithLineInformation rootLocation = ITextRegionWithLineInformation.EMPTY_REGION;
ITextRegionWithLineInformation associated = ITextRegionWithLineInformation.EMPTY_REGION;
for (final AbstractTraceRegion child : regions) {
{
int _myOffset = child.getMyOffset();
int _myLength = child.getMyLength();
int _myLineNumber = child.getMyLineNumber();
int _myEndLineNumber = child.getMyEndLineNumber();
TextRegionWithLineInformation _textRegionWithLineInformation = new TextRegionWithLineInformation(_myOffset, _myLength, _myLineNumber, _myEndLineNumber);
rootLocation = rootLocation.merge(_textRegionWithLineInformation);
ILocationData childAssociation = child.getMergedAssociatedLocation();
if ((childAssociation != null)) {
associated = associated.merge(childAssociation);
}
}
}
final RootTraceRegionForTesting root = new RootTraceRegionForTesting(rootLocation, associated);
for (final AbstractTraceRegion child_1 : regions) {
child_1.setParent(root);
}
return root;
} else {
return IterableExtensions.<AbstractTraceRegion>head(regions);
}
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation 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);
}
use of org.eclipse.xtext.util.ITextRegionWithLineInformation in project xtext-core by eclipse.
the class DiagnosticConverterImpl method getLocationForNode.
protected IssueLocation getLocationForNode(INode node) {
ITextRegionWithLineInformation nodeRegion = node.getTextRegionWithLineInformation();
IssueLocation result = new IssueLocation();
result.lineNumber = nodeRegion.getLineNumber();
result.offset = nodeRegion.getOffset();
result.column = NodeModelUtils.getLineAndColumn(node, result.offset).getColumn();
result.length = nodeRegion.getLength();
return result;
}
Aggregations