Java Code Examples for org.eclipse.xtext.util.ITextRegionWithLineInformation#getLength()
The following examples show how to use
org.eclipse.xtext.util.ITextRegionWithLineInformation#getLength() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: N4JSDiagnosticConverter.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected IssueLocation getLocationForNode(INode node) { ITextRegionWithLineInformation nodeRegion = node.getTextRegionWithLineInformation(); N4JSIssueLocation result = new N4JSIssueLocation(); result.offset = nodeRegion.getOffset(); result.length = nodeRegion.getLength(); LineAndColumn lineAndColumnStart = NodeModelUtils.getLineAndColumn(node, result.offset); result.lineNumber = lineAndColumnStart.getLine(); result.column = lineAndColumnStart.getColumn(); LineAndColumn lineAndColumnEnd = NodeModelUtils.getLineAndColumn(node, result.offset + result.length); result.lineNumberEnd = lineAndColumnEnd.getLine(); result.columnEnd = lineAndColumnEnd.getColumn(); return result; }
Example 2
Source File: DefaultLocationInFileProvider.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.3 */ protected ITextRegion createRegion(List<INode> nodes, RegionDescription query) { if (query == RegionDescription.FULL || query == RegionDescription.SIGNIFICANT) return createRegion(nodes); ITextRegion result = ITextRegion.EMPTY_REGION; for (INode node : nodes) { for(INode leafNode: node.getLeafNodes()) { if (!isHidden(leafNode, query)) { ITextRegionWithLineInformation region = leafNode.getTextRegionWithLineInformation(); if (region.getLength() != 0) { result = result.merge(toZeroBasedRegion(region)); } } } } return result; }
Example 3
Source File: FeatureCallCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ILocationData toLocationData(List<INode> nodes) { ITextRegionWithLineInformation result = ITextRegionWithLineInformation.EMPTY_REGION; for (INode node : nodes) { if (!isHidden(node)) { ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation(); if (region.getLength() != 0) { result = result.merge(new TextRegionWithLineInformation(region.getOffset(), region.getLength(), region.getLineNumber() - 1, region.getEndLineNumber() - 1)); } } } if (result.getLength() == 0) return null; return new LocationData(result.getOffset(), result.getLength(), result.getLineNumber(), result.getEndLineNumber(), null); }
Example 4
Source File: AbstractTraceRegion.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Returns the merged location of all associated locations if they belong to the same resource. Otherwise * <code>null</code> is returned. */ public ILocationData getMergedAssociatedLocation() { List<ILocationData> allData = getAssociatedLocations(); if (allData.isEmpty()) { return null; } if (allData.size() == 1) { return allData.get(0); } boolean allNull = true; SourceRelativeURI path = null; ITextRegionWithLineInformation region = ITextRegionWithLineInformation.EMPTY_REGION; for (ILocationData data : allData) { if (path != null) { if (!path.equals(data.getSrcRelativePath())) { return null; } } else { if (data.getSrcRelativePath() == null) { if (!allNull) throw new IllegalStateException( "Iff multiple associated locations are present, the path has to be set"); } else { allNull = false; path = data.getSrcRelativePath(); } } region = region.merge(new TextRegionWithLineInformation(data.getOffset(), data.getLength(), data.getLineNumber(), data.getEndLineNumber())); } return new LocationData(region.getOffset(), region.getLength(), region.getLineNumber(), region.getEndLineNumber(), path); }
Example 5
Source File: DiagnosticConverterImpl.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Computes {@link IssueLocation} for the given node. */ protected IssueLocation getLocationForNode(INode node) { ITextRegionWithLineInformation nodeRegion = node.getTextRegionWithLineInformation(); int offset = nodeRegion.getOffset(); int length = nodeRegion.getLength(); return getLocationForNode(node, offset, length); }
Example 6
Source File: DefaultLocationInFileProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected ITextRegion createRegion(final List<INode> nodes) { ITextRegion result = ITextRegion.EMPTY_REGION; for (INode node : nodes) { if (!isHidden(node)) { ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation(); if (region.getLength() != 0) { result = result.merge(toZeroBasedRegion(region)); } } } return result; }
Example 7
Source File: DefaultCallHierarchyBuilder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String getText(EObject obj, ITextRegionWithLineInformation textRegion) { if (obj == null || textRegion == ITextRegionWithLineInformation.EMPTY_REGION) { return ""; } ICompositeNode node = NodeModelUtils.getNode(EcoreUtil.getRootContainer(obj)); if (node == null) { return ""; } int endOffset = textRegion.getOffset() + textRegion.getLength(); return node.getRootNode().getText().substring(textRegion.getOffset(), endOffset); }
Example 8
Source File: AbstractEclipseTrace.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override protected ILocationInEclipseResource createLocationInResource(ITextRegionWithLineInformation region, SourceRelativeURI srcRelativePath) { return new LocationInEclipseResource(region.getOffset(), region.getLength(), region.getLineNumber(), region.getEndLineNumber(), srcRelativePath, this); }
Example 9
Source File: XtendLocationInFileProvider.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@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); }
Example 10
Source File: LocationData.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public LocationData(ITextRegionWithLineInformation region, SourceRelativeURI path) { this(region.getOffset(), region.getLength(), region.getLineNumber(), region.getEndLineNumber(), path); }
Example 11
Source File: AbstractTrace.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected ILocationInResource createLocationInResource(ITextRegionWithLineInformation region, SourceRelativeURI srcRelativePath) { return new LocationInResource(region.getOffset(), region.getLength(), region.getLineNumber(), region.getEndLineNumber(), srcRelativePath, this); }
Example 12
Source File: DefaultLocationInFileProvider.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.5 */ protected TextRegionWithLineInformation toZeroBasedRegion(ITextRegionWithLineInformation region) { return new TextRegionWithLineInformation(region.getOffset(), region.getLength(), region.getLineNumber() - 1, region.getEndLineNumber() - 1); }